Annotation of loncom/interface/domainprefs.pm, revision 1.175
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.175 ! bisitz 4: # $Id: domainprefs.pm,v 1.174 2012/10/30 10:39:02 foxr 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>';
818: foreach my $hostid (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.174 foxr 1193: my $js = "<script type='text/javascript'>\n";
1194: $js .= &Apache::lonhtmlcommon::color_picker();
1195: my $js = "\n</script>\n";
1196: my $datatable = $js . '<tr'.$css_class.'>'.
1.6 raeburn 1197: '<td>'.$choices->{'font'}.'</td>';
1198: if (!$is_custom->{'font'}) {
1.30 raeburn 1199: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1200: } else {
1201: $datatable .= '<td> </td>';
1202: }
1.174 foxr 1203: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1204:
1.8 raeburn 1205: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1206: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1207: ' value="'.$current_color.'" /> '.
1208: ' </td></tr>';
1.107 raeburn 1209: unless ($role eq 'login') {
1210: $datatable .= '<tr'.$css_class.'>'.
1211: '<td>'.$choices->{'fontmenu'}.'</td>';
1212: if (!$is_custom->{'fontmenu'}) {
1213: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1214: } else {
1215: $datatable .= '<td> </td>';
1216: }
1.174 foxr 1217: $current_color = $designs->{'fontmenu'} ?
1218: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1219: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1220: '<input class="colorchooser" type="text" size="10" name="'
1221: .$role.'_fontmenu"'.
1222: ' value="'.$current_color.'" /> '.
1223: ' </td></tr>';
1.97 tempelho 1224: }
1.9 raeburn 1225: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1226: foreach my $img (@{$images}) {
1.18 albertel 1227: $itemcount ++;
1.6 raeburn 1228: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1229: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1230: '<td>'.$choices->{$img};
1.41 raeburn 1231: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1232: if ($role eq 'login') {
1233: if ($img eq 'login') {
1234: $login_hdr_pick =
1.135 bisitz 1235: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1236: $logincolors =
1237: &login_text_colors($img,$role,$logintext,$phase,$choices,
1238: $designs);
1239: } elsif ($img ne 'domlogo') {
1240: $datatable.= &logo_display_options($img,$defaults,$designs);
1241: }
1242: }
1243: $datatable .= '</td>';
1.6 raeburn 1244: if ($designs->{$img} ne '') {
1245: $imgfile = $designs->{$img};
1.18 albertel 1246: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1247: } else {
1248: $imgfile = $defaults->{$img};
1249: }
1250: if ($imgfile) {
1.9 raeburn 1251: my ($showfile,$fullsize);
1252: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1253: my $urldir = $1;
1254: my $filename = $2;
1255: my @info = &Apache::lonnet::stat_file($designs->{$img});
1256: if (@info) {
1257: my $thumbfile = 'tn-'.$filename;
1258: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1259: if (@thumb) {
1260: $showfile = $urldir.'/'.$thumbfile;
1261: } else {
1262: $showfile = $imgfile;
1263: }
1264: } else {
1265: $showfile = '';
1266: }
1267: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1268: $showfile = $imgfile;
1.6 raeburn 1269: my $imgdir = $1;
1270: my $filename = $2;
1.159 raeburn 1271: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1272: $showfile = "/$imgdir/tn-".$filename;
1273: } else {
1.159 raeburn 1274: my $input = $londocroot.$imgfile;
1275: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1276: if (!-e $output) {
1.9 raeburn 1277: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1278: my ($fullwidth,$fullheight) = &check_dimensions($input);
1279: if ($fullwidth ne '' && $fullheight ne '') {
1280: if ($fullwidth > $width && $fullheight > $height) {
1281: my $size = $width.'x'.$height;
1282: system("convert -sample $size $input $output");
1.159 raeburn 1283: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1284: }
1285: }
1.6 raeburn 1286: }
1287: }
1.16 raeburn 1288: }
1.6 raeburn 1289: if ($showfile) {
1.40 raeburn 1290: if ($showfile =~ m{^/(adm|res)/}) {
1291: if ($showfile =~ m{^/res/}) {
1292: my $local_showfile =
1293: &Apache::lonnet::filelocation('',$showfile);
1294: &Apache::lonnet::repcopy($local_showfile);
1295: }
1296: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1297: }
1298: if ($imgfile) {
1299: if ($imgfile =~ m{^/(adm|res)/}) {
1300: if ($imgfile =~ m{^/res/}) {
1301: my $local_imgfile =
1302: &Apache::lonnet::filelocation('',$imgfile);
1303: &Apache::lonnet::repcopy($local_imgfile);
1304: }
1305: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1306: } else {
1307: $fullsize = $imgfile;
1308: }
1309: }
1.41 raeburn 1310: $datatable .= '<td>';
1311: if ($img eq 'login') {
1.135 bisitz 1312: $datatable .= $login_hdr_pick;
1313: }
1.41 raeburn 1314: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1315: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1316: } else {
1317: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1318: &mt('Upload:');
1319: }
1320: } else {
1321: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1322: &mt('Upload:');
1323: }
1.9 raeburn 1324: if ($switchserver) {
1325: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1326: } else {
1.135 bisitz 1327: if ($img ne 'login') { # suppress file selection for Log-in header
1328: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1329: }
1.9 raeburn 1330: }
1331: $datatable .= '</td></tr>';
1.6 raeburn 1332: }
1333: $itemcount ++;
1334: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1335: $datatable .= '<tr'.$css_class.'>'.
1336: '<td>'.$choices->{'bgs'}.'</td>';
1337: my $bgs_def;
1338: foreach my $item (@{$bgs}) {
1339: if (!$is_custom->{$item}) {
1.70 raeburn 1340: $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 1341: }
1342: }
1343: if ($bgs_def) {
1.8 raeburn 1344: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1345: } else {
1346: $datatable .= '<td> </td>';
1347: }
1348: $datatable .= '<td class="LC_right_item">'.
1349: '<table border="0"><tr>';
1.174 foxr 1350:
1351:
1.6 raeburn 1352: foreach my $item (@{$bgs}) {
1.174 foxr 1353: # my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1354: $datatable .= '<td align="center">';
1355: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1356: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1357: $datatable .= ' ';
1.6 raeburn 1358: }
1.174 foxr 1359: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1360: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1361: }
1362: $datatable .= '</tr></table></td></tr>';
1363: $itemcount ++;
1364: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1365: $datatable .= '<tr'.$css_class.'>'.
1366: '<td>'.$choices->{'links'}.'</td>';
1367: my $links_def;
1368: foreach my $item (@{$links}) {
1369: if (!$is_custom->{$item}) {
1.30 raeburn 1370: $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 1371: }
1372: }
1373: if ($links_def) {
1.8 raeburn 1374: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1375: } else {
1376: $datatable .= '<td> </td>';
1377: }
1378: $datatable .= '<td class="LC_right_item">'.
1379: '<table border="0"><tr>';
1380: foreach my $item (@{$links}) {
1.174 foxr 1381: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1382: $datatable .= '<td align="center">'."\n";
1383:
1.6 raeburn 1384: if ($designs->{'links'}{$item}) {
1.174 foxr 1385: $datatable.=' ';
1.6 raeburn 1386: }
1.174 foxr 1387: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1388: '" /></td>';
1389: }
1.30 raeburn 1390: $$rowtotal += $itemcount;
1.3 raeburn 1391: return $datatable;
1392: }
1393:
1.70 raeburn 1394: sub logo_display_options {
1395: my ($img,$defaults,$designs) = @_;
1396: my $checkedon;
1397: if (ref($defaults) eq 'HASH') {
1398: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1399: if ($defaults->{'showlogo'}{$img}) {
1400: $checkedon = 'checked="checked" ';
1401: }
1402: }
1403: }
1404: if (ref($designs) eq 'HASH') {
1405: if (ref($designs->{'showlogo'}) eq 'HASH') {
1406: if (defined($designs->{'showlogo'}{$img})) {
1407: if ($designs->{'showlogo'}{$img} == 0) {
1408: $checkedon = '';
1409: } elsif ($designs->{'showlogo'}{$img} == 1) {
1410: $checkedon = 'checked="checked" ';
1411: }
1412: }
1413: }
1414: }
1415: return '<br /><label> <input type="checkbox" name="'.
1416: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1417: &mt('show').'</label>'."\n";
1418: }
1419:
1.41 raeburn 1420: sub login_header_options {
1.135 bisitz 1421: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1422: my $output = '';
1.41 raeburn 1423: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1424: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1425: if (!$is_custom->{'textcol'}) {
1426: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1427: ' ';
1428: }
1429: if (!$is_custom->{'bgcol'}) {
1430: $output .= $choices->{'bgcol'}.': '.
1431: '<span id="css_'.$role.'_font" style="background-color: '.
1432: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1433: }
1434: $output .= '<br />';
1435: }
1436: $output .='<br />';
1437: return $output;
1438: }
1439:
1440: sub login_text_colors {
1441: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1442: my $color_menu = '<table border="0"><tr>';
1443: foreach my $item (@{$logintext}) {
1444: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1445: $color_menu .= '<td align="center">'.$link;
1446: if ($designs->{'logintext'}{$item}) {
1447: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1448: }
1449: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1450: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1451: '<td> </td>';
1452: }
1453: $color_menu .= '</tr></table><br />';
1454: return $color_menu;
1455: }
1456:
1457: sub image_changes {
1458: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1459: my $output;
1.135 bisitz 1460: if ($img eq 'login') {
1461: # suppress image for Log-in header
1462: } elsif (!$is_custom) {
1.70 raeburn 1463: if ($img ne 'domlogo') {
1.41 raeburn 1464: $output .= &mt('Default image:').'<br />';
1465: } else {
1466: $output .= &mt('Default in use:').'<br />';
1467: }
1468: }
1.135 bisitz 1469: if ($img eq 'login') { # suppress image for Log-in header
1470: $output .= '<td>'.$logincolors;
1.41 raeburn 1471: } else {
1.135 bisitz 1472: if ($img_import) {
1473: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1474: }
1475: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1476: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1477: if ($is_custom) {
1478: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1479: '<input type="checkbox" name="'.
1480: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1481: '</label> '.&mt('Replace:').'</span><br />';
1482: } else {
1483: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1484: }
1.41 raeburn 1485: }
1486: return $output;
1487: }
1488:
1.6 raeburn 1489: sub color_pick {
1490: my ($phase,$role,$item,$desc,$curcol) = @_;
1491: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1492: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1493: ');">'.$desc.'</a>';
1494: return $link;
1495: }
1496:
1.3 raeburn 1497: sub print_quotas {
1.86 raeburn 1498: my ($dom,$settings,$rowtotal,$action) = @_;
1499: my $context;
1500: if ($action eq 'quotas') {
1501: $context = 'tools';
1502: } else {
1503: $context = $action;
1504: }
1.101 raeburn 1505: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1506: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1507: my $typecount = 0;
1.101 raeburn 1508: my ($css_class,%titles);
1.86 raeburn 1509: if ($context eq 'requestcourses') {
1.98 raeburn 1510: @usertools = ('official','unofficial','community');
1.106 raeburn 1511: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1512: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1513: %titles = &courserequest_titles();
1.163 raeburn 1514: } elsif ($context eq 'requestauthor') {
1515: @usertools = ('author');
1516: @options = ('norequest','approval','automatic');
1517: %titles = &authorrequest_titles();
1.86 raeburn 1518: } else {
1.162 raeburn 1519: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1520: %titles = &tool_titles();
1.86 raeburn 1521: }
1.26 raeburn 1522: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1523: foreach my $type (@{$types}) {
1.72 raeburn 1524: my $currdefquota;
1.163 raeburn 1525: unless (($context eq 'requestcourses') ||
1526: ($context eq 'requestauthor')) {
1.86 raeburn 1527: if (ref($settings) eq 'HASH') {
1528: if (ref($settings->{defaultquota}) eq 'HASH') {
1529: $currdefquota = $settings->{defaultquota}->{$type};
1530: } else {
1531: $currdefquota = $settings->{$type};
1532: }
1.78 raeburn 1533: }
1.72 raeburn 1534: }
1.3 raeburn 1535: if (defined($usertypes->{$type})) {
1536: $typecount ++;
1537: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1538: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1539: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1540: '<td class="LC_left_item">';
1.101 raeburn 1541: if ($context eq 'requestcourses') {
1542: $datatable .= '<table><tr>';
1543: }
1544: my %cell;
1.72 raeburn 1545: foreach my $item (@usertools) {
1.101 raeburn 1546: if ($context eq 'requestcourses') {
1547: my ($curroption,$currlimit);
1548: if (ref($settings) eq 'HASH') {
1549: if (ref($settings->{$item}) eq 'HASH') {
1550: $curroption = $settings->{$item}->{$type};
1551: if ($curroption =~ /^autolimit=(\d*)$/) {
1552: $currlimit = $1;
1553: }
1554: }
1555: }
1556: if (!$curroption) {
1557: $curroption = 'norequest';
1558: }
1559: $datatable .= '<th>'.$titles{$item}.'</th>';
1560: foreach my $option (@options) {
1561: my $val = $option;
1562: if ($option eq 'norequest') {
1563: $val = 0;
1564: }
1565: if ($option eq 'validate') {
1566: my $canvalidate = 0;
1567: if (ref($validations{$item}) eq 'HASH') {
1568: if ($validations{$item}{$type}) {
1569: $canvalidate = 1;
1570: }
1571: }
1572: next if (!$canvalidate);
1573: }
1574: my $checked = '';
1575: if ($option eq $curroption) {
1576: $checked = ' checked="checked"';
1577: } elsif ($option eq 'autolimit') {
1578: if ($curroption =~ /^autolimit/) {
1579: $checked = ' checked="checked"';
1580: }
1581: }
1582: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1583: '<input type="radio" name="crsreq_'.$item.
1584: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1585: $titles{$option}.'</label>';
1.101 raeburn 1586: if ($option eq 'autolimit') {
1.127 raeburn 1587: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1588: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1589: 'value="'.$currlimit.'" />';
1.101 raeburn 1590: }
1.127 raeburn 1591: $cell{$item} .= '</span> ';
1.103 raeburn 1592: if ($option eq 'autolimit') {
1.127 raeburn 1593: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1594: }
1.101 raeburn 1595: }
1.163 raeburn 1596: } elsif ($context eq 'requestauthor') {
1597: my $curroption;
1598: if (ref($settings) eq 'HASH') {
1599: $curroption = $settings->{$type};
1600: }
1601: if (!$curroption) {
1602: $curroption = 'norequest';
1603: }
1604: foreach my $option (@options) {
1605: my $val = $option;
1606: if ($option eq 'norequest') {
1607: $val = 0;
1608: }
1609: my $checked = '';
1610: if ($option eq $curroption) {
1611: $checked = ' checked="checked"';
1612: }
1613: $datatable .= '<span class="LC_nobreak"><label>'.
1614: '<input type="radio" name="authorreq_'.$type.
1615: '" value="'.$val.'"'.$checked.' />'.
1616: $titles{$option}.'</label></span> ';
1617: }
1.101 raeburn 1618: } else {
1619: my $checked = 'checked="checked" ';
1620: if (ref($settings) eq 'HASH') {
1621: if (ref($settings->{$item}) eq 'HASH') {
1622: if ($settings->{$item}->{$type} == 0) {
1623: $checked = '';
1624: } elsif ($settings->{$item}->{$type} == 1) {
1625: $checked = 'checked="checked" ';
1626: }
1.78 raeburn 1627: }
1.72 raeburn 1628: }
1.101 raeburn 1629: $datatable .= '<span class="LC_nobreak"><label>'.
1630: '<input type="checkbox" name="'.$context.'_'.$item.
1631: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1632: '</label></span> ';
1.72 raeburn 1633: }
1.101 raeburn 1634: }
1635: if ($context eq 'requestcourses') {
1636: $datatable .= '</tr><tr>';
1637: foreach my $item (@usertools) {
1.106 raeburn 1638: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1639: }
1640: $datatable .= '</tr></table>';
1.72 raeburn 1641: }
1.86 raeburn 1642: $datatable .= '</td>';
1.163 raeburn 1643: unless (($context eq 'requestcourses') ||
1644: ($context eq 'requestauthor')) {
1.86 raeburn 1645: $datatable .=
1646: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1647: '<input type="text" name="quota_'.$type.
1.72 raeburn 1648: '" value="'.$currdefquota.
1.86 raeburn 1649: '" size="5" /> Mb</span></td>';
1650: }
1651: $datatable .= '</tr>';
1.3 raeburn 1652: }
1653: }
1654: }
1.163 raeburn 1655: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1656: $defaultquota = '20';
1657: if (ref($settings) eq 'HASH') {
1658: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1659: $defaultquota = $settings->{'defaultquota'}->{'default'};
1660: } elsif (defined($settings->{'default'})) {
1661: $defaultquota = $settings->{'default'};
1662: }
1.3 raeburn 1663: }
1664: }
1665: $typecount ++;
1666: $css_class = $typecount%2?' class="LC_odd_row"':'';
1667: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1668: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1669: '<td class="LC_left_item">';
1.101 raeburn 1670: if ($context eq 'requestcourses') {
1671: $datatable .= '<table><tr>';
1672: }
1673: my %defcell;
1.72 raeburn 1674: foreach my $item (@usertools) {
1.101 raeburn 1675: if ($context eq 'requestcourses') {
1676: my ($curroption,$currlimit);
1677: if (ref($settings) eq 'HASH') {
1678: if (ref($settings->{$item}) eq 'HASH') {
1679: $curroption = $settings->{$item}->{'default'};
1680: if ($curroption =~ /^autolimit=(\d*)$/) {
1681: $currlimit = $1;
1682: }
1683: }
1684: }
1685: if (!$curroption) {
1686: $curroption = 'norequest';
1687: }
1688: $datatable .= '<th>'.$titles{$item}.'</th>';
1689: foreach my $option (@options) {
1690: my $val = $option;
1691: if ($option eq 'norequest') {
1692: $val = 0;
1693: }
1694: if ($option eq 'validate') {
1695: my $canvalidate = 0;
1696: if (ref($validations{$item}) eq 'HASH') {
1697: if ($validations{$item}{'default'}) {
1698: $canvalidate = 1;
1699: }
1700: }
1701: next if (!$canvalidate);
1702: }
1703: my $checked = '';
1704: if ($option eq $curroption) {
1705: $checked = ' checked="checked"';
1706: } elsif ($option eq 'autolimit') {
1707: if ($curroption =~ /^autolimit/) {
1708: $checked = ' checked="checked"';
1709: }
1710: }
1711: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1712: '<input type="radio" name="crsreq_'.$item.
1713: '_default" value="'.$val.'"'.$checked.' />'.
1714: $titles{$option}.'</label>';
1715: if ($option eq 'autolimit') {
1.127 raeburn 1716: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1717: $item.'_limit_default" size="1" '.
1718: 'value="'.$currlimit.'" />';
1719: }
1.127 raeburn 1720: $defcell{$item} .= '</span> ';
1.104 raeburn 1721: if ($option eq 'autolimit') {
1.127 raeburn 1722: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1723: }
1.101 raeburn 1724: }
1.163 raeburn 1725: } elsif ($context eq 'requestauthor') {
1726: my $curroption;
1727: if (ref($settings) eq 'HASH') {
1.172 raeburn 1728: $curroption = $settings->{'default'};
1.163 raeburn 1729: }
1730: if (!$curroption) {
1731: $curroption = 'norequest';
1732: }
1733: foreach my $option (@options) {
1734: my $val = $option;
1735: if ($option eq 'norequest') {
1736: $val = 0;
1737: }
1738: my $checked = '';
1739: if ($option eq $curroption) {
1740: $checked = ' checked="checked"';
1741: }
1742: $datatable .= '<span class="LC_nobreak"><label>'.
1743: '<input type="radio" name="authorreq_default"'.
1744: ' value="'.$val.'"'.$checked.' />'.
1745: $titles{$option}.'</label></span> ';
1746: }
1.101 raeburn 1747: } else {
1748: my $checked = 'checked="checked" ';
1749: if (ref($settings) eq 'HASH') {
1750: if (ref($settings->{$item}) eq 'HASH') {
1751: if ($settings->{$item}->{'default'} == 0) {
1752: $checked = '';
1753: } elsif ($settings->{$item}->{'default'} == 1) {
1754: $checked = 'checked="checked" ';
1755: }
1.78 raeburn 1756: }
1.72 raeburn 1757: }
1.101 raeburn 1758: $datatable .= '<span class="LC_nobreak"><label>'.
1759: '<input type="checkbox" name="'.$context.'_'.$item.
1760: '" value="default" '.$checked.'/>'.$titles{$item}.
1761: '</label></span> ';
1762: }
1763: }
1764: if ($context eq 'requestcourses') {
1765: $datatable .= '</tr><tr>';
1766: foreach my $item (@usertools) {
1.106 raeburn 1767: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1768: }
1.101 raeburn 1769: $datatable .= '</tr></table>';
1.72 raeburn 1770: }
1.86 raeburn 1771: $datatable .= '</td>';
1.163 raeburn 1772: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1773: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1774: '<input type="text" name="defaultquota" value="'.
1775: $defaultquota.'" size="5" /> Mb</span></td>';
1776: }
1777: $datatable .= '</tr>';
1.72 raeburn 1778: $typecount ++;
1779: $css_class = $typecount%2?' class="LC_odd_row"':'';
1780: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1781: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1782: if ($context eq 'requestcourses') {
1.109 raeburn 1783: $datatable .= &mt('(overrides affiliation, if set)').
1784: '</td>'.
1785: '<td class="LC_left_item">'.
1786: '<table><tr>';
1.101 raeburn 1787: } else {
1.109 raeburn 1788: $datatable .= &mt('(overrides affiliation, if checked)').
1789: '</td>'.
1790: '<td class="LC_left_item" colspan="2">'.
1791: '<br />';
1.101 raeburn 1792: }
1793: my %advcell;
1.72 raeburn 1794: foreach my $item (@usertools) {
1.101 raeburn 1795: if ($context eq 'requestcourses') {
1796: my ($curroption,$currlimit);
1797: if (ref($settings) eq 'HASH') {
1798: if (ref($settings->{$item}) eq 'HASH') {
1799: $curroption = $settings->{$item}->{'_LC_adv'};
1800: if ($curroption =~ /^autolimit=(\d*)$/) {
1801: $currlimit = $1;
1802: }
1803: }
1804: }
1805: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1806: my $checked = '';
1807: if ($curroption eq '') {
1808: $checked = ' checked="checked"';
1809: }
1810: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1811: '<input type="radio" name="crsreq_'.$item.
1812: '__LC_adv" value=""'.$checked.' />'.
1813: &mt('No override set').'</label></span> ';
1.101 raeburn 1814: foreach my $option (@options) {
1815: my $val = $option;
1816: if ($option eq 'norequest') {
1817: $val = 0;
1818: }
1819: if ($option eq 'validate') {
1820: my $canvalidate = 0;
1821: if (ref($validations{$item}) eq 'HASH') {
1822: if ($validations{$item}{'_LC_adv'}) {
1823: $canvalidate = 1;
1824: }
1825: }
1826: next if (!$canvalidate);
1827: }
1828: my $checked = '';
1.104 raeburn 1829: if ($val eq $curroption) {
1.101 raeburn 1830: $checked = ' checked="checked"';
1831: } elsif ($option eq 'autolimit') {
1832: if ($curroption =~ /^autolimit/) {
1833: $checked = ' checked="checked"';
1834: }
1835: }
1836: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1837: '<input type="radio" name="crsreq_'.$item.
1838: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1839: $titles{$option}.'</label>';
1840: if ($option eq 'autolimit') {
1.127 raeburn 1841: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1842: $item.'_limit__LC_adv" size="1" '.
1843: 'value="'.$currlimit.'" />';
1844: }
1.127 raeburn 1845: $advcell{$item} .= '</span> ';
1.104 raeburn 1846: if ($option eq 'autolimit') {
1.127 raeburn 1847: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1848: }
1.101 raeburn 1849: }
1.163 raeburn 1850: } elsif ($context eq 'requestauthor') {
1851: my $curroption;
1852: if (ref($settings) eq 'HASH') {
1853: $curroption = $settings->{'_LC_adv'};
1854: }
1855: my $checked = '';
1856: if ($curroption eq '') {
1857: $checked = ' checked="checked"';
1858: }
1859: $datatable .= '<span class="LC_nobreak"><label>'.
1860: '<input type="radio" name="authorreq__LC_adv"'.
1861: ' value=""'.$checked.' />'.
1862: &mt('No override set').'</label></span> ';
1863: foreach my $option (@options) {
1864: my $val = $option;
1865: if ($option eq 'norequest') {
1866: $val = 0;
1867: }
1868: my $checked = '';
1869: if ($val eq $curroption) {
1870: $checked = ' checked="checked"';
1871: }
1872: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1873: '<input type="radio" name="authorreq__LC_adv"'.
1874: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1875: $titles{$option}.'</label></span> ';
1876: }
1.101 raeburn 1877: } else {
1878: my $checked = 'checked="checked" ';
1879: if (ref($settings) eq 'HASH') {
1880: if (ref($settings->{$item}) eq 'HASH') {
1881: if ($settings->{$item}->{'_LC_adv'} == 0) {
1882: $checked = '';
1883: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1884: $checked = 'checked="checked" ';
1885: }
1.79 raeburn 1886: }
1.72 raeburn 1887: }
1.101 raeburn 1888: $datatable .= '<span class="LC_nobreak"><label>'.
1889: '<input type="checkbox" name="'.$context.'_'.$item.
1890: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1891: '</label></span> ';
1892: }
1893: }
1894: if ($context eq 'requestcourses') {
1895: $datatable .= '</tr><tr>';
1896: foreach my $item (@usertools) {
1.106 raeburn 1897: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1898: }
1.101 raeburn 1899: $datatable .= '</tr></table>';
1.72 raeburn 1900: }
1.98 raeburn 1901: $datatable .= '</td></tr>';
1.30 raeburn 1902: $$rowtotal += $typecount;
1.3 raeburn 1903: return $datatable;
1904: }
1905:
1.163 raeburn 1906: sub print_requestmail {
1907: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1908: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1909: $now = time;
1910: $rows = 0;
1911: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1912: foreach my $server (keys(%dompersonnel)) {
1913: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1914: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1915: if (!grep(/^$uname:$udom$/,@domcoord)) {
1916: push(@domcoord,$uname.':'.$udom);
1917: }
1918: }
1919: }
1920: if (ref($settings) eq 'HASH') {
1921: if (ref($settings->{'notify'}) eq 'HASH') {
1922: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1923: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1924: }
1925: }
1926: }
1.104 raeburn 1927: if (@currapproval) {
1928: foreach my $dc (@currapproval) {
1.102 raeburn 1929: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1930: push(@domcoord,$dc);
1931: }
1932: }
1933: }
1934: @domcoord = sort(@domcoord);
1935: my $numinrow = 4;
1936: my $numdc = @domcoord;
1937: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1938: my $text;
1939: if ($action eq 'requestcourses') {
1940: $text = &mt('Receive notification of course requests requiring approval');
1941: } else {
1942: $text = &mt('Receive notification of authoring space requests requiring approval')
1943: }
1944: $datatable = '<tr '.$css_class.'>'.
1945: ' <td>'.$text.'</td>'.
1.102 raeburn 1946: ' <td class="LC_left_item">';
1947: if (@domcoord > 0) {
1948: $datatable .= '<table>';
1949: for (my $i=0; $i<$numdc; $i++) {
1950: my $rem = $i%($numinrow);
1951: if ($rem == 0) {
1952: if ($i > 0) {
1953: $datatable .= '</tr>';
1954: }
1955: $datatable .= '<tr>';
1956: $rows ++;
1957: }
1958: my $check = ' ';
1.104 raeburn 1959: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1960: $check = ' checked="checked" ';
1961: }
1962: my ($uname,$udom) = split(':',$domcoord[$i]);
1963: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1964: if ($i == $numdc-1) {
1965: my $colsleft = $numinrow-$rem;
1966: if ($colsleft > 1) {
1967: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1968: } else {
1969: $datatable .= '<td class="LC_left_item">';
1970: }
1971: } else {
1972: $datatable .= '<td class="LC_left_item">';
1973: }
1974: $datatable .= '<span class="LC_nobreak"><label>'.
1975: '<input type="checkbox" name="reqapprovalnotify" '.
1976: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 ! bisitz 1977: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 1978: }
1979: $datatable .= '</tr></table>';
1980: } else {
1981: $datatable .= &mt('There are no active Domain Coordinators');
1982: $rows ++;
1983: }
1984: $datatable .='</td></tr>';
1985: $$rowtotal += $rows;
1986: return $datatable;
1987: }
1988:
1.3 raeburn 1989: sub print_autoenroll {
1.30 raeburn 1990: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 1991: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 1992: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 1993: if (ref($settings) eq 'HASH') {
1994: if (exists($settings->{'run'})) {
1995: if ($settings->{'run'} eq '0') {
1996: $runoff = ' checked="checked" ';
1997: $runon = ' ';
1998: } else {
1999: $runon = ' checked="checked" ';
2000: $runoff = ' ';
2001: }
2002: } else {
2003: if ($autorun) {
2004: $runon = ' checked="checked" ';
2005: $runoff = ' ';
2006: } else {
2007: $runoff = ' checked="checked" ';
2008: $runon = ' ';
2009: }
2010: }
1.129 raeburn 2011: if (exists($settings->{'co-owners'})) {
2012: if ($settings->{'co-owners'} eq '0') {
2013: $coownersoff = ' checked="checked" ';
2014: $coownerson = ' ';
2015: } else {
2016: $coownerson = ' checked="checked" ';
2017: $coownersoff = ' ';
2018: }
2019: } else {
2020: $coownersoff = ' checked="checked" ';
2021: $coownerson = ' ';
2022: }
1.3 raeburn 2023: if (exists($settings->{'sender_domain'})) {
2024: $defdom = $settings->{'sender_domain'};
2025: }
1.14 raeburn 2026: } else {
2027: if ($autorun) {
2028: $runon = ' checked="checked" ';
2029: $runoff = ' ';
2030: } else {
2031: $runoff = ' checked="checked" ';
2032: $runon = ' ';
2033: }
1.3 raeburn 2034: }
2035: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2036: my $notif_sender;
2037: if (ref($settings) eq 'HASH') {
2038: $notif_sender = $settings->{'sender_uname'};
2039: }
1.3 raeburn 2040: my $datatable='<tr class="LC_odd_row">'.
2041: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2042: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2043: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2044: $runon.' value="1" />'.&mt('Yes').'</label> '.
2045: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2046: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2047: '</tr><tr>'.
2048: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2049: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2050: &mt('username').': '.
2051: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2052: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2053: ': '.$domform.'</span></td></tr>'.
2054: '<tr class="LC_odd_row">'.
2055: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2056: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2057: '<input type="radio" name="autoassign_coowners"'.
2058: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2059: '<label><input type="radio" name="autoassign_coowners"'.
2060: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2061: '</tr>';
2062: $$rowtotal += 3;
1.3 raeburn 2063: return $datatable;
2064: }
2065:
2066: sub print_autoupdate {
1.30 raeburn 2067: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2068: my $datatable;
2069: if ($position eq 'top') {
2070: my $updateon = ' ';
2071: my $updateoff = ' checked="checked" ';
2072: my $classlistson = ' ';
2073: my $classlistsoff = ' checked="checked" ';
2074: if (ref($settings) eq 'HASH') {
2075: if ($settings->{'run'} eq '1') {
2076: $updateon = $updateoff;
2077: $updateoff = ' ';
2078: }
2079: if ($settings->{'classlists'} eq '1') {
2080: $classlistson = $classlistsoff;
2081: $classlistsoff = ' ';
2082: }
2083: }
2084: my %title = (
2085: run => 'Auto-update active?',
2086: classlists => 'Update information in classlists?',
2087: );
2088: $datatable = '<tr class="LC_odd_row">'.
2089: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2090: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2091: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2092: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2093: '<label><input type="radio" name="autoupdate_run"'.
2094: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2095: '</tr><tr>'.
2096: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2097: '<td class="LC_right_item"><span class="LC_nobreak">'.
2098: '<label><input type="radio" name="classlists"'.
2099: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2100: '<label><input type="radio" name="classlists"'.
2101: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2102: '</tr>';
1.30 raeburn 2103: $$rowtotal += 2;
1.131 raeburn 2104: } elsif ($position eq 'middle') {
2105: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2106: my $numinrow = 3;
2107: my $locknamesettings;
2108: $datatable .= &insttypes_row($settings,$types,$usertypes,
2109: $dom,$numinrow,$othertitle,
2110: 'lockablenames');
2111: $$rowtotal ++;
1.3 raeburn 2112: } else {
1.44 raeburn 2113: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2114: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2115: 'permanentemail','id');
1.33 raeburn 2116: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2117: my $numrows = 0;
1.26 raeburn 2118: if (ref($types) eq 'ARRAY') {
2119: if (@{$types} > 0) {
2120: $datatable =
2121: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2122: \@fields,$types,\$numrows);
1.30 raeburn 2123: $$rowtotal += @{$types};
1.26 raeburn 2124: }
1.3 raeburn 2125: }
2126: $datatable .=
2127: &usertype_update_row($settings,{'default' => $othertitle},
2128: \%fieldtitles,\@fields,['default'],
2129: \$numrows);
1.30 raeburn 2130: $$rowtotal ++;
1.3 raeburn 2131: }
2132: return $datatable;
2133: }
2134:
1.125 raeburn 2135: sub print_autocreate {
2136: my ($dom,$settings,$rowtotal) = @_;
2137: my (%createon,%createoff);
2138: my $curr_dc;
2139: my @types = ('xml','req');
2140: if (ref($settings) eq 'HASH') {
2141: foreach my $item (@types) {
2142: $createoff{$item} = ' checked="checked" ';
2143: $createon{$item} = ' ';
2144: if (exists($settings->{$item})) {
2145: if ($settings->{$item}) {
2146: $createon{$item} = ' checked="checked" ';
2147: $createoff{$item} = ' ';
2148: }
2149: }
2150: }
2151: $curr_dc = $settings->{'xmldc'};
2152: } else {
2153: foreach my $item (@types) {
2154: $createoff{$item} = ' checked="checked" ';
2155: $createon{$item} = ' ';
2156: }
2157: }
2158: $$rowtotal += 2;
2159: my $datatable='<tr class="LC_odd_row">'.
2160: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2161: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2162: '<input type="radio" name="autocreate_xml"'.
2163: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2164: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2165: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2166: '</td></tr><tr>'.
2167: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2168: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2169: '<input type="radio" name="autocreate_req"'.
2170: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2171: '<label><input type="radio" name="autocreate_req"'.
2172: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2173: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2174: if ($numdc > 1) {
1.143 raeburn 2175: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2176: &mt('Course creation processed as: (choose Dom. Coord.)').
2177: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2178: $$rowtotal ++ ;
2179: } else {
1.143 raeburn 2180: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2181: }
2182: return $datatable;
2183: }
2184:
1.23 raeburn 2185: sub print_directorysrch {
1.30 raeburn 2186: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2187: my $srchon = ' ';
2188: my $srchoff = ' checked="checked" ';
1.25 raeburn 2189: my ($exacton,$containson,$beginson);
1.24 raeburn 2190: my $localon = ' ';
2191: my $localoff = ' checked="checked" ';
1.23 raeburn 2192: if (ref($settings) eq 'HASH') {
2193: if ($settings->{'available'} eq '1') {
2194: $srchon = $srchoff;
2195: $srchoff = ' ';
2196: }
1.24 raeburn 2197: if ($settings->{'localonly'} eq '1') {
2198: $localon = $localoff;
2199: $localoff = ' ';
2200: }
1.25 raeburn 2201: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2202: foreach my $type (@{$settings->{'searchtypes'}}) {
2203: if ($type eq 'exact') {
2204: $exacton = ' checked="checked" ';
2205: } elsif ($type eq 'contains') {
2206: $containson = ' checked="checked" ';
2207: } elsif ($type eq 'begins') {
2208: $beginson = ' checked="checked" ';
2209: }
2210: }
2211: } else {
2212: if ($settings->{'searchtypes'} eq 'exact') {
2213: $exacton = ' checked="checked" ';
2214: } elsif ($settings->{'searchtypes'} eq 'contains') {
2215: $containson = ' checked="checked" ';
2216: } elsif ($settings->{'searchtypes'} eq 'specify') {
2217: $exacton = ' checked="checked" ';
2218: $containson = ' checked="checked" ';
2219: }
1.23 raeburn 2220: }
2221: }
2222: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2223: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2224:
2225: my $numinrow = 4;
1.26 raeburn 2226: my $cansrchrow = 0;
1.23 raeburn 2227: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2228: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2229: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2230: '<input type="radio" name="dirsrch_available"'.
2231: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2232: '<label><input type="radio" name="dirsrch_available"'.
2233: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2234: '</tr><tr>'.
1.30 raeburn 2235: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2236: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2237: '<input type="radio" name="dirsrch_localonly"'.
2238: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2239: '<label><input type="radio" name="dirsrch_localonly"'.
2240: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2241: '</tr>';
1.30 raeburn 2242: $$rowtotal += 2;
1.26 raeburn 2243: if (ref($usertypes) eq 'HASH') {
2244: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2245: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2246: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2247: $cansrchrow = 1;
2248: }
2249: }
2250: if ($cansrchrow) {
1.30 raeburn 2251: $$rowtotal ++;
1.26 raeburn 2252: $datatable .= '<tr>';
2253: } else {
2254: $datatable .= '<tr class="LC_odd_row">';
2255: }
1.30 raeburn 2256: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2257: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2258: foreach my $title (@{$titleorder}) {
2259: if (defined($searchtitles->{$title})) {
2260: my $check = ' ';
1.93 raeburn 2261: if (ref($settings) eq 'HASH') {
1.39 raeburn 2262: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2263: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2264: $check = ' checked="checked" ';
2265: }
1.25 raeburn 2266: }
2267: }
2268: $datatable .= '<td class="LC_left_item">'.
2269: '<span class="LC_nobreak"><label>'.
2270: '<input type="checkbox" name="searchby" '.
2271: 'value="'.$title.'"'.$check.'/>'.
2272: $searchtitles->{$title}.'</label></span></td>';
2273: }
2274: }
1.26 raeburn 2275: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2276: $$rowtotal ++;
1.26 raeburn 2277: if ($cansrchrow) {
2278: $datatable .= '<tr class="LC_odd_row">';
2279: } else {
2280: $datatable .= '<tr>';
2281: }
1.30 raeburn 2282: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2283: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2284: '<span class="LC_nobreak"><label>'.
2285: '<input type="checkbox" name="searchtypes" '.
2286: $exacton.' value="exact" />'.&mt('Exact match').
2287: '</label> '.
2288: '<label><input type="checkbox" name="searchtypes" '.
2289: $beginson.' value="begins" />'.&mt('Begins with').
2290: '</label> '.
2291: '<label><input type="checkbox" name="searchtypes" '.
2292: $containson.' value="contains" />'.&mt('Contains').
2293: '</label></span></td></tr>';
1.30 raeburn 2294: $$rowtotal ++;
1.25 raeburn 2295: return $datatable;
2296: }
2297:
1.28 raeburn 2298: sub print_contacts {
1.30 raeburn 2299: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2300: my $datatable;
2301: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2302: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2303: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2304: 'requestsmail');
1.28 raeburn 2305: foreach my $type (@mailings) {
2306: $otheremails{$type} = '';
2307: }
1.134 raeburn 2308: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2309: if (ref($settings) eq 'HASH') {
2310: foreach my $item (@contacts) {
2311: if (exists($settings->{$item})) {
2312: $to{$item} = $settings->{$item};
2313: }
2314: }
2315: foreach my $type (@mailings) {
2316: if (exists($settings->{$type})) {
2317: if (ref($settings->{$type}) eq 'HASH') {
2318: foreach my $item (@contacts) {
2319: if ($settings->{$type}{$item}) {
2320: $checked{$type}{$item} = ' checked="checked" ';
2321: }
2322: }
2323: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2324: if ($type eq 'helpdeskmail') {
2325: $bccemails{$type} = $settings->{$type}{'bcc'};
2326: }
1.28 raeburn 2327: }
1.89 raeburn 2328: } elsif ($type eq 'lonstatusmail') {
2329: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2330: }
2331: }
2332: } else {
2333: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2334: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2335: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2336: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2337: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2338: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2339: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2340: }
2341: my ($titles,$short_titles) = &contact_titles();
2342: my $rownum = 0;
2343: my $css_class;
2344: foreach my $item (@contacts) {
1.69 raeburn 2345: $rownum ++;
2346: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2347: $datatable .= '<tr'.$css_class.'>'.
2348: '<td><span class="LC_nobreak">'.$titles->{$item}.
2349: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2350: '<input type="text" name="'.$item.'" value="'.
2351: $to{$item}.'" /></td></tr>';
2352: }
2353: foreach my $type (@mailings) {
1.69 raeburn 2354: $rownum ++;
2355: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2356: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2357: '<td><span class="LC_nobreak">'.
2358: $titles->{$type}.': </span></td>'.
1.28 raeburn 2359: '<td class="LC_left_item">'.
2360: '<span class="LC_nobreak">';
2361: foreach my $item (@contacts) {
2362: $datatable .= '<label>'.
2363: '<input type="checkbox" name="'.$type.'"'.
2364: $checked{$type}{$item}.
2365: ' value="'.$item.'" />'.$short_titles->{$item}.
2366: '</label> ';
2367: }
2368: $datatable .= '</span><br />'.&mt('Others').': '.
2369: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2370: 'value="'.$otheremails{$type}.'" />';
2371: if ($type eq 'helpdeskmail') {
1.136 raeburn 2372: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2373: '<input type="text" name="'.$type.'_bcc" '.
2374: 'value="'.$bccemails{$type}.'" />';
2375: }
2376: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2377: }
1.30 raeburn 2378: $$rowtotal += $rownum;
1.28 raeburn 2379: return $datatable;
2380: }
2381:
1.118 jms 2382: sub print_helpsettings {
1.168 raeburn 2383: my ($dom,$confname,$settings,$rowtotal) = @_;
2384: my ($datatable,$itemcount);
1.166 raeburn 2385: $itemcount = 1;
1.168 raeburn 2386: my (%choices,%defaultchecked,@toggles);
2387: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2388: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2389: &mt('LON-CAPA bug tracker'),600,500));
2390: %defaultchecked = ('submitbugs' => 'on');
2391: @toggles = ('submitbugs',);
1.166 raeburn 2392:
1.168 raeburn 2393: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2394: \%choices,$itemcount);
1.166 raeburn 2395: return $datatable;
1.121 raeburn 2396: }
2397:
2398: sub radiobutton_prefs {
2399: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2400: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2401: (ref($choices) eq 'HASH'));
2402:
1.170 raeburn 2403: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2404:
2405: foreach my $item (@{$toggles}) {
2406: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2407: $checkedon{$item} = ' checked="checked" ';
2408: $checkedoff{$item} = ' ';
1.121 raeburn 2409: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2410: $checkedoff{$item} = ' checked="checked" ';
2411: $checkedon{$item} = ' ';
2412: }
2413: }
2414: if (ref($settings) eq 'HASH') {
1.121 raeburn 2415: foreach my $item (@{$toggles}) {
1.118 jms 2416: if ($settings->{$item} eq '1') {
2417: $checkedon{$item} = ' checked="checked" ';
2418: $checkedoff{$item} = ' ';
2419: } elsif ($settings->{$item} eq '0') {
2420: $checkedoff{$item} = ' checked="checked" ';
2421: $checkedon{$item} = ' ';
2422: }
2423: }
1.121 raeburn 2424: }
2425: foreach my $item (@{$toggles}) {
1.118 jms 2426: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2427: $datatable .=
2428: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2429: '</span></td>'.
2430: '<td class="LC_right_item"><span class="LC_nobreak">'.
2431: '<label><input type="radio" name="'.
2432: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2433: '</label> <label><input type="radio" name="'.$item.'" '.
2434: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2435: '</span></td>'.
2436: '</tr>';
2437: $itemcount ++;
1.121 raeburn 2438: }
2439: return ($datatable,$itemcount);
2440: }
2441:
2442: sub print_coursedefaults {
1.139 raeburn 2443: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2444: my ($css_class,$datatable);
2445: my $itemcount = 1;
1.139 raeburn 2446: if ($position eq 'top') {
2447: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2448: %choices =
2449: &Apache::lonlocal::texthash (
2450: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2451: );
2452: %defaultchecked = ('canuse_pdfforms' => 'off');
2453: @toggles = ('canuse_pdfforms',);
2454: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2455: \%choices,$itemcount);
1.139 raeburn 2456: $$rowtotal += $itemcount;
2457: } else {
2458: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2459: my %choices =
2460: &Apache::lonlocal::texthash (
2461: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2462: );
2463: my $currdefresponder;
2464: if (ref($settings) eq 'HASH') {
2465: $currdefresponder = $settings->{'anonsurvey_threshold'};
2466: }
2467: if (!$currdefresponder) {
2468: $currdefresponder = 10;
2469: } elsif ($currdefresponder < 1) {
2470: $currdefresponder = 1;
2471: }
2472: $datatable .=
2473: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2474: '</span></td>'.
2475: '<td class="LC_right_item"><span class="LC_nobreak">'.
2476: '<input type="text" name="anonsurvey_threshold"'.
2477: ' value="'.$currdefresponder.'" size="5" /></span>'.
2478: '</td></tr>';
2479: }
1.121 raeburn 2480: return $datatable;
1.118 jms 2481: }
2482:
1.137 raeburn 2483: sub print_usersessions {
2484: my ($position,$dom,$settings,$rowtotal) = @_;
2485: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2486: my (%by_ip,%by_location,@intdoms);
2487: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2488:
2489: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2490: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2491: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2492: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2493: my $itemcount = 1;
2494: if ($position eq 'top') {
1.152 raeburn 2495: if (keys(%serverhomes) > 1) {
1.145 raeburn 2496: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2497: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2498: } else {
1.140 raeburn 2499: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2500: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2501: }
1.137 raeburn 2502: } else {
1.145 raeburn 2503: if (keys(%by_location) == 0) {
2504: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2505: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2506: } else {
2507: my %lt = &usersession_titles();
2508: my $numinrow = 5;
2509: my $prefix;
2510: my @types;
2511: if ($position eq 'bottom') {
2512: $prefix = 'remote';
2513: @types = ('version','excludedomain','includedomain');
2514: } else {
2515: $prefix = 'hosted';
2516: @types = ('excludedomain','includedomain');
2517: }
2518: my (%current,%checkedon,%checkedoff);
2519: my @lcversions = &Apache::lonnet::all_loncaparevs();
2520: my @locations = sort(keys(%by_location));
2521: foreach my $type (@types) {
2522: $checkedon{$type} = '';
2523: $checkedoff{$type} = ' checked="checked"';
2524: }
2525: if (ref($settings) eq 'HASH') {
2526: if (ref($settings->{$prefix}) eq 'HASH') {
2527: foreach my $key (keys(%{$settings->{$prefix}})) {
2528: $current{$key} = $settings->{$prefix}{$key};
2529: if ($key eq 'version') {
2530: if ($current{$key} ne '') {
2531: $checkedon{$key} = ' checked="checked"';
2532: $checkedoff{$key} = '';
2533: }
2534: } elsif (ref($current{$key}) eq 'ARRAY') {
2535: $checkedon{$key} = ' checked="checked"';
2536: $checkedoff{$key} = '';
2537: }
1.137 raeburn 2538: }
2539: }
2540: }
1.145 raeburn 2541: foreach my $type (@types) {
2542: next if ($type ne 'version' && !@locations);
2543: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2544: $datatable .= '<tr'.$css_class.'>
2545: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2546: <span class="LC_nobreak">
2547: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2548: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2549: if ($type eq 'version') {
2550: my $selector = '<select name="'.$prefix.'_version">';
2551: foreach my $version (@lcversions) {
2552: my $selected = '';
2553: if ($current{'version'} eq $version) {
2554: $selected = ' selected="selected"';
2555: }
2556: $selector .= ' <option value="'.$version.'"'.
2557: $selected.'>'.$version.'</option>';
2558: }
2559: $selector .= '</select> ';
2560: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2561: } else {
2562: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2563: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2564: ' />'.(' 'x2).
2565: '<input type="button" value="'.&mt('uncheck all').'" '.
2566: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2567: "\n".
2568: '</div><div><table>';
2569: my $rem;
2570: for (my $i=0; $i<@locations; $i++) {
2571: my ($showloc,$value,$checkedtype);
2572: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2573: my $ip = $by_location{$locations[$i]}->[0];
2574: if (ref($by_ip{$ip}) eq 'ARRAY') {
2575: $value = join(':',@{$by_ip{$ip}});
2576: $showloc = join(', ',@{$by_ip{$ip}});
2577: if (ref($current{$type}) eq 'ARRAY') {
2578: foreach my $loc (@{$by_ip{$ip}}) {
2579: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2580: $checkedtype = ' checked="checked"';
2581: last;
2582: }
2583: }
1.138 raeburn 2584: }
2585: }
2586: }
1.145 raeburn 2587: $rem = $i%($numinrow);
2588: if ($rem == 0) {
2589: if ($i > 0) {
2590: $datatable .= '</tr>';
2591: }
2592: $datatable .= '<tr>';
2593: }
2594: $datatable .= '<td class="LC_left_item">'.
2595: '<span class="LC_nobreak"><label>'.
2596: '<input type="checkbox" name="'.$prefix.'_'.$type.
2597: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2598: '</label></span></td>';
1.137 raeburn 2599: }
1.145 raeburn 2600: $rem = @locations%($numinrow);
2601: my $colsleft = $numinrow - $rem;
2602: if ($colsleft > 1 ) {
2603: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2604: ' </td>';
2605: } elsif ($colsleft == 1) {
2606: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2607: }
1.145 raeburn 2608: $datatable .= '</tr></table>';
1.137 raeburn 2609: }
1.145 raeburn 2610: $datatable .= '</td></tr>';
2611: $itemcount ++;
1.137 raeburn 2612: }
2613: }
2614: }
2615: $$rowtotal += $itemcount;
2616: return $datatable;
2617: }
2618:
1.138 raeburn 2619: sub build_location_hashes {
2620: my ($intdoms,$by_ip,$by_location) = @_;
2621: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2622: (ref($by_location) eq 'HASH'));
2623: my %iphost = &Apache::lonnet::get_iphost();
2624: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2625: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2626: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2627: foreach my $id (@{$iphost{$primary_ip}}) {
2628: my $intdom = &Apache::lonnet::internet_dom($id);
2629: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2630: push(@{$intdoms},$intdom);
2631: }
2632: }
2633: }
2634: foreach my $ip (keys(%iphost)) {
2635: if (ref($iphost{$ip}) eq 'ARRAY') {
2636: foreach my $id (@{$iphost{$ip}}) {
2637: my $location = &Apache::lonnet::internet_dom($id);
2638: if ($location) {
2639: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2640: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2641: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2642: push(@{$by_ip->{$ip}},$location);
2643: }
2644: } else {
2645: $by_ip->{$ip} = [$location];
2646: }
2647: }
2648: }
2649: }
2650: }
2651: foreach my $ip (sort(keys(%{$by_ip}))) {
2652: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2653: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2654: my $first = $by_ip->{$ip}->[0];
2655: if (ref($by_location->{$first}) eq 'ARRAY') {
2656: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2657: push(@{$by_location->{$first}},$ip);
2658: }
2659: } else {
2660: $by_location->{$first} = [$ip];
2661: }
2662: }
2663: }
2664: return;
2665: }
2666:
1.145 raeburn 2667: sub current_offloads_to {
2668: my ($dom,$settings,$servers) = @_;
2669: my (%spareid,%otherdomconfigs);
1.152 raeburn 2670: if (ref($servers) eq 'HASH') {
1.145 raeburn 2671: foreach my $lonhost (sort(keys(%{$servers}))) {
2672: my $gotspares;
1.152 raeburn 2673: if (ref($settings) eq 'HASH') {
2674: if (ref($settings->{'spares'}) eq 'HASH') {
2675: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2676: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2677: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2678: $gotspares = 1;
2679: }
1.145 raeburn 2680: }
2681: }
2682: unless ($gotspares) {
2683: my $gotspares;
2684: my $serverhomeID =
2685: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2686: my $serverhomedom =
2687: &Apache::lonnet::host_domain($serverhomeID);
2688: if ($serverhomedom ne $dom) {
2689: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2690: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2691: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2692: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2693: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2694: $gotspares = 1;
2695: }
2696: }
2697: } else {
2698: $otherdomconfigs{$serverhomedom} =
2699: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2700: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2701: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2702: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2703: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2704: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2705: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2706: $gotspares = 1;
2707: }
2708: }
2709: }
2710: }
2711: }
2712: }
2713: }
2714: unless ($gotspares) {
2715: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2716: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2717: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2718: } else {
2719: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2720: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2721: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2722: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2723: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2724: } else {
1.150 raeburn 2725: my %what = (
2726: spareid => 1,
2727: );
2728: my ($result,$returnhash) =
2729: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2730: if ($result eq 'ok') {
2731: if (ref($returnhash) eq 'HASH') {
2732: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2733: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2734: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2735: }
2736: }
1.145 raeburn 2737: }
2738: }
2739: }
2740: }
2741: }
2742: }
2743: return %spareid;
2744: }
2745:
2746: sub spares_row {
1.152 raeburn 2747: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2748: my $css_class;
2749: my $numinrow = 4;
2750: my $itemcount = 1;
2751: my $datatable;
1.152 raeburn 2752: my %typetitles = &sparestype_titles();
2753: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2754: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2755: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2756: my ($othercontrol,$serverdom);
2757: if ($serverhome ne $server) {
2758: $serverdom = &Apache::lonnet::host_domain($serverhome);
2759: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2760: } else {
2761: $serverdom = &Apache::lonnet::host_domain($server);
2762: if ($serverdom ne $dom) {
2763: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2764: }
2765: }
2766: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2767: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2768: $datatable .= '<tr'.$css_class.'>
2769: <td rowspan="2">
1.152 raeburn 2770: <span class="LC_nobreak"><b>'.$server.'</b> when busy, offloads to:</span></td>'."\n";
1.145 raeburn 2771: my (%current,%canselect);
1.152 raeburn 2772: my @choices =
2773: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2774: foreach my $type ('primary','default') {
2775: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2776: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2777: my @spares = @{$spareid->{$server}{$type}};
2778: if (@spares > 0) {
1.152 raeburn 2779: if ($othercontrol) {
2780: $current{$type} = join(', ',@spares);
2781: } else {
2782: $current{$type} .= '<table>';
2783: my $numspares = scalar(@spares);
2784: for (my $i=0; $i<@spares; $i++) {
2785: my $rem = $i%($numinrow);
2786: if ($rem == 0) {
2787: if ($i > 0) {
2788: $current{$type} .= '</tr>';
2789: }
2790: $current{$type} .= '<tr>';
1.145 raeburn 2791: }
1.152 raeburn 2792: $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'".');" /> '.
2793: $spareid->{$server}{$type}[$i].
2794: '</label></td>'."\n";
2795: }
2796: my $rem = @spares%($numinrow);
2797: my $colsleft = $numinrow - $rem;
2798: if ($colsleft > 1 ) {
2799: $current{$type} .= '<td colspan="'.$colsleft.
2800: '" class="LC_left_item">'.
2801: ' </td>';
2802: } elsif ($colsleft == 1) {
2803: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2804: }
1.152 raeburn 2805: $current{$type} .= '</tr></table>';
1.150 raeburn 2806: }
1.145 raeburn 2807: }
2808: }
2809: if ($current{$type} eq '') {
2810: $current{$type} = &mt('None specified');
2811: }
1.152 raeburn 2812: if ($othercontrol) {
2813: if ($type eq 'primary') {
2814: $canselect{$type} = $othercontrol;
2815: }
2816: } else {
2817: $canselect{$type} =
2818: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2819: '<select name="newspare_'.$type.'_'.$server.'" '.
2820: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2821: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2822: if (@choices > 0) {
2823: foreach my $lonhost (@choices) {
2824: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2825: }
2826: }
2827: $canselect{$type} .= '</select>'."\n";
2828: }
2829: } else {
2830: $current{$type} = &mt('Could not be determined');
2831: if ($type eq 'primary') {
2832: $canselect{$type} = $othercontrol;
2833: }
1.145 raeburn 2834: }
1.152 raeburn 2835: if ($type eq 'default') {
2836: $datatable .= '<tr'.$css_class.'>';
2837: }
2838: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2839: '<td>'.$current{$type}.'</td>'."\n".
2840: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2841: }
2842: $itemcount ++;
2843: }
2844: }
2845: $$rowtotal += $itemcount;
2846: return $datatable;
2847: }
2848:
1.152 raeburn 2849: sub possible_newspares {
2850: my ($server,$currspares,$serverhomes,$altids) = @_;
2851: my $serverhostname = &Apache::lonnet::hostname($server);
2852: my %excluded;
2853: if ($serverhostname ne '') {
2854: %excluded = (
2855: $serverhostname => 1,
2856: );
2857: }
2858: if (ref($currspares) eq 'HASH') {
2859: foreach my $type (keys(%{$currspares})) {
2860: if (ref($currspares->{$type}) eq 'ARRAY') {
2861: if (@{$currspares->{$type}} > 0) {
2862: foreach my $curr (@{$currspares->{$type}}) {
2863: my $hostname = &Apache::lonnet::hostname($curr);
2864: $excluded{$hostname} = 1;
2865: }
2866: }
2867: }
2868: }
2869: }
2870: my @choices;
2871: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2872: if (keys(%{$serverhomes}) > 1) {
2873: foreach my $name (sort(keys(%{$serverhomes}))) {
2874: unless ($excluded{$name}) {
2875: if (exists($altids->{$serverhomes->{$name}})) {
2876: push(@choices,$altids->{$serverhomes->{$name}});
2877: } else {
2878: push(@choices,$serverhomes->{$name});
1.145 raeburn 2879: }
2880: }
2881: }
2882: }
2883: }
1.152 raeburn 2884: return sort(@choices);
1.145 raeburn 2885: }
2886:
1.150 raeburn 2887: sub print_loadbalancing {
2888: my ($dom,$settings,$rowtotal) = @_;
2889: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2890: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2891: my $numinrow = 1;
2892: my $datatable;
2893: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2894: my (%currbalancer,%currtargets,%currrules,%existing);
2895: if (ref($settings) eq 'HASH') {
2896: %existing = %{$settings};
2897: }
2898: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2899: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2900: \%currtargets,\%currrules);
1.150 raeburn 2901: } else {
2902: return;
2903: }
2904: my ($othertitle,$usertypes,$types) =
2905: &Apache::loncommon::sorted_inst_types($dom);
2906: my $rownum = 6;
2907: if (ref($types) eq 'ARRAY') {
2908: $rownum += scalar(@{$types});
2909: }
1.171 raeburn 2910: my @css_class = ('LC_odd_row','LC_even_row');
2911: my $balnum = 0;
2912: my $islast;
2913: my (@toshow,$disabledtext);
2914: if (keys(%currbalancer) > 0) {
2915: @toshow = sort(keys(%currbalancer));
2916: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2917: push(@toshow,'');
2918: }
2919: } else {
2920: @toshow = ('');
2921: $disabledtext = &mt('No existing load balancer');
2922: }
2923: foreach my $lonhost (@toshow) {
2924: if ($balnum == scalar(@toshow)-1) {
2925: $islast = 1;
2926: } else {
2927: $islast = 0;
2928: }
2929: my $cssidx = $balnum%2;
2930: my $targets_div_style = 'display: none';
2931: my $disabled_div_style = 'display: block';
2932: my $homedom_div_style = 'display: none';
2933: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2934: '<td rowspan="'.$rownum.'" valign="top">'.
2935: '<p>';
2936: if ($lonhost eq '') {
2937: $datatable .= '<span class="LC_nobreak">';
2938: if (keys(%currbalancer) > 0) {
2939: $datatable .= &mt('Add balancer:');
2940: } else {
2941: $datatable .= &mt('Enable balancer:');
2942: }
2943: $datatable .= ' '.
2944: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2945: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2946: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2947: '<option value="" selected="selected">'.&mt('None').
2948: '</option>'."\n";
2949: foreach my $server (sort(keys(%servers))) {
2950: next if ($currbalancer{$server});
2951: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2952: }
2953: $datatable .=
2954: '</select>'."\n".
2955: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2956: } else {
2957: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2958: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2959: &mt('Stop balancing').'</label>'.
2960: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2961: $targets_div_style = 'display: block';
2962: $disabled_div_style = 'display: none';
2963: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2964: $homedom_div_style = 'display: block';
2965: }
2966: }
2967: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2968: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2969: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2970: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2971: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2972: my @sparestypes = ('primary','default');
2973: my %typetitles = &sparestype_titles();
2974: foreach my $sparetype (@sparestypes) {
2975: my $targettable;
2976: for (my $i=0; $i<$numspares; $i++) {
2977: my $checked;
2978: if (ref($currtargets{$lonhost}) eq 'HASH') {
2979: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
2980: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
2981: $checked = ' checked="checked"';
2982: }
2983: }
2984: }
2985: my ($chkboxval,$disabled);
2986: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
2987: $chkboxval = $spares[$i];
2988: }
2989: if (exists($currbalancer{$spares[$i]})) {
2990: $disabled = ' disabled="disabled"';
2991: }
2992: $targettable .=
2993: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
2994: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
2995: '</span></label></td>';
2996: my $rem = $i%($numinrow);
2997: if ($rem == 0) {
2998: if (($i > 0) && ($i < $numspares-1)) {
2999: $targettable .= '</tr>';
3000: }
3001: if ($i < $numspares-1) {
3002: $targettable .= '<tr>';
1.150 raeburn 3003: }
3004: }
3005: }
1.171 raeburn 3006: if ($targettable ne '') {
3007: my $rem = $numspares%($numinrow);
3008: my $colsleft = $numinrow - $rem;
3009: if ($colsleft > 1 ) {
3010: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3011: ' </td>';
3012: } elsif ($colsleft == 1) {
3013: $targettable .= '<td class="LC_left_item"> </td>';
3014: }
3015: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3016: '<table><tr>'.$targettable.'</tr></table><br />';
3017: }
3018: }
3019: my $cssidx = $balnum%2;
3020: $datatable .= '</div></td></tr>'.
3021: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3022: $othertitle,$usertypes,$types,\%servers,
3023: \%currbalancer,$lonhost,
3024: $targets_div_style,$homedom_div_style,
3025: $css_class[$cssidx],$balnum,$islast);
3026: $$rowtotal += $rownum;
3027: $balnum ++;
3028: }
3029: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3030: return $datatable;
3031: }
3032:
3033: sub get_loadbalancers_config {
3034: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3035: return unless ((ref($servers) eq 'HASH') &&
3036: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3037: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3038: if (keys(%{$existing}) > 0) {
3039: my $oldlonhost;
3040: foreach my $key (sort(keys(%{$existing}))) {
3041: if ($key eq 'lonhost') {
3042: $oldlonhost = $existing->{'lonhost'};
3043: $currbalancer->{$oldlonhost} = 1;
3044: } elsif ($key eq 'targets') {
3045: if ($oldlonhost) {
3046: $currtargets->{$oldlonhost} = $existing->{'targets'};
3047: }
3048: } elsif ($key eq 'rules') {
3049: if ($oldlonhost) {
3050: $currrules->{$oldlonhost} = $existing->{'rules'};
3051: }
3052: } elsif (ref($existing->{$key}) eq 'HASH') {
3053: $currbalancer->{$key} = 1;
3054: $currtargets->{$key} = $existing->{$key}{'targets'};
3055: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3056: }
3057: }
1.171 raeburn 3058: } else {
3059: my ($balancerref,$targetsref) =
3060: &Apache::lonnet::get_lonbalancer_config($servers);
3061: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3062: foreach my $server (sort(keys(%{$balancerref}))) {
3063: $currbalancer->{$server} = 1;
3064: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3065: }
3066: }
3067: }
1.171 raeburn 3068: return;
1.150 raeburn 3069: }
3070:
3071: sub loadbalancing_rules {
3072: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3073: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3074: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3075: my $output;
1.171 raeburn 3076: my $num = 0;
1.150 raeburn 3077: my ($alltypes,$othertypes,$titles) =
3078: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3079: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3080: foreach my $type (@{$alltypes}) {
1.171 raeburn 3081: $num ++;
1.150 raeburn 3082: my $current;
3083: if (ref($currrules) eq 'HASH') {
3084: $current = $currrules->{$type};
3085: }
3086: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3087: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3088: $current = '';
3089: }
3090: }
3091: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3092: $servers,$currbalancer,$lonhost,$dom,
3093: $targets_div_style,$homedom_div_style,
3094: $css_class,$balnum,$num,$islast);
1.150 raeburn 3095: }
3096: }
3097: return $output;
3098: }
3099:
3100: sub loadbalancing_titles {
3101: my ($dom,$intdom,$usertypes,$types) = @_;
3102: my %othertypes = (
3103: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3104: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3105: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3106: '_LC_external' => &mt('Users not from [_1]',$intdom),
3107: );
3108: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3109: if (ref($types) eq 'ARRAY') {
3110: unshift(@alltypes,@{$types},'default');
3111: }
3112: my %titles;
3113: foreach my $type (@alltypes) {
3114: if ($type =~ /^_LC_/) {
3115: $titles{$type} = $othertypes{$type};
3116: } elsif ($type eq 'default') {
3117: $titles{$type} = &mt('All users from [_1]',$dom);
3118: if (ref($types) eq 'ARRAY') {
3119: if (@{$types} > 0) {
3120: $titles{$type} = &mt('Other users from [_1]',$dom);
3121: }
3122: }
3123: } elsif (ref($usertypes) eq 'HASH') {
3124: $titles{$type} = $usertypes->{$type};
3125: }
3126: }
3127: return (\@alltypes,\%othertypes,\%titles);
3128: }
3129:
3130: sub loadbalance_rule_row {
1.171 raeburn 3131: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3132: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3133: my @rulenames = ('default','homeserver');
3134: my %ruletitles = &offloadtype_text();
3135: if ($type eq '_LC_external') {
3136: push(@rulenames,'externalbalancer');
3137: } else {
3138: push(@rulenames,'specific');
3139: }
1.161 raeburn 3140: push(@rulenames,'none');
1.150 raeburn 3141: my $style = $targets_div_style;
3142: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3143: $style = $homedom_div_style;
3144: }
1.171 raeburn 3145: my $space;
3146: if ($islast && $num == 1) {
3147: $space = '<div display="inline-block"> </div>';
3148: }
1.150 raeburn 3149: my $output =
1.171 raeburn 3150: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3151: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3152: '<td valaign="top">'.$space.
3153: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3154: for (my $i=0; $i<@rulenames; $i++) {
3155: my $rule = $rulenames[$i];
3156: my ($checked,$extra);
3157: if ($rulenames[$i] eq 'default') {
3158: $rule = '';
3159: }
3160: if ($rulenames[$i] eq 'specific') {
3161: if (ref($servers) eq 'HASH') {
3162: my $default;
3163: if (($current ne '') && (exists($servers->{$current}))) {
3164: $checked = ' checked="checked"';
3165: }
3166: unless ($checked) {
3167: $default = ' selected="selected"';
3168: }
1.171 raeburn 3169: $extra =
3170: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3171: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3172: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3173: '<option value=""'.$default.'></option>'."\n";
3174: foreach my $server (sort(keys(%{$servers}))) {
3175: if (ref($currbalancer) eq 'HASH') {
3176: next if (exists($currbalancer->{$server}));
3177: }
1.150 raeburn 3178: my $selected;
1.171 raeburn 3179: if ($server eq $current) {
1.150 raeburn 3180: $selected = ' selected="selected"';
3181: }
1.171 raeburn 3182: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3183: }
3184: $extra .= '</select>';
3185: }
3186: } elsif ($rule eq $current) {
3187: $checked = ' checked="checked"';
3188: }
3189: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3190: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3191: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3192: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3193: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3194: '</label>'.$extra.'</span><br />'."\n";
3195: }
3196: $output .= '</div></td></tr>'."\n";
3197: return $output;
3198: }
3199:
3200: sub offloadtype_text {
3201: my %ruletitles = &Apache::lonlocal::texthash (
3202: 'default' => 'Offloads to default destinations',
3203: 'homeserver' => "Offloads to user's home server",
3204: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3205: 'specific' => 'Offloads to specific server',
1.161 raeburn 3206: 'none' => 'No offload',
1.150 raeburn 3207: );
3208: return %ruletitles;
3209: }
3210:
3211: sub sparestype_titles {
3212: my %typestitles = &Apache::lonlocal::texthash (
3213: 'primary' => 'primary',
3214: 'default' => 'default',
3215: );
3216: return %typestitles;
3217: }
3218:
1.28 raeburn 3219: sub contact_titles {
3220: my %titles = &Apache::lonlocal::texthash (
3221: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3222: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3223: 'errormail' => 'Error reports to be e-mailed to',
3224: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3225: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3226: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3227: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3228: );
3229: my %short_titles = &Apache::lonlocal::texthash (
3230: adminemail => 'Admin E-mail address',
3231: supportemail => 'Support E-mail',
3232: );
3233: return (\%titles,\%short_titles);
3234: }
3235:
1.72 raeburn 3236: sub tool_titles {
3237: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3238: aboutme => 'Personal web page',
1.86 raeburn 3239: blog => 'Blog',
1.162 raeburn 3240: webdav => 'WebDAV',
1.86 raeburn 3241: portfolio => 'Portfolio',
1.88 bisitz 3242: official => 'Official courses (with institutional codes)',
3243: unofficial => 'Unofficial courses',
1.98 raeburn 3244: community => 'Communities',
1.86 raeburn 3245: );
1.72 raeburn 3246: return %titles;
3247: }
3248:
1.101 raeburn 3249: sub courserequest_titles {
3250: my %titles = &Apache::lonlocal::texthash (
3251: official => 'Official',
3252: unofficial => 'Unofficial',
3253: community => 'Communities',
3254: norequest => 'Not allowed',
1.104 raeburn 3255: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3256: validate => 'With validation',
3257: autolimit => 'Numerical limit',
1.103 raeburn 3258: unlimited => '(blank for unlimited)',
1.101 raeburn 3259: );
3260: return %titles;
3261: }
3262:
1.163 raeburn 3263: sub authorrequest_titles {
3264: my %titles = &Apache::lonlocal::texthash (
3265: norequest => 'Not allowed',
3266: approval => 'Approval by Dom. Coord.',
3267: automatic => 'Automatic approval',
3268: );
3269: return %titles;
3270: }
3271:
1.101 raeburn 3272: sub courserequest_conditions {
3273: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3274: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3275: validate => '(Processing of request subject to instittutional validation).',
3276: );
3277: return %conditions;
3278: }
3279:
3280:
1.27 raeburn 3281: sub print_usercreation {
1.30 raeburn 3282: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3283: my $numinrow = 4;
1.28 raeburn 3284: my $datatable;
3285: if ($position eq 'top') {
1.30 raeburn 3286: $$rowtotal ++;
1.34 raeburn 3287: my $rowcount = 0;
1.32 raeburn 3288: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3289: if (ref($rules) eq 'HASH') {
3290: if (keys(%{$rules}) > 0) {
1.32 raeburn 3291: $datatable .= &user_formats_row('username',$settings,$rules,
3292: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3293: $$rowtotal ++;
1.32 raeburn 3294: $rowcount ++;
3295: }
3296: }
3297: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3298: if (ref($idrules) eq 'HASH') {
3299: if (keys(%{$idrules}) > 0) {
3300: $datatable .= &user_formats_row('id',$settings,$idrules,
3301: $idruleorder,$numinrow,$rowcount);
3302: $$rowtotal ++;
3303: $rowcount ++;
1.28 raeburn 3304: }
3305: }
1.43 raeburn 3306: my ($emailrules,$emailruleorder) =
3307: &Apache::lonnet::inst_userrules($dom,'email');
3308: if (ref($emailrules) eq 'HASH') {
3309: if (keys(%{$emailrules}) > 0) {
3310: $datatable .= &user_formats_row('email',$settings,$emailrules,
3311: $emailruleorder,$numinrow,$rowcount);
3312: $$rowtotal ++;
3313: $rowcount ++;
3314: }
3315: }
1.39 raeburn 3316: if ($rowcount == 0) {
3317: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3318: $$rowtotal ++;
3319: $rowcount ++;
3320: }
1.34 raeburn 3321: } elsif ($position eq 'middle') {
1.100 raeburn 3322: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3323: my ($rules,$ruleorder) =
3324: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3325: my %lt = &usercreation_types();
3326: my %checked;
1.50 raeburn 3327: my @selfcreate;
1.34 raeburn 3328: if (ref($settings) eq 'HASH') {
3329: if (ref($settings->{'cancreate'}) eq 'HASH') {
3330: foreach my $item (@creators) {
3331: $checked{$item} = $settings->{'cancreate'}{$item};
3332: }
1.50 raeburn 3333: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3334: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3335: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3336: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3337: @selfcreate = ('email','login','sso');
3338: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3339: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3340: }
3341: }
1.34 raeburn 3342: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3343: foreach my $item (@creators) {
3344: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3345: $checked{$item} = 'none';
3346: }
3347: }
3348: }
3349: }
3350: my $rownum = 0;
3351: foreach my $item (@creators) {
3352: $rownum ++;
1.50 raeburn 3353: if ($item ne 'selfcreate') {
3354: if ($checked{$item} eq '') {
1.43 raeburn 3355: $checked{$item} = 'any';
3356: }
1.34 raeburn 3357: }
3358: my $css_class;
3359: if ($rownum%2) {
3360: $css_class = '';
3361: } else {
3362: $css_class = ' class="LC_odd_row" ';
3363: }
3364: $datatable .= '<tr'.$css_class.'>'.
3365: '<td><span class="LC_nobreak">'.$lt{$item}.
3366: '</span></td><td align="right">';
1.50 raeburn 3367: my @options;
1.45 raeburn 3368: if ($item eq 'selfcreate') {
1.43 raeburn 3369: push(@options,('email','login','sso'));
3370: } else {
1.50 raeburn 3371: @options = ('any');
1.43 raeburn 3372: if (ref($rules) eq 'HASH') {
3373: if (keys(%{$rules}) > 0) {
3374: push(@options,('official','unofficial'));
3375: }
1.37 raeburn 3376: }
1.50 raeburn 3377: push(@options,'none');
1.37 raeburn 3378: }
3379: foreach my $option (@options) {
1.50 raeburn 3380: my $type = 'radio';
1.34 raeburn 3381: my $check = ' ';
1.50 raeburn 3382: if ($item eq 'selfcreate') {
3383: $type = 'checkbox';
3384: if (grep(/^\Q$option\E$/,@selfcreate)) {
3385: $check = ' checked="checked" ';
3386: }
3387: } else {
3388: if ($checked{$item} eq $option) {
3389: $check = ' checked="checked" ';
3390: }
1.34 raeburn 3391: }
3392: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3393: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3394: $item.'" value="'.$option.'"'.$check.'/> '.
3395: $lt{$option}.'</label> </span>';
3396: }
3397: $datatable .= '</td></tr>';
3398: }
1.93 raeburn 3399: my ($othertitle,$usertypes,$types) =
3400: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3401: my $createsettings;
3402: if (ref($settings) eq 'HASH') {
3403: $createsettings = $settings->{cancreate};
3404: }
1.93 raeburn 3405: if (ref($usertypes) eq 'HASH') {
3406: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3407: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3408: $dom,$numinrow,$othertitle,
3409: 'statustocreate');
3410: $$rowtotal ++;
1.169 raeburn 3411: $rownum ++;
1.93 raeburn 3412: }
3413: }
1.169 raeburn 3414: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3415: } else {
3416: my @contexts = ('author','course','domain');
3417: my @authtypes = ('int','krb4','krb5','loc');
3418: my %checked;
3419: if (ref($settings) eq 'HASH') {
3420: if (ref($settings->{'authtypes'}) eq 'HASH') {
3421: foreach my $item (@contexts) {
3422: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3423: foreach my $auth (@authtypes) {
3424: if ($settings->{'authtypes'}{$item}{$auth}) {
3425: $checked{$item}{$auth} = ' checked="checked" ';
3426: }
3427: }
3428: }
3429: }
1.27 raeburn 3430: }
1.35 raeburn 3431: } else {
3432: foreach my $item (@contexts) {
1.36 raeburn 3433: foreach my $auth (@authtypes) {
1.35 raeburn 3434: $checked{$item}{$auth} = ' checked="checked" ';
3435: }
3436: }
1.27 raeburn 3437: }
1.28 raeburn 3438: my %title = &context_names();
3439: my %authname = &authtype_names();
3440: my $rownum = 0;
3441: my $css_class;
3442: foreach my $item (@contexts) {
3443: if ($rownum%2) {
3444: $css_class = '';
3445: } else {
3446: $css_class = ' class="LC_odd_row" ';
3447: }
1.30 raeburn 3448: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3449: '<td>'.$title{$item}.
3450: '</td><td class="LC_left_item">'.
3451: '<span class="LC_nobreak">';
3452: foreach my $auth (@authtypes) {
3453: $datatable .= '<label>'.
3454: '<input type="checkbox" name="'.$item.'_auth" '.
3455: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3456: $authname{$auth}.'</label> ';
3457: }
3458: $datatable .= '</span></td></tr>';
3459: $rownum ++;
1.27 raeburn 3460: }
1.30 raeburn 3461: $$rowtotal += $rownum;
1.27 raeburn 3462: }
3463: return $datatable;
3464: }
3465:
1.165 raeburn 3466: sub captcha_choice {
1.169 raeburn 3467: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3468: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3469: my %lt = &captcha_phrases();
3470: $keyentry = 'hidden';
3471: if ($context eq 'cancreate') {
3472: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3473: } elsif ($context eq 'login') {
3474: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3475: }
3476: if (ref($settings) eq 'HASH') {
3477: if ($settings->{'captcha'}) {
3478: $checked{$settings->{'captcha'}} = ' checked="checked"';
3479: } else {
3480: $checked{'original'} = ' checked="checked"';
3481: }
3482: if ($settings->{'captcha'} eq 'recaptcha') {
3483: $pubtext = $lt{'pub'};
3484: $privtext = $lt{'priv'};
3485: $keyentry = 'text';
3486: }
3487: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3488: $currpub = $settings->{'recaptchakeys'}{'public'};
3489: $currpriv = $settings->{'recaptchakeys'}{'private'};
3490: }
3491: } else {
3492: $checked{'original'} = ' checked="checked"';
3493: }
1.169 raeburn 3494: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3495: my $output = '<tr'.$css_class.'>'.
3496: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3497: '<table><tr><td>'."\n";
3498: foreach my $option ('original','recaptcha','notused') {
3499: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3500: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3501: $lt{$option}.'</label></span>';
3502: unless ($option eq 'notused') {
3503: $output .= (' 'x2)."\n";
3504: }
3505: }
3506: #
3507: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3508: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3509: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3510: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3511: #
3512: $output .= '</td></tr>'."\n".
3513: '<tr><td>'."\n".
3514: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3515: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3516: $currpub.'" size="40" /></span><br />'."\n".
3517: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3518: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3519: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3520: '</td></tr>';
3521: return $output;
3522: }
3523:
1.32 raeburn 3524: sub user_formats_row {
3525: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3526: my $output;
3527: my %text = (
3528: 'username' => 'new usernames',
3529: 'id' => 'IDs',
1.45 raeburn 3530: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3531: );
3532: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3533: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3534: '<td><span class="LC_nobreak">';
3535: if ($type eq 'email') {
3536: $output .= &mt("Formats disallowed for $text{$type}: ");
3537: } else {
3538: $output .= &mt("Format rules to check for $text{$type}: ");
3539: }
3540: $output .= '</span></td>'.
3541: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3542: my $rem;
3543: if (ref($ruleorder) eq 'ARRAY') {
3544: for (my $i=0; $i<@{$ruleorder}; $i++) {
3545: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3546: my $rem = $i%($numinrow);
3547: if ($rem == 0) {
3548: if ($i > 0) {
3549: $output .= '</tr>';
3550: }
3551: $output .= '<tr>';
3552: }
3553: my $check = ' ';
1.39 raeburn 3554: if (ref($settings) eq 'HASH') {
3555: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3556: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3557: $check = ' checked="checked" ';
3558: }
1.27 raeburn 3559: }
3560: }
3561: $output .= '<td class="LC_left_item">'.
3562: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3563: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3564: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3565: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3566: }
3567: }
3568: $rem = @{$ruleorder}%($numinrow);
3569: }
3570: my $colsleft = $numinrow - $rem;
3571: if ($colsleft > 1 ) {
3572: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3573: ' </td>';
3574: } elsif ($colsleft == 1) {
3575: $output .= '<td class="LC_left_item"> </td>';
3576: }
3577: $output .= '</tr></table></td></tr>';
3578: return $output;
3579: }
3580:
1.34 raeburn 3581: sub usercreation_types {
3582: my %lt = &Apache::lonlocal::texthash (
3583: author => 'When adding a co-author',
3584: course => 'When adding a user to a course',
1.100 raeburn 3585: requestcrs => 'When requesting a course',
1.45 raeburn 3586: selfcreate => 'User creates own account',
1.34 raeburn 3587: any => 'Any',
3588: official => 'Institutional only ',
3589: unofficial => 'Non-institutional only',
1.85 schafran 3590: email => 'E-mail address',
1.43 raeburn 3591: login => 'Institutional Login',
3592: sso => 'SSO',
1.34 raeburn 3593: none => 'None',
3594: );
3595: return %lt;
1.48 raeburn 3596: }
1.34 raeburn 3597:
1.28 raeburn 3598: sub authtype_names {
3599: my %lt = &Apache::lonlocal::texthash(
3600: int => 'Internal',
3601: krb4 => 'Kerberos 4',
3602: krb5 => 'Kerberos 5',
3603: loc => 'Local',
3604: );
3605: return %lt;
3606: }
3607:
3608: sub context_names {
3609: my %context_title = &Apache::lonlocal::texthash(
3610: author => 'Creating users when an Author',
3611: course => 'Creating users when in a course',
3612: domain => 'Creating users when a Domain Coordinator',
3613: );
3614: return %context_title;
3615: }
3616:
1.33 raeburn 3617: sub print_usermodification {
3618: my ($position,$dom,$settings,$rowtotal) = @_;
3619: my $numinrow = 4;
3620: my ($context,$datatable,$rowcount);
3621: if ($position eq 'top') {
3622: $rowcount = 0;
3623: $context = 'author';
3624: foreach my $role ('ca','aa') {
3625: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3626: $numinrow,$rowcount);
3627: $$rowtotal ++;
3628: $rowcount ++;
3629: }
1.63 raeburn 3630: } elsif ($position eq 'middle') {
1.33 raeburn 3631: $context = 'course';
3632: $rowcount = 0;
3633: foreach my $role ('st','ep','ta','in','cr') {
3634: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3635: $numinrow,$rowcount);
3636: $$rowtotal ++;
3637: $rowcount ++;
3638: }
1.63 raeburn 3639: } elsif ($position eq 'bottom') {
3640: $context = 'selfcreate';
3641: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3642: $usertypes->{'default'} = $othertitle;
3643: if (ref($types) eq 'ARRAY') {
3644: push(@{$types},'default');
3645: $usertypes->{'default'} = $othertitle;
3646: foreach my $status (@{$types}) {
3647: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3648: $numinrow,$rowcount,$usertypes);
3649: $$rowtotal ++;
3650: $rowcount ++;
3651: }
3652: }
1.33 raeburn 3653: }
3654: return $datatable;
3655: }
3656:
1.43 raeburn 3657: sub print_defaults {
3658: my ($dom,$rowtotal) = @_;
1.68 raeburn 3659: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3660: 'datelocale_def','portal_def');
1.43 raeburn 3661: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3662: my $titles = &defaults_titles($dom);
1.43 raeburn 3663: my $rownum = 0;
3664: my ($datatable,$css_class);
3665: foreach my $item (@items) {
3666: if ($rownum%2) {
3667: $css_class = '';
3668: } else {
3669: $css_class = ' class="LC_odd_row" ';
3670: }
3671: $datatable .= '<tr'.$css_class.'>'.
3672: '<td><span class="LC_nobreak">'.$titles->{$item}.
3673: '</span></td><td class="LC_right_item">';
3674: if ($item eq 'auth_def') {
3675: my @authtypes = ('internal','krb4','krb5','localauth');
3676: my %shortauth = (
3677: internal => 'int',
3678: krb4 => 'krb4',
3679: krb5 => 'krb5',
3680: localauth => 'loc'
3681: );
3682: my %authnames = &authtype_names();
3683: foreach my $auth (@authtypes) {
3684: my $checked = ' ';
3685: if ($domdefaults{$item} eq $auth) {
3686: $checked = ' checked="checked" ';
3687: }
3688: $datatable .= '<label><input type="radio" name="'.$item.
3689: '" value="'.$auth.'"'.$checked.'/>'.
3690: $authnames{$shortauth{$auth}}.'</label> ';
3691: }
1.54 raeburn 3692: } elsif ($item eq 'timezone_def') {
3693: my $includeempty = 1;
3694: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3695: } elsif ($item eq 'datelocale_def') {
3696: my $includeempty = 1;
3697: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3698: } elsif ($item eq 'lang_def') {
1.168 raeburn 3699: my %langchoices = &get_languages_hash();
3700: $langchoices{''} = 'No language preference';
1.167 raeburn 3701: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3702: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3703: \%langchoices);
1.43 raeburn 3704: } else {
1.141 raeburn 3705: my $size;
3706: if ($item eq 'portal_def') {
3707: $size = ' size="25"';
3708: }
1.43 raeburn 3709: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3710: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3711: }
3712: $datatable .= '</td></tr>';
3713: $rownum ++;
3714: }
3715: $$rowtotal += $rownum;
3716: return $datatable;
3717: }
3718:
1.168 raeburn 3719: sub get_languages_hash {
3720: my %langchoices;
3721: foreach my $id (&Apache::loncommon::languageids()) {
3722: my $code = &Apache::loncommon::supportedlanguagecode($id);
3723: if ($code ne '') {
3724: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3725: }
3726: }
3727: return %langchoices;
3728: }
3729:
1.43 raeburn 3730: sub defaults_titles {
1.141 raeburn 3731: my ($dom) = @_;
1.43 raeburn 3732: my %titles = &Apache::lonlocal::texthash (
3733: 'auth_def' => 'Default authentication type',
3734: 'auth_arg_def' => 'Default authentication argument',
3735: 'lang_def' => 'Default language',
1.54 raeburn 3736: 'timezone_def' => 'Default timezone',
1.68 raeburn 3737: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3738: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3739: );
1.141 raeburn 3740: if ($dom) {
3741: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3742: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3743: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3744: $protocol = 'http' if ($protocol ne 'https');
3745: if ($uint_dom) {
3746: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3747: $uint_dom);
3748: }
3749: }
1.43 raeburn 3750: return (\%titles);
3751: }
3752:
1.46 raeburn 3753: sub print_scantronformat {
3754: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3755: my $itemcount = 1;
1.60 raeburn 3756: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3757: %confhash);
1.46 raeburn 3758: my $switchserver = &check_switchserver($dom,$confname);
3759: my %lt = &Apache::lonlocal::texthash (
1.95 www 3760: default => 'Default bubblesheet format file error',
3761: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3762: );
3763: my %scantronfiles = (
3764: default => 'default.tab',
3765: custom => 'custom.tab',
3766: );
3767: foreach my $key (keys(%scantronfiles)) {
3768: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3769: .$scantronfiles{$key};
3770: }
3771: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3772: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3773: if (!$switchserver) {
3774: my $servadm = $r->dir_config('lonAdmEMail');
3775: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3776: if ($configuserok eq 'ok') {
3777: if ($author_ok eq 'ok') {
3778: my %legacyfile = (
3779: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3780: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3781: );
3782: my %md5chk;
3783: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3784: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3785: chomp($md5chk{$type});
1.46 raeburn 3786: }
3787: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3788: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3789: ($scantronurls{$type},my $error) =
1.46 raeburn 3790: &legacy_scantronformat($r,$dom,$confname,
3791: $type,$legacyfile{$type},
3792: $scantronurls{$type},
3793: $scantronfiles{$type});
1.60 raeburn 3794: if ($error ne '') {
3795: $error{$type} = $error;
3796: }
3797: }
3798: if (keys(%error) == 0) {
3799: $is_custom = 1;
3800: $confhash{'scantron'}{'scantronformat'} =
3801: $scantronurls{'custom'};
3802: my $putresult =
3803: &Apache::lonnet::put_dom('configuration',
3804: \%confhash,$dom);
3805: if ($putresult ne 'ok') {
3806: $error{'custom'} =
3807: '<span class="LC_error">'.
3808: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3809: }
1.46 raeburn 3810: }
3811: } else {
1.60 raeburn 3812: ($scantronurls{'default'},my $error) =
1.46 raeburn 3813: &legacy_scantronformat($r,$dom,$confname,
3814: 'default',$legacyfile{'default'},
3815: $scantronurls{'default'},
3816: $scantronfiles{'default'});
1.60 raeburn 3817: if ($error eq '') {
3818: $confhash{'scantron'}{'scantronformat'} = '';
3819: my $putresult =
3820: &Apache::lonnet::put_dom('configuration',
3821: \%confhash,$dom);
3822: if ($putresult ne 'ok') {
3823: $error{'default'} =
3824: '<span class="LC_error">'.
3825: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3826: }
3827: } else {
3828: $error{'default'} = $error;
3829: }
1.46 raeburn 3830: }
3831: }
3832: }
3833: } else {
1.95 www 3834: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3835: }
3836: }
3837: if (ref($settings) eq 'HASH') {
3838: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3839: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3840: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3841: $scantronurl = '';
3842: } else {
3843: $scantronurl = $settings->{'scantronformat'};
3844: }
3845: $is_custom = 1;
3846: } else {
3847: $scantronurl = $scantronurls{'default'};
3848: }
3849: } else {
1.60 raeburn 3850: if ($is_custom) {
3851: $scantronurl = $scantronurls{'custom'};
3852: } else {
3853: $scantronurl = $scantronurls{'default'};
3854: }
1.46 raeburn 3855: }
3856: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3857: $datatable .= '<tr'.$css_class.'>';
3858: if (!$is_custom) {
1.65 raeburn 3859: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3860: '<span class="LC_nobreak">';
1.46 raeburn 3861: if ($scantronurl) {
3862: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3863: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3864: } else {
3865: $datatable = &mt('File unavailable for display');
3866: }
1.65 raeburn 3867: $datatable .= '</span></td>';
1.60 raeburn 3868: if (keys(%error) == 0) {
3869: $datatable .= '<td valign="bottom">';
3870: if (!$switchserver) {
3871: $datatable .= &mt('Upload:').'<br />';
3872: }
3873: } else {
3874: my $errorstr;
3875: foreach my $key (sort(keys(%error))) {
3876: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3877: }
3878: $datatable .= '<td>'.$errorstr;
3879: }
1.46 raeburn 3880: } else {
3881: if (keys(%error) > 0) {
3882: my $errorstr;
3883: foreach my $key (sort(keys(%error))) {
3884: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3885: }
1.60 raeburn 3886: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3887: } elsif ($scantronurl) {
1.65 raeburn 3888: $datatable .= '<td><span class="LC_nobreak">'.
3889: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3890: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3891: '<input type="checkbox" name="scantronformat_del"'.
3892: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3893: '<td><span class="LC_nobreak"> '.
3894: &mt('Replace:').'</span><br />';
1.46 raeburn 3895: }
3896: }
3897: if (keys(%error) == 0) {
3898: if ($switchserver) {
3899: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3900: } else {
1.65 raeburn 3901: $datatable .='<span class="LC_nobreak"> '.
3902: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3903: }
3904: }
3905: $datatable .= '</td></tr>';
3906: $$rowtotal ++;
3907: return $datatable;
3908: }
3909:
3910: sub legacy_scantronformat {
3911: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3912: my ($url,$error);
3913: my @statinfo = &Apache::lonnet::stat_file($newurl);
3914: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3915: (my $result,$url) =
3916: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3917: '','',$newfile);
3918: if ($result ne 'ok') {
1.130 raeburn 3919: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3920: }
3921: }
3922: return ($url,$error);
3923: }
1.43 raeburn 3924:
1.49 raeburn 3925: sub print_coursecategories {
1.57 raeburn 3926: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3927: my $datatable;
3928: if ($position eq 'top') {
3929: my $toggle_cats_crs = ' ';
3930: my $toggle_cats_dom = ' checked="checked" ';
3931: my $can_cat_crs = ' ';
3932: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3933: my $toggle_catscomm_comm = ' ';
3934: my $toggle_catscomm_dom = ' checked="checked" ';
3935: my $can_catcomm_comm = ' ';
3936: my $can_catcomm_dom = ' checked="checked" ';
3937:
1.57 raeburn 3938: if (ref($settings) eq 'HASH') {
3939: if ($settings->{'togglecats'} eq 'crs') {
3940: $toggle_cats_crs = $toggle_cats_dom;
3941: $toggle_cats_dom = ' ';
3942: }
3943: if ($settings->{'categorize'} eq 'crs') {
3944: $can_cat_crs = $can_cat_dom;
3945: $can_cat_dom = ' ';
3946: }
1.120 raeburn 3947: if ($settings->{'togglecatscomm'} eq 'comm') {
3948: $toggle_catscomm_comm = $toggle_catscomm_dom;
3949: $toggle_catscomm_dom = ' ';
3950: }
3951: if ($settings->{'categorizecomm'} eq 'comm') {
3952: $can_catcomm_comm = $can_catcomm_dom;
3953: $can_catcomm_dom = ' ';
3954: }
1.57 raeburn 3955: }
3956: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3957: togglecats => 'Show/Hide a course in catalog',
3958: togglecatscomm => 'Show/Hide a community in catalog',
3959: categorize => 'Assign a category to a course',
3960: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3961: );
3962: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3963: dom => 'Set in Domain',
3964: crs => 'Set in Course',
3965: comm => 'Set in Community',
1.57 raeburn 3966: );
3967: $datatable = '<tr class="LC_odd_row">'.
3968: '<td>'.$title{'togglecats'}.'</td>'.
3969: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3970: '<input type="radio" name="togglecats"'.
3971: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3972: '<label><input type="radio" name="togglecats"'.
3973: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3974: '</tr><tr>'.
3975: '<td>'.$title{'categorize'}.'</td>'.
3976: '<td class="LC_right_item"><span class="LC_nobreak">'.
3977: '<label><input type="radio" name="categorize"'.
3978: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3979: '<label><input type="radio" name="categorize"'.
3980: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 3981: '</tr><tr class="LC_odd_row">'.
3982: '<td>'.$title{'togglecatscomm'}.'</td>'.
3983: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3984: '<input type="radio" name="togglecatscomm"'.
3985: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3986: '<label><input type="radio" name="togglecatscomm"'.
3987: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
3988: '</tr><tr>'.
3989: '<td>'.$title{'categorizecomm'}.'</td>'.
3990: '<td class="LC_right_item"><span class="LC_nobreak">'.
3991: '<label><input type="radio" name="categorizecomm"'.
3992: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3993: '<label><input type="radio" name="categorizecomm"'.
3994: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 3995: '</tr>';
1.120 raeburn 3996: $$rowtotal += 4;
1.57 raeburn 3997: } else {
3998: my $css_class;
3999: my $itemcount = 1;
4000: my $cathash;
4001: if (ref($settings) eq 'HASH') {
4002: $cathash = $settings->{'cats'};
4003: }
4004: if (ref($cathash) eq 'HASH') {
4005: my (@cats,@trails,%allitems,%idx,@jsarray);
4006: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4007: \%allitems,\%idx,\@jsarray);
4008: my $maxdepth = scalar(@cats);
4009: my $colattrib = '';
4010: if ($maxdepth > 2) {
4011: $colattrib = ' colspan="2" ';
4012: }
4013: my @path;
4014: if (@cats > 0) {
4015: if (ref($cats[0]) eq 'ARRAY') {
4016: my $numtop = @{$cats[0]};
4017: my $maxnum = $numtop;
1.120 raeburn 4018: my %default_names = (
4019: instcode => &mt('Official courses'),
4020: communities => &mt('Communities'),
4021: );
4022:
4023: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4024: ($cathash->{'instcode::0'} eq '') ||
4025: (!grep(/^communities$/,@{$cats[0]})) ||
4026: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4027: $maxnum ++;
4028: }
4029: my $lastidx;
4030: for (my $i=0; $i<$numtop; $i++) {
4031: my $parent = $cats[0][$i];
4032: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4033: my $item = &escape($parent).'::0';
4034: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4035: $lastidx = $idx{$item};
4036: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4037: .'<select name="'.$item.'"'.$chgstr.'>';
4038: for (my $k=0; $k<=$maxnum; $k++) {
4039: my $vpos = $k+1;
4040: my $selstr;
4041: if ($k == $i) {
4042: $selstr = ' selected="selected" ';
4043: }
4044: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4045: }
4046: $datatable .= '</select></td><td>';
1.120 raeburn 4047: if ($parent eq 'instcode' || $parent eq 'communities') {
4048: $datatable .= '<span class="LC_nobreak">'
4049: .$default_names{$parent}.'</span>';
4050: if ($parent eq 'instcode') {
4051: $datatable .= '<br /><span class="LC_nobreak">('
4052: .&mt('with institutional codes')
4053: .')</span></td><td'.$colattrib.'>';
4054: } else {
4055: $datatable .= '<table><tr><td>';
4056: }
4057: $datatable .= '<span class="LC_nobreak">'
4058: .'<label><input type="radio" name="'
4059: .$parent.'" value="1" checked="checked" />'
4060: .&mt('Display').'</label>';
4061: if ($parent eq 'instcode') {
4062: $datatable .= ' ';
4063: } else {
4064: $datatable .= '</span></td></tr><tr><td>'
4065: .'<span class="LC_nobreak">';
4066: }
4067: $datatable .= '<label><input type="radio" name="'
4068: .$parent.'" value="0" />'
4069: .&mt('Do not display').'</label></span>';
4070: if ($parent eq 'communities') {
4071: $datatable .= '</td></tr></table>';
4072: }
4073: $datatable .= '</td>';
1.57 raeburn 4074: } else {
4075: $datatable .= $parent
4076: .' <label><input type="checkbox" name="deletecategory" '
4077: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4078: }
4079: my $depth = 1;
4080: push(@path,$parent);
4081: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4082: pop(@path);
4083: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4084: $itemcount ++;
4085: }
1.48 raeburn 4086: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4087: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4088: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4089: for (my $k=0; $k<=$maxnum; $k++) {
4090: my $vpos = $k+1;
4091: my $selstr;
1.57 raeburn 4092: if ($k == $numtop) {
1.48 raeburn 4093: $selstr = ' selected="selected" ';
4094: }
4095: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4096: }
1.59 bisitz 4097: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4098: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4099: .'</tr>'."\n";
1.48 raeburn 4100: $itemcount ++;
1.120 raeburn 4101: foreach my $default ('instcode','communities') {
4102: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4103: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4104: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4105: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4106: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4107: for (my $k=0; $k<=$maxnum; $k++) {
4108: my $vpos = $k+1;
4109: my $selstr;
4110: if ($k == $maxnum) {
4111: $selstr = ' selected="selected" ';
4112: }
4113: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4114: }
1.120 raeburn 4115: $datatable .= '</select></span></td>'.
4116: '<td><span class="LC_nobreak">'.
4117: $default_names{$default}.'</span>';
4118: if ($default eq 'instcode') {
4119: $datatable .= '<br /><span class="LC_nobreak">('
4120: .&mt('with institutional codes').')</span>';
4121: }
4122: $datatable .= '</td>'
4123: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4124: .&mt('Display').'</label> '
4125: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4126: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4127: }
4128: }
4129: }
1.57 raeburn 4130: } else {
4131: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4132: }
4133: } else {
1.57 raeburn 4134: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4135: .&initialize_categories($itemcount);
1.48 raeburn 4136: }
1.57 raeburn 4137: $$rowtotal += $itemcount;
1.48 raeburn 4138: }
4139: return $datatable;
4140: }
4141:
1.69 raeburn 4142: sub print_serverstatuses {
4143: my ($dom,$settings,$rowtotal) = @_;
4144: my $datatable;
4145: my @pages = &serverstatus_pages();
4146: my (%namedaccess,%machineaccess);
4147: foreach my $type (@pages) {
4148: $namedaccess{$type} = '';
4149: $machineaccess{$type}= '';
4150: }
4151: if (ref($settings) eq 'HASH') {
4152: foreach my $type (@pages) {
4153: if (exists($settings->{$type})) {
4154: if (ref($settings->{$type}) eq 'HASH') {
4155: foreach my $key (keys(%{$settings->{$type}})) {
4156: if ($key eq 'namedusers') {
4157: $namedaccess{$type} = $settings->{$type}->{$key};
4158: } elsif ($key eq 'machines') {
4159: $machineaccess{$type} = $settings->{$type}->{$key};
4160: }
4161: }
4162: }
4163: }
4164: }
4165: }
1.81 raeburn 4166: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4167: my $rownum = 0;
4168: my $css_class;
4169: foreach my $type (@pages) {
4170: $rownum ++;
4171: $css_class = $rownum%2?' class="LC_odd_row"':'';
4172: $datatable .= '<tr'.$css_class.'>'.
4173: '<td><span class="LC_nobreak">'.
4174: $titles->{$type}.'</span></td>'.
4175: '<td class="LC_left_item">'.
4176: '<input type="text" name="'.$type.'_namedusers" '.
4177: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4178: '<td class="LC_right_item">'.
4179: '<span class="LC_nobreak">'.
4180: '<input type="text" name="'.$type.'_machines" '.
4181: 'value="'.$machineaccess{$type}.'" size="10" />'.
4182: '</td></tr>'."\n";
4183: }
4184: $$rowtotal += $rownum;
4185: return $datatable;
4186: }
4187:
4188: sub serverstatus_pages {
4189: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4190: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4191: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4192: }
4193:
1.49 raeburn 4194: sub coursecategories_javascript {
4195: my ($settings) = @_;
1.57 raeburn 4196: my ($output,$jstext,$cathash);
1.49 raeburn 4197: if (ref($settings) eq 'HASH') {
1.57 raeburn 4198: $cathash = $settings->{'cats'};
4199: }
4200: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4201: my (@cats,@jsarray,%idx);
1.57 raeburn 4202: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4203: if (@jsarray > 0) {
4204: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4205: for (my $i=0; $i<@jsarray; $i++) {
4206: if (ref($jsarray[$i]) eq 'ARRAY') {
4207: my $catstr = join('","',@{$jsarray[$i]});
4208: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4209: }
4210: }
4211: }
4212: } else {
4213: $jstext = ' var categories = Array(1);'."\n".
4214: ' categories[0] = Array("instcode_pos");'."\n";
4215: }
1.120 raeburn 4216: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4217: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4218: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4219: $output = <<"ENDSCRIPT";
4220: <script type="text/javascript">
1.109 raeburn 4221: // <![CDATA[
1.49 raeburn 4222: function reorderCats(form,parent,item,idx) {
4223: var changedVal;
4224: $jstext
4225: var newpos = 'addcategory_pos';
4226: var current = new Array;
4227: if (parent == '') {
4228: var has_instcode = 0;
4229: var maxtop = categories[idx].length;
4230: for (var j=0; j<maxtop; j++) {
4231: if (categories[idx][j] == 'instcode::0') {
4232: has_instcode == 1;
4233: }
4234: }
4235: if (has_instcode == 0) {
4236: categories[idx][maxtop] = 'instcode_pos';
4237: }
4238: } else {
4239: newpos += '_'+parent;
4240: }
4241: var maxh = 1 + categories[idx].length;
4242: var current = new Array;
4243: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4244: if (item == newpos) {
4245: changedVal = newitemVal;
4246: } else {
4247: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4248: current[newitemVal] = newpos;
4249: }
4250: for (var i=0; i<categories[idx].length; i++) {
4251: var elementName = categories[idx][i];
4252: if (elementName != item) {
4253: if (form.elements[elementName]) {
4254: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4255: current[currVal] = elementName;
4256: }
4257: }
4258: }
4259: var oldVal;
4260: for (var j=0; j<maxh; j++) {
4261: if (current[j] == undefined) {
4262: oldVal = j;
4263: }
4264: }
4265: if (oldVal < changedVal) {
4266: for (var k=oldVal+1; k<=changedVal ; k++) {
4267: var elementName = current[k];
4268: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4269: }
4270: } else {
4271: for (var k=changedVal; k<oldVal; k++) {
4272: var elementName = current[k];
4273: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4274: }
4275: }
4276: return;
4277: }
1.120 raeburn 4278:
4279: function categoryCheck(form) {
4280: if (form.elements['addcategory_name'].value == 'instcode') {
4281: alert('$instcode_reserved\\n$choose_again');
4282: return false;
4283: }
4284: if (form.elements['addcategory_name'].value == 'communities') {
4285: alert('$communities_reserved\\n$choose_again');
4286: return false;
4287: }
4288: return true;
4289: }
4290:
1.109 raeburn 4291: // ]]>
1.49 raeburn 4292: </script>
4293:
4294: ENDSCRIPT
4295: return $output;
4296: }
4297:
1.48 raeburn 4298: sub initialize_categories {
4299: my ($itemcount) = @_;
1.120 raeburn 4300: my ($datatable,$css_class,$chgstr);
4301: my %default_names = (
4302: instcode => 'Official courses (with institutional codes)',
4303: communities => 'Communities',
4304: );
4305: my $select0 = ' selected="selected"';
4306: my $select1 = '';
4307: foreach my $default ('instcode','communities') {
4308: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4309: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4310: if ($default eq 'communities') {
4311: $select1 = $select0;
4312: $select0 = '';
4313: }
4314: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4315: .'<select name="'.$default.'_pos">'
4316: .'<option value="0"'.$select0.'>1</option>'
4317: .'<option value="1"'.$select1.'>2</option>'
4318: .'<option value="2">3</option></select> '
4319: .$default_names{$default}
4320: .'</span></td><td><span class="LC_nobreak">'
4321: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4322: .&mt('Display').'</label> <label>'
4323: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4324: .'</label></span></td></tr>';
1.120 raeburn 4325: $itemcount ++;
4326: }
1.48 raeburn 4327: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4328: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4329: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4330: .'<select name="addcategory_pos"'.$chgstr.'>'
4331: .'<option value="0">1</option>'
4332: .'<option value="1">2</option>'
4333: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4334: .&mt('Add category').'</td><td>'.&mt('Name:')
4335: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4336: return $datatable;
4337: }
4338:
4339: sub build_category_rows {
1.49 raeburn 4340: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4341: my ($text,$name,$item,$chgstr);
1.48 raeburn 4342: if (ref($cats) eq 'ARRAY') {
4343: my $maxdepth = scalar(@{$cats});
4344: if (ref($cats->[$depth]) eq 'HASH') {
4345: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4346: my $numchildren = @{$cats->[$depth]{$parent}};
4347: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4348: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4349: my ($idxnum,$parent_name,$parent_item);
4350: my $higher = $depth - 1;
4351: if ($higher == 0) {
4352: $parent_name = &escape($parent).'::'.$higher;
4353: } else {
4354: if (ref($path) eq 'ARRAY') {
4355: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4356: }
4357: }
4358: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4359: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4360: if ($j < $numchildren) {
1.48 raeburn 4361: $name = $cats->[$depth]{$parent}[$j];
4362: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4363: $idxnum = $idx->{$item};
4364: } else {
4365: $name = $parent_name;
4366: $item = $parent_item;
1.48 raeburn 4367: }
1.49 raeburn 4368: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4369: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4370: for (my $i=0; $i<=$numchildren; $i++) {
4371: my $vpos = $i+1;
4372: my $selstr;
4373: if ($j == $i) {
4374: $selstr = ' selected="selected" ';
4375: }
4376: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4377: }
4378: $text .= '</select> ';
4379: if ($j < $numchildren) {
4380: my $deeper = $depth+1;
4381: $text .= $name.' '
4382: .'<label><input type="checkbox" name="deletecategory" value="'
4383: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4384: if(ref($path) eq 'ARRAY') {
4385: push(@{$path},$name);
1.49 raeburn 4386: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4387: pop(@{$path});
4388: }
4389: } else {
1.59 bisitz 4390: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4391: if ($j == $numchildren) {
4392: $text .= $name;
4393: } else {
4394: $text .= $item;
4395: }
4396: $text .= '" value="" />';
4397: }
4398: $text .= '</td></tr>';
4399: }
4400: $text .= '</table></td>';
4401: } else {
4402: my $higher = $depth-1;
4403: if ($higher == 0) {
4404: $name = &escape($parent).'::'.$higher;
4405: } else {
4406: if (ref($path) eq 'ARRAY') {
4407: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4408: }
4409: }
4410: my $colspan;
4411: if ($parent ne 'instcode') {
4412: $colspan = $maxdepth - $depth - 1;
4413: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4414: }
4415: }
4416: }
4417: }
4418: return $text;
4419: }
4420:
1.33 raeburn 4421: sub modifiable_userdata_row {
1.63 raeburn 4422: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4423: my $rolename;
1.63 raeburn 4424: if ($context eq 'selfcreate') {
4425: if (ref($usertypes) eq 'HASH') {
4426: $rolename = $usertypes->{$role};
4427: } else {
4428: $rolename = $role;
4429: }
1.33 raeburn 4430: } else {
1.63 raeburn 4431: if ($role eq 'cr') {
4432: $rolename = &mt('Custom role');
4433: } else {
4434: $rolename = &Apache::lonnet::plaintext($role);
4435: }
1.33 raeburn 4436: }
4437: my @fields = ('lastname','firstname','middlename','generation',
4438: 'permanentemail','id');
4439: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4440: my $output;
4441: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4442: $output = '<tr '.$css_class.'>'.
4443: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4444: '<td class="LC_left_item" colspan="2"><table>';
4445: my $rem;
4446: my %checks;
4447: if (ref($settings) eq 'HASH') {
4448: if (ref($settings->{$context}) eq 'HASH') {
4449: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4450: foreach my $field (@fields) {
4451: if ($settings->{$context}->{$role}->{$field}) {
4452: $checks{$field} = ' checked="checked" ';
4453: }
4454: }
4455: }
4456: }
4457: }
4458: for (my $i=0; $i<@fields; $i++) {
4459: my $rem = $i%($numinrow);
4460: if ($rem == 0) {
4461: if ($i > 0) {
4462: $output .= '</tr>';
4463: }
4464: $output .= '<tr>';
4465: }
4466: my $check = ' ';
4467: if (exists($checks{$fields[$i]})) {
4468: $check = $checks{$fields[$i]}
4469: } else {
4470: if ($role eq 'st') {
4471: if (ref($settings) ne 'HASH') {
4472: $check = ' checked="checked" ';
4473: }
4474: }
4475: }
4476: $output .= '<td class="LC_left_item">'.
4477: '<span class="LC_nobreak"><label>'.
4478: '<input type="checkbox" name="canmodify_'.$role.'" '.
4479: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4480: '</label></span></td>';
4481: $rem = @fields%($numinrow);
4482: }
4483: my $colsleft = $numinrow - $rem;
4484: if ($colsleft > 1 ) {
4485: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4486: ' </td>';
4487: } elsif ($colsleft == 1) {
4488: $output .= '<td class="LC_left_item"> </td>';
4489: }
4490: $output .= '</tr></table></td></tr>';
4491: return $output;
4492: }
1.28 raeburn 4493:
1.93 raeburn 4494: sub insttypes_row {
4495: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4496: my %lt = &Apache::lonlocal::texthash (
4497: cansearch => 'Users allowed to search',
4498: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4499: lockablenames => 'User preference to lock name',
1.93 raeburn 4500: );
4501: my $showdom;
4502: if ($context eq 'cansearch') {
4503: $showdom = ' ('.$dom.')';
4504: }
1.165 raeburn 4505: my $class = 'LC_left_item';
4506: if ($context eq 'statustocreate') {
4507: $class = 'LC_right_item';
4508: }
1.25 raeburn 4509: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4510: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4511: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4512: my $rem;
4513: if (ref($types) eq 'ARRAY') {
4514: for (my $i=0; $i<@{$types}; $i++) {
4515: if (defined($usertypes->{$types->[$i]})) {
4516: my $rem = $i%($numinrow);
4517: if ($rem == 0) {
4518: if ($i > 0) {
4519: $output .= '</tr>';
4520: }
4521: $output .= '<tr>';
1.23 raeburn 4522: }
1.26 raeburn 4523: my $check = ' ';
1.99 raeburn 4524: if (ref($settings) eq 'HASH') {
4525: if (ref($settings->{$context}) eq 'ARRAY') {
4526: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4527: $check = ' checked="checked" ';
4528: }
4529: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4530: $check = ' checked="checked" ';
4531: }
1.23 raeburn 4532: }
1.26 raeburn 4533: $output .= '<td class="LC_left_item">'.
4534: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4535: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4536: 'value="'.$types->[$i].'"'.$check.'/>'.
4537: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4538: }
4539: }
1.26 raeburn 4540: $rem = @{$types}%($numinrow);
1.23 raeburn 4541: }
4542: my $colsleft = $numinrow - $rem;
1.131 raeburn 4543: if (($rem == 0) && (@{$types} > 0)) {
4544: $output .= '<tr>';
4545: }
1.23 raeburn 4546: if ($colsleft > 1) {
1.25 raeburn 4547: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4548: } else {
1.25 raeburn 4549: $output .= '<td class="LC_left_item">';
1.23 raeburn 4550: }
4551: my $defcheck = ' ';
1.99 raeburn 4552: if (ref($settings) eq 'HASH') {
4553: if (ref($settings->{$context}) eq 'ARRAY') {
4554: if (grep(/^default$/,@{$settings->{$context}})) {
4555: $defcheck = ' checked="checked" ';
4556: }
4557: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4558: $defcheck = ' checked="checked" ';
4559: }
1.23 raeburn 4560: }
1.25 raeburn 4561: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4562: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4563: 'value="default"'.$defcheck.'/>'.
4564: $othertitle.'</label></span></td>'.
4565: '</tr></table></td></tr>';
4566: return $output;
1.23 raeburn 4567: }
4568:
4569: sub sorted_searchtitles {
4570: my %searchtitles = &Apache::lonlocal::texthash(
4571: 'uname' => 'username',
4572: 'lastname' => 'last name',
4573: 'lastfirst' => 'last name, first name',
4574: );
4575: my @titleorder = ('uname','lastname','lastfirst');
4576: return (\%searchtitles,\@titleorder);
4577: }
4578:
1.25 raeburn 4579: sub sorted_searchtypes {
4580: my %srchtypes_desc = (
4581: exact => 'is exact match',
4582: contains => 'contains ..',
4583: begins => 'begins with ..',
4584: );
4585: my @srchtypeorder = ('exact','begins','contains');
4586: return (\%srchtypes_desc,\@srchtypeorder);
4587: }
4588:
1.3 raeburn 4589: sub usertype_update_row {
4590: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4591: my $datatable;
4592: my $numinrow = 4;
4593: foreach my $type (@{$types}) {
4594: if (defined($usertypes->{$type})) {
4595: $$rownums ++;
4596: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4597: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4598: '</td><td class="LC_left_item"><table>';
4599: for (my $i=0; $i<@{$fields}; $i++) {
4600: my $rem = $i%($numinrow);
4601: if ($rem == 0) {
4602: if ($i > 0) {
4603: $datatable .= '</tr>';
4604: }
4605: $datatable .= '<tr>';
4606: }
4607: my $check = ' ';
1.39 raeburn 4608: if (ref($settings) eq 'HASH') {
4609: if (ref($settings->{'fields'}) eq 'HASH') {
4610: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4611: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4612: $check = ' checked="checked" ';
4613: }
1.3 raeburn 4614: }
4615: }
4616: }
4617:
4618: if ($i == @{$fields}-1) {
4619: my $colsleft = $numinrow - $rem;
4620: if ($colsleft > 1) {
4621: $datatable .= '<td colspan="'.$colsleft.'">';
4622: } else {
4623: $datatable .= '<td>';
4624: }
4625: } else {
4626: $datatable .= '<td>';
4627: }
1.8 raeburn 4628: $datatable .= '<span class="LC_nobreak"><label>'.
4629: '<input type="checkbox" name="updateable_'.$type.
4630: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4631: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4632: }
4633: $datatable .= '</tr></table></td></tr>';
4634: }
4635: }
4636: return $datatable;
1.1 raeburn 4637: }
4638:
4639: sub modify_login {
1.9 raeburn 4640: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4641: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4642: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4643: %title = ( coursecatalog => 'Display course catalog',
4644: adminmail => 'Display administrator E-mail address',
4645: newuser => 'Link for visitors to create a user account',
4646: loginheader => 'Log-in box header');
4647: @offon = ('off','on');
1.112 raeburn 4648: if (ref($domconfig{login}) eq 'HASH') {
4649: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4650: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4651: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4652: }
4653: }
4654: }
1.9 raeburn 4655: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4656: \%domconfig,\%loginhash);
1.118 jms 4657: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4658: foreach my $item (@toggles) {
4659: $loginhash{login}{$item} = $env{'form.'.$item};
4660: }
1.41 raeburn 4661: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4662: if (ref($colchanges{'login'}) eq 'HASH') {
4663: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4664: \%loginhash);
4665: }
1.110 raeburn 4666:
1.149 raeburn 4667: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4668: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4669: if (keys(%servers) > 1) {
4670: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4671: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4672: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4673: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4674: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4675: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4676: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4677: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4678: $changes{'loginvia'}{$lonhost} = 1;
4679: } else {
4680: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4681: $changes{'loginvia'}{$lonhost} = 1;
4682: }
4683: } else {
4684: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4685: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4686: $changes{'loginvia'}{$lonhost} = 1;
4687: }
4688: }
4689: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4690: foreach my $item (@loginvia_attribs) {
4691: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4692: }
4693: } else {
4694: foreach my $item (@loginvia_attribs) {
4695: my $new = $env{'form.'.$lonhost.'_'.$item};
4696: if (($item eq 'serverpath') && ($new eq 'custom')) {
4697: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4698: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4699: $new = '/';
4700: }
4701: }
4702: if (($item eq 'custompath') &&
4703: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4704: $new = '';
4705: }
4706: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4707: $changes{'loginvia'}{$lonhost} = 1;
4708: }
4709: if ($item eq 'exempt') {
4710: $new =~ s/^\s+//;
4711: $new =~ s/\s+$//;
4712: my @poss_ips = split(/\s*[,:]\s*/,$new);
4713: my @okips;
4714: foreach my $ip (@poss_ips) {
4715: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4716: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4717: push(@okips,$ip);
4718: }
4719: }
4720: }
4721: if (@okips > 0) {
4722: $new = join(',',@okips);
4723: } else {
4724: $new = '';
4725: }
4726: }
4727: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4728: }
4729: }
1.112 raeburn 4730: } else {
1.128 raeburn 4731: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4732: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4733: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4734: foreach my $item (@loginvia_attribs) {
4735: my $new = $env{'form.'.$lonhost.'_'.$item};
4736: if (($item eq 'serverpath') && ($new eq 'custom')) {
4737: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4738: $new = '/';
4739: }
4740: }
4741: if (($item eq 'custompath') &&
4742: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4743: $new = '';
4744: }
4745: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4746: }
1.110 raeburn 4747: }
4748: }
4749: }
4750: }
1.119 raeburn 4751:
1.168 raeburn 4752: my $servadm = $r->dir_config('lonAdmEMail');
4753: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4754: if (ref($domconfig{'login'}) eq 'HASH') {
4755: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4756: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4757: if ($lang eq 'nolang') {
4758: push(@currlangs,$lang);
4759: } elsif (defined($langchoices{$lang})) {
4760: push(@currlangs,$lang);
4761: } else {
4762: next;
4763: }
4764: }
4765: }
4766: }
4767: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4768: if (@currlangs > 0) {
4769: foreach my $lang (@currlangs) {
4770: if (grep(/^\Q$lang\E$/,@delurls)) {
4771: $changes{'helpurl'}{$lang} = 1;
4772: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4773: $changes{'helpurl'}{$lang} = 1;
4774: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4775: push(@newlangs,$lang);
4776: } else {
4777: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4778: }
4779: }
4780: }
4781: unless (grep(/^nolang$/,@currlangs)) {
4782: if ($env{'form.loginhelpurl_nolang.filename'}) {
4783: $changes{'helpurl'}{'nolang'} = 1;
4784: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4785: push(@newlangs,'nolang');
4786: }
4787: }
4788: if ($env{'form.loginhelpurl_add_lang'}) {
4789: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4790: ($env{'form.loginhelpurl_add_file.filename'})) {
4791: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4792: $addedfile = $env{'form.loginhelpurl_add_lang'};
4793: }
4794: }
4795: if ((@newlangs > 0) || ($addedfile)) {
4796: my $error;
4797: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4798: if ($configuserok eq 'ok') {
4799: if ($switchserver) {
4800: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4801: } elsif ($author_ok eq 'ok') {
4802: my @allnew = @newlangs;
4803: if ($addedfile ne '') {
4804: push(@allnew,$addedfile);
4805: }
4806: foreach my $lang (@allnew) {
4807: my $formelem = 'loginhelpurl_'.$lang;
4808: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4809: $formelem = 'loginhelpurl_add_file';
4810: }
4811: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4812: "help/$lang",'','',$newfile{$lang});
4813: if ($result eq 'ok') {
4814: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4815: $changes{'helpurl'}{$lang} = 1;
4816: } else {
4817: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4818: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4819: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4820: (!grep(/^\Q$lang\E$/,@delurls))) {
4821:
4822: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4823: }
4824: }
4825: }
4826: } else {
4827: $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);
4828: }
4829: } else {
4830: $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);
4831: }
4832: if ($error) {
4833: &Apache::lonnet::logthis($error);
4834: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4835: }
4836: }
1.169 raeburn 4837: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4838:
4839: my $defaulthelpfile = '/adm/loginproblems.html';
4840: my $defaulttext = &mt('Default in use');
4841:
1.1 raeburn 4842: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4843: $dom);
4844: if ($putresult eq 'ok') {
1.118 jms 4845: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4846: my %defaultchecked = (
4847: 'coursecatalog' => 'on',
4848: 'adminmail' => 'off',
1.43 raeburn 4849: 'newuser' => 'off',
1.42 raeburn 4850: );
1.55 raeburn 4851: if (ref($domconfig{'login'}) eq 'HASH') {
4852: foreach my $item (@toggles) {
4853: if ($defaultchecked{$item} eq 'on') {
4854: if (($domconfig{'login'}{$item} eq '0') &&
4855: ($env{'form.'.$item} eq '1')) {
4856: $changes{$item} = 1;
4857: } elsif (($domconfig{'login'}{$item} eq '' ||
4858: $domconfig{'login'}{$item} eq '1') &&
4859: ($env{'form.'.$item} eq '0')) {
4860: $changes{$item} = 1;
4861: }
4862: } elsif ($defaultchecked{$item} eq 'off') {
4863: if (($domconfig{'login'}{$item} eq '1') &&
4864: ($env{'form.'.$item} eq '0')) {
4865: $changes{$item} = 1;
4866: } elsif (($domconfig{'login'}{$item} eq '' ||
4867: $domconfig{'login'}{$item} eq '0') &&
4868: ($env{'form.'.$item} eq '1')) {
4869: $changes{$item} = 1;
4870: }
1.42 raeburn 4871: }
4872: }
1.41 raeburn 4873: }
1.6 raeburn 4874: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4875: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4876: $resulttext = &mt('Changes made:').'<ul>';
4877: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4878: if ($item eq 'loginvia') {
1.112 raeburn 4879: if (ref($changes{$item}) eq 'HASH') {
4880: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4881: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4882: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4883: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4884: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4885: $protocol = 'http' if ($protocol ne 'https');
4886: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4887:
4888: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4889: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4890: } else {
4891: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4892: }
4893: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4894: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4895: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4896: }
4897: $resulttext .= '</li>';
4898: } else {
4899: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4900: }
1.112 raeburn 4901: } else {
1.128 raeburn 4902: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4903: }
4904: }
1.128 raeburn 4905: $resulttext .= '</ul></li>';
1.112 raeburn 4906: }
1.168 raeburn 4907: } elsif ($item eq 'helpurl') {
4908: if (ref($changes{$item}) eq 'HASH') {
4909: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4910: if (grep(/^\Q$lang\E$/,@delurls)) {
4911: my ($chg,$link);
4912: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4913: if ($lang eq 'nolang') {
4914: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4915: } else {
4916: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4917: }
4918: $resulttext .= '<li>'.$chg.'</li>';
4919: } else {
4920: my $chg;
4921: if ($lang eq 'nolang') {
4922: $chg = &mt('custom log-in help file for no preferred language');
4923: } else {
4924: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4925: }
4926: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4927: $loginhash{'login'}{'helpurl'}{$lang}.
4928: '?inhibitmenu=yes',$chg,600,500).
4929: '</li>';
4930: }
4931: }
4932: }
1.169 raeburn 4933: } elsif ($item eq 'captcha') {
4934: if (ref($loginhash{'login'}) eq 'HASH') {
4935: my $chgtxt;
4936: if ($loginhash{'login'}{$item} eq 'notused') {
4937: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4938: } else {
4939: my %captchas = &captcha_phrases();
4940: if ($captchas{$loginhash{'login'}{$item}}) {
4941: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4942: } else {
4943: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4944: }
4945: }
4946: $resulttext .= '<li>'.$chgtxt.'</li>';
4947: }
4948: } elsif ($item eq 'recaptchakeys') {
4949: if (ref($loginhash{'login'}) eq 'HASH') {
4950: my ($privkey,$pubkey);
4951: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4952: $pubkey = $loginhash{'login'}{$item}{'public'};
4953: $privkey = $loginhash{'login'}{$item}{'private'};
4954: }
4955: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4956: if (!$pubkey) {
4957: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4958: } else {
4959: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4960: }
4961: if (!$privkey) {
4962: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4963: } else {
4964: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4965: }
4966: $chgtxt .= '</ul>';
4967: $resulttext .= '<li>'.$chgtxt.'</li>';
4968: }
1.41 raeburn 4969: } else {
4970: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4971: }
1.1 raeburn 4972: }
1.6 raeburn 4973: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4974: } else {
4975: $resulttext = &mt('No changes made to log-in page settings');
4976: }
4977: } else {
1.11 albertel 4978: $resulttext = '<span class="LC_error">'.
4979: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 4980: }
1.6 raeburn 4981: if ($errors) {
1.9 raeburn 4982: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 4983: $errors.'</ul>';
4984: }
4985: return $resulttext;
4986: }
4987:
4988: sub color_font_choices {
4989: my %choices =
4990: &Apache::lonlocal::texthash (
4991: img => "Header",
4992: bgs => "Background colors",
4993: links => "Link colors",
1.55 raeburn 4994: images => "Images",
1.6 raeburn 4995: font => "Font color",
1.97 tempelho 4996: fontmenu => "Font Menu",
1.76 raeburn 4997: pgbg => "Page",
1.6 raeburn 4998: tabbg => "Header",
4999: sidebg => "Border",
5000: link => "Link",
5001: alink => "Active link",
5002: vlink => "Visited link",
5003: );
5004: return %choices;
5005: }
5006:
5007: sub modify_rolecolors {
1.9 raeburn 5008: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5009: my ($resulttext,%rolehash);
5010: $rolehash{'rolecolors'} = {};
1.55 raeburn 5011: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5012: if ($domconfig{'rolecolors'} eq '') {
5013: $domconfig{'rolecolors'} = {};
5014: }
5015: }
1.9 raeburn 5016: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5017: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5018: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5019: $dom);
5020: if ($putresult eq 'ok') {
5021: if (keys(%changes) > 0) {
1.41 raeburn 5022: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5023: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5024: $rolehash{'rolecolors'});
5025: } else {
5026: $resulttext = &mt('No changes made to default color schemes');
5027: }
5028: } else {
1.11 albertel 5029: $resulttext = '<span class="LC_error">'.
5030: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5031: }
5032: if ($errors) {
5033: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5034: $errors.'</ul>';
5035: }
5036: return $resulttext;
5037: }
5038:
5039: sub modify_colors {
1.9 raeburn 5040: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5041: my (%changes,%choices);
1.51 raeburn 5042: my @bgs;
1.6 raeburn 5043: my @links = ('link','alink','vlink');
1.41 raeburn 5044: my @logintext;
1.6 raeburn 5045: my @images;
5046: my $servadm = $r->dir_config('lonAdmEMail');
5047: my $errors;
5048: foreach my $role (@{$roles}) {
5049: if ($role eq 'login') {
1.12 raeburn 5050: %choices = &login_choices();
1.41 raeburn 5051: @logintext = ('textcol','bgcol');
1.12 raeburn 5052: } else {
5053: %choices = &color_font_choices();
1.107 raeburn 5054: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5055: }
5056: if ($role eq 'login') {
1.41 raeburn 5057: @images = ('img','logo','domlogo','login');
1.51 raeburn 5058: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5059: } else {
5060: @images = ('img');
1.51 raeburn 5061: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5062: }
5063: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5064: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5065: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5066: }
1.46 raeburn 5067: my ($configuserok,$author_ok,$switchserver) =
5068: &config_check($dom,$confname,$servadm);
1.9 raeburn 5069: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5070: if (ref($domconfig->{$role}) ne 'HASH') {
5071: $domconfig->{$role} = {};
5072: }
1.8 raeburn 5073: foreach my $img (@images) {
1.70 raeburn 5074: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5075: if (defined($env{'form.login_showlogo_'.$img})) {
5076: $confhash->{$role}{'showlogo'}{$img} = 1;
5077: } else {
5078: $confhash->{$role}{'showlogo'}{$img} = 0;
5079: }
5080: }
1.18 albertel 5081: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5082: && !defined($domconfig->{$role}{$img})
5083: && !$env{'form.'.$role.'_del_'.$img}
5084: && $env{'form.'.$role.'_import_'.$img}) {
5085: # import the old configured image from the .tab setting
5086: # if they haven't provided a new one
5087: $domconfig->{$role}{$img} =
5088: $env{'form.'.$role.'_import_'.$img};
5089: }
1.6 raeburn 5090: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5091: my $error;
1.6 raeburn 5092: if ($configuserok eq 'ok') {
1.9 raeburn 5093: if ($switchserver) {
1.12 raeburn 5094: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5095: } else {
5096: if ($author_ok eq 'ok') {
5097: my ($result,$logourl) =
5098: &publishlogo($r,'upload',$role.'_'.$img,
5099: $dom,$confname,$img,$width,$height);
5100: if ($result eq 'ok') {
5101: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5102: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5103: } else {
1.12 raeburn 5104: $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 5105: }
5106: } else {
1.46 raeburn 5107: $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 5108: }
5109: }
5110: } else {
1.46 raeburn 5111: $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 5112: }
5113: if ($error) {
1.8 raeburn 5114: &Apache::lonnet::logthis($error);
1.11 albertel 5115: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5116: }
5117: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5118: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5119: my $error;
5120: if ($configuserok eq 'ok') {
5121: # is confname an author?
5122: if ($switchserver eq '') {
5123: if ($author_ok eq 'ok') {
5124: my ($result,$logourl) =
5125: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5126: $dom,$confname,$img,$width,$height);
5127: if ($result eq 'ok') {
5128: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5129: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5130: }
5131: }
5132: }
5133: }
1.6 raeburn 5134: }
5135: }
5136: }
5137: if (ref($domconfig) eq 'HASH') {
5138: if (ref($domconfig->{$role}) eq 'HASH') {
5139: foreach my $img (@images) {
5140: if ($domconfig->{$role}{$img} ne '') {
5141: if ($env{'form.'.$role.'_del_'.$img}) {
5142: $confhash->{$role}{$img} = '';
1.12 raeburn 5143: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5144: } else {
1.9 raeburn 5145: if ($confhash->{$role}{$img} eq '') {
5146: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5147: }
1.6 raeburn 5148: }
5149: } else {
5150: if ($env{'form.'.$role.'_del_'.$img}) {
5151: $confhash->{$role}{$img} = '';
1.12 raeburn 5152: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5153: }
5154: }
1.70 raeburn 5155: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5156: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5157: if ($confhash->{$role}{'showlogo'}{$img} ne
5158: $domconfig->{$role}{'showlogo'}{$img}) {
5159: $changes{$role}{'showlogo'}{$img} = 1;
5160: }
5161: } else {
5162: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5163: $changes{$role}{'showlogo'}{$img} = 1;
5164: }
5165: }
5166: }
5167: }
1.6 raeburn 5168: if ($domconfig->{$role}{'font'} ne '') {
5169: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5170: $changes{$role}{'font'} = 1;
5171: }
5172: } else {
5173: if ($confhash->{$role}{'font'}) {
5174: $changes{$role}{'font'} = 1;
5175: }
5176: }
1.107 raeburn 5177: if ($role ne 'login') {
5178: if ($domconfig->{$role}{'fontmenu'} ne '') {
5179: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5180: $changes{$role}{'fontmenu'} = 1;
5181: }
5182: } else {
5183: if ($confhash->{$role}{'fontmenu'}) {
5184: $changes{$role}{'fontmenu'} = 1;
5185: }
1.97 tempelho 5186: }
5187: }
1.6 raeburn 5188: foreach my $item (@bgs) {
5189: if ($domconfig->{$role}{$item} ne '') {
5190: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5191: $changes{$role}{'bgs'}{$item} = 1;
5192: }
5193: } else {
5194: if ($confhash->{$role}{$item}) {
5195: $changes{$role}{'bgs'}{$item} = 1;
5196: }
5197: }
5198: }
5199: foreach my $item (@links) {
5200: if ($domconfig->{$role}{$item} ne '') {
5201: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5202: $changes{$role}{'links'}{$item} = 1;
5203: }
5204: } else {
5205: if ($confhash->{$role}{$item}) {
5206: $changes{$role}{'links'}{$item} = 1;
5207: }
5208: }
5209: }
1.41 raeburn 5210: foreach my $item (@logintext) {
5211: if ($domconfig->{$role}{$item} ne '') {
5212: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5213: $changes{$role}{'logintext'}{$item} = 1;
5214: }
5215: } else {
5216: if ($confhash->{$role}{$item}) {
5217: $changes{$role}{'logintext'}{$item} = 1;
5218: }
5219: }
5220: }
1.6 raeburn 5221: } else {
5222: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5223: \@logintext,$confhash,\%changes);
1.6 raeburn 5224: }
5225: } else {
5226: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5227: \@logintext,$confhash,\%changes);
1.6 raeburn 5228: }
5229: }
5230: return ($errors,%changes);
5231: }
5232:
1.46 raeburn 5233: sub config_check {
5234: my ($dom,$confname,$servadm) = @_;
5235: my ($configuserok,$author_ok,$switchserver,%currroles);
5236: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5237: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5238: $confname,$servadm);
5239: if ($configuserok eq 'ok') {
5240: $switchserver = &check_switchserver($dom,$confname);
5241: if ($switchserver eq '') {
5242: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5243: }
5244: }
5245: return ($configuserok,$author_ok,$switchserver);
5246: }
5247:
1.6 raeburn 5248: sub default_change_checker {
1.41 raeburn 5249: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5250: foreach my $item (@{$links}) {
5251: if ($confhash->{$role}{$item}) {
5252: $changes->{$role}{'links'}{$item} = 1;
5253: }
5254: }
5255: foreach my $item (@{$bgs}) {
5256: if ($confhash->{$role}{$item}) {
5257: $changes->{$role}{'bgs'}{$item} = 1;
5258: }
5259: }
1.41 raeburn 5260: foreach my $item (@{$logintext}) {
5261: if ($confhash->{$role}{$item}) {
5262: $changes->{$role}{'logintext'}{$item} = 1;
5263: }
5264: }
1.6 raeburn 5265: foreach my $img (@{$images}) {
5266: if ($env{'form.'.$role.'_del_'.$img}) {
5267: $confhash->{$role}{$img} = '';
1.12 raeburn 5268: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5269: }
1.70 raeburn 5270: if ($role eq 'login') {
5271: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5272: $changes->{$role}{'showlogo'}{$img} = 1;
5273: }
5274: }
1.6 raeburn 5275: }
5276: if ($confhash->{$role}{'font'}) {
5277: $changes->{$role}{'font'} = 1;
5278: }
1.48 raeburn 5279: }
1.6 raeburn 5280:
5281: sub display_colorchgs {
5282: my ($dom,$changes,$roles,$confhash) = @_;
5283: my (%choices,$resulttext);
5284: if (!grep(/^login$/,@{$roles})) {
5285: $resulttext = &mt('Changes made:').'<br />';
5286: }
5287: foreach my $role (@{$roles}) {
5288: if ($role eq 'login') {
5289: %choices = &login_choices();
5290: } else {
5291: %choices = &color_font_choices();
5292: }
5293: if (ref($changes->{$role}) eq 'HASH') {
5294: if ($role ne 'login') {
5295: $resulttext .= '<h4>'.&mt($role).'</h4>';
5296: }
5297: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5298: if ($role ne 'login') {
5299: $resulttext .= '<ul>';
5300: }
5301: if (ref($changes->{$role}{$key}) eq 'HASH') {
5302: if ($role ne 'login') {
5303: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5304: }
5305: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5306: if (($role eq 'login') && ($key eq 'showlogo')) {
5307: if ($confhash->{$role}{$key}{$item}) {
5308: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5309: } else {
5310: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5311: }
5312: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5313: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5314: } else {
1.12 raeburn 5315: my $newitem = $confhash->{$role}{$item};
5316: if ($key eq 'images') {
5317: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5318: }
5319: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5320: }
5321: }
5322: if ($role ne 'login') {
5323: $resulttext .= '</ul></li>';
5324: }
5325: } else {
5326: if ($confhash->{$role}{$key} eq '') {
5327: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5328: } else {
5329: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5330: }
5331: }
5332: if ($role ne 'login') {
5333: $resulttext .= '</ul>';
5334: }
5335: }
5336: }
5337: }
1.3 raeburn 5338: return $resulttext;
1.1 raeburn 5339: }
5340:
1.9 raeburn 5341: sub thumb_dimensions {
5342: return ('200','50');
5343: }
5344:
1.16 raeburn 5345: sub check_dimensions {
5346: my ($inputfile) = @_;
5347: my ($fullwidth,$fullheight);
5348: if ($inputfile =~ m|^[/\w.\-]+$|) {
5349: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5350: my $imageinfo = <PIPE>;
5351: if (!close(PIPE)) {
5352: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5353: }
5354: chomp($imageinfo);
5355: my ($fullsize) =
1.21 raeburn 5356: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5357: if ($fullsize) {
5358: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5359: }
5360: }
5361: }
5362: return ($fullwidth,$fullheight);
5363: }
5364:
1.9 raeburn 5365: sub check_configuser {
5366: my ($uhome,$dom,$confname,$servadm) = @_;
5367: my ($configuserok,%currroles);
5368: if ($uhome eq 'no_host') {
5369: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5370: my $configpass = &LONCAPA::Enrollment::create_password();
5371: $configuserok =
5372: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5373: $configpass,'','','','','',undef,$servadm);
5374: } else {
5375: $configuserok = 'ok';
5376: %currroles =
5377: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5378: }
5379: return ($configuserok,%currroles);
5380: }
5381:
5382: sub check_authorstatus {
5383: my ($dom,$confname,%currroles) = @_;
5384: my $author_ok;
1.40 raeburn 5385: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5386: my $start = time;
5387: my $end = 0;
5388: $author_ok =
5389: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5390: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5391: } else {
5392: $author_ok = 'ok';
5393: }
5394: return $author_ok;
5395: }
5396:
5397: sub publishlogo {
1.46 raeburn 5398: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5399: my ($output,$fname,$logourl);
5400: if ($action eq 'upload') {
5401: $fname=$env{'form.'.$formname.'.filename'};
5402: chop($env{'form.'.$formname});
5403: } else {
5404: ($fname) = ($formname =~ /([^\/]+)$/);
5405: }
1.46 raeburn 5406: if ($savefileas ne '') {
5407: $fname = $savefileas;
5408: }
1.9 raeburn 5409: $fname=&Apache::lonnet::clean_filename($fname);
5410: # See if there is anything left
5411: unless ($fname) { return ('error: no uploaded file'); }
5412: $fname="$subdir/$fname";
1.164 raeburn 5413: my $docroot=$r->dir_config('lonDocRoot');
5414: my $filepath="$docroot/priv";
5415: my $relpath = "$dom/$confname";
1.9 raeburn 5416: my ($fnamepath,$file,$fetchthumb);
5417: $file=$fname;
5418: if ($fname=~m|/|) {
5419: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5420: }
1.164 raeburn 5421: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5422: my $count;
1.164 raeburn 5423: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5424: $filepath.="/$parts[$count]";
5425: if ((-e $filepath)!=1) {
5426: mkdir($filepath,02770);
5427: }
5428: }
5429: # Check for bad extension and disallow upload
5430: if ($file=~/\.(\w+)$/ &&
5431: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5432: $output =
5433: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5434: } elsif ($file=~/\.(\w+)$/ &&
5435: !defined(&Apache::loncommon::fileembstyle($1))) {
5436: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5437: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5438: $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 5439: } elsif (-d "$filepath/$file") {
5440: $output = &mt('File name is a directory name - rename the file and re-upload');
5441: } else {
5442: my $source = $filepath.'/'.$file;
5443: my $logfile;
5444: if (!open($logfile,">>$source".'.log')) {
5445: return (&mt('No write permission to Construction Space'));
5446: }
5447: print $logfile
5448: "\n================= Publish ".localtime()." ================\n".
5449: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5450: # Save the file
5451: if (!open(FH,'>'.$source)) {
5452: &Apache::lonnet::logthis('Failed to create '.$source);
5453: return (&mt('Failed to create file'));
5454: }
5455: if ($action eq 'upload') {
5456: if (!print FH ($env{'form.'.$formname})) {
5457: &Apache::lonnet::logthis('Failed to write to '.$source);
5458: return (&mt('Failed to write file'));
5459: }
5460: } else {
5461: my $original = &Apache::lonnet::filelocation('',$formname);
5462: if(!copy($original,$source)) {
5463: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5464: return (&mt('Failed to write file'));
5465: }
5466: }
5467: close(FH);
5468: chmod(0660, $source); # Permissions to rw-rw---.
5469:
5470: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5471: my $copyfile=$targetdir.'/'.$file;
5472:
5473: my @parts=split(/\//,$targetdir);
5474: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5475: for (my $count=5;$count<=$#parts;$count++) {
5476: $path.="/$parts[$count]";
5477: if (!-e $path) {
5478: print $logfile "\nCreating directory ".$path;
5479: mkdir($path,02770);
5480: }
5481: }
5482: my $versionresult;
5483: if (-e $copyfile) {
5484: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5485: } else {
5486: $versionresult = 'ok';
5487: }
5488: if ($versionresult eq 'ok') {
5489: if (copy($source,$copyfile)) {
5490: print $logfile "\nCopied original source to ".$copyfile."\n";
5491: $output = 'ok';
5492: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5493: push(@{$modified_urls},[$copyfile,$source]);
5494: my $metaoutput =
5495: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5496: unless ($registered_cleanup) {
5497: my $handlers = $r->get_handlers('PerlCleanupHandler');
5498: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5499: $registered_cleanup=1;
5500: }
1.9 raeburn 5501: } else {
5502: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5503: $output = &mt('Failed to copy file to RES space').", $!";
5504: }
5505: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5506: my $inputfile = $filepath.'/'.$file;
5507: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5508: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5509: if ($fullwidth ne '' && $fullheight ne '') {
5510: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5511: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5512: system("convert -sample $thumbsize $inputfile $outfile");
5513: chmod(0660, $filepath.'/tn-'.$file);
5514: if (-e $outfile) {
5515: my $copyfile=$targetdir.'/tn-'.$file;
5516: if (copy($outfile,$copyfile)) {
5517: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5518: my $thumb_metaoutput =
5519: &write_metadata($dom,$confname,$formname,
5520: $targetdir,'tn-'.$file,$logfile);
5521: push(@{$modified_urls},[$copyfile,$outfile]);
5522: unless ($registered_cleanup) {
5523: my $handlers = $r->get_handlers('PerlCleanupHandler');
5524: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5525: $registered_cleanup=1;
5526: }
1.16 raeburn 5527: } else {
5528: print $logfile "\nUnable to write ".$copyfile.
5529: ':'.$!."\n";
5530: }
5531: }
1.9 raeburn 5532: }
5533: }
5534: }
5535: } else {
5536: $output = $versionresult;
5537: }
5538: }
5539: return ($output,$logourl);
5540: }
5541:
5542: sub logo_versioning {
5543: my ($targetdir,$file,$logfile) = @_;
5544: my $target = $targetdir.'/'.$file;
5545: my ($maxversion,$fn,$extn,$output);
5546: $maxversion = 0;
5547: if ($file =~ /^(.+)\.(\w+)$/) {
5548: $fn=$1;
5549: $extn=$2;
5550: }
5551: opendir(DIR,$targetdir);
5552: while (my $filename=readdir(DIR)) {
5553: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5554: $maxversion=($1>$maxversion)?$1:$maxversion;
5555: }
5556: }
5557: $maxversion++;
5558: print $logfile "\nCreating old version ".$maxversion."\n";
5559: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5560: if (copy($target,$copyfile)) {
5561: print $logfile "Copied old target to ".$copyfile."\n";
5562: $copyfile=$copyfile.'.meta';
5563: if (copy($target.'.meta',$copyfile)) {
5564: print $logfile "Copied old target metadata to ".$copyfile."\n";
5565: $output = 'ok';
5566: } else {
5567: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5568: $output = &mt('Failed to copy old meta').", $!, ";
5569: }
5570: } else {
5571: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5572: $output = &mt('Failed to copy old target').", $!, ";
5573: }
5574: return $output;
5575: }
5576:
5577: sub write_metadata {
5578: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5579: my (%metadatafields,%metadatakeys,$output);
5580: $metadatafields{'title'}=$formname;
5581: $metadatafields{'creationdate'}=time;
5582: $metadatafields{'lastrevisiondate'}=time;
5583: $metadatafields{'copyright'}='public';
5584: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5585: $env{'user.domain'};
5586: $metadatafields{'authorspace'}=$confname.':'.$dom;
5587: $metadatafields{'domain'}=$dom;
5588: {
5589: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5590: my $mfh;
1.155 raeburn 5591: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
5592: foreach (sort keys %metadatafields) {
5593: unless ($_=~/\./) {
5594: my $unikey=$_;
5595: $unikey=~/^([A-Za-z]+)/;
5596: my $tag=$1;
5597: $tag=~tr/A-Z/a-z/;
5598: print $mfh "\n\<$tag";
5599: foreach (split(/\,/,$metadatakeys{$unikey})) {
5600: my $value=$metadatafields{$unikey.'.'.$_};
5601: $value=~s/\"/\'\'/g;
5602: print $mfh ' '.$_.'="'.$value.'"';
5603: }
5604: print $mfh '>'.
5605: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5606: .'</'.$tag.'>';
5607: }
5608: }
5609: $output = 'ok';
5610: print $logfile "\nWrote metadata";
5611: close($mfh);
5612: } else {
5613: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5614: $output = &mt('Could not write metadata');
5615: }
5616: }
1.155 raeburn 5617: return $output;
5618: }
5619:
5620: sub notifysubscribed {
5621: foreach my $targetsource (@{$modified_urls}){
5622: next unless (ref($targetsource) eq 'ARRAY');
5623: my ($target,$source)=@{$targetsource};
5624: if ($source ne '') {
5625: if (open(my $logfh,'>>'.$source.'.log')) {
5626: print $logfh "\nCleanup phase: Notifications\n";
5627: my @subscribed=&subscribed_hosts($target);
5628: foreach my $subhost (@subscribed) {
5629: print $logfh "\nNotifying host ".$subhost.':';
5630: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5631: print $logfh $reply;
5632: }
5633: my @subscribedmeta=&subscribed_hosts("$target.meta");
5634: foreach my $subhost (@subscribedmeta) {
5635: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5636: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5637: $subhost);
5638: print $logfh $reply;
5639: }
5640: print $logfh "\n============ Done ============\n";
1.160 raeburn 5641: close($logfh);
1.155 raeburn 5642: }
5643: }
5644: }
5645: return OK;
5646: }
5647:
5648: sub subscribed_hosts {
5649: my ($target) = @_;
5650: my @subscribed;
5651: if (open(my $fh,"<$target.subscription")) {
5652: while (my $subline=<$fh>) {
5653: if ($subline =~ /^($match_lonid):/) {
5654: my $host = $1;
5655: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5656: unless (grep(/^\Q$host\E$/,@subscribed)) {
5657: push(@subscribed,$host);
5658: }
5659: }
5660: }
5661: }
5662: }
5663: return @subscribed;
1.9 raeburn 5664: }
5665:
5666: sub check_switchserver {
5667: my ($dom,$confname) = @_;
5668: my ($allowed,$switchserver);
5669: my $home = &Apache::lonnet::homeserver($confname,$dom);
5670: if ($home eq 'no_host') {
5671: $home = &Apache::lonnet::domain($dom,'primary');
5672: }
5673: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5674: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5675: if (!$allowed) {
5676: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/">'.&mt('Switch Server').'</a>';
1.9 raeburn 5677: }
5678: return $switchserver;
5679: }
5680:
1.1 raeburn 5681: sub modify_quotas {
1.86 raeburn 5682: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5683: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5684: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5685: if ($action eq 'quotas') {
5686: $context = 'tools';
1.163 raeburn 5687: } else {
1.86 raeburn 5688: $context = $action;
5689: }
5690: if ($context eq 'requestcourses') {
1.98 raeburn 5691: @usertools = ('official','unofficial','community');
1.106 raeburn 5692: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5693: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5694: %titles = &courserequest_titles();
5695: $toolregexp = join('|',@usertools);
5696: %conditions = &courserequest_conditions();
1.163 raeburn 5697: } elsif ($context eq 'requestauthor') {
5698: @usertools = ('author');
5699: %titles = &authorrequest_titles();
1.86 raeburn 5700: } else {
1.162 raeburn 5701: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5702: %titles = &tool_titles();
1.86 raeburn 5703: }
1.72 raeburn 5704: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5705: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5706: foreach my $key (keys(%env)) {
1.101 raeburn 5707: if ($context eq 'requestcourses') {
5708: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5709: my $item = $1;
5710: my $type = $2;
5711: if ($type =~ /^limit_(.+)/) {
5712: $limithash{$item}{$1} = $env{$key};
5713: } else {
5714: $confhash{$item}{$type} = $env{$key};
5715: }
5716: }
1.163 raeburn 5717: } elsif ($context eq 'requestauthor') {
5718: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5719: $confhash{$1} = $env{$key};
5720: }
1.101 raeburn 5721: } else {
1.86 raeburn 5722: if ($key =~ /^form\.quota_(.+)$/) {
5723: $confhash{'defaultquota'}{$1} = $env{$key};
5724: }
1.101 raeburn 5725: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5726: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5727: }
1.72 raeburn 5728: }
5729: }
1.163 raeburn 5730: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5731: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5732: @approvalnotify = sort(@approvalnotify);
5733: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5734: if (ref($domconfig{$action}) eq 'HASH') {
5735: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5736: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5737: $changes{'notify'}{'approval'} = 1;
5738: }
5739: } else {
1.144 raeburn 5740: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5741: $changes{'notify'}{'approval'} = 1;
5742: }
5743: }
5744: } else {
1.144 raeburn 5745: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5746: $changes{'notify'}{'approval'} = 1;
5747: }
5748: }
5749: } else {
1.86 raeburn 5750: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5751: }
1.72 raeburn 5752: foreach my $item (@usertools) {
5753: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5754: my $unset;
1.101 raeburn 5755: if ($context eq 'requestcourses') {
1.104 raeburn 5756: $unset = '0';
5757: if ($type eq '_LC_adv') {
5758: $unset = '';
5759: }
1.101 raeburn 5760: if ($confhash{$item}{$type} eq 'autolimit') {
5761: $confhash{$item}{$type} .= '=';
5762: unless ($limithash{$item}{$type} =~ /\D/) {
5763: $confhash{$item}{$type} .= $limithash{$item}{$type};
5764: }
5765: }
1.163 raeburn 5766: } elsif ($context eq 'requestauthor') {
5767: $unset = '0';
5768: if ($type eq '_LC_adv') {
5769: $unset = '';
5770: }
1.72 raeburn 5771: } else {
1.101 raeburn 5772: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5773: $confhash{$item}{$type} = 1;
5774: } else {
5775: $confhash{$item}{$type} = 0;
5776: }
1.72 raeburn 5777: }
1.86 raeburn 5778: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5779: if ($action eq 'requestauthor') {
5780: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5781: $changes{$type} = 1;
5782: }
5783: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5784: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5785: $changes{$item}{$type} = 1;
5786: }
5787: } else {
5788: if ($context eq 'requestcourses') {
1.104 raeburn 5789: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5790: $changes{$item}{$type} = 1;
5791: }
5792: } else {
5793: if (!$confhash{$item}{$type}) {
5794: $changes{$item}{$type} = 1;
5795: }
5796: }
5797: }
5798: } else {
5799: if ($context eq 'requestcourses') {
1.104 raeburn 5800: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5801: $changes{$item}{$type} = 1;
5802: }
1.163 raeburn 5803: } elsif ($context eq 'requestauthor') {
5804: if ($confhash{$type} ne $unset) {
5805: $changes{$type} = 1;
5806: }
1.72 raeburn 5807: } else {
5808: if (!$confhash{$item}{$type}) {
5809: $changes{$item}{$type} = 1;
5810: }
5811: }
5812: }
1.1 raeburn 5813: }
5814: }
1.163 raeburn 5815: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5816: if (ref($domconfig{'quotas'}) eq 'HASH') {
5817: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5818: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5819: if (exists($confhash{'defaultquota'}{$key})) {
5820: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5821: $changes{'defaultquota'}{$key} = 1;
5822: }
5823: } else {
5824: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5825: }
5826: }
1.86 raeburn 5827: } else {
5828: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5829: if (exists($confhash{'defaultquota'}{$key})) {
5830: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5831: $changes{'defaultquota'}{$key} = 1;
5832: }
5833: } else {
5834: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5835: }
1.1 raeburn 5836: }
5837: }
5838: }
1.86 raeburn 5839: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5840: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5841: if (ref($domconfig{'quotas'}) eq 'HASH') {
5842: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5843: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5844: $changes{'defaultquota'}{$key} = 1;
5845: }
5846: } else {
5847: if (!exists($domconfig{'quotas'}{$key})) {
5848: $changes{'defaultquota'}{$key} = 1;
5849: }
1.72 raeburn 5850: }
5851: } else {
1.86 raeburn 5852: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5853: }
1.1 raeburn 5854: }
5855: }
5856: }
1.72 raeburn 5857:
1.163 raeburn 5858: if ($context eq 'requestauthor') {
5859: $domdefaults{'requestauthor'} = \%confhash;
5860: } else {
5861: foreach my $key (keys(%confhash)) {
5862: $domdefaults{$key} = $confhash{$key};
5863: }
1.72 raeburn 5864: }
1.163 raeburn 5865:
1.1 raeburn 5866: my %quotahash = (
1.86 raeburn 5867: $action => { %confhash }
1.1 raeburn 5868: );
5869: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5870: $dom);
5871: if ($putresult eq 'ok') {
5872: if (keys(%changes) > 0) {
1.72 raeburn 5873: my $cachetime = 24*60*60;
5874: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5875:
1.1 raeburn 5876: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5877: unless (($context eq 'requestcourses') ||
5878: ($context eq 'requestauthor')) {
1.86 raeburn 5879: if (ref($changes{'defaultquota'}) eq 'HASH') {
5880: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5881: foreach my $type (@{$types},'default') {
5882: if (defined($changes{'defaultquota'}{$type})) {
5883: my $typetitle = $usertypes->{$type};
5884: if ($type eq 'default') {
5885: $typetitle = $othertitle;
5886: }
5887: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5888: }
5889: }
1.86 raeburn 5890: $resulttext .= '</ul></li>';
1.72 raeburn 5891: }
5892: }
1.80 raeburn 5893: my %newenv;
1.72 raeburn 5894: foreach my $item (@usertools) {
1.163 raeburn 5895: my (%haschgs,%inconf);
5896: if ($context eq 'requestauthor') {
5897: %haschgs = %changes;
5898: %inconf = %confhash;
5899: } else {
5900: if (ref($changes{$item}) eq 'HASH') {
5901: %haschgs = %{$changes{$item}};
5902: }
5903: if (ref($confhash{$item}) eq 'HASH') {
5904: %inconf = %{$confhash{$item}};
5905: }
5906: }
5907: if (keys(%haschgs) > 0) {
1.80 raeburn 5908: my $newacc =
5909: &Apache::lonnet::usertools_access($env{'user.name'},
5910: $env{'user.domain'},
1.86 raeburn 5911: $item,'reload',$context);
1.163 raeburn 5912: if (($context eq 'requestcourses') ||
5913: ($context eq 'requestauthor')) {
1.108 raeburn 5914: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5915: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5916: }
5917: } else {
5918: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5919: $newenv{'environment.availabletools.'.$item} = $newacc;
5920: }
1.80 raeburn 5921: }
1.163 raeburn 5922: unless ($context eq 'requestauthor') {
5923: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5924: }
1.72 raeburn 5925: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5926: if ($haschgs{$type}) {
1.72 raeburn 5927: my $typetitle = $usertypes->{$type};
5928: if ($type eq 'default') {
5929: $typetitle = $othertitle;
5930: } elsif ($type eq '_LC_adv') {
5931: $typetitle = 'LON-CAPA Advanced Users';
5932: }
1.163 raeburn 5933: if ($inconf{$type}) {
1.101 raeburn 5934: if ($context eq 'requestcourses') {
5935: my $cond;
1.163 raeburn 5936: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5937: if ($1 eq '') {
5938: $cond = &mt('(Automatic processing of any request).');
5939: } else {
5940: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5941: }
5942: } else {
1.163 raeburn 5943: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5944: }
5945: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5946: } elsif ($context eq 'requestauthor') {
5947: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5948: $titles{$inconf{$type}},$typetitle);
5949:
1.101 raeburn 5950: } else {
5951: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5952: }
1.72 raeburn 5953: } else {
1.104 raeburn 5954: if ($type eq '_LC_adv') {
1.163 raeburn 5955: if ($inconf{$type} eq '0') {
1.104 raeburn 5956: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5957: } else {
5958: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5959: }
5960: } else {
5961: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5962: }
1.72 raeburn 5963: }
5964: }
1.26 raeburn 5965: }
1.163 raeburn 5966: unless ($context eq 'requestauthor') {
5967: $resulttext .= '</ul></li>';
5968: }
1.26 raeburn 5969: }
1.1 raeburn 5970: }
1.163 raeburn 5971: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5972: if (ref($changes{'notify'}) eq 'HASH') {
5973: if ($changes{'notify'}{'approval'}) {
5974: if (ref($confhash{'notify'}) eq 'HASH') {
5975: if ($confhash{'notify'}{'approval'}) {
5976: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
5977: } else {
1.163 raeburn 5978: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 5979: }
5980: }
5981: }
5982: }
5983: }
1.1 raeburn 5984: $resulttext .= '</ul>';
1.80 raeburn 5985: if (keys(%newenv)) {
5986: &Apache::lonnet::appenv(\%newenv);
5987: }
1.1 raeburn 5988: } else {
1.86 raeburn 5989: if ($context eq 'requestcourses') {
5990: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 5991: } elsif ($context eq 'requestauthor') {
5992: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 5993: } else {
1.90 weissno 5994: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 5995: }
1.1 raeburn 5996: }
5997: } else {
1.11 albertel 5998: $resulttext = '<span class="LC_error">'.
5999: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6000: }
1.3 raeburn 6001: return $resulttext;
1.1 raeburn 6002: }
6003:
1.3 raeburn 6004: sub modify_autoenroll {
6005: my ($dom,%domconfig) = @_;
1.1 raeburn 6006: my ($resulttext,%changes);
6007: my %currautoenroll;
6008: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6009: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6010: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6011: }
6012: }
6013: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6014: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6015: sender => 'Sender for notification messages',
6016: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6017: my @offon = ('off','on');
1.17 raeburn 6018: my $sender_uname = $env{'form.sender_uname'};
6019: my $sender_domain = $env{'form.sender_domain'};
6020: if ($sender_domain eq '') {
6021: $sender_uname = '';
6022: } elsif ($sender_uname eq '') {
6023: $sender_domain = '';
6024: }
1.129 raeburn 6025: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6026: my %autoenrollhash = (
1.129 raeburn 6027: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6028: 'sender_uname' => $sender_uname,
6029: 'sender_domain' => $sender_domain,
6030: 'co-owners' => $coowners,
1.1 raeburn 6031: }
6032: );
1.4 raeburn 6033: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6034: $dom);
1.1 raeburn 6035: if ($putresult eq 'ok') {
6036: if (exists($currautoenroll{'run'})) {
6037: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6038: $changes{'run'} = 1;
6039: }
6040: } elsif ($autorun) {
6041: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6042: $changes{'run'} = 1;
1.1 raeburn 6043: }
6044: }
1.17 raeburn 6045: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6046: $changes{'sender'} = 1;
6047: }
1.17 raeburn 6048: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6049: $changes{'sender'} = 1;
6050: }
1.129 raeburn 6051: if ($currautoenroll{'co-owners'} ne '') {
6052: if ($currautoenroll{'co-owners'} ne $coowners) {
6053: $changes{'coowners'} = 1;
6054: }
6055: } elsif ($coowners) {
6056: $changes{'coowners'} = 1;
6057: }
1.1 raeburn 6058: if (keys(%changes) > 0) {
6059: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6060: if ($changes{'run'}) {
1.1 raeburn 6061: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6062: }
6063: if ($changes{'sender'}) {
1.17 raeburn 6064: if ($sender_uname eq '' || $sender_domain eq '') {
6065: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6066: } else {
6067: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6068: }
1.1 raeburn 6069: }
1.129 raeburn 6070: if ($changes{'coowners'}) {
6071: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6072: &Apache::loncommon::devalidate_domconfig_cache($dom);
6073: }
1.1 raeburn 6074: $resulttext .= '</ul>';
6075: } else {
6076: $resulttext = &mt('No changes made to auto-enrollment settings');
6077: }
6078: } else {
1.11 albertel 6079: $resulttext = '<span class="LC_error">'.
6080: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6081: }
1.3 raeburn 6082: return $resulttext;
1.1 raeburn 6083: }
6084:
6085: sub modify_autoupdate {
1.3 raeburn 6086: my ($dom,%domconfig) = @_;
1.1 raeburn 6087: my ($resulttext,%currautoupdate,%fields,%changes);
6088: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6089: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6090: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6091: }
6092: }
6093: my @offon = ('off','on');
6094: my %title = &Apache::lonlocal::texthash (
6095: run => 'Auto-update:',
6096: classlists => 'Updates to user information in classlists?'
6097: );
1.44 raeburn 6098: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6099: my %fieldtitles = &Apache::lonlocal::texthash (
6100: id => 'Student/Employee ID',
1.20 raeburn 6101: permanentemail => 'E-mail address',
1.1 raeburn 6102: lastname => 'Last Name',
6103: firstname => 'First Name',
6104: middlename => 'Middle Name',
1.132 raeburn 6105: generation => 'Generation',
1.1 raeburn 6106: );
1.142 raeburn 6107: $othertitle = &mt('All users');
1.1 raeburn 6108: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6109: $othertitle = &mt('Other users');
1.1 raeburn 6110: }
6111: foreach my $key (keys(%env)) {
6112: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6113: my ($usertype,$item) = ($1,$2);
6114: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6115: if ($usertype eq 'default') {
6116: push(@{$fields{$1}},$2);
6117: } elsif (ref($types) eq 'ARRAY') {
6118: if (grep(/^\Q$usertype\E$/,@{$types})) {
6119: push(@{$fields{$1}},$2);
6120: }
6121: }
6122: }
1.1 raeburn 6123: }
6124: }
1.131 raeburn 6125: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6126: @lockablenames = sort(@lockablenames);
6127: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6128: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6129: if (@changed) {
6130: $changes{'lockablenames'} = 1;
6131: }
6132: } else {
6133: if (@lockablenames) {
6134: $changes{'lockablenames'} = 1;
6135: }
6136: }
1.1 raeburn 6137: my %updatehash = (
6138: autoupdate => { run => $env{'form.autoupdate_run'},
6139: classlists => $env{'form.classlists'},
6140: fields => {%fields},
1.131 raeburn 6141: lockablenames => \@lockablenames,
1.1 raeburn 6142: }
6143: );
6144: foreach my $key (keys(%currautoupdate)) {
6145: if (($key eq 'run') || ($key eq 'classlists')) {
6146: if (exists($updatehash{autoupdate}{$key})) {
6147: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6148: $changes{$key} = 1;
6149: }
6150: }
6151: } elsif ($key eq 'fields') {
6152: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6153: foreach my $item (@{$types},'default') {
1.1 raeburn 6154: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6155: my $change = 0;
6156: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6157: if (!exists($fields{$item})) {
6158: $change = 1;
1.132 raeburn 6159: last;
1.1 raeburn 6160: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6161: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6162: $change = 1;
1.132 raeburn 6163: last;
1.1 raeburn 6164: }
6165: }
6166: }
6167: if ($change) {
6168: push(@{$changes{$key}},$item);
6169: }
1.26 raeburn 6170: }
1.1 raeburn 6171: }
6172: }
1.131 raeburn 6173: } elsif ($key eq 'lockablenames') {
6174: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6175: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6176: if (@changed) {
6177: $changes{'lockablenames'} = 1;
6178: }
6179: } else {
6180: if (@lockablenames) {
6181: $changes{'lockablenames'} = 1;
6182: }
6183: }
6184: }
6185: }
6186: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6187: if (@lockablenames) {
6188: $changes{'lockablenames'} = 1;
1.1 raeburn 6189: }
6190: }
1.26 raeburn 6191: foreach my $item (@{$types},'default') {
6192: if (defined($fields{$item})) {
6193: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6194: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6195: my $change = 0;
6196: if (ref($fields{$item}) eq 'ARRAY') {
6197: foreach my $type (@{$fields{$item}}) {
6198: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6199: $change = 1;
6200: last;
6201: }
6202: }
6203: }
6204: if ($change) {
6205: push(@{$changes{'fields'}},$item);
6206: }
6207: } else {
1.26 raeburn 6208: push(@{$changes{'fields'}},$item);
6209: }
6210: } else {
6211: push(@{$changes{'fields'}},$item);
1.1 raeburn 6212: }
6213: }
6214: }
6215: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6216: $dom);
6217: if ($putresult eq 'ok') {
6218: if (keys(%changes) > 0) {
6219: $resulttext = &mt('Changes made:').'<ul>';
6220: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6221: if ($key eq 'lockablenames') {
6222: $resulttext .= '<li>';
6223: if (@lockablenames) {
6224: $usertypes->{'default'} = $othertitle;
6225: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6226: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6227: } else {
6228: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6229: }
6230: $resulttext .= '</li>';
6231: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6232: foreach my $item (@{$changes{$key}}) {
6233: my @newvalues;
6234: foreach my $type (@{$fields{$item}}) {
6235: push(@newvalues,$fieldtitles{$type});
6236: }
1.3 raeburn 6237: my $newvaluestr;
6238: if (@newvalues > 0) {
6239: $newvaluestr = join(', ',@newvalues);
6240: } else {
6241: $newvaluestr = &mt('none');
1.6 raeburn 6242: }
1.1 raeburn 6243: if ($item eq 'default') {
1.26 raeburn 6244: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6245: } else {
1.26 raeburn 6246: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6247: }
6248: }
6249: } else {
6250: my $newvalue;
6251: if ($key eq 'run') {
6252: $newvalue = $offon[$env{'form.autoupdate_run'}];
6253: } else {
6254: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6255: }
1.1 raeburn 6256: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6257: }
6258: }
6259: $resulttext .= '</ul>';
6260: } else {
1.3 raeburn 6261: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6262: }
6263: } else {
1.11 albertel 6264: $resulttext = '<span class="LC_error">'.
6265: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6266: }
1.3 raeburn 6267: return $resulttext;
1.1 raeburn 6268: }
6269:
1.125 raeburn 6270: sub modify_autocreate {
6271: my ($dom,%domconfig) = @_;
6272: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6273: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6274: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6275: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6276: }
6277: }
6278: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6279: req => 'Auto-creation of validated requests for official courses',
6280: xmldc => 'Identity of course creator of courses from XML files',
6281: );
6282: my @types = ('xml','req');
6283: foreach my $item (@types) {
6284: $newvals{$item} = $env{'form.autocreate_'.$item};
6285: $newvals{$item} =~ s/\D//g;
6286: $newvals{$item} = 0 if ($newvals{$item} eq '');
6287: }
6288: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6289: my %domcoords = &get_active_dcs($dom);
6290: unless (exists($domcoords{$newvals{'xmldc'}})) {
6291: $newvals{'xmldc'} = '';
6292: }
6293: %autocreatehash = (
6294: autocreate => { xml => $newvals{'xml'},
6295: req => $newvals{'req'},
6296: }
6297: );
6298: if ($newvals{'xmldc'} ne '') {
6299: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6300: }
6301: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6302: $dom);
6303: if ($putresult eq 'ok') {
6304: my @items = @types;
6305: if ($newvals{'xml'}) {
6306: push(@items,'xmldc');
6307: }
6308: foreach my $item (@items) {
6309: if (exists($currautocreate{$item})) {
6310: if ($currautocreate{$item} ne $newvals{$item}) {
6311: $changes{$item} = 1;
6312: }
6313: } elsif ($newvals{$item}) {
6314: $changes{$item} = 1;
6315: }
6316: }
6317: if (keys(%changes) > 0) {
6318: my @offon = ('off','on');
6319: $resulttext = &mt('Changes made:').'<ul>';
6320: foreach my $item (@types) {
6321: if ($changes{$item}) {
6322: my $newtxt = $offon[$newvals{$item}];
6323: $resulttext .= '<li>'.&mt("$title{$item} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
6324: }
6325: }
6326: if ($changes{'xmldc'}) {
6327: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6328: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
6329: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]$newtxt [_2]",'<b>','</b>').'</li>';
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: }
6475: $resulttext .= '<li>'.&mt("Users from domain '<span class=\"LC_cusr_emph\">[_1]</span>' permitted to search the institutional directory set to: [_2]",$dom,$chgtext).'</li>';
1.23 raeburn 6476: }
6477: }
6478: }
6479: if (ref($changes{'searchby'}) eq 'ARRAY') {
6480: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6481: my $chgtext;
6482: foreach my $type (@{$titleorder}) {
6483: if (grep(/^\Q$type\E$/,@searchby)) {
6484: if (defined($searchtitles->{$type})) {
6485: $chgtext .= $searchtitles->{$type}.'; ';
6486: }
6487: }
6488: }
6489: $chgtext =~ s/\; $//;
6490: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6491: }
1.25 raeburn 6492: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6493: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6494: my $chgtext;
6495: foreach my $type (@{$srchtypeorder}) {
6496: if (grep(/^\Q$type\E$/,@searchtypes)) {
6497: if (defined($srchtypes_desc->{$type})) {
6498: $chgtext .= $srchtypes_desc->{$type}.'; ';
6499: }
6500: }
6501: }
6502: $chgtext =~ s/\; $//;
6503: $resulttext .= '<li>'.&mt("$title{'searchtypes'} set to: \"[_1]\"",$chgtext).'</li>';
1.23 raeburn 6504: }
6505: $resulttext .= '</ul>';
6506: } else {
6507: $resulttext = &mt('No changes made to institution directory search settings');
6508: }
6509: } else {
6510: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6511: &mt('An error occurred: [_1]',$putresult).'</span>';
6512: }
6513: return $resulttext;
6514: }
6515:
1.28 raeburn 6516: sub modify_contacts {
6517: my ($dom,%domconfig) = @_;
6518: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6519: if (ref($domconfig{'contacts'}) eq 'HASH') {
6520: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6521: $currsetting{$key} = $domconfig{'contacts'}{$key};
6522: }
6523: }
1.134 raeburn 6524: my (%others,%to,%bcc);
1.28 raeburn 6525: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6526: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6527: 'requestsmail');
1.28 raeburn 6528: foreach my $type (@mailings) {
6529: @{$newsetting{$type}} =
6530: &Apache::loncommon::get_env_multiple('form.'.$type);
6531: foreach my $item (@contacts) {
6532: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6533: $contacts_hash{contacts}{$type}{$item} = 1;
6534: } else {
6535: $contacts_hash{contacts}{$type}{$item} = 0;
6536: }
6537: }
6538: $others{$type} = $env{'form.'.$type.'_others'};
6539: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6540: if ($type eq 'helpdeskmail') {
6541: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6542: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6543: }
1.28 raeburn 6544: }
6545: foreach my $item (@contacts) {
6546: $to{$item} = $env{'form.'.$item};
6547: $contacts_hash{'contacts'}{$item} = $to{$item};
6548: }
6549: if (keys(%currsetting) > 0) {
6550: foreach my $item (@contacts) {
6551: if ($to{$item} ne $currsetting{$item}) {
6552: $changes{$item} = 1;
6553: }
6554: }
6555: foreach my $type (@mailings) {
6556: foreach my $item (@contacts) {
6557: if (ref($currsetting{$type}) eq 'HASH') {
6558: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6559: push(@{$changes{$type}},$item);
6560: }
6561: } else {
6562: push(@{$changes{$type}},@{$newsetting{$type}});
6563: }
6564: }
6565: if ($others{$type} ne $currsetting{$type}{'others'}) {
6566: push(@{$changes{$type}},'others');
6567: }
1.134 raeburn 6568: if ($type eq 'helpdeskmail') {
6569: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6570: push(@{$changes{$type}},'bcc');
6571: }
6572: }
1.28 raeburn 6573: }
6574: } else {
6575: my %default;
6576: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6577: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6578: $default{'errormail'} = 'adminemail';
6579: $default{'packagesmail'} = 'adminemail';
6580: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6581: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6582: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6583: foreach my $item (@contacts) {
6584: if ($to{$item} ne $default{$item}) {
6585: $changes{$item} = 1;
6586: }
6587: }
6588: foreach my $type (@mailings) {
6589: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6590:
6591: push(@{$changes{$type}},@{$newsetting{$type}});
6592: }
6593: if ($others{$type} ne '') {
6594: push(@{$changes{$type}},'others');
1.134 raeburn 6595: }
6596: if ($type eq 'helpdeskmail') {
6597: if ($bcc{$type} ne '') {
6598: push(@{$changes{$type}},'bcc');
6599: }
6600: }
1.28 raeburn 6601: }
6602: }
6603: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6604: $dom);
6605: if ($putresult eq 'ok') {
6606: if (keys(%changes) > 0) {
6607: my ($titles,$short_titles) = &contact_titles();
6608: $resulttext = &mt('Changes made:').'<ul>';
6609: foreach my $item (@contacts) {
6610: if ($changes{$item}) {
6611: $resulttext .= '<li>'.$titles->{$item}.
6612: &mt(' set to: ').
6613: '<span class="LC_cusr_emph">'.
6614: $to{$item}.'</span></li>';
6615: }
6616: }
6617: foreach my $type (@mailings) {
6618: if (ref($changes{$type}) eq 'ARRAY') {
6619: $resulttext .= '<li>'.$titles->{$type}.': ';
6620: my @text;
6621: foreach my $item (@{$newsetting{$type}}) {
6622: push(@text,$short_titles->{$item});
6623: }
6624: if ($others{$type} ne '') {
6625: push(@text,$others{$type});
6626: }
6627: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6628: join(', ',@text).'</span>';
6629: if ($type eq 'helpdeskmail') {
6630: if ($bcc{$type} ne '') {
6631: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6632: }
6633: }
6634: $resulttext .= '</li>';
1.28 raeburn 6635: }
6636: }
6637: $resulttext .= '</ul>';
6638: } else {
1.34 raeburn 6639: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6640: }
6641: } else {
6642: $resulttext = '<span class="LC_error">'.
6643: &mt('An error occurred: [_1].',$putresult).'</span>';
6644: }
6645: return $resulttext;
6646: }
6647:
6648: sub modify_usercreation {
1.27 raeburn 6649: my ($dom,%domconfig) = @_;
1.34 raeburn 6650: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6651: my $warningmsg;
1.27 raeburn 6652: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6653: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6654: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6655: }
6656: }
6657: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6658: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6659: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6660: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6661: foreach my $item(@contexts) {
1.45 raeburn 6662: if ($item eq 'selfcreate') {
1.50 raeburn 6663: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6664: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6665: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6666: if (ref($cancreate{$item}) eq 'ARRAY') {
6667: if (grep(/^login$/,@{$cancreate{$item}})) {
6668: $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.');
6669: }
1.43 raeburn 6670: }
6671: }
1.50 raeburn 6672: } else {
6673: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6674: }
1.34 raeburn 6675: }
1.93 raeburn 6676: my ($othertitle,$usertypes,$types) =
6677: &Apache::loncommon::sorted_inst_types($dom);
6678: if (ref($types) eq 'ARRAY') {
6679: if (@{$types} > 0) {
6680: @{$cancreate{'statustocreate'}} =
6681: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6682: } else {
6683: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6684: }
6685: push(@contexts,'statustocreate');
6686: }
1.165 raeburn 6687: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6688: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6689: foreach my $item (@contexts) {
1.93 raeburn 6690: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6691: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6692: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6693: if (ref($cancreate{$item}) eq 'ARRAY') {
6694: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6695: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6696: push(@{$changes{'cancreate'}},$item);
6697: }
1.50 raeburn 6698: }
6699: }
6700: }
6701: } else {
6702: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6703: if (@{$cancreate{$item}} > 0) {
6704: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6705: push(@{$changes{'cancreate'}},$item);
6706: }
6707: }
6708: } else {
6709: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6710: if (@{$cancreate{$item}} < 3) {
6711: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6712: push(@{$changes{'cancreate'}},$item);
6713: }
6714: }
6715: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6716: if (@{$cancreate{$item}} > 0) {
6717: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6718: push(@{$changes{'cancreate'}},$item);
6719: }
6720: }
6721: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6722: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6723: push(@{$changes{'cancreate'}},$item);
6724: }
6725: }
6726: }
6727: }
6728: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6729: foreach my $type (@{$cancreate{$item}}) {
6730: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6731: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6732: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6733: push(@{$changes{'cancreate'}},$item);
6734: }
6735: }
6736: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6737: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6738: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6739: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6740: push(@{$changes{'cancreate'}},$item);
6741: }
6742: }
6743: }
6744: }
6745: }
6746: } else {
6747: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6748: push(@{$changes{'cancreate'}},$item);
6749: }
6750: }
1.27 raeburn 6751: }
1.34 raeburn 6752: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6753: foreach my $item (@contexts) {
1.43 raeburn 6754: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6755: if ($cancreate{$item} ne 'any') {
6756: push(@{$changes{'cancreate'}},$item);
6757: }
6758: } else {
6759: if ($cancreate{$item} ne 'none') {
6760: push(@{$changes{'cancreate'}},$item);
6761: }
1.27 raeburn 6762: }
6763: }
6764: } else {
1.43 raeburn 6765: foreach my $item (@contexts) {
1.34 raeburn 6766: push(@{$changes{'cancreate'}},$item);
6767: }
1.27 raeburn 6768: }
1.34 raeburn 6769:
1.27 raeburn 6770: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6771: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6772: if (!grep(/^\Q$type\E$/,@username_rule)) {
6773: push(@{$changes{'username_rule'}},$type);
6774: }
6775: }
6776: foreach my $type (@username_rule) {
6777: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6778: push(@{$changes{'username_rule'}},$type);
6779: }
6780: }
6781: } else {
6782: push(@{$changes{'username_rule'}},@username_rule);
6783: }
6784:
1.32 raeburn 6785: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6786: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6787: if (!grep(/^\Q$type\E$/,@id_rule)) {
6788: push(@{$changes{'id_rule'}},$type);
6789: }
6790: }
6791: foreach my $type (@id_rule) {
6792: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6793: push(@{$changes{'id_rule'}},$type);
6794: }
6795: }
6796: } else {
6797: push(@{$changes{'id_rule'}},@id_rule);
6798: }
6799:
1.43 raeburn 6800: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6801: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6802: if (!grep(/^\Q$type\E$/,@email_rule)) {
6803: push(@{$changes{'email_rule'}},$type);
6804: }
6805: }
6806: foreach my $type (@email_rule) {
6807: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6808: push(@{$changes{'email_rule'}},$type);
6809: }
6810: }
6811: } else {
6812: push(@{$changes{'email_rule'}},@email_rule);
6813: }
6814:
6815: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6816: my @authtypes = ('int','krb4','krb5','loc');
6817: my %authhash;
1.43 raeburn 6818: foreach my $item (@authen_contexts) {
1.28 raeburn 6819: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6820: foreach my $auth (@authtypes) {
6821: if (grep(/^\Q$auth\E$/,@authallowed)) {
6822: $authhash{$item}{$auth} = 1;
6823: } else {
6824: $authhash{$item}{$auth} = 0;
6825: }
6826: }
6827: }
6828: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6829: foreach my $item (@authen_contexts) {
1.28 raeburn 6830: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6831: foreach my $auth (@authtypes) {
6832: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6833: push(@{$changes{'authtypes'}},$item);
6834: last;
6835: }
6836: }
6837: }
6838: }
6839: } else {
1.43 raeburn 6840: foreach my $item (@authen_contexts) {
1.28 raeburn 6841: push(@{$changes{'authtypes'}},$item);
6842: }
6843: }
6844:
1.27 raeburn 6845: my %usercreation_hash = (
1.28 raeburn 6846: usercreation => {
1.34 raeburn 6847: cancreate => \%cancreate,
1.27 raeburn 6848: username_rule => \@username_rule,
1.32 raeburn 6849: id_rule => \@id_rule,
1.43 raeburn 6850: email_rule => \@email_rule,
1.32 raeburn 6851: authtypes => \%authhash,
1.27 raeburn 6852: }
6853: );
6854:
6855: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6856: $dom);
1.50 raeburn 6857:
6858: my %selfcreatetypes = (
6859: sso => 'users authenticated by institutional single sign on',
6860: login => 'users authenticated by institutional log-in',
6861: email => 'users who provide a valid e-mail address for use as the username',
6862: );
1.27 raeburn 6863: if ($putresult eq 'ok') {
6864: if (keys(%changes) > 0) {
6865: $resulttext = &mt('Changes made:').'<ul>';
6866: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6867: my %lt = &usercreation_types();
6868: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6869: my $chgtext;
1.165 raeburn 6870: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6871: $chgtext = $lt{$type}.', ';
6872: }
1.45 raeburn 6873: if ($type eq 'selfcreate') {
1.50 raeburn 6874: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6875: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6876: } else {
1.100 raeburn 6877: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6878: foreach my $case (@{$cancreate{$type}}) {
6879: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6880: }
6881: $chgtext .= '</ul>';
1.100 raeburn 6882: if (ref($cancreate{$type}) eq 'ARRAY') {
6883: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6884: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6885: if (@{$cancreate{'statustocreate'}} == 0) {
6886: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6887: }
6888: }
6889: }
6890: }
1.43 raeburn 6891: }
1.93 raeburn 6892: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6893: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6894: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6895: if (@{$cancreate{'selfcreate'}} > 0) {
6896: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6897:
6898: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6899: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6900: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6901: }
1.96 raeburn 6902: } elsif (ref($usertypes) eq 'HASH') {
6903: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6904: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6905: } else {
6906: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6907: }
6908: $chgtext .= '<ul>';
6909: foreach my $case (@{$cancreate{$type}}) {
6910: if ($case eq 'default') {
6911: $chgtext .= '<li>'.$othertitle.'</li>';
6912: } else {
6913: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6914: }
6915: }
1.100 raeburn 6916: $chgtext .= '</ul>';
6917: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6918: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6919: }
6920: }
6921: } else {
6922: if (@{$cancreate{$type}} == 0) {
6923: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6924: } else {
6925: $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 6926: }
6927: }
6928: }
1.165 raeburn 6929: } elsif ($type eq 'captcha') {
6930: if ($cancreate{$type} eq 'notused') {
6931: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6932: } else {
6933: my %captchas = &captcha_phrases();
6934: if ($captchas{$cancreate{$type}}) {
6935: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6936: } else {
6937: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6938: }
6939: }
6940: } elsif ($type eq 'recaptchakeys') {
6941: my ($privkey,$pubkey);
6942: if (ref($cancreate{$type}) eq 'HASH') {
6943: $pubkey = $cancreate{$type}{'public'};
6944: $privkey = $cancreate{$type}{'private'};
6945: }
6946: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6947: if (!$pubkey) {
6948: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6949: } else {
6950: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6951: }
6952: if (!$privkey) {
6953: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6954: } else {
6955: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6956: }
6957: $chgtext .= '</ul>';
1.43 raeburn 6958: } else {
6959: if ($cancreate{$type} eq 'none') {
6960: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6961: } elsif ($cancreate{$type} eq 'any') {
6962: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6963: } elsif ($cancreate{$type} eq 'official') {
6964: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6965: } elsif ($cancreate{$type} eq 'unofficial') {
6966: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6967: }
1.34 raeburn 6968: }
6969: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 6970: }
6971: }
6972: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 6973: my ($rules,$ruleorder) =
6974: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 6975: my $chgtext = '<ul>';
6976: foreach my $type (@username_rule) {
6977: if (ref($rules->{$type}) eq 'HASH') {
6978: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
6979: }
6980: }
6981: $chgtext .= '</ul>';
6982: if (@username_rule > 0) {
6983: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
6984: } else {
1.28 raeburn 6985: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 6986: }
6987: }
1.32 raeburn 6988: if (ref($changes{'id_rule'}) eq 'ARRAY') {
6989: my ($idrules,$idruleorder) =
6990: &Apache::lonnet::inst_userrules($dom,'id');
6991: my $chgtext = '<ul>';
6992: foreach my $type (@id_rule) {
6993: if (ref($idrules->{$type}) eq 'HASH') {
6994: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
6995: }
6996: }
6997: $chgtext .= '</ul>';
6998: if (@id_rule > 0) {
6999: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7000: } else {
7001: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7002: }
7003: }
1.43 raeburn 7004: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7005: my ($emailrules,$emailruleorder) =
7006: &Apache::lonnet::inst_userrules($dom,'email');
7007: my $chgtext = '<ul>';
7008: foreach my $type (@email_rule) {
7009: if (ref($emailrules->{$type}) eq 'HASH') {
7010: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7011: }
7012: }
7013: $chgtext .= '</ul>';
7014: if (@email_rule > 0) {
7015: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7016: } else {
7017: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7018: }
7019: }
7020:
1.28 raeburn 7021: my %authname = &authtype_names();
7022: my %context_title = &context_names();
7023: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7024: my $chgtext = '<ul>';
7025: foreach my $type (@{$changes{'authtypes'}}) {
7026: my @allowed;
7027: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7028: foreach my $auth (@authtypes) {
7029: if ($authhash{$type}{$auth}) {
7030: push(@allowed,$authname{$auth});
7031: }
7032: }
1.43 raeburn 7033: if (@allowed > 0) {
7034: $chgtext .= join(', ',@allowed).'</li>';
7035: } else {
7036: $chgtext .= &mt('none').'</li>';
7037: }
1.28 raeburn 7038: }
7039: $chgtext .= '</ul>';
7040: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7041: $resulttext .= '</li>';
7042: }
1.27 raeburn 7043: $resulttext .= '</ul>';
7044: } else {
1.28 raeburn 7045: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7046: }
7047: } else {
7048: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7049: &mt('An error occurred: [_1]',$putresult).'</span>';
7050: }
1.43 raeburn 7051: if ($warningmsg ne '') {
7052: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7053: }
1.23 raeburn 7054: return $resulttext;
7055: }
7056:
1.165 raeburn 7057: sub process_captcha {
7058: my ($container,$changes,$newsettings,$current) = @_;
7059: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7060: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7061: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7062: $newsettings->{'captcha'} = 'original';
7063: }
7064: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7065: if ($container eq 'cancreate') {
7066: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7067: push(@{$changes->{'cancreate'}},'captcha');
7068: } elsif (!defined($changes->{'cancreate'})) {
7069: $changes->{'cancreate'} = ['captcha'];
7070: }
7071: } else {
7072: $changes->{'captcha'} = 1;
1.165 raeburn 7073: }
7074: }
7075: my ($newpub,$newpriv,$currpub,$currpriv);
7076: if ($newsettings->{'captcha'} eq 'recaptcha') {
7077: $newpub = $env{'form.'.$container.'_recaptchapub'};
7078: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7079: $newpub =~ s/\W//g;
7080: $newpriv =~ s/\W//g;
7081: $newsettings->{'recaptchakeys'} = {
7082: public => $newpub,
7083: private => $newpriv,
7084: };
1.165 raeburn 7085: }
7086: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7087: $currpub = $current->{'recaptchakeys'}{'public'};
7088: $currpriv = $current->{'recaptchakeys'}{'private'};
1.169 raeburn 7089: $newsettings->{'recaptchakeys'} = {
7090: public => '',
7091: private => '',
7092: }
1.165 raeburn 7093: }
7094: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7095: if ($container eq 'cancreate') {
7096: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7097: push(@{$changes->{'cancreate'}},'recaptchakeys');
7098: } elsif (!defined($changes->{'cancreate'})) {
7099: $changes->{'cancreate'} = ['recaptchakeys'];
7100: }
7101: } else {
7102: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7103: }
7104: }
7105: return;
7106: }
7107:
1.33 raeburn 7108: sub modify_usermodification {
7109: my ($dom,%domconfig) = @_;
7110: my ($resulttext,%curr_usermodification,%changes);
7111: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7112: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7113: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7114: }
7115: }
1.63 raeburn 7116: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7117: my %context_title = (
7118: author => 'In author context',
7119: course => 'In course context',
1.63 raeburn 7120: selfcreate => 'When self creating account',
1.33 raeburn 7121: );
7122: my @fields = ('lastname','firstname','middlename','generation',
7123: 'permanentemail','id');
7124: my %roles = (
7125: author => ['ca','aa'],
7126: course => ['st','ep','ta','in','cr'],
7127: );
1.63 raeburn 7128: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7129: if (ref($types) eq 'ARRAY') {
7130: push(@{$types},'default');
7131: $usertypes->{'default'} = $othertitle;
7132: }
7133: $roles{'selfcreate'} = $types;
1.33 raeburn 7134: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7135: my %modifyhash;
7136: foreach my $context (@contexts) {
7137: foreach my $role (@{$roles{$context}}) {
7138: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7139: foreach my $item (@fields) {
7140: if (grep(/^\Q$item\E$/,@modifiable)) {
7141: $modifyhash{$context}{$role}{$item} = 1;
7142: } else {
7143: $modifyhash{$context}{$role}{$item} = 0;
7144: }
7145: }
7146: }
7147: if (ref($curr_usermodification{$context}) eq 'HASH') {
7148: foreach my $role (@{$roles{$context}}) {
7149: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7150: foreach my $field (@fields) {
7151: if ($modifyhash{$context}{$role}{$field} ne
7152: $curr_usermodification{$context}{$role}{$field}) {
7153: push(@{$changes{$context}},$role);
7154: last;
7155: }
7156: }
7157: }
7158: }
7159: } else {
7160: foreach my $context (@contexts) {
7161: foreach my $role (@{$roles{$context}}) {
7162: push(@{$changes{$context}},$role);
7163: }
7164: }
7165: }
7166: }
7167: my %usermodification_hash = (
7168: usermodification => \%modifyhash,
7169: );
7170: my $putresult = &Apache::lonnet::put_dom('configuration',
7171: \%usermodification_hash,$dom);
7172: if ($putresult eq 'ok') {
7173: if (keys(%changes) > 0) {
7174: $resulttext = &mt('Changes made: ').'<ul>';
7175: foreach my $context (@contexts) {
7176: if (ref($changes{$context}) eq 'ARRAY') {
7177: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7178: if (ref($changes{$context}) eq 'ARRAY') {
7179: foreach my $role (@{$changes{$context}}) {
7180: my $rolename;
1.63 raeburn 7181: if ($context eq 'selfcreate') {
7182: $rolename = $role;
7183: if (ref($usertypes) eq 'HASH') {
7184: if ($usertypes->{$role} ne '') {
7185: $rolename = $usertypes->{$role};
7186: }
7187: }
1.33 raeburn 7188: } else {
1.63 raeburn 7189: if ($role eq 'cr') {
7190: $rolename = &mt('Custom');
7191: } else {
7192: $rolename = &Apache::lonnet::plaintext($role);
7193: }
1.33 raeburn 7194: }
7195: my @modifiable;
1.63 raeburn 7196: if ($context eq 'selfcreate') {
1.126 bisitz 7197: $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 7198: } else {
7199: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7200: }
1.33 raeburn 7201: foreach my $field (@fields) {
7202: if ($modifyhash{$context}{$role}{$field}) {
7203: push(@modifiable,$fieldtitles{$field});
7204: }
7205: }
7206: if (@modifiable > 0) {
7207: $resulttext .= join(', ',@modifiable);
7208: } else {
7209: $resulttext .= &mt('none');
7210: }
7211: $resulttext .= '</li>';
7212: }
7213: $resulttext .= '</ul></li>';
7214: }
7215: }
7216: }
7217: $resulttext .= '</ul>';
7218: } else {
7219: $resulttext = &mt('No changes made to user modification settings');
7220: }
7221: } else {
7222: $resulttext = '<span class="LC_error">'.
7223: &mt('An error occurred: [_1]',$putresult).'</span>';
7224: }
7225: return $resulttext;
7226: }
7227:
1.43 raeburn 7228: sub modify_defaults {
7229: my ($dom,$r) = @_;
7230: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7231: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7232: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7233: my @authtypes = ('internal','krb4','krb5','localauth');
7234: foreach my $item (@items) {
7235: $newvalues{$item} = $env{'form.'.$item};
7236: if ($item eq 'auth_def') {
7237: if ($newvalues{$item} ne '') {
7238: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7239: push(@errors,$item);
7240: }
7241: }
7242: } elsif ($item eq 'lang_def') {
7243: if ($newvalues{$item} ne '') {
7244: if ($newvalues{$item} =~ /^(\w+)/) {
7245: my $langcode = $1;
1.103 raeburn 7246: if ($langcode ne 'x_chef') {
7247: if (code2language($langcode) eq '') {
7248: push(@errors,$item);
7249: }
1.43 raeburn 7250: }
7251: } else {
7252: push(@errors,$item);
7253: }
7254: }
1.54 raeburn 7255: } elsif ($item eq 'timezone_def') {
7256: if ($newvalues{$item} ne '') {
1.62 raeburn 7257: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7258: push(@errors,$item);
7259: }
7260: }
1.68 raeburn 7261: } elsif ($item eq 'datelocale_def') {
7262: if ($newvalues{$item} ne '') {
7263: my @datelocale_ids = DateTime::Locale->ids();
7264: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7265: push(@errors,$item);
7266: }
7267: }
1.141 raeburn 7268: } elsif ($item eq 'portal_def') {
7269: if ($newvalues{$item} ne '') {
7270: 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])\/?$/) {
7271: push(@errors,$item);
7272: }
7273: }
1.43 raeburn 7274: }
7275: if (grep(/^\Q$item\E$/,@errors)) {
7276: $newvalues{$item} = $domdefaults{$item};
7277: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7278: $changes{$item} = 1;
7279: }
1.72 raeburn 7280: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7281: }
7282: my %defaults_hash = (
1.72 raeburn 7283: defaults => \%newvalues,
7284: );
1.43 raeburn 7285: my $title = &defaults_titles();
7286: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7287: $dom);
7288: if ($putresult eq 'ok') {
7289: if (keys(%changes) > 0) {
7290: $resulttext = &mt('Changes made:').'<ul>';
7291: my $version = $r->dir_config('lonVersion');
7292: 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";
7293: foreach my $item (sort(keys(%changes))) {
7294: my $value = $env{'form.'.$item};
7295: if ($value eq '') {
7296: $value = &mt('none');
7297: } elsif ($item eq 'auth_def') {
7298: my %authnames = &authtype_names();
7299: my %shortauth = (
7300: internal => 'int',
7301: krb4 => 'krb4',
7302: krb5 => 'krb5',
7303: localauth => 'loc',
7304: );
7305: $value = $authnames{$shortauth{$value}};
7306: }
7307: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7308: $mailmsgtext .= "$title->{$item} set to $value\n";
7309: }
7310: $resulttext .= '</ul>';
7311: $mailmsgtext .= "\n";
7312: my $cachetime = 24*60*60;
1.72 raeburn 7313: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7314: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7315: my $sysmail = $r->dir_config('lonSysEMail');
7316: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7317: }
1.43 raeburn 7318: } else {
1.54 raeburn 7319: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7320: }
7321: } else {
7322: $resulttext = '<span class="LC_error">'.
7323: &mt('An error occurred: [_1]',$putresult).'</span>';
7324: }
7325: if (@errors > 0) {
7326: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7327: foreach my $item (@errors) {
7328: $resulttext .= ' "'.$title->{$item}.'",';
7329: }
7330: $resulttext =~ s/,$//;
7331: }
7332: return $resulttext;
7333: }
7334:
1.46 raeburn 7335: sub modify_scantron {
1.48 raeburn 7336: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7337: my ($resulttext,%confhash,%changes,$errors);
7338: my $custom = 'custom.tab';
7339: my $default = 'default.tab';
7340: my $servadm = $r->dir_config('lonAdmEMail');
7341: my ($configuserok,$author_ok,$switchserver) =
7342: &config_check($dom,$confname,$servadm);
7343: if ($env{'form.scantronformat.filename'} ne '') {
7344: my $error;
7345: if ($configuserok eq 'ok') {
7346: if ($switchserver) {
1.130 raeburn 7347: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7348: } else {
7349: if ($author_ok eq 'ok') {
7350: my ($result,$scantronurl) =
7351: &publishlogo($r,'upload','scantronformat',$dom,
7352: $confname,'scantron','','',$custom);
7353: if ($result eq 'ok') {
7354: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7355: $changes{'scantronformat'} = 1;
1.46 raeburn 7356: } else {
7357: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7358: }
7359: } else {
7360: $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);
7361: }
7362: }
7363: } else {
7364: $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);
7365: }
7366: if ($error) {
7367: &Apache::lonnet::logthis($error);
7368: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7369: }
7370: }
1.48 raeburn 7371: if (ref($domconfig{'scantron'}) eq 'HASH') {
7372: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7373: if ($env{'form.scantronformat_del'}) {
7374: $confhash{'scantron'}{'scantronformat'} = '';
7375: $changes{'scantronformat'} = 1;
1.46 raeburn 7376: }
7377: }
7378: }
7379: if (keys(%confhash) > 0) {
7380: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7381: $dom);
7382: if ($putresult eq 'ok') {
7383: if (keys(%changes) > 0) {
1.48 raeburn 7384: if (ref($confhash{'scantron'}) eq 'HASH') {
7385: $resulttext = &mt('Changes made:').'<ul>';
7386: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7387: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7388: } else {
1.130 raeburn 7389: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7390: }
1.48 raeburn 7391: $resulttext .= '</ul>';
7392: } else {
1.130 raeburn 7393: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7394: }
7395: $resulttext .= '</ul>';
7396: &Apache::loncommon::devalidate_domconfig_cache($dom);
7397: } else {
1.130 raeburn 7398: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7399: }
7400: } else {
7401: $resulttext = '<span class="LC_error">'.
7402: &mt('An error occurred: [_1]',$putresult).'</span>';
7403: }
7404: } else {
1.130 raeburn 7405: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7406: }
7407: if ($errors) {
7408: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7409: $errors.'</ul>';
7410: }
7411: return $resulttext;
7412: }
7413:
1.48 raeburn 7414: sub modify_coursecategories {
7415: my ($dom,%domconfig) = @_;
1.57 raeburn 7416: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7417: $cathash);
1.48 raeburn 7418: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7419: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7420: $cathash = $domconfig{'coursecategories'}{'cats'};
7421: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7422: $changes{'togglecats'} = 1;
7423: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7424: }
7425: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7426: $changes{'categorize'} = 1;
7427: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7428: }
1.120 raeburn 7429: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7430: $changes{'togglecatscomm'} = 1;
7431: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7432: }
7433: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7434: $changes{'categorizecomm'} = 1;
7435: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7436: }
1.57 raeburn 7437: } else {
7438: $changes{'togglecats'} = 1;
7439: $changes{'categorize'} = 1;
1.124 raeburn 7440: $changes{'togglecatscomm'} = 1;
7441: $changes{'categorizecomm'} = 1;
1.87 raeburn 7442: $domconfig{'coursecategories'} = {
7443: togglecats => $env{'form.togglecats'},
7444: categorize => $env{'form.categorize'},
1.124 raeburn 7445: togglecatscomm => $env{'form.togglecatscomm'},
7446: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7447: };
1.57 raeburn 7448: }
7449: if (ref($cathash) eq 'HASH') {
7450: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7451: push (@deletecategory,'instcode::0');
7452: }
1.120 raeburn 7453: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7454: push(@deletecategory,'communities::0');
7455: }
1.48 raeburn 7456: }
1.57 raeburn 7457: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7458: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7459: if (@deletecategory > 0) {
7460: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7461: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7462: foreach my $item (@deletecategory) {
1.57 raeburn 7463: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7464: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7465: $deletions{$item} = 1;
1.57 raeburn 7466: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7467: }
7468: }
7469: }
1.57 raeburn 7470: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7471: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7472: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7473: $reorderings{$item} = 1;
1.57 raeburn 7474: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7475: }
7476: if ($env{'form.addcategory_name_'.$item} ne '') {
7477: my $newcat = $env{'form.addcategory_name_'.$item};
7478: my $newdepth = $depth+1;
7479: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7480: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7481: $adds{$newitem} = 1;
7482: }
7483: if ($env{'form.subcat_'.$item} ne '') {
7484: my $newcat = $env{'form.subcat_'.$item};
7485: my $newdepth = $depth+1;
7486: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7487: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7488: $adds{$newitem} = 1;
7489: }
7490: }
7491: }
7492: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7493: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7494: my $newitem = 'instcode::0';
1.57 raeburn 7495: if ($cathash->{$newitem} eq '') {
7496: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7497: $adds{$newitem} = 1;
7498: }
7499: } else {
7500: my $newitem = 'instcode::0';
1.57 raeburn 7501: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7502: $adds{$newitem} = 1;
7503: }
7504: }
1.120 raeburn 7505: if ($env{'form.communities'} eq '1') {
7506: if (ref($cathash) eq 'HASH') {
7507: my $newitem = 'communities::0';
7508: if ($cathash->{$newitem} eq '') {
7509: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7510: $adds{$newitem} = 1;
7511: }
7512: } else {
7513: my $newitem = 'communities::0';
7514: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7515: $adds{$newitem} = 1;
7516: }
7517: }
1.48 raeburn 7518: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7519: if (($env{'form.addcategory_name'} ne 'instcode') &&
7520: ($env{'form.addcategory_name'} ne 'communities')) {
7521: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7522: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7523: $adds{$newitem} = 1;
7524: }
1.48 raeburn 7525: }
1.57 raeburn 7526: my $putresult;
1.48 raeburn 7527: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7528: if (keys(%deletions) > 0) {
7529: foreach my $key (keys(%deletions)) {
7530: if ($predelallitems{$key} ne '') {
7531: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7532: }
7533: }
7534: }
7535: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7536: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7537: if (ref($chkcats[0]) eq 'ARRAY') {
7538: my $depth = 0;
7539: my $chg = 0;
7540: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7541: my $name = $chkcats[0][$i];
7542: my $item;
7543: if ($name eq '') {
7544: $chg ++;
7545: } else {
7546: $item = &escape($name).'::0';
7547: if ($chg) {
1.57 raeburn 7548: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7549: }
7550: $depth ++;
1.57 raeburn 7551: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7552: $depth --;
7553: }
7554: }
7555: }
1.57 raeburn 7556: }
7557: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7558: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7559: if ($putresult eq 'ok') {
1.57 raeburn 7560: my %title = (
1.120 raeburn 7561: togglecats => 'Show/Hide a course in catalog',
7562: categorize => 'Assign a category to a course',
7563: togglecatscomm => 'Show/Hide a community in catalog',
7564: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7565: );
7566: my %level = (
1.120 raeburn 7567: dom => 'set in Domain ("Modify Course/Community")',
7568: crs => 'set in Course ("Course Configuration")',
7569: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7570: );
1.48 raeburn 7571: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7572: if ($changes{'togglecats'}) {
7573: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7574: }
7575: if ($changes{'categorize'}) {
7576: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7577: }
1.120 raeburn 7578: if ($changes{'togglecatscomm'}) {
7579: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7580: }
7581: if ($changes{'categorizecomm'}) {
7582: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7583: }
1.57 raeburn 7584: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7585: my $cathash;
7586: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7587: $cathash = $domconfig{'coursecategories'}{'cats'};
7588: } else {
7589: $cathash = {};
7590: }
7591: my (@cats,@trails,%allitems);
7592: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7593: if (keys(%deletions) > 0) {
7594: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7595: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7596: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7597: }
7598: $resulttext .= '</ul></li>';
7599: }
7600: if (keys(%reorderings) > 0) {
7601: my %sort_by_trail;
7602: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7603: foreach my $key (keys(%reorderings)) {
7604: if ($allitems{$key} ne '') {
7605: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7606: }
1.48 raeburn 7607: }
1.57 raeburn 7608: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7609: $resulttext .= '<li>'.$trails[$trail].'</li>';
7610: }
7611: $resulttext .= '</ul></li>';
1.48 raeburn 7612: }
1.57 raeburn 7613: if (keys(%adds) > 0) {
7614: my %sort_by_trail;
7615: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7616: foreach my $key (keys(%adds)) {
7617: if ($allitems{$key} ne '') {
7618: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7619: }
7620: }
7621: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7622: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7623: }
1.57 raeburn 7624: $resulttext .= '</ul></li>';
1.48 raeburn 7625: }
7626: }
7627: $resulttext .= '</ul>';
7628: } else {
7629: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7630: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7631: }
7632: } else {
1.120 raeburn 7633: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7634: }
7635: return $resulttext;
7636: }
7637:
1.69 raeburn 7638: sub modify_serverstatuses {
7639: my ($dom,%domconfig) = @_;
7640: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7641: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7642: %currserverstatus = %{$domconfig{'serverstatuses'}};
7643: }
7644: my @pages = &serverstatus_pages();
7645: foreach my $type (@pages) {
7646: $newserverstatus{$type}{'namedusers'} = '';
7647: $newserverstatus{$type}{'machines'} = '';
7648: if (defined($env{'form.'.$type.'_namedusers'})) {
7649: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7650: my @okusers;
7651: foreach my $user (@users) {
7652: my ($uname,$udom) = split(/:/,$user);
7653: if (($udom =~ /^$match_domain$/) &&
7654: (&Apache::lonnet::domain($udom)) &&
7655: ($uname =~ /^$match_username$/)) {
7656: if (!grep(/^\Q$user\E/,@okusers)) {
7657: push(@okusers,$user);
7658: }
7659: }
7660: }
7661: if (@okusers > 0) {
7662: @okusers = sort(@okusers);
7663: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7664: }
7665: }
7666: if (defined($env{'form.'.$type.'_machines'})) {
7667: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7668: my @okmachines;
7669: foreach my $ip (@machines) {
7670: my @parts = split(/\./,$ip);
7671: next if (@parts < 4);
7672: my $badip = 0;
7673: for (my $i=0; $i<4; $i++) {
7674: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7675: $badip = 1;
7676: last;
7677: }
7678: }
7679: if (!$badip) {
7680: push(@okmachines,$ip);
7681: }
7682: }
7683: @okmachines = sort(@okmachines);
7684: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7685: }
7686: }
7687: my %serverstatushash = (
7688: serverstatuses => \%newserverstatus,
7689: );
7690: foreach my $type (@pages) {
1.83 raeburn 7691: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7692: my (@current,@new);
1.83 raeburn 7693: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7694: if ($currserverstatus{$type}{$setting} ne '') {
7695: @current = split(/,/,$currserverstatus{$type}{$setting});
7696: }
7697: }
7698: if ($newserverstatus{$type}{$setting} ne '') {
7699: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7700: }
7701: if (@current > 0) {
7702: if (@new > 0) {
7703: foreach my $item (@current) {
7704: if (!grep(/^\Q$item\E$/,@new)) {
7705: $changes{$type}{$setting} = 1;
1.82 raeburn 7706: last;
7707: }
7708: }
1.84 raeburn 7709: foreach my $item (@new) {
7710: if (!grep(/^\Q$item\E$/,@current)) {
7711: $changes{$type}{$setting} = 1;
7712: last;
1.82 raeburn 7713: }
7714: }
7715: } else {
1.83 raeburn 7716: $changes{$type}{$setting} = 1;
1.69 raeburn 7717: }
1.83 raeburn 7718: } elsif (@new > 0) {
7719: $changes{$type}{$setting} = 1;
1.69 raeburn 7720: }
7721: }
7722: }
7723: if (keys(%changes) > 0) {
1.81 raeburn 7724: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7725: my $putresult = &Apache::lonnet::put_dom('configuration',
7726: \%serverstatushash,$dom);
7727: if ($putresult eq 'ok') {
7728: $resulttext .= &mt('Changes made:').'<ul>';
7729: foreach my $type (@pages) {
1.84 raeburn 7730: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7731: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7732: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7733: if ($newserverstatus{$type}{'namedusers'} eq '') {
7734: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7735: } else {
7736: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7737: }
1.84 raeburn 7738: }
7739: if ($changes{$type}{'machines'}) {
1.69 raeburn 7740: if ($newserverstatus{$type}{'machines'} eq '') {
7741: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7742: } else {
7743: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7744: }
7745:
7746: }
7747: $resulttext .= '</ul></li>';
7748: }
7749: }
7750: $resulttext .= '</ul>';
7751: } else {
7752: $resulttext = '<span class="LC_error">'.
7753: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7754:
7755: }
7756: } else {
7757: $resulttext = &mt('No changes made to access to server status pages');
7758: }
7759: return $resulttext;
7760: }
7761:
1.118 jms 7762: sub modify_helpsettings {
1.122 jms 7763: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7764: my ($resulttext,$errors,%changes,%helphash);
7765: my %defaultchecked = ('submitbugs' => 'on');
7766: my @offon = ('off','on');
1.118 jms 7767: my @toggles = ('submitbugs');
7768: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7769: foreach my $item (@toggles) {
1.166 raeburn 7770: if ($defaultchecked{$item} eq 'on') {
7771: if ($domconfig{'helpsettings'}{$item} eq '') {
7772: if ($env{'form.'.$item} eq '0') {
7773: $changes{$item} = 1;
7774: }
7775: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7776: $changes{$item} = 1;
7777: }
7778: } elsif ($defaultchecked{$item} eq 'off') {
7779: if ($domconfig{'helpsettings'}{$item} eq '') {
7780: if ($env{'form.'.$item} eq '1') {
7781: $changes{$item} = 1;
7782: }
7783: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7784: $changes{$item} = 1;
7785: }
7786: }
7787: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7788: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7789: }
7790: }
1.118 jms 7791: }
1.123 jms 7792: my $putresult;
7793: if (keys(%changes) > 0) {
1.166 raeburn 7794: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7795: if ($putresult eq 'ok') {
1.166 raeburn 7796: $resulttext = &mt('Changes made:').'<ul>';
7797: foreach my $item (sort(keys(%changes))) {
7798: if ($item eq 'submitbugs') {
7799: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7800: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7801: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7802: }
7803: }
7804: $resulttext .= '</ul>';
7805: } else {
7806: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7807: $errors .= '<li><span class="LC_error">'.
7808: &mt('An error occurred storing the settings: [_1]',
7809: $putresult).'</span></li>';
1.166 raeburn 7810: }
1.118 jms 7811: }
7812: if ($errors) {
1.168 raeburn 7813: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7814: $errors.'</ul>';
7815: }
7816: return $resulttext;
7817: }
7818:
1.121 raeburn 7819: sub modify_coursedefaults {
7820: my ($dom,%domconfig) = @_;
7821: my ($resulttext,$errors,%changes,%defaultshash);
7822: my %defaultchecked = ('canuse_pdfforms' => 'off');
7823: my @offon = ('off','on');
7824: my @toggles = ('canuse_pdfforms');
7825:
7826: $defaultshash{'coursedefaults'} = {};
7827:
7828: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7829: if ($domconfig{'coursedefaults'} eq '') {
7830: $domconfig{'coursedefaults'} = {};
7831: }
7832: }
7833:
7834: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7835: foreach my $item (@toggles) {
7836: if ($defaultchecked{$item} eq 'on') {
7837: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7838: ($env{'form.'.$item} eq '0')) {
7839: $changes{$item} = 1;
7840: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7841: $changes{$item} = 1;
7842: }
7843: } elsif ($defaultchecked{$item} eq 'off') {
7844: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7845: ($env{'form.'.$item} eq '1')) {
7846: $changes{$item} = 1;
7847: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7848: $changes{$item} = 1;
7849: }
7850: }
7851: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7852: }
1.139 raeburn 7853: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7854: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7855: $newdefresponder =~ s/\D//g;
7856: if ($newdefresponder eq '' || $newdefresponder < 1) {
7857: $newdefresponder = 1;
7858: }
7859: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7860: if ($currdefresponder ne $newdefresponder) {
7861: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7862: $changes{'anonsurvey_threshold'} = 1;
7863: }
7864: }
1.121 raeburn 7865: }
7866: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7867: $dom);
7868: if ($putresult eq 'ok') {
7869: if (keys(%changes) > 0) {
7870: if ($changes{'canuse_pdfforms'}) {
7871: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7872: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7873: my $cachetime = 24*60*60;
7874: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7875: }
7876: $resulttext = &mt('Changes made:').'<ul>';
7877: foreach my $item (sort(keys(%changes))) {
7878: if ($item eq 'canuse_pdfforms') {
7879: if ($env{'form.'.$item} eq '1') {
7880: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7881: } else {
7882: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7883: }
1.139 raeburn 7884: } elsif ($item eq 'anonsurvey_threshold') {
7885: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7886: }
1.121 raeburn 7887: }
7888: $resulttext .= '</ul>';
7889: } else {
7890: $resulttext = &mt('No changes made to course defaults');
7891: }
7892: } else {
7893: $resulttext = '<span class="LC_error">'.
7894: &mt('An error occurred: [_1]',$putresult).'</span>';
7895: }
7896: return $resulttext;
7897: }
7898:
1.137 raeburn 7899: sub modify_usersessions {
7900: my ($dom,%domconfig) = @_;
1.145 raeburn 7901: my @hostingtypes = ('version','excludedomain','includedomain');
7902: my @offloadtypes = ('primary','default');
7903: my %types = (
7904: remote => \@hostingtypes,
7905: hosted => \@hostingtypes,
7906: spares => \@offloadtypes,
7907: );
7908: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7909: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7910: my (%by_ip,%by_location,@intdoms);
7911: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7912: my @locations = sort(keys(%by_location));
1.137 raeburn 7913: my (%defaultshash,%changes);
7914: foreach my $prefix (@prefixes) {
7915: $defaultshash{'usersessions'}{$prefix} = {};
7916: }
7917: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7918: my $resulttext;
1.138 raeburn 7919: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7920: foreach my $prefix (@prefixes) {
1.145 raeburn 7921: next if ($prefix eq 'spares');
7922: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7923: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7924: if ($type eq 'version') {
7925: my $value = $env{'form.'.$prefix.'_'.$type};
7926: my $okvalue;
7927: if ($value ne '') {
7928: if (grep(/^\Q$value\E$/,@lcversions)) {
7929: $okvalue = $value;
7930: }
7931: }
7932: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7933: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7934: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7935: if ($inuse == 0) {
7936: $changes{$prefix}{$type} = 1;
7937: } else {
7938: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7939: $changes{$prefix}{$type} = 1;
7940: }
7941: if ($okvalue ne '') {
7942: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7943: }
7944: }
7945: } else {
7946: if (($inuse == 1) && ($okvalue ne '')) {
7947: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7948: $changes{$prefix}{$type} = 1;
7949: }
7950: }
7951: } else {
7952: if (($inuse == 1) && ($okvalue ne '')) {
7953: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7954: $changes{$prefix}{$type} = 1;
7955: }
7956: }
7957: } else {
7958: if (($inuse == 1) && ($okvalue ne '')) {
7959: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7960: $changes{$prefix}{$type} = 1;
7961: }
7962: }
7963: } else {
7964: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7965: my @okvals;
7966: foreach my $val (@vals) {
1.138 raeburn 7967: if ($val =~ /:/) {
7968: my @items = split(/:/,$val);
7969: foreach my $item (@items) {
7970: if (ref($by_location{$item}) eq 'ARRAY') {
7971: push(@okvals,$item);
7972: }
7973: }
7974: } else {
7975: if (ref($by_location{$val}) eq 'ARRAY') {
7976: push(@okvals,$val);
7977: }
1.137 raeburn 7978: }
7979: }
7980: @okvals = sort(@okvals);
7981: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7982: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7983: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
7984: if ($inuse == 0) {
7985: $changes{$prefix}{$type} = 1;
7986: } else {
7987: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7988: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
7989: if (@changed > 0) {
7990: $changes{$prefix}{$type} = 1;
7991: }
7992: }
7993: } else {
7994: if ($inuse == 1) {
7995: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
7996: $changes{$prefix}{$type} = 1;
7997: }
7998: }
7999: } else {
8000: if ($inuse == 1) {
8001: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8002: $changes{$prefix}{$type} = 1;
8003: }
8004: }
8005: } else {
8006: if ($inuse == 1) {
8007: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8008: $changes{$prefix}{$type} = 1;
8009: }
8010: }
8011: }
8012: }
8013: }
1.145 raeburn 8014:
8015: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8016: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8017: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8018: my $savespares;
8019:
8020: foreach my $lonhost (sort(keys(%servers))) {
8021: my $serverhomeID =
8022: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8023: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8024: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8025: my %spareschg;
8026: foreach my $type (@{$types{'spares'}}) {
8027: my @okspares;
8028: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8029: foreach my $server (@checked) {
1.152 raeburn 8030: if (&Apache::lonnet::hostname($server) ne '') {
8031: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8032: unless (grep(/^\Q$server\E$/,@okspares)) {
8033: push(@okspares,$server);
8034: }
1.145 raeburn 8035: }
8036: }
8037: }
8038: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8039: my $newspare;
1.152 raeburn 8040: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8041: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8042: $newspare = $new;
8043: }
8044: }
1.152 raeburn 8045: my @spares;
8046: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8047: @spares = sort(@okspares,$newspare);
8048: } else {
8049: @spares = sort(@okspares);
8050: }
8051: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8052: if (ref($spareid{$lonhost}) eq 'HASH') {
8053: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8054: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8055: if (@diffs > 0) {
8056: $spareschg{$type} = 1;
8057: }
8058: }
8059: }
8060: }
8061: if (keys(%spareschg) > 0) {
8062: $changes{'spares'}{$lonhost} = \%spareschg;
8063: }
8064: }
8065:
8066: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8067: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8068: if (ref($changes{'spares'}) eq 'HASH') {
8069: if (keys(%{$changes{'spares'}}) > 0) {
8070: $savespares = 1;
8071: }
8072: }
8073: } else {
8074: $savespares = 1;
8075: }
8076: }
8077:
1.147 raeburn 8078: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8079: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8080: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8081: $dom);
8082: if ($putresult eq 'ok') {
8083: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8084: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8085: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8086: }
8087: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8088: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8089: }
8090: }
8091: my $cachetime = 24*60*60;
8092: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8093: if (keys(%changes) > 0) {
8094: my %lt = &usersession_titles();
8095: $resulttext = &mt('Changes made:').'<ul>';
8096: foreach my $prefix (@prefixes) {
8097: if (ref($changes{$prefix}) eq 'HASH') {
8098: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8099: if ($prefix eq 'spares') {
8100: if (ref($changes{$prefix}) eq 'HASH') {
8101: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8102: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8103: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8104: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8105: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8106: foreach my $type (@{$types{$prefix}}) {
8107: if ($changes{$prefix}{$lonhost}{$type}) {
8108: my $offloadto = &mt('None');
8109: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8110: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8111: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8112: }
1.145 raeburn 8113: }
1.147 raeburn 8114: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8115: }
1.137 raeburn 8116: }
8117: }
1.147 raeburn 8118: $resulttext .= '</li>';
1.137 raeburn 8119: }
8120: }
1.147 raeburn 8121: } else {
8122: foreach my $type (@{$types{$prefix}}) {
8123: if (defined($changes{$prefix}{$type})) {
8124: my $newvalue;
8125: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8126: if (ref($defaultshash{'usersessions'}{$prefix})) {
8127: if ($type eq 'version') {
8128: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8129: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8130: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8131: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8132: }
1.145 raeburn 8133: }
8134: }
8135: }
1.147 raeburn 8136: if ($newvalue eq '') {
8137: if ($type eq 'version') {
8138: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8139: } else {
8140: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8141: }
1.145 raeburn 8142: } else {
1.147 raeburn 8143: if ($type eq 'version') {
8144: $newvalue .= ' '.&mt('(or later)');
8145: }
8146: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8147: }
1.137 raeburn 8148: }
8149: }
8150: }
1.147 raeburn 8151: $resulttext .= '</ul>';
1.137 raeburn 8152: }
8153: }
1.147 raeburn 8154: $resulttext .= '</ul>';
8155: } else {
8156: $resulttext = $nochgmsg;
1.137 raeburn 8157: }
8158: } else {
8159: $resulttext = '<span class="LC_error">'.
8160: &mt('An error occurred: [_1]',$putresult).'</span>';
8161: }
8162: } else {
1.147 raeburn 8163: $resulttext = $nochgmsg;
1.137 raeburn 8164: }
8165: return $resulttext;
8166: }
8167:
1.150 raeburn 8168: sub modify_loadbalancing {
8169: my ($dom,%domconfig) = @_;
8170: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8171: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8172: my ($othertitle,$usertypes,$types) =
8173: &Apache::loncommon::sorted_inst_types($dom);
8174: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8175: my @sparestypes = ('primary','default');
8176: my %typetitles = &sparestype_titles();
8177: my $resulttext;
1.171 raeburn 8178: my (%currbalancer,%currtargets,%currrules,%existing);
8179: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8180: %existing = %{$domconfig{'loadbalancing'}};
8181: }
8182: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8183: \%currtargets,\%currrules);
8184: my ($saveloadbalancing,%defaultshash,%changes);
8185: my ($alltypes,$othertypes,$titles) =
8186: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8187: my %ruletitles = &offloadtype_text();
8188: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8189: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8190: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8191: if ($balancer eq '') {
8192: next;
8193: }
8194: if (!exists($servers{$balancer})) {
8195: if (exists($currbalancer{$balancer})) {
8196: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8197: }
1.171 raeburn 8198: next;
8199: }
8200: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8201: push(@{$changes{'delete'}},$balancer);
8202: next;
8203: }
8204: if (!exists($currbalancer{$balancer})) {
8205: push(@{$changes{'add'}},$balancer);
8206: }
8207: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8208: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8209: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8210: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8211: $saveloadbalancing = 1;
8212: }
8213: foreach my $sparetype (@sparestypes) {
8214: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8215: my @offloadto;
8216: foreach my $target (@targets) {
8217: if (($servers{$target}) && ($target ne $balancer)) {
8218: if ($sparetype eq 'default') {
8219: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8220: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8221: }
8222: }
1.171 raeburn 8223: unless(grep(/^\Q$target\E$/,@offloadto)) {
8224: push(@offloadto,$target);
8225: }
1.150 raeburn 8226: }
1.171 raeburn 8227: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8228: }
8229: }
1.171 raeburn 8230: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8231: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8232: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8233: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8234: if (@targetdiffs > 0) {
1.171 raeburn 8235: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8236: }
1.171 raeburn 8237: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8238: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8239: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8240: }
8241: }
8242: }
8243: } else {
1.171 raeburn 8244: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8245: foreach my $sparetype (@sparestypes) {
8246: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8247: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8248: $changes{'curr'}{$balancer}{'targets'} = 1;
8249: }
1.150 raeburn 8250: }
8251: }
8252: }
8253: }
8254: my $ishomedom;
1.171 raeburn 8255: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8256: $ishomedom = 1;
1.150 raeburn 8257: }
8258: if (ref($alltypes) eq 'ARRAY') {
8259: foreach my $type (@{$alltypes}) {
8260: my $rule;
1.171 raeburn 8261: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8262: (!$ishomedom)) {
1.171 raeburn 8263: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8264: }
8265: if ($rule eq 'specific') {
8266: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8267: }
1.171 raeburn 8268: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8269: if (ref($currrules{$balancer}) eq 'HASH') {
8270: if ($rule ne $currrules{$balancer}{$type}) {
8271: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8272: }
8273: } elsif ($rule ne '') {
1.171 raeburn 8274: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8275: }
8276: }
8277: }
1.171 raeburn 8278: }
8279: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8280: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8281: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8282: $defaultshash{'loadbalancing'} = {};
8283: }
8284: my $putresult = &Apache::lonnet::put_dom('configuration',
8285: \%defaultshash,$dom);
8286:
8287: if ($putresult eq 'ok') {
8288: if (keys(%changes) > 0) {
8289: if (ref($changes{'delete'}) eq 'ARRAY') {
8290: foreach my $balancer (sort(@{$changes{'delete'}})) {
8291: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8292: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8293: }
1.171 raeburn 8294: }
8295: if (ref($changes{'add'}) eq 'ARRAY') {
8296: foreach my $balancer (sort(@{$changes{'add'}})) {
8297: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8298: }
8299: }
8300: if (ref($changes{'curr'}) eq 'HASH') {
8301: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8302: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8303: if ($changes{'curr'}{$balancer}{'targets'}) {
8304: my %offloadstr;
8305: foreach my $sparetype (@sparestypes) {
8306: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8307: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8308: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8309: }
8310: }
1.150 raeburn 8311: }
1.171 raeburn 8312: if (keys(%offloadstr) == 0) {
8313: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8314: } else {
1.171 raeburn 8315: my $showoffload;
8316: foreach my $sparetype (@sparestypes) {
8317: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8318: if (defined($offloadstr{$sparetype})) {
8319: $showoffload .= $offloadstr{$sparetype};
8320: } else {
8321: $showoffload .= &mt('None');
8322: }
8323: $showoffload .= (' 'x3);
8324: }
8325: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8326: }
8327: }
8328: }
1.171 raeburn 8329: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8330: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8331: foreach my $type (@{$alltypes}) {
8332: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8333: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8334: my $balancetext;
8335: if ($rule eq '') {
8336: $balancetext = $ruletitles{'default'};
8337: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8338: $balancetext = $ruletitles{$rule};
8339: } else {
8340: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8341: }
8342: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8343: }
8344: }
8345: }
8346: }
1.171 raeburn 8347: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8348: }
1.171 raeburn 8349: }
8350: if ($resulttext ne '') {
8351: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8352: } else {
8353: $resulttext = $nochgmsg;
8354: }
8355: } else {
1.171 raeburn 8356: $resulttext = $nochgmsg;
1.150 raeburn 8357: }
8358: } else {
1.171 raeburn 8359: $resulttext = '<span class="LC_error">'.
8360: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8361: }
8362: } else {
1.171 raeburn 8363: $resulttext = $nochgmsg;
1.150 raeburn 8364: }
8365: return $resulttext;
8366: }
8367:
1.48 raeburn 8368: sub recurse_check {
8369: my ($chkcats,$categories,$depth,$name) = @_;
8370: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8371: my $chg = 0;
8372: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8373: my $category = $chkcats->[$depth]{$name}[$j];
8374: my $item;
8375: if ($category eq '') {
8376: $chg ++;
8377: } else {
8378: my $deeper = $depth + 1;
8379: $item = &escape($category).':'.&escape($name).':'.$depth;
8380: if ($chg) {
8381: $categories->{$item} -= $chg;
8382: }
8383: &recurse_check($chkcats,$categories,$deeper,$category);
8384: $deeper --;
8385: }
8386: }
8387: }
8388: return;
8389: }
8390:
8391: sub recurse_cat_deletes {
8392: my ($item,$coursecategories,$deletions) = @_;
8393: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8394: my $subdepth = $depth + 1;
8395: if (ref($coursecategories) eq 'HASH') {
8396: foreach my $subitem (keys(%{$coursecategories})) {
8397: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8398: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8399: delete($coursecategories->{$subitem});
8400: $deletions->{$subitem} = 1;
8401: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8402: }
1.48 raeburn 8403: }
8404: }
8405: return;
8406: }
8407:
1.125 raeburn 8408: sub get_active_dcs {
8409: my ($dom) = @_;
8410: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8411: my %domcoords;
8412: my $numdcs = 0;
8413: my $now = time;
8414: foreach my $server (keys(%dompersonnel)) {
8415: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8416: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8417: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8418: if (($end eq '') || ($end == 0) || ($end > $now)) {
8419: if ($start <= $now) {
8420: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8421: }
8422: }
8423: }
8424: }
8425: return %domcoords;
8426: }
8427:
8428: sub active_dc_picker {
8429: my ($dom,$curr_dc) = @_;
8430: my %domcoords = &get_active_dcs($dom);
8431: my @dcs = sort(keys(%domcoords));
8432: my $numdcs = scalar(@dcs);
8433: my $datatable;
8434: my $numinrow = 2;
8435: if ($numdcs > 1) {
8436: $datatable = '<table>';
8437: for (my $i=0; $i<@dcs; $i++) {
8438: my $rem = $i%($numinrow);
8439: if ($rem == 0) {
8440: if ($i > 0) {
8441: $datatable .= '</tr>';
8442: }
8443: $datatable .= '<tr>';
8444: }
8445: my $check = ' ';
8446: if ($curr_dc eq '') {
8447: if (!$i) {
8448: $check = ' checked="checked" ';
8449: }
8450: } elsif ($dcs[$i] eq $curr_dc) {
8451: $check = ' checked="checked" ';
8452: }
8453: if ($i == @dcs - 1) {
8454: my $colsleft = $numinrow - $rem;
8455: if ($colsleft > 1) {
8456: $datatable .= '<td colspan="'.$colsleft.'">';
8457: } else {
8458: $datatable .= '<td>';
8459: }
8460: } else {
8461: $datatable .= '<td>';
8462: }
8463: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8464: $datatable .= '<span class="LC_nobreak"><label>'.
8465: '<input type="radio" name="autocreate_xmldc"'.
8466: ' value="'.$dcs[$i].'"'.$check.'/>'.
8467: &Apache::loncommon::plainname($dcname,$dcdom).
8468: '</label></span></td>';
8469: }
8470: $datatable .= '</tr></table>';
8471: } elsif (@dcs) {
8472: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8473: $dcs[0].'" />';
8474: }
8475: return ($numdcs,$datatable);
8476: }
8477:
1.137 raeburn 8478: sub usersession_titles {
8479: return &Apache::lonlocal::texthash(
8480: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8481: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8482: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8483: version => 'LON-CAPA version requirement',
1.138 raeburn 8484: excludedomain => 'Allow all, but exclude specific domains',
8485: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8486: primary => 'Primary (checked first)',
1.154 raeburn 8487: default => 'Default',
1.137 raeburn 8488: );
8489: }
8490:
1.152 raeburn 8491: sub id_for_thisdom {
8492: my (%servers) = @_;
8493: my %altids;
8494: foreach my $server (keys(%servers)) {
8495: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8496: if ($serverhome ne $server) {
8497: $altids{$serverhome} = $server;
8498: }
8499: }
8500: return %altids;
8501: }
8502:
1.150 raeburn 8503: sub count_servers {
8504: my ($currbalancer,%servers) = @_;
8505: my (@spares,$numspares);
8506: foreach my $lonhost (sort(keys(%servers))) {
8507: next if ($currbalancer eq $lonhost);
8508: push(@spares,$lonhost);
8509: }
8510: if ($currbalancer) {
8511: $numspares = scalar(@spares);
8512: } else {
8513: $numspares = scalar(@spares) - 1;
8514: }
8515: return ($numspares,@spares);
8516: }
8517:
8518: sub lonbalance_targets_js {
1.171 raeburn 8519: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8520: my $select = &mt('Select');
8521: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8522: if (ref($servers) eq 'HASH') {
8523: $alltargets = join("','",sort(keys(%{$servers})));
8524: my @homedoms;
8525: foreach my $server (sort(keys(%{$servers}))) {
8526: if (&Apache::lonnet::host_domain($server) eq $dom) {
8527: push(@homedoms,'1');
8528: } else {
8529: push(@homedoms,'0');
8530: }
8531: }
8532: $allishome = join("','",@homedoms);
8533: }
8534: if (ref($types) eq 'ARRAY') {
8535: if (@{$types} > 0) {
8536: @alltypes = @{$types};
8537: }
8538: }
8539: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8540: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8541: my (%currbalancer,%currtargets,%currrules,%existing);
8542: if (ref($settings) eq 'HASH') {
8543: %existing = %{$settings};
8544: }
8545: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8546: \%currtargets,\%currrules);
8547: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8548: return <<"END";
8549:
8550: <script type="text/javascript">
8551: // <![CDATA[
8552:
1.171 raeburn 8553: currBalancers = new Array('$balancers');
8554:
8555: function toggleTargets(balnum) {
8556: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8557: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8558: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8559: var prevbalancer = prevhostitem.value;
8560: var baltotal = document.getElementById('loadbalancing_total').value;
8561: prevhostitem.value = balancer;
8562: if (prevbalancer != '') {
8563: var prevIdx = currBalancers.indexOf(prevbalancer);
8564: if (prevIdx != -1) {
8565: currBalancers.splice(prevIdx,1);
8566: }
8567: }
1.150 raeburn 8568: if (balancer == '') {
1.171 raeburn 8569: hideSpares(balnum);
1.150 raeburn 8570: } else {
1.171 raeburn 8571: var currIdx = currBalancers.indexOf(balancer);
8572: if (currIdx == -1) {
8573: currBalancers.push(balancer);
8574: }
1.150 raeburn 8575: var homedoms = new Array('$allishome');
1.171 raeburn 8576: var ishomedom = homedoms[lonhostitem.selectedIndex];
8577: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8578: }
1.171 raeburn 8579: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8580: return;
8581: }
8582:
1.171 raeburn 8583: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8584: var alltargets = new Array('$alltargets');
8585: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8586: var offloadtypes = new Array('primary','default');
8587:
1.171 raeburn 8588: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8589: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8590:
1.151 raeburn 8591: for (var i=0; i<offloadtypes.length; i++) {
8592: var count = 0;
8593: for (var j=0; j<alltargets.length; j++) {
8594: if (alltargets[j] != balancer) {
1.171 raeburn 8595: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8596: item.value = alltargets[j];
8597: item.style.textAlign='left';
8598: item.style.textFace='normal';
8599: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8600: if (currBalancers.indexOf(alltargets[j]) == -1) {
8601: item.disabled = '';
8602: } else {
8603: item.disabled = 'disabled';
8604: item.checked = false;
8605: }
1.151 raeburn 8606: count ++;
8607: }
1.150 raeburn 8608: }
8609: }
1.151 raeburn 8610: for (var k=0; k<insttypes.length; k++) {
8611: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8612: if (ishomedom == 1) {
1.171 raeburn 8613: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8614: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8615: } else {
1.171 raeburn 8616: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8617: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8618:
8619: }
8620: } else {
1.171 raeburn 8621: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8622: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8623: }
1.151 raeburn 8624: if ((insttypes[k] != '_LC_external') &&
8625: ((insttypes[k] != '_LC_internetdom') ||
8626: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8627: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8628: item.options.length = 0;
8629: item.options[0] = new Option("","",true,true);
8630: var idx = 0;
1.151 raeburn 8631: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8632: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8633: idx ++;
8634: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8635:
1.150 raeburn 8636: }
8637: }
8638: }
8639: }
8640: return;
8641: }
8642:
1.171 raeburn 8643: function hideSpares(balnum) {
1.150 raeburn 8644: var alltargets = new Array('$alltargets');
8645: var insttypes = new Array('$allinsttypes');
8646: var offloadtypes = new Array('primary','default');
8647:
1.171 raeburn 8648: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8649: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8650:
8651: var total = alltargets.length - 1;
8652: for (var i=0; i<offloadtypes; i++) {
8653: for (var j=0; j<total; j++) {
1.171 raeburn 8654: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8655: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8656: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8657: }
1.150 raeburn 8658: }
8659: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8660: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8661: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8662: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8663: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8664: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8665: }
8666: }
8667: return;
8668: }
8669:
1.171 raeburn 8670: function checkOffloads(item,balnum,type) {
1.150 raeburn 8671: var alltargets = new Array('$alltargets');
8672: var offloadtypes = new Array('primary','default');
8673: if (item.checked) {
8674: var total = alltargets.length - 1;
8675: var other;
8676: if (type == offloadtypes[0]) {
1.151 raeburn 8677: other = offloadtypes[1];
1.150 raeburn 8678: } else {
1.151 raeburn 8679: other = offloadtypes[0];
1.150 raeburn 8680: }
8681: for (var i=0; i<total; i++) {
1.171 raeburn 8682: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8683: if (server == item.value) {
1.171 raeburn 8684: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8685: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8686: }
8687: }
8688: }
8689: }
8690: return;
8691: }
8692:
1.171 raeburn 8693: function singleServerToggle(balnum,type) {
8694: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8695: if (offloadtoSelIdx == 0) {
1.171 raeburn 8696: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8697: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8698:
8699: } else {
1.171 raeburn 8700: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8701: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8702: }
8703: return;
8704: }
8705:
1.171 raeburn 8706: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8707: if (type == '_LC_external') {
1.171 raeburn 8708: return;
1.150 raeburn 8709: }
1.171 raeburn 8710: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8711: for (var i=0; i<typesRules.length; i++) {
8712: if (formname.elements[typesRules[i]].checked) {
8713: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8714: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8715: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8716: } else {
1.171 raeburn 8717: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8718: }
8719: }
8720: }
8721: return;
8722: }
8723:
8724: function balancerDeleteChange(balnum) {
8725: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8726: var baltotal = document.getElementById('loadbalancing_total').value;
8727: var addtarget;
8728: var removetarget;
8729: var action = 'delete';
8730: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8731: var lonhost = hostitem.value;
8732: var currIdx = currBalancers.indexOf(lonhost);
8733: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8734: if (currIdx != -1) {
8735: currBalancers.splice(currIdx,1);
8736: }
8737: addtarget = lonhost;
8738: } else {
8739: if (currIdx == -1) {
8740: currBalancers.push(lonhost);
8741: }
8742: removetarget = lonhost;
8743: action = 'undelete';
8744: }
8745: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8746: }
8747: return;
8748: }
8749:
8750: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8751: if (baltotal > 1) {
8752: var offloadtypes = new Array('primary','default');
8753: var alltargets = new Array('$alltargets');
8754: var insttypes = new Array('$allinsttypes');
8755: for (var i=0; i<baltotal; i++) {
8756: if (i != balnum) {
8757: for (var j=0; j<offloadtypes.length; j++) {
8758: var total = alltargets.length - 1;
8759: for (var k=0; k<total; k++) {
8760: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8761: var server = serveritem.value;
8762: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8763: if (server == addtarget) {
8764: serveritem.disabled = '';
8765: }
8766: }
8767: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8768: if (server == removetarget) {
8769: serveritem.disabled = 'disabled';
8770: serveritem.checked = false;
8771: }
8772: }
8773: }
8774: }
8775: for (var j=0; j<insttypes.length; j++) {
8776: if (insttypes[j] != '_LC_external') {
8777: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8778: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8779: var currSel = singleserver.selectedIndex;
8780: var currVal = singleserver.options[currSel].value;
8781: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8782: var numoptions = singleserver.options.length;
8783: var needsnew = 1;
8784: for (var k=0; k<numoptions; k++) {
8785: if (singleserver.options[k] == addtarget) {
8786: needsnew = 0;
8787: break;
8788: }
8789: }
8790: if (needsnew == 1) {
8791: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8792: }
8793: }
8794: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8795: singleserver.options.length = 0;
8796: if ((currVal) && (currVal != removetarget)) {
8797: singleserver.options[0] = new Option("","",false,false);
8798: } else {
8799: singleserver.options[0] = new Option("","",true,true);
8800: }
8801: var idx = 0;
8802: for (var m=0; m<alltargets.length; m++) {
8803: if (currBalancers.indexOf(alltargets[m]) == -1) {
8804: idx ++;
8805: if (currVal == alltargets[m]) {
8806: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8807: } else {
8808: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8809: }
8810: }
8811: }
8812: }
8813: }
8814: }
8815: }
1.150 raeburn 8816: }
8817: }
8818: }
8819: return;
8820: }
8821:
1.152 raeburn 8822: // ]]>
8823: </script>
8824:
8825: END
8826: }
8827:
8828: sub new_spares_js {
8829: my @sparestypes = ('primary','default');
8830: my $types = join("','",@sparestypes);
8831: my $select = &mt('Select');
8832: return <<"END";
8833:
8834: <script type="text/javascript">
8835: // <![CDATA[
8836:
8837: function updateNewSpares(formname,lonhost) {
8838: var types = new Array('$types');
8839: var include = new Array();
8840: var exclude = new Array();
8841: for (var i=0; i<types.length; i++) {
8842: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8843: for (var j=0; j<spareboxes.length; j++) {
8844: if (formname.elements[spareboxes[j]].checked) {
8845: exclude.push(formname.elements[spareboxes[j]].value);
8846: } else {
8847: include.push(formname.elements[spareboxes[j]].value);
8848: }
8849: }
8850: }
8851: for (var i=0; i<types.length; i++) {
8852: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8853: var selIdx = newSpare.selectedIndex;
8854: var currnew = newSpare.options[selIdx].value;
8855: var okSpares = new Array();
8856: for (var j=0; j<newSpare.options.length; j++) {
8857: var possible = newSpare.options[j].value;
8858: if (possible != '') {
8859: if (exclude.indexOf(possible) == -1) {
8860: okSpares.push(possible);
8861: } else {
8862: if (currnew == possible) {
8863: selIdx = 0;
8864: }
8865: }
8866: }
8867: }
8868: for (var k=0; k<include.length; k++) {
8869: if (okSpares.indexOf(include[k]) == -1) {
8870: okSpares.push(include[k]);
8871: }
8872: }
8873: okSpares.sort();
8874: newSpare.options.length = 0;
8875: if (selIdx == 0) {
8876: newSpare.options[0] = new Option("$select","",true,true);
8877: } else {
8878: newSpare.options[0] = new Option("$select","",false,false);
8879: }
8880: for (var m=0; m<okSpares.length; m++) {
8881: var idx = m+1;
8882: var selThis = 0;
8883: if (selIdx != 0) {
8884: if (okSpares[m] == currnew) {
8885: selThis = 1;
8886: }
8887: }
8888: if (selThis == 1) {
8889: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8890: } else {
8891: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8892: }
8893: }
8894: }
8895: return;
8896: }
8897:
8898: function checkNewSpares(lonhost,type) {
8899: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8900: var chosen = newSpare.options[newSpare.selectedIndex].value;
8901: if (chosen != '') {
8902: var othertype;
8903: var othernewSpare;
8904: if (type == 'primary') {
8905: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8906: }
8907: if (type == 'default') {
8908: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8909: }
8910: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8911: othernewSpare.selectedIndex = 0;
8912: }
8913: }
8914: return;
8915: }
8916:
8917: // ]]>
8918: </script>
8919:
8920: END
8921:
8922: }
8923:
8924: sub common_domprefs_js {
8925: return <<"END";
8926:
8927: <script type="text/javascript">
8928: // <![CDATA[
8929:
1.150 raeburn 8930: function getIndicesByName(formname,item) {
1.152 raeburn 8931: var group = new Array();
1.150 raeburn 8932: for (var i=0;i<formname.elements.length;i++) {
8933: if (formname.elements[i].name == item) {
1.152 raeburn 8934: group.push(formname.elements[i].id);
1.150 raeburn 8935: }
8936: }
1.152 raeburn 8937: return group;
1.150 raeburn 8938: }
8939:
8940: // ]]>
8941: </script>
8942:
8943: END
1.152 raeburn 8944:
1.150 raeburn 8945: }
8946:
1.165 raeburn 8947: sub recaptcha_js {
8948: my %lt = &captcha_phrases();
8949: return <<"END";
8950:
8951: <script type="text/javascript">
8952: // <![CDATA[
8953:
8954: function updateCaptcha(caller,context) {
8955: var privitem;
8956: var pubitem;
8957: var privtext;
8958: var pubtext;
8959: if (document.getElementById(context+'_recaptchapub')) {
8960: pubitem = document.getElementById(context+'_recaptchapub');
8961: } else {
8962: return;
8963: }
8964: if (document.getElementById(context+'_recaptchapriv')) {
8965: privitem = document.getElementById(context+'_recaptchapriv');
8966: } else {
8967: return;
8968: }
8969: if (document.getElementById(context+'_recaptchapubtxt')) {
8970: pubtext = document.getElementById(context+'_recaptchapubtxt');
8971: } else {
8972: return;
8973: }
8974: if (document.getElementById(context+'_recaptchaprivtxt')) {
8975: privtext = document.getElementById(context+'_recaptchaprivtxt');
8976: } else {
8977: return;
8978: }
8979: if (caller.checked) {
8980: if (caller.value == 'recaptcha') {
8981: pubitem.type = 'text';
8982: privitem.type = 'text';
8983: pubitem.size = '40';
8984: privitem.size = '40';
8985: pubtext.innerHTML = "$lt{'pub'}";
8986: privtext.innerHTML = "$lt{'priv'}";
8987: } else {
8988: pubitem.type = 'hidden';
8989: privitem.type = 'hidden';
8990: pubtext.innerHTML = '';
8991: privtext.innerHTML = '';
8992: }
8993: }
8994: return;
8995: }
8996:
8997: // ]]>
8998: </script>
8999:
9000: END
9001:
9002: }
9003:
9004: sub captcha_phrases {
9005: return &Apache::lonlocal::texthash (
9006: priv => 'Private key',
9007: pub => 'Public key',
9008: original => 'original (CAPTCHA)',
9009: recaptcha => 'successor (ReCAPTCHA)',
9010: notused => 'unused',
9011: );
9012: }
9013:
1.3 raeburn 9014: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>