Annotation of loncom/interface/domainprefs.pm, revision 1.178
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.178 ! raeburn 4: # $Id: domainprefs.pm,v 1.177 2012/12/12 12:54:01 bisitz 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.163 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',
213: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 214: 'coursedefaults','usersessions','loadbalancing',
215: 'requestauthor'],$dom);
1.43 raeburn 216: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 217: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 218: 'usercreation','usermodification','scantron',
1.163 raeburn 219: 'requestcourses','requestauthor','coursecategories',
220: 'serverstatuses','helpsettings',
1.137 raeburn 221: 'coursedefaults','usersessions');
1.171 raeburn 222: my %existing;
223: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
224: %existing = %{$domconfig{'loadbalancing'}};
225: }
226: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 227: push(@prefs_order,'loadbalancing');
228: }
1.30 raeburn 229: my %prefs = (
230: 'rolecolors' =>
231: { text => 'Default color schemes',
1.67 raeburn 232: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 233: header => [{col1 => 'Student Settings',
234: col2 => '',},
235: {col1 => 'Coordinator Settings',
236: col2 => '',},
237: {col1 => 'Author Settings',
238: col2 => '',},
239: {col1 => 'Administrator Settings',
240: col2 => '',}],
241: },
1.110 raeburn 242: 'login' =>
1.30 raeburn 243: { text => 'Log-in page options',
1.67 raeburn 244: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 245: header => [{col1 => 'Log-in Page Items',
246: col2 => '',},
247: {col1 => 'Log-in Help',
248: col2 => 'Value'}],
1.30 raeburn 249: },
1.43 raeburn 250: 'defaults' =>
1.141 raeburn 251: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 252: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 253: header => [{col1 => 'Setting',
254: col2 => 'Value'}],
255: },
1.30 raeburn 256: 'quotas' =>
1.162 raeburn 257: { text => 'Blogs, personal web pages, webDAV, portfolios',
1.67 raeburn 258: help => 'Domain_Configuration_Quotas',
1.77 raeburn 259: header => [{col1 => 'User affiliation',
1.72 raeburn 260: col2 => 'Available tools',
261: col3 => 'Portfolio quota',}],
1.30 raeburn 262: },
263: 'autoenroll' =>
264: { text => 'Auto-enrollment settings',
1.67 raeburn 265: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 266: header => [{col1 => 'Configuration setting',
267: col2 => 'Value(s)'}],
268: },
269: 'autoupdate' =>
270: { text => 'Auto-update settings',
1.67 raeburn 271: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 272: header => [{col1 => 'Setting',
273: col2 => 'Value',},
1.131 raeburn 274: {col1 => 'Setting',
275: col2 => 'Affiliation'},
1.43 raeburn 276: {col1 => 'User population',
1.131 raeburn 277: col2 => 'Updateable user data'}],
1.30 raeburn 278: },
1.125 raeburn 279: 'autocreate' =>
280: { text => 'Auto-course creation settings',
281: help => 'Domain_Configuration_Auto_Creation',
282: header => [{col1 => 'Configuration Setting',
283: col2 => 'Value',}],
284: },
1.30 raeburn 285: 'directorysrch' =>
286: { text => 'Institutional directory searches',
1.67 raeburn 287: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 288: header => [{col1 => 'Setting',
289: col2 => 'Value',}],
290: },
291: 'contacts' =>
292: { text => 'Contact Information',
1.67 raeburn 293: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 294: header => [{col1 => 'Setting',
295: col2 => 'Value',}],
296: },
297:
298: 'usercreation' =>
299: { text => 'User creation',
1.67 raeburn 300: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 301: header => [{col1 => 'Format rule type',
302: col2 => 'Format rules in force'},
1.34 raeburn 303: {col1 => 'User account creation',
304: col2 => 'Usernames which may be created',},
1.30 raeburn 305: {col1 => 'Context',
1.43 raeburn 306: col2 => 'Assignable authentication types'}],
1.30 raeburn 307: },
1.69 raeburn 308: 'usermodification' =>
1.33 raeburn 309: { text => 'User modification',
1.67 raeburn 310: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 311: header => [{col1 => 'Target user has role',
312: col2 => 'User information updateable in author context'},
313: {col1 => 'Target user has role',
1.63 raeburn 314: col2 => 'User information updateable in course context'},
315: {col1 => "Status of user",
316: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 317: },
1.69 raeburn 318: 'scantron' =>
1.95 www 319: { text => 'Bubblesheet format file',
1.67 raeburn 320: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 321: header => [ {col1 => 'Item',
322: col2 => '',
323: }],
324: },
1.86 raeburn 325: 'requestcourses' =>
326: {text => 'Request creation of courses',
327: help => 'Domain_Configuration_Request_Courses',
328: header => [{col1 => 'User affiliation',
1.102 raeburn 329: col2 => 'Availability/Processing of requests',},
330: {col1 => 'Setting',
331: col2 => 'Value'}],
1.86 raeburn 332: },
1.163 raeburn 333: 'requestauthor' =>
334: {text => 'Request authoring space',
335: help => 'Domain_Configuration_Request_Author',
336: header => [{col1 => 'User affiliation',
337: col2 => 'Availability/Processing of requests',},
338: {col1 => 'Setting',
339: col2 => 'Value'}],
340: },
1.69 raeburn 341: 'coursecategories' =>
1.120 raeburn 342: { text => 'Cataloging of courses/communities',
1.67 raeburn 343: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 344: header => [{col1 => 'Category settings',
1.57 raeburn 345: col2 => '',},
346: {col1 => 'Categories',
347: col2 => '',
348: }],
1.69 raeburn 349: },
350: 'serverstatuses' =>
1.77 raeburn 351: {text => 'Access to server status pages',
1.69 raeburn 352: help => 'Domain_Configuration_Server_Status',
353: header => [{col1 => 'Status Page',
354: col2 => 'Other named users',
355: col3 => 'Specific IPs',
356: }],
357: },
1.118 jms 358: 'helpsettings' =>
359: {text => 'Help page settings',
360: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 361: header => [{col1 => 'Help Settings (logged-in users)',
362: col2 => 'Value'}],
1.118 jms 363: },
1.121 raeburn 364: 'coursedefaults' =>
365: {text => 'Course/Community defaults',
366: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 367: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
368: col2 => 'Value',},
369: {col1 => 'Defaults which can be overridden for each course by a DC',
370: col2 => 'Value',},],
1.121 raeburn 371: },
1.120 raeburn 372: 'privacy' =>
373: {text => 'User Privacy',
374: help => 'Domain_Configuration_User_Privacy',
375: header => [{col1 => 'Setting',
376: col2 => 'Value',}],
377: },
1.141 raeburn 378: 'usersessions' =>
1.145 raeburn 379: {text => 'User session hosting/offloading',
1.137 raeburn 380: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 381: header => [{col1 => 'Domain server',
382: col2 => 'Servers to offload sessions to when busy'},
383: {col1 => 'Hosting of users from other domains',
1.137 raeburn 384: col2 => 'Rules'},
385: {col1 => "Hosting domain's own users elsewhere",
386: col2 => 'Rules'}],
387: },
1.150 raeburn 388: 'loadbalancing' =>
389: {text => 'Dedicated Load Balancer',
390: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 391: header => [{col1 => 'Balancers',
1.150 raeburn 392: col2 => 'Default destinations',
393: col3 => 'User affliation',
394: col4 => 'Overrides'},
395: ],
396: },
1.3 raeburn 397: );
1.110 raeburn 398: if (keys(%servers) > 1) {
399: $prefs{'login'} = { text => 'Log-in page options',
400: help => 'Domain_Configuration_Login_Page',
401: header => [{col1 => 'Log-in Service',
402: col2 => 'Server Setting',},
403: {col1 => 'Log-in Page Items',
1.168 raeburn 404: col2 => ''},
405: {col1 => 'Log-in Help',
406: col2 => 'Value'}],
1.110 raeburn 407: };
408: }
1.174 foxr 409:
410:
411:
1.6 raeburn 412: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 413: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 414: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 415: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 416: text=>"Settings to display/modify"});
1.9 raeburn 417: my $confname = $dom.'-domainconfig';
1.174 foxr 418:
1.3 raeburn 419: if ($phase eq 'process') {
1.91 raeburn 420: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 421: } elsif ($phase eq 'display') {
1.165 raeburn 422: my $js = &recaptcha_js();
1.171 raeburn 423: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 424: my ($othertitle,$usertypes,$types) =
425: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 426: $js .= &lonbalance_targets_js($dom,$types,\%servers,
427: $domconfig{'loadbalancing'}).
1.170 raeburn 428: &new_spares_js().
429: &common_domprefs_js().
430: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 431: }
1.150 raeburn 432: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 433: } else {
1.21 raeburn 434: if (keys(%domconfig) == 0) {
435: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 436: my @ids=&Apache::lonnet::current_machine_ids();
437: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 438: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 439: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 440: my $custom_img_count = 0;
441: foreach my $img (@loginimages) {
442: if ($designhash{$dom.'.login.'.$img} ne '') {
443: $custom_img_count ++;
444: }
445: }
446: foreach my $role (@roles) {
447: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
448: $custom_img_count ++;
449: }
450: }
451: if ($custom_img_count > 0) {
1.94 raeburn 452: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 453: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 454: $r->print(
455: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
456: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
457: &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 />'.
458: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
459: if ($switch_server) {
1.30 raeburn 460: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 461: }
1.91 raeburn 462: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 463: return OK;
464: }
465: }
466: }
1.174 foxr 467:
1.91 raeburn 468: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 469: }
470: return OK;
471: }
472:
473: sub process_changes {
1.92 raeburn 474: my ($r,$dom,$confname,$action,$roles,$values) = @_;
475: my %domconfig;
476: if (ref($values) eq 'HASH') {
477: %domconfig = %{$values};
478: }
1.3 raeburn 479: my $output;
480: if ($action eq 'login') {
1.9 raeburn 481: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 482: } elsif ($action eq 'rolecolors') {
1.9 raeburn 483: $output = &modify_rolecolors($r,$dom,$confname,$roles,
484: %domconfig);
1.3 raeburn 485: } elsif ($action eq 'quotas') {
1.86 raeburn 486: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 487: } elsif ($action eq 'autoenroll') {
488: $output = &modify_autoenroll($dom,%domconfig);
489: } elsif ($action eq 'autoupdate') {
490: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 491: } elsif ($action eq 'autocreate') {
492: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 493: } elsif ($action eq 'directorysrch') {
494: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 495: } elsif ($action eq 'usercreation') {
1.28 raeburn 496: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 497: } elsif ($action eq 'usermodification') {
498: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 499: } elsif ($action eq 'contacts') {
500: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 501: } elsif ($action eq 'defaults') {
502: $output = &modify_defaults($dom,$r);
1.46 raeburn 503: } elsif ($action eq 'scantron') {
1.48 raeburn 504: $output = &modify_scantron($r,$dom,$confname,%domconfig);
505: } elsif ($action eq 'coursecategories') {
506: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 507: } elsif ($action eq 'serverstatuses') {
508: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 509: } elsif ($action eq 'requestcourses') {
510: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 511: } elsif ($action eq 'requestauthor') {
512: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 513: } elsif ($action eq 'helpsettings') {
1.122 jms 514: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 515: } elsif ($action eq 'coursedefaults') {
516: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 517: } elsif ($action eq 'usersessions') {
518: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 519: } elsif ($action eq 'loadbalancing') {
520: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 521: }
522: return $output;
523: }
524:
525: sub print_config_box {
1.9 raeburn 526: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 527: my $rowtotal = 0;
1.49 raeburn 528: my $output;
1.174 foxr 529:
1.49 raeburn 530: if ($action eq 'coursecategories') {
531: $output = &coursecategories_javascript($settings);
1.91 raeburn 532: }
1.49 raeburn 533: $output .=
1.30 raeburn 534: '<table class="LC_nested_outer">
1.3 raeburn 535: <tr>
1.66 raeburn 536: <th align="left" valign="middle"><span class="LC_nobreak">'.
537: &mt($item->{text}).' '.
538: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
539: '</tr>';
1.30 raeburn 540: $rowtotal ++;
1.110 raeburn 541: my $numheaders = 1;
542: if (ref($item->{'header'}) eq 'ARRAY') {
543: $numheaders = scalar(@{$item->{'header'}});
544: }
545: if ($numheaders > 1) {
1.64 raeburn 546: my $colspan = '';
1.145 raeburn 547: my $rightcolspan = '';
1.168 raeburn 548: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
549: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 550: $colspan = ' colspan="2"';
551: }
1.145 raeburn 552: if ($action eq 'usersessions') {
553: $rightcolspan = ' colspan="3"';
554: }
1.30 raeburn 555: $output .= '
1.3 raeburn 556: <tr>
557: <td>
558: <table class="LC_nested">
559: <tr class="LC_info_row">
1.59 bisitz 560: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 561: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 562: </tr>';
1.69 raeburn 563: $rowtotal ++;
1.6 raeburn 564: if ($action eq 'autoupdate') {
1.30 raeburn 565: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 566: } elsif ($action eq 'usercreation') {
1.33 raeburn 567: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
568: } elsif ($action eq 'usermodification') {
569: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 570: } elsif ($action eq 'coursecategories') {
571: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 572: } elsif ($action eq 'login') {
1.168 raeburn 573: if ($numheaders == 3) {
574: $colspan = ' colspan="2"';
575: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
576: } else {
577: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
578: }
1.102 raeburn 579: } elsif ($action eq 'requestcourses') {
580: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 581: } elsif ($action eq 'requestauthor') {
582: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 583: } elsif ($action eq 'usersessions') {
584: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 585: } elsif ($action eq 'rolecolors') {
1.30 raeburn 586: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 587: } elsif ($action eq 'coursedefaults') {
588: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 589: }
1.30 raeburn 590: $output .= '
1.6 raeburn 591: </table>
592: </td>
593: </tr>
594: <tr>
595: <td>
596: <table class="LC_nested">
597: <tr class="LC_info_row">
1.59 bisitz 598: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 599: $output .= '
1.59 bisitz 600: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 601: </tr>';
602: $rowtotal ++;
1.6 raeburn 603: if ($action eq 'autoupdate') {
1.131 raeburn 604: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
605: </table>
606: </td>
607: </tr>
608: <tr>
609: <td>
610: <table class="LC_nested">
611: <tr class="LC_info_row">
612: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
613: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
614: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
615: $rowtotal ++;
1.28 raeburn 616: } elsif ($action eq 'usercreation') {
1.34 raeburn 617: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
618: </table>
619: </td>
620: </tr>
621: <tr>
622: <td>
623: <table class="LC_nested">
624: <tr class="LC_info_row">
1.59 bisitz 625: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
626: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 627: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
628: $rowtotal ++;
1.33 raeburn 629: } elsif ($action eq 'usermodification') {
1.63 raeburn 630: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
631: </table>
632: </td>
633: </tr>
634: <tr>
635: <td>
636: <table class="LC_nested">
637: <tr class="LC_info_row">
638: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
639: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
640: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
641: $rowtotal ++;
1.57 raeburn 642: } elsif ($action eq 'coursecategories') {
643: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 644: } elsif ($action eq 'login') {
1.168 raeburn 645: if ($numheaders == 3) {
646: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
647: </table>
648: </td>
649: </tr>
650: <tr>
651: <td>
652: <table class="LC_nested">
653: <tr class="LC_info_row">
654: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
655: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
656: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
657: $rowtotal ++;
658: } else {
659: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
660: }
1.102 raeburn 661: } elsif ($action eq 'requestcourses') {
1.163 raeburn 662: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
663: } elsif ($action eq 'requestauthor') {
664: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 665: } elsif ($action eq 'usersessions') {
1.145 raeburn 666: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
667: </table>
668: </td>
669: </tr>
670: <tr>
671: <td>
672: <table class="LC_nested">
673: <tr class="LC_info_row">
674: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
675: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
676: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
677: $rowtotal ++;
1.139 raeburn 678: } elsif ($action eq 'coursedefaults') {
679: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 680: } elsif ($action eq 'rolecolors') {
1.30 raeburn 681: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 682: </table>
683: </td>
684: </tr>
685: <tr>
686: <td>
687: <table class="LC_nested">
688: <tr class="LC_info_row">
1.69 raeburn 689: <td class="LC_left_item"'.$colspan.' valign="top">'.
690: &mt($item->{'header'}->[2]->{'col1'}).'</td>
691: <td class="LC_right_item" valign="top">'.
692: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 693: </tr>'.
1.30 raeburn 694: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 695: </table>
696: </td>
697: </tr>
698: <tr>
699: <td>
700: <table class="LC_nested">
701: <tr class="LC_info_row">
1.59 bisitz 702: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
703: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 704: </tr>'.
1.30 raeburn 705: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
706: $rowtotal += 2;
1.6 raeburn 707: }
1.3 raeburn 708: } else {
1.30 raeburn 709: $output .= '
1.3 raeburn 710: <tr>
711: <td>
712: <table class="LC_nested">
1.30 raeburn 713: <tr class="LC_info_row">';
1.24 raeburn 714: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 715: $output .= '
1.59 bisitz 716: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 717: } elsif ($action eq 'serverstatuses') {
718: $output .= '
719: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
720: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
721:
1.6 raeburn 722: } else {
1.30 raeburn 723: $output .= '
1.69 raeburn 724: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
725: }
1.72 raeburn 726: if (defined($item->{'header'}->[0]->{'col3'})) {
727: $output .= '<td class="LC_left_item" valign="top">'.
728: &mt($item->{'header'}->[0]->{'col2'});
729: if ($action eq 'serverstatuses') {
730: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
731: }
1.69 raeburn 732: } else {
733: $output .= '<td class="LC_right_item" valign="top">'.
734: &mt($item->{'header'}->[0]->{'col2'});
735: }
736: $output .= '</td>';
737: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 738: if (defined($item->{'header'}->[0]->{'col4'})) {
739: $output .= '<td class="LC_left_item" valign="top">'.
740: &mt($item->{'header'}->[0]->{'col3'});
741: } else {
742: $output .= '<td class="LC_right_item" valign="top">'.
743: &mt($item->{'header'}->[0]->{'col3'});
744: }
1.69 raeburn 745: if ($action eq 'serverstatuses') {
746: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
747: }
748: $output .= '</td>';
1.6 raeburn 749: }
1.150 raeburn 750: if ($item->{'header'}->[0]->{'col4'}) {
751: $output .= '<td class="LC_right_item" valign="top">'.
752: &mt($item->{'header'}->[0]->{'col4'});
753: }
1.69 raeburn 754: $output .= '</tr>';
1.48 raeburn 755: $rowtotal ++;
1.168 raeburn 756: if ($action eq 'quotas') {
1.86 raeburn 757: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 758: } elsif ($action eq 'autoenroll') {
1.30 raeburn 759: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 760: } elsif ($action eq 'autocreate') {
761: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 762: } elsif ($action eq 'directorysrch') {
1.30 raeburn 763: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 764: } elsif ($action eq 'contacts') {
1.30 raeburn 765: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 766: } elsif ($action eq 'defaults') {
767: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 768: } elsif ($action eq 'scantron') {
769: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 770: } elsif ($action eq 'serverstatuses') {
771: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 772: } elsif ($action eq 'helpsettings') {
1.168 raeburn 773: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 774: } elsif ($action eq 'loadbalancing') {
775: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 776: }
1.3 raeburn 777: }
1.30 raeburn 778: $output .= '
1.3 raeburn 779: </table>
780: </td>
781: </tr>
1.30 raeburn 782: </table><br />';
783: return ($output,$rowtotal);
1.1 raeburn 784: }
785:
1.3 raeburn 786: sub print_login {
1.168 raeburn 787: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 788: my ($css_class,$datatable);
1.6 raeburn 789: my %choices = &login_choices();
1.110 raeburn 790:
1.168 raeburn 791: if ($caller eq 'service') {
1.149 raeburn 792: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 793: my $choice = $choices{'disallowlogin'};
794: $css_class = ' class="LC_odd_row"';
1.128 raeburn 795: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 796: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 797: '<th>'.$choices{'server'}.'</th>'.
798: '<th>'.$choices{'serverpath'}.'</th>'.
799: '<th>'.$choices{'custompath'}.'</th>'.
800: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 801: my %disallowed;
802: if (ref($settings) eq 'HASH') {
803: if (ref($settings->{'loginvia'}) eq 'HASH') {
804: %disallowed = %{$settings->{'loginvia'}};
805: }
806: }
807: foreach my $lonhost (sort(keys(%servers))) {
808: my $direct = 'selected="selected"';
1.128 raeburn 809: if (ref($disallowed{$lonhost}) eq 'HASH') {
810: if ($disallowed{$lonhost}{'server'} ne '') {
811: $direct = '';
812: }
1.110 raeburn 813: }
1.115 raeburn 814: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 815: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 816: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
817: '</option>';
1.177 bisitz 818: foreach my $hostid (sort keys(%servers)) {
1.115 raeburn 819: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 820: my $selected = '';
1.128 raeburn 821: if (ref($disallowed{$lonhost}) eq 'HASH') {
822: if ($hostid eq $disallowed{$lonhost}{'server'}) {
823: $selected = 'selected="selected"';
824: }
1.110 raeburn 825: }
826: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
827: $servers{$hostid}.'</option>';
828: }
1.128 raeburn 829: $datatable .= '</select></td>'.
830: '<td><select name="'.$lonhost.'_serverpath">';
831: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
832: my $pathname = $path;
833: if ($path eq 'custom') {
834: $pathname = &mt('Custom Path').' ->';
835: }
836: my $selected = '';
837: if (ref($disallowed{$lonhost}) eq 'HASH') {
838: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
839: $selected = 'selected="selected"';
840: }
841: } elsif ($path eq '') {
842: $selected = 'selected="selected"';
843: }
844: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
845: }
846: $datatable .= '</select></td>';
847: my ($custom,$exempt);
848: if (ref($disallowed{$lonhost}) eq 'HASH') {
849: $custom = $disallowed{$lonhost}{'custompath'};
850: $exempt = $disallowed{$lonhost}{'exempt'};
851: }
852: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
853: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
854: '</tr>';
1.110 raeburn 855: }
856: $datatable .= '</table></td></tr>';
857: return $datatable;
1.168 raeburn 858: } elsif ($caller eq 'page') {
859: my %defaultchecked = (
860: 'coursecatalog' => 'on',
861: 'adminmail' => 'off',
862: 'newuser' => 'off',
863: );
864: my @toggles = ('coursecatalog','adminmail','newuser');
865: my (%checkedon,%checkedoff);
1.42 raeburn 866: foreach my $item (@toggles) {
1.168 raeburn 867: if ($defaultchecked{$item} eq 'on') {
868: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 869: $checkedoff{$item} = ' ';
1.168 raeburn 870: } elsif ($defaultchecked{$item} eq 'off') {
871: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 872: $checkedon{$item} = ' ';
873: }
1.1 raeburn 874: }
1.168 raeburn 875: my @images = ('img','logo','domlogo','login');
876: my @logintext = ('textcol','bgcol');
877: my @bgs = ('pgbg','mainbg','sidebg');
878: my @links = ('link','alink','vlink');
879: my %designhash = &Apache::loncommon::get_domainconf($dom);
880: my %defaultdesign = %Apache::loncommon::defaultdesign;
881: my (%is_custom,%designs);
882: my %defaults = (
883: font => $defaultdesign{'login.font'},
884: );
1.6 raeburn 885: foreach my $item (@images) {
1.168 raeburn 886: $defaults{$item} = $defaultdesign{'login.'.$item};
887: $defaults{'showlogo'}{$item} = 1;
888: }
889: foreach my $item (@bgs) {
890: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 891: }
1.41 raeburn 892: foreach my $item (@logintext) {
1.168 raeburn 893: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 894: }
1.168 raeburn 895: foreach my $item (@links) {
896: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 897: }
1.168 raeburn 898: if (ref($settings) eq 'HASH') {
899: foreach my $item (@toggles) {
900: if ($settings->{$item} eq '1') {
901: $checkedon{$item} = ' checked="checked" ';
902: $checkedoff{$item} = ' ';
903: } elsif ($settings->{$item} eq '0') {
904: $checkedoff{$item} = ' checked="checked" ';
905: $checkedon{$item} = ' ';
906: }
907: }
908: foreach my $item (@images) {
909: if (defined($settings->{$item})) {
910: $designs{$item} = $settings->{$item};
911: $is_custom{$item} = 1;
912: }
913: if (defined($settings->{'showlogo'}{$item})) {
914: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
915: }
916: }
917: foreach my $item (@logintext) {
918: if ($settings->{$item} ne '') {
919: $designs{'logintext'}{$item} = $settings->{$item};
920: $is_custom{$item} = 1;
921: }
922: }
923: if ($settings->{'font'} ne '') {
924: $designs{'font'} = $settings->{'font'};
925: $is_custom{'font'} = 1;
926: }
927: foreach my $item (@bgs) {
928: if ($settings->{$item} ne '') {
929: $designs{'bgs'}{$item} = $settings->{$item};
930: $is_custom{$item} = 1;
931: }
932: }
933: foreach my $item (@links) {
934: if ($settings->{$item} ne '') {
935: $designs{'links'}{$item} = $settings->{$item};
936: $is_custom{$item} = 1;
937: }
938: }
939: } else {
940: if ($designhash{$dom.'.login.font'} ne '') {
941: $designs{'font'} = $designhash{$dom.'.login.font'};
942: $is_custom{'font'} = 1;
943: }
944: foreach my $item (@images) {
945: if ($designhash{$dom.'.login.'.$item} ne '') {
946: $designs{$item} = $designhash{$dom.'.login.'.$item};
947: $is_custom{$item} = 1;
948: }
949: }
950: foreach my $item (@bgs) {
951: if ($designhash{$dom.'.login.'.$item} ne '') {
952: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
953: $is_custom{$item} = 1;
954: }
1.6 raeburn 955: }
1.168 raeburn 956: foreach my $item (@links) {
957: if ($designhash{$dom.'.login.'.$item} ne '') {
958: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
959: $is_custom{$item} = 1;
960: }
1.6 raeburn 961: }
962: }
1.168 raeburn 963: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
964: logo => 'Institution Logo',
965: domlogo => 'Domain Logo',
966: login => 'Login box');
967: my $itemcount = 1;
968: foreach my $item (@toggles) {
969: $css_class = $itemcount%2?' class="LC_odd_row"':'';
970: $datatable .=
971: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
972: '</td><td>'.
973: '<span class="LC_nobreak"><label><input type="radio" name="'.
974: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
975: '</label> <label><input type="radio" name="'.$item.'"'.
976: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
977: '</tr>';
978: $itemcount ++;
1.6 raeburn 979: }
1.168 raeburn 980: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
981: $datatable .= '</tr></table></td></tr>';
982: } elsif ($caller eq 'help') {
983: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
984: my $switchserver = &check_switchserver($dom,$confname);
985: my $itemcount = 1;
986: $defaulturl = '/adm/loginproblems.html';
987: $defaulttype = 'default';
988: %lt = &Apache::lonlocal::texthash (
989: del => 'Delete?',
990: rep => 'Replace:',
991: upl => 'Upload:',
992: default => 'Default',
993: custom => 'Custom',
994: );
995: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
996: my @currlangs;
997: if (ref($settings) eq 'HASH') {
998: if (ref($settings->{'helpurl'}) eq 'HASH') {
999: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1000: next if ($settings->{'helpurl'}{$key} eq '');
1001: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1002: $type{$key} = 'custom';
1003: unless ($key eq 'nolang') {
1004: push(@currlangs,$key);
1005: }
1006: }
1007: } elsif ($settings->{'helpurl'} ne '') {
1008: $type{'nolang'} = 'custom';
1009: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1010: }
1011: }
1.168 raeburn 1012: foreach my $lang ('nolang',sort(@currlangs)) {
1013: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1014: $datatable .= '<tr'.$css_class.'>';
1015: if ($url{$lang} eq '') {
1016: $url{$lang} = $defaulturl;
1017: }
1018: if ($type{$lang} eq '') {
1019: $type{$lang} = $defaulttype;
1020: }
1021: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1022: if ($lang eq 'nolang') {
1023: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1024: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1025: } else {
1026: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1027: $langchoices{$lang},
1028: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1029: }
1030: $datatable .= '</span></td>'."\n".
1031: '<td class="LC_left_item">';
1032: if ($type{$lang} eq 'custom') {
1033: $datatable .= '<span class="LC_nobreak"><label>'.
1034: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1035: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1036: } else {
1037: $datatable .= $lt{'upl'};
1038: }
1039: $datatable .='<br />';
1040: if ($switchserver) {
1041: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1042: } else {
1043: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1044: }
1.168 raeburn 1045: $datatable .= '</td></tr>';
1046: $itemcount ++;
1.6 raeburn 1047: }
1.168 raeburn 1048: my @addlangs;
1049: foreach my $lang (sort(keys(%langchoices))) {
1050: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1051: push(@addlangs,$lang);
1052: }
1053: if (@addlangs > 0) {
1054: my %toadd;
1055: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1056: $toadd{''} = &mt('Select');
1057: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1058: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1059: &mt('Add log-in help page for a specific language:').' '.
1060: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1061: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1062: if ($switchserver) {
1063: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1064: } else {
1065: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1066: }
1.168 raeburn 1067: $datatable .= '</td></tr>';
1.169 raeburn 1068: $itemcount ++;
1.6 raeburn 1069: }
1.169 raeburn 1070: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1071: }
1.6 raeburn 1072: return $datatable;
1073: }
1074:
1075: sub login_choices {
1076: my %choices =
1077: &Apache::lonlocal::texthash (
1.116 bisitz 1078: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1079: adminmail => "Display Administrator's E-mail Address?",
1080: disallowlogin => "Login page requests redirected",
1081: hostid => "Server",
1.128 raeburn 1082: server => "Redirect to:",
1083: serverpath => "Path",
1084: custompath => "Custom",
1085: exempt => "Exempt IP(s)",
1.110 raeburn 1086: directlogin => "No redirect",
1087: newuser => "Link to create a user account",
1088: img => "Header",
1089: logo => "Main Logo",
1090: domlogo => "Domain Logo",
1091: login => "Log-in Header",
1092: textcol => "Text color",
1093: bgcol => "Box color",
1094: bgs => "Background colors",
1095: links => "Link colors",
1096: font => "Font color",
1097: pgbg => "Header",
1098: mainbg => "Page",
1099: sidebg => "Login box",
1100: link => "Link",
1101: alink => "Active link",
1102: vlink => "Visited link",
1.6 raeburn 1103: );
1104: return %choices;
1105: }
1106:
1107: sub print_rolecolors {
1.30 raeburn 1108: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1109: my %choices = &color_font_choices();
1110: my @bgs = ('pgbg','tabbg','sidebg');
1111: my @links = ('link','alink','vlink');
1112: my @images = ('img');
1113: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1114: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1115: my %defaultdesign = %Apache::loncommon::defaultdesign;
1116: my (%is_custom,%designs);
1117: my %defaults = (
1118: img => $defaultdesign{$role.'.img'},
1119: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1120: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1121: );
1122: foreach my $item (@bgs) {
1123: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1124: }
1125: foreach my $item (@links) {
1126: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1127: }
1128: if (ref($settings) eq 'HASH') {
1129: if (ref($settings->{$role}) eq 'HASH') {
1130: if ($settings->{$role}->{'img'} ne '') {
1131: $designs{'img'} = $settings->{$role}->{'img'};
1132: $is_custom{'img'} = 1;
1133: }
1134: if ($settings->{$role}->{'font'} ne '') {
1135: $designs{'font'} = $settings->{$role}->{'font'};
1136: $is_custom{'font'} = 1;
1137: }
1.97 tempelho 1138: if ($settings->{$role}->{'fontmenu'} ne '') {
1139: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1140: $is_custom{'fontmenu'} = 1;
1141: }
1.6 raeburn 1142: foreach my $item (@bgs) {
1143: if ($settings->{$role}->{$item} ne '') {
1144: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1145: $is_custom{$item} = 1;
1146: }
1147: }
1148: foreach my $item (@links) {
1149: if ($settings->{$role}->{$item} ne '') {
1150: $designs{'links'}{$item} = $settings->{$role}->{$item};
1151: $is_custom{$item} = 1;
1152: }
1153: }
1154: }
1155: } else {
1156: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1157: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1158: $is_custom{'img'} = 1;
1159: }
1.97 tempelho 1160: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1161: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1162: $is_custom{'fontmenu'} = 1;
1163: }
1.6 raeburn 1164: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1165: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1166: $is_custom{'font'} = 1;
1167: }
1168: foreach my $item (@bgs) {
1169: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1170: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1171: $is_custom{$item} = 1;
1172:
1173: }
1174: }
1175: foreach my $item (@links) {
1176: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1177: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1178: $is_custom{$item} = 1;
1179: }
1180: }
1181: }
1182: my $itemcount = 1;
1.30 raeburn 1183: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1184: $datatable .= '</tr></table></td></tr>';
1185: return $datatable;
1186: }
1187:
1188: sub display_color_options {
1.9 raeburn 1189: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1190: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1191: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1192: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1193: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1194: '<td>'.$choices->{'font'}.'</td>';
1195: if (!$is_custom->{'font'}) {
1.30 raeburn 1196: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1197: } else {
1198: $datatable .= '<td> </td>';
1199: }
1.174 foxr 1200: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1201:
1.8 raeburn 1202: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1203: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1204: ' value="'.$current_color.'" /> '.
1205: ' </td></tr>';
1.107 raeburn 1206: unless ($role eq 'login') {
1207: $datatable .= '<tr'.$css_class.'>'.
1208: '<td>'.$choices->{'fontmenu'}.'</td>';
1209: if (!$is_custom->{'fontmenu'}) {
1210: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1211: } else {
1212: $datatable .= '<td> </td>';
1213: }
1.174 foxr 1214: $current_color = $designs->{'fontmenu'} ?
1215: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1216: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1217: '<input class="colorchooser" type="text" size="10" name="'
1218: .$role.'_fontmenu"'.
1219: ' value="'.$current_color.'" /> '.
1220: ' </td></tr>';
1.97 tempelho 1221: }
1.9 raeburn 1222: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1223: foreach my $img (@{$images}) {
1.18 albertel 1224: $itemcount ++;
1.6 raeburn 1225: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1226: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1227: '<td>'.$choices->{$img};
1.41 raeburn 1228: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1229: if ($role eq 'login') {
1230: if ($img eq 'login') {
1231: $login_hdr_pick =
1.135 bisitz 1232: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1233: $logincolors =
1234: &login_text_colors($img,$role,$logintext,$phase,$choices,
1235: $designs);
1236: } elsif ($img ne 'domlogo') {
1237: $datatable.= &logo_display_options($img,$defaults,$designs);
1238: }
1239: }
1240: $datatable .= '</td>';
1.6 raeburn 1241: if ($designs->{$img} ne '') {
1242: $imgfile = $designs->{$img};
1.18 albertel 1243: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1244: } else {
1245: $imgfile = $defaults->{$img};
1246: }
1247: if ($imgfile) {
1.9 raeburn 1248: my ($showfile,$fullsize);
1249: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1250: my $urldir = $1;
1251: my $filename = $2;
1252: my @info = &Apache::lonnet::stat_file($designs->{$img});
1253: if (@info) {
1254: my $thumbfile = 'tn-'.$filename;
1255: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1256: if (@thumb) {
1257: $showfile = $urldir.'/'.$thumbfile;
1258: } else {
1259: $showfile = $imgfile;
1260: }
1261: } else {
1262: $showfile = '';
1263: }
1264: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1265: $showfile = $imgfile;
1.6 raeburn 1266: my $imgdir = $1;
1267: my $filename = $2;
1.159 raeburn 1268: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1269: $showfile = "/$imgdir/tn-".$filename;
1270: } else {
1.159 raeburn 1271: my $input = $londocroot.$imgfile;
1272: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1273: if (!-e $output) {
1.9 raeburn 1274: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1275: my ($fullwidth,$fullheight) = &check_dimensions($input);
1276: if ($fullwidth ne '' && $fullheight ne '') {
1277: if ($fullwidth > $width && $fullheight > $height) {
1278: my $size = $width.'x'.$height;
1279: system("convert -sample $size $input $output");
1.159 raeburn 1280: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1281: }
1282: }
1.6 raeburn 1283: }
1284: }
1.16 raeburn 1285: }
1.6 raeburn 1286: if ($showfile) {
1.40 raeburn 1287: if ($showfile =~ m{^/(adm|res)/}) {
1288: if ($showfile =~ m{^/res/}) {
1289: my $local_showfile =
1290: &Apache::lonnet::filelocation('',$showfile);
1291: &Apache::lonnet::repcopy($local_showfile);
1292: }
1293: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1294: }
1295: if ($imgfile) {
1296: if ($imgfile =~ m{^/(adm|res)/}) {
1297: if ($imgfile =~ m{^/res/}) {
1298: my $local_imgfile =
1299: &Apache::lonnet::filelocation('',$imgfile);
1300: &Apache::lonnet::repcopy($local_imgfile);
1301: }
1302: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1303: } else {
1304: $fullsize = $imgfile;
1305: }
1306: }
1.41 raeburn 1307: $datatable .= '<td>';
1308: if ($img eq 'login') {
1.135 bisitz 1309: $datatable .= $login_hdr_pick;
1310: }
1.41 raeburn 1311: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1312: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1313: } else {
1314: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1315: &mt('Upload:');
1316: }
1317: } else {
1318: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1319: &mt('Upload:');
1320: }
1.9 raeburn 1321: if ($switchserver) {
1322: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1323: } else {
1.135 bisitz 1324: if ($img ne 'login') { # suppress file selection for Log-in header
1325: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1326: }
1.9 raeburn 1327: }
1328: $datatable .= '</td></tr>';
1.6 raeburn 1329: }
1330: $itemcount ++;
1331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1332: $datatable .= '<tr'.$css_class.'>'.
1333: '<td>'.$choices->{'bgs'}.'</td>';
1334: my $bgs_def;
1335: foreach my $item (@{$bgs}) {
1336: if (!$is_custom->{$item}) {
1.70 raeburn 1337: $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 1338: }
1339: }
1340: if ($bgs_def) {
1.8 raeburn 1341: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1342: } else {
1343: $datatable .= '<td> </td>';
1344: }
1345: $datatable .= '<td class="LC_right_item">'.
1346: '<table border="0"><tr>';
1.174 foxr 1347:
1348:
1.6 raeburn 1349: foreach my $item (@{$bgs}) {
1.174 foxr 1350: # my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1351: $datatable .= '<td align="center">';
1352: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1353: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1354: $datatable .= ' ';
1.6 raeburn 1355: }
1.174 foxr 1356: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1357: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1358: }
1359: $datatable .= '</tr></table></td></tr>';
1360: $itemcount ++;
1361: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1362: $datatable .= '<tr'.$css_class.'>'.
1363: '<td>'.$choices->{'links'}.'</td>';
1364: my $links_def;
1365: foreach my $item (@{$links}) {
1366: if (!$is_custom->{$item}) {
1.30 raeburn 1367: $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 1368: }
1369: }
1370: if ($links_def) {
1.8 raeburn 1371: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1372: } else {
1373: $datatable .= '<td> </td>';
1374: }
1375: $datatable .= '<td class="LC_right_item">'.
1376: '<table border="0"><tr>';
1377: foreach my $item (@{$links}) {
1.174 foxr 1378: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1379: $datatable .= '<td align="center">'."\n";
1380:
1.6 raeburn 1381: if ($designs->{'links'}{$item}) {
1.174 foxr 1382: $datatable.=' ';
1.6 raeburn 1383: }
1.174 foxr 1384: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1385: '" /></td>';
1386: }
1.30 raeburn 1387: $$rowtotal += $itemcount;
1.3 raeburn 1388: return $datatable;
1389: }
1390:
1.70 raeburn 1391: sub logo_display_options {
1392: my ($img,$defaults,$designs) = @_;
1393: my $checkedon;
1394: if (ref($defaults) eq 'HASH') {
1395: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1396: if ($defaults->{'showlogo'}{$img}) {
1397: $checkedon = 'checked="checked" ';
1398: }
1399: }
1400: }
1401: if (ref($designs) eq 'HASH') {
1402: if (ref($designs->{'showlogo'}) eq 'HASH') {
1403: if (defined($designs->{'showlogo'}{$img})) {
1404: if ($designs->{'showlogo'}{$img} == 0) {
1405: $checkedon = '';
1406: } elsif ($designs->{'showlogo'}{$img} == 1) {
1407: $checkedon = 'checked="checked" ';
1408: }
1409: }
1410: }
1411: }
1412: return '<br /><label> <input type="checkbox" name="'.
1413: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1414: &mt('show').'</label>'."\n";
1415: }
1416:
1.41 raeburn 1417: sub login_header_options {
1.135 bisitz 1418: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1419: my $output = '';
1.41 raeburn 1420: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1421: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1422: if (!$is_custom->{'textcol'}) {
1423: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1424: ' ';
1425: }
1426: if (!$is_custom->{'bgcol'}) {
1427: $output .= $choices->{'bgcol'}.': '.
1428: '<span id="css_'.$role.'_font" style="background-color: '.
1429: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1430: }
1431: $output .= '<br />';
1432: }
1433: $output .='<br />';
1434: return $output;
1435: }
1436:
1437: sub login_text_colors {
1438: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1439: my $color_menu = '<table border="0"><tr>';
1440: foreach my $item (@{$logintext}) {
1441: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1442: $color_menu .= '<td align="center">'.$link;
1443: if ($designs->{'logintext'}{$item}) {
1444: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1445: }
1446: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1447: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1448: '<td> </td>';
1449: }
1450: $color_menu .= '</tr></table><br />';
1451: return $color_menu;
1452: }
1453:
1454: sub image_changes {
1455: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1456: my $output;
1.135 bisitz 1457: if ($img eq 'login') {
1458: # suppress image for Log-in header
1459: } elsif (!$is_custom) {
1.70 raeburn 1460: if ($img ne 'domlogo') {
1.41 raeburn 1461: $output .= &mt('Default image:').'<br />';
1462: } else {
1463: $output .= &mt('Default in use:').'<br />';
1464: }
1465: }
1.135 bisitz 1466: if ($img eq 'login') { # suppress image for Log-in header
1467: $output .= '<td>'.$logincolors;
1.41 raeburn 1468: } else {
1.135 bisitz 1469: if ($img_import) {
1470: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1471: }
1472: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1473: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1474: if ($is_custom) {
1475: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1476: '<input type="checkbox" name="'.
1477: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1478: '</label> '.&mt('Replace:').'</span><br />';
1479: } else {
1480: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1481: }
1.41 raeburn 1482: }
1483: return $output;
1484: }
1485:
1.6 raeburn 1486: sub color_pick {
1487: my ($phase,$role,$item,$desc,$curcol) = @_;
1488: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1489: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1490: ');">'.$desc.'</a>';
1491: return $link;
1492: }
1493:
1.3 raeburn 1494: sub print_quotas {
1.86 raeburn 1495: my ($dom,$settings,$rowtotal,$action) = @_;
1496: my $context;
1497: if ($action eq 'quotas') {
1498: $context = 'tools';
1499: } else {
1500: $context = $action;
1501: }
1.101 raeburn 1502: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1503: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1504: my $typecount = 0;
1.101 raeburn 1505: my ($css_class,%titles);
1.86 raeburn 1506: if ($context eq 'requestcourses') {
1.98 raeburn 1507: @usertools = ('official','unofficial','community');
1.106 raeburn 1508: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1509: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1510: %titles = &courserequest_titles();
1.163 raeburn 1511: } elsif ($context eq 'requestauthor') {
1512: @usertools = ('author');
1513: @options = ('norequest','approval','automatic');
1514: %titles = &authorrequest_titles();
1.86 raeburn 1515: } else {
1.162 raeburn 1516: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1517: %titles = &tool_titles();
1.86 raeburn 1518: }
1.26 raeburn 1519: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1520: foreach my $type (@{$types}) {
1.72 raeburn 1521: my $currdefquota;
1.163 raeburn 1522: unless (($context eq 'requestcourses') ||
1523: ($context eq 'requestauthor')) {
1.86 raeburn 1524: if (ref($settings) eq 'HASH') {
1525: if (ref($settings->{defaultquota}) eq 'HASH') {
1526: $currdefquota = $settings->{defaultquota}->{$type};
1527: } else {
1528: $currdefquota = $settings->{$type};
1529: }
1.78 raeburn 1530: }
1.72 raeburn 1531: }
1.3 raeburn 1532: if (defined($usertypes->{$type})) {
1533: $typecount ++;
1534: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1535: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1536: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1537: '<td class="LC_left_item">';
1.101 raeburn 1538: if ($context eq 'requestcourses') {
1539: $datatable .= '<table><tr>';
1540: }
1541: my %cell;
1.72 raeburn 1542: foreach my $item (@usertools) {
1.101 raeburn 1543: if ($context eq 'requestcourses') {
1544: my ($curroption,$currlimit);
1545: if (ref($settings) eq 'HASH') {
1546: if (ref($settings->{$item}) eq 'HASH') {
1547: $curroption = $settings->{$item}->{$type};
1548: if ($curroption =~ /^autolimit=(\d*)$/) {
1549: $currlimit = $1;
1550: }
1551: }
1552: }
1553: if (!$curroption) {
1554: $curroption = 'norequest';
1555: }
1556: $datatable .= '<th>'.$titles{$item}.'</th>';
1557: foreach my $option (@options) {
1558: my $val = $option;
1559: if ($option eq 'norequest') {
1560: $val = 0;
1561: }
1562: if ($option eq 'validate') {
1563: my $canvalidate = 0;
1564: if (ref($validations{$item}) eq 'HASH') {
1565: if ($validations{$item}{$type}) {
1566: $canvalidate = 1;
1567: }
1568: }
1569: next if (!$canvalidate);
1570: }
1571: my $checked = '';
1572: if ($option eq $curroption) {
1573: $checked = ' checked="checked"';
1574: } elsif ($option eq 'autolimit') {
1575: if ($curroption =~ /^autolimit/) {
1576: $checked = ' checked="checked"';
1577: }
1578: }
1579: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1580: '<input type="radio" name="crsreq_'.$item.
1581: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1582: $titles{$option}.'</label>';
1.101 raeburn 1583: if ($option eq 'autolimit') {
1.127 raeburn 1584: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1585: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1586: 'value="'.$currlimit.'" />';
1.101 raeburn 1587: }
1.127 raeburn 1588: $cell{$item} .= '</span> ';
1.103 raeburn 1589: if ($option eq 'autolimit') {
1.127 raeburn 1590: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1591: }
1.101 raeburn 1592: }
1.163 raeburn 1593: } elsif ($context eq 'requestauthor') {
1594: my $curroption;
1595: if (ref($settings) eq 'HASH') {
1596: $curroption = $settings->{$type};
1597: }
1598: if (!$curroption) {
1599: $curroption = 'norequest';
1600: }
1601: foreach my $option (@options) {
1602: my $val = $option;
1603: if ($option eq 'norequest') {
1604: $val = 0;
1605: }
1606: my $checked = '';
1607: if ($option eq $curroption) {
1608: $checked = ' checked="checked"';
1609: }
1610: $datatable .= '<span class="LC_nobreak"><label>'.
1611: '<input type="radio" name="authorreq_'.$type.
1612: '" value="'.$val.'"'.$checked.' />'.
1613: $titles{$option}.'</label></span> ';
1614: }
1.101 raeburn 1615: } else {
1616: my $checked = 'checked="checked" ';
1617: if (ref($settings) eq 'HASH') {
1618: if (ref($settings->{$item}) eq 'HASH') {
1619: if ($settings->{$item}->{$type} == 0) {
1620: $checked = '';
1621: } elsif ($settings->{$item}->{$type} == 1) {
1622: $checked = 'checked="checked" ';
1623: }
1.78 raeburn 1624: }
1.72 raeburn 1625: }
1.101 raeburn 1626: $datatable .= '<span class="LC_nobreak"><label>'.
1627: '<input type="checkbox" name="'.$context.'_'.$item.
1628: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1629: '</label></span> ';
1.72 raeburn 1630: }
1.101 raeburn 1631: }
1632: if ($context eq 'requestcourses') {
1633: $datatable .= '</tr><tr>';
1634: foreach my $item (@usertools) {
1.106 raeburn 1635: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1636: }
1637: $datatable .= '</tr></table>';
1.72 raeburn 1638: }
1.86 raeburn 1639: $datatable .= '</td>';
1.163 raeburn 1640: unless (($context eq 'requestcourses') ||
1641: ($context eq 'requestauthor')) {
1.86 raeburn 1642: $datatable .=
1643: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1644: '<input type="text" name="quota_'.$type.
1.72 raeburn 1645: '" value="'.$currdefquota.
1.86 raeburn 1646: '" size="5" /> Mb</span></td>';
1647: }
1648: $datatable .= '</tr>';
1.3 raeburn 1649: }
1650: }
1651: }
1.163 raeburn 1652: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1653: $defaultquota = '20';
1654: if (ref($settings) eq 'HASH') {
1655: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1656: $defaultquota = $settings->{'defaultquota'}->{'default'};
1657: } elsif (defined($settings->{'default'})) {
1658: $defaultquota = $settings->{'default'};
1659: }
1.3 raeburn 1660: }
1661: }
1662: $typecount ++;
1663: $css_class = $typecount%2?' class="LC_odd_row"':'';
1664: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1665: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1666: '<td class="LC_left_item">';
1.101 raeburn 1667: if ($context eq 'requestcourses') {
1668: $datatable .= '<table><tr>';
1669: }
1670: my %defcell;
1.72 raeburn 1671: foreach my $item (@usertools) {
1.101 raeburn 1672: if ($context eq 'requestcourses') {
1673: my ($curroption,$currlimit);
1674: if (ref($settings) eq 'HASH') {
1675: if (ref($settings->{$item}) eq 'HASH') {
1676: $curroption = $settings->{$item}->{'default'};
1677: if ($curroption =~ /^autolimit=(\d*)$/) {
1678: $currlimit = $1;
1679: }
1680: }
1681: }
1682: if (!$curroption) {
1683: $curroption = 'norequest';
1684: }
1685: $datatable .= '<th>'.$titles{$item}.'</th>';
1686: foreach my $option (@options) {
1687: my $val = $option;
1688: if ($option eq 'norequest') {
1689: $val = 0;
1690: }
1691: if ($option eq 'validate') {
1692: my $canvalidate = 0;
1693: if (ref($validations{$item}) eq 'HASH') {
1694: if ($validations{$item}{'default'}) {
1695: $canvalidate = 1;
1696: }
1697: }
1698: next if (!$canvalidate);
1699: }
1700: my $checked = '';
1701: if ($option eq $curroption) {
1702: $checked = ' checked="checked"';
1703: } elsif ($option eq 'autolimit') {
1704: if ($curroption =~ /^autolimit/) {
1705: $checked = ' checked="checked"';
1706: }
1707: }
1708: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1709: '<input type="radio" name="crsreq_'.$item.
1710: '_default" value="'.$val.'"'.$checked.' />'.
1711: $titles{$option}.'</label>';
1712: if ($option eq 'autolimit') {
1.127 raeburn 1713: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1714: $item.'_limit_default" size="1" '.
1715: 'value="'.$currlimit.'" />';
1716: }
1.127 raeburn 1717: $defcell{$item} .= '</span> ';
1.104 raeburn 1718: if ($option eq 'autolimit') {
1.127 raeburn 1719: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1720: }
1.101 raeburn 1721: }
1.163 raeburn 1722: } elsif ($context eq 'requestauthor') {
1723: my $curroption;
1724: if (ref($settings) eq 'HASH') {
1.172 raeburn 1725: $curroption = $settings->{'default'};
1.163 raeburn 1726: }
1727: if (!$curroption) {
1728: $curroption = 'norequest';
1729: }
1730: foreach my $option (@options) {
1731: my $val = $option;
1732: if ($option eq 'norequest') {
1733: $val = 0;
1734: }
1735: my $checked = '';
1736: if ($option eq $curroption) {
1737: $checked = ' checked="checked"';
1738: }
1739: $datatable .= '<span class="LC_nobreak"><label>'.
1740: '<input type="radio" name="authorreq_default"'.
1741: ' value="'.$val.'"'.$checked.' />'.
1742: $titles{$option}.'</label></span> ';
1743: }
1.101 raeburn 1744: } else {
1745: my $checked = 'checked="checked" ';
1746: if (ref($settings) eq 'HASH') {
1747: if (ref($settings->{$item}) eq 'HASH') {
1748: if ($settings->{$item}->{'default'} == 0) {
1749: $checked = '';
1750: } elsif ($settings->{$item}->{'default'} == 1) {
1751: $checked = 'checked="checked" ';
1752: }
1.78 raeburn 1753: }
1.72 raeburn 1754: }
1.101 raeburn 1755: $datatable .= '<span class="LC_nobreak"><label>'.
1756: '<input type="checkbox" name="'.$context.'_'.$item.
1757: '" value="default" '.$checked.'/>'.$titles{$item}.
1758: '</label></span> ';
1759: }
1760: }
1761: if ($context eq 'requestcourses') {
1762: $datatable .= '</tr><tr>';
1763: foreach my $item (@usertools) {
1.106 raeburn 1764: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1765: }
1.101 raeburn 1766: $datatable .= '</tr></table>';
1.72 raeburn 1767: }
1.86 raeburn 1768: $datatable .= '</td>';
1.163 raeburn 1769: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1770: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1771: '<input type="text" name="defaultquota" value="'.
1772: $defaultquota.'" size="5" /> Mb</span></td>';
1773: }
1774: $datatable .= '</tr>';
1.72 raeburn 1775: $typecount ++;
1776: $css_class = $typecount%2?' class="LC_odd_row"':'';
1777: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1778: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1779: if ($context eq 'requestcourses') {
1.109 raeburn 1780: $datatable .= &mt('(overrides affiliation, if set)').
1781: '</td>'.
1782: '<td class="LC_left_item">'.
1783: '<table><tr>';
1.101 raeburn 1784: } else {
1.109 raeburn 1785: $datatable .= &mt('(overrides affiliation, if checked)').
1786: '</td>'.
1787: '<td class="LC_left_item" colspan="2">'.
1788: '<br />';
1.101 raeburn 1789: }
1790: my %advcell;
1.72 raeburn 1791: foreach my $item (@usertools) {
1.101 raeburn 1792: if ($context eq 'requestcourses') {
1793: my ($curroption,$currlimit);
1794: if (ref($settings) eq 'HASH') {
1795: if (ref($settings->{$item}) eq 'HASH') {
1796: $curroption = $settings->{$item}->{'_LC_adv'};
1797: if ($curroption =~ /^autolimit=(\d*)$/) {
1798: $currlimit = $1;
1799: }
1800: }
1801: }
1802: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1803: my $checked = '';
1804: if ($curroption eq '') {
1805: $checked = ' checked="checked"';
1806: }
1807: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1808: '<input type="radio" name="crsreq_'.$item.
1809: '__LC_adv" value=""'.$checked.' />'.
1810: &mt('No override set').'</label></span> ';
1.101 raeburn 1811: foreach my $option (@options) {
1812: my $val = $option;
1813: if ($option eq 'norequest') {
1814: $val = 0;
1815: }
1816: if ($option eq 'validate') {
1817: my $canvalidate = 0;
1818: if (ref($validations{$item}) eq 'HASH') {
1819: if ($validations{$item}{'_LC_adv'}) {
1820: $canvalidate = 1;
1821: }
1822: }
1823: next if (!$canvalidate);
1824: }
1825: my $checked = '';
1.104 raeburn 1826: if ($val eq $curroption) {
1.101 raeburn 1827: $checked = ' checked="checked"';
1828: } elsif ($option eq 'autolimit') {
1829: if ($curroption =~ /^autolimit/) {
1830: $checked = ' checked="checked"';
1831: }
1832: }
1833: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1834: '<input type="radio" name="crsreq_'.$item.
1835: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1836: $titles{$option}.'</label>';
1837: if ($option eq 'autolimit') {
1.127 raeburn 1838: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1839: $item.'_limit__LC_adv" size="1" '.
1840: 'value="'.$currlimit.'" />';
1841: }
1.127 raeburn 1842: $advcell{$item} .= '</span> ';
1.104 raeburn 1843: if ($option eq 'autolimit') {
1.127 raeburn 1844: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1845: }
1.101 raeburn 1846: }
1.163 raeburn 1847: } elsif ($context eq 'requestauthor') {
1848: my $curroption;
1849: if (ref($settings) eq 'HASH') {
1850: $curroption = $settings->{'_LC_adv'};
1851: }
1852: my $checked = '';
1853: if ($curroption eq '') {
1854: $checked = ' checked="checked"';
1855: }
1856: $datatable .= '<span class="LC_nobreak"><label>'.
1857: '<input type="radio" name="authorreq__LC_adv"'.
1858: ' value=""'.$checked.' />'.
1859: &mt('No override set').'</label></span> ';
1860: foreach my $option (@options) {
1861: my $val = $option;
1862: if ($option eq 'norequest') {
1863: $val = 0;
1864: }
1865: my $checked = '';
1866: if ($val eq $curroption) {
1867: $checked = ' checked="checked"';
1868: }
1869: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1870: '<input type="radio" name="authorreq__LC_adv"'.
1871: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1872: $titles{$option}.'</label></span> ';
1873: }
1.101 raeburn 1874: } else {
1875: my $checked = 'checked="checked" ';
1876: if (ref($settings) eq 'HASH') {
1877: if (ref($settings->{$item}) eq 'HASH') {
1878: if ($settings->{$item}->{'_LC_adv'} == 0) {
1879: $checked = '';
1880: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1881: $checked = 'checked="checked" ';
1882: }
1.79 raeburn 1883: }
1.72 raeburn 1884: }
1.101 raeburn 1885: $datatable .= '<span class="LC_nobreak"><label>'.
1886: '<input type="checkbox" name="'.$context.'_'.$item.
1887: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1888: '</label></span> ';
1889: }
1890: }
1891: if ($context eq 'requestcourses') {
1892: $datatable .= '</tr><tr>';
1893: foreach my $item (@usertools) {
1.106 raeburn 1894: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1895: }
1.101 raeburn 1896: $datatable .= '</tr></table>';
1.72 raeburn 1897: }
1.98 raeburn 1898: $datatable .= '</td></tr>';
1.30 raeburn 1899: $$rowtotal += $typecount;
1.3 raeburn 1900: return $datatable;
1901: }
1902:
1.163 raeburn 1903: sub print_requestmail {
1904: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1905: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1906: $now = time;
1907: $rows = 0;
1908: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1909: foreach my $server (keys(%dompersonnel)) {
1910: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1911: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1912: if (!grep(/^$uname:$udom$/,@domcoord)) {
1913: push(@domcoord,$uname.':'.$udom);
1914: }
1915: }
1916: }
1917: if (ref($settings) eq 'HASH') {
1918: if (ref($settings->{'notify'}) eq 'HASH') {
1919: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1920: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1921: }
1922: }
1923: }
1.104 raeburn 1924: if (@currapproval) {
1925: foreach my $dc (@currapproval) {
1.102 raeburn 1926: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1927: push(@domcoord,$dc);
1928: }
1929: }
1930: }
1931: @domcoord = sort(@domcoord);
1932: my $numinrow = 4;
1933: my $numdc = @domcoord;
1934: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1935: my $text;
1936: if ($action eq 'requestcourses') {
1937: $text = &mt('Receive notification of course requests requiring approval');
1938: } else {
1939: $text = &mt('Receive notification of authoring space requests requiring approval')
1940: }
1941: $datatable = '<tr '.$css_class.'>'.
1942: ' <td>'.$text.'</td>'.
1.102 raeburn 1943: ' <td class="LC_left_item">';
1944: if (@domcoord > 0) {
1945: $datatable .= '<table>';
1946: for (my $i=0; $i<$numdc; $i++) {
1947: my $rem = $i%($numinrow);
1948: if ($rem == 0) {
1949: if ($i > 0) {
1950: $datatable .= '</tr>';
1951: }
1952: $datatable .= '<tr>';
1953: $rows ++;
1954: }
1955: my $check = ' ';
1.104 raeburn 1956: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1957: $check = ' checked="checked" ';
1958: }
1959: my ($uname,$udom) = split(':',$domcoord[$i]);
1960: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1961: if ($i == $numdc-1) {
1962: my $colsleft = $numinrow-$rem;
1963: if ($colsleft > 1) {
1964: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1965: } else {
1966: $datatable .= '<td class="LC_left_item">';
1967: }
1968: } else {
1969: $datatable .= '<td class="LC_left_item">';
1970: }
1971: $datatable .= '<span class="LC_nobreak"><label>'.
1972: '<input type="checkbox" name="reqapprovalnotify" '.
1973: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 bisitz 1974: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 1975: }
1976: $datatable .= '</tr></table>';
1977: } else {
1978: $datatable .= &mt('There are no active Domain Coordinators');
1979: $rows ++;
1980: }
1981: $datatable .='</td></tr>';
1982: $$rowtotal += $rows;
1983: return $datatable;
1984: }
1985:
1.3 raeburn 1986: sub print_autoenroll {
1.30 raeburn 1987: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1988: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1989: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1990: if (ref($settings) eq 'HASH') {
1991: if (exists($settings->{'run'})) {
1992: if ($settings->{'run'} eq '0') {
1993: $runoff = ' checked="checked" ';
1994: $runon = ' ';
1995: } else {
1996: $runon = ' checked="checked" ';
1997: $runoff = ' ';
1998: }
1999: } else {
2000: if ($autorun) {
2001: $runon = ' checked="checked" ';
2002: $runoff = ' ';
2003: } else {
2004: $runoff = ' checked="checked" ';
2005: $runon = ' ';
2006: }
2007: }
1.129 raeburn 2008: if (exists($settings->{'co-owners'})) {
2009: if ($settings->{'co-owners'} eq '0') {
2010: $coownersoff = ' checked="checked" ';
2011: $coownerson = ' ';
2012: } else {
2013: $coownerson = ' checked="checked" ';
2014: $coownersoff = ' ';
2015: }
2016: } else {
2017: $coownersoff = ' checked="checked" ';
2018: $coownerson = ' ';
2019: }
1.3 raeburn 2020: if (exists($settings->{'sender_domain'})) {
2021: $defdom = $settings->{'sender_domain'};
2022: }
1.14 raeburn 2023: } else {
2024: if ($autorun) {
2025: $runon = ' checked="checked" ';
2026: $runoff = ' ';
2027: } else {
2028: $runoff = ' checked="checked" ';
2029: $runon = ' ';
2030: }
1.3 raeburn 2031: }
2032: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2033: my $notif_sender;
2034: if (ref($settings) eq 'HASH') {
2035: $notif_sender = $settings->{'sender_uname'};
2036: }
1.3 raeburn 2037: my $datatable='<tr class="LC_odd_row">'.
2038: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2039: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2040: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2041: $runon.' value="1" />'.&mt('Yes').'</label> '.
2042: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2043: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2044: '</tr><tr>'.
2045: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2046: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2047: &mt('username').': '.
2048: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2049: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2050: ': '.$domform.'</span></td></tr>'.
2051: '<tr class="LC_odd_row">'.
2052: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2053: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2054: '<input type="radio" name="autoassign_coowners"'.
2055: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2056: '<label><input type="radio" name="autoassign_coowners"'.
2057: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2058: '</tr>';
2059: $$rowtotal += 3;
1.3 raeburn 2060: return $datatable;
2061: }
2062:
2063: sub print_autoupdate {
1.30 raeburn 2064: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2065: my $datatable;
2066: if ($position eq 'top') {
2067: my $updateon = ' ';
2068: my $updateoff = ' checked="checked" ';
2069: my $classlistson = ' ';
2070: my $classlistsoff = ' checked="checked" ';
2071: if (ref($settings) eq 'HASH') {
2072: if ($settings->{'run'} eq '1') {
2073: $updateon = $updateoff;
2074: $updateoff = ' ';
2075: }
2076: if ($settings->{'classlists'} eq '1') {
2077: $classlistson = $classlistsoff;
2078: $classlistsoff = ' ';
2079: }
2080: }
2081: my %title = (
2082: run => 'Auto-update active?',
2083: classlists => 'Update information in classlists?',
2084: );
2085: $datatable = '<tr class="LC_odd_row">'.
2086: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2087: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2088: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2089: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2090: '<label><input type="radio" name="autoupdate_run"'.
2091: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2092: '</tr><tr>'.
2093: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2094: '<td class="LC_right_item"><span class="LC_nobreak">'.
2095: '<label><input type="radio" name="classlists"'.
2096: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2097: '<label><input type="radio" name="classlists"'.
2098: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2099: '</tr>';
1.30 raeburn 2100: $$rowtotal += 2;
1.131 raeburn 2101: } elsif ($position eq 'middle') {
2102: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2103: my $numinrow = 3;
2104: my $locknamesettings;
2105: $datatable .= &insttypes_row($settings,$types,$usertypes,
2106: $dom,$numinrow,$othertitle,
2107: 'lockablenames');
2108: $$rowtotal ++;
1.3 raeburn 2109: } else {
1.44 raeburn 2110: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2111: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2112: 'permanentemail','id');
1.33 raeburn 2113: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2114: my $numrows = 0;
1.26 raeburn 2115: if (ref($types) eq 'ARRAY') {
2116: if (@{$types} > 0) {
2117: $datatable =
2118: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2119: \@fields,$types,\$numrows);
1.30 raeburn 2120: $$rowtotal += @{$types};
1.26 raeburn 2121: }
1.3 raeburn 2122: }
2123: $datatable .=
2124: &usertype_update_row($settings,{'default' => $othertitle},
2125: \%fieldtitles,\@fields,['default'],
2126: \$numrows);
1.30 raeburn 2127: $$rowtotal ++;
1.3 raeburn 2128: }
2129: return $datatable;
2130: }
2131:
1.125 raeburn 2132: sub print_autocreate {
2133: my ($dom,$settings,$rowtotal) = @_;
2134: my (%createon,%createoff);
2135: my $curr_dc;
2136: my @types = ('xml','req');
2137: if (ref($settings) eq 'HASH') {
2138: foreach my $item (@types) {
2139: $createoff{$item} = ' checked="checked" ';
2140: $createon{$item} = ' ';
2141: if (exists($settings->{$item})) {
2142: if ($settings->{$item}) {
2143: $createon{$item} = ' checked="checked" ';
2144: $createoff{$item} = ' ';
2145: }
2146: }
2147: }
2148: $curr_dc = $settings->{'xmldc'};
2149: } else {
2150: foreach my $item (@types) {
2151: $createoff{$item} = ' checked="checked" ';
2152: $createon{$item} = ' ';
2153: }
2154: }
2155: $$rowtotal += 2;
2156: my $datatable='<tr class="LC_odd_row">'.
2157: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2158: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2159: '<input type="radio" name="autocreate_xml"'.
2160: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2161: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2162: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2163: '</td></tr><tr>'.
2164: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2165: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2166: '<input type="radio" name="autocreate_req"'.
2167: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2168: '<label><input type="radio" name="autocreate_req"'.
2169: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2170: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2171: if ($numdc > 1) {
1.143 raeburn 2172: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2173: &mt('Course creation processed as: (choose Dom. Coord.)').
2174: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2175: $$rowtotal ++ ;
2176: } else {
1.143 raeburn 2177: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2178: }
2179: return $datatable;
2180: }
2181:
1.23 raeburn 2182: sub print_directorysrch {
1.30 raeburn 2183: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2184: my $srchon = ' ';
2185: my $srchoff = ' checked="checked" ';
1.25 raeburn 2186: my ($exacton,$containson,$beginson);
1.24 raeburn 2187: my $localon = ' ';
2188: my $localoff = ' checked="checked" ';
1.23 raeburn 2189: if (ref($settings) eq 'HASH') {
2190: if ($settings->{'available'} eq '1') {
2191: $srchon = $srchoff;
2192: $srchoff = ' ';
2193: }
1.24 raeburn 2194: if ($settings->{'localonly'} eq '1') {
2195: $localon = $localoff;
2196: $localoff = ' ';
2197: }
1.25 raeburn 2198: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2199: foreach my $type (@{$settings->{'searchtypes'}}) {
2200: if ($type eq 'exact') {
2201: $exacton = ' checked="checked" ';
2202: } elsif ($type eq 'contains') {
2203: $containson = ' checked="checked" ';
2204: } elsif ($type eq 'begins') {
2205: $beginson = ' checked="checked" ';
2206: }
2207: }
2208: } else {
2209: if ($settings->{'searchtypes'} eq 'exact') {
2210: $exacton = ' checked="checked" ';
2211: } elsif ($settings->{'searchtypes'} eq 'contains') {
2212: $containson = ' checked="checked" ';
2213: } elsif ($settings->{'searchtypes'} eq 'specify') {
2214: $exacton = ' checked="checked" ';
2215: $containson = ' checked="checked" ';
2216: }
1.23 raeburn 2217: }
2218: }
2219: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2220: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2221:
2222: my $numinrow = 4;
1.26 raeburn 2223: my $cansrchrow = 0;
1.23 raeburn 2224: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2225: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2226: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2227: '<input type="radio" name="dirsrch_available"'.
2228: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2229: '<label><input type="radio" name="dirsrch_available"'.
2230: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2231: '</tr><tr>'.
1.30 raeburn 2232: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2233: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2234: '<input type="radio" name="dirsrch_localonly"'.
2235: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2236: '<label><input type="radio" name="dirsrch_localonly"'.
2237: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2238: '</tr>';
1.30 raeburn 2239: $$rowtotal += 2;
1.26 raeburn 2240: if (ref($usertypes) eq 'HASH') {
2241: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2242: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2243: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2244: $cansrchrow = 1;
2245: }
2246: }
2247: if ($cansrchrow) {
1.30 raeburn 2248: $$rowtotal ++;
1.26 raeburn 2249: $datatable .= '<tr>';
2250: } else {
2251: $datatable .= '<tr class="LC_odd_row">';
2252: }
1.30 raeburn 2253: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2254: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2255: foreach my $title (@{$titleorder}) {
2256: if (defined($searchtitles->{$title})) {
2257: my $check = ' ';
1.93 raeburn 2258: if (ref($settings) eq 'HASH') {
1.39 raeburn 2259: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2260: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2261: $check = ' checked="checked" ';
2262: }
1.25 raeburn 2263: }
2264: }
2265: $datatable .= '<td class="LC_left_item">'.
2266: '<span class="LC_nobreak"><label>'.
2267: '<input type="checkbox" name="searchby" '.
2268: 'value="'.$title.'"'.$check.'/>'.
2269: $searchtitles->{$title}.'</label></span></td>';
2270: }
2271: }
1.26 raeburn 2272: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2273: $$rowtotal ++;
1.26 raeburn 2274: if ($cansrchrow) {
2275: $datatable .= '<tr class="LC_odd_row">';
2276: } else {
2277: $datatable .= '<tr>';
2278: }
1.30 raeburn 2279: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2280: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2281: '<span class="LC_nobreak"><label>'.
2282: '<input type="checkbox" name="searchtypes" '.
2283: $exacton.' value="exact" />'.&mt('Exact match').
2284: '</label> '.
2285: '<label><input type="checkbox" name="searchtypes" '.
2286: $beginson.' value="begins" />'.&mt('Begins with').
2287: '</label> '.
2288: '<label><input type="checkbox" name="searchtypes" '.
2289: $containson.' value="contains" />'.&mt('Contains').
2290: '</label></span></td></tr>';
1.30 raeburn 2291: $$rowtotal ++;
1.25 raeburn 2292: return $datatable;
2293: }
2294:
1.28 raeburn 2295: sub print_contacts {
1.30 raeburn 2296: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2297: my $datatable;
2298: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2299: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2300: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2301: 'requestsmail');
1.28 raeburn 2302: foreach my $type (@mailings) {
2303: $otheremails{$type} = '';
2304: }
1.134 raeburn 2305: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2306: if (ref($settings) eq 'HASH') {
2307: foreach my $item (@contacts) {
2308: if (exists($settings->{$item})) {
2309: $to{$item} = $settings->{$item};
2310: }
2311: }
2312: foreach my $type (@mailings) {
2313: if (exists($settings->{$type})) {
2314: if (ref($settings->{$type}) eq 'HASH') {
2315: foreach my $item (@contacts) {
2316: if ($settings->{$type}{$item}) {
2317: $checked{$type}{$item} = ' checked="checked" ';
2318: }
2319: }
2320: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2321: if ($type eq 'helpdeskmail') {
2322: $bccemails{$type} = $settings->{$type}{'bcc'};
2323: }
1.28 raeburn 2324: }
1.89 raeburn 2325: } elsif ($type eq 'lonstatusmail') {
2326: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2327: }
2328: }
2329: } else {
2330: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2331: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2332: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2333: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2334: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2335: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2336: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2337: }
2338: my ($titles,$short_titles) = &contact_titles();
2339: my $rownum = 0;
2340: my $css_class;
2341: foreach my $item (@contacts) {
1.69 raeburn 2342: $rownum ++;
2343: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2344: $datatable .= '<tr'.$css_class.'>'.
2345: '<td><span class="LC_nobreak">'.$titles->{$item}.
2346: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2347: '<input type="text" name="'.$item.'" value="'.
2348: $to{$item}.'" /></td></tr>';
2349: }
2350: foreach my $type (@mailings) {
1.69 raeburn 2351: $rownum ++;
2352: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2353: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2354: '<td><span class="LC_nobreak">'.
2355: $titles->{$type}.': </span></td>'.
1.28 raeburn 2356: '<td class="LC_left_item">'.
2357: '<span class="LC_nobreak">';
2358: foreach my $item (@contacts) {
2359: $datatable .= '<label>'.
2360: '<input type="checkbox" name="'.$type.'"'.
2361: $checked{$type}{$item}.
2362: ' value="'.$item.'" />'.$short_titles->{$item}.
2363: '</label> ';
2364: }
2365: $datatable .= '</span><br />'.&mt('Others').': '.
2366: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2367: 'value="'.$otheremails{$type}.'" />';
2368: if ($type eq 'helpdeskmail') {
1.136 raeburn 2369: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2370: '<input type="text" name="'.$type.'_bcc" '.
2371: 'value="'.$bccemails{$type}.'" />';
2372: }
2373: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2374: }
1.30 raeburn 2375: $$rowtotal += $rownum;
1.28 raeburn 2376: return $datatable;
2377: }
2378:
1.118 jms 2379: sub print_helpsettings {
1.168 raeburn 2380: my ($dom,$confname,$settings,$rowtotal) = @_;
2381: my ($datatable,$itemcount);
1.166 raeburn 2382: $itemcount = 1;
1.168 raeburn 2383: my (%choices,%defaultchecked,@toggles);
2384: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2385: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2386: &mt('LON-CAPA bug tracker'),600,500));
2387: %defaultchecked = ('submitbugs' => 'on');
2388: @toggles = ('submitbugs',);
1.166 raeburn 2389:
1.168 raeburn 2390: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2391: \%choices,$itemcount);
1.166 raeburn 2392: return $datatable;
1.121 raeburn 2393: }
2394:
2395: sub radiobutton_prefs {
2396: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2397: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2398: (ref($choices) eq 'HASH'));
2399:
1.170 raeburn 2400: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2401:
2402: foreach my $item (@{$toggles}) {
2403: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2404: $checkedon{$item} = ' checked="checked" ';
2405: $checkedoff{$item} = ' ';
1.121 raeburn 2406: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2407: $checkedoff{$item} = ' checked="checked" ';
2408: $checkedon{$item} = ' ';
2409: }
2410: }
2411: if (ref($settings) eq 'HASH') {
1.121 raeburn 2412: foreach my $item (@{$toggles}) {
1.118 jms 2413: if ($settings->{$item} eq '1') {
2414: $checkedon{$item} = ' checked="checked" ';
2415: $checkedoff{$item} = ' ';
2416: } elsif ($settings->{$item} eq '0') {
2417: $checkedoff{$item} = ' checked="checked" ';
2418: $checkedon{$item} = ' ';
2419: }
2420: }
1.121 raeburn 2421: }
2422: foreach my $item (@{$toggles}) {
1.118 jms 2423: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2424: $datatable .=
2425: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2426: '</span></td>'.
2427: '<td class="LC_right_item"><span class="LC_nobreak">'.
2428: '<label><input type="radio" name="'.
2429: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2430: '</label> <label><input type="radio" name="'.$item.'" '.
2431: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2432: '</span></td>'.
2433: '</tr>';
2434: $itemcount ++;
1.121 raeburn 2435: }
2436: return ($datatable,$itemcount);
2437: }
2438:
2439: sub print_coursedefaults {
1.139 raeburn 2440: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2441: my ($css_class,$datatable);
2442: my $itemcount = 1;
1.139 raeburn 2443: if ($position eq 'top') {
2444: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2445: %choices =
2446: &Apache::lonlocal::texthash (
2447: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2448: );
2449: %defaultchecked = ('canuse_pdfforms' => 'off');
2450: @toggles = ('canuse_pdfforms',);
2451: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2452: \%choices,$itemcount);
1.139 raeburn 2453: $$rowtotal += $itemcount;
2454: } else {
2455: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2456: my %choices =
2457: &Apache::lonlocal::texthash (
2458: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2459: );
2460: my $currdefresponder;
2461: if (ref($settings) eq 'HASH') {
2462: $currdefresponder = $settings->{'anonsurvey_threshold'};
2463: }
2464: if (!$currdefresponder) {
2465: $currdefresponder = 10;
2466: } elsif ($currdefresponder < 1) {
2467: $currdefresponder = 1;
2468: }
2469: $datatable .=
2470: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2471: '</span></td>'.
2472: '<td class="LC_right_item"><span class="LC_nobreak">'.
2473: '<input type="text" name="anonsurvey_threshold"'.
2474: ' value="'.$currdefresponder.'" size="5" /></span>'.
2475: '</td></tr>';
2476: }
1.121 raeburn 2477: return $datatable;
1.118 jms 2478: }
2479:
1.137 raeburn 2480: sub print_usersessions {
2481: my ($position,$dom,$settings,$rowtotal) = @_;
2482: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2483: my (%by_ip,%by_location,@intdoms);
2484: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2485:
2486: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2487: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2488: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2489: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2490: my $itemcount = 1;
2491: if ($position eq 'top') {
1.152 raeburn 2492: if (keys(%serverhomes) > 1) {
1.145 raeburn 2493: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2494: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2495: } else {
1.140 raeburn 2496: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2497: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2498: }
1.137 raeburn 2499: } else {
1.145 raeburn 2500: if (keys(%by_location) == 0) {
2501: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2502: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2503: } else {
2504: my %lt = &usersession_titles();
2505: my $numinrow = 5;
2506: my $prefix;
2507: my @types;
2508: if ($position eq 'bottom') {
2509: $prefix = 'remote';
2510: @types = ('version','excludedomain','includedomain');
2511: } else {
2512: $prefix = 'hosted';
2513: @types = ('excludedomain','includedomain');
2514: }
2515: my (%current,%checkedon,%checkedoff);
2516: my @lcversions = &Apache::lonnet::all_loncaparevs();
2517: my @locations = sort(keys(%by_location));
2518: foreach my $type (@types) {
2519: $checkedon{$type} = '';
2520: $checkedoff{$type} = ' checked="checked"';
2521: }
2522: if (ref($settings) eq 'HASH') {
2523: if (ref($settings->{$prefix}) eq 'HASH') {
2524: foreach my $key (keys(%{$settings->{$prefix}})) {
2525: $current{$key} = $settings->{$prefix}{$key};
2526: if ($key eq 'version') {
2527: if ($current{$key} ne '') {
2528: $checkedon{$key} = ' checked="checked"';
2529: $checkedoff{$key} = '';
2530: }
2531: } elsif (ref($current{$key}) eq 'ARRAY') {
2532: $checkedon{$key} = ' checked="checked"';
2533: $checkedoff{$key} = '';
2534: }
1.137 raeburn 2535: }
2536: }
2537: }
1.145 raeburn 2538: foreach my $type (@types) {
2539: next if ($type ne 'version' && !@locations);
2540: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2541: $datatable .= '<tr'.$css_class.'>
2542: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2543: <span class="LC_nobreak">
2544: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2545: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2546: if ($type eq 'version') {
2547: my $selector = '<select name="'.$prefix.'_version">';
2548: foreach my $version (@lcversions) {
2549: my $selected = '';
2550: if ($current{'version'} eq $version) {
2551: $selected = ' selected="selected"';
2552: }
2553: $selector .= ' <option value="'.$version.'"'.
2554: $selected.'>'.$version.'</option>';
2555: }
2556: $selector .= '</select> ';
2557: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2558: } else {
2559: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2560: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2561: ' />'.(' 'x2).
2562: '<input type="button" value="'.&mt('uncheck all').'" '.
2563: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2564: "\n".
2565: '</div><div><table>';
2566: my $rem;
2567: for (my $i=0; $i<@locations; $i++) {
2568: my ($showloc,$value,$checkedtype);
2569: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2570: my $ip = $by_location{$locations[$i]}->[0];
2571: if (ref($by_ip{$ip}) eq 'ARRAY') {
2572: $value = join(':',@{$by_ip{$ip}});
2573: $showloc = join(', ',@{$by_ip{$ip}});
2574: if (ref($current{$type}) eq 'ARRAY') {
2575: foreach my $loc (@{$by_ip{$ip}}) {
2576: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2577: $checkedtype = ' checked="checked"';
2578: last;
2579: }
2580: }
1.138 raeburn 2581: }
2582: }
2583: }
1.145 raeburn 2584: $rem = $i%($numinrow);
2585: if ($rem == 0) {
2586: if ($i > 0) {
2587: $datatable .= '</tr>';
2588: }
2589: $datatable .= '<tr>';
2590: }
2591: $datatable .= '<td class="LC_left_item">'.
2592: '<span class="LC_nobreak"><label>'.
2593: '<input type="checkbox" name="'.$prefix.'_'.$type.
2594: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2595: '</label></span></td>';
1.137 raeburn 2596: }
1.145 raeburn 2597: $rem = @locations%($numinrow);
2598: my $colsleft = $numinrow - $rem;
2599: if ($colsleft > 1 ) {
2600: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2601: ' </td>';
2602: } elsif ($colsleft == 1) {
2603: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2604: }
1.145 raeburn 2605: $datatable .= '</tr></table>';
1.137 raeburn 2606: }
1.145 raeburn 2607: $datatable .= '</td></tr>';
2608: $itemcount ++;
1.137 raeburn 2609: }
2610: }
2611: }
2612: $$rowtotal += $itemcount;
2613: return $datatable;
2614: }
2615:
1.138 raeburn 2616: sub build_location_hashes {
2617: my ($intdoms,$by_ip,$by_location) = @_;
2618: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2619: (ref($by_location) eq 'HASH'));
2620: my %iphost = &Apache::lonnet::get_iphost();
2621: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2622: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2623: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2624: foreach my $id (@{$iphost{$primary_ip}}) {
2625: my $intdom = &Apache::lonnet::internet_dom($id);
2626: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2627: push(@{$intdoms},$intdom);
2628: }
2629: }
2630: }
2631: foreach my $ip (keys(%iphost)) {
2632: if (ref($iphost{$ip}) eq 'ARRAY') {
2633: foreach my $id (@{$iphost{$ip}}) {
2634: my $location = &Apache::lonnet::internet_dom($id);
2635: if ($location) {
2636: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2637: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2638: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2639: push(@{$by_ip->{$ip}},$location);
2640: }
2641: } else {
2642: $by_ip->{$ip} = [$location];
2643: }
2644: }
2645: }
2646: }
2647: }
2648: foreach my $ip (sort(keys(%{$by_ip}))) {
2649: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2650: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2651: my $first = $by_ip->{$ip}->[0];
2652: if (ref($by_location->{$first}) eq 'ARRAY') {
2653: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2654: push(@{$by_location->{$first}},$ip);
2655: }
2656: } else {
2657: $by_location->{$first} = [$ip];
2658: }
2659: }
2660: }
2661: return;
2662: }
2663:
1.145 raeburn 2664: sub current_offloads_to {
2665: my ($dom,$settings,$servers) = @_;
2666: my (%spareid,%otherdomconfigs);
1.152 raeburn 2667: if (ref($servers) eq 'HASH') {
1.145 raeburn 2668: foreach my $lonhost (sort(keys(%{$servers}))) {
2669: my $gotspares;
1.152 raeburn 2670: if (ref($settings) eq 'HASH') {
2671: if (ref($settings->{'spares'}) eq 'HASH') {
2672: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2673: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2674: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2675: $gotspares = 1;
2676: }
1.145 raeburn 2677: }
2678: }
2679: unless ($gotspares) {
2680: my $gotspares;
2681: my $serverhomeID =
2682: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2683: my $serverhomedom =
2684: &Apache::lonnet::host_domain($serverhomeID);
2685: if ($serverhomedom ne $dom) {
2686: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2687: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2688: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2689: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2690: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2691: $gotspares = 1;
2692: }
2693: }
2694: } else {
2695: $otherdomconfigs{$serverhomedom} =
2696: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2697: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2698: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2699: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2700: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2701: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2702: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2703: $gotspares = 1;
2704: }
2705: }
2706: }
2707: }
2708: }
2709: }
2710: }
2711: unless ($gotspares) {
2712: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2713: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2714: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2715: } else {
2716: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2717: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2718: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2719: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2720: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2721: } else {
1.150 raeburn 2722: my %what = (
2723: spareid => 1,
2724: );
2725: my ($result,$returnhash) =
2726: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2727: if ($result eq 'ok') {
2728: if (ref($returnhash) eq 'HASH') {
2729: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2730: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2731: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2732: }
2733: }
1.145 raeburn 2734: }
2735: }
2736: }
2737: }
2738: }
2739: }
2740: return %spareid;
2741: }
2742:
2743: sub spares_row {
1.152 raeburn 2744: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2745: my $css_class;
2746: my $numinrow = 4;
2747: my $itemcount = 1;
2748: my $datatable;
1.152 raeburn 2749: my %typetitles = &sparestype_titles();
2750: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2751: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2752: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2753: my ($othercontrol,$serverdom);
2754: if ($serverhome ne $server) {
2755: $serverdom = &Apache::lonnet::host_domain($serverhome);
2756: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2757: } else {
2758: $serverdom = &Apache::lonnet::host_domain($server);
2759: if ($serverdom ne $dom) {
2760: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2761: }
2762: }
2763: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2764: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2765: $datatable .= '<tr'.$css_class.'>
2766: <td rowspan="2">
1.152 raeburn 2767: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2768: my (%current,%canselect);
1.152 raeburn 2769: my @choices =
2770: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2771: foreach my $type ('primary','default') {
2772: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2773: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2774: my @spares = @{$spareid->{$server}{$type}};
2775: if (@spares > 0) {
1.152 raeburn 2776: if ($othercontrol) {
2777: $current{$type} = join(', ',@spares);
2778: } else {
2779: $current{$type} .= '<table>';
2780: my $numspares = scalar(@spares);
2781: for (my $i=0; $i<@spares; $i++) {
2782: my $rem = $i%($numinrow);
2783: if ($rem == 0) {
2784: if ($i > 0) {
2785: $current{$type} .= '</tr>';
2786: }
2787: $current{$type} .= '<tr>';
1.145 raeburn 2788: }
1.152 raeburn 2789: $current{$type} .= '<td><label><input type="checkbox" name="spare_'.$type.'_'.$server.'" id="spare_'.$type.'_'.$server.'_'.$i.'" checked="checked" value="'.$spareid->{$server}{$type}[$i].'" onclick="updateNewSpares(this.form,'."'$server'".');" /> '.
2790: $spareid->{$server}{$type}[$i].
2791: '</label></td>'."\n";
2792: }
2793: my $rem = @spares%($numinrow);
2794: my $colsleft = $numinrow - $rem;
2795: if ($colsleft > 1 ) {
2796: $current{$type} .= '<td colspan="'.$colsleft.
2797: '" class="LC_left_item">'.
2798: ' </td>';
2799: } elsif ($colsleft == 1) {
2800: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2801: }
1.152 raeburn 2802: $current{$type} .= '</tr></table>';
1.150 raeburn 2803: }
1.145 raeburn 2804: }
2805: }
2806: if ($current{$type} eq '') {
2807: $current{$type} = &mt('None specified');
2808: }
1.152 raeburn 2809: if ($othercontrol) {
2810: if ($type eq 'primary') {
2811: $canselect{$type} = $othercontrol;
2812: }
2813: } else {
2814: $canselect{$type} =
2815: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2816: '<select name="newspare_'.$type.'_'.$server.'" '.
2817: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2818: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2819: if (@choices > 0) {
2820: foreach my $lonhost (@choices) {
2821: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2822: }
2823: }
2824: $canselect{$type} .= '</select>'."\n";
2825: }
2826: } else {
2827: $current{$type} = &mt('Could not be determined');
2828: if ($type eq 'primary') {
2829: $canselect{$type} = $othercontrol;
2830: }
1.145 raeburn 2831: }
1.152 raeburn 2832: if ($type eq 'default') {
2833: $datatable .= '<tr'.$css_class.'>';
2834: }
2835: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2836: '<td>'.$current{$type}.'</td>'."\n".
2837: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2838: }
2839: $itemcount ++;
2840: }
2841: }
2842: $$rowtotal += $itemcount;
2843: return $datatable;
2844: }
2845:
1.152 raeburn 2846: sub possible_newspares {
2847: my ($server,$currspares,$serverhomes,$altids) = @_;
2848: my $serverhostname = &Apache::lonnet::hostname($server);
2849: my %excluded;
2850: if ($serverhostname ne '') {
2851: %excluded = (
2852: $serverhostname => 1,
2853: );
2854: }
2855: if (ref($currspares) eq 'HASH') {
2856: foreach my $type (keys(%{$currspares})) {
2857: if (ref($currspares->{$type}) eq 'ARRAY') {
2858: if (@{$currspares->{$type}} > 0) {
2859: foreach my $curr (@{$currspares->{$type}}) {
2860: my $hostname = &Apache::lonnet::hostname($curr);
2861: $excluded{$hostname} = 1;
2862: }
2863: }
2864: }
2865: }
2866: }
2867: my @choices;
2868: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2869: if (keys(%{$serverhomes}) > 1) {
2870: foreach my $name (sort(keys(%{$serverhomes}))) {
2871: unless ($excluded{$name}) {
2872: if (exists($altids->{$serverhomes->{$name}})) {
2873: push(@choices,$altids->{$serverhomes->{$name}});
2874: } else {
2875: push(@choices,$serverhomes->{$name});
1.145 raeburn 2876: }
2877: }
2878: }
2879: }
2880: }
1.152 raeburn 2881: return sort(@choices);
1.145 raeburn 2882: }
2883:
1.150 raeburn 2884: sub print_loadbalancing {
2885: my ($dom,$settings,$rowtotal) = @_;
2886: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2887: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2888: my $numinrow = 1;
2889: my $datatable;
2890: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2891: my (%currbalancer,%currtargets,%currrules,%existing);
2892: if (ref($settings) eq 'HASH') {
2893: %existing = %{$settings};
2894: }
2895: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2896: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2897: \%currtargets,\%currrules);
1.150 raeburn 2898: } else {
2899: return;
2900: }
2901: my ($othertitle,$usertypes,$types) =
2902: &Apache::loncommon::sorted_inst_types($dom);
2903: my $rownum = 6;
2904: if (ref($types) eq 'ARRAY') {
2905: $rownum += scalar(@{$types});
2906: }
1.171 raeburn 2907: my @css_class = ('LC_odd_row','LC_even_row');
2908: my $balnum = 0;
2909: my $islast;
2910: my (@toshow,$disabledtext);
2911: if (keys(%currbalancer) > 0) {
2912: @toshow = sort(keys(%currbalancer));
2913: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2914: push(@toshow,'');
2915: }
2916: } else {
2917: @toshow = ('');
2918: $disabledtext = &mt('No existing load balancer');
2919: }
2920: foreach my $lonhost (@toshow) {
2921: if ($balnum == scalar(@toshow)-1) {
2922: $islast = 1;
2923: } else {
2924: $islast = 0;
2925: }
2926: my $cssidx = $balnum%2;
2927: my $targets_div_style = 'display: none';
2928: my $disabled_div_style = 'display: block';
2929: my $homedom_div_style = 'display: none';
2930: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2931: '<td rowspan="'.$rownum.'" valign="top">'.
2932: '<p>';
2933: if ($lonhost eq '') {
2934: $datatable .= '<span class="LC_nobreak">';
2935: if (keys(%currbalancer) > 0) {
2936: $datatable .= &mt('Add balancer:');
2937: } else {
2938: $datatable .= &mt('Enable balancer:');
2939: }
2940: $datatable .= ' '.
2941: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2942: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2943: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2944: '<option value="" selected="selected">'.&mt('None').
2945: '</option>'."\n";
2946: foreach my $server (sort(keys(%servers))) {
2947: next if ($currbalancer{$server});
2948: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2949: }
2950: $datatable .=
2951: '</select>'."\n".
2952: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2953: } else {
2954: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2955: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2956: &mt('Stop balancing').'</label>'.
2957: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2958: $targets_div_style = 'display: block';
2959: $disabled_div_style = 'display: none';
2960: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2961: $homedom_div_style = 'display: block';
2962: }
2963: }
2964: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2965: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2966: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2967: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2968: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2969: my @sparestypes = ('primary','default');
2970: my %typetitles = &sparestype_titles();
2971: foreach my $sparetype (@sparestypes) {
2972: my $targettable;
2973: for (my $i=0; $i<$numspares; $i++) {
2974: my $checked;
2975: if (ref($currtargets{$lonhost}) eq 'HASH') {
2976: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2977: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2978: $checked = ' checked="checked"';
2979: }
2980: }
2981: }
2982: my ($chkboxval,$disabled);
2983: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
2984: $chkboxval = $spares[$i];
2985: }
2986: if (exists($currbalancer{$spares[$i]})) {
2987: $disabled = ' disabled="disabled"';
2988: }
2989: $targettable .=
2990: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
2991: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2992: '</span></label></td>';
2993: my $rem = $i%($numinrow);
2994: if ($rem == 0) {
2995: if (($i > 0) && ($i < $numspares-1)) {
2996: $targettable .= '</tr>';
2997: }
2998: if ($i < $numspares-1) {
2999: $targettable .= '<tr>';
1.150 raeburn 3000: }
3001: }
3002: }
1.171 raeburn 3003: if ($targettable ne '') {
3004: my $rem = $numspares%($numinrow);
3005: my $colsleft = $numinrow - $rem;
3006: if ($colsleft > 1 ) {
3007: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3008: ' </td>';
3009: } elsif ($colsleft == 1) {
3010: $targettable .= '<td class="LC_left_item"> </td>';
3011: }
3012: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3013: '<table><tr>'.$targettable.'</tr></table><br />';
3014: }
3015: }
3016: my $cssidx = $balnum%2;
3017: $datatable .= '</div></td></tr>'.
3018: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3019: $othertitle,$usertypes,$types,\%servers,
3020: \%currbalancer,$lonhost,
3021: $targets_div_style,$homedom_div_style,
3022: $css_class[$cssidx],$balnum,$islast);
3023: $$rowtotal += $rownum;
3024: $balnum ++;
3025: }
3026: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3027: return $datatable;
3028: }
3029:
3030: sub get_loadbalancers_config {
3031: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3032: return unless ((ref($servers) eq 'HASH') &&
3033: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3034: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3035: if (keys(%{$existing}) > 0) {
3036: my $oldlonhost;
3037: foreach my $key (sort(keys(%{$existing}))) {
3038: if ($key eq 'lonhost') {
3039: $oldlonhost = $existing->{'lonhost'};
3040: $currbalancer->{$oldlonhost} = 1;
3041: } elsif ($key eq 'targets') {
3042: if ($oldlonhost) {
3043: $currtargets->{$oldlonhost} = $existing->{'targets'};
3044: }
3045: } elsif ($key eq 'rules') {
3046: if ($oldlonhost) {
3047: $currrules->{$oldlonhost} = $existing->{'rules'};
3048: }
3049: } elsif (ref($existing->{$key}) eq 'HASH') {
3050: $currbalancer->{$key} = 1;
3051: $currtargets->{$key} = $existing->{$key}{'targets'};
3052: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3053: }
3054: }
1.171 raeburn 3055: } else {
3056: my ($balancerref,$targetsref) =
3057: &Apache::lonnet::get_lonbalancer_config($servers);
3058: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3059: foreach my $server (sort(keys(%{$balancerref}))) {
3060: $currbalancer->{$server} = 1;
3061: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3062: }
3063: }
3064: }
1.171 raeburn 3065: return;
1.150 raeburn 3066: }
3067:
3068: sub loadbalancing_rules {
3069: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3070: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3071: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3072: my $output;
1.171 raeburn 3073: my $num = 0;
1.150 raeburn 3074: my ($alltypes,$othertypes,$titles) =
3075: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3076: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3077: foreach my $type (@{$alltypes}) {
1.171 raeburn 3078: $num ++;
1.150 raeburn 3079: my $current;
3080: if (ref($currrules) eq 'HASH') {
3081: $current = $currrules->{$type};
3082: }
3083: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3084: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3085: $current = '';
3086: }
3087: }
3088: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3089: $servers,$currbalancer,$lonhost,$dom,
3090: $targets_div_style,$homedom_div_style,
3091: $css_class,$balnum,$num,$islast);
1.150 raeburn 3092: }
3093: }
3094: return $output;
3095: }
3096:
3097: sub loadbalancing_titles {
3098: my ($dom,$intdom,$usertypes,$types) = @_;
3099: my %othertypes = (
3100: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3101: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3102: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3103: '_LC_external' => &mt('Users not from [_1]',$intdom),
3104: );
3105: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3106: if (ref($types) eq 'ARRAY') {
3107: unshift(@alltypes,@{$types},'default');
3108: }
3109: my %titles;
3110: foreach my $type (@alltypes) {
3111: if ($type =~ /^_LC_/) {
3112: $titles{$type} = $othertypes{$type};
3113: } elsif ($type eq 'default') {
3114: $titles{$type} = &mt('All users from [_1]',$dom);
3115: if (ref($types) eq 'ARRAY') {
3116: if (@{$types} > 0) {
3117: $titles{$type} = &mt('Other users from [_1]',$dom);
3118: }
3119: }
3120: } elsif (ref($usertypes) eq 'HASH') {
3121: $titles{$type} = $usertypes->{$type};
3122: }
3123: }
3124: return (\@alltypes,\%othertypes,\%titles);
3125: }
3126:
3127: sub loadbalance_rule_row {
1.171 raeburn 3128: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3129: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3130: my @rulenames = ('default','homeserver');
3131: my %ruletitles = &offloadtype_text();
3132: if ($type eq '_LC_external') {
3133: push(@rulenames,'externalbalancer');
3134: } else {
3135: push(@rulenames,'specific');
3136: }
1.161 raeburn 3137: push(@rulenames,'none');
1.150 raeburn 3138: my $style = $targets_div_style;
3139: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3140: $style = $homedom_div_style;
3141: }
1.171 raeburn 3142: my $space;
3143: if ($islast && $num == 1) {
3144: $space = '<div display="inline-block"> </div>';
3145: }
1.150 raeburn 3146: my $output =
1.171 raeburn 3147: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3148: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3149: '<td valaign="top">'.$space.
3150: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3151: for (my $i=0; $i<@rulenames; $i++) {
3152: my $rule = $rulenames[$i];
3153: my ($checked,$extra);
3154: if ($rulenames[$i] eq 'default') {
3155: $rule = '';
3156: }
3157: if ($rulenames[$i] eq 'specific') {
3158: if (ref($servers) eq 'HASH') {
3159: my $default;
3160: if (($current ne '') && (exists($servers->{$current}))) {
3161: $checked = ' checked="checked"';
3162: }
3163: unless ($checked) {
3164: $default = ' selected="selected"';
3165: }
1.171 raeburn 3166: $extra =
3167: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3168: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3169: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3170: '<option value=""'.$default.'></option>'."\n";
3171: foreach my $server (sort(keys(%{$servers}))) {
3172: if (ref($currbalancer) eq 'HASH') {
3173: next if (exists($currbalancer->{$server}));
3174: }
1.150 raeburn 3175: my $selected;
1.171 raeburn 3176: if ($server eq $current) {
1.150 raeburn 3177: $selected = ' selected="selected"';
3178: }
1.171 raeburn 3179: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3180: }
3181: $extra .= '</select>';
3182: }
3183: } elsif ($rule eq $current) {
3184: $checked = ' checked="checked"';
3185: }
3186: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3187: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3188: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3189: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3190: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3191: '</label>'.$extra.'</span><br />'."\n";
3192: }
3193: $output .= '</div></td></tr>'."\n";
3194: return $output;
3195: }
3196:
3197: sub offloadtype_text {
3198: my %ruletitles = &Apache::lonlocal::texthash (
3199: 'default' => 'Offloads to default destinations',
3200: 'homeserver' => "Offloads to user's home server",
3201: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3202: 'specific' => 'Offloads to specific server',
1.161 raeburn 3203: 'none' => 'No offload',
1.150 raeburn 3204: );
3205: return %ruletitles;
3206: }
3207:
3208: sub sparestype_titles {
3209: my %typestitles = &Apache::lonlocal::texthash (
3210: 'primary' => 'primary',
3211: 'default' => 'default',
3212: );
3213: return %typestitles;
3214: }
3215:
1.28 raeburn 3216: sub contact_titles {
3217: my %titles = &Apache::lonlocal::texthash (
3218: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3219: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3220: 'errormail' => 'Error reports to be e-mailed to',
3221: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3222: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3223: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3224: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3225: );
3226: my %short_titles = &Apache::lonlocal::texthash (
3227: adminemail => 'Admin E-mail address',
3228: supportemail => 'Support E-mail',
3229: );
3230: return (\%titles,\%short_titles);
3231: }
3232:
1.72 raeburn 3233: sub tool_titles {
3234: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3235: aboutme => 'Personal web page',
1.86 raeburn 3236: blog => 'Blog',
1.162 raeburn 3237: webdav => 'WebDAV',
1.86 raeburn 3238: portfolio => 'Portfolio',
1.88 bisitz 3239: official => 'Official courses (with institutional codes)',
3240: unofficial => 'Unofficial courses',
1.98 raeburn 3241: community => 'Communities',
1.86 raeburn 3242: );
1.72 raeburn 3243: return %titles;
3244: }
3245:
1.101 raeburn 3246: sub courserequest_titles {
3247: my %titles = &Apache::lonlocal::texthash (
3248: official => 'Official',
3249: unofficial => 'Unofficial',
3250: community => 'Communities',
3251: norequest => 'Not allowed',
1.104 raeburn 3252: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3253: validate => 'With validation',
3254: autolimit => 'Numerical limit',
1.103 raeburn 3255: unlimited => '(blank for unlimited)',
1.101 raeburn 3256: );
3257: return %titles;
3258: }
3259:
1.163 raeburn 3260: sub authorrequest_titles {
3261: my %titles = &Apache::lonlocal::texthash (
3262: norequest => 'Not allowed',
3263: approval => 'Approval by Dom. Coord.',
3264: automatic => 'Automatic approval',
3265: );
3266: return %titles;
3267: }
3268:
1.101 raeburn 3269: sub courserequest_conditions {
3270: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3271: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3272: validate => '(Processing of request subject to instittutional validation).',
3273: );
3274: return %conditions;
3275: }
3276:
3277:
1.27 raeburn 3278: sub print_usercreation {
1.30 raeburn 3279: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3280: my $numinrow = 4;
1.28 raeburn 3281: my $datatable;
3282: if ($position eq 'top') {
1.30 raeburn 3283: $$rowtotal ++;
1.34 raeburn 3284: my $rowcount = 0;
1.32 raeburn 3285: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3286: if (ref($rules) eq 'HASH') {
3287: if (keys(%{$rules}) > 0) {
1.32 raeburn 3288: $datatable .= &user_formats_row('username',$settings,$rules,
3289: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3290: $$rowtotal ++;
1.32 raeburn 3291: $rowcount ++;
3292: }
3293: }
3294: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3295: if (ref($idrules) eq 'HASH') {
3296: if (keys(%{$idrules}) > 0) {
3297: $datatable .= &user_formats_row('id',$settings,$idrules,
3298: $idruleorder,$numinrow,$rowcount);
3299: $$rowtotal ++;
3300: $rowcount ++;
1.28 raeburn 3301: }
3302: }
1.43 raeburn 3303: my ($emailrules,$emailruleorder) =
3304: &Apache::lonnet::inst_userrules($dom,'email');
3305: if (ref($emailrules) eq 'HASH') {
3306: if (keys(%{$emailrules}) > 0) {
3307: $datatable .= &user_formats_row('email',$settings,$emailrules,
3308: $emailruleorder,$numinrow,$rowcount);
3309: $$rowtotal ++;
3310: $rowcount ++;
3311: }
3312: }
1.39 raeburn 3313: if ($rowcount == 0) {
3314: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3315: $$rowtotal ++;
3316: $rowcount ++;
3317: }
1.34 raeburn 3318: } elsif ($position eq 'middle') {
1.100 raeburn 3319: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3320: my ($rules,$ruleorder) =
3321: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3322: my %lt = &usercreation_types();
3323: my %checked;
1.50 raeburn 3324: my @selfcreate;
1.34 raeburn 3325: if (ref($settings) eq 'HASH') {
3326: if (ref($settings->{'cancreate'}) eq 'HASH') {
3327: foreach my $item (@creators) {
3328: $checked{$item} = $settings->{'cancreate'}{$item};
3329: }
1.50 raeburn 3330: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3331: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3332: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3333: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3334: @selfcreate = ('email','login','sso');
3335: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3336: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3337: }
3338: }
1.34 raeburn 3339: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3340: foreach my $item (@creators) {
3341: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3342: $checked{$item} = 'none';
3343: }
3344: }
3345: }
3346: }
3347: my $rownum = 0;
3348: foreach my $item (@creators) {
3349: $rownum ++;
1.50 raeburn 3350: if ($item ne 'selfcreate') {
3351: if ($checked{$item} eq '') {
1.43 raeburn 3352: $checked{$item} = 'any';
3353: }
1.34 raeburn 3354: }
3355: my $css_class;
3356: if ($rownum%2) {
3357: $css_class = '';
3358: } else {
3359: $css_class = ' class="LC_odd_row" ';
3360: }
3361: $datatable .= '<tr'.$css_class.'>'.
3362: '<td><span class="LC_nobreak">'.$lt{$item}.
3363: '</span></td><td align="right">';
1.50 raeburn 3364: my @options;
1.45 raeburn 3365: if ($item eq 'selfcreate') {
1.43 raeburn 3366: push(@options,('email','login','sso'));
3367: } else {
1.50 raeburn 3368: @options = ('any');
1.43 raeburn 3369: if (ref($rules) eq 'HASH') {
3370: if (keys(%{$rules}) > 0) {
3371: push(@options,('official','unofficial'));
3372: }
1.37 raeburn 3373: }
1.50 raeburn 3374: push(@options,'none');
1.37 raeburn 3375: }
3376: foreach my $option (@options) {
1.50 raeburn 3377: my $type = 'radio';
1.34 raeburn 3378: my $check = ' ';
1.50 raeburn 3379: if ($item eq 'selfcreate') {
3380: $type = 'checkbox';
3381: if (grep(/^\Q$option\E$/,@selfcreate)) {
3382: $check = ' checked="checked" ';
3383: }
3384: } else {
3385: if ($checked{$item} eq $option) {
3386: $check = ' checked="checked" ';
3387: }
1.34 raeburn 3388: }
3389: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3390: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3391: $item.'" value="'.$option.'"'.$check.'/> '.
3392: $lt{$option}.'</label> </span>';
3393: }
3394: $datatable .= '</td></tr>';
3395: }
1.93 raeburn 3396: my ($othertitle,$usertypes,$types) =
3397: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3398: my $createsettings;
3399: if (ref($settings) eq 'HASH') {
3400: $createsettings = $settings->{cancreate};
3401: }
1.93 raeburn 3402: if (ref($usertypes) eq 'HASH') {
3403: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3404: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3405: $dom,$numinrow,$othertitle,
3406: 'statustocreate');
3407: $$rowtotal ++;
1.169 raeburn 3408: $rownum ++;
1.93 raeburn 3409: }
3410: }
1.169 raeburn 3411: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3412: } else {
3413: my @contexts = ('author','course','domain');
3414: my @authtypes = ('int','krb4','krb5','loc');
3415: my %checked;
3416: if (ref($settings) eq 'HASH') {
3417: if (ref($settings->{'authtypes'}) eq 'HASH') {
3418: foreach my $item (@contexts) {
3419: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3420: foreach my $auth (@authtypes) {
3421: if ($settings->{'authtypes'}{$item}{$auth}) {
3422: $checked{$item}{$auth} = ' checked="checked" ';
3423: }
3424: }
3425: }
3426: }
1.27 raeburn 3427: }
1.35 raeburn 3428: } else {
3429: foreach my $item (@contexts) {
1.36 raeburn 3430: foreach my $auth (@authtypes) {
1.35 raeburn 3431: $checked{$item}{$auth} = ' checked="checked" ';
3432: }
3433: }
1.27 raeburn 3434: }
1.28 raeburn 3435: my %title = &context_names();
3436: my %authname = &authtype_names();
3437: my $rownum = 0;
3438: my $css_class;
3439: foreach my $item (@contexts) {
3440: if ($rownum%2) {
3441: $css_class = '';
3442: } else {
3443: $css_class = ' class="LC_odd_row" ';
3444: }
1.30 raeburn 3445: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3446: '<td>'.$title{$item}.
3447: '</td><td class="LC_left_item">'.
3448: '<span class="LC_nobreak">';
3449: foreach my $auth (@authtypes) {
3450: $datatable .= '<label>'.
3451: '<input type="checkbox" name="'.$item.'_auth" '.
3452: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3453: $authname{$auth}.'</label> ';
3454: }
3455: $datatable .= '</span></td></tr>';
3456: $rownum ++;
1.27 raeburn 3457: }
1.30 raeburn 3458: $$rowtotal += $rownum;
1.27 raeburn 3459: }
3460: return $datatable;
3461: }
3462:
1.165 raeburn 3463: sub captcha_choice {
1.169 raeburn 3464: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3465: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3466: my %lt = &captcha_phrases();
3467: $keyentry = 'hidden';
3468: if ($context eq 'cancreate') {
3469: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3470: } elsif ($context eq 'login') {
3471: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3472: }
3473: if (ref($settings) eq 'HASH') {
3474: if ($settings->{'captcha'}) {
3475: $checked{$settings->{'captcha'}} = ' checked="checked"';
3476: } else {
3477: $checked{'original'} = ' checked="checked"';
3478: }
3479: if ($settings->{'captcha'} eq 'recaptcha') {
3480: $pubtext = $lt{'pub'};
3481: $privtext = $lt{'priv'};
3482: $keyentry = 'text';
3483: }
3484: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3485: $currpub = $settings->{'recaptchakeys'}{'public'};
3486: $currpriv = $settings->{'recaptchakeys'}{'private'};
3487: }
3488: } else {
3489: $checked{'original'} = ' checked="checked"';
3490: }
1.169 raeburn 3491: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3492: my $output = '<tr'.$css_class.'>'.
3493: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3494: '<table><tr><td>'."\n";
3495: foreach my $option ('original','recaptcha','notused') {
3496: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3497: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3498: $lt{$option}.'</label></span>';
3499: unless ($option eq 'notused') {
3500: $output .= (' 'x2)."\n";
3501: }
3502: }
3503: #
3504: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3505: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3506: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3507: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3508: #
3509: $output .= '</td></tr>'."\n".
3510: '<tr><td>'."\n".
3511: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3512: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3513: $currpub.'" size="40" /></span><br />'."\n".
3514: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3515: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3516: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3517: '</td></tr>';
3518: return $output;
3519: }
3520:
1.32 raeburn 3521: sub user_formats_row {
3522: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3523: my $output;
3524: my %text = (
3525: 'username' => 'new usernames',
3526: 'id' => 'IDs',
1.45 raeburn 3527: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3528: );
3529: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3530: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3531: '<td><span class="LC_nobreak">';
3532: if ($type eq 'email') {
3533: $output .= &mt("Formats disallowed for $text{$type}: ");
3534: } else {
3535: $output .= &mt("Format rules to check for $text{$type}: ");
3536: }
3537: $output .= '</span></td>'.
3538: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3539: my $rem;
3540: if (ref($ruleorder) eq 'ARRAY') {
3541: for (my $i=0; $i<@{$ruleorder}; $i++) {
3542: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3543: my $rem = $i%($numinrow);
3544: if ($rem == 0) {
3545: if ($i > 0) {
3546: $output .= '</tr>';
3547: }
3548: $output .= '<tr>';
3549: }
3550: my $check = ' ';
1.39 raeburn 3551: if (ref($settings) eq 'HASH') {
3552: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3553: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3554: $check = ' checked="checked" ';
3555: }
1.27 raeburn 3556: }
3557: }
3558: $output .= '<td class="LC_left_item">'.
3559: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3560: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3561: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3562: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3563: }
3564: }
3565: $rem = @{$ruleorder}%($numinrow);
3566: }
3567: my $colsleft = $numinrow - $rem;
3568: if ($colsleft > 1 ) {
3569: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3570: ' </td>';
3571: } elsif ($colsleft == 1) {
3572: $output .= '<td class="LC_left_item"> </td>';
3573: }
3574: $output .= '</tr></table></td></tr>';
3575: return $output;
3576: }
3577:
1.34 raeburn 3578: sub usercreation_types {
3579: my %lt = &Apache::lonlocal::texthash (
3580: author => 'When adding a co-author',
3581: course => 'When adding a user to a course',
1.100 raeburn 3582: requestcrs => 'When requesting a course',
1.45 raeburn 3583: selfcreate => 'User creates own account',
1.34 raeburn 3584: any => 'Any',
3585: official => 'Institutional only ',
3586: unofficial => 'Non-institutional only',
1.85 schafran 3587: email => 'E-mail address',
1.43 raeburn 3588: login => 'Institutional Login',
3589: sso => 'SSO',
1.34 raeburn 3590: none => 'None',
3591: );
3592: return %lt;
1.48 raeburn 3593: }
1.34 raeburn 3594:
1.28 raeburn 3595: sub authtype_names {
3596: my %lt = &Apache::lonlocal::texthash(
3597: int => 'Internal',
3598: krb4 => 'Kerberos 4',
3599: krb5 => 'Kerberos 5',
3600: loc => 'Local',
3601: );
3602: return %lt;
3603: }
3604:
3605: sub context_names {
3606: my %context_title = &Apache::lonlocal::texthash(
3607: author => 'Creating users when an Author',
3608: course => 'Creating users when in a course',
3609: domain => 'Creating users when a Domain Coordinator',
3610: );
3611: return %context_title;
3612: }
3613:
1.33 raeburn 3614: sub print_usermodification {
3615: my ($position,$dom,$settings,$rowtotal) = @_;
3616: my $numinrow = 4;
3617: my ($context,$datatable,$rowcount);
3618: if ($position eq 'top') {
3619: $rowcount = 0;
3620: $context = 'author';
3621: foreach my $role ('ca','aa') {
3622: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3623: $numinrow,$rowcount);
3624: $$rowtotal ++;
3625: $rowcount ++;
3626: }
1.63 raeburn 3627: } elsif ($position eq 'middle') {
1.33 raeburn 3628: $context = 'course';
3629: $rowcount = 0;
3630: foreach my $role ('st','ep','ta','in','cr') {
3631: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3632: $numinrow,$rowcount);
3633: $$rowtotal ++;
3634: $rowcount ++;
3635: }
1.63 raeburn 3636: } elsif ($position eq 'bottom') {
3637: $context = 'selfcreate';
3638: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3639: $usertypes->{'default'} = $othertitle;
3640: if (ref($types) eq 'ARRAY') {
3641: push(@{$types},'default');
3642: $usertypes->{'default'} = $othertitle;
3643: foreach my $status (@{$types}) {
3644: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3645: $numinrow,$rowcount,$usertypes);
3646: $$rowtotal ++;
3647: $rowcount ++;
3648: }
3649: }
1.33 raeburn 3650: }
3651: return $datatable;
3652: }
3653:
1.43 raeburn 3654: sub print_defaults {
3655: my ($dom,$rowtotal) = @_;
1.68 raeburn 3656: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3657: 'datelocale_def','portal_def');
1.43 raeburn 3658: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3659: my $titles = &defaults_titles($dom);
1.43 raeburn 3660: my $rownum = 0;
3661: my ($datatable,$css_class);
3662: foreach my $item (@items) {
3663: if ($rownum%2) {
3664: $css_class = '';
3665: } else {
3666: $css_class = ' class="LC_odd_row" ';
3667: }
3668: $datatable .= '<tr'.$css_class.'>'.
3669: '<td><span class="LC_nobreak">'.$titles->{$item}.
3670: '</span></td><td class="LC_right_item">';
3671: if ($item eq 'auth_def') {
3672: my @authtypes = ('internal','krb4','krb5','localauth');
3673: my %shortauth = (
3674: internal => 'int',
3675: krb4 => 'krb4',
3676: krb5 => 'krb5',
3677: localauth => 'loc'
3678: );
3679: my %authnames = &authtype_names();
3680: foreach my $auth (@authtypes) {
3681: my $checked = ' ';
3682: if ($domdefaults{$item} eq $auth) {
3683: $checked = ' checked="checked" ';
3684: }
3685: $datatable .= '<label><input type="radio" name="'.$item.
3686: '" value="'.$auth.'"'.$checked.'/>'.
3687: $authnames{$shortauth{$auth}}.'</label> ';
3688: }
1.54 raeburn 3689: } elsif ($item eq 'timezone_def') {
3690: my $includeempty = 1;
3691: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3692: } elsif ($item eq 'datelocale_def') {
3693: my $includeempty = 1;
3694: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3695: } elsif ($item eq 'lang_def') {
1.168 raeburn 3696: my %langchoices = &get_languages_hash();
3697: $langchoices{''} = 'No language preference';
1.167 raeburn 3698: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3699: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3700: \%langchoices);
1.43 raeburn 3701: } else {
1.141 raeburn 3702: my $size;
3703: if ($item eq 'portal_def') {
3704: $size = ' size="25"';
3705: }
1.43 raeburn 3706: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3707: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3708: }
3709: $datatable .= '</td></tr>';
3710: $rownum ++;
3711: }
3712: $$rowtotal += $rownum;
3713: return $datatable;
3714: }
3715:
1.168 raeburn 3716: sub get_languages_hash {
3717: my %langchoices;
3718: foreach my $id (&Apache::loncommon::languageids()) {
3719: my $code = &Apache::loncommon::supportedlanguagecode($id);
3720: if ($code ne '') {
3721: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3722: }
3723: }
3724: return %langchoices;
3725: }
3726:
1.43 raeburn 3727: sub defaults_titles {
1.141 raeburn 3728: my ($dom) = @_;
1.43 raeburn 3729: my %titles = &Apache::lonlocal::texthash (
3730: 'auth_def' => 'Default authentication type',
3731: 'auth_arg_def' => 'Default authentication argument',
3732: 'lang_def' => 'Default language',
1.54 raeburn 3733: 'timezone_def' => 'Default timezone',
1.68 raeburn 3734: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3735: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3736: );
1.141 raeburn 3737: if ($dom) {
3738: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3739: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3740: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3741: $protocol = 'http' if ($protocol ne 'https');
3742: if ($uint_dom) {
3743: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3744: $uint_dom);
3745: }
3746: }
1.43 raeburn 3747: return (\%titles);
3748: }
3749:
1.46 raeburn 3750: sub print_scantronformat {
3751: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3752: my $itemcount = 1;
1.60 raeburn 3753: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3754: %confhash);
1.46 raeburn 3755: my $switchserver = &check_switchserver($dom,$confname);
3756: my %lt = &Apache::lonlocal::texthash (
1.95 www 3757: default => 'Default bubblesheet format file error',
3758: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3759: );
3760: my %scantronfiles = (
3761: default => 'default.tab',
3762: custom => 'custom.tab',
3763: );
3764: foreach my $key (keys(%scantronfiles)) {
3765: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3766: .$scantronfiles{$key};
3767: }
3768: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3769: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3770: if (!$switchserver) {
3771: my $servadm = $r->dir_config('lonAdmEMail');
3772: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3773: if ($configuserok eq 'ok') {
3774: if ($author_ok eq 'ok') {
3775: my %legacyfile = (
3776: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3777: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3778: );
3779: my %md5chk;
3780: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3781: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3782: chomp($md5chk{$type});
1.46 raeburn 3783: }
3784: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3785: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3786: ($scantronurls{$type},my $error) =
1.46 raeburn 3787: &legacy_scantronformat($r,$dom,$confname,
3788: $type,$legacyfile{$type},
3789: $scantronurls{$type},
3790: $scantronfiles{$type});
1.60 raeburn 3791: if ($error ne '') {
3792: $error{$type} = $error;
3793: }
3794: }
3795: if (keys(%error) == 0) {
3796: $is_custom = 1;
3797: $confhash{'scantron'}{'scantronformat'} =
3798: $scantronurls{'custom'};
3799: my $putresult =
3800: &Apache::lonnet::put_dom('configuration',
3801: \%confhash,$dom);
3802: if ($putresult ne 'ok') {
3803: $error{'custom'} =
3804: '<span class="LC_error">'.
3805: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3806: }
1.46 raeburn 3807: }
3808: } else {
1.60 raeburn 3809: ($scantronurls{'default'},my $error) =
1.46 raeburn 3810: &legacy_scantronformat($r,$dom,$confname,
3811: 'default',$legacyfile{'default'},
3812: $scantronurls{'default'},
3813: $scantronfiles{'default'});
1.60 raeburn 3814: if ($error eq '') {
3815: $confhash{'scantron'}{'scantronformat'} = '';
3816: my $putresult =
3817: &Apache::lonnet::put_dom('configuration',
3818: \%confhash,$dom);
3819: if ($putresult ne 'ok') {
3820: $error{'default'} =
3821: '<span class="LC_error">'.
3822: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3823: }
3824: } else {
3825: $error{'default'} = $error;
3826: }
1.46 raeburn 3827: }
3828: }
3829: }
3830: } else {
1.95 www 3831: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3832: }
3833: }
3834: if (ref($settings) eq 'HASH') {
3835: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3836: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3837: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3838: $scantronurl = '';
3839: } else {
3840: $scantronurl = $settings->{'scantronformat'};
3841: }
3842: $is_custom = 1;
3843: } else {
3844: $scantronurl = $scantronurls{'default'};
3845: }
3846: } else {
1.60 raeburn 3847: if ($is_custom) {
3848: $scantronurl = $scantronurls{'custom'};
3849: } else {
3850: $scantronurl = $scantronurls{'default'};
3851: }
1.46 raeburn 3852: }
3853: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3854: $datatable .= '<tr'.$css_class.'>';
3855: if (!$is_custom) {
1.65 raeburn 3856: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3857: '<span class="LC_nobreak">';
1.46 raeburn 3858: if ($scantronurl) {
3859: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3860: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3861: } else {
3862: $datatable = &mt('File unavailable for display');
3863: }
1.65 raeburn 3864: $datatable .= '</span></td>';
1.60 raeburn 3865: if (keys(%error) == 0) {
3866: $datatable .= '<td valign="bottom">';
3867: if (!$switchserver) {
3868: $datatable .= &mt('Upload:').'<br />';
3869: }
3870: } else {
3871: my $errorstr;
3872: foreach my $key (sort(keys(%error))) {
3873: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3874: }
3875: $datatable .= '<td>'.$errorstr;
3876: }
1.46 raeburn 3877: } else {
3878: if (keys(%error) > 0) {
3879: my $errorstr;
3880: foreach my $key (sort(keys(%error))) {
3881: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3882: }
1.60 raeburn 3883: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3884: } elsif ($scantronurl) {
1.65 raeburn 3885: $datatable .= '<td><span class="LC_nobreak">'.
3886: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3887: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3888: '<input type="checkbox" name="scantronformat_del"'.
3889: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3890: '<td><span class="LC_nobreak"> '.
3891: &mt('Replace:').'</span><br />';
1.46 raeburn 3892: }
3893: }
3894: if (keys(%error) == 0) {
3895: if ($switchserver) {
3896: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3897: } else {
1.65 raeburn 3898: $datatable .='<span class="LC_nobreak"> '.
3899: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3900: }
3901: }
3902: $datatable .= '</td></tr>';
3903: $$rowtotal ++;
3904: return $datatable;
3905: }
3906:
3907: sub legacy_scantronformat {
3908: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3909: my ($url,$error);
3910: my @statinfo = &Apache::lonnet::stat_file($newurl);
3911: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3912: (my $result,$url) =
3913: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3914: '','',$newfile);
3915: if ($result ne 'ok') {
1.130 raeburn 3916: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3917: }
3918: }
3919: return ($url,$error);
3920: }
1.43 raeburn 3921:
1.49 raeburn 3922: sub print_coursecategories {
1.57 raeburn 3923: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3924: my $datatable;
3925: if ($position eq 'top') {
3926: my $toggle_cats_crs = ' ';
3927: my $toggle_cats_dom = ' checked="checked" ';
3928: my $can_cat_crs = ' ';
3929: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3930: my $toggle_catscomm_comm = ' ';
3931: my $toggle_catscomm_dom = ' checked="checked" ';
3932: my $can_catcomm_comm = ' ';
3933: my $can_catcomm_dom = ' checked="checked" ';
3934:
1.57 raeburn 3935: if (ref($settings) eq 'HASH') {
3936: if ($settings->{'togglecats'} eq 'crs') {
3937: $toggle_cats_crs = $toggle_cats_dom;
3938: $toggle_cats_dom = ' ';
3939: }
3940: if ($settings->{'categorize'} eq 'crs') {
3941: $can_cat_crs = $can_cat_dom;
3942: $can_cat_dom = ' ';
3943: }
1.120 raeburn 3944: if ($settings->{'togglecatscomm'} eq 'comm') {
3945: $toggle_catscomm_comm = $toggle_catscomm_dom;
3946: $toggle_catscomm_dom = ' ';
3947: }
3948: if ($settings->{'categorizecomm'} eq 'comm') {
3949: $can_catcomm_comm = $can_catcomm_dom;
3950: $can_catcomm_dom = ' ';
3951: }
1.57 raeburn 3952: }
3953: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3954: togglecats => 'Show/Hide a course in catalog',
3955: togglecatscomm => 'Show/Hide a community in catalog',
3956: categorize => 'Assign a category to a course',
3957: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3958: );
3959: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3960: dom => 'Set in Domain',
3961: crs => 'Set in Course',
3962: comm => 'Set in Community',
1.57 raeburn 3963: );
3964: $datatable = '<tr class="LC_odd_row">'.
3965: '<td>'.$title{'togglecats'}.'</td>'.
3966: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3967: '<input type="radio" name="togglecats"'.
3968: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3969: '<label><input type="radio" name="togglecats"'.
3970: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3971: '</tr><tr>'.
3972: '<td>'.$title{'categorize'}.'</td>'.
3973: '<td class="LC_right_item"><span class="LC_nobreak">'.
3974: '<label><input type="radio" name="categorize"'.
3975: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3976: '<label><input type="radio" name="categorize"'.
3977: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3978: '</tr><tr class="LC_odd_row">'.
3979: '<td>'.$title{'togglecatscomm'}.'</td>'.
3980: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3981: '<input type="radio" name="togglecatscomm"'.
3982: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3983: '<label><input type="radio" name="togglecatscomm"'.
3984: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3985: '</tr><tr>'.
3986: '<td>'.$title{'categorizecomm'}.'</td>'.
3987: '<td class="LC_right_item"><span class="LC_nobreak">'.
3988: '<label><input type="radio" name="categorizecomm"'.
3989: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3990: '<label><input type="radio" name="categorizecomm"'.
3991: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3992: '</tr>';
1.120 raeburn 3993: $$rowtotal += 4;
1.57 raeburn 3994: } else {
3995: my $css_class;
3996: my $itemcount = 1;
3997: my $cathash;
3998: if (ref($settings) eq 'HASH') {
3999: $cathash = $settings->{'cats'};
4000: }
4001: if (ref($cathash) eq 'HASH') {
4002: my (@cats,@trails,%allitems,%idx,@jsarray);
4003: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4004: \%allitems,\%idx,\@jsarray);
4005: my $maxdepth = scalar(@cats);
4006: my $colattrib = '';
4007: if ($maxdepth > 2) {
4008: $colattrib = ' colspan="2" ';
4009: }
4010: my @path;
4011: if (@cats > 0) {
4012: if (ref($cats[0]) eq 'ARRAY') {
4013: my $numtop = @{$cats[0]};
4014: my $maxnum = $numtop;
1.120 raeburn 4015: my %default_names = (
4016: instcode => &mt('Official courses'),
4017: communities => &mt('Communities'),
4018: );
4019:
4020: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4021: ($cathash->{'instcode::0'} eq '') ||
4022: (!grep(/^communities$/,@{$cats[0]})) ||
4023: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4024: $maxnum ++;
4025: }
4026: my $lastidx;
4027: for (my $i=0; $i<$numtop; $i++) {
4028: my $parent = $cats[0][$i];
4029: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4030: my $item = &escape($parent).'::0';
4031: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4032: $lastidx = $idx{$item};
4033: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4034: .'<select name="'.$item.'"'.$chgstr.'>';
4035: for (my $k=0; $k<=$maxnum; $k++) {
4036: my $vpos = $k+1;
4037: my $selstr;
4038: if ($k == $i) {
4039: $selstr = ' selected="selected" ';
4040: }
4041: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4042: }
4043: $datatable .= '</select></td><td>';
1.120 raeburn 4044: if ($parent eq 'instcode' || $parent eq 'communities') {
4045: $datatable .= '<span class="LC_nobreak">'
4046: .$default_names{$parent}.'</span>';
4047: if ($parent eq 'instcode') {
4048: $datatable .= '<br /><span class="LC_nobreak">('
4049: .&mt('with institutional codes')
4050: .')</span></td><td'.$colattrib.'>';
4051: } else {
4052: $datatable .= '<table><tr><td>';
4053: }
4054: $datatable .= '<span class="LC_nobreak">'
4055: .'<label><input type="radio" name="'
4056: .$parent.'" value="1" checked="checked" />'
4057: .&mt('Display').'</label>';
4058: if ($parent eq 'instcode') {
4059: $datatable .= ' ';
4060: } else {
4061: $datatable .= '</span></td></tr><tr><td>'
4062: .'<span class="LC_nobreak">';
4063: }
4064: $datatable .= '<label><input type="radio" name="'
4065: .$parent.'" value="0" />'
4066: .&mt('Do not display').'</label></span>';
4067: if ($parent eq 'communities') {
4068: $datatable .= '</td></tr></table>';
4069: }
4070: $datatable .= '</td>';
1.57 raeburn 4071: } else {
4072: $datatable .= $parent
4073: .' <label><input type="checkbox" name="deletecategory" '
4074: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4075: }
4076: my $depth = 1;
4077: push(@path,$parent);
4078: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4079: pop(@path);
4080: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4081: $itemcount ++;
4082: }
1.48 raeburn 4083: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4084: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4085: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4086: for (my $k=0; $k<=$maxnum; $k++) {
4087: my $vpos = $k+1;
4088: my $selstr;
1.57 raeburn 4089: if ($k == $numtop) {
1.48 raeburn 4090: $selstr = ' selected="selected" ';
4091: }
4092: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4093: }
1.59 bisitz 4094: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4095: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4096: .'</tr>'."\n";
1.48 raeburn 4097: $itemcount ++;
1.120 raeburn 4098: foreach my $default ('instcode','communities') {
4099: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4100: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4101: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4102: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4103: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4104: for (my $k=0; $k<=$maxnum; $k++) {
4105: my $vpos = $k+1;
4106: my $selstr;
4107: if ($k == $maxnum) {
4108: $selstr = ' selected="selected" ';
4109: }
4110: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4111: }
1.120 raeburn 4112: $datatable .= '</select></span></td>'.
4113: '<td><span class="LC_nobreak">'.
4114: $default_names{$default}.'</span>';
4115: if ($default eq 'instcode') {
4116: $datatable .= '<br /><span class="LC_nobreak">('
4117: .&mt('with institutional codes').')</span>';
4118: }
4119: $datatable .= '</td>'
4120: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4121: .&mt('Display').'</label> '
4122: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4123: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4124: }
4125: }
4126: }
1.57 raeburn 4127: } else {
4128: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4129: }
4130: } else {
1.57 raeburn 4131: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4132: .&initialize_categories($itemcount);
1.48 raeburn 4133: }
1.57 raeburn 4134: $$rowtotal += $itemcount;
1.48 raeburn 4135: }
4136: return $datatable;
4137: }
4138:
1.69 raeburn 4139: sub print_serverstatuses {
4140: my ($dom,$settings,$rowtotal) = @_;
4141: my $datatable;
4142: my @pages = &serverstatus_pages();
4143: my (%namedaccess,%machineaccess);
4144: foreach my $type (@pages) {
4145: $namedaccess{$type} = '';
4146: $machineaccess{$type}= '';
4147: }
4148: if (ref($settings) eq 'HASH') {
4149: foreach my $type (@pages) {
4150: if (exists($settings->{$type})) {
4151: if (ref($settings->{$type}) eq 'HASH') {
4152: foreach my $key (keys(%{$settings->{$type}})) {
4153: if ($key eq 'namedusers') {
4154: $namedaccess{$type} = $settings->{$type}->{$key};
4155: } elsif ($key eq 'machines') {
4156: $machineaccess{$type} = $settings->{$type}->{$key};
4157: }
4158: }
4159: }
4160: }
4161: }
4162: }
1.81 raeburn 4163: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4164: my $rownum = 0;
4165: my $css_class;
4166: foreach my $type (@pages) {
4167: $rownum ++;
4168: $css_class = $rownum%2?' class="LC_odd_row"':'';
4169: $datatable .= '<tr'.$css_class.'>'.
4170: '<td><span class="LC_nobreak">'.
4171: $titles->{$type}.'</span></td>'.
4172: '<td class="LC_left_item">'.
4173: '<input type="text" name="'.$type.'_namedusers" '.
4174: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4175: '<td class="LC_right_item">'.
4176: '<span class="LC_nobreak">'.
4177: '<input type="text" name="'.$type.'_machines" '.
4178: 'value="'.$machineaccess{$type}.'" size="10" />'.
4179: '</td></tr>'."\n";
4180: }
4181: $$rowtotal += $rownum;
4182: return $datatable;
4183: }
4184:
4185: sub serverstatus_pages {
4186: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4187: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4188: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4189: }
4190:
1.49 raeburn 4191: sub coursecategories_javascript {
4192: my ($settings) = @_;
1.57 raeburn 4193: my ($output,$jstext,$cathash);
1.49 raeburn 4194: if (ref($settings) eq 'HASH') {
1.57 raeburn 4195: $cathash = $settings->{'cats'};
4196: }
4197: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4198: my (@cats,@jsarray,%idx);
1.57 raeburn 4199: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4200: if (@jsarray > 0) {
4201: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4202: for (my $i=0; $i<@jsarray; $i++) {
4203: if (ref($jsarray[$i]) eq 'ARRAY') {
4204: my $catstr = join('","',@{$jsarray[$i]});
4205: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4206: }
4207: }
4208: }
4209: } else {
4210: $jstext = ' var categories = Array(1);'."\n".
4211: ' categories[0] = Array("instcode_pos");'."\n";
4212: }
1.120 raeburn 4213: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4214: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4215: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4216: $output = <<"ENDSCRIPT";
4217: <script type="text/javascript">
1.109 raeburn 4218: // <![CDATA[
1.49 raeburn 4219: function reorderCats(form,parent,item,idx) {
4220: var changedVal;
4221: $jstext
4222: var newpos = 'addcategory_pos';
4223: var current = new Array;
4224: if (parent == '') {
4225: var has_instcode = 0;
4226: var maxtop = categories[idx].length;
4227: for (var j=0; j<maxtop; j++) {
4228: if (categories[idx][j] == 'instcode::0') {
4229: has_instcode == 1;
4230: }
4231: }
4232: if (has_instcode == 0) {
4233: categories[idx][maxtop] = 'instcode_pos';
4234: }
4235: } else {
4236: newpos += '_'+parent;
4237: }
4238: var maxh = 1 + categories[idx].length;
4239: var current = new Array;
4240: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4241: if (item == newpos) {
4242: changedVal = newitemVal;
4243: } else {
4244: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4245: current[newitemVal] = newpos;
4246: }
4247: for (var i=0; i<categories[idx].length; i++) {
4248: var elementName = categories[idx][i];
4249: if (elementName != item) {
4250: if (form.elements[elementName]) {
4251: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4252: current[currVal] = elementName;
4253: }
4254: }
4255: }
4256: var oldVal;
4257: for (var j=0; j<maxh; j++) {
4258: if (current[j] == undefined) {
4259: oldVal = j;
4260: }
4261: }
4262: if (oldVal < changedVal) {
4263: for (var k=oldVal+1; k<=changedVal ; k++) {
4264: var elementName = current[k];
4265: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4266: }
4267: } else {
4268: for (var k=changedVal; k<oldVal; k++) {
4269: var elementName = current[k];
4270: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4271: }
4272: }
4273: return;
4274: }
1.120 raeburn 4275:
4276: function categoryCheck(form) {
4277: if (form.elements['addcategory_name'].value == 'instcode') {
4278: alert('$instcode_reserved\\n$choose_again');
4279: return false;
4280: }
4281: if (form.elements['addcategory_name'].value == 'communities') {
4282: alert('$communities_reserved\\n$choose_again');
4283: return false;
4284: }
4285: return true;
4286: }
4287:
1.109 raeburn 4288: // ]]>
1.49 raeburn 4289: </script>
4290:
4291: ENDSCRIPT
4292: return $output;
4293: }
4294:
1.48 raeburn 4295: sub initialize_categories {
4296: my ($itemcount) = @_;
1.120 raeburn 4297: my ($datatable,$css_class,$chgstr);
4298: my %default_names = (
4299: instcode => 'Official courses (with institutional codes)',
4300: communities => 'Communities',
4301: );
4302: my $select0 = ' selected="selected"';
4303: my $select1 = '';
4304: foreach my $default ('instcode','communities') {
4305: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4306: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4307: if ($default eq 'communities') {
4308: $select1 = $select0;
4309: $select0 = '';
4310: }
4311: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4312: .'<select name="'.$default.'_pos">'
4313: .'<option value="0"'.$select0.'>1</option>'
4314: .'<option value="1"'.$select1.'>2</option>'
4315: .'<option value="2">3</option></select> '
4316: .$default_names{$default}
4317: .'</span></td><td><span class="LC_nobreak">'
4318: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4319: .&mt('Display').'</label> <label>'
4320: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4321: .'</label></span></td></tr>';
1.120 raeburn 4322: $itemcount ++;
4323: }
1.48 raeburn 4324: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4325: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4326: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4327: .'<select name="addcategory_pos"'.$chgstr.'>'
4328: .'<option value="0">1</option>'
4329: .'<option value="1">2</option>'
4330: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4331: .&mt('Add category').'</td><td>'.&mt('Name:')
4332: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4333: return $datatable;
4334: }
4335:
4336: sub build_category_rows {
1.49 raeburn 4337: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4338: my ($text,$name,$item,$chgstr);
1.48 raeburn 4339: if (ref($cats) eq 'ARRAY') {
4340: my $maxdepth = scalar(@{$cats});
4341: if (ref($cats->[$depth]) eq 'HASH') {
4342: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4343: my $numchildren = @{$cats->[$depth]{$parent}};
4344: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4345: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4346: my ($idxnum,$parent_name,$parent_item);
4347: my $higher = $depth - 1;
4348: if ($higher == 0) {
4349: $parent_name = &escape($parent).'::'.$higher;
4350: } else {
4351: if (ref($path) eq 'ARRAY') {
4352: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4353: }
4354: }
4355: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4356: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4357: if ($j < $numchildren) {
1.48 raeburn 4358: $name = $cats->[$depth]{$parent}[$j];
4359: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4360: $idxnum = $idx->{$item};
4361: } else {
4362: $name = $parent_name;
4363: $item = $parent_item;
1.48 raeburn 4364: }
1.49 raeburn 4365: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4366: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4367: for (my $i=0; $i<=$numchildren; $i++) {
4368: my $vpos = $i+1;
4369: my $selstr;
4370: if ($j == $i) {
4371: $selstr = ' selected="selected" ';
4372: }
4373: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4374: }
4375: $text .= '</select> ';
4376: if ($j < $numchildren) {
4377: my $deeper = $depth+1;
4378: $text .= $name.' '
4379: .'<label><input type="checkbox" name="deletecategory" value="'
4380: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4381: if(ref($path) eq 'ARRAY') {
4382: push(@{$path},$name);
1.49 raeburn 4383: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4384: pop(@{$path});
4385: }
4386: } else {
1.59 bisitz 4387: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4388: if ($j == $numchildren) {
4389: $text .= $name;
4390: } else {
4391: $text .= $item;
4392: }
4393: $text .= '" value="" />';
4394: }
4395: $text .= '</td></tr>';
4396: }
4397: $text .= '</table></td>';
4398: } else {
4399: my $higher = $depth-1;
4400: if ($higher == 0) {
4401: $name = &escape($parent).'::'.$higher;
4402: } else {
4403: if (ref($path) eq 'ARRAY') {
4404: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4405: }
4406: }
4407: my $colspan;
4408: if ($parent ne 'instcode') {
4409: $colspan = $maxdepth - $depth - 1;
4410: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4411: }
4412: }
4413: }
4414: }
4415: return $text;
4416: }
4417:
1.33 raeburn 4418: sub modifiable_userdata_row {
1.63 raeburn 4419: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4420: my $rolename;
1.63 raeburn 4421: if ($context eq 'selfcreate') {
4422: if (ref($usertypes) eq 'HASH') {
4423: $rolename = $usertypes->{$role};
4424: } else {
4425: $rolename = $role;
4426: }
1.33 raeburn 4427: } else {
1.63 raeburn 4428: if ($role eq 'cr') {
4429: $rolename = &mt('Custom role');
4430: } else {
4431: $rolename = &Apache::lonnet::plaintext($role);
4432: }
1.33 raeburn 4433: }
4434: my @fields = ('lastname','firstname','middlename','generation',
4435: 'permanentemail','id');
4436: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4437: my $output;
4438: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4439: $output = '<tr '.$css_class.'>'.
4440: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4441: '<td class="LC_left_item" colspan="2"><table>';
4442: my $rem;
4443: my %checks;
4444: if (ref($settings) eq 'HASH') {
4445: if (ref($settings->{$context}) eq 'HASH') {
4446: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4447: foreach my $field (@fields) {
4448: if ($settings->{$context}->{$role}->{$field}) {
4449: $checks{$field} = ' checked="checked" ';
4450: }
4451: }
4452: }
4453: }
4454: }
4455: for (my $i=0; $i<@fields; $i++) {
4456: my $rem = $i%($numinrow);
4457: if ($rem == 0) {
4458: if ($i > 0) {
4459: $output .= '</tr>';
4460: }
4461: $output .= '<tr>';
4462: }
4463: my $check = ' ';
4464: if (exists($checks{$fields[$i]})) {
4465: $check = $checks{$fields[$i]}
4466: } else {
4467: if ($role eq 'st') {
4468: if (ref($settings) ne 'HASH') {
4469: $check = ' checked="checked" ';
4470: }
4471: }
4472: }
4473: $output .= '<td class="LC_left_item">'.
4474: '<span class="LC_nobreak"><label>'.
4475: '<input type="checkbox" name="canmodify_'.$role.'" '.
4476: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4477: '</label></span></td>';
4478: $rem = @fields%($numinrow);
4479: }
4480: my $colsleft = $numinrow - $rem;
4481: if ($colsleft > 1 ) {
4482: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4483: ' </td>';
4484: } elsif ($colsleft == 1) {
4485: $output .= '<td class="LC_left_item"> </td>';
4486: }
4487: $output .= '</tr></table></td></tr>';
4488: return $output;
4489: }
1.28 raeburn 4490:
1.93 raeburn 4491: sub insttypes_row {
4492: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4493: my %lt = &Apache::lonlocal::texthash (
4494: cansearch => 'Users allowed to search',
4495: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4496: lockablenames => 'User preference to lock name',
1.93 raeburn 4497: );
4498: my $showdom;
4499: if ($context eq 'cansearch') {
4500: $showdom = ' ('.$dom.')';
4501: }
1.165 raeburn 4502: my $class = 'LC_left_item';
4503: if ($context eq 'statustocreate') {
4504: $class = 'LC_right_item';
4505: }
1.25 raeburn 4506: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4507: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4508: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4509: my $rem;
4510: if (ref($types) eq 'ARRAY') {
4511: for (my $i=0; $i<@{$types}; $i++) {
4512: if (defined($usertypes->{$types->[$i]})) {
4513: my $rem = $i%($numinrow);
4514: if ($rem == 0) {
4515: if ($i > 0) {
4516: $output .= '</tr>';
4517: }
4518: $output .= '<tr>';
1.23 raeburn 4519: }
1.26 raeburn 4520: my $check = ' ';
1.99 raeburn 4521: if (ref($settings) eq 'HASH') {
4522: if (ref($settings->{$context}) eq 'ARRAY') {
4523: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4524: $check = ' checked="checked" ';
4525: }
4526: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4527: $check = ' checked="checked" ';
4528: }
1.23 raeburn 4529: }
1.26 raeburn 4530: $output .= '<td class="LC_left_item">'.
4531: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4532: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4533: 'value="'.$types->[$i].'"'.$check.'/>'.
4534: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4535: }
4536: }
1.26 raeburn 4537: $rem = @{$types}%($numinrow);
1.23 raeburn 4538: }
4539: my $colsleft = $numinrow - $rem;
1.131 raeburn 4540: if (($rem == 0) && (@{$types} > 0)) {
4541: $output .= '<tr>';
4542: }
1.23 raeburn 4543: if ($colsleft > 1) {
1.25 raeburn 4544: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4545: } else {
1.25 raeburn 4546: $output .= '<td class="LC_left_item">';
1.23 raeburn 4547: }
4548: my $defcheck = ' ';
1.99 raeburn 4549: if (ref($settings) eq 'HASH') {
4550: if (ref($settings->{$context}) eq 'ARRAY') {
4551: if (grep(/^default$/,@{$settings->{$context}})) {
4552: $defcheck = ' checked="checked" ';
4553: }
4554: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4555: $defcheck = ' checked="checked" ';
4556: }
1.23 raeburn 4557: }
1.25 raeburn 4558: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4559: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4560: 'value="default"'.$defcheck.'/>'.
4561: $othertitle.'</label></span></td>'.
4562: '</tr></table></td></tr>';
4563: return $output;
1.23 raeburn 4564: }
4565:
4566: sub sorted_searchtitles {
4567: my %searchtitles = &Apache::lonlocal::texthash(
4568: 'uname' => 'username',
4569: 'lastname' => 'last name',
4570: 'lastfirst' => 'last name, first name',
4571: );
4572: my @titleorder = ('uname','lastname','lastfirst');
4573: return (\%searchtitles,\@titleorder);
4574: }
4575:
1.25 raeburn 4576: sub sorted_searchtypes {
4577: my %srchtypes_desc = (
4578: exact => 'is exact match',
4579: contains => 'contains ..',
4580: begins => 'begins with ..',
4581: );
4582: my @srchtypeorder = ('exact','begins','contains');
4583: return (\%srchtypes_desc,\@srchtypeorder);
4584: }
4585:
1.3 raeburn 4586: sub usertype_update_row {
4587: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4588: my $datatable;
4589: my $numinrow = 4;
4590: foreach my $type (@{$types}) {
4591: if (defined($usertypes->{$type})) {
4592: $$rownums ++;
4593: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4594: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4595: '</td><td class="LC_left_item"><table>';
4596: for (my $i=0; $i<@{$fields}; $i++) {
4597: my $rem = $i%($numinrow);
4598: if ($rem == 0) {
4599: if ($i > 0) {
4600: $datatable .= '</tr>';
4601: }
4602: $datatable .= '<tr>';
4603: }
4604: my $check = ' ';
1.39 raeburn 4605: if (ref($settings) eq 'HASH') {
4606: if (ref($settings->{'fields'}) eq 'HASH') {
4607: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4608: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4609: $check = ' checked="checked" ';
4610: }
1.3 raeburn 4611: }
4612: }
4613: }
4614:
4615: if ($i == @{$fields}-1) {
4616: my $colsleft = $numinrow - $rem;
4617: if ($colsleft > 1) {
4618: $datatable .= '<td colspan="'.$colsleft.'">';
4619: } else {
4620: $datatable .= '<td>';
4621: }
4622: } else {
4623: $datatable .= '<td>';
4624: }
1.8 raeburn 4625: $datatable .= '<span class="LC_nobreak"><label>'.
4626: '<input type="checkbox" name="updateable_'.$type.
4627: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4628: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4629: }
4630: $datatable .= '</tr></table></td></tr>';
4631: }
4632: }
4633: return $datatable;
1.1 raeburn 4634: }
4635:
4636: sub modify_login {
1.9 raeburn 4637: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4638: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4639: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4640: %title = ( coursecatalog => 'Display course catalog',
4641: adminmail => 'Display administrator E-mail address',
4642: newuser => 'Link for visitors to create a user account',
4643: loginheader => 'Log-in box header');
4644: @offon = ('off','on');
1.112 raeburn 4645: if (ref($domconfig{login}) eq 'HASH') {
4646: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4647: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4648: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4649: }
4650: }
4651: }
1.9 raeburn 4652: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4653: \%domconfig,\%loginhash);
1.118 jms 4654: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4655: foreach my $item (@toggles) {
4656: $loginhash{login}{$item} = $env{'form.'.$item};
4657: }
1.41 raeburn 4658: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4659: if (ref($colchanges{'login'}) eq 'HASH') {
4660: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4661: \%loginhash);
4662: }
1.110 raeburn 4663:
1.149 raeburn 4664: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4665: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4666: if (keys(%servers) > 1) {
4667: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4668: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4669: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4670: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4671: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4672: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4673: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4674: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4675: $changes{'loginvia'}{$lonhost} = 1;
4676: } else {
4677: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4678: $changes{'loginvia'}{$lonhost} = 1;
4679: }
4680: } else {
4681: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4682: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4683: $changes{'loginvia'}{$lonhost} = 1;
4684: }
4685: }
4686: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4687: foreach my $item (@loginvia_attribs) {
4688: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4689: }
4690: } else {
4691: foreach my $item (@loginvia_attribs) {
4692: my $new = $env{'form.'.$lonhost.'_'.$item};
4693: if (($item eq 'serverpath') && ($new eq 'custom')) {
4694: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4695: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4696: $new = '/';
4697: }
4698: }
4699: if (($item eq 'custompath') &&
4700: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4701: $new = '';
4702: }
4703: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4704: $changes{'loginvia'}{$lonhost} = 1;
4705: }
4706: if ($item eq 'exempt') {
4707: $new =~ s/^\s+//;
4708: $new =~ s/\s+$//;
4709: my @poss_ips = split(/\s*[,:]\s*/,$new);
4710: my @okips;
4711: foreach my $ip (@poss_ips) {
4712: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4713: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4714: push(@okips,$ip);
4715: }
4716: }
4717: }
4718: if (@okips > 0) {
4719: $new = join(',',@okips);
4720: } else {
4721: $new = '';
4722: }
4723: }
4724: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4725: }
4726: }
1.112 raeburn 4727: } else {
1.128 raeburn 4728: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4729: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4730: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4731: foreach my $item (@loginvia_attribs) {
4732: my $new = $env{'form.'.$lonhost.'_'.$item};
4733: if (($item eq 'serverpath') && ($new eq 'custom')) {
4734: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4735: $new = '/';
4736: }
4737: }
4738: if (($item eq 'custompath') &&
4739: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4740: $new = '';
4741: }
4742: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4743: }
1.110 raeburn 4744: }
4745: }
4746: }
4747: }
1.119 raeburn 4748:
1.168 raeburn 4749: my $servadm = $r->dir_config('lonAdmEMail');
4750: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4751: if (ref($domconfig{'login'}) eq 'HASH') {
4752: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4753: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4754: if ($lang eq 'nolang') {
4755: push(@currlangs,$lang);
4756: } elsif (defined($langchoices{$lang})) {
4757: push(@currlangs,$lang);
4758: } else {
4759: next;
4760: }
4761: }
4762: }
4763: }
4764: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4765: if (@currlangs > 0) {
4766: foreach my $lang (@currlangs) {
4767: if (grep(/^\Q$lang\E$/,@delurls)) {
4768: $changes{'helpurl'}{$lang} = 1;
4769: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4770: $changes{'helpurl'}{$lang} = 1;
4771: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4772: push(@newlangs,$lang);
4773: } else {
4774: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4775: }
4776: }
4777: }
4778: unless (grep(/^nolang$/,@currlangs)) {
4779: if ($env{'form.loginhelpurl_nolang.filename'}) {
4780: $changes{'helpurl'}{'nolang'} = 1;
4781: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4782: push(@newlangs,'nolang');
4783: }
4784: }
4785: if ($env{'form.loginhelpurl_add_lang'}) {
4786: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4787: ($env{'form.loginhelpurl_add_file.filename'})) {
4788: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4789: $addedfile = $env{'form.loginhelpurl_add_lang'};
4790: }
4791: }
4792: if ((@newlangs > 0) || ($addedfile)) {
4793: my $error;
4794: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4795: if ($configuserok eq 'ok') {
4796: if ($switchserver) {
4797: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4798: } elsif ($author_ok eq 'ok') {
4799: my @allnew = @newlangs;
4800: if ($addedfile ne '') {
4801: push(@allnew,$addedfile);
4802: }
4803: foreach my $lang (@allnew) {
4804: my $formelem = 'loginhelpurl_'.$lang;
4805: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4806: $formelem = 'loginhelpurl_add_file';
4807: }
4808: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4809: "help/$lang",'','',$newfile{$lang});
4810: if ($result eq 'ok') {
4811: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4812: $changes{'helpurl'}{$lang} = 1;
4813: } else {
4814: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4815: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4816: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4817: (!grep(/^\Q$lang\E$/,@delurls))) {
4818:
4819: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4820: }
4821: }
4822: }
4823: } else {
4824: $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);
4825: }
4826: } else {
4827: $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);
4828: }
4829: if ($error) {
4830: &Apache::lonnet::logthis($error);
4831: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4832: }
4833: }
1.169 raeburn 4834: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4835:
4836: my $defaulthelpfile = '/adm/loginproblems.html';
4837: my $defaulttext = &mt('Default in use');
4838:
1.1 raeburn 4839: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4840: $dom);
4841: if ($putresult eq 'ok') {
1.118 jms 4842: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4843: my %defaultchecked = (
4844: 'coursecatalog' => 'on',
4845: 'adminmail' => 'off',
1.43 raeburn 4846: 'newuser' => 'off',
1.42 raeburn 4847: );
1.55 raeburn 4848: if (ref($domconfig{'login'}) eq 'HASH') {
4849: foreach my $item (@toggles) {
4850: if ($defaultchecked{$item} eq 'on') {
4851: if (($domconfig{'login'}{$item} eq '0') &&
4852: ($env{'form.'.$item} eq '1')) {
4853: $changes{$item} = 1;
4854: } elsif (($domconfig{'login'}{$item} eq '' ||
4855: $domconfig{'login'}{$item} eq '1') &&
4856: ($env{'form.'.$item} eq '0')) {
4857: $changes{$item} = 1;
4858: }
4859: } elsif ($defaultchecked{$item} eq 'off') {
4860: if (($domconfig{'login'}{$item} eq '1') &&
4861: ($env{'form.'.$item} eq '0')) {
4862: $changes{$item} = 1;
4863: } elsif (($domconfig{'login'}{$item} eq '' ||
4864: $domconfig{'login'}{$item} eq '0') &&
4865: ($env{'form.'.$item} eq '1')) {
4866: $changes{$item} = 1;
4867: }
1.42 raeburn 4868: }
4869: }
1.41 raeburn 4870: }
1.6 raeburn 4871: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4872: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4873: $resulttext = &mt('Changes made:').'<ul>';
4874: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4875: if ($item eq 'loginvia') {
1.112 raeburn 4876: if (ref($changes{$item}) eq 'HASH') {
4877: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4878: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4879: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4880: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4881: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4882: $protocol = 'http' if ($protocol ne 'https');
4883: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4884:
4885: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4886: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4887: } else {
4888: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4889: }
4890: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4891: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4892: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4893: }
4894: $resulttext .= '</li>';
4895: } else {
4896: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4897: }
1.112 raeburn 4898: } else {
1.128 raeburn 4899: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4900: }
4901: }
1.128 raeburn 4902: $resulttext .= '</ul></li>';
1.112 raeburn 4903: }
1.168 raeburn 4904: } elsif ($item eq 'helpurl') {
4905: if (ref($changes{$item}) eq 'HASH') {
4906: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4907: if (grep(/^\Q$lang\E$/,@delurls)) {
4908: my ($chg,$link);
4909: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4910: if ($lang eq 'nolang') {
4911: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4912: } else {
4913: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4914: }
4915: $resulttext .= '<li>'.$chg.'</li>';
4916: } else {
4917: my $chg;
4918: if ($lang eq 'nolang') {
4919: $chg = &mt('custom log-in help file for no preferred language');
4920: } else {
4921: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4922: }
4923: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4924: $loginhash{'login'}{'helpurl'}{$lang}.
4925: '?inhibitmenu=yes',$chg,600,500).
4926: '</li>';
4927: }
4928: }
4929: }
1.169 raeburn 4930: } elsif ($item eq 'captcha') {
4931: if (ref($loginhash{'login'}) eq 'HASH') {
4932: my $chgtxt;
4933: if ($loginhash{'login'}{$item} eq 'notused') {
4934: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4935: } else {
4936: my %captchas = &captcha_phrases();
4937: if ($captchas{$loginhash{'login'}{$item}}) {
4938: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4939: } else {
4940: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4941: }
4942: }
4943: $resulttext .= '<li>'.$chgtxt.'</li>';
4944: }
4945: } elsif ($item eq 'recaptchakeys') {
4946: if (ref($loginhash{'login'}) eq 'HASH') {
4947: my ($privkey,$pubkey);
4948: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4949: $pubkey = $loginhash{'login'}{$item}{'public'};
4950: $privkey = $loginhash{'login'}{$item}{'private'};
4951: }
4952: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4953: if (!$pubkey) {
4954: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4955: } else {
4956: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4957: }
4958: if (!$privkey) {
4959: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4960: } else {
4961: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4962: }
4963: $chgtxt .= '</ul>';
4964: $resulttext .= '<li>'.$chgtxt.'</li>';
4965: }
1.41 raeburn 4966: } else {
4967: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4968: }
1.1 raeburn 4969: }
1.6 raeburn 4970: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4971: } else {
4972: $resulttext = &mt('No changes made to log-in page settings');
4973: }
4974: } else {
1.11 albertel 4975: $resulttext = '<span class="LC_error">'.
4976: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4977: }
1.6 raeburn 4978: if ($errors) {
1.9 raeburn 4979: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4980: $errors.'</ul>';
4981: }
4982: return $resulttext;
4983: }
4984:
4985: sub color_font_choices {
4986: my %choices =
4987: &Apache::lonlocal::texthash (
4988: img => "Header",
4989: bgs => "Background colors",
4990: links => "Link colors",
1.55 raeburn 4991: images => "Images",
1.6 raeburn 4992: font => "Font color",
1.97 tempelho 4993: fontmenu => "Font Menu",
1.76 raeburn 4994: pgbg => "Page",
1.6 raeburn 4995: tabbg => "Header",
4996: sidebg => "Border",
4997: link => "Link",
4998: alink => "Active link",
4999: vlink => "Visited link",
5000: );
5001: return %choices;
5002: }
5003:
5004: sub modify_rolecolors {
1.9 raeburn 5005: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5006: my ($resulttext,%rolehash);
5007: $rolehash{'rolecolors'} = {};
1.55 raeburn 5008: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5009: if ($domconfig{'rolecolors'} eq '') {
5010: $domconfig{'rolecolors'} = {};
5011: }
5012: }
1.9 raeburn 5013: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5014: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5015: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5016: $dom);
5017: if ($putresult eq 'ok') {
5018: if (keys(%changes) > 0) {
1.41 raeburn 5019: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5020: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5021: $rolehash{'rolecolors'});
5022: } else {
5023: $resulttext = &mt('No changes made to default color schemes');
5024: }
5025: } else {
1.11 albertel 5026: $resulttext = '<span class="LC_error">'.
5027: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5028: }
5029: if ($errors) {
5030: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5031: $errors.'</ul>';
5032: }
5033: return $resulttext;
5034: }
5035:
5036: sub modify_colors {
1.9 raeburn 5037: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5038: my (%changes,%choices);
1.51 raeburn 5039: my @bgs;
1.6 raeburn 5040: my @links = ('link','alink','vlink');
1.41 raeburn 5041: my @logintext;
1.6 raeburn 5042: my @images;
5043: my $servadm = $r->dir_config('lonAdmEMail');
5044: my $errors;
5045: foreach my $role (@{$roles}) {
5046: if ($role eq 'login') {
1.12 raeburn 5047: %choices = &login_choices();
1.41 raeburn 5048: @logintext = ('textcol','bgcol');
1.12 raeburn 5049: } else {
5050: %choices = &color_font_choices();
1.107 raeburn 5051: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5052: }
5053: if ($role eq 'login') {
1.41 raeburn 5054: @images = ('img','logo','domlogo','login');
1.51 raeburn 5055: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5056: } else {
5057: @images = ('img');
1.51 raeburn 5058: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5059: }
5060: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5061: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5062: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5063: }
1.46 raeburn 5064: my ($configuserok,$author_ok,$switchserver) =
5065: &config_check($dom,$confname,$servadm);
1.9 raeburn 5066: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5067: if (ref($domconfig->{$role}) ne 'HASH') {
5068: $domconfig->{$role} = {};
5069: }
1.8 raeburn 5070: foreach my $img (@images) {
1.70 raeburn 5071: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5072: if (defined($env{'form.login_showlogo_'.$img})) {
5073: $confhash->{$role}{'showlogo'}{$img} = 1;
5074: } else {
5075: $confhash->{$role}{'showlogo'}{$img} = 0;
5076: }
5077: }
1.18 albertel 5078: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5079: && !defined($domconfig->{$role}{$img})
5080: && !$env{'form.'.$role.'_del_'.$img}
5081: && $env{'form.'.$role.'_import_'.$img}) {
5082: # import the old configured image from the .tab setting
5083: # if they haven't provided a new one
5084: $domconfig->{$role}{$img} =
5085: $env{'form.'.$role.'_import_'.$img};
5086: }
1.6 raeburn 5087: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5088: my $error;
1.6 raeburn 5089: if ($configuserok eq 'ok') {
1.9 raeburn 5090: if ($switchserver) {
1.12 raeburn 5091: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5092: } else {
5093: if ($author_ok eq 'ok') {
5094: my ($result,$logourl) =
5095: &publishlogo($r,'upload',$role.'_'.$img,
5096: $dom,$confname,$img,$width,$height);
5097: if ($result eq 'ok') {
5098: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5099: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5100: } else {
1.12 raeburn 5101: $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 5102: }
5103: } else {
1.46 raeburn 5104: $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 5105: }
5106: }
5107: } else {
1.46 raeburn 5108: $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 5109: }
5110: if ($error) {
1.8 raeburn 5111: &Apache::lonnet::logthis($error);
1.11 albertel 5112: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5113: }
5114: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5115: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5116: my $error;
5117: if ($configuserok eq 'ok') {
5118: # is confname an author?
5119: if ($switchserver eq '') {
5120: if ($author_ok eq 'ok') {
5121: my ($result,$logourl) =
5122: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5123: $dom,$confname,$img,$width,$height);
5124: if ($result eq 'ok') {
5125: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5126: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5127: }
5128: }
5129: }
5130: }
1.6 raeburn 5131: }
5132: }
5133: }
5134: if (ref($domconfig) eq 'HASH') {
5135: if (ref($domconfig->{$role}) eq 'HASH') {
5136: foreach my $img (@images) {
5137: if ($domconfig->{$role}{$img} ne '') {
5138: if ($env{'form.'.$role.'_del_'.$img}) {
5139: $confhash->{$role}{$img} = '';
1.12 raeburn 5140: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5141: } else {
1.9 raeburn 5142: if ($confhash->{$role}{$img} eq '') {
5143: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5144: }
1.6 raeburn 5145: }
5146: } else {
5147: if ($env{'form.'.$role.'_del_'.$img}) {
5148: $confhash->{$role}{$img} = '';
1.12 raeburn 5149: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5150: }
5151: }
1.70 raeburn 5152: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5153: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5154: if ($confhash->{$role}{'showlogo'}{$img} ne
5155: $domconfig->{$role}{'showlogo'}{$img}) {
5156: $changes{$role}{'showlogo'}{$img} = 1;
5157: }
5158: } else {
5159: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5160: $changes{$role}{'showlogo'}{$img} = 1;
5161: }
5162: }
5163: }
5164: }
1.6 raeburn 5165: if ($domconfig->{$role}{'font'} ne '') {
5166: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5167: $changes{$role}{'font'} = 1;
5168: }
5169: } else {
5170: if ($confhash->{$role}{'font'}) {
5171: $changes{$role}{'font'} = 1;
5172: }
5173: }
1.107 raeburn 5174: if ($role ne 'login') {
5175: if ($domconfig->{$role}{'fontmenu'} ne '') {
5176: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5177: $changes{$role}{'fontmenu'} = 1;
5178: }
5179: } else {
5180: if ($confhash->{$role}{'fontmenu'}) {
5181: $changes{$role}{'fontmenu'} = 1;
5182: }
1.97 tempelho 5183: }
5184: }
1.6 raeburn 5185: foreach my $item (@bgs) {
5186: if ($domconfig->{$role}{$item} ne '') {
5187: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5188: $changes{$role}{'bgs'}{$item} = 1;
5189: }
5190: } else {
5191: if ($confhash->{$role}{$item}) {
5192: $changes{$role}{'bgs'}{$item} = 1;
5193: }
5194: }
5195: }
5196: foreach my $item (@links) {
5197: if ($domconfig->{$role}{$item} ne '') {
5198: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5199: $changes{$role}{'links'}{$item} = 1;
5200: }
5201: } else {
5202: if ($confhash->{$role}{$item}) {
5203: $changes{$role}{'links'}{$item} = 1;
5204: }
5205: }
5206: }
1.41 raeburn 5207: foreach my $item (@logintext) {
5208: if ($domconfig->{$role}{$item} ne '') {
5209: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5210: $changes{$role}{'logintext'}{$item} = 1;
5211: }
5212: } else {
5213: if ($confhash->{$role}{$item}) {
5214: $changes{$role}{'logintext'}{$item} = 1;
5215: }
5216: }
5217: }
1.6 raeburn 5218: } else {
5219: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5220: \@logintext,$confhash,\%changes);
1.6 raeburn 5221: }
5222: } else {
5223: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5224: \@logintext,$confhash,\%changes);
1.6 raeburn 5225: }
5226: }
5227: return ($errors,%changes);
5228: }
5229:
1.46 raeburn 5230: sub config_check {
5231: my ($dom,$confname,$servadm) = @_;
5232: my ($configuserok,$author_ok,$switchserver,%currroles);
5233: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5234: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5235: $confname,$servadm);
5236: if ($configuserok eq 'ok') {
5237: $switchserver = &check_switchserver($dom,$confname);
5238: if ($switchserver eq '') {
5239: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5240: }
5241: }
5242: return ($configuserok,$author_ok,$switchserver);
5243: }
5244:
1.6 raeburn 5245: sub default_change_checker {
1.41 raeburn 5246: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5247: foreach my $item (@{$links}) {
5248: if ($confhash->{$role}{$item}) {
5249: $changes->{$role}{'links'}{$item} = 1;
5250: }
5251: }
5252: foreach my $item (@{$bgs}) {
5253: if ($confhash->{$role}{$item}) {
5254: $changes->{$role}{'bgs'}{$item} = 1;
5255: }
5256: }
1.41 raeburn 5257: foreach my $item (@{$logintext}) {
5258: if ($confhash->{$role}{$item}) {
5259: $changes->{$role}{'logintext'}{$item} = 1;
5260: }
5261: }
1.6 raeburn 5262: foreach my $img (@{$images}) {
5263: if ($env{'form.'.$role.'_del_'.$img}) {
5264: $confhash->{$role}{$img} = '';
1.12 raeburn 5265: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5266: }
1.70 raeburn 5267: if ($role eq 'login') {
5268: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5269: $changes->{$role}{'showlogo'}{$img} = 1;
5270: }
5271: }
1.6 raeburn 5272: }
5273: if ($confhash->{$role}{'font'}) {
5274: $changes->{$role}{'font'} = 1;
5275: }
1.48 raeburn 5276: }
1.6 raeburn 5277:
5278: sub display_colorchgs {
5279: my ($dom,$changes,$roles,$confhash) = @_;
5280: my (%choices,$resulttext);
5281: if (!grep(/^login$/,@{$roles})) {
5282: $resulttext = &mt('Changes made:').'<br />';
5283: }
5284: foreach my $role (@{$roles}) {
5285: if ($role eq 'login') {
5286: %choices = &login_choices();
5287: } else {
5288: %choices = &color_font_choices();
5289: }
5290: if (ref($changes->{$role}) eq 'HASH') {
5291: if ($role ne 'login') {
5292: $resulttext .= '<h4>'.&mt($role).'</h4>';
5293: }
5294: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5295: if ($role ne 'login') {
5296: $resulttext .= '<ul>';
5297: }
5298: if (ref($changes->{$role}{$key}) eq 'HASH') {
5299: if ($role ne 'login') {
5300: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5301: }
5302: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5303: if (($role eq 'login') && ($key eq 'showlogo')) {
5304: if ($confhash->{$role}{$key}{$item}) {
5305: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5306: } else {
5307: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5308: }
5309: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5310: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5311: } else {
1.12 raeburn 5312: my $newitem = $confhash->{$role}{$item};
5313: if ($key eq 'images') {
5314: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5315: }
5316: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5317: }
5318: }
5319: if ($role ne 'login') {
5320: $resulttext .= '</ul></li>';
5321: }
5322: } else {
5323: if ($confhash->{$role}{$key} eq '') {
5324: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5325: } else {
5326: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5327: }
5328: }
5329: if ($role ne 'login') {
5330: $resulttext .= '</ul>';
5331: }
5332: }
5333: }
5334: }
1.3 raeburn 5335: return $resulttext;
1.1 raeburn 5336: }
5337:
1.9 raeburn 5338: sub thumb_dimensions {
5339: return ('200','50');
5340: }
5341:
1.16 raeburn 5342: sub check_dimensions {
5343: my ($inputfile) = @_;
5344: my ($fullwidth,$fullheight);
5345: if ($inputfile =~ m|^[/\w.\-]+$|) {
5346: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5347: my $imageinfo = <PIPE>;
5348: if (!close(PIPE)) {
5349: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5350: }
5351: chomp($imageinfo);
5352: my ($fullsize) =
1.21 raeburn 5353: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5354: if ($fullsize) {
5355: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5356: }
5357: }
5358: }
5359: return ($fullwidth,$fullheight);
5360: }
5361:
1.9 raeburn 5362: sub check_configuser {
5363: my ($uhome,$dom,$confname,$servadm) = @_;
5364: my ($configuserok,%currroles);
5365: if ($uhome eq 'no_host') {
5366: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5367: my $configpass = &LONCAPA::Enrollment::create_password();
5368: $configuserok =
5369: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5370: $configpass,'','','','','',undef,$servadm);
5371: } else {
5372: $configuserok = 'ok';
5373: %currroles =
5374: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5375: }
5376: return ($configuserok,%currroles);
5377: }
5378:
5379: sub check_authorstatus {
5380: my ($dom,$confname,%currroles) = @_;
5381: my $author_ok;
1.40 raeburn 5382: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5383: my $start = time;
5384: my $end = 0;
5385: $author_ok =
5386: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5387: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5388: } else {
5389: $author_ok = 'ok';
5390: }
5391: return $author_ok;
5392: }
5393:
5394: sub publishlogo {
1.46 raeburn 5395: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5396: my ($output,$fname,$logourl);
5397: if ($action eq 'upload') {
5398: $fname=$env{'form.'.$formname.'.filename'};
5399: chop($env{'form.'.$formname});
5400: } else {
5401: ($fname) = ($formname =~ /([^\/]+)$/);
5402: }
1.46 raeburn 5403: if ($savefileas ne '') {
5404: $fname = $savefileas;
5405: }
1.9 raeburn 5406: $fname=&Apache::lonnet::clean_filename($fname);
5407: # See if there is anything left
5408: unless ($fname) { return ('error: no uploaded file'); }
5409: $fname="$subdir/$fname";
1.164 raeburn 5410: my $docroot=$r->dir_config('lonDocRoot');
5411: my $filepath="$docroot/priv";
5412: my $relpath = "$dom/$confname";
1.9 raeburn 5413: my ($fnamepath,$file,$fetchthumb);
5414: $file=$fname;
5415: if ($fname=~m|/|) {
5416: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5417: }
1.164 raeburn 5418: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5419: my $count;
1.164 raeburn 5420: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5421: $filepath.="/$parts[$count]";
5422: if ((-e $filepath)!=1) {
5423: mkdir($filepath,02770);
5424: }
5425: }
5426: # Check for bad extension and disallow upload
5427: if ($file=~/\.(\w+)$/ &&
5428: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5429: $output =
5430: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5431: } elsif ($file=~/\.(\w+)$/ &&
5432: !defined(&Apache::loncommon::fileembstyle($1))) {
5433: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5434: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5435: $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 5436: } elsif (-d "$filepath/$file") {
5437: $output = &mt('File name is a directory name - rename the file and re-upload');
5438: } else {
5439: my $source = $filepath.'/'.$file;
5440: my $logfile;
5441: if (!open($logfile,">>$source".'.log')) {
5442: return (&mt('No write permission to Construction Space'));
5443: }
5444: print $logfile
5445: "\n================= Publish ".localtime()." ================\n".
5446: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5447: # Save the file
5448: if (!open(FH,'>'.$source)) {
5449: &Apache::lonnet::logthis('Failed to create '.$source);
5450: return (&mt('Failed to create file'));
5451: }
5452: if ($action eq 'upload') {
5453: if (!print FH ($env{'form.'.$formname})) {
5454: &Apache::lonnet::logthis('Failed to write to '.$source);
5455: return (&mt('Failed to write file'));
5456: }
5457: } else {
5458: my $original = &Apache::lonnet::filelocation('',$formname);
5459: if(!copy($original,$source)) {
5460: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5461: return (&mt('Failed to write file'));
5462: }
5463: }
5464: close(FH);
5465: chmod(0660, $source); # Permissions to rw-rw---.
5466:
5467: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5468: my $copyfile=$targetdir.'/'.$file;
5469:
5470: my @parts=split(/\//,$targetdir);
5471: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5472: for (my $count=5;$count<=$#parts;$count++) {
5473: $path.="/$parts[$count]";
5474: if (!-e $path) {
5475: print $logfile "\nCreating directory ".$path;
5476: mkdir($path,02770);
5477: }
5478: }
5479: my $versionresult;
5480: if (-e $copyfile) {
5481: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5482: } else {
5483: $versionresult = 'ok';
5484: }
5485: if ($versionresult eq 'ok') {
5486: if (copy($source,$copyfile)) {
5487: print $logfile "\nCopied original source to ".$copyfile."\n";
5488: $output = 'ok';
5489: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5490: push(@{$modified_urls},[$copyfile,$source]);
5491: my $metaoutput =
5492: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5493: unless ($registered_cleanup) {
5494: my $handlers = $r->get_handlers('PerlCleanupHandler');
5495: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5496: $registered_cleanup=1;
5497: }
1.9 raeburn 5498: } else {
5499: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5500: $output = &mt('Failed to copy file to RES space').", $!";
5501: }
5502: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5503: my $inputfile = $filepath.'/'.$file;
5504: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5505: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5506: if ($fullwidth ne '' && $fullheight ne '') {
5507: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5508: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5509: system("convert -sample $thumbsize $inputfile $outfile");
5510: chmod(0660, $filepath.'/tn-'.$file);
5511: if (-e $outfile) {
5512: my $copyfile=$targetdir.'/tn-'.$file;
5513: if (copy($outfile,$copyfile)) {
5514: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5515: my $thumb_metaoutput =
5516: &write_metadata($dom,$confname,$formname,
5517: $targetdir,'tn-'.$file,$logfile);
5518: push(@{$modified_urls},[$copyfile,$outfile]);
5519: unless ($registered_cleanup) {
5520: my $handlers = $r->get_handlers('PerlCleanupHandler');
5521: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5522: $registered_cleanup=1;
5523: }
1.16 raeburn 5524: } else {
5525: print $logfile "\nUnable to write ".$copyfile.
5526: ':'.$!."\n";
5527: }
5528: }
1.9 raeburn 5529: }
5530: }
5531: }
5532: } else {
5533: $output = $versionresult;
5534: }
5535: }
5536: return ($output,$logourl);
5537: }
5538:
5539: sub logo_versioning {
5540: my ($targetdir,$file,$logfile) = @_;
5541: my $target = $targetdir.'/'.$file;
5542: my ($maxversion,$fn,$extn,$output);
5543: $maxversion = 0;
5544: if ($file =~ /^(.+)\.(\w+)$/) {
5545: $fn=$1;
5546: $extn=$2;
5547: }
5548: opendir(DIR,$targetdir);
5549: while (my $filename=readdir(DIR)) {
5550: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5551: $maxversion=($1>$maxversion)?$1:$maxversion;
5552: }
5553: }
5554: $maxversion++;
5555: print $logfile "\nCreating old version ".$maxversion."\n";
5556: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5557: if (copy($target,$copyfile)) {
5558: print $logfile "Copied old target to ".$copyfile."\n";
5559: $copyfile=$copyfile.'.meta';
5560: if (copy($target.'.meta',$copyfile)) {
5561: print $logfile "Copied old target metadata to ".$copyfile."\n";
5562: $output = 'ok';
5563: } else {
5564: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5565: $output = &mt('Failed to copy old meta').", $!, ";
5566: }
5567: } else {
5568: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5569: $output = &mt('Failed to copy old target').", $!, ";
5570: }
5571: return $output;
5572: }
5573:
5574: sub write_metadata {
5575: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5576: my (%metadatafields,%metadatakeys,$output);
5577: $metadatafields{'title'}=$formname;
5578: $metadatafields{'creationdate'}=time;
5579: $metadatafields{'lastrevisiondate'}=time;
5580: $metadatafields{'copyright'}='public';
5581: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5582: $env{'user.domain'};
5583: $metadatafields{'authorspace'}=$confname.':'.$dom;
5584: $metadatafields{'domain'}=$dom;
5585: {
5586: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5587: my $mfh;
1.155 raeburn 5588: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5589: foreach (sort keys %metadatafields) {
5590: unless ($_=~/\./) {
5591: my $unikey=$_;
5592: $unikey=~/^([A-Za-z]+)/;
5593: my $tag=$1;
5594: $tag=~tr/A-Z/a-z/;
5595: print $mfh "\n\<$tag";
5596: foreach (split(/\,/,$metadatakeys{$unikey})) {
5597: my $value=$metadatafields{$unikey.'.'.$_};
5598: $value=~s/\"/\'\'/g;
5599: print $mfh ' '.$_.'="'.$value.'"';
5600: }
5601: print $mfh '>'.
5602: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5603: .'</'.$tag.'>';
5604: }
5605: }
5606: $output = 'ok';
5607: print $logfile "\nWrote metadata";
5608: close($mfh);
5609: } else {
5610: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5611: $output = &mt('Could not write metadata');
5612: }
5613: }
1.155 raeburn 5614: return $output;
5615: }
5616:
5617: sub notifysubscribed {
5618: foreach my $targetsource (@{$modified_urls}){
5619: next unless (ref($targetsource) eq 'ARRAY');
5620: my ($target,$source)=@{$targetsource};
5621: if ($source ne '') {
5622: if (open(my $logfh,'>>'.$source.'.log')) {
5623: print $logfh "\nCleanup phase: Notifications\n";
5624: my @subscribed=&subscribed_hosts($target);
5625: foreach my $subhost (@subscribed) {
5626: print $logfh "\nNotifying host ".$subhost.':';
5627: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5628: print $logfh $reply;
5629: }
5630: my @subscribedmeta=&subscribed_hosts("$target.meta");
5631: foreach my $subhost (@subscribedmeta) {
5632: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5633: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5634: $subhost);
5635: print $logfh $reply;
5636: }
5637: print $logfh "\n============ Done ============\n";
1.160 raeburn 5638: close($logfh);
1.155 raeburn 5639: }
5640: }
5641: }
5642: return OK;
5643: }
5644:
5645: sub subscribed_hosts {
5646: my ($target) = @_;
5647: my @subscribed;
5648: if (open(my $fh,"<$target.subscription")) {
5649: while (my $subline=<$fh>) {
5650: if ($subline =~ /^($match_lonid):/) {
5651: my $host = $1;
5652: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5653: unless (grep(/^\Q$host\E$/,@subscribed)) {
5654: push(@subscribed,$host);
5655: }
5656: }
5657: }
5658: }
5659: }
5660: return @subscribed;
1.9 raeburn 5661: }
5662:
5663: sub check_switchserver {
5664: my ($dom,$confname) = @_;
5665: my ($allowed,$switchserver);
5666: my $home = &Apache::lonnet::homeserver($confname,$dom);
5667: if ($home eq 'no_host') {
5668: $home = &Apache::lonnet::domain($dom,'primary');
5669: }
5670: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5671: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5672: if (!$allowed) {
5673: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5674: }
5675: return $switchserver;
5676: }
5677:
1.1 raeburn 5678: sub modify_quotas {
1.86 raeburn 5679: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5680: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5681: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5682: if ($action eq 'quotas') {
5683: $context = 'tools';
1.163 raeburn 5684: } else {
1.86 raeburn 5685: $context = $action;
5686: }
5687: if ($context eq 'requestcourses') {
1.98 raeburn 5688: @usertools = ('official','unofficial','community');
1.106 raeburn 5689: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5690: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5691: %titles = &courserequest_titles();
5692: $toolregexp = join('|',@usertools);
5693: %conditions = &courserequest_conditions();
1.163 raeburn 5694: } elsif ($context eq 'requestauthor') {
5695: @usertools = ('author');
5696: %titles = &authorrequest_titles();
1.86 raeburn 5697: } else {
1.162 raeburn 5698: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5699: %titles = &tool_titles();
1.86 raeburn 5700: }
1.72 raeburn 5701: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5702: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5703: foreach my $key (keys(%env)) {
1.101 raeburn 5704: if ($context eq 'requestcourses') {
5705: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5706: my $item = $1;
5707: my $type = $2;
5708: if ($type =~ /^limit_(.+)/) {
5709: $limithash{$item}{$1} = $env{$key};
5710: } else {
5711: $confhash{$item}{$type} = $env{$key};
5712: }
5713: }
1.163 raeburn 5714: } elsif ($context eq 'requestauthor') {
5715: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5716: $confhash{$1} = $env{$key};
5717: }
1.101 raeburn 5718: } else {
1.86 raeburn 5719: if ($key =~ /^form\.quota_(.+)$/) {
5720: $confhash{'defaultquota'}{$1} = $env{$key};
5721: }
1.101 raeburn 5722: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5723: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5724: }
1.72 raeburn 5725: }
5726: }
1.163 raeburn 5727: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5728: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5729: @approvalnotify = sort(@approvalnotify);
5730: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5731: if (ref($domconfig{$action}) eq 'HASH') {
5732: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5733: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5734: $changes{'notify'}{'approval'} = 1;
5735: }
5736: } else {
1.144 raeburn 5737: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5738: $changes{'notify'}{'approval'} = 1;
5739: }
5740: }
5741: } else {
1.144 raeburn 5742: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5743: $changes{'notify'}{'approval'} = 1;
5744: }
5745: }
5746: } else {
1.86 raeburn 5747: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5748: }
1.72 raeburn 5749: foreach my $item (@usertools) {
5750: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5751: my $unset;
1.101 raeburn 5752: if ($context eq 'requestcourses') {
1.104 raeburn 5753: $unset = '0';
5754: if ($type eq '_LC_adv') {
5755: $unset = '';
5756: }
1.101 raeburn 5757: if ($confhash{$item}{$type} eq 'autolimit') {
5758: $confhash{$item}{$type} .= '=';
5759: unless ($limithash{$item}{$type} =~ /\D/) {
5760: $confhash{$item}{$type} .= $limithash{$item}{$type};
5761: }
5762: }
1.163 raeburn 5763: } elsif ($context eq 'requestauthor') {
5764: $unset = '0';
5765: if ($type eq '_LC_adv') {
5766: $unset = '';
5767: }
1.72 raeburn 5768: } else {
1.101 raeburn 5769: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5770: $confhash{$item}{$type} = 1;
5771: } else {
5772: $confhash{$item}{$type} = 0;
5773: }
1.72 raeburn 5774: }
1.86 raeburn 5775: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5776: if ($action eq 'requestauthor') {
5777: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5778: $changes{$type} = 1;
5779: }
5780: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5781: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5782: $changes{$item}{$type} = 1;
5783: }
5784: } else {
5785: if ($context eq 'requestcourses') {
1.104 raeburn 5786: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5787: $changes{$item}{$type} = 1;
5788: }
5789: } else {
5790: if (!$confhash{$item}{$type}) {
5791: $changes{$item}{$type} = 1;
5792: }
5793: }
5794: }
5795: } else {
5796: if ($context eq 'requestcourses') {
1.104 raeburn 5797: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5798: $changes{$item}{$type} = 1;
5799: }
1.163 raeburn 5800: } elsif ($context eq 'requestauthor') {
5801: if ($confhash{$type} ne $unset) {
5802: $changes{$type} = 1;
5803: }
1.72 raeburn 5804: } else {
5805: if (!$confhash{$item}{$type}) {
5806: $changes{$item}{$type} = 1;
5807: }
5808: }
5809: }
1.1 raeburn 5810: }
5811: }
1.163 raeburn 5812: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5813: if (ref($domconfig{'quotas'}) eq 'HASH') {
5814: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5815: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5816: if (exists($confhash{'defaultquota'}{$key})) {
5817: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5818: $changes{'defaultquota'}{$key} = 1;
5819: }
5820: } else {
5821: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5822: }
5823: }
1.86 raeburn 5824: } else {
5825: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5826: if (exists($confhash{'defaultquota'}{$key})) {
5827: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5828: $changes{'defaultquota'}{$key} = 1;
5829: }
5830: } else {
5831: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5832: }
1.1 raeburn 5833: }
5834: }
5835: }
1.86 raeburn 5836: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5837: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5838: if (ref($domconfig{'quotas'}) eq 'HASH') {
5839: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5840: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5841: $changes{'defaultquota'}{$key} = 1;
5842: }
5843: } else {
5844: if (!exists($domconfig{'quotas'}{$key})) {
5845: $changes{'defaultquota'}{$key} = 1;
5846: }
1.72 raeburn 5847: }
5848: } else {
1.86 raeburn 5849: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5850: }
1.1 raeburn 5851: }
5852: }
5853: }
1.72 raeburn 5854:
1.163 raeburn 5855: if ($context eq 'requestauthor') {
5856: $domdefaults{'requestauthor'} = \%confhash;
5857: } else {
5858: foreach my $key (keys(%confhash)) {
5859: $domdefaults{$key} = $confhash{$key};
5860: }
1.72 raeburn 5861: }
1.163 raeburn 5862:
1.1 raeburn 5863: my %quotahash = (
1.86 raeburn 5864: $action => { %confhash }
1.1 raeburn 5865: );
5866: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5867: $dom);
5868: if ($putresult eq 'ok') {
5869: if (keys(%changes) > 0) {
1.72 raeburn 5870: my $cachetime = 24*60*60;
5871: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5872:
1.1 raeburn 5873: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5874: unless (($context eq 'requestcourses') ||
5875: ($context eq 'requestauthor')) {
1.86 raeburn 5876: if (ref($changes{'defaultquota'}) eq 'HASH') {
5877: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5878: foreach my $type (@{$types},'default') {
5879: if (defined($changes{'defaultquota'}{$type})) {
5880: my $typetitle = $usertypes->{$type};
5881: if ($type eq 'default') {
5882: $typetitle = $othertitle;
5883: }
5884: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5885: }
5886: }
1.86 raeburn 5887: $resulttext .= '</ul></li>';
1.72 raeburn 5888: }
5889: }
1.80 raeburn 5890: my %newenv;
1.72 raeburn 5891: foreach my $item (@usertools) {
1.163 raeburn 5892: my (%haschgs,%inconf);
5893: if ($context eq 'requestauthor') {
5894: %haschgs = %changes;
5895: %inconf = %confhash;
5896: } else {
5897: if (ref($changes{$item}) eq 'HASH') {
5898: %haschgs = %{$changes{$item}};
5899: }
5900: if (ref($confhash{$item}) eq 'HASH') {
5901: %inconf = %{$confhash{$item}};
5902: }
5903: }
5904: if (keys(%haschgs) > 0) {
1.80 raeburn 5905: my $newacc =
5906: &Apache::lonnet::usertools_access($env{'user.name'},
5907: $env{'user.domain'},
1.86 raeburn 5908: $item,'reload',$context);
1.163 raeburn 5909: if (($context eq 'requestcourses') ||
5910: ($context eq 'requestauthor')) {
1.108 raeburn 5911: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5912: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5913: }
5914: } else {
5915: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5916: $newenv{'environment.availabletools.'.$item} = $newacc;
5917: }
1.80 raeburn 5918: }
1.163 raeburn 5919: unless ($context eq 'requestauthor') {
5920: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5921: }
1.72 raeburn 5922: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5923: if ($haschgs{$type}) {
1.72 raeburn 5924: my $typetitle = $usertypes->{$type};
5925: if ($type eq 'default') {
5926: $typetitle = $othertitle;
5927: } elsif ($type eq '_LC_adv') {
5928: $typetitle = 'LON-CAPA Advanced Users';
5929: }
1.163 raeburn 5930: if ($inconf{$type}) {
1.101 raeburn 5931: if ($context eq 'requestcourses') {
5932: my $cond;
1.163 raeburn 5933: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5934: if ($1 eq '') {
5935: $cond = &mt('(Automatic processing of any request).');
5936: } else {
5937: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5938: }
5939: } else {
1.163 raeburn 5940: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5941: }
5942: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5943: } elsif ($context eq 'requestauthor') {
5944: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5945: $titles{$inconf{$type}},$typetitle);
5946:
1.101 raeburn 5947: } else {
5948: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5949: }
1.72 raeburn 5950: } else {
1.104 raeburn 5951: if ($type eq '_LC_adv') {
1.163 raeburn 5952: if ($inconf{$type} eq '0') {
1.104 raeburn 5953: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5954: } else {
5955: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5956: }
5957: } else {
5958: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5959: }
1.72 raeburn 5960: }
5961: }
1.26 raeburn 5962: }
1.163 raeburn 5963: unless ($context eq 'requestauthor') {
5964: $resulttext .= '</ul></li>';
5965: }
1.26 raeburn 5966: }
1.1 raeburn 5967: }
1.163 raeburn 5968: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5969: if (ref($changes{'notify'}) eq 'HASH') {
5970: if ($changes{'notify'}{'approval'}) {
5971: if (ref($confhash{'notify'}) eq 'HASH') {
5972: if ($confhash{'notify'}{'approval'}) {
5973: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5974: } else {
1.163 raeburn 5975: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5976: }
5977: }
5978: }
5979: }
5980: }
1.1 raeburn 5981: $resulttext .= '</ul>';
1.80 raeburn 5982: if (keys(%newenv)) {
5983: &Apache::lonnet::appenv(\%newenv);
5984: }
1.1 raeburn 5985: } else {
1.86 raeburn 5986: if ($context eq 'requestcourses') {
5987: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 5988: } elsif ($context eq 'requestauthor') {
5989: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5990: } else {
1.90 weissno 5991: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5992: }
1.1 raeburn 5993: }
5994: } else {
1.11 albertel 5995: $resulttext = '<span class="LC_error">'.
5996: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5997: }
1.3 raeburn 5998: return $resulttext;
1.1 raeburn 5999: }
6000:
1.3 raeburn 6001: sub modify_autoenroll {
6002: my ($dom,%domconfig) = @_;
1.1 raeburn 6003: my ($resulttext,%changes);
6004: my %currautoenroll;
6005: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6006: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6007: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6008: }
6009: }
6010: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6011: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6012: sender => 'Sender for notification messages',
6013: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6014: my @offon = ('off','on');
1.17 raeburn 6015: my $sender_uname = $env{'form.sender_uname'};
6016: my $sender_domain = $env{'form.sender_domain'};
6017: if ($sender_domain eq '') {
6018: $sender_uname = '';
6019: } elsif ($sender_uname eq '') {
6020: $sender_domain = '';
6021: }
1.129 raeburn 6022: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6023: my %autoenrollhash = (
1.129 raeburn 6024: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6025: 'sender_uname' => $sender_uname,
6026: 'sender_domain' => $sender_domain,
6027: 'co-owners' => $coowners,
1.1 raeburn 6028: }
6029: );
1.4 raeburn 6030: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6031: $dom);
1.1 raeburn 6032: if ($putresult eq 'ok') {
6033: if (exists($currautoenroll{'run'})) {
6034: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6035: $changes{'run'} = 1;
6036: }
6037: } elsif ($autorun) {
6038: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6039: $changes{'run'} = 1;
1.1 raeburn 6040: }
6041: }
1.17 raeburn 6042: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6043: $changes{'sender'} = 1;
6044: }
1.17 raeburn 6045: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6046: $changes{'sender'} = 1;
6047: }
1.129 raeburn 6048: if ($currautoenroll{'co-owners'} ne '') {
6049: if ($currautoenroll{'co-owners'} ne $coowners) {
6050: $changes{'coowners'} = 1;
6051: }
6052: } elsif ($coowners) {
6053: $changes{'coowners'} = 1;
6054: }
1.1 raeburn 6055: if (keys(%changes) > 0) {
6056: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6057: if ($changes{'run'}) {
1.1 raeburn 6058: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6059: }
6060: if ($changes{'sender'}) {
1.17 raeburn 6061: if ($sender_uname eq '' || $sender_domain eq '') {
6062: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6063: } else {
6064: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6065: }
1.1 raeburn 6066: }
1.129 raeburn 6067: if ($changes{'coowners'}) {
6068: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6069: &Apache::loncommon::devalidate_domconfig_cache($dom);
6070: }
1.1 raeburn 6071: $resulttext .= '</ul>';
6072: } else {
6073: $resulttext = &mt('No changes made to auto-enrollment settings');
6074: }
6075: } else {
1.11 albertel 6076: $resulttext = '<span class="LC_error">'.
6077: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6078: }
1.3 raeburn 6079: return $resulttext;
1.1 raeburn 6080: }
6081:
6082: sub modify_autoupdate {
1.3 raeburn 6083: my ($dom,%domconfig) = @_;
1.1 raeburn 6084: my ($resulttext,%currautoupdate,%fields,%changes);
6085: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6086: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6087: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6088: }
6089: }
6090: my @offon = ('off','on');
6091: my %title = &Apache::lonlocal::texthash (
6092: run => 'Auto-update:',
6093: classlists => 'Updates to user information in classlists?'
6094: );
1.44 raeburn 6095: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6096: my %fieldtitles = &Apache::lonlocal::texthash (
6097: id => 'Student/Employee ID',
1.20 raeburn 6098: permanentemail => 'E-mail address',
1.1 raeburn 6099: lastname => 'Last Name',
6100: firstname => 'First Name',
6101: middlename => 'Middle Name',
1.132 raeburn 6102: generation => 'Generation',
1.1 raeburn 6103: );
1.142 raeburn 6104: $othertitle = &mt('All users');
1.1 raeburn 6105: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6106: $othertitle = &mt('Other users');
1.1 raeburn 6107: }
6108: foreach my $key (keys(%env)) {
6109: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6110: my ($usertype,$item) = ($1,$2);
6111: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6112: if ($usertype eq 'default') {
6113: push(@{$fields{$1}},$2);
6114: } elsif (ref($types) eq 'ARRAY') {
6115: if (grep(/^\Q$usertype\E$/,@{$types})) {
6116: push(@{$fields{$1}},$2);
6117: }
6118: }
6119: }
1.1 raeburn 6120: }
6121: }
1.131 raeburn 6122: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6123: @lockablenames = sort(@lockablenames);
6124: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6125: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6126: if (@changed) {
6127: $changes{'lockablenames'} = 1;
6128: }
6129: } else {
6130: if (@lockablenames) {
6131: $changes{'lockablenames'} = 1;
6132: }
6133: }
1.1 raeburn 6134: my %updatehash = (
6135: autoupdate => { run => $env{'form.autoupdate_run'},
6136: classlists => $env{'form.classlists'},
6137: fields => {%fields},
1.131 raeburn 6138: lockablenames => \@lockablenames,
1.1 raeburn 6139: }
6140: );
6141: foreach my $key (keys(%currautoupdate)) {
6142: if (($key eq 'run') || ($key eq 'classlists')) {
6143: if (exists($updatehash{autoupdate}{$key})) {
6144: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6145: $changes{$key} = 1;
6146: }
6147: }
6148: } elsif ($key eq 'fields') {
6149: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6150: foreach my $item (@{$types},'default') {
1.1 raeburn 6151: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6152: my $change = 0;
6153: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6154: if (!exists($fields{$item})) {
6155: $change = 1;
1.132 raeburn 6156: last;
1.1 raeburn 6157: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6158: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6159: $change = 1;
1.132 raeburn 6160: last;
1.1 raeburn 6161: }
6162: }
6163: }
6164: if ($change) {
6165: push(@{$changes{$key}},$item);
6166: }
1.26 raeburn 6167: }
1.1 raeburn 6168: }
6169: }
1.131 raeburn 6170: } elsif ($key eq 'lockablenames') {
6171: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6172: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6173: if (@changed) {
6174: $changes{'lockablenames'} = 1;
6175: }
6176: } else {
6177: if (@lockablenames) {
6178: $changes{'lockablenames'} = 1;
6179: }
6180: }
6181: }
6182: }
6183: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6184: if (@lockablenames) {
6185: $changes{'lockablenames'} = 1;
1.1 raeburn 6186: }
6187: }
1.26 raeburn 6188: foreach my $item (@{$types},'default') {
6189: if (defined($fields{$item})) {
6190: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6191: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6192: my $change = 0;
6193: if (ref($fields{$item}) eq 'ARRAY') {
6194: foreach my $type (@{$fields{$item}}) {
6195: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6196: $change = 1;
6197: last;
6198: }
6199: }
6200: }
6201: if ($change) {
6202: push(@{$changes{'fields'}},$item);
6203: }
6204: } else {
1.26 raeburn 6205: push(@{$changes{'fields'}},$item);
6206: }
6207: } else {
6208: push(@{$changes{'fields'}},$item);
1.1 raeburn 6209: }
6210: }
6211: }
6212: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6213: $dom);
6214: if ($putresult eq 'ok') {
6215: if (keys(%changes) > 0) {
6216: $resulttext = &mt('Changes made:').'<ul>';
6217: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6218: if ($key eq 'lockablenames') {
6219: $resulttext .= '<li>';
6220: if (@lockablenames) {
6221: $usertypes->{'default'} = $othertitle;
6222: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6223: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6224: } else {
6225: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6226: }
6227: $resulttext .= '</li>';
6228: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6229: foreach my $item (@{$changes{$key}}) {
6230: my @newvalues;
6231: foreach my $type (@{$fields{$item}}) {
6232: push(@newvalues,$fieldtitles{$type});
6233: }
1.3 raeburn 6234: my $newvaluestr;
6235: if (@newvalues > 0) {
6236: $newvaluestr = join(', ',@newvalues);
6237: } else {
6238: $newvaluestr = &mt('none');
1.6 raeburn 6239: }
1.1 raeburn 6240: if ($item eq 'default') {
1.26 raeburn 6241: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6242: } else {
1.26 raeburn 6243: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6244: }
6245: }
6246: } else {
6247: my $newvalue;
6248: if ($key eq 'run') {
6249: $newvalue = $offon[$env{'form.autoupdate_run'}];
6250: } else {
6251: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6252: }
1.1 raeburn 6253: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6254: }
6255: }
6256: $resulttext .= '</ul>';
6257: } else {
1.3 raeburn 6258: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6259: }
6260: } else {
1.11 albertel 6261: $resulttext = '<span class="LC_error">'.
6262: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6263: }
1.3 raeburn 6264: return $resulttext;
1.1 raeburn 6265: }
6266:
1.125 raeburn 6267: sub modify_autocreate {
6268: my ($dom,%domconfig) = @_;
6269: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6270: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6271: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6272: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6273: }
6274: }
6275: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6276: req => 'Auto-creation of validated requests for official courses',
6277: xmldc => 'Identity of course creator of courses from XML files',
6278: );
6279: my @types = ('xml','req');
6280: foreach my $item (@types) {
6281: $newvals{$item} = $env{'form.autocreate_'.$item};
6282: $newvals{$item} =~ s/\D//g;
6283: $newvals{$item} = 0 if ($newvals{$item} eq '');
6284: }
6285: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6286: my %domcoords = &get_active_dcs($dom);
6287: unless (exists($domcoords{$newvals{'xmldc'}})) {
6288: $newvals{'xmldc'} = '';
6289: }
6290: %autocreatehash = (
6291: autocreate => { xml => $newvals{'xml'},
6292: req => $newvals{'req'},
6293: }
6294: );
6295: if ($newvals{'xmldc'} ne '') {
6296: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6297: }
6298: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6299: $dom);
6300: if ($putresult eq 'ok') {
6301: my @items = @types;
6302: if ($newvals{'xml'}) {
6303: push(@items,'xmldc');
6304: }
6305: foreach my $item (@items) {
6306: if (exists($currautocreate{$item})) {
6307: if ($currautocreate{$item} ne $newvals{$item}) {
6308: $changes{$item} = 1;
6309: }
6310: } elsif ($newvals{$item}) {
6311: $changes{$item} = 1;
6312: }
6313: }
6314: if (keys(%changes) > 0) {
6315: my @offon = ('off','on');
6316: $resulttext = &mt('Changes made:').'<ul>';
6317: foreach my $item (@types) {
6318: if ($changes{$item}) {
6319: my $newtxt = $offon[$newvals{$item}];
1.178 ! raeburn 6320: $resulttext .= '<li>'.
! 6321: &mt("$title{$item} set to [_1]$newtxt [_2]",
! 6322: '<b>','</b>').
! 6323: '</li>';
1.125 raeburn 6324: }
6325: }
6326: if ($changes{'xmldc'}) {
6327: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6328: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 ! raeburn 6329: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6330: }
6331: $resulttext .= '</ul>';
6332: } else {
6333: $resulttext = &mt('No changes made to auto-creation settings');
6334: }
6335: } else {
6336: $resulttext = '<span class="LC_error">'.
6337: &mt('An error occurred: [_1]',$putresult).'</span>';
6338: }
6339: return $resulttext;
6340: }
6341:
1.23 raeburn 6342: sub modify_directorysrch {
6343: my ($dom,%domconfig) = @_;
6344: my ($resulttext,%changes);
6345: my %currdirsrch;
6346: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6347: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6348: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6349: }
6350: }
6351: my %title = ( available => 'Directory search available',
1.24 raeburn 6352: localonly => 'Other domains can search',
1.23 raeburn 6353: searchby => 'Search types',
6354: searchtypes => 'Search latitude');
6355: my @offon = ('off','on');
1.24 raeburn 6356: my @otherdoms = ('Yes','No');
1.23 raeburn 6357:
1.25 raeburn 6358: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6359: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6360: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6361:
1.44 raeburn 6362: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6363: if (keys(%{$usertypes}) == 0) {
6364: @cansearch = ('default');
6365: } else {
6366: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6367: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6368: if (!grep(/^\Q$type\E$/,@cansearch)) {
6369: push(@{$changes{'cansearch'}},$type);
6370: }
1.23 raeburn 6371: }
1.26 raeburn 6372: foreach my $type (@cansearch) {
6373: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6374: push(@{$changes{'cansearch'}},$type);
6375: }
1.23 raeburn 6376: }
1.26 raeburn 6377: } else {
6378: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6379: }
6380: }
6381:
6382: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6383: foreach my $by (@{$currdirsrch{'searchby'}}) {
6384: if (!grep(/^\Q$by\E$/,@searchby)) {
6385: push(@{$changes{'searchby'}},$by);
6386: }
6387: }
6388: foreach my $by (@searchby) {
6389: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6390: push(@{$changes{'searchby'}},$by);
6391: }
6392: }
6393: } else {
6394: push(@{$changes{'searchby'}},@searchby);
6395: }
1.25 raeburn 6396:
6397: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6398: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6399: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6400: push(@{$changes{'searchtypes'}},$type);
6401: }
6402: }
6403: foreach my $type (@searchtypes) {
6404: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6405: push(@{$changes{'searchtypes'}},$type);
6406: }
6407: }
6408: } else {
6409: if (exists($currdirsrch{'searchtypes'})) {
6410: foreach my $type (@searchtypes) {
6411: if ($type ne $currdirsrch{'searchtypes'}) {
6412: push(@{$changes{'searchtypes'}},$type);
6413: }
6414: }
6415: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6416: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6417: }
6418: } else {
6419: push(@{$changes{'searchtypes'}},@searchtypes);
6420: }
6421: }
6422:
1.23 raeburn 6423: my %dirsrch_hash = (
6424: directorysrch => { available => $env{'form.dirsrch_available'},
6425: cansearch => \@cansearch,
1.24 raeburn 6426: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6427: searchby => \@searchby,
1.25 raeburn 6428: searchtypes => \@searchtypes,
1.23 raeburn 6429: }
6430: );
6431: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6432: $dom);
6433: if ($putresult eq 'ok') {
6434: if (exists($currdirsrch{'available'})) {
6435: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6436: $changes{'available'} = 1;
6437: }
6438: } else {
6439: if ($env{'form.dirsrch_available'} eq '1') {
6440: $changes{'available'} = 1;
6441: }
6442: }
1.24 raeburn 6443: if (exists($currdirsrch{'localonly'})) {
6444: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6445: $changes{'localonly'} = 1;
6446: }
6447: } else {
6448: if ($env{'form.dirsrch_localonly'} eq '1') {
6449: $changes{'localonly'} = 1;
6450: }
6451: }
1.23 raeburn 6452: if (keys(%changes) > 0) {
6453: $resulttext = &mt('Changes made:').'<ul>';
6454: if ($changes{'available'}) {
6455: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6456: }
1.24 raeburn 6457: if ($changes{'localonly'}) {
6458: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6459: }
6460:
1.23 raeburn 6461: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6462: my $chgtext;
1.26 raeburn 6463: if (ref($usertypes) eq 'HASH') {
6464: if (keys(%{$usertypes}) > 0) {
6465: foreach my $type (@{$types}) {
6466: if (grep(/^\Q$type\E$/,@cansearch)) {
6467: $chgtext .= $usertypes->{$type}.'; ';
6468: }
6469: }
6470: if (grep(/^default$/,@cansearch)) {
6471: $chgtext .= $othertitle;
6472: } else {
6473: $chgtext =~ s/\; $//;
6474: }
1.178 ! raeburn 6475: $resulttext .=
! 6476: '<li>'.
! 6477: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
! 6478: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
! 6479: '</li>';
1.23 raeburn 6480: }
6481: }
6482: }
6483: if (ref($changes{'searchby'}) eq 'ARRAY') {
6484: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6485: my $chgtext;
6486: foreach my $type (@{$titleorder}) {
6487: if (grep(/^\Q$type\E$/,@searchby)) {
6488: if (defined($searchtitles->{$type})) {
6489: $chgtext .= $searchtitles->{$type}.'; ';
6490: }
6491: }
6492: }
6493: $chgtext =~ s/\; $//;
6494: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6495: }
1.25 raeburn 6496: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6497: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6498: my $chgtext;
6499: foreach my $type (@{$srchtypeorder}) {
6500: if (grep(/^\Q$type\E$/,@searchtypes)) {
6501: if (defined($srchtypes_desc->{$type})) {
6502: $chgtext .= $srchtypes_desc->{$type}.'; ';
6503: }
6504: }
6505: }
6506: $chgtext =~ s/\; $//;
1.178 ! raeburn 6507: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6508: }
6509: $resulttext .= '</ul>';
6510: } else {
6511: $resulttext = &mt('No changes made to institution directory search settings');
6512: }
6513: } else {
6514: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6515: &mt('An error occurred: [_1]',$putresult).'</span>';
6516: }
6517: return $resulttext;
6518: }
6519:
1.28 raeburn 6520: sub modify_contacts {
6521: my ($dom,%domconfig) = @_;
6522: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6523: if (ref($domconfig{'contacts'}) eq 'HASH') {
6524: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6525: $currsetting{$key} = $domconfig{'contacts'}{$key};
6526: }
6527: }
1.134 raeburn 6528: my (%others,%to,%bcc);
1.28 raeburn 6529: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6530: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6531: 'requestsmail');
1.28 raeburn 6532: foreach my $type (@mailings) {
6533: @{$newsetting{$type}} =
6534: &Apache::loncommon::get_env_multiple('form.'.$type);
6535: foreach my $item (@contacts) {
6536: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6537: $contacts_hash{contacts}{$type}{$item} = 1;
6538: } else {
6539: $contacts_hash{contacts}{$type}{$item} = 0;
6540: }
6541: }
6542: $others{$type} = $env{'form.'.$type.'_others'};
6543: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6544: if ($type eq 'helpdeskmail') {
6545: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6546: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6547: }
1.28 raeburn 6548: }
6549: foreach my $item (@contacts) {
6550: $to{$item} = $env{'form.'.$item};
6551: $contacts_hash{'contacts'}{$item} = $to{$item};
6552: }
6553: if (keys(%currsetting) > 0) {
6554: foreach my $item (@contacts) {
6555: if ($to{$item} ne $currsetting{$item}) {
6556: $changes{$item} = 1;
6557: }
6558: }
6559: foreach my $type (@mailings) {
6560: foreach my $item (@contacts) {
6561: if (ref($currsetting{$type}) eq 'HASH') {
6562: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6563: push(@{$changes{$type}},$item);
6564: }
6565: } else {
6566: push(@{$changes{$type}},@{$newsetting{$type}});
6567: }
6568: }
6569: if ($others{$type} ne $currsetting{$type}{'others'}) {
6570: push(@{$changes{$type}},'others');
6571: }
1.134 raeburn 6572: if ($type eq 'helpdeskmail') {
6573: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6574: push(@{$changes{$type}},'bcc');
6575: }
6576: }
1.28 raeburn 6577: }
6578: } else {
6579: my %default;
6580: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6581: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6582: $default{'errormail'} = 'adminemail';
6583: $default{'packagesmail'} = 'adminemail';
6584: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6585: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6586: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6587: foreach my $item (@contacts) {
6588: if ($to{$item} ne $default{$item}) {
6589: $changes{$item} = 1;
6590: }
6591: }
6592: foreach my $type (@mailings) {
6593: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6594:
6595: push(@{$changes{$type}},@{$newsetting{$type}});
6596: }
6597: if ($others{$type} ne '') {
6598: push(@{$changes{$type}},'others');
1.134 raeburn 6599: }
6600: if ($type eq 'helpdeskmail') {
6601: if ($bcc{$type} ne '') {
6602: push(@{$changes{$type}},'bcc');
6603: }
6604: }
1.28 raeburn 6605: }
6606: }
6607: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6608: $dom);
6609: if ($putresult eq 'ok') {
6610: if (keys(%changes) > 0) {
6611: my ($titles,$short_titles) = &contact_titles();
6612: $resulttext = &mt('Changes made:').'<ul>';
6613: foreach my $item (@contacts) {
6614: if ($changes{$item}) {
6615: $resulttext .= '<li>'.$titles->{$item}.
6616: &mt(' set to: ').
6617: '<span class="LC_cusr_emph">'.
6618: $to{$item}.'</span></li>';
6619: }
6620: }
6621: foreach my $type (@mailings) {
6622: if (ref($changes{$type}) eq 'ARRAY') {
6623: $resulttext .= '<li>'.$titles->{$type}.': ';
6624: my @text;
6625: foreach my $item (@{$newsetting{$type}}) {
6626: push(@text,$short_titles->{$item});
6627: }
6628: if ($others{$type} ne '') {
6629: push(@text,$others{$type});
6630: }
6631: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6632: join(', ',@text).'</span>';
6633: if ($type eq 'helpdeskmail') {
6634: if ($bcc{$type} ne '') {
6635: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6636: }
6637: }
6638: $resulttext .= '</li>';
1.28 raeburn 6639: }
6640: }
6641: $resulttext .= '</ul>';
6642: } else {
1.34 raeburn 6643: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6644: }
6645: } else {
6646: $resulttext = '<span class="LC_error">'.
6647: &mt('An error occurred: [_1].',$putresult).'</span>';
6648: }
6649: return $resulttext;
6650: }
6651:
6652: sub modify_usercreation {
1.27 raeburn 6653: my ($dom,%domconfig) = @_;
1.34 raeburn 6654: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6655: my $warningmsg;
1.27 raeburn 6656: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6657: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6658: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6659: }
6660: }
6661: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6662: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6663: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6664: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6665: foreach my $item(@contexts) {
1.45 raeburn 6666: if ($item eq 'selfcreate') {
1.50 raeburn 6667: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6668: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6669: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6670: if (ref($cancreate{$item}) eq 'ARRAY') {
6671: if (grep(/^login$/,@{$cancreate{$item}})) {
6672: $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.');
6673: }
1.43 raeburn 6674: }
6675: }
1.50 raeburn 6676: } else {
6677: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6678: }
1.34 raeburn 6679: }
1.93 raeburn 6680: my ($othertitle,$usertypes,$types) =
6681: &Apache::loncommon::sorted_inst_types($dom);
6682: if (ref($types) eq 'ARRAY') {
6683: if (@{$types} > 0) {
6684: @{$cancreate{'statustocreate'}} =
6685: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6686: } else {
6687: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6688: }
6689: push(@contexts,'statustocreate');
6690: }
1.165 raeburn 6691: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6692: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6693: foreach my $item (@contexts) {
1.93 raeburn 6694: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6695: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6696: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6697: if (ref($cancreate{$item}) eq 'ARRAY') {
6698: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6699: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6700: push(@{$changes{'cancreate'}},$item);
6701: }
1.50 raeburn 6702: }
6703: }
6704: }
6705: } else {
6706: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6707: if (@{$cancreate{$item}} > 0) {
6708: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6709: push(@{$changes{'cancreate'}},$item);
6710: }
6711: }
6712: } else {
6713: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6714: if (@{$cancreate{$item}} < 3) {
6715: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6716: push(@{$changes{'cancreate'}},$item);
6717: }
6718: }
6719: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6720: if (@{$cancreate{$item}} > 0) {
6721: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6722: push(@{$changes{'cancreate'}},$item);
6723: }
6724: }
6725: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6726: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6727: push(@{$changes{'cancreate'}},$item);
6728: }
6729: }
6730: }
6731: }
6732: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6733: foreach my $type (@{$cancreate{$item}}) {
6734: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6735: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6736: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6737: push(@{$changes{'cancreate'}},$item);
6738: }
6739: }
6740: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6741: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6742: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6743: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6744: push(@{$changes{'cancreate'}},$item);
6745: }
6746: }
6747: }
6748: }
6749: }
6750: } else {
6751: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6752: push(@{$changes{'cancreate'}},$item);
6753: }
6754: }
1.27 raeburn 6755: }
1.34 raeburn 6756: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6757: foreach my $item (@contexts) {
1.43 raeburn 6758: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6759: if ($cancreate{$item} ne 'any') {
6760: push(@{$changes{'cancreate'}},$item);
6761: }
6762: } else {
6763: if ($cancreate{$item} ne 'none') {
6764: push(@{$changes{'cancreate'}},$item);
6765: }
1.27 raeburn 6766: }
6767: }
6768: } else {
1.43 raeburn 6769: foreach my $item (@contexts) {
1.34 raeburn 6770: push(@{$changes{'cancreate'}},$item);
6771: }
1.27 raeburn 6772: }
1.34 raeburn 6773:
1.27 raeburn 6774: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6775: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6776: if (!grep(/^\Q$type\E$/,@username_rule)) {
6777: push(@{$changes{'username_rule'}},$type);
6778: }
6779: }
6780: foreach my $type (@username_rule) {
6781: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6782: push(@{$changes{'username_rule'}},$type);
6783: }
6784: }
6785: } else {
6786: push(@{$changes{'username_rule'}},@username_rule);
6787: }
6788:
1.32 raeburn 6789: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6790: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6791: if (!grep(/^\Q$type\E$/,@id_rule)) {
6792: push(@{$changes{'id_rule'}},$type);
6793: }
6794: }
6795: foreach my $type (@id_rule) {
6796: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6797: push(@{$changes{'id_rule'}},$type);
6798: }
6799: }
6800: } else {
6801: push(@{$changes{'id_rule'}},@id_rule);
6802: }
6803:
1.43 raeburn 6804: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6805: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6806: if (!grep(/^\Q$type\E$/,@email_rule)) {
6807: push(@{$changes{'email_rule'}},$type);
6808: }
6809: }
6810: foreach my $type (@email_rule) {
6811: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6812: push(@{$changes{'email_rule'}},$type);
6813: }
6814: }
6815: } else {
6816: push(@{$changes{'email_rule'}},@email_rule);
6817: }
6818:
6819: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6820: my @authtypes = ('int','krb4','krb5','loc');
6821: my %authhash;
1.43 raeburn 6822: foreach my $item (@authen_contexts) {
1.28 raeburn 6823: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6824: foreach my $auth (@authtypes) {
6825: if (grep(/^\Q$auth\E$/,@authallowed)) {
6826: $authhash{$item}{$auth} = 1;
6827: } else {
6828: $authhash{$item}{$auth} = 0;
6829: }
6830: }
6831: }
6832: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6833: foreach my $item (@authen_contexts) {
1.28 raeburn 6834: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6835: foreach my $auth (@authtypes) {
6836: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6837: push(@{$changes{'authtypes'}},$item);
6838: last;
6839: }
6840: }
6841: }
6842: }
6843: } else {
1.43 raeburn 6844: foreach my $item (@authen_contexts) {
1.28 raeburn 6845: push(@{$changes{'authtypes'}},$item);
6846: }
6847: }
6848:
1.27 raeburn 6849: my %usercreation_hash = (
1.28 raeburn 6850: usercreation => {
1.34 raeburn 6851: cancreate => \%cancreate,
1.27 raeburn 6852: username_rule => \@username_rule,
1.32 raeburn 6853: id_rule => \@id_rule,
1.43 raeburn 6854: email_rule => \@email_rule,
1.32 raeburn 6855: authtypes => \%authhash,
1.27 raeburn 6856: }
6857: );
6858:
6859: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6860: $dom);
1.50 raeburn 6861:
6862: my %selfcreatetypes = (
6863: sso => 'users authenticated by institutional single sign on',
6864: login => 'users authenticated by institutional log-in',
6865: email => 'users who provide a valid e-mail address for use as the username',
6866: );
1.27 raeburn 6867: if ($putresult eq 'ok') {
6868: if (keys(%changes) > 0) {
6869: $resulttext = &mt('Changes made:').'<ul>';
6870: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6871: my %lt = &usercreation_types();
6872: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6873: my $chgtext;
1.165 raeburn 6874: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6875: $chgtext = $lt{$type}.', ';
6876: }
1.45 raeburn 6877: if ($type eq 'selfcreate') {
1.50 raeburn 6878: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6879: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6880: } else {
1.100 raeburn 6881: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6882: foreach my $case (@{$cancreate{$type}}) {
6883: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6884: }
6885: $chgtext .= '</ul>';
1.100 raeburn 6886: if (ref($cancreate{$type}) eq 'ARRAY') {
6887: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6888: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6889: if (@{$cancreate{'statustocreate'}} == 0) {
6890: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6891: }
6892: }
6893: }
6894: }
1.43 raeburn 6895: }
1.93 raeburn 6896: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6897: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6898: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6899: if (@{$cancreate{'selfcreate'}} > 0) {
6900: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6901:
6902: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6903: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6904: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6905: }
1.96 raeburn 6906: } elsif (ref($usertypes) eq 'HASH') {
6907: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6908: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6909: } else {
6910: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6911: }
6912: $chgtext .= '<ul>';
6913: foreach my $case (@{$cancreate{$type}}) {
6914: if ($case eq 'default') {
6915: $chgtext .= '<li>'.$othertitle.'</li>';
6916: } else {
6917: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6918: }
6919: }
1.100 raeburn 6920: $chgtext .= '</ul>';
6921: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6922: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6923: }
6924: }
6925: } else {
6926: if (@{$cancreate{$type}} == 0) {
6927: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6928: } else {
6929: $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 6930: }
6931: }
6932: }
1.165 raeburn 6933: } elsif ($type eq 'captcha') {
6934: if ($cancreate{$type} eq 'notused') {
6935: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6936: } else {
6937: my %captchas = &captcha_phrases();
6938: if ($captchas{$cancreate{$type}}) {
6939: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6940: } else {
6941: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6942: }
6943: }
6944: } elsif ($type eq 'recaptchakeys') {
6945: my ($privkey,$pubkey);
6946: if (ref($cancreate{$type}) eq 'HASH') {
6947: $pubkey = $cancreate{$type}{'public'};
6948: $privkey = $cancreate{$type}{'private'};
6949: }
6950: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6951: if (!$pubkey) {
6952: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6953: } else {
6954: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6955: }
6956: if (!$privkey) {
6957: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6958: } else {
6959: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6960: }
6961: $chgtext .= '</ul>';
1.43 raeburn 6962: } else {
6963: if ($cancreate{$type} eq 'none') {
6964: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6965: } elsif ($cancreate{$type} eq 'any') {
6966: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6967: } elsif ($cancreate{$type} eq 'official') {
6968: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6969: } elsif ($cancreate{$type} eq 'unofficial') {
6970: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6971: }
1.34 raeburn 6972: }
6973: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6974: }
6975: }
6976: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6977: my ($rules,$ruleorder) =
6978: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6979: my $chgtext = '<ul>';
6980: foreach my $type (@username_rule) {
6981: if (ref($rules->{$type}) eq 'HASH') {
6982: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6983: }
6984: }
6985: $chgtext .= '</ul>';
6986: if (@username_rule > 0) {
6987: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6988: } else {
1.28 raeburn 6989: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6990: }
6991: }
1.32 raeburn 6992: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6993: my ($idrules,$idruleorder) =
6994: &Apache::lonnet::inst_userrules($dom,'id');
6995: my $chgtext = '<ul>';
6996: foreach my $type (@id_rule) {
6997: if (ref($idrules->{$type}) eq 'HASH') {
6998: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6999: }
7000: }
7001: $chgtext .= '</ul>';
7002: if (@id_rule > 0) {
7003: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7004: } else {
7005: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7006: }
7007: }
1.43 raeburn 7008: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7009: my ($emailrules,$emailruleorder) =
7010: &Apache::lonnet::inst_userrules($dom,'email');
7011: my $chgtext = '<ul>';
7012: foreach my $type (@email_rule) {
7013: if (ref($emailrules->{$type}) eq 'HASH') {
7014: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7015: }
7016: }
7017: $chgtext .= '</ul>';
7018: if (@email_rule > 0) {
7019: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7020: } else {
7021: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7022: }
7023: }
7024:
1.28 raeburn 7025: my %authname = &authtype_names();
7026: my %context_title = &context_names();
7027: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7028: my $chgtext = '<ul>';
7029: foreach my $type (@{$changes{'authtypes'}}) {
7030: my @allowed;
7031: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7032: foreach my $auth (@authtypes) {
7033: if ($authhash{$type}{$auth}) {
7034: push(@allowed,$authname{$auth});
7035: }
7036: }
1.43 raeburn 7037: if (@allowed > 0) {
7038: $chgtext .= join(', ',@allowed).'</li>';
7039: } else {
7040: $chgtext .= &mt('none').'</li>';
7041: }
1.28 raeburn 7042: }
7043: $chgtext .= '</ul>';
7044: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7045: $resulttext .= '</li>';
7046: }
1.27 raeburn 7047: $resulttext .= '</ul>';
7048: } else {
1.28 raeburn 7049: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7050: }
7051: } else {
7052: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7053: &mt('An error occurred: [_1]',$putresult).'</span>';
7054: }
1.43 raeburn 7055: if ($warningmsg ne '') {
7056: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7057: }
1.23 raeburn 7058: return $resulttext;
7059: }
7060:
1.165 raeburn 7061: sub process_captcha {
7062: my ($container,$changes,$newsettings,$current) = @_;
7063: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7064: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7065: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7066: $newsettings->{'captcha'} = 'original';
7067: }
7068: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7069: if ($container eq 'cancreate') {
7070: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7071: push(@{$changes->{'cancreate'}},'captcha');
7072: } elsif (!defined($changes->{'cancreate'})) {
7073: $changes->{'cancreate'} = ['captcha'];
7074: }
7075: } else {
7076: $changes->{'captcha'} = 1;
1.165 raeburn 7077: }
7078: }
7079: my ($newpub,$newpriv,$currpub,$currpriv);
7080: if ($newsettings->{'captcha'} eq 'recaptcha') {
7081: $newpub = $env{'form.'.$container.'_recaptchapub'};
7082: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7083: $newpub =~ s/\W//g;
7084: $newpriv =~ s/\W//g;
7085: $newsettings->{'recaptchakeys'} = {
7086: public => $newpub,
7087: private => $newpriv,
7088: };
1.165 raeburn 7089: }
7090: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7091: $currpub = $current->{'recaptchakeys'}{'public'};
7092: $currpriv = $current->{'recaptchakeys'}{'private'};
1.169 raeburn 7093: $newsettings->{'recaptchakeys'} = {
7094: public => '',
7095: private => '',
7096: }
1.165 raeburn 7097: }
7098: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7099: if ($container eq 'cancreate') {
7100: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7101: push(@{$changes->{'cancreate'}},'recaptchakeys');
7102: } elsif (!defined($changes->{'cancreate'})) {
7103: $changes->{'cancreate'} = ['recaptchakeys'];
7104: }
7105: } else {
7106: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7107: }
7108: }
7109: return;
7110: }
7111:
1.33 raeburn 7112: sub modify_usermodification {
7113: my ($dom,%domconfig) = @_;
7114: my ($resulttext,%curr_usermodification,%changes);
7115: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7116: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7117: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7118: }
7119: }
1.63 raeburn 7120: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7121: my %context_title = (
7122: author => 'In author context',
7123: course => 'In course context',
1.63 raeburn 7124: selfcreate => 'When self creating account',
1.33 raeburn 7125: );
7126: my @fields = ('lastname','firstname','middlename','generation',
7127: 'permanentemail','id');
7128: my %roles = (
7129: author => ['ca','aa'],
7130: course => ['st','ep','ta','in','cr'],
7131: );
1.63 raeburn 7132: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7133: if (ref($types) eq 'ARRAY') {
7134: push(@{$types},'default');
7135: $usertypes->{'default'} = $othertitle;
7136: }
7137: $roles{'selfcreate'} = $types;
1.33 raeburn 7138: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7139: my %modifyhash;
7140: foreach my $context (@contexts) {
7141: foreach my $role (@{$roles{$context}}) {
7142: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7143: foreach my $item (@fields) {
7144: if (grep(/^\Q$item\E$/,@modifiable)) {
7145: $modifyhash{$context}{$role}{$item} = 1;
7146: } else {
7147: $modifyhash{$context}{$role}{$item} = 0;
7148: }
7149: }
7150: }
7151: if (ref($curr_usermodification{$context}) eq 'HASH') {
7152: foreach my $role (@{$roles{$context}}) {
7153: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7154: foreach my $field (@fields) {
7155: if ($modifyhash{$context}{$role}{$field} ne
7156: $curr_usermodification{$context}{$role}{$field}) {
7157: push(@{$changes{$context}},$role);
7158: last;
7159: }
7160: }
7161: }
7162: }
7163: } else {
7164: foreach my $context (@contexts) {
7165: foreach my $role (@{$roles{$context}}) {
7166: push(@{$changes{$context}},$role);
7167: }
7168: }
7169: }
7170: }
7171: my %usermodification_hash = (
7172: usermodification => \%modifyhash,
7173: );
7174: my $putresult = &Apache::lonnet::put_dom('configuration',
7175: \%usermodification_hash,$dom);
7176: if ($putresult eq 'ok') {
7177: if (keys(%changes) > 0) {
7178: $resulttext = &mt('Changes made: ').'<ul>';
7179: foreach my $context (@contexts) {
7180: if (ref($changes{$context}) eq 'ARRAY') {
7181: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7182: if (ref($changes{$context}) eq 'ARRAY') {
7183: foreach my $role (@{$changes{$context}}) {
7184: my $rolename;
1.63 raeburn 7185: if ($context eq 'selfcreate') {
7186: $rolename = $role;
7187: if (ref($usertypes) eq 'HASH') {
7188: if ($usertypes->{$role} ne '') {
7189: $rolename = $usertypes->{$role};
7190: }
7191: }
1.33 raeburn 7192: } else {
1.63 raeburn 7193: if ($role eq 'cr') {
7194: $rolename = &mt('Custom');
7195: } else {
7196: $rolename = &Apache::lonnet::plaintext($role);
7197: }
1.33 raeburn 7198: }
7199: my @modifiable;
1.63 raeburn 7200: if ($context eq 'selfcreate') {
1.126 bisitz 7201: $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 7202: } else {
7203: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7204: }
1.33 raeburn 7205: foreach my $field (@fields) {
7206: if ($modifyhash{$context}{$role}{$field}) {
7207: push(@modifiable,$fieldtitles{$field});
7208: }
7209: }
7210: if (@modifiable > 0) {
7211: $resulttext .= join(', ',@modifiable);
7212: } else {
7213: $resulttext .= &mt('none');
7214: }
7215: $resulttext .= '</li>';
7216: }
7217: $resulttext .= '</ul></li>';
7218: }
7219: }
7220: }
7221: $resulttext .= '</ul>';
7222: } else {
7223: $resulttext = &mt('No changes made to user modification settings');
7224: }
7225: } else {
7226: $resulttext = '<span class="LC_error">'.
7227: &mt('An error occurred: [_1]',$putresult).'</span>';
7228: }
7229: return $resulttext;
7230: }
7231:
1.43 raeburn 7232: sub modify_defaults {
7233: my ($dom,$r) = @_;
7234: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7235: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7236: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7237: my @authtypes = ('internal','krb4','krb5','localauth');
7238: foreach my $item (@items) {
7239: $newvalues{$item} = $env{'form.'.$item};
7240: if ($item eq 'auth_def') {
7241: if ($newvalues{$item} ne '') {
7242: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7243: push(@errors,$item);
7244: }
7245: }
7246: } elsif ($item eq 'lang_def') {
7247: if ($newvalues{$item} ne '') {
7248: if ($newvalues{$item} =~ /^(\w+)/) {
7249: my $langcode = $1;
1.103 raeburn 7250: if ($langcode ne 'x_chef') {
7251: if (code2language($langcode) eq '') {
7252: push(@errors,$item);
7253: }
1.43 raeburn 7254: }
7255: } else {
7256: push(@errors,$item);
7257: }
7258: }
1.54 raeburn 7259: } elsif ($item eq 'timezone_def') {
7260: if ($newvalues{$item} ne '') {
1.62 raeburn 7261: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7262: push(@errors,$item);
7263: }
7264: }
1.68 raeburn 7265: } elsif ($item eq 'datelocale_def') {
7266: if ($newvalues{$item} ne '') {
7267: my @datelocale_ids = DateTime::Locale->ids();
7268: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7269: push(@errors,$item);
7270: }
7271: }
1.141 raeburn 7272: } elsif ($item eq 'portal_def') {
7273: if ($newvalues{$item} ne '') {
7274: 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])\/?$/) {
7275: push(@errors,$item);
7276: }
7277: }
1.43 raeburn 7278: }
7279: if (grep(/^\Q$item\E$/,@errors)) {
7280: $newvalues{$item} = $domdefaults{$item};
7281: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7282: $changes{$item} = 1;
7283: }
1.72 raeburn 7284: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7285: }
7286: my %defaults_hash = (
1.72 raeburn 7287: defaults => \%newvalues,
7288: );
1.43 raeburn 7289: my $title = &defaults_titles();
7290: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7291: $dom);
7292: if ($putresult eq 'ok') {
7293: if (keys(%changes) > 0) {
7294: $resulttext = &mt('Changes made:').'<ul>';
7295: my $version = $r->dir_config('lonVersion');
7296: 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";
7297: foreach my $item (sort(keys(%changes))) {
7298: my $value = $env{'form.'.$item};
7299: if ($value eq '') {
7300: $value = &mt('none');
7301: } elsif ($item eq 'auth_def') {
7302: my %authnames = &authtype_names();
7303: my %shortauth = (
7304: internal => 'int',
7305: krb4 => 'krb4',
7306: krb5 => 'krb5',
7307: localauth => 'loc',
7308: );
7309: $value = $authnames{$shortauth{$value}};
7310: }
7311: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7312: $mailmsgtext .= "$title->{$item} set to $value\n";
7313: }
7314: $resulttext .= '</ul>';
7315: $mailmsgtext .= "\n";
7316: my $cachetime = 24*60*60;
1.72 raeburn 7317: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7318: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7319: my $sysmail = $r->dir_config('lonSysEMail');
7320: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7321: }
1.43 raeburn 7322: } else {
1.54 raeburn 7323: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7324: }
7325: } else {
7326: $resulttext = '<span class="LC_error">'.
7327: &mt('An error occurred: [_1]',$putresult).'</span>';
7328: }
7329: if (@errors > 0) {
7330: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7331: foreach my $item (@errors) {
7332: $resulttext .= ' "'.$title->{$item}.'",';
7333: }
7334: $resulttext =~ s/,$//;
7335: }
7336: return $resulttext;
7337: }
7338:
1.46 raeburn 7339: sub modify_scantron {
1.48 raeburn 7340: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7341: my ($resulttext,%confhash,%changes,$errors);
7342: my $custom = 'custom.tab';
7343: my $default = 'default.tab';
7344: my $servadm = $r->dir_config('lonAdmEMail');
7345: my ($configuserok,$author_ok,$switchserver) =
7346: &config_check($dom,$confname,$servadm);
7347: if ($env{'form.scantronformat.filename'} ne '') {
7348: my $error;
7349: if ($configuserok eq 'ok') {
7350: if ($switchserver) {
1.130 raeburn 7351: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7352: } else {
7353: if ($author_ok eq 'ok') {
7354: my ($result,$scantronurl) =
7355: &publishlogo($r,'upload','scantronformat',$dom,
7356: $confname,'scantron','','',$custom);
7357: if ($result eq 'ok') {
7358: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7359: $changes{'scantronformat'} = 1;
1.46 raeburn 7360: } else {
7361: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7362: }
7363: } else {
7364: $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);
7365: }
7366: }
7367: } else {
7368: $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);
7369: }
7370: if ($error) {
7371: &Apache::lonnet::logthis($error);
7372: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7373: }
7374: }
1.48 raeburn 7375: if (ref($domconfig{'scantron'}) eq 'HASH') {
7376: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7377: if ($env{'form.scantronformat_del'}) {
7378: $confhash{'scantron'}{'scantronformat'} = '';
7379: $changes{'scantronformat'} = 1;
1.46 raeburn 7380: }
7381: }
7382: }
7383: if (keys(%confhash) > 0) {
7384: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7385: $dom);
7386: if ($putresult eq 'ok') {
7387: if (keys(%changes) > 0) {
1.48 raeburn 7388: if (ref($confhash{'scantron'}) eq 'HASH') {
7389: $resulttext = &mt('Changes made:').'<ul>';
7390: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7391: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7392: } else {
1.130 raeburn 7393: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7394: }
1.48 raeburn 7395: $resulttext .= '</ul>';
7396: } else {
1.130 raeburn 7397: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7398: }
7399: $resulttext .= '</ul>';
7400: &Apache::loncommon::devalidate_domconfig_cache($dom);
7401: } else {
1.130 raeburn 7402: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7403: }
7404: } else {
7405: $resulttext = '<span class="LC_error">'.
7406: &mt('An error occurred: [_1]',$putresult).'</span>';
7407: }
7408: } else {
1.130 raeburn 7409: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7410: }
7411: if ($errors) {
7412: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7413: $errors.'</ul>';
7414: }
7415: return $resulttext;
7416: }
7417:
1.48 raeburn 7418: sub modify_coursecategories {
7419: my ($dom,%domconfig) = @_;
1.57 raeburn 7420: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7421: $cathash);
1.48 raeburn 7422: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7423: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7424: $cathash = $domconfig{'coursecategories'}{'cats'};
7425: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7426: $changes{'togglecats'} = 1;
7427: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7428: }
7429: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7430: $changes{'categorize'} = 1;
7431: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7432: }
1.120 raeburn 7433: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7434: $changes{'togglecatscomm'} = 1;
7435: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7436: }
7437: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7438: $changes{'categorizecomm'} = 1;
7439: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7440: }
1.57 raeburn 7441: } else {
7442: $changes{'togglecats'} = 1;
7443: $changes{'categorize'} = 1;
1.124 raeburn 7444: $changes{'togglecatscomm'} = 1;
7445: $changes{'categorizecomm'} = 1;
1.87 raeburn 7446: $domconfig{'coursecategories'} = {
7447: togglecats => $env{'form.togglecats'},
7448: categorize => $env{'form.categorize'},
1.124 raeburn 7449: togglecatscomm => $env{'form.togglecatscomm'},
7450: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7451: };
1.57 raeburn 7452: }
7453: if (ref($cathash) eq 'HASH') {
7454: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7455: push (@deletecategory,'instcode::0');
7456: }
1.120 raeburn 7457: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7458: push(@deletecategory,'communities::0');
7459: }
1.48 raeburn 7460: }
1.57 raeburn 7461: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7462: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7463: if (@deletecategory > 0) {
7464: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7465: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7466: foreach my $item (@deletecategory) {
1.57 raeburn 7467: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7468: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7469: $deletions{$item} = 1;
1.57 raeburn 7470: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7471: }
7472: }
7473: }
1.57 raeburn 7474: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7475: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7476: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7477: $reorderings{$item} = 1;
1.57 raeburn 7478: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7479: }
7480: if ($env{'form.addcategory_name_'.$item} ne '') {
7481: my $newcat = $env{'form.addcategory_name_'.$item};
7482: my $newdepth = $depth+1;
7483: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7484: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7485: $adds{$newitem} = 1;
7486: }
7487: if ($env{'form.subcat_'.$item} ne '') {
7488: my $newcat = $env{'form.subcat_'.$item};
7489: my $newdepth = $depth+1;
7490: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7491: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7492: $adds{$newitem} = 1;
7493: }
7494: }
7495: }
7496: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7497: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7498: my $newitem = 'instcode::0';
1.57 raeburn 7499: if ($cathash->{$newitem} eq '') {
7500: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7501: $adds{$newitem} = 1;
7502: }
7503: } else {
7504: my $newitem = 'instcode::0';
1.57 raeburn 7505: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7506: $adds{$newitem} = 1;
7507: }
7508: }
1.120 raeburn 7509: if ($env{'form.communities'} eq '1') {
7510: if (ref($cathash) eq 'HASH') {
7511: my $newitem = 'communities::0';
7512: if ($cathash->{$newitem} eq '') {
7513: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7514: $adds{$newitem} = 1;
7515: }
7516: } else {
7517: my $newitem = 'communities::0';
7518: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7519: $adds{$newitem} = 1;
7520: }
7521: }
1.48 raeburn 7522: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7523: if (($env{'form.addcategory_name'} ne 'instcode') &&
7524: ($env{'form.addcategory_name'} ne 'communities')) {
7525: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7526: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7527: $adds{$newitem} = 1;
7528: }
1.48 raeburn 7529: }
1.57 raeburn 7530: my $putresult;
1.48 raeburn 7531: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7532: if (keys(%deletions) > 0) {
7533: foreach my $key (keys(%deletions)) {
7534: if ($predelallitems{$key} ne '') {
7535: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7536: }
7537: }
7538: }
7539: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7540: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7541: if (ref($chkcats[0]) eq 'ARRAY') {
7542: my $depth = 0;
7543: my $chg = 0;
7544: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7545: my $name = $chkcats[0][$i];
7546: my $item;
7547: if ($name eq '') {
7548: $chg ++;
7549: } else {
7550: $item = &escape($name).'::0';
7551: if ($chg) {
1.57 raeburn 7552: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7553: }
7554: $depth ++;
1.57 raeburn 7555: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7556: $depth --;
7557: }
7558: }
7559: }
1.57 raeburn 7560: }
7561: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7562: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7563: if ($putresult eq 'ok') {
1.57 raeburn 7564: my %title = (
1.120 raeburn 7565: togglecats => 'Show/Hide a course in catalog',
7566: categorize => 'Assign a category to a course',
7567: togglecatscomm => 'Show/Hide a community in catalog',
7568: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7569: );
7570: my %level = (
1.120 raeburn 7571: dom => 'set in Domain ("Modify Course/Community")',
7572: crs => 'set in Course ("Course Configuration")',
7573: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7574: );
1.48 raeburn 7575: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7576: if ($changes{'togglecats'}) {
7577: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7578: }
7579: if ($changes{'categorize'}) {
7580: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7581: }
1.120 raeburn 7582: if ($changes{'togglecatscomm'}) {
7583: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7584: }
7585: if ($changes{'categorizecomm'}) {
7586: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7587: }
1.57 raeburn 7588: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7589: my $cathash;
7590: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7591: $cathash = $domconfig{'coursecategories'}{'cats'};
7592: } else {
7593: $cathash = {};
7594: }
7595: my (@cats,@trails,%allitems);
7596: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7597: if (keys(%deletions) > 0) {
7598: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7599: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7600: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7601: }
7602: $resulttext .= '</ul></li>';
7603: }
7604: if (keys(%reorderings) > 0) {
7605: my %sort_by_trail;
7606: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7607: foreach my $key (keys(%reorderings)) {
7608: if ($allitems{$key} ne '') {
7609: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7610: }
1.48 raeburn 7611: }
1.57 raeburn 7612: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7613: $resulttext .= '<li>'.$trails[$trail].'</li>';
7614: }
7615: $resulttext .= '</ul></li>';
1.48 raeburn 7616: }
1.57 raeburn 7617: if (keys(%adds) > 0) {
7618: my %sort_by_trail;
7619: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7620: foreach my $key (keys(%adds)) {
7621: if ($allitems{$key} ne '') {
7622: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7623: }
7624: }
7625: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7626: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7627: }
1.57 raeburn 7628: $resulttext .= '</ul></li>';
1.48 raeburn 7629: }
7630: }
7631: $resulttext .= '</ul>';
7632: } else {
7633: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7634: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7635: }
7636: } else {
1.120 raeburn 7637: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7638: }
7639: return $resulttext;
7640: }
7641:
1.69 raeburn 7642: sub modify_serverstatuses {
7643: my ($dom,%domconfig) = @_;
7644: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7645: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7646: %currserverstatus = %{$domconfig{'serverstatuses'}};
7647: }
7648: my @pages = &serverstatus_pages();
7649: foreach my $type (@pages) {
7650: $newserverstatus{$type}{'namedusers'} = '';
7651: $newserverstatus{$type}{'machines'} = '';
7652: if (defined($env{'form.'.$type.'_namedusers'})) {
7653: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7654: my @okusers;
7655: foreach my $user (@users) {
7656: my ($uname,$udom) = split(/:/,$user);
7657: if (($udom =~ /^$match_domain$/) &&
7658: (&Apache::lonnet::domain($udom)) &&
7659: ($uname =~ /^$match_username$/)) {
7660: if (!grep(/^\Q$user\E/,@okusers)) {
7661: push(@okusers,$user);
7662: }
7663: }
7664: }
7665: if (@okusers > 0) {
7666: @okusers = sort(@okusers);
7667: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7668: }
7669: }
7670: if (defined($env{'form.'.$type.'_machines'})) {
7671: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7672: my @okmachines;
7673: foreach my $ip (@machines) {
7674: my @parts = split(/\./,$ip);
7675: next if (@parts < 4);
7676: my $badip = 0;
7677: for (my $i=0; $i<4; $i++) {
7678: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7679: $badip = 1;
7680: last;
7681: }
7682: }
7683: if (!$badip) {
7684: push(@okmachines,$ip);
7685: }
7686: }
7687: @okmachines = sort(@okmachines);
7688: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7689: }
7690: }
7691: my %serverstatushash = (
7692: serverstatuses => \%newserverstatus,
7693: );
7694: foreach my $type (@pages) {
1.83 raeburn 7695: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7696: my (@current,@new);
1.83 raeburn 7697: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7698: if ($currserverstatus{$type}{$setting} ne '') {
7699: @current = split(/,/,$currserverstatus{$type}{$setting});
7700: }
7701: }
7702: if ($newserverstatus{$type}{$setting} ne '') {
7703: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7704: }
7705: if (@current > 0) {
7706: if (@new > 0) {
7707: foreach my $item (@current) {
7708: if (!grep(/^\Q$item\E$/,@new)) {
7709: $changes{$type}{$setting} = 1;
1.82 raeburn 7710: last;
7711: }
7712: }
1.84 raeburn 7713: foreach my $item (@new) {
7714: if (!grep(/^\Q$item\E$/,@current)) {
7715: $changes{$type}{$setting} = 1;
7716: last;
1.82 raeburn 7717: }
7718: }
7719: } else {
1.83 raeburn 7720: $changes{$type}{$setting} = 1;
1.69 raeburn 7721: }
1.83 raeburn 7722: } elsif (@new > 0) {
7723: $changes{$type}{$setting} = 1;
1.69 raeburn 7724: }
7725: }
7726: }
7727: if (keys(%changes) > 0) {
1.81 raeburn 7728: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7729: my $putresult = &Apache::lonnet::put_dom('configuration',
7730: \%serverstatushash,$dom);
7731: if ($putresult eq 'ok') {
7732: $resulttext .= &mt('Changes made:').'<ul>';
7733: foreach my $type (@pages) {
1.84 raeburn 7734: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7735: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7736: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7737: if ($newserverstatus{$type}{'namedusers'} eq '') {
7738: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7739: } else {
7740: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7741: }
1.84 raeburn 7742: }
7743: if ($changes{$type}{'machines'}) {
1.69 raeburn 7744: if ($newserverstatus{$type}{'machines'} eq '') {
7745: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7746: } else {
7747: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7748: }
7749:
7750: }
7751: $resulttext .= '</ul></li>';
7752: }
7753: }
7754: $resulttext .= '</ul>';
7755: } else {
7756: $resulttext = '<span class="LC_error">'.
7757: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7758:
7759: }
7760: } else {
7761: $resulttext = &mt('No changes made to access to server status pages');
7762: }
7763: return $resulttext;
7764: }
7765:
1.118 jms 7766: sub modify_helpsettings {
1.122 jms 7767: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7768: my ($resulttext,$errors,%changes,%helphash);
7769: my %defaultchecked = ('submitbugs' => 'on');
7770: my @offon = ('off','on');
1.118 jms 7771: my @toggles = ('submitbugs');
7772: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7773: foreach my $item (@toggles) {
1.166 raeburn 7774: if ($defaultchecked{$item} eq 'on') {
7775: if ($domconfig{'helpsettings'}{$item} eq '') {
7776: if ($env{'form.'.$item} eq '0') {
7777: $changes{$item} = 1;
7778: }
7779: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7780: $changes{$item} = 1;
7781: }
7782: } elsif ($defaultchecked{$item} eq 'off') {
7783: if ($domconfig{'helpsettings'}{$item} eq '') {
7784: if ($env{'form.'.$item} eq '1') {
7785: $changes{$item} = 1;
7786: }
7787: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7788: $changes{$item} = 1;
7789: }
7790: }
7791: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7792: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7793: }
7794: }
1.118 jms 7795: }
1.123 jms 7796: my $putresult;
7797: if (keys(%changes) > 0) {
1.166 raeburn 7798: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7799: if ($putresult eq 'ok') {
1.166 raeburn 7800: $resulttext = &mt('Changes made:').'<ul>';
7801: foreach my $item (sort(keys(%changes))) {
7802: if ($item eq 'submitbugs') {
7803: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7804: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7805: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7806: }
7807: }
7808: $resulttext .= '</ul>';
7809: } else {
7810: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7811: $errors .= '<li><span class="LC_error">'.
7812: &mt('An error occurred storing the settings: [_1]',
7813: $putresult).'</span></li>';
1.166 raeburn 7814: }
1.118 jms 7815: }
7816: if ($errors) {
1.168 raeburn 7817: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7818: $errors.'</ul>';
7819: }
7820: return $resulttext;
7821: }
7822:
1.121 raeburn 7823: sub modify_coursedefaults {
7824: my ($dom,%domconfig) = @_;
7825: my ($resulttext,$errors,%changes,%defaultshash);
7826: my %defaultchecked = ('canuse_pdfforms' => 'off');
7827: my @offon = ('off','on');
7828: my @toggles = ('canuse_pdfforms');
7829:
7830: $defaultshash{'coursedefaults'} = {};
7831:
7832: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7833: if ($domconfig{'coursedefaults'} eq '') {
7834: $domconfig{'coursedefaults'} = {};
7835: }
7836: }
7837:
7838: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7839: foreach my $item (@toggles) {
7840: if ($defaultchecked{$item} eq 'on') {
7841: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7842: ($env{'form.'.$item} eq '0')) {
7843: $changes{$item} = 1;
7844: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7845: $changes{$item} = 1;
7846: }
7847: } elsif ($defaultchecked{$item} eq 'off') {
7848: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7849: ($env{'form.'.$item} eq '1')) {
7850: $changes{$item} = 1;
7851: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7852: $changes{$item} = 1;
7853: }
7854: }
7855: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7856: }
1.139 raeburn 7857: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7858: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7859: $newdefresponder =~ s/\D//g;
7860: if ($newdefresponder eq '' || $newdefresponder < 1) {
7861: $newdefresponder = 1;
7862: }
7863: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7864: if ($currdefresponder ne $newdefresponder) {
7865: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7866: $changes{'anonsurvey_threshold'} = 1;
7867: }
7868: }
1.121 raeburn 7869: }
7870: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7871: $dom);
7872: if ($putresult eq 'ok') {
7873: if (keys(%changes) > 0) {
7874: if ($changes{'canuse_pdfforms'}) {
7875: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7876: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7877: my $cachetime = 24*60*60;
7878: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7879: }
7880: $resulttext = &mt('Changes made:').'<ul>';
7881: foreach my $item (sort(keys(%changes))) {
7882: if ($item eq 'canuse_pdfforms') {
7883: if ($env{'form.'.$item} eq '1') {
7884: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7885: } else {
7886: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7887: }
1.139 raeburn 7888: } elsif ($item eq 'anonsurvey_threshold') {
7889: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7890: }
1.121 raeburn 7891: }
7892: $resulttext .= '</ul>';
7893: } else {
7894: $resulttext = &mt('No changes made to course defaults');
7895: }
7896: } else {
7897: $resulttext = '<span class="LC_error">'.
7898: &mt('An error occurred: [_1]',$putresult).'</span>';
7899: }
7900: return $resulttext;
7901: }
7902:
1.137 raeburn 7903: sub modify_usersessions {
7904: my ($dom,%domconfig) = @_;
1.145 raeburn 7905: my @hostingtypes = ('version','excludedomain','includedomain');
7906: my @offloadtypes = ('primary','default');
7907: my %types = (
7908: remote => \@hostingtypes,
7909: hosted => \@hostingtypes,
7910: spares => \@offloadtypes,
7911: );
7912: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7913: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7914: my (%by_ip,%by_location,@intdoms);
7915: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7916: my @locations = sort(keys(%by_location));
1.137 raeburn 7917: my (%defaultshash,%changes);
7918: foreach my $prefix (@prefixes) {
7919: $defaultshash{'usersessions'}{$prefix} = {};
7920: }
7921: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7922: my $resulttext;
1.138 raeburn 7923: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7924: foreach my $prefix (@prefixes) {
1.145 raeburn 7925: next if ($prefix eq 'spares');
7926: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7927: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7928: if ($type eq 'version') {
7929: my $value = $env{'form.'.$prefix.'_'.$type};
7930: my $okvalue;
7931: if ($value ne '') {
7932: if (grep(/^\Q$value\E$/,@lcversions)) {
7933: $okvalue = $value;
7934: }
7935: }
7936: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7937: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7938: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7939: if ($inuse == 0) {
7940: $changes{$prefix}{$type} = 1;
7941: } else {
7942: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7943: $changes{$prefix}{$type} = 1;
7944: }
7945: if ($okvalue ne '') {
7946: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7947: }
7948: }
7949: } else {
7950: if (($inuse == 1) && ($okvalue ne '')) {
7951: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7952: $changes{$prefix}{$type} = 1;
7953: }
7954: }
7955: } else {
7956: if (($inuse == 1) && ($okvalue ne '')) {
7957: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7958: $changes{$prefix}{$type} = 1;
7959: }
7960: }
7961: } else {
7962: if (($inuse == 1) && ($okvalue ne '')) {
7963: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7964: $changes{$prefix}{$type} = 1;
7965: }
7966: }
7967: } else {
7968: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7969: my @okvals;
7970: foreach my $val (@vals) {
1.138 raeburn 7971: if ($val =~ /:/) {
7972: my @items = split(/:/,$val);
7973: foreach my $item (@items) {
7974: if (ref($by_location{$item}) eq 'ARRAY') {
7975: push(@okvals,$item);
7976: }
7977: }
7978: } else {
7979: if (ref($by_location{$val}) eq 'ARRAY') {
7980: push(@okvals,$val);
7981: }
1.137 raeburn 7982: }
7983: }
7984: @okvals = sort(@okvals);
7985: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7986: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7987: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7988: if ($inuse == 0) {
7989: $changes{$prefix}{$type} = 1;
7990: } else {
7991: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7992: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7993: if (@changed > 0) {
7994: $changes{$prefix}{$type} = 1;
7995: }
7996: }
7997: } else {
7998: if ($inuse == 1) {
7999: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8000: $changes{$prefix}{$type} = 1;
8001: }
8002: }
8003: } else {
8004: if ($inuse == 1) {
8005: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8006: $changes{$prefix}{$type} = 1;
8007: }
8008: }
8009: } else {
8010: if ($inuse == 1) {
8011: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8012: $changes{$prefix}{$type} = 1;
8013: }
8014: }
8015: }
8016: }
8017: }
1.145 raeburn 8018:
8019: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8020: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8021: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8022: my $savespares;
8023:
8024: foreach my $lonhost (sort(keys(%servers))) {
8025: my $serverhomeID =
8026: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8027: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8028: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8029: my %spareschg;
8030: foreach my $type (@{$types{'spares'}}) {
8031: my @okspares;
8032: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8033: foreach my $server (@checked) {
1.152 raeburn 8034: if (&Apache::lonnet::hostname($server) ne '') {
8035: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8036: unless (grep(/^\Q$server\E$/,@okspares)) {
8037: push(@okspares,$server);
8038: }
1.145 raeburn 8039: }
8040: }
8041: }
8042: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8043: my $newspare;
1.152 raeburn 8044: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8045: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8046: $newspare = $new;
8047: }
8048: }
1.152 raeburn 8049: my @spares;
8050: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8051: @spares = sort(@okspares,$newspare);
8052: } else {
8053: @spares = sort(@okspares);
8054: }
8055: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8056: if (ref($spareid{$lonhost}) eq 'HASH') {
8057: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8058: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8059: if (@diffs > 0) {
8060: $spareschg{$type} = 1;
8061: }
8062: }
8063: }
8064: }
8065: if (keys(%spareschg) > 0) {
8066: $changes{'spares'}{$lonhost} = \%spareschg;
8067: }
8068: }
8069:
8070: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8071: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8072: if (ref($changes{'spares'}) eq 'HASH') {
8073: if (keys(%{$changes{'spares'}}) > 0) {
8074: $savespares = 1;
8075: }
8076: }
8077: } else {
8078: $savespares = 1;
8079: }
8080: }
8081:
1.147 raeburn 8082: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8083: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8084: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8085: $dom);
8086: if ($putresult eq 'ok') {
8087: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8088: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8089: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8090: }
8091: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8092: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8093: }
8094: }
8095: my $cachetime = 24*60*60;
8096: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8097: if (keys(%changes) > 0) {
8098: my %lt = &usersession_titles();
8099: $resulttext = &mt('Changes made:').'<ul>';
8100: foreach my $prefix (@prefixes) {
8101: if (ref($changes{$prefix}) eq 'HASH') {
8102: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8103: if ($prefix eq 'spares') {
8104: if (ref($changes{$prefix}) eq 'HASH') {
8105: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8106: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8107: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8108: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8109: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8110: foreach my $type (@{$types{$prefix}}) {
8111: if ($changes{$prefix}{$lonhost}{$type}) {
8112: my $offloadto = &mt('None');
8113: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8114: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8115: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8116: }
1.145 raeburn 8117: }
1.147 raeburn 8118: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8119: }
1.137 raeburn 8120: }
8121: }
1.147 raeburn 8122: $resulttext .= '</li>';
1.137 raeburn 8123: }
8124: }
1.147 raeburn 8125: } else {
8126: foreach my $type (@{$types{$prefix}}) {
8127: if (defined($changes{$prefix}{$type})) {
8128: my $newvalue;
8129: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8130: if (ref($defaultshash{'usersessions'}{$prefix})) {
8131: if ($type eq 'version') {
8132: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8133: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8134: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8135: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8136: }
1.145 raeburn 8137: }
8138: }
8139: }
1.147 raeburn 8140: if ($newvalue eq '') {
8141: if ($type eq 'version') {
8142: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8143: } else {
8144: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8145: }
1.145 raeburn 8146: } else {
1.147 raeburn 8147: if ($type eq 'version') {
8148: $newvalue .= ' '.&mt('(or later)');
8149: }
8150: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8151: }
1.137 raeburn 8152: }
8153: }
8154: }
1.147 raeburn 8155: $resulttext .= '</ul>';
1.137 raeburn 8156: }
8157: }
1.147 raeburn 8158: $resulttext .= '</ul>';
8159: } else {
8160: $resulttext = $nochgmsg;
1.137 raeburn 8161: }
8162: } else {
8163: $resulttext = '<span class="LC_error">'.
8164: &mt('An error occurred: [_1]',$putresult).'</span>';
8165: }
8166: } else {
1.147 raeburn 8167: $resulttext = $nochgmsg;
1.137 raeburn 8168: }
8169: return $resulttext;
8170: }
8171:
1.150 raeburn 8172: sub modify_loadbalancing {
8173: my ($dom,%domconfig) = @_;
8174: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8175: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8176: my ($othertitle,$usertypes,$types) =
8177: &Apache::loncommon::sorted_inst_types($dom);
8178: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8179: my @sparestypes = ('primary','default');
8180: my %typetitles = &sparestype_titles();
8181: my $resulttext;
1.171 raeburn 8182: my (%currbalancer,%currtargets,%currrules,%existing);
8183: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8184: %existing = %{$domconfig{'loadbalancing'}};
8185: }
8186: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8187: \%currtargets,\%currrules);
8188: my ($saveloadbalancing,%defaultshash,%changes);
8189: my ($alltypes,$othertypes,$titles) =
8190: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8191: my %ruletitles = &offloadtype_text();
8192: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8193: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8194: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8195: if ($balancer eq '') {
8196: next;
8197: }
8198: if (!exists($servers{$balancer})) {
8199: if (exists($currbalancer{$balancer})) {
8200: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8201: }
1.171 raeburn 8202: next;
8203: }
8204: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8205: push(@{$changes{'delete'}},$balancer);
8206: next;
8207: }
8208: if (!exists($currbalancer{$balancer})) {
8209: push(@{$changes{'add'}},$balancer);
8210: }
8211: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8212: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8213: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8214: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8215: $saveloadbalancing = 1;
8216: }
8217: foreach my $sparetype (@sparestypes) {
8218: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8219: my @offloadto;
8220: foreach my $target (@targets) {
8221: if (($servers{$target}) && ($target ne $balancer)) {
8222: if ($sparetype eq 'default') {
8223: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8224: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8225: }
8226: }
1.171 raeburn 8227: unless(grep(/^\Q$target\E$/,@offloadto)) {
8228: push(@offloadto,$target);
8229: }
1.150 raeburn 8230: }
1.171 raeburn 8231: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8232: }
8233: }
1.171 raeburn 8234: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8235: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8236: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8237: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8238: if (@targetdiffs > 0) {
1.171 raeburn 8239: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8240: }
1.171 raeburn 8241: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8242: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8243: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8244: }
8245: }
8246: }
8247: } else {
1.171 raeburn 8248: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8249: foreach my $sparetype (@sparestypes) {
8250: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8251: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8252: $changes{'curr'}{$balancer}{'targets'} = 1;
8253: }
1.150 raeburn 8254: }
8255: }
8256: }
8257: }
8258: my $ishomedom;
1.171 raeburn 8259: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8260: $ishomedom = 1;
1.150 raeburn 8261: }
8262: if (ref($alltypes) eq 'ARRAY') {
8263: foreach my $type (@{$alltypes}) {
8264: my $rule;
1.171 raeburn 8265: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8266: (!$ishomedom)) {
1.171 raeburn 8267: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8268: }
8269: if ($rule eq 'specific') {
8270: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8271: }
1.171 raeburn 8272: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8273: if (ref($currrules{$balancer}) eq 'HASH') {
8274: if ($rule ne $currrules{$balancer}{$type}) {
8275: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8276: }
8277: } elsif ($rule ne '') {
1.171 raeburn 8278: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8279: }
8280: }
8281: }
1.171 raeburn 8282: }
8283: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8284: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8285: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8286: $defaultshash{'loadbalancing'} = {};
8287: }
8288: my $putresult = &Apache::lonnet::put_dom('configuration',
8289: \%defaultshash,$dom);
8290:
8291: if ($putresult eq 'ok') {
8292: if (keys(%changes) > 0) {
8293: if (ref($changes{'delete'}) eq 'ARRAY') {
8294: foreach my $balancer (sort(@{$changes{'delete'}})) {
8295: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8296: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8297: }
1.171 raeburn 8298: }
8299: if (ref($changes{'add'}) eq 'ARRAY') {
8300: foreach my $balancer (sort(@{$changes{'add'}})) {
8301: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8302: }
8303: }
8304: if (ref($changes{'curr'}) eq 'HASH') {
8305: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8306: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8307: if ($changes{'curr'}{$balancer}{'targets'}) {
8308: my %offloadstr;
8309: foreach my $sparetype (@sparestypes) {
8310: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8311: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8312: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8313: }
8314: }
1.150 raeburn 8315: }
1.171 raeburn 8316: if (keys(%offloadstr) == 0) {
8317: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8318: } else {
1.171 raeburn 8319: my $showoffload;
8320: foreach my $sparetype (@sparestypes) {
8321: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8322: if (defined($offloadstr{$sparetype})) {
8323: $showoffload .= $offloadstr{$sparetype};
8324: } else {
8325: $showoffload .= &mt('None');
8326: }
8327: $showoffload .= (' 'x3);
8328: }
8329: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8330: }
8331: }
8332: }
1.171 raeburn 8333: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8334: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8335: foreach my $type (@{$alltypes}) {
8336: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8337: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8338: my $balancetext;
8339: if ($rule eq '') {
8340: $balancetext = $ruletitles{'default'};
8341: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8342: $balancetext = $ruletitles{$rule};
8343: } else {
8344: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8345: }
8346: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8347: }
8348: }
8349: }
8350: }
1.171 raeburn 8351: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8352: }
1.171 raeburn 8353: }
8354: if ($resulttext ne '') {
8355: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8356: } else {
8357: $resulttext = $nochgmsg;
8358: }
8359: } else {
1.171 raeburn 8360: $resulttext = $nochgmsg;
1.150 raeburn 8361: }
8362: } else {
1.171 raeburn 8363: $resulttext = '<span class="LC_error">'.
8364: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8365: }
8366: } else {
1.171 raeburn 8367: $resulttext = $nochgmsg;
1.150 raeburn 8368: }
8369: return $resulttext;
8370: }
8371:
1.48 raeburn 8372: sub recurse_check {
8373: my ($chkcats,$categories,$depth,$name) = @_;
8374: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8375: my $chg = 0;
8376: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8377: my $category = $chkcats->[$depth]{$name}[$j];
8378: my $item;
8379: if ($category eq '') {
8380: $chg ++;
8381: } else {
8382: my $deeper = $depth + 1;
8383: $item = &escape($category).':'.&escape($name).':'.$depth;
8384: if ($chg) {
8385: $categories->{$item} -= $chg;
8386: }
8387: &recurse_check($chkcats,$categories,$deeper,$category);
8388: $deeper --;
8389: }
8390: }
8391: }
8392: return;
8393: }
8394:
8395: sub recurse_cat_deletes {
8396: my ($item,$coursecategories,$deletions) = @_;
8397: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8398: my $subdepth = $depth + 1;
8399: if (ref($coursecategories) eq 'HASH') {
8400: foreach my $subitem (keys(%{$coursecategories})) {
8401: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8402: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8403: delete($coursecategories->{$subitem});
8404: $deletions->{$subitem} = 1;
8405: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8406: }
1.48 raeburn 8407: }
8408: }
8409: return;
8410: }
8411:
1.125 raeburn 8412: sub get_active_dcs {
8413: my ($dom) = @_;
8414: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8415: my %domcoords;
8416: my $numdcs = 0;
8417: my $now = time;
8418: foreach my $server (keys(%dompersonnel)) {
8419: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8420: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8421: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8422: if (($end eq '') || ($end == 0) || ($end > $now)) {
8423: if ($start <= $now) {
8424: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8425: }
8426: }
8427: }
8428: }
8429: return %domcoords;
8430: }
8431:
8432: sub active_dc_picker {
8433: my ($dom,$curr_dc) = @_;
8434: my %domcoords = &get_active_dcs($dom);
8435: my @dcs = sort(keys(%domcoords));
8436: my $numdcs = scalar(@dcs);
8437: my $datatable;
8438: my $numinrow = 2;
8439: if ($numdcs > 1) {
8440: $datatable = '<table>';
8441: for (my $i=0; $i<@dcs; $i++) {
8442: my $rem = $i%($numinrow);
8443: if ($rem == 0) {
8444: if ($i > 0) {
8445: $datatable .= '</tr>';
8446: }
8447: $datatable .= '<tr>';
8448: }
8449: my $check = ' ';
8450: if ($curr_dc eq '') {
8451: if (!$i) {
8452: $check = ' checked="checked" ';
8453: }
8454: } elsif ($dcs[$i] eq $curr_dc) {
8455: $check = ' checked="checked" ';
8456: }
8457: if ($i == @dcs - 1) {
8458: my $colsleft = $numinrow - $rem;
8459: if ($colsleft > 1) {
8460: $datatable .= '<td colspan="'.$colsleft.'">';
8461: } else {
8462: $datatable .= '<td>';
8463: }
8464: } else {
8465: $datatable .= '<td>';
8466: }
8467: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8468: $datatable .= '<span class="LC_nobreak"><label>'.
8469: '<input type="radio" name="autocreate_xmldc"'.
8470: ' value="'.$dcs[$i].'"'.$check.'/>'.
8471: &Apache::loncommon::plainname($dcname,$dcdom).
1.177 bisitz 8472: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8473: '</label></span></td>';
8474: }
8475: $datatable .= '</tr></table>';
8476: } elsif (@dcs) {
8477: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8478: $dcs[0].'" />';
8479: }
8480: return ($numdcs,$datatable);
8481: }
8482:
1.137 raeburn 8483: sub usersession_titles {
8484: return &Apache::lonlocal::texthash(
8485: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8486: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8487: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8488: version => 'LON-CAPA version requirement',
1.138 raeburn 8489: excludedomain => 'Allow all, but exclude specific domains',
8490: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8491: primary => 'Primary (checked first)',
1.154 raeburn 8492: default => 'Default',
1.137 raeburn 8493: );
8494: }
8495:
1.152 raeburn 8496: sub id_for_thisdom {
8497: my (%servers) = @_;
8498: my %altids;
8499: foreach my $server (keys(%servers)) {
8500: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8501: if ($serverhome ne $server) {
8502: $altids{$serverhome} = $server;
8503: }
8504: }
8505: return %altids;
8506: }
8507:
1.150 raeburn 8508: sub count_servers {
8509: my ($currbalancer,%servers) = @_;
8510: my (@spares,$numspares);
8511: foreach my $lonhost (sort(keys(%servers))) {
8512: next if ($currbalancer eq $lonhost);
8513: push(@spares,$lonhost);
8514: }
8515: if ($currbalancer) {
8516: $numspares = scalar(@spares);
8517: } else {
8518: $numspares = scalar(@spares) - 1;
8519: }
8520: return ($numspares,@spares);
8521: }
8522:
8523: sub lonbalance_targets_js {
1.171 raeburn 8524: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8525: my $select = &mt('Select');
8526: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8527: if (ref($servers) eq 'HASH') {
8528: $alltargets = join("','",sort(keys(%{$servers})));
8529: my @homedoms;
8530: foreach my $server (sort(keys(%{$servers}))) {
8531: if (&Apache::lonnet::host_domain($server) eq $dom) {
8532: push(@homedoms,'1');
8533: } else {
8534: push(@homedoms,'0');
8535: }
8536: }
8537: $allishome = join("','",@homedoms);
8538: }
8539: if (ref($types) eq 'ARRAY') {
8540: if (@{$types} > 0) {
8541: @alltypes = @{$types};
8542: }
8543: }
8544: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8545: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8546: my (%currbalancer,%currtargets,%currrules,%existing);
8547: if (ref($settings) eq 'HASH') {
8548: %existing = %{$settings};
8549: }
8550: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8551: \%currtargets,\%currrules);
8552: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8553: return <<"END";
8554:
8555: <script type="text/javascript">
8556: // <![CDATA[
8557:
1.171 raeburn 8558: currBalancers = new Array('$balancers');
8559:
8560: function toggleTargets(balnum) {
8561: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8562: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8563: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8564: var prevbalancer = prevhostitem.value;
8565: var baltotal = document.getElementById('loadbalancing_total').value;
8566: prevhostitem.value = balancer;
8567: if (prevbalancer != '') {
8568: var prevIdx = currBalancers.indexOf(prevbalancer);
8569: if (prevIdx != -1) {
8570: currBalancers.splice(prevIdx,1);
8571: }
8572: }
1.150 raeburn 8573: if (balancer == '') {
1.171 raeburn 8574: hideSpares(balnum);
1.150 raeburn 8575: } else {
1.171 raeburn 8576: var currIdx = currBalancers.indexOf(balancer);
8577: if (currIdx == -1) {
8578: currBalancers.push(balancer);
8579: }
1.150 raeburn 8580: var homedoms = new Array('$allishome');
1.171 raeburn 8581: var ishomedom = homedoms[lonhostitem.selectedIndex];
8582: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8583: }
1.171 raeburn 8584: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8585: return;
8586: }
8587:
1.171 raeburn 8588: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8589: var alltargets = new Array('$alltargets');
8590: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8591: var offloadtypes = new Array('primary','default');
8592:
1.171 raeburn 8593: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8594: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8595:
1.151 raeburn 8596: for (var i=0; i<offloadtypes.length; i++) {
8597: var count = 0;
8598: for (var j=0; j<alltargets.length; j++) {
8599: if (alltargets[j] != balancer) {
1.171 raeburn 8600: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8601: item.value = alltargets[j];
8602: item.style.textAlign='left';
8603: item.style.textFace='normal';
8604: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8605: if (currBalancers.indexOf(alltargets[j]) == -1) {
8606: item.disabled = '';
8607: } else {
8608: item.disabled = 'disabled';
8609: item.checked = false;
8610: }
1.151 raeburn 8611: count ++;
8612: }
1.150 raeburn 8613: }
8614: }
1.151 raeburn 8615: for (var k=0; k<insttypes.length; k++) {
8616: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8617: if (ishomedom == 1) {
1.171 raeburn 8618: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8619: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8620: } else {
1.171 raeburn 8621: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8622: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8623:
8624: }
8625: } else {
1.171 raeburn 8626: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8627: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8628: }
1.151 raeburn 8629: if ((insttypes[k] != '_LC_external') &&
8630: ((insttypes[k] != '_LC_internetdom') ||
8631: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8632: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8633: item.options.length = 0;
8634: item.options[0] = new Option("","",true,true);
8635: var idx = 0;
1.151 raeburn 8636: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8637: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8638: idx ++;
8639: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8640:
1.150 raeburn 8641: }
8642: }
8643: }
8644: }
8645: return;
8646: }
8647:
1.171 raeburn 8648: function hideSpares(balnum) {
1.150 raeburn 8649: var alltargets = new Array('$alltargets');
8650: var insttypes = new Array('$allinsttypes');
8651: var offloadtypes = new Array('primary','default');
8652:
1.171 raeburn 8653: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8654: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8655:
8656: var total = alltargets.length - 1;
8657: for (var i=0; i<offloadtypes; i++) {
8658: for (var j=0; j<total; j++) {
1.171 raeburn 8659: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8660: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8661: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8662: }
1.150 raeburn 8663: }
8664: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8665: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8666: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8667: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8668: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8669: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8670: }
8671: }
8672: return;
8673: }
8674:
1.171 raeburn 8675: function checkOffloads(item,balnum,type) {
1.150 raeburn 8676: var alltargets = new Array('$alltargets');
8677: var offloadtypes = new Array('primary','default');
8678: if (item.checked) {
8679: var total = alltargets.length - 1;
8680: var other;
8681: if (type == offloadtypes[0]) {
1.151 raeburn 8682: other = offloadtypes[1];
1.150 raeburn 8683: } else {
1.151 raeburn 8684: other = offloadtypes[0];
1.150 raeburn 8685: }
8686: for (var i=0; i<total; i++) {
1.171 raeburn 8687: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8688: if (server == item.value) {
1.171 raeburn 8689: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8690: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8691: }
8692: }
8693: }
8694: }
8695: return;
8696: }
8697:
1.171 raeburn 8698: function singleServerToggle(balnum,type) {
8699: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8700: if (offloadtoSelIdx == 0) {
1.171 raeburn 8701: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8702: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8703:
8704: } else {
1.171 raeburn 8705: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8706: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8707: }
8708: return;
8709: }
8710:
1.171 raeburn 8711: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8712: if (type == '_LC_external') {
1.171 raeburn 8713: return;
1.150 raeburn 8714: }
1.171 raeburn 8715: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8716: for (var i=0; i<typesRules.length; i++) {
8717: if (formname.elements[typesRules[i]].checked) {
8718: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8719: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8720: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8721: } else {
1.171 raeburn 8722: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8723: }
8724: }
8725: }
8726: return;
8727: }
8728:
8729: function balancerDeleteChange(balnum) {
8730: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8731: var baltotal = document.getElementById('loadbalancing_total').value;
8732: var addtarget;
8733: var removetarget;
8734: var action = 'delete';
8735: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8736: var lonhost = hostitem.value;
8737: var currIdx = currBalancers.indexOf(lonhost);
8738: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8739: if (currIdx != -1) {
8740: currBalancers.splice(currIdx,1);
8741: }
8742: addtarget = lonhost;
8743: } else {
8744: if (currIdx == -1) {
8745: currBalancers.push(lonhost);
8746: }
8747: removetarget = lonhost;
8748: action = 'undelete';
8749: }
8750: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8751: }
8752: return;
8753: }
8754:
8755: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8756: if (baltotal > 1) {
8757: var offloadtypes = new Array('primary','default');
8758: var alltargets = new Array('$alltargets');
8759: var insttypes = new Array('$allinsttypes');
8760: for (var i=0; i<baltotal; i++) {
8761: if (i != balnum) {
8762: for (var j=0; j<offloadtypes.length; j++) {
8763: var total = alltargets.length - 1;
8764: for (var k=0; k<total; k++) {
8765: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8766: var server = serveritem.value;
8767: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8768: if (server == addtarget) {
8769: serveritem.disabled = '';
8770: }
8771: }
8772: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8773: if (server == removetarget) {
8774: serveritem.disabled = 'disabled';
8775: serveritem.checked = false;
8776: }
8777: }
8778: }
8779: }
8780: for (var j=0; j<insttypes.length; j++) {
8781: if (insttypes[j] != '_LC_external') {
8782: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8783: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8784: var currSel = singleserver.selectedIndex;
8785: var currVal = singleserver.options[currSel].value;
8786: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8787: var numoptions = singleserver.options.length;
8788: var needsnew = 1;
8789: for (var k=0; k<numoptions; k++) {
8790: if (singleserver.options[k] == addtarget) {
8791: needsnew = 0;
8792: break;
8793: }
8794: }
8795: if (needsnew == 1) {
8796: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8797: }
8798: }
8799: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8800: singleserver.options.length = 0;
8801: if ((currVal) && (currVal != removetarget)) {
8802: singleserver.options[0] = new Option("","",false,false);
8803: } else {
8804: singleserver.options[0] = new Option("","",true,true);
8805: }
8806: var idx = 0;
8807: for (var m=0; m<alltargets.length; m++) {
8808: if (currBalancers.indexOf(alltargets[m]) == -1) {
8809: idx ++;
8810: if (currVal == alltargets[m]) {
8811: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8812: } else {
8813: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8814: }
8815: }
8816: }
8817: }
8818: }
8819: }
8820: }
1.150 raeburn 8821: }
8822: }
8823: }
8824: return;
8825: }
8826:
1.152 raeburn 8827: // ]]>
8828: </script>
8829:
8830: END
8831: }
8832:
8833: sub new_spares_js {
8834: my @sparestypes = ('primary','default');
8835: my $types = join("','",@sparestypes);
8836: my $select = &mt('Select');
8837: return <<"END";
8838:
8839: <script type="text/javascript">
8840: // <![CDATA[
8841:
8842: function updateNewSpares(formname,lonhost) {
8843: var types = new Array('$types');
8844: var include = new Array();
8845: var exclude = new Array();
8846: for (var i=0; i<types.length; i++) {
8847: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8848: for (var j=0; j<spareboxes.length; j++) {
8849: if (formname.elements[spareboxes[j]].checked) {
8850: exclude.push(formname.elements[spareboxes[j]].value);
8851: } else {
8852: include.push(formname.elements[spareboxes[j]].value);
8853: }
8854: }
8855: }
8856: for (var i=0; i<types.length; i++) {
8857: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8858: var selIdx = newSpare.selectedIndex;
8859: var currnew = newSpare.options[selIdx].value;
8860: var okSpares = new Array();
8861: for (var j=0; j<newSpare.options.length; j++) {
8862: var possible = newSpare.options[j].value;
8863: if (possible != '') {
8864: if (exclude.indexOf(possible) == -1) {
8865: okSpares.push(possible);
8866: } else {
8867: if (currnew == possible) {
8868: selIdx = 0;
8869: }
8870: }
8871: }
8872: }
8873: for (var k=0; k<include.length; k++) {
8874: if (okSpares.indexOf(include[k]) == -1) {
8875: okSpares.push(include[k]);
8876: }
8877: }
8878: okSpares.sort();
8879: newSpare.options.length = 0;
8880: if (selIdx == 0) {
8881: newSpare.options[0] = new Option("$select","",true,true);
8882: } else {
8883: newSpare.options[0] = new Option("$select","",false,false);
8884: }
8885: for (var m=0; m<okSpares.length; m++) {
8886: var idx = m+1;
8887: var selThis = 0;
8888: if (selIdx != 0) {
8889: if (okSpares[m] == currnew) {
8890: selThis = 1;
8891: }
8892: }
8893: if (selThis == 1) {
8894: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8895: } else {
8896: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8897: }
8898: }
8899: }
8900: return;
8901: }
8902:
8903: function checkNewSpares(lonhost,type) {
8904: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8905: var chosen = newSpare.options[newSpare.selectedIndex].value;
8906: if (chosen != '') {
8907: var othertype;
8908: var othernewSpare;
8909: if (type == 'primary') {
8910: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8911: }
8912: if (type == 'default') {
8913: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8914: }
8915: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8916: othernewSpare.selectedIndex = 0;
8917: }
8918: }
8919: return;
8920: }
8921:
8922: // ]]>
8923: </script>
8924:
8925: END
8926:
8927: }
8928:
8929: sub common_domprefs_js {
8930: return <<"END";
8931:
8932: <script type="text/javascript">
8933: // <![CDATA[
8934:
1.150 raeburn 8935: function getIndicesByName(formname,item) {
1.152 raeburn 8936: var group = new Array();
1.150 raeburn 8937: for (var i=0;i<formname.elements.length;i++) {
8938: if (formname.elements[i].name == item) {
1.152 raeburn 8939: group.push(formname.elements[i].id);
1.150 raeburn 8940: }
8941: }
1.152 raeburn 8942: return group;
1.150 raeburn 8943: }
8944:
8945: // ]]>
8946: </script>
8947:
8948: END
1.152 raeburn 8949:
1.150 raeburn 8950: }
8951:
1.165 raeburn 8952: sub recaptcha_js {
8953: my %lt = &captcha_phrases();
8954: return <<"END";
8955:
8956: <script type="text/javascript">
8957: // <![CDATA[
8958:
8959: function updateCaptcha(caller,context) {
8960: var privitem;
8961: var pubitem;
8962: var privtext;
8963: var pubtext;
8964: if (document.getElementById(context+'_recaptchapub')) {
8965: pubitem = document.getElementById(context+'_recaptchapub');
8966: } else {
8967: return;
8968: }
8969: if (document.getElementById(context+'_recaptchapriv')) {
8970: privitem = document.getElementById(context+'_recaptchapriv');
8971: } else {
8972: return;
8973: }
8974: if (document.getElementById(context+'_recaptchapubtxt')) {
8975: pubtext = document.getElementById(context+'_recaptchapubtxt');
8976: } else {
8977: return;
8978: }
8979: if (document.getElementById(context+'_recaptchaprivtxt')) {
8980: privtext = document.getElementById(context+'_recaptchaprivtxt');
8981: } else {
8982: return;
8983: }
8984: if (caller.checked) {
8985: if (caller.value == 'recaptcha') {
8986: pubitem.type = 'text';
8987: privitem.type = 'text';
8988: pubitem.size = '40';
8989: privitem.size = '40';
8990: pubtext.innerHTML = "$lt{'pub'}";
8991: privtext.innerHTML = "$lt{'priv'}";
8992: } else {
8993: pubitem.type = 'hidden';
8994: privitem.type = 'hidden';
8995: pubtext.innerHTML = '';
8996: privtext.innerHTML = '';
8997: }
8998: }
8999: return;
9000: }
9001:
9002: // ]]>
9003: </script>
9004:
9005: END
9006:
9007: }
9008:
9009: sub captcha_phrases {
9010: return &Apache::lonlocal::texthash (
9011: priv => 'Private key',
9012: pub => 'Public key',
9013: original => 'original (CAPTCHA)',
9014: recaptcha => 'successor (ReCAPTCHA)',
9015: notused => 'unused',
9016: );
9017: }
9018:
1.3 raeburn 9019: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>