Annotation of loncom/interface/domainprefs.pm, revision 1.184
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.184 ! raeburn 4: # $Id: domainprefs.pm,v 1.183 2013/01/09 18:14:04 bisitz Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.183 bisitz 48: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 49: may define a default set of logos and a color scheme which can be used to "brand"
50: the LON-CAPA instance. In addition, an institution will typically have a language
51: and timezone which are used for the majority of courses.
52:
53: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
54: host of other domain-wide settings which determine the types of functionality
55: available to users and courses in the domain.
56:
57: There is also a mechanism to configure cataloging of courses in the domain, and
58: controls on the operation of automated processes which govern such things as
59: roster updates, user directory updates and processing of course requests.
60:
61: The domain coordination manual which is built dynamically on install/update of
62: LON-CAPA from the relevant help items provides more information about domain
63: configuration.
64:
65: Most of the domain settings are stored in the configuration.db GDBM file which is
66: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
67: where $dom is the domain. The configuration.db stores settings in a number of
68: frozen hashes of hashes. In a few cases, domain information must be uploaded to
69: the domain as files (e.g., image files for logos etc., or plain text files for
70: bubblesheet formats). In this case the domainprefs.pm must be running in a user
71: session hosted on the primary library server in the domain, as these files are
72: stored in author space belonging to a special $dom-domainconfig user.
73:
74: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
75: the current settings, and provides an interface to make modifications.
76:
77: =head1 SUBROUTINES
78:
79: =over
80:
81: =item print_quotas()
82:
83: Inputs: 4
84:
85: $dom,$settings,$rowtotal,$action.
86:
87: $dom is the domain, $settings is a reference to a hash of current settings for
88: the current context, $rowtotal is a reference to the scalar used to record the
1.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',
1.183 bisitz 393: col3 => 'User affiliation',
1.150 raeburn 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.180 raeburn 434: # check if domconfig user exists for the domain.
435: my $servadm = $r->dir_config('lonAdmEMail');
436: my ($configuserok,$author_ok,$switchserver) =
437: &config_check($dom,$confname,$servadm);
438: unless ($configuserok eq 'ok') {
1.181 raeburn 439: &Apache::lonconfigsettings::print_header($r,$phase,$context);
440: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
441: $confname).
442: '<br />'
443: );
1.180 raeburn 444: if ($switchserver) {
1.181 raeburn 445: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
446: '<br />'.
447: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
448: '<br />'.
449: &mt('The "[_1]" user can be created automatically when a Domain Coordinator visits the web-based "Set domain configuration" screen, in a session hosted on the primary library server.',$confname).
450: '<br />'.
451: &mt('To do that now, use the following link: [_1]',$switchserver)
452: );
453: } else {
454: $r->print(&mt('To create that user from the command line run the ./UPDATE script found in the top level directory of the extracted LON-CAPA tarball.').
455: '<br />'.
456: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
457: );
1.180 raeburn 458: }
459: $r->print(&Apache::loncommon::end_page());
460: return OK;
461: }
1.21 raeburn 462: if (keys(%domconfig) == 0) {
463: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 464: my @ids=&Apache::lonnet::current_machine_ids();
465: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 466: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 467: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 468: my $custom_img_count = 0;
469: foreach my $img (@loginimages) {
470: if ($designhash{$dom.'.login.'.$img} ne '') {
471: $custom_img_count ++;
472: }
473: }
474: foreach my $role (@roles) {
475: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
476: $custom_img_count ++;
477: }
478: }
479: if ($custom_img_count > 0) {
1.94 raeburn 480: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 481: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 482: $r->print(
483: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
484: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
485: &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 />'.
486: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
487: if ($switch_server) {
1.30 raeburn 488: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 489: }
1.91 raeburn 490: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 491: return OK;
492: }
493: }
494: }
1.174 foxr 495:
1.91 raeburn 496: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 497: }
498: return OK;
499: }
500:
501: sub process_changes {
1.92 raeburn 502: my ($r,$dom,$confname,$action,$roles,$values) = @_;
503: my %domconfig;
504: if (ref($values) eq 'HASH') {
505: %domconfig = %{$values};
506: }
1.3 raeburn 507: my $output;
508: if ($action eq 'login') {
1.9 raeburn 509: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 510: } elsif ($action eq 'rolecolors') {
1.9 raeburn 511: $output = &modify_rolecolors($r,$dom,$confname,$roles,
512: %domconfig);
1.3 raeburn 513: } elsif ($action eq 'quotas') {
1.86 raeburn 514: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 515: } elsif ($action eq 'autoenroll') {
516: $output = &modify_autoenroll($dom,%domconfig);
517: } elsif ($action eq 'autoupdate') {
518: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 519: } elsif ($action eq 'autocreate') {
520: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 521: } elsif ($action eq 'directorysrch') {
522: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 523: } elsif ($action eq 'usercreation') {
1.28 raeburn 524: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 525: } elsif ($action eq 'usermodification') {
526: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 527: } elsif ($action eq 'contacts') {
528: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 529: } elsif ($action eq 'defaults') {
530: $output = &modify_defaults($dom,$r);
1.46 raeburn 531: } elsif ($action eq 'scantron') {
1.48 raeburn 532: $output = &modify_scantron($r,$dom,$confname,%domconfig);
533: } elsif ($action eq 'coursecategories') {
534: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 535: } elsif ($action eq 'serverstatuses') {
536: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 537: } elsif ($action eq 'requestcourses') {
538: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 539: } elsif ($action eq 'requestauthor') {
540: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 541: } elsif ($action eq 'helpsettings') {
1.122 jms 542: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 543: } elsif ($action eq 'coursedefaults') {
544: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 545: } elsif ($action eq 'usersessions') {
546: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 547: } elsif ($action eq 'loadbalancing') {
548: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 549: }
550: return $output;
551: }
552:
553: sub print_config_box {
1.9 raeburn 554: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 555: my $rowtotal = 0;
1.49 raeburn 556: my $output;
1.174 foxr 557:
1.49 raeburn 558: if ($action eq 'coursecategories') {
559: $output = &coursecategories_javascript($settings);
1.91 raeburn 560: }
1.49 raeburn 561: $output .=
1.30 raeburn 562: '<table class="LC_nested_outer">
1.3 raeburn 563: <tr>
1.66 raeburn 564: <th align="left" valign="middle"><span class="LC_nobreak">'.
565: &mt($item->{text}).' '.
566: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
567: '</tr>';
1.30 raeburn 568: $rowtotal ++;
1.110 raeburn 569: my $numheaders = 1;
570: if (ref($item->{'header'}) eq 'ARRAY') {
571: $numheaders = scalar(@{$item->{'header'}});
572: }
573: if ($numheaders > 1) {
1.64 raeburn 574: my $colspan = '';
1.145 raeburn 575: my $rightcolspan = '';
1.168 raeburn 576: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
577: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 578: $colspan = ' colspan="2"';
579: }
1.145 raeburn 580: if ($action eq 'usersessions') {
581: $rightcolspan = ' colspan="3"';
582: }
1.30 raeburn 583: $output .= '
1.3 raeburn 584: <tr>
585: <td>
586: <table class="LC_nested">
587: <tr class="LC_info_row">
1.59 bisitz 588: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 589: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 590: </tr>';
1.69 raeburn 591: $rowtotal ++;
1.6 raeburn 592: if ($action eq 'autoupdate') {
1.30 raeburn 593: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 594: } elsif ($action eq 'usercreation') {
1.33 raeburn 595: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
596: } elsif ($action eq 'usermodification') {
597: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 598: } elsif ($action eq 'coursecategories') {
599: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 600: } elsif ($action eq 'login') {
1.168 raeburn 601: if ($numheaders == 3) {
602: $colspan = ' colspan="2"';
603: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
604: } else {
605: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
606: }
1.102 raeburn 607: } elsif ($action eq 'requestcourses') {
608: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 609: } elsif ($action eq 'requestauthor') {
610: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 611: } elsif ($action eq 'usersessions') {
612: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 613: } elsif ($action eq 'rolecolors') {
1.30 raeburn 614: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 615: } elsif ($action eq 'coursedefaults') {
616: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 617: }
1.30 raeburn 618: $output .= '
1.6 raeburn 619: </table>
620: </td>
621: </tr>
622: <tr>
623: <td>
624: <table class="LC_nested">
625: <tr class="LC_info_row">
1.59 bisitz 626: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 627: $output .= '
1.59 bisitz 628: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 629: </tr>';
630: $rowtotal ++;
1.6 raeburn 631: if ($action eq 'autoupdate') {
1.131 raeburn 632: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
633: </table>
634: </td>
635: </tr>
636: <tr>
637: <td>
638: <table class="LC_nested">
639: <tr class="LC_info_row">
640: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
641: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
642: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
643: $rowtotal ++;
1.28 raeburn 644: } elsif ($action eq 'usercreation') {
1.34 raeburn 645: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
646: </table>
647: </td>
648: </tr>
649: <tr>
650: <td>
651: <table class="LC_nested">
652: <tr class="LC_info_row">
1.59 bisitz 653: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
654: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 655: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
656: $rowtotal ++;
1.33 raeburn 657: } elsif ($action eq 'usermodification') {
1.63 raeburn 658: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
659: </table>
660: </td>
661: </tr>
662: <tr>
663: <td>
664: <table class="LC_nested">
665: <tr class="LC_info_row">
666: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
667: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
668: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
669: $rowtotal ++;
1.57 raeburn 670: } elsif ($action eq 'coursecategories') {
671: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 672: } elsif ($action eq 'login') {
1.168 raeburn 673: if ($numheaders == 3) {
674: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
675: </table>
676: </td>
677: </tr>
678: <tr>
679: <td>
680: <table class="LC_nested">
681: <tr class="LC_info_row">
682: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
683: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
684: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
685: $rowtotal ++;
686: } else {
687: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
688: }
1.102 raeburn 689: } elsif ($action eq 'requestcourses') {
1.163 raeburn 690: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
691: } elsif ($action eq 'requestauthor') {
692: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 693: } elsif ($action eq 'usersessions') {
1.145 raeburn 694: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
695: </table>
696: </td>
697: </tr>
698: <tr>
699: <td>
700: <table class="LC_nested">
701: <tr class="LC_info_row">
702: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
703: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
704: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
705: $rowtotal ++;
1.139 raeburn 706: } elsif ($action eq 'coursedefaults') {
707: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 708: } elsif ($action eq 'rolecolors') {
1.30 raeburn 709: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 710: </table>
711: </td>
712: </tr>
713: <tr>
714: <td>
715: <table class="LC_nested">
716: <tr class="LC_info_row">
1.69 raeburn 717: <td class="LC_left_item"'.$colspan.' valign="top">'.
718: &mt($item->{'header'}->[2]->{'col1'}).'</td>
719: <td class="LC_right_item" valign="top">'.
720: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 721: </tr>'.
1.30 raeburn 722: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 723: </table>
724: </td>
725: </tr>
726: <tr>
727: <td>
728: <table class="LC_nested">
729: <tr class="LC_info_row">
1.59 bisitz 730: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
731: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 732: </tr>'.
1.30 raeburn 733: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
734: $rowtotal += 2;
1.6 raeburn 735: }
1.3 raeburn 736: } else {
1.30 raeburn 737: $output .= '
1.3 raeburn 738: <tr>
739: <td>
740: <table class="LC_nested">
1.30 raeburn 741: <tr class="LC_info_row">';
1.24 raeburn 742: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 743: $output .= '
1.59 bisitz 744: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 745: } elsif ($action eq 'serverstatuses') {
746: $output .= '
747: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
748: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
749:
1.6 raeburn 750: } else {
1.30 raeburn 751: $output .= '
1.69 raeburn 752: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
753: }
1.72 raeburn 754: if (defined($item->{'header'}->[0]->{'col3'})) {
755: $output .= '<td class="LC_left_item" valign="top">'.
756: &mt($item->{'header'}->[0]->{'col2'});
757: if ($action eq 'serverstatuses') {
758: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
759: }
1.69 raeburn 760: } else {
761: $output .= '<td class="LC_right_item" valign="top">'.
762: &mt($item->{'header'}->[0]->{'col2'});
763: }
764: $output .= '</td>';
765: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 766: if (defined($item->{'header'}->[0]->{'col4'})) {
767: $output .= '<td class="LC_left_item" valign="top">'.
768: &mt($item->{'header'}->[0]->{'col3'});
769: } else {
770: $output .= '<td class="LC_right_item" valign="top">'.
771: &mt($item->{'header'}->[0]->{'col3'});
772: }
1.69 raeburn 773: if ($action eq 'serverstatuses') {
774: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
775: }
776: $output .= '</td>';
1.6 raeburn 777: }
1.150 raeburn 778: if ($item->{'header'}->[0]->{'col4'}) {
779: $output .= '<td class="LC_right_item" valign="top">'.
780: &mt($item->{'header'}->[0]->{'col4'});
781: }
1.69 raeburn 782: $output .= '</tr>';
1.48 raeburn 783: $rowtotal ++;
1.168 raeburn 784: if ($action eq 'quotas') {
1.86 raeburn 785: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 786: } elsif ($action eq 'autoenroll') {
1.30 raeburn 787: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 788: } elsif ($action eq 'autocreate') {
789: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 790: } elsif ($action eq 'directorysrch') {
1.30 raeburn 791: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 792: } elsif ($action eq 'contacts') {
1.30 raeburn 793: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 794: } elsif ($action eq 'defaults') {
795: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 796: } elsif ($action eq 'scantron') {
797: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 798: } elsif ($action eq 'serverstatuses') {
799: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 800: } elsif ($action eq 'helpsettings') {
1.168 raeburn 801: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 802: } elsif ($action eq 'loadbalancing') {
803: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 804: }
1.3 raeburn 805: }
1.30 raeburn 806: $output .= '
1.3 raeburn 807: </table>
808: </td>
809: </tr>
1.30 raeburn 810: </table><br />';
811: return ($output,$rowtotal);
1.1 raeburn 812: }
813:
1.3 raeburn 814: sub print_login {
1.168 raeburn 815: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 816: my ($css_class,$datatable);
1.6 raeburn 817: my %choices = &login_choices();
1.110 raeburn 818:
1.168 raeburn 819: if ($caller eq 'service') {
1.149 raeburn 820: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 821: my $choice = $choices{'disallowlogin'};
822: $css_class = ' class="LC_odd_row"';
1.128 raeburn 823: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 824: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 825: '<th>'.$choices{'server'}.'</th>'.
826: '<th>'.$choices{'serverpath'}.'</th>'.
827: '<th>'.$choices{'custompath'}.'</th>'.
828: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 829: my %disallowed;
830: if (ref($settings) eq 'HASH') {
831: if (ref($settings->{'loginvia'}) eq 'HASH') {
832: %disallowed = %{$settings->{'loginvia'}};
833: }
834: }
835: foreach my $lonhost (sort(keys(%servers))) {
836: my $direct = 'selected="selected"';
1.128 raeburn 837: if (ref($disallowed{$lonhost}) eq 'HASH') {
838: if ($disallowed{$lonhost}{'server'} ne '') {
839: $direct = '';
840: }
1.110 raeburn 841: }
1.115 raeburn 842: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 843: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 844: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
845: '</option>';
1.184 ! raeburn 846: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 847: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 848: my $selected = '';
1.128 raeburn 849: if (ref($disallowed{$lonhost}) eq 'HASH') {
850: if ($hostid eq $disallowed{$lonhost}{'server'}) {
851: $selected = 'selected="selected"';
852: }
1.110 raeburn 853: }
854: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
855: $servers{$hostid}.'</option>';
856: }
1.128 raeburn 857: $datatable .= '</select></td>'.
858: '<td><select name="'.$lonhost.'_serverpath">';
859: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
860: my $pathname = $path;
861: if ($path eq 'custom') {
862: $pathname = &mt('Custom Path').' ->';
863: }
864: my $selected = '';
865: if (ref($disallowed{$lonhost}) eq 'HASH') {
866: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
867: $selected = 'selected="selected"';
868: }
869: } elsif ($path eq '') {
870: $selected = 'selected="selected"';
871: }
872: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
873: }
874: $datatable .= '</select></td>';
875: my ($custom,$exempt);
876: if (ref($disallowed{$lonhost}) eq 'HASH') {
877: $custom = $disallowed{$lonhost}{'custompath'};
878: $exempt = $disallowed{$lonhost}{'exempt'};
879: }
880: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
881: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
882: '</tr>';
1.110 raeburn 883: }
884: $datatable .= '</table></td></tr>';
885: return $datatable;
1.168 raeburn 886: } elsif ($caller eq 'page') {
887: my %defaultchecked = (
888: 'coursecatalog' => 'on',
889: 'adminmail' => 'off',
890: 'newuser' => 'off',
891: );
892: my @toggles = ('coursecatalog','adminmail','newuser');
893: my (%checkedon,%checkedoff);
1.42 raeburn 894: foreach my $item (@toggles) {
1.168 raeburn 895: if ($defaultchecked{$item} eq 'on') {
896: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 897: $checkedoff{$item} = ' ';
1.168 raeburn 898: } elsif ($defaultchecked{$item} eq 'off') {
899: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 900: $checkedon{$item} = ' ';
901: }
1.1 raeburn 902: }
1.168 raeburn 903: my @images = ('img','logo','domlogo','login');
904: my @logintext = ('textcol','bgcol');
905: my @bgs = ('pgbg','mainbg','sidebg');
906: my @links = ('link','alink','vlink');
907: my %designhash = &Apache::loncommon::get_domainconf($dom);
908: my %defaultdesign = %Apache::loncommon::defaultdesign;
909: my (%is_custom,%designs);
910: my %defaults = (
911: font => $defaultdesign{'login.font'},
912: );
1.6 raeburn 913: foreach my $item (@images) {
1.168 raeburn 914: $defaults{$item} = $defaultdesign{'login.'.$item};
915: $defaults{'showlogo'}{$item} = 1;
916: }
917: foreach my $item (@bgs) {
918: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 919: }
1.41 raeburn 920: foreach my $item (@logintext) {
1.168 raeburn 921: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 922: }
1.168 raeburn 923: foreach my $item (@links) {
924: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 925: }
1.168 raeburn 926: if (ref($settings) eq 'HASH') {
927: foreach my $item (@toggles) {
928: if ($settings->{$item} eq '1') {
929: $checkedon{$item} = ' checked="checked" ';
930: $checkedoff{$item} = ' ';
931: } elsif ($settings->{$item} eq '0') {
932: $checkedoff{$item} = ' checked="checked" ';
933: $checkedon{$item} = ' ';
934: }
935: }
936: foreach my $item (@images) {
937: if (defined($settings->{$item})) {
938: $designs{$item} = $settings->{$item};
939: $is_custom{$item} = 1;
940: }
941: if (defined($settings->{'showlogo'}{$item})) {
942: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
943: }
944: }
945: foreach my $item (@logintext) {
946: if ($settings->{$item} ne '') {
947: $designs{'logintext'}{$item} = $settings->{$item};
948: $is_custom{$item} = 1;
949: }
950: }
951: if ($settings->{'font'} ne '') {
952: $designs{'font'} = $settings->{'font'};
953: $is_custom{'font'} = 1;
954: }
955: foreach my $item (@bgs) {
956: if ($settings->{$item} ne '') {
957: $designs{'bgs'}{$item} = $settings->{$item};
958: $is_custom{$item} = 1;
959: }
960: }
961: foreach my $item (@links) {
962: if ($settings->{$item} ne '') {
963: $designs{'links'}{$item} = $settings->{$item};
964: $is_custom{$item} = 1;
965: }
966: }
967: } else {
968: if ($designhash{$dom.'.login.font'} ne '') {
969: $designs{'font'} = $designhash{$dom.'.login.font'};
970: $is_custom{'font'} = 1;
971: }
972: foreach my $item (@images) {
973: if ($designhash{$dom.'.login.'.$item} ne '') {
974: $designs{$item} = $designhash{$dom.'.login.'.$item};
975: $is_custom{$item} = 1;
976: }
977: }
978: foreach my $item (@bgs) {
979: if ($designhash{$dom.'.login.'.$item} ne '') {
980: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
981: $is_custom{$item} = 1;
982: }
1.6 raeburn 983: }
1.168 raeburn 984: foreach my $item (@links) {
985: if ($designhash{$dom.'.login.'.$item} ne '') {
986: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
987: $is_custom{$item} = 1;
988: }
1.6 raeburn 989: }
990: }
1.168 raeburn 991: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
992: logo => 'Institution Logo',
993: domlogo => 'Domain Logo',
994: login => 'Login box');
995: my $itemcount = 1;
996: foreach my $item (@toggles) {
997: $css_class = $itemcount%2?' class="LC_odd_row"':'';
998: $datatable .=
999: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1000: '</td><td>'.
1001: '<span class="LC_nobreak"><label><input type="radio" name="'.
1002: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1003: '</label> <label><input type="radio" name="'.$item.'"'.
1004: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1005: '</tr>';
1006: $itemcount ++;
1.6 raeburn 1007: }
1.168 raeburn 1008: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1009: $datatable .= '</tr></table></td></tr>';
1010: } elsif ($caller eq 'help') {
1011: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1012: my $switchserver = &check_switchserver($dom,$confname);
1013: my $itemcount = 1;
1014: $defaulturl = '/adm/loginproblems.html';
1015: $defaulttype = 'default';
1016: %lt = &Apache::lonlocal::texthash (
1017: del => 'Delete?',
1018: rep => 'Replace:',
1019: upl => 'Upload:',
1020: default => 'Default',
1021: custom => 'Custom',
1022: );
1023: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1024: my @currlangs;
1025: if (ref($settings) eq 'HASH') {
1026: if (ref($settings->{'helpurl'}) eq 'HASH') {
1027: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1028: next if ($settings->{'helpurl'}{$key} eq '');
1029: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1030: $type{$key} = 'custom';
1031: unless ($key eq 'nolang') {
1032: push(@currlangs,$key);
1033: }
1034: }
1035: } elsif ($settings->{'helpurl'} ne '') {
1036: $type{'nolang'} = 'custom';
1037: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1038: }
1039: }
1.168 raeburn 1040: foreach my $lang ('nolang',sort(@currlangs)) {
1041: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1042: $datatable .= '<tr'.$css_class.'>';
1043: if ($url{$lang} eq '') {
1044: $url{$lang} = $defaulturl;
1045: }
1046: if ($type{$lang} eq '') {
1047: $type{$lang} = $defaulttype;
1048: }
1049: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1050: if ($lang eq 'nolang') {
1051: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1052: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1053: } else {
1054: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1055: $langchoices{$lang},
1056: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1057: }
1058: $datatable .= '</span></td>'."\n".
1059: '<td class="LC_left_item">';
1060: if ($type{$lang} eq 'custom') {
1061: $datatable .= '<span class="LC_nobreak"><label>'.
1062: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1063: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1064: } else {
1065: $datatable .= $lt{'upl'};
1066: }
1067: $datatable .='<br />';
1068: if ($switchserver) {
1069: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1070: } else {
1071: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1072: }
1.168 raeburn 1073: $datatable .= '</td></tr>';
1074: $itemcount ++;
1.6 raeburn 1075: }
1.168 raeburn 1076: my @addlangs;
1077: foreach my $lang (sort(keys(%langchoices))) {
1078: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1079: push(@addlangs,$lang);
1080: }
1081: if (@addlangs > 0) {
1082: my %toadd;
1083: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1084: $toadd{''} = &mt('Select');
1085: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1086: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1087: &mt('Add log-in help page for a specific language:').' '.
1088: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1089: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1090: if ($switchserver) {
1091: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1092: } else {
1093: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1094: }
1.168 raeburn 1095: $datatable .= '</td></tr>';
1.169 raeburn 1096: $itemcount ++;
1.6 raeburn 1097: }
1.169 raeburn 1098: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1099: }
1.6 raeburn 1100: return $datatable;
1101: }
1102:
1103: sub login_choices {
1104: my %choices =
1105: &Apache::lonlocal::texthash (
1.116 bisitz 1106: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1107: adminmail => "Display Administrator's E-mail Address?",
1108: disallowlogin => "Login page requests redirected",
1109: hostid => "Server",
1.128 raeburn 1110: server => "Redirect to:",
1111: serverpath => "Path",
1112: custompath => "Custom",
1113: exempt => "Exempt IP(s)",
1.110 raeburn 1114: directlogin => "No redirect",
1115: newuser => "Link to create a user account",
1116: img => "Header",
1117: logo => "Main Logo",
1118: domlogo => "Domain Logo",
1119: login => "Log-in Header",
1120: textcol => "Text color",
1121: bgcol => "Box color",
1122: bgs => "Background colors",
1123: links => "Link colors",
1124: font => "Font color",
1125: pgbg => "Header",
1126: mainbg => "Page",
1127: sidebg => "Login box",
1128: link => "Link",
1129: alink => "Active link",
1130: vlink => "Visited link",
1.6 raeburn 1131: );
1132: return %choices;
1133: }
1134:
1135: sub print_rolecolors {
1.30 raeburn 1136: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1137: my %choices = &color_font_choices();
1138: my @bgs = ('pgbg','tabbg','sidebg');
1139: my @links = ('link','alink','vlink');
1140: my @images = ('img');
1141: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1142: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1143: my %defaultdesign = %Apache::loncommon::defaultdesign;
1144: my (%is_custom,%designs);
1145: my %defaults = (
1146: img => $defaultdesign{$role.'.img'},
1147: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1148: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1149: );
1150: foreach my $item (@bgs) {
1151: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1152: }
1153: foreach my $item (@links) {
1154: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1155: }
1156: if (ref($settings) eq 'HASH') {
1157: if (ref($settings->{$role}) eq 'HASH') {
1158: if ($settings->{$role}->{'img'} ne '') {
1159: $designs{'img'} = $settings->{$role}->{'img'};
1160: $is_custom{'img'} = 1;
1161: }
1162: if ($settings->{$role}->{'font'} ne '') {
1163: $designs{'font'} = $settings->{$role}->{'font'};
1164: $is_custom{'font'} = 1;
1165: }
1.97 tempelho 1166: if ($settings->{$role}->{'fontmenu'} ne '') {
1167: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1168: $is_custom{'fontmenu'} = 1;
1169: }
1.6 raeburn 1170: foreach my $item (@bgs) {
1171: if ($settings->{$role}->{$item} ne '') {
1172: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1173: $is_custom{$item} = 1;
1174: }
1175: }
1176: foreach my $item (@links) {
1177: if ($settings->{$role}->{$item} ne '') {
1178: $designs{'links'}{$item} = $settings->{$role}->{$item};
1179: $is_custom{$item} = 1;
1180: }
1181: }
1182: }
1183: } else {
1184: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1185: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1186: $is_custom{'img'} = 1;
1187: }
1.97 tempelho 1188: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1189: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1190: $is_custom{'fontmenu'} = 1;
1191: }
1.6 raeburn 1192: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1193: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1194: $is_custom{'font'} = 1;
1195: }
1196: foreach my $item (@bgs) {
1197: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1198: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1199: $is_custom{$item} = 1;
1200:
1201: }
1202: }
1203: foreach my $item (@links) {
1204: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1205: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1206: $is_custom{$item} = 1;
1207: }
1208: }
1209: }
1210: my $itemcount = 1;
1.30 raeburn 1211: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1212: $datatable .= '</tr></table></td></tr>';
1213: return $datatable;
1214: }
1215:
1216: sub display_color_options {
1.9 raeburn 1217: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1218: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1219: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1220: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1221: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1222: '<td>'.$choices->{'font'}.'</td>';
1223: if (!$is_custom->{'font'}) {
1.30 raeburn 1224: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1225: } else {
1226: $datatable .= '<td> </td>';
1227: }
1.174 foxr 1228: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1229:
1.8 raeburn 1230: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1231: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1232: ' value="'.$current_color.'" /> '.
1233: ' </td></tr>';
1.107 raeburn 1234: unless ($role eq 'login') {
1235: $datatable .= '<tr'.$css_class.'>'.
1236: '<td>'.$choices->{'fontmenu'}.'</td>';
1237: if (!$is_custom->{'fontmenu'}) {
1238: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1239: } else {
1240: $datatable .= '<td> </td>';
1241: }
1.174 foxr 1242: $current_color = $designs->{'fontmenu'} ?
1243: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1244: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1245: '<input class="colorchooser" type="text" size="10" name="'
1246: .$role.'_fontmenu"'.
1247: ' value="'.$current_color.'" /> '.
1248: ' </td></tr>';
1.97 tempelho 1249: }
1.9 raeburn 1250: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1251: foreach my $img (@{$images}) {
1.18 albertel 1252: $itemcount ++;
1.6 raeburn 1253: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1254: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1255: '<td>'.$choices->{$img};
1.41 raeburn 1256: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1257: if ($role eq 'login') {
1258: if ($img eq 'login') {
1259: $login_hdr_pick =
1.135 bisitz 1260: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1261: $logincolors =
1262: &login_text_colors($img,$role,$logintext,$phase,$choices,
1263: $designs);
1264: } elsif ($img ne 'domlogo') {
1265: $datatable.= &logo_display_options($img,$defaults,$designs);
1266: }
1267: }
1268: $datatable .= '</td>';
1.6 raeburn 1269: if ($designs->{$img} ne '') {
1270: $imgfile = $designs->{$img};
1.18 albertel 1271: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1272: } else {
1273: $imgfile = $defaults->{$img};
1274: }
1275: if ($imgfile) {
1.9 raeburn 1276: my ($showfile,$fullsize);
1277: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1278: my $urldir = $1;
1279: my $filename = $2;
1280: my @info = &Apache::lonnet::stat_file($designs->{$img});
1281: if (@info) {
1282: my $thumbfile = 'tn-'.$filename;
1283: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1284: if (@thumb) {
1285: $showfile = $urldir.'/'.$thumbfile;
1286: } else {
1287: $showfile = $imgfile;
1288: }
1289: } else {
1290: $showfile = '';
1291: }
1292: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1293: $showfile = $imgfile;
1.6 raeburn 1294: my $imgdir = $1;
1295: my $filename = $2;
1.159 raeburn 1296: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1297: $showfile = "/$imgdir/tn-".$filename;
1298: } else {
1.159 raeburn 1299: my $input = $londocroot.$imgfile;
1300: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1301: if (!-e $output) {
1.9 raeburn 1302: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1303: my ($fullwidth,$fullheight) = &check_dimensions($input);
1304: if ($fullwidth ne '' && $fullheight ne '') {
1305: if ($fullwidth > $width && $fullheight > $height) {
1306: my $size = $width.'x'.$height;
1307: system("convert -sample $size $input $output");
1.159 raeburn 1308: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1309: }
1310: }
1.6 raeburn 1311: }
1312: }
1.16 raeburn 1313: }
1.6 raeburn 1314: if ($showfile) {
1.40 raeburn 1315: if ($showfile =~ m{^/(adm|res)/}) {
1316: if ($showfile =~ m{^/res/}) {
1317: my $local_showfile =
1318: &Apache::lonnet::filelocation('',$showfile);
1319: &Apache::lonnet::repcopy($local_showfile);
1320: }
1321: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1322: }
1323: if ($imgfile) {
1324: if ($imgfile =~ m{^/(adm|res)/}) {
1325: if ($imgfile =~ m{^/res/}) {
1326: my $local_imgfile =
1327: &Apache::lonnet::filelocation('',$imgfile);
1328: &Apache::lonnet::repcopy($local_imgfile);
1329: }
1330: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1331: } else {
1332: $fullsize = $imgfile;
1333: }
1334: }
1.41 raeburn 1335: $datatable .= '<td>';
1336: if ($img eq 'login') {
1.135 bisitz 1337: $datatable .= $login_hdr_pick;
1338: }
1.41 raeburn 1339: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1340: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1341: } else {
1342: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1343: &mt('Upload:');
1344: }
1345: } else {
1346: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1347: &mt('Upload:');
1348: }
1.9 raeburn 1349: if ($switchserver) {
1350: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1351: } else {
1.135 bisitz 1352: if ($img ne 'login') { # suppress file selection for Log-in header
1353: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1354: }
1.9 raeburn 1355: }
1356: $datatable .= '</td></tr>';
1.6 raeburn 1357: }
1358: $itemcount ++;
1359: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1360: $datatable .= '<tr'.$css_class.'>'.
1361: '<td>'.$choices->{'bgs'}.'</td>';
1362: my $bgs_def;
1363: foreach my $item (@{$bgs}) {
1364: if (!$is_custom->{$item}) {
1.70 raeburn 1365: $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 1366: }
1367: }
1368: if ($bgs_def) {
1.8 raeburn 1369: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1370: } else {
1371: $datatable .= '<td> </td>';
1372: }
1373: $datatable .= '<td class="LC_right_item">'.
1374: '<table border="0"><tr>';
1.174 foxr 1375:
1376:
1.6 raeburn 1377: foreach my $item (@{$bgs}) {
1.174 foxr 1378: # my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'bgs'}{$item});
1379: $datatable .= '<td align="center">';
1380: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1381: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1382: $datatable .= ' ';
1.6 raeburn 1383: }
1.174 foxr 1384: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1385: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1386: }
1387: $datatable .= '</tr></table></td></tr>';
1388: $itemcount ++;
1389: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1390: $datatable .= '<tr'.$css_class.'>'.
1391: '<td>'.$choices->{'links'}.'</td>';
1392: my $links_def;
1393: foreach my $item (@{$links}) {
1394: if (!$is_custom->{$item}) {
1.30 raeburn 1395: $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 1396: }
1397: }
1398: if ($links_def) {
1.8 raeburn 1399: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1400: } else {
1401: $datatable .= '<td> </td>';
1402: }
1403: $datatable .= '<td class="LC_right_item">'.
1404: '<table border="0"><tr>';
1405: foreach my $item (@{$links}) {
1.174 foxr 1406: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1407: $datatable .= '<td align="center">'."\n";
1408:
1.6 raeburn 1409: if ($designs->{'links'}{$item}) {
1.174 foxr 1410: $datatable.=' ';
1.6 raeburn 1411: }
1.174 foxr 1412: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1413: '" /></td>';
1414: }
1.30 raeburn 1415: $$rowtotal += $itemcount;
1.3 raeburn 1416: return $datatable;
1417: }
1418:
1.70 raeburn 1419: sub logo_display_options {
1420: my ($img,$defaults,$designs) = @_;
1421: my $checkedon;
1422: if (ref($defaults) eq 'HASH') {
1423: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1424: if ($defaults->{'showlogo'}{$img}) {
1425: $checkedon = 'checked="checked" ';
1426: }
1427: }
1428: }
1429: if (ref($designs) eq 'HASH') {
1430: if (ref($designs->{'showlogo'}) eq 'HASH') {
1431: if (defined($designs->{'showlogo'}{$img})) {
1432: if ($designs->{'showlogo'}{$img} == 0) {
1433: $checkedon = '';
1434: } elsif ($designs->{'showlogo'}{$img} == 1) {
1435: $checkedon = 'checked="checked" ';
1436: }
1437: }
1438: }
1439: }
1440: return '<br /><label> <input type="checkbox" name="'.
1441: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1442: &mt('show').'</label>'."\n";
1443: }
1444:
1.41 raeburn 1445: sub login_header_options {
1.135 bisitz 1446: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1447: my $output = '';
1.41 raeburn 1448: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1449: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1450: if (!$is_custom->{'textcol'}) {
1451: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1452: ' ';
1453: }
1454: if (!$is_custom->{'bgcol'}) {
1455: $output .= $choices->{'bgcol'}.': '.
1456: '<span id="css_'.$role.'_font" style="background-color: '.
1457: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1458: }
1459: $output .= '<br />';
1460: }
1461: $output .='<br />';
1462: return $output;
1463: }
1464:
1465: sub login_text_colors {
1466: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1467: my $color_menu = '<table border="0"><tr>';
1468: foreach my $item (@{$logintext}) {
1469: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1470: $color_menu .= '<td align="center">'.$link;
1471: if ($designs->{'logintext'}{$item}) {
1472: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1473: }
1474: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1475: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1476: '<td> </td>';
1477: }
1478: $color_menu .= '</tr></table><br />';
1479: return $color_menu;
1480: }
1481:
1482: sub image_changes {
1483: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1484: my $output;
1.135 bisitz 1485: if ($img eq 'login') {
1486: # suppress image for Log-in header
1487: } elsif (!$is_custom) {
1.70 raeburn 1488: if ($img ne 'domlogo') {
1.41 raeburn 1489: $output .= &mt('Default image:').'<br />';
1490: } else {
1491: $output .= &mt('Default in use:').'<br />';
1492: }
1493: }
1.135 bisitz 1494: if ($img eq 'login') { # suppress image for Log-in header
1495: $output .= '<td>'.$logincolors;
1.41 raeburn 1496: } else {
1.135 bisitz 1497: if ($img_import) {
1498: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1499: }
1500: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1501: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1502: if ($is_custom) {
1503: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1504: '<input type="checkbox" name="'.
1505: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1506: '</label> '.&mt('Replace:').'</span><br />';
1507: } else {
1508: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1509: }
1.41 raeburn 1510: }
1511: return $output;
1512: }
1513:
1.6 raeburn 1514: sub color_pick {
1515: my ($phase,$role,$item,$desc,$curcol) = @_;
1516: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1517: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1518: ');">'.$desc.'</a>';
1519: return $link;
1520: }
1521:
1.3 raeburn 1522: sub print_quotas {
1.86 raeburn 1523: my ($dom,$settings,$rowtotal,$action) = @_;
1524: my $context;
1525: if ($action eq 'quotas') {
1526: $context = 'tools';
1527: } else {
1528: $context = $action;
1529: }
1.101 raeburn 1530: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1531: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1532: my $typecount = 0;
1.101 raeburn 1533: my ($css_class,%titles);
1.86 raeburn 1534: if ($context eq 'requestcourses') {
1.98 raeburn 1535: @usertools = ('official','unofficial','community');
1.106 raeburn 1536: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1537: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1538: %titles = &courserequest_titles();
1.163 raeburn 1539: } elsif ($context eq 'requestauthor') {
1540: @usertools = ('author');
1541: @options = ('norequest','approval','automatic');
1542: %titles = &authorrequest_titles();
1.86 raeburn 1543: } else {
1.162 raeburn 1544: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1545: %titles = &tool_titles();
1.86 raeburn 1546: }
1.26 raeburn 1547: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1548: foreach my $type (@{$types}) {
1.72 raeburn 1549: my $currdefquota;
1.163 raeburn 1550: unless (($context eq 'requestcourses') ||
1551: ($context eq 'requestauthor')) {
1.86 raeburn 1552: if (ref($settings) eq 'HASH') {
1553: if (ref($settings->{defaultquota}) eq 'HASH') {
1554: $currdefquota = $settings->{defaultquota}->{$type};
1555: } else {
1556: $currdefquota = $settings->{$type};
1557: }
1.78 raeburn 1558: }
1.72 raeburn 1559: }
1.3 raeburn 1560: if (defined($usertypes->{$type})) {
1561: $typecount ++;
1562: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1563: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1564: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1565: '<td class="LC_left_item">';
1.101 raeburn 1566: if ($context eq 'requestcourses') {
1567: $datatable .= '<table><tr>';
1568: }
1569: my %cell;
1.72 raeburn 1570: foreach my $item (@usertools) {
1.101 raeburn 1571: if ($context eq 'requestcourses') {
1572: my ($curroption,$currlimit);
1573: if (ref($settings) eq 'HASH') {
1574: if (ref($settings->{$item}) eq 'HASH') {
1575: $curroption = $settings->{$item}->{$type};
1576: if ($curroption =~ /^autolimit=(\d*)$/) {
1577: $currlimit = $1;
1578: }
1579: }
1580: }
1581: if (!$curroption) {
1582: $curroption = 'norequest';
1583: }
1584: $datatable .= '<th>'.$titles{$item}.'</th>';
1585: foreach my $option (@options) {
1586: my $val = $option;
1587: if ($option eq 'norequest') {
1588: $val = 0;
1589: }
1590: if ($option eq 'validate') {
1591: my $canvalidate = 0;
1592: if (ref($validations{$item}) eq 'HASH') {
1593: if ($validations{$item}{$type}) {
1594: $canvalidate = 1;
1595: }
1596: }
1597: next if (!$canvalidate);
1598: }
1599: my $checked = '';
1600: if ($option eq $curroption) {
1601: $checked = ' checked="checked"';
1602: } elsif ($option eq 'autolimit') {
1603: if ($curroption =~ /^autolimit/) {
1604: $checked = ' checked="checked"';
1605: }
1606: }
1607: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1608: '<input type="radio" name="crsreq_'.$item.
1609: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1610: $titles{$option}.'</label>';
1.101 raeburn 1611: if ($option eq 'autolimit') {
1.127 raeburn 1612: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1613: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1614: 'value="'.$currlimit.'" />';
1.101 raeburn 1615: }
1.127 raeburn 1616: $cell{$item} .= '</span> ';
1.103 raeburn 1617: if ($option eq 'autolimit') {
1.127 raeburn 1618: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1619: }
1.101 raeburn 1620: }
1.163 raeburn 1621: } elsif ($context eq 'requestauthor') {
1622: my $curroption;
1623: if (ref($settings) eq 'HASH') {
1624: $curroption = $settings->{$type};
1625: }
1626: if (!$curroption) {
1627: $curroption = 'norequest';
1628: }
1629: foreach my $option (@options) {
1630: my $val = $option;
1631: if ($option eq 'norequest') {
1632: $val = 0;
1633: }
1634: my $checked = '';
1635: if ($option eq $curroption) {
1636: $checked = ' checked="checked"';
1637: }
1638: $datatable .= '<span class="LC_nobreak"><label>'.
1639: '<input type="radio" name="authorreq_'.$type.
1640: '" value="'.$val.'"'.$checked.' />'.
1641: $titles{$option}.'</label></span> ';
1642: }
1.101 raeburn 1643: } else {
1644: my $checked = 'checked="checked" ';
1645: if (ref($settings) eq 'HASH') {
1646: if (ref($settings->{$item}) eq 'HASH') {
1647: if ($settings->{$item}->{$type} == 0) {
1648: $checked = '';
1649: } elsif ($settings->{$item}->{$type} == 1) {
1650: $checked = 'checked="checked" ';
1651: }
1.78 raeburn 1652: }
1.72 raeburn 1653: }
1.101 raeburn 1654: $datatable .= '<span class="LC_nobreak"><label>'.
1655: '<input type="checkbox" name="'.$context.'_'.$item.
1656: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1657: '</label></span> ';
1.72 raeburn 1658: }
1.101 raeburn 1659: }
1660: if ($context eq 'requestcourses') {
1661: $datatable .= '</tr><tr>';
1662: foreach my $item (@usertools) {
1.106 raeburn 1663: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1664: }
1665: $datatable .= '</tr></table>';
1.72 raeburn 1666: }
1.86 raeburn 1667: $datatable .= '</td>';
1.163 raeburn 1668: unless (($context eq 'requestcourses') ||
1669: ($context eq 'requestauthor')) {
1.86 raeburn 1670: $datatable .=
1671: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1672: '<input type="text" name="quota_'.$type.
1.72 raeburn 1673: '" value="'.$currdefquota.
1.86 raeburn 1674: '" size="5" /> Mb</span></td>';
1675: }
1676: $datatable .= '</tr>';
1.3 raeburn 1677: }
1678: }
1679: }
1.163 raeburn 1680: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1681: $defaultquota = '20';
1682: if (ref($settings) eq 'HASH') {
1683: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1684: $defaultquota = $settings->{'defaultquota'}->{'default'};
1685: } elsif (defined($settings->{'default'})) {
1686: $defaultquota = $settings->{'default'};
1687: }
1.3 raeburn 1688: }
1689: }
1690: $typecount ++;
1691: $css_class = $typecount%2?' class="LC_odd_row"':'';
1692: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1693: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1694: '<td class="LC_left_item">';
1.101 raeburn 1695: if ($context eq 'requestcourses') {
1696: $datatable .= '<table><tr>';
1697: }
1698: my %defcell;
1.72 raeburn 1699: foreach my $item (@usertools) {
1.101 raeburn 1700: if ($context eq 'requestcourses') {
1701: my ($curroption,$currlimit);
1702: if (ref($settings) eq 'HASH') {
1703: if (ref($settings->{$item}) eq 'HASH') {
1704: $curroption = $settings->{$item}->{'default'};
1705: if ($curroption =~ /^autolimit=(\d*)$/) {
1706: $currlimit = $1;
1707: }
1708: }
1709: }
1710: if (!$curroption) {
1711: $curroption = 'norequest';
1712: }
1713: $datatable .= '<th>'.$titles{$item}.'</th>';
1714: foreach my $option (@options) {
1715: my $val = $option;
1716: if ($option eq 'norequest') {
1717: $val = 0;
1718: }
1719: if ($option eq 'validate') {
1720: my $canvalidate = 0;
1721: if (ref($validations{$item}) eq 'HASH') {
1722: if ($validations{$item}{'default'}) {
1723: $canvalidate = 1;
1724: }
1725: }
1726: next if (!$canvalidate);
1727: }
1728: my $checked = '';
1729: if ($option eq $curroption) {
1730: $checked = ' checked="checked"';
1731: } elsif ($option eq 'autolimit') {
1732: if ($curroption =~ /^autolimit/) {
1733: $checked = ' checked="checked"';
1734: }
1735: }
1736: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1737: '<input type="radio" name="crsreq_'.$item.
1738: '_default" value="'.$val.'"'.$checked.' />'.
1739: $titles{$option}.'</label>';
1740: if ($option eq 'autolimit') {
1.127 raeburn 1741: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1742: $item.'_limit_default" size="1" '.
1743: 'value="'.$currlimit.'" />';
1744: }
1.127 raeburn 1745: $defcell{$item} .= '</span> ';
1.104 raeburn 1746: if ($option eq 'autolimit') {
1.127 raeburn 1747: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1748: }
1.101 raeburn 1749: }
1.163 raeburn 1750: } elsif ($context eq 'requestauthor') {
1751: my $curroption;
1752: if (ref($settings) eq 'HASH') {
1.172 raeburn 1753: $curroption = $settings->{'default'};
1.163 raeburn 1754: }
1755: if (!$curroption) {
1756: $curroption = 'norequest';
1757: }
1758: foreach my $option (@options) {
1759: my $val = $option;
1760: if ($option eq 'norequest') {
1761: $val = 0;
1762: }
1763: my $checked = '';
1764: if ($option eq $curroption) {
1765: $checked = ' checked="checked"';
1766: }
1767: $datatable .= '<span class="LC_nobreak"><label>'.
1768: '<input type="radio" name="authorreq_default"'.
1769: ' value="'.$val.'"'.$checked.' />'.
1770: $titles{$option}.'</label></span> ';
1771: }
1.101 raeburn 1772: } else {
1773: my $checked = 'checked="checked" ';
1774: if (ref($settings) eq 'HASH') {
1775: if (ref($settings->{$item}) eq 'HASH') {
1776: if ($settings->{$item}->{'default'} == 0) {
1777: $checked = '';
1778: } elsif ($settings->{$item}->{'default'} == 1) {
1779: $checked = 'checked="checked" ';
1780: }
1.78 raeburn 1781: }
1.72 raeburn 1782: }
1.101 raeburn 1783: $datatable .= '<span class="LC_nobreak"><label>'.
1784: '<input type="checkbox" name="'.$context.'_'.$item.
1785: '" value="default" '.$checked.'/>'.$titles{$item}.
1786: '</label></span> ';
1787: }
1788: }
1789: if ($context eq 'requestcourses') {
1790: $datatable .= '</tr><tr>';
1791: foreach my $item (@usertools) {
1.106 raeburn 1792: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1793: }
1.101 raeburn 1794: $datatable .= '</tr></table>';
1.72 raeburn 1795: }
1.86 raeburn 1796: $datatable .= '</td>';
1.163 raeburn 1797: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1798: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1799: '<input type="text" name="defaultquota" value="'.
1800: $defaultquota.'" size="5" /> Mb</span></td>';
1801: }
1802: $datatable .= '</tr>';
1.72 raeburn 1803: $typecount ++;
1804: $css_class = $typecount%2?' class="LC_odd_row"':'';
1805: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1806: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1807: if ($context eq 'requestcourses') {
1.109 raeburn 1808: $datatable .= &mt('(overrides affiliation, if set)').
1809: '</td>'.
1810: '<td class="LC_left_item">'.
1811: '<table><tr>';
1.101 raeburn 1812: } else {
1.109 raeburn 1813: $datatable .= &mt('(overrides affiliation, if checked)').
1814: '</td>'.
1815: '<td class="LC_left_item" colspan="2">'.
1816: '<br />';
1.101 raeburn 1817: }
1818: my %advcell;
1.72 raeburn 1819: foreach my $item (@usertools) {
1.101 raeburn 1820: if ($context eq 'requestcourses') {
1821: my ($curroption,$currlimit);
1822: if (ref($settings) eq 'HASH') {
1823: if (ref($settings->{$item}) eq 'HASH') {
1824: $curroption = $settings->{$item}->{'_LC_adv'};
1825: if ($curroption =~ /^autolimit=(\d*)$/) {
1826: $currlimit = $1;
1827: }
1828: }
1829: }
1830: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1831: my $checked = '';
1832: if ($curroption eq '') {
1833: $checked = ' checked="checked"';
1834: }
1835: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1836: '<input type="radio" name="crsreq_'.$item.
1837: '__LC_adv" value=""'.$checked.' />'.
1838: &mt('No override set').'</label></span> ';
1.101 raeburn 1839: foreach my $option (@options) {
1840: my $val = $option;
1841: if ($option eq 'norequest') {
1842: $val = 0;
1843: }
1844: if ($option eq 'validate') {
1845: my $canvalidate = 0;
1846: if (ref($validations{$item}) eq 'HASH') {
1847: if ($validations{$item}{'_LC_adv'}) {
1848: $canvalidate = 1;
1849: }
1850: }
1851: next if (!$canvalidate);
1852: }
1853: my $checked = '';
1.104 raeburn 1854: if ($val eq $curroption) {
1.101 raeburn 1855: $checked = ' checked="checked"';
1856: } elsif ($option eq 'autolimit') {
1857: if ($curroption =~ /^autolimit/) {
1858: $checked = ' checked="checked"';
1859: }
1860: }
1861: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1862: '<input type="radio" name="crsreq_'.$item.
1863: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1864: $titles{$option}.'</label>';
1865: if ($option eq 'autolimit') {
1.127 raeburn 1866: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1867: $item.'_limit__LC_adv" size="1" '.
1868: 'value="'.$currlimit.'" />';
1869: }
1.127 raeburn 1870: $advcell{$item} .= '</span> ';
1.104 raeburn 1871: if ($option eq 'autolimit') {
1.127 raeburn 1872: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1873: }
1.101 raeburn 1874: }
1.163 raeburn 1875: } elsif ($context eq 'requestauthor') {
1876: my $curroption;
1877: if (ref($settings) eq 'HASH') {
1878: $curroption = $settings->{'_LC_adv'};
1879: }
1880: my $checked = '';
1881: if ($curroption eq '') {
1882: $checked = ' checked="checked"';
1883: }
1884: $datatable .= '<span class="LC_nobreak"><label>'.
1885: '<input type="radio" name="authorreq__LC_adv"'.
1886: ' value=""'.$checked.' />'.
1887: &mt('No override set').'</label></span> ';
1888: foreach my $option (@options) {
1889: my $val = $option;
1890: if ($option eq 'norequest') {
1891: $val = 0;
1892: }
1893: my $checked = '';
1894: if ($val eq $curroption) {
1895: $checked = ' checked="checked"';
1896: }
1897: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1898: '<input type="radio" name="authorreq__LC_adv"'.
1899: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1900: $titles{$option}.'</label></span> ';
1901: }
1.101 raeburn 1902: } else {
1903: my $checked = 'checked="checked" ';
1904: if (ref($settings) eq 'HASH') {
1905: if (ref($settings->{$item}) eq 'HASH') {
1906: if ($settings->{$item}->{'_LC_adv'} == 0) {
1907: $checked = '';
1908: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1909: $checked = 'checked="checked" ';
1910: }
1.79 raeburn 1911: }
1.72 raeburn 1912: }
1.101 raeburn 1913: $datatable .= '<span class="LC_nobreak"><label>'.
1914: '<input type="checkbox" name="'.$context.'_'.$item.
1915: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1916: '</label></span> ';
1917: }
1918: }
1919: if ($context eq 'requestcourses') {
1920: $datatable .= '</tr><tr>';
1921: foreach my $item (@usertools) {
1.106 raeburn 1922: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1923: }
1.101 raeburn 1924: $datatable .= '</tr></table>';
1.72 raeburn 1925: }
1.98 raeburn 1926: $datatable .= '</td></tr>';
1.30 raeburn 1927: $$rowtotal += $typecount;
1.3 raeburn 1928: return $datatable;
1929: }
1930:
1.163 raeburn 1931: sub print_requestmail {
1932: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1933: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1934: $now = time;
1935: $rows = 0;
1936: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1937: foreach my $server (keys(%dompersonnel)) {
1938: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1939: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1940: if (!grep(/^$uname:$udom$/,@domcoord)) {
1941: push(@domcoord,$uname.':'.$udom);
1942: }
1943: }
1944: }
1945: if (ref($settings) eq 'HASH') {
1946: if (ref($settings->{'notify'}) eq 'HASH') {
1947: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1948: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1949: }
1950: }
1951: }
1.104 raeburn 1952: if (@currapproval) {
1953: foreach my $dc (@currapproval) {
1.102 raeburn 1954: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1955: push(@domcoord,$dc);
1956: }
1957: }
1958: }
1959: @domcoord = sort(@domcoord);
1960: my $numinrow = 4;
1961: my $numdc = @domcoord;
1962: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1963: my $text;
1964: if ($action eq 'requestcourses') {
1965: $text = &mt('Receive notification of course requests requiring approval');
1966: } else {
1967: $text = &mt('Receive notification of authoring space requests requiring approval')
1968: }
1969: $datatable = '<tr '.$css_class.'>'.
1970: ' <td>'.$text.'</td>'.
1.102 raeburn 1971: ' <td class="LC_left_item">';
1972: if (@domcoord > 0) {
1973: $datatable .= '<table>';
1974: for (my $i=0; $i<$numdc; $i++) {
1975: my $rem = $i%($numinrow);
1976: if ($rem == 0) {
1977: if ($i > 0) {
1978: $datatable .= '</tr>';
1979: }
1980: $datatable .= '<tr>';
1981: $rows ++;
1982: }
1983: my $check = ' ';
1.104 raeburn 1984: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1985: $check = ' checked="checked" ';
1986: }
1987: my ($uname,$udom) = split(':',$domcoord[$i]);
1988: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1989: if ($i == $numdc-1) {
1990: my $colsleft = $numinrow-$rem;
1991: if ($colsleft > 1) {
1992: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1993: } else {
1994: $datatable .= '<td class="LC_left_item">';
1995: }
1996: } else {
1997: $datatable .= '<td class="LC_left_item">';
1998: }
1999: $datatable .= '<span class="LC_nobreak"><label>'.
2000: '<input type="checkbox" name="reqapprovalnotify" '.
2001: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 bisitz 2002: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 2003: }
2004: $datatable .= '</tr></table>';
2005: } else {
2006: $datatable .= &mt('There are no active Domain Coordinators');
2007: $rows ++;
2008: }
2009: $datatable .='</td></tr>';
2010: $$rowtotal += $rows;
2011: return $datatable;
2012: }
2013:
1.3 raeburn 2014: sub print_autoenroll {
1.30 raeburn 2015: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2016: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2017: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2018: if (ref($settings) eq 'HASH') {
2019: if (exists($settings->{'run'})) {
2020: if ($settings->{'run'} eq '0') {
2021: $runoff = ' checked="checked" ';
2022: $runon = ' ';
2023: } else {
2024: $runon = ' checked="checked" ';
2025: $runoff = ' ';
2026: }
2027: } else {
2028: if ($autorun) {
2029: $runon = ' checked="checked" ';
2030: $runoff = ' ';
2031: } else {
2032: $runoff = ' checked="checked" ';
2033: $runon = ' ';
2034: }
2035: }
1.129 raeburn 2036: if (exists($settings->{'co-owners'})) {
2037: if ($settings->{'co-owners'} eq '0') {
2038: $coownersoff = ' checked="checked" ';
2039: $coownerson = ' ';
2040: } else {
2041: $coownerson = ' checked="checked" ';
2042: $coownersoff = ' ';
2043: }
2044: } else {
2045: $coownersoff = ' checked="checked" ';
2046: $coownerson = ' ';
2047: }
1.3 raeburn 2048: if (exists($settings->{'sender_domain'})) {
2049: $defdom = $settings->{'sender_domain'};
2050: }
1.14 raeburn 2051: } else {
2052: if ($autorun) {
2053: $runon = ' checked="checked" ';
2054: $runoff = ' ';
2055: } else {
2056: $runoff = ' checked="checked" ';
2057: $runon = ' ';
2058: }
1.3 raeburn 2059: }
2060: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2061: my $notif_sender;
2062: if (ref($settings) eq 'HASH') {
2063: $notif_sender = $settings->{'sender_uname'};
2064: }
1.3 raeburn 2065: my $datatable='<tr class="LC_odd_row">'.
2066: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2067: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2068: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2069: $runon.' value="1" />'.&mt('Yes').'</label> '.
2070: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2071: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2072: '</tr><tr>'.
2073: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2074: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2075: &mt('username').': '.
2076: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2077: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2078: ': '.$domform.'</span></td></tr>'.
2079: '<tr class="LC_odd_row">'.
2080: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2081: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2082: '<input type="radio" name="autoassign_coowners"'.
2083: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2084: '<label><input type="radio" name="autoassign_coowners"'.
2085: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2086: '</tr>';
2087: $$rowtotal += 3;
1.3 raeburn 2088: return $datatable;
2089: }
2090:
2091: sub print_autoupdate {
1.30 raeburn 2092: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2093: my $datatable;
2094: if ($position eq 'top') {
2095: my $updateon = ' ';
2096: my $updateoff = ' checked="checked" ';
2097: my $classlistson = ' ';
2098: my $classlistsoff = ' checked="checked" ';
2099: if (ref($settings) eq 'HASH') {
2100: if ($settings->{'run'} eq '1') {
2101: $updateon = $updateoff;
2102: $updateoff = ' ';
2103: }
2104: if ($settings->{'classlists'} eq '1') {
2105: $classlistson = $classlistsoff;
2106: $classlistsoff = ' ';
2107: }
2108: }
2109: my %title = (
2110: run => 'Auto-update active?',
2111: classlists => 'Update information in classlists?',
2112: );
2113: $datatable = '<tr class="LC_odd_row">'.
2114: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2115: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2116: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2117: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2118: '<label><input type="radio" name="autoupdate_run"'.
2119: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2120: '</tr><tr>'.
2121: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2122: '<td class="LC_right_item"><span class="LC_nobreak">'.
2123: '<label><input type="radio" name="classlists"'.
2124: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2125: '<label><input type="radio" name="classlists"'.
2126: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2127: '</tr>';
1.30 raeburn 2128: $$rowtotal += 2;
1.131 raeburn 2129: } elsif ($position eq 'middle') {
2130: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2131: my $numinrow = 3;
2132: my $locknamesettings;
2133: $datatable .= &insttypes_row($settings,$types,$usertypes,
2134: $dom,$numinrow,$othertitle,
2135: 'lockablenames');
2136: $$rowtotal ++;
1.3 raeburn 2137: } else {
1.44 raeburn 2138: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2139: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2140: 'permanentemail','id');
1.33 raeburn 2141: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2142: my $numrows = 0;
1.26 raeburn 2143: if (ref($types) eq 'ARRAY') {
2144: if (@{$types} > 0) {
2145: $datatable =
2146: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2147: \@fields,$types,\$numrows);
1.30 raeburn 2148: $$rowtotal += @{$types};
1.26 raeburn 2149: }
1.3 raeburn 2150: }
2151: $datatable .=
2152: &usertype_update_row($settings,{'default' => $othertitle},
2153: \%fieldtitles,\@fields,['default'],
2154: \$numrows);
1.30 raeburn 2155: $$rowtotal ++;
1.3 raeburn 2156: }
2157: return $datatable;
2158: }
2159:
1.125 raeburn 2160: sub print_autocreate {
2161: my ($dom,$settings,$rowtotal) = @_;
2162: my (%createon,%createoff);
2163: my $curr_dc;
2164: my @types = ('xml','req');
2165: if (ref($settings) eq 'HASH') {
2166: foreach my $item (@types) {
2167: $createoff{$item} = ' checked="checked" ';
2168: $createon{$item} = ' ';
2169: if (exists($settings->{$item})) {
2170: if ($settings->{$item}) {
2171: $createon{$item} = ' checked="checked" ';
2172: $createoff{$item} = ' ';
2173: }
2174: }
2175: }
2176: $curr_dc = $settings->{'xmldc'};
2177: } else {
2178: foreach my $item (@types) {
2179: $createoff{$item} = ' checked="checked" ';
2180: $createon{$item} = ' ';
2181: }
2182: }
2183: $$rowtotal += 2;
2184: my $datatable='<tr class="LC_odd_row">'.
2185: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2186: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2187: '<input type="radio" name="autocreate_xml"'.
2188: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2189: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2190: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2191: '</td></tr><tr>'.
2192: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2193: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2194: '<input type="radio" name="autocreate_req"'.
2195: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2196: '<label><input type="radio" name="autocreate_req"'.
2197: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2198: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2199: if ($numdc > 1) {
1.143 raeburn 2200: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2201: &mt('Course creation processed as: (choose Dom. Coord.)').
2202: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2203: $$rowtotal ++ ;
2204: } else {
1.143 raeburn 2205: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2206: }
2207: return $datatable;
2208: }
2209:
1.23 raeburn 2210: sub print_directorysrch {
1.30 raeburn 2211: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2212: my $srchon = ' ';
2213: my $srchoff = ' checked="checked" ';
1.25 raeburn 2214: my ($exacton,$containson,$beginson);
1.24 raeburn 2215: my $localon = ' ';
2216: my $localoff = ' checked="checked" ';
1.23 raeburn 2217: if (ref($settings) eq 'HASH') {
2218: if ($settings->{'available'} eq '1') {
2219: $srchon = $srchoff;
2220: $srchoff = ' ';
2221: }
1.24 raeburn 2222: if ($settings->{'localonly'} eq '1') {
2223: $localon = $localoff;
2224: $localoff = ' ';
2225: }
1.25 raeburn 2226: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2227: foreach my $type (@{$settings->{'searchtypes'}}) {
2228: if ($type eq 'exact') {
2229: $exacton = ' checked="checked" ';
2230: } elsif ($type eq 'contains') {
2231: $containson = ' checked="checked" ';
2232: } elsif ($type eq 'begins') {
2233: $beginson = ' checked="checked" ';
2234: }
2235: }
2236: } else {
2237: if ($settings->{'searchtypes'} eq 'exact') {
2238: $exacton = ' checked="checked" ';
2239: } elsif ($settings->{'searchtypes'} eq 'contains') {
2240: $containson = ' checked="checked" ';
2241: } elsif ($settings->{'searchtypes'} eq 'specify') {
2242: $exacton = ' checked="checked" ';
2243: $containson = ' checked="checked" ';
2244: }
1.23 raeburn 2245: }
2246: }
2247: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2249:
2250: my $numinrow = 4;
1.26 raeburn 2251: my $cansrchrow = 0;
1.23 raeburn 2252: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2253: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2254: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2255: '<input type="radio" name="dirsrch_available"'.
2256: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2257: '<label><input type="radio" name="dirsrch_available"'.
2258: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2259: '</tr><tr>'.
1.30 raeburn 2260: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2261: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2262: '<input type="radio" name="dirsrch_localonly"'.
2263: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2264: '<label><input type="radio" name="dirsrch_localonly"'.
2265: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2266: '</tr>';
1.30 raeburn 2267: $$rowtotal += 2;
1.26 raeburn 2268: if (ref($usertypes) eq 'HASH') {
2269: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2270: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2271: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2272: $cansrchrow = 1;
2273: }
2274: }
2275: if ($cansrchrow) {
1.30 raeburn 2276: $$rowtotal ++;
1.26 raeburn 2277: $datatable .= '<tr>';
2278: } else {
2279: $datatable .= '<tr class="LC_odd_row">';
2280: }
1.30 raeburn 2281: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2282: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2283: foreach my $title (@{$titleorder}) {
2284: if (defined($searchtitles->{$title})) {
2285: my $check = ' ';
1.93 raeburn 2286: if (ref($settings) eq 'HASH') {
1.39 raeburn 2287: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2288: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2289: $check = ' checked="checked" ';
2290: }
1.25 raeburn 2291: }
2292: }
2293: $datatable .= '<td class="LC_left_item">'.
2294: '<span class="LC_nobreak"><label>'.
2295: '<input type="checkbox" name="searchby" '.
2296: 'value="'.$title.'"'.$check.'/>'.
2297: $searchtitles->{$title}.'</label></span></td>';
2298: }
2299: }
1.26 raeburn 2300: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2301: $$rowtotal ++;
1.26 raeburn 2302: if ($cansrchrow) {
2303: $datatable .= '<tr class="LC_odd_row">';
2304: } else {
2305: $datatable .= '<tr>';
2306: }
1.30 raeburn 2307: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2308: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2309: '<span class="LC_nobreak"><label>'.
2310: '<input type="checkbox" name="searchtypes" '.
2311: $exacton.' value="exact" />'.&mt('Exact match').
2312: '</label> '.
2313: '<label><input type="checkbox" name="searchtypes" '.
2314: $beginson.' value="begins" />'.&mt('Begins with').
2315: '</label> '.
2316: '<label><input type="checkbox" name="searchtypes" '.
2317: $containson.' value="contains" />'.&mt('Contains').
2318: '</label></span></td></tr>';
1.30 raeburn 2319: $$rowtotal ++;
1.25 raeburn 2320: return $datatable;
2321: }
2322:
1.28 raeburn 2323: sub print_contacts {
1.30 raeburn 2324: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2325: my $datatable;
2326: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2327: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2328: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2329: 'requestsmail');
1.28 raeburn 2330: foreach my $type (@mailings) {
2331: $otheremails{$type} = '';
2332: }
1.134 raeburn 2333: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2334: if (ref($settings) eq 'HASH') {
2335: foreach my $item (@contacts) {
2336: if (exists($settings->{$item})) {
2337: $to{$item} = $settings->{$item};
2338: }
2339: }
2340: foreach my $type (@mailings) {
2341: if (exists($settings->{$type})) {
2342: if (ref($settings->{$type}) eq 'HASH') {
2343: foreach my $item (@contacts) {
2344: if ($settings->{$type}{$item}) {
2345: $checked{$type}{$item} = ' checked="checked" ';
2346: }
2347: }
2348: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2349: if ($type eq 'helpdeskmail') {
2350: $bccemails{$type} = $settings->{$type}{'bcc'};
2351: }
1.28 raeburn 2352: }
1.89 raeburn 2353: } elsif ($type eq 'lonstatusmail') {
2354: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2355: }
2356: }
2357: } else {
2358: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2359: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2360: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2361: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2362: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2363: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2364: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2365: }
2366: my ($titles,$short_titles) = &contact_titles();
2367: my $rownum = 0;
2368: my $css_class;
2369: foreach my $item (@contacts) {
1.69 raeburn 2370: $rownum ++;
2371: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2372: $datatable .= '<tr'.$css_class.'>'.
2373: '<td><span class="LC_nobreak">'.$titles->{$item}.
2374: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2375: '<input type="text" name="'.$item.'" value="'.
2376: $to{$item}.'" /></td></tr>';
2377: }
2378: foreach my $type (@mailings) {
1.69 raeburn 2379: $rownum ++;
2380: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2381: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2382: '<td><span class="LC_nobreak">'.
2383: $titles->{$type}.': </span></td>'.
1.28 raeburn 2384: '<td class="LC_left_item">'.
2385: '<span class="LC_nobreak">';
2386: foreach my $item (@contacts) {
2387: $datatable .= '<label>'.
2388: '<input type="checkbox" name="'.$type.'"'.
2389: $checked{$type}{$item}.
2390: ' value="'.$item.'" />'.$short_titles->{$item}.
2391: '</label> ';
2392: }
2393: $datatable .= '</span><br />'.&mt('Others').': '.
2394: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2395: 'value="'.$otheremails{$type}.'" />';
2396: if ($type eq 'helpdeskmail') {
1.136 raeburn 2397: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2398: '<input type="text" name="'.$type.'_bcc" '.
2399: 'value="'.$bccemails{$type}.'" />';
2400: }
2401: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2402: }
1.30 raeburn 2403: $$rowtotal += $rownum;
1.28 raeburn 2404: return $datatable;
2405: }
2406:
1.118 jms 2407: sub print_helpsettings {
1.168 raeburn 2408: my ($dom,$confname,$settings,$rowtotal) = @_;
2409: my ($datatable,$itemcount);
1.166 raeburn 2410: $itemcount = 1;
1.168 raeburn 2411: my (%choices,%defaultchecked,@toggles);
2412: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2413: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2414: &mt('LON-CAPA bug tracker'),600,500));
2415: %defaultchecked = ('submitbugs' => 'on');
2416: @toggles = ('submitbugs',);
1.166 raeburn 2417:
1.168 raeburn 2418: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2419: \%choices,$itemcount);
1.166 raeburn 2420: return $datatable;
1.121 raeburn 2421: }
2422:
2423: sub radiobutton_prefs {
2424: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2425: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2426: (ref($choices) eq 'HASH'));
2427:
1.170 raeburn 2428: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2429:
2430: foreach my $item (@{$toggles}) {
2431: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2432: $checkedon{$item} = ' checked="checked" ';
2433: $checkedoff{$item} = ' ';
1.121 raeburn 2434: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2435: $checkedoff{$item} = ' checked="checked" ';
2436: $checkedon{$item} = ' ';
2437: }
2438: }
2439: if (ref($settings) eq 'HASH') {
1.121 raeburn 2440: foreach my $item (@{$toggles}) {
1.118 jms 2441: if ($settings->{$item} eq '1') {
2442: $checkedon{$item} = ' checked="checked" ';
2443: $checkedoff{$item} = ' ';
2444: } elsif ($settings->{$item} eq '0') {
2445: $checkedoff{$item} = ' checked="checked" ';
2446: $checkedon{$item} = ' ';
2447: }
2448: }
1.121 raeburn 2449: }
2450: foreach my $item (@{$toggles}) {
1.118 jms 2451: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2452: $datatable .=
2453: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2454: '</span></td>'.
2455: '<td class="LC_right_item"><span class="LC_nobreak">'.
2456: '<label><input type="radio" name="'.
2457: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2458: '</label> <label><input type="radio" name="'.$item.'" '.
2459: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2460: '</span></td>'.
2461: '</tr>';
2462: $itemcount ++;
1.121 raeburn 2463: }
2464: return ($datatable,$itemcount);
2465: }
2466:
2467: sub print_coursedefaults {
1.139 raeburn 2468: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2469: my ($css_class,$datatable);
2470: my $itemcount = 1;
1.139 raeburn 2471: if ($position eq 'top') {
2472: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2473: %choices =
2474: &Apache::lonlocal::texthash (
2475: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2476: );
2477: %defaultchecked = ('canuse_pdfforms' => 'off');
2478: @toggles = ('canuse_pdfforms',);
2479: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2480: \%choices,$itemcount);
1.139 raeburn 2481: $$rowtotal += $itemcount;
2482: } else {
2483: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2484: my %choices =
2485: &Apache::lonlocal::texthash (
2486: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2487: );
2488: my $currdefresponder;
2489: if (ref($settings) eq 'HASH') {
2490: $currdefresponder = $settings->{'anonsurvey_threshold'};
2491: }
2492: if (!$currdefresponder) {
2493: $currdefresponder = 10;
2494: } elsif ($currdefresponder < 1) {
2495: $currdefresponder = 1;
2496: }
2497: $datatable .=
2498: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2499: '</span></td>'.
2500: '<td class="LC_right_item"><span class="LC_nobreak">'.
2501: '<input type="text" name="anonsurvey_threshold"'.
2502: ' value="'.$currdefresponder.'" size="5" /></span>'.
2503: '</td></tr>';
2504: }
1.121 raeburn 2505: return $datatable;
1.118 jms 2506: }
2507:
1.137 raeburn 2508: sub print_usersessions {
2509: my ($position,$dom,$settings,$rowtotal) = @_;
2510: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2511: my (%by_ip,%by_location,@intdoms);
2512: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2513:
2514: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2515: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2516: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2517: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2518: my $itemcount = 1;
2519: if ($position eq 'top') {
1.152 raeburn 2520: if (keys(%serverhomes) > 1) {
1.145 raeburn 2521: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2522: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2523: } else {
1.140 raeburn 2524: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2525: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2526: }
1.137 raeburn 2527: } else {
1.145 raeburn 2528: if (keys(%by_location) == 0) {
2529: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2530: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2531: } else {
2532: my %lt = &usersession_titles();
2533: my $numinrow = 5;
2534: my $prefix;
2535: my @types;
2536: if ($position eq 'bottom') {
2537: $prefix = 'remote';
2538: @types = ('version','excludedomain','includedomain');
2539: } else {
2540: $prefix = 'hosted';
2541: @types = ('excludedomain','includedomain');
2542: }
2543: my (%current,%checkedon,%checkedoff);
2544: my @lcversions = &Apache::lonnet::all_loncaparevs();
2545: my @locations = sort(keys(%by_location));
2546: foreach my $type (@types) {
2547: $checkedon{$type} = '';
2548: $checkedoff{$type} = ' checked="checked"';
2549: }
2550: if (ref($settings) eq 'HASH') {
2551: if (ref($settings->{$prefix}) eq 'HASH') {
2552: foreach my $key (keys(%{$settings->{$prefix}})) {
2553: $current{$key} = $settings->{$prefix}{$key};
2554: if ($key eq 'version') {
2555: if ($current{$key} ne '') {
2556: $checkedon{$key} = ' checked="checked"';
2557: $checkedoff{$key} = '';
2558: }
2559: } elsif (ref($current{$key}) eq 'ARRAY') {
2560: $checkedon{$key} = ' checked="checked"';
2561: $checkedoff{$key} = '';
2562: }
1.137 raeburn 2563: }
2564: }
2565: }
1.145 raeburn 2566: foreach my $type (@types) {
2567: next if ($type ne 'version' && !@locations);
2568: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2569: $datatable .= '<tr'.$css_class.'>
2570: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2571: <span class="LC_nobreak">
2572: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2573: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2574: if ($type eq 'version') {
2575: my $selector = '<select name="'.$prefix.'_version">';
2576: foreach my $version (@lcversions) {
2577: my $selected = '';
2578: if ($current{'version'} eq $version) {
2579: $selected = ' selected="selected"';
2580: }
2581: $selector .= ' <option value="'.$version.'"'.
2582: $selected.'>'.$version.'</option>';
2583: }
2584: $selector .= '</select> ';
2585: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2586: } else {
2587: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2588: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2589: ' />'.(' 'x2).
2590: '<input type="button" value="'.&mt('uncheck all').'" '.
2591: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2592: "\n".
2593: '</div><div><table>';
2594: my $rem;
2595: for (my $i=0; $i<@locations; $i++) {
2596: my ($showloc,$value,$checkedtype);
2597: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2598: my $ip = $by_location{$locations[$i]}->[0];
2599: if (ref($by_ip{$ip}) eq 'ARRAY') {
2600: $value = join(':',@{$by_ip{$ip}});
2601: $showloc = join(', ',@{$by_ip{$ip}});
2602: if (ref($current{$type}) eq 'ARRAY') {
2603: foreach my $loc (@{$by_ip{$ip}}) {
2604: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2605: $checkedtype = ' checked="checked"';
2606: last;
2607: }
2608: }
1.138 raeburn 2609: }
2610: }
2611: }
1.145 raeburn 2612: $rem = $i%($numinrow);
2613: if ($rem == 0) {
2614: if ($i > 0) {
2615: $datatable .= '</tr>';
2616: }
2617: $datatable .= '<tr>';
2618: }
2619: $datatable .= '<td class="LC_left_item">'.
2620: '<span class="LC_nobreak"><label>'.
2621: '<input type="checkbox" name="'.$prefix.'_'.$type.
2622: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2623: '</label></span></td>';
1.137 raeburn 2624: }
1.145 raeburn 2625: $rem = @locations%($numinrow);
2626: my $colsleft = $numinrow - $rem;
2627: if ($colsleft > 1 ) {
2628: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2629: ' </td>';
2630: } elsif ($colsleft == 1) {
2631: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2632: }
1.145 raeburn 2633: $datatable .= '</tr></table>';
1.137 raeburn 2634: }
1.145 raeburn 2635: $datatable .= '</td></tr>';
2636: $itemcount ++;
1.137 raeburn 2637: }
2638: }
2639: }
2640: $$rowtotal += $itemcount;
2641: return $datatable;
2642: }
2643:
1.138 raeburn 2644: sub build_location_hashes {
2645: my ($intdoms,$by_ip,$by_location) = @_;
2646: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2647: (ref($by_location) eq 'HASH'));
2648: my %iphost = &Apache::lonnet::get_iphost();
2649: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2650: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2651: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2652: foreach my $id (@{$iphost{$primary_ip}}) {
2653: my $intdom = &Apache::lonnet::internet_dom($id);
2654: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2655: push(@{$intdoms},$intdom);
2656: }
2657: }
2658: }
2659: foreach my $ip (keys(%iphost)) {
2660: if (ref($iphost{$ip}) eq 'ARRAY') {
2661: foreach my $id (@{$iphost{$ip}}) {
2662: my $location = &Apache::lonnet::internet_dom($id);
2663: if ($location) {
2664: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2665: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2666: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2667: push(@{$by_ip->{$ip}},$location);
2668: }
2669: } else {
2670: $by_ip->{$ip} = [$location];
2671: }
2672: }
2673: }
2674: }
2675: }
2676: foreach my $ip (sort(keys(%{$by_ip}))) {
2677: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2678: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2679: my $first = $by_ip->{$ip}->[0];
2680: if (ref($by_location->{$first}) eq 'ARRAY') {
2681: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2682: push(@{$by_location->{$first}},$ip);
2683: }
2684: } else {
2685: $by_location->{$first} = [$ip];
2686: }
2687: }
2688: }
2689: return;
2690: }
2691:
1.145 raeburn 2692: sub current_offloads_to {
2693: my ($dom,$settings,$servers) = @_;
2694: my (%spareid,%otherdomconfigs);
1.152 raeburn 2695: if (ref($servers) eq 'HASH') {
1.145 raeburn 2696: foreach my $lonhost (sort(keys(%{$servers}))) {
2697: my $gotspares;
1.152 raeburn 2698: if (ref($settings) eq 'HASH') {
2699: if (ref($settings->{'spares'}) eq 'HASH') {
2700: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2701: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2702: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2703: $gotspares = 1;
2704: }
1.145 raeburn 2705: }
2706: }
2707: unless ($gotspares) {
2708: my $gotspares;
2709: my $serverhomeID =
2710: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2711: my $serverhomedom =
2712: &Apache::lonnet::host_domain($serverhomeID);
2713: if ($serverhomedom ne $dom) {
2714: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2715: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2716: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2717: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2718: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2719: $gotspares = 1;
2720: }
2721: }
2722: } else {
2723: $otherdomconfigs{$serverhomedom} =
2724: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2725: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2726: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2727: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2728: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2729: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2730: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2731: $gotspares = 1;
2732: }
2733: }
2734: }
2735: }
2736: }
2737: }
2738: }
2739: unless ($gotspares) {
2740: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2741: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2742: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2743: } else {
2744: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2745: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2746: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2747: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2748: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2749: } else {
1.150 raeburn 2750: my %what = (
2751: spareid => 1,
2752: );
2753: my ($result,$returnhash) =
2754: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2755: if ($result eq 'ok') {
2756: if (ref($returnhash) eq 'HASH') {
2757: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2758: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2759: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2760: }
2761: }
1.145 raeburn 2762: }
2763: }
2764: }
2765: }
2766: }
2767: }
2768: return %spareid;
2769: }
2770:
2771: sub spares_row {
1.152 raeburn 2772: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2773: my $css_class;
2774: my $numinrow = 4;
2775: my $itemcount = 1;
2776: my $datatable;
1.152 raeburn 2777: my %typetitles = &sparestype_titles();
2778: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2779: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2780: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2781: my ($othercontrol,$serverdom);
2782: if ($serverhome ne $server) {
2783: $serverdom = &Apache::lonnet::host_domain($serverhome);
2784: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2785: } else {
2786: $serverdom = &Apache::lonnet::host_domain($server);
2787: if ($serverdom ne $dom) {
2788: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2789: }
2790: }
2791: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2792: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2793: $datatable .= '<tr'.$css_class.'>
2794: <td rowspan="2">
1.183 bisitz 2795: <span class="LC_nobreak">'.
2796: &mt('[_1] when busy, offloads to:'
2797: ,'<b>'.$server.'</b>').
2798: "\n";
1.145 raeburn 2799: my (%current,%canselect);
1.152 raeburn 2800: my @choices =
2801: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2802: foreach my $type ('primary','default') {
2803: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2804: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2805: my @spares = @{$spareid->{$server}{$type}};
2806: if (@spares > 0) {
1.152 raeburn 2807: if ($othercontrol) {
2808: $current{$type} = join(', ',@spares);
2809: } else {
2810: $current{$type} .= '<table>';
2811: my $numspares = scalar(@spares);
2812: for (my $i=0; $i<@spares; $i++) {
2813: my $rem = $i%($numinrow);
2814: if ($rem == 0) {
2815: if ($i > 0) {
2816: $current{$type} .= '</tr>';
2817: }
2818: $current{$type} .= '<tr>';
1.145 raeburn 2819: }
1.152 raeburn 2820: $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'".');" /> '.
2821: $spareid->{$server}{$type}[$i].
2822: '</label></td>'."\n";
2823: }
2824: my $rem = @spares%($numinrow);
2825: my $colsleft = $numinrow - $rem;
2826: if ($colsleft > 1 ) {
2827: $current{$type} .= '<td colspan="'.$colsleft.
2828: '" class="LC_left_item">'.
2829: ' </td>';
2830: } elsif ($colsleft == 1) {
2831: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2832: }
1.152 raeburn 2833: $current{$type} .= '</tr></table>';
1.150 raeburn 2834: }
1.145 raeburn 2835: }
2836: }
2837: if ($current{$type} eq '') {
2838: $current{$type} = &mt('None specified');
2839: }
1.152 raeburn 2840: if ($othercontrol) {
2841: if ($type eq 'primary') {
2842: $canselect{$type} = $othercontrol;
2843: }
2844: } else {
2845: $canselect{$type} =
2846: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2847: '<select name="newspare_'.$type.'_'.$server.'" '.
2848: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2849: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2850: if (@choices > 0) {
2851: foreach my $lonhost (@choices) {
2852: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2853: }
2854: }
2855: $canselect{$type} .= '</select>'."\n";
2856: }
2857: } else {
2858: $current{$type} = &mt('Could not be determined');
2859: if ($type eq 'primary') {
2860: $canselect{$type} = $othercontrol;
2861: }
1.145 raeburn 2862: }
1.152 raeburn 2863: if ($type eq 'default') {
2864: $datatable .= '<tr'.$css_class.'>';
2865: }
2866: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2867: '<td>'.$current{$type}.'</td>'."\n".
2868: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2869: }
2870: $itemcount ++;
2871: }
2872: }
2873: $$rowtotal += $itemcount;
2874: return $datatable;
2875: }
2876:
1.152 raeburn 2877: sub possible_newspares {
2878: my ($server,$currspares,$serverhomes,$altids) = @_;
2879: my $serverhostname = &Apache::lonnet::hostname($server);
2880: my %excluded;
2881: if ($serverhostname ne '') {
2882: %excluded = (
2883: $serverhostname => 1,
2884: );
2885: }
2886: if (ref($currspares) eq 'HASH') {
2887: foreach my $type (keys(%{$currspares})) {
2888: if (ref($currspares->{$type}) eq 'ARRAY') {
2889: if (@{$currspares->{$type}} > 0) {
2890: foreach my $curr (@{$currspares->{$type}}) {
2891: my $hostname = &Apache::lonnet::hostname($curr);
2892: $excluded{$hostname} = 1;
2893: }
2894: }
2895: }
2896: }
2897: }
2898: my @choices;
2899: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2900: if (keys(%{$serverhomes}) > 1) {
2901: foreach my $name (sort(keys(%{$serverhomes}))) {
2902: unless ($excluded{$name}) {
2903: if (exists($altids->{$serverhomes->{$name}})) {
2904: push(@choices,$altids->{$serverhomes->{$name}});
2905: } else {
2906: push(@choices,$serverhomes->{$name});
1.145 raeburn 2907: }
2908: }
2909: }
2910: }
2911: }
1.152 raeburn 2912: return sort(@choices);
1.145 raeburn 2913: }
2914:
1.150 raeburn 2915: sub print_loadbalancing {
2916: my ($dom,$settings,$rowtotal) = @_;
2917: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2918: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2919: my $numinrow = 1;
2920: my $datatable;
2921: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2922: my (%currbalancer,%currtargets,%currrules,%existing);
2923: if (ref($settings) eq 'HASH') {
2924: %existing = %{$settings};
2925: }
2926: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2927: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2928: \%currtargets,\%currrules);
1.150 raeburn 2929: } else {
2930: return;
2931: }
2932: my ($othertitle,$usertypes,$types) =
2933: &Apache::loncommon::sorted_inst_types($dom);
2934: my $rownum = 6;
2935: if (ref($types) eq 'ARRAY') {
2936: $rownum += scalar(@{$types});
2937: }
1.171 raeburn 2938: my @css_class = ('LC_odd_row','LC_even_row');
2939: my $balnum = 0;
2940: my $islast;
2941: my (@toshow,$disabledtext);
2942: if (keys(%currbalancer) > 0) {
2943: @toshow = sort(keys(%currbalancer));
2944: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2945: push(@toshow,'');
2946: }
2947: } else {
2948: @toshow = ('');
2949: $disabledtext = &mt('No existing load balancer');
2950: }
2951: foreach my $lonhost (@toshow) {
2952: if ($balnum == scalar(@toshow)-1) {
2953: $islast = 1;
2954: } else {
2955: $islast = 0;
2956: }
2957: my $cssidx = $balnum%2;
2958: my $targets_div_style = 'display: none';
2959: my $disabled_div_style = 'display: block';
2960: my $homedom_div_style = 'display: none';
2961: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2962: '<td rowspan="'.$rownum.'" valign="top">'.
2963: '<p>';
2964: if ($lonhost eq '') {
2965: $datatable .= '<span class="LC_nobreak">';
2966: if (keys(%currbalancer) > 0) {
2967: $datatable .= &mt('Add balancer:');
2968: } else {
2969: $datatable .= &mt('Enable balancer:');
2970: }
2971: $datatable .= ' '.
2972: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2973: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2974: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2975: '<option value="" selected="selected">'.&mt('None').
2976: '</option>'."\n";
2977: foreach my $server (sort(keys(%servers))) {
2978: next if ($currbalancer{$server});
2979: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2980: }
2981: $datatable .=
2982: '</select>'."\n".
2983: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2984: } else {
2985: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2986: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2987: &mt('Stop balancing').'</label>'.
2988: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2989: $targets_div_style = 'display: block';
2990: $disabled_div_style = 'display: none';
2991: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2992: $homedom_div_style = 'display: block';
2993: }
2994: }
2995: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2996: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2997: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2998: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2999: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3000: my @sparestypes = ('primary','default');
3001: my %typetitles = &sparestype_titles();
3002: foreach my $sparetype (@sparestypes) {
3003: my $targettable;
3004: for (my $i=0; $i<$numspares; $i++) {
3005: my $checked;
3006: if (ref($currtargets{$lonhost}) eq 'HASH') {
3007: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3008: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3009: $checked = ' checked="checked"';
3010: }
3011: }
3012: }
3013: my ($chkboxval,$disabled);
3014: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3015: $chkboxval = $spares[$i];
3016: }
3017: if (exists($currbalancer{$spares[$i]})) {
3018: $disabled = ' disabled="disabled"';
3019: }
3020: $targettable .=
3021: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3022: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3023: '</span></label></td>';
3024: my $rem = $i%($numinrow);
3025: if ($rem == 0) {
3026: if (($i > 0) && ($i < $numspares-1)) {
3027: $targettable .= '</tr>';
3028: }
3029: if ($i < $numspares-1) {
3030: $targettable .= '<tr>';
1.150 raeburn 3031: }
3032: }
3033: }
1.171 raeburn 3034: if ($targettable ne '') {
3035: my $rem = $numspares%($numinrow);
3036: my $colsleft = $numinrow - $rem;
3037: if ($colsleft > 1 ) {
3038: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3039: ' </td>';
3040: } elsif ($colsleft == 1) {
3041: $targettable .= '<td class="LC_left_item"> </td>';
3042: }
3043: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3044: '<table><tr>'.$targettable.'</tr></table><br />';
3045: }
3046: }
3047: $datatable .= '</div></td></tr>'.
3048: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3049: $othertitle,$usertypes,$types,\%servers,
3050: \%currbalancer,$lonhost,
3051: $targets_div_style,$homedom_div_style,
3052: $css_class[$cssidx],$balnum,$islast);
3053: $$rowtotal += $rownum;
3054: $balnum ++;
3055: }
3056: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3057: return $datatable;
3058: }
3059:
3060: sub get_loadbalancers_config {
3061: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3062: return unless ((ref($servers) eq 'HASH') &&
3063: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3064: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3065: if (keys(%{$existing}) > 0) {
3066: my $oldlonhost;
3067: foreach my $key (sort(keys(%{$existing}))) {
3068: if ($key eq 'lonhost') {
3069: $oldlonhost = $existing->{'lonhost'};
3070: $currbalancer->{$oldlonhost} = 1;
3071: } elsif ($key eq 'targets') {
3072: if ($oldlonhost) {
3073: $currtargets->{$oldlonhost} = $existing->{'targets'};
3074: }
3075: } elsif ($key eq 'rules') {
3076: if ($oldlonhost) {
3077: $currrules->{$oldlonhost} = $existing->{'rules'};
3078: }
3079: } elsif (ref($existing->{$key}) eq 'HASH') {
3080: $currbalancer->{$key} = 1;
3081: $currtargets->{$key} = $existing->{$key}{'targets'};
3082: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3083: }
3084: }
1.171 raeburn 3085: } else {
3086: my ($balancerref,$targetsref) =
3087: &Apache::lonnet::get_lonbalancer_config($servers);
3088: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3089: foreach my $server (sort(keys(%{$balancerref}))) {
3090: $currbalancer->{$server} = 1;
3091: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3092: }
3093: }
3094: }
1.171 raeburn 3095: return;
1.150 raeburn 3096: }
3097:
3098: sub loadbalancing_rules {
3099: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3100: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3101: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3102: my $output;
1.171 raeburn 3103: my $num = 0;
1.150 raeburn 3104: my ($alltypes,$othertypes,$titles) =
3105: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3106: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3107: foreach my $type (@{$alltypes}) {
1.171 raeburn 3108: $num ++;
1.150 raeburn 3109: my $current;
3110: if (ref($currrules) eq 'HASH') {
3111: $current = $currrules->{$type};
3112: }
3113: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3114: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3115: $current = '';
3116: }
3117: }
3118: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3119: $servers,$currbalancer,$lonhost,$dom,
3120: $targets_div_style,$homedom_div_style,
3121: $css_class,$balnum,$num,$islast);
1.150 raeburn 3122: }
3123: }
3124: return $output;
3125: }
3126:
3127: sub loadbalancing_titles {
3128: my ($dom,$intdom,$usertypes,$types) = @_;
3129: my %othertypes = (
3130: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3131: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3132: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3133: '_LC_external' => &mt('Users not from [_1]',$intdom),
3134: );
3135: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3136: if (ref($types) eq 'ARRAY') {
3137: unshift(@alltypes,@{$types},'default');
3138: }
3139: my %titles;
3140: foreach my $type (@alltypes) {
3141: if ($type =~ /^_LC_/) {
3142: $titles{$type} = $othertypes{$type};
3143: } elsif ($type eq 'default') {
3144: $titles{$type} = &mt('All users from [_1]',$dom);
3145: if (ref($types) eq 'ARRAY') {
3146: if (@{$types} > 0) {
3147: $titles{$type} = &mt('Other users from [_1]',$dom);
3148: }
3149: }
3150: } elsif (ref($usertypes) eq 'HASH') {
3151: $titles{$type} = $usertypes->{$type};
3152: }
3153: }
3154: return (\@alltypes,\%othertypes,\%titles);
3155: }
3156:
3157: sub loadbalance_rule_row {
1.171 raeburn 3158: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3159: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3160: my @rulenames = ('default','homeserver');
3161: my %ruletitles = &offloadtype_text();
3162: if ($type eq '_LC_external') {
3163: push(@rulenames,'externalbalancer');
3164: } else {
3165: push(@rulenames,'specific');
3166: }
1.161 raeburn 3167: push(@rulenames,'none');
1.150 raeburn 3168: my $style = $targets_div_style;
3169: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3170: $style = $homedom_div_style;
3171: }
1.171 raeburn 3172: my $space;
3173: if ($islast && $num == 1) {
3174: $space = '<div display="inline-block"> </div>';
3175: }
1.150 raeburn 3176: my $output =
1.171 raeburn 3177: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3178: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3179: '<td valaign="top">'.$space.
3180: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3181: for (my $i=0; $i<@rulenames; $i++) {
3182: my $rule = $rulenames[$i];
3183: my ($checked,$extra);
3184: if ($rulenames[$i] eq 'default') {
3185: $rule = '';
3186: }
3187: if ($rulenames[$i] eq 'specific') {
3188: if (ref($servers) eq 'HASH') {
3189: my $default;
3190: if (($current ne '') && (exists($servers->{$current}))) {
3191: $checked = ' checked="checked"';
3192: }
3193: unless ($checked) {
3194: $default = ' selected="selected"';
3195: }
1.171 raeburn 3196: $extra =
3197: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3198: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3199: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3200: '<option value=""'.$default.'></option>'."\n";
3201: foreach my $server (sort(keys(%{$servers}))) {
3202: if (ref($currbalancer) eq 'HASH') {
3203: next if (exists($currbalancer->{$server}));
3204: }
1.150 raeburn 3205: my $selected;
1.171 raeburn 3206: if ($server eq $current) {
1.150 raeburn 3207: $selected = ' selected="selected"';
3208: }
1.171 raeburn 3209: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3210: }
3211: $extra .= '</select>';
3212: }
3213: } elsif ($rule eq $current) {
3214: $checked = ' checked="checked"';
3215: }
3216: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3217: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3218: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3219: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3220: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3221: '</label>'.$extra.'</span><br />'."\n";
3222: }
3223: $output .= '</div></td></tr>'."\n";
3224: return $output;
3225: }
3226:
3227: sub offloadtype_text {
3228: my %ruletitles = &Apache::lonlocal::texthash (
3229: 'default' => 'Offloads to default destinations',
3230: 'homeserver' => "Offloads to user's home server",
3231: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3232: 'specific' => 'Offloads to specific server',
1.161 raeburn 3233: 'none' => 'No offload',
1.150 raeburn 3234: );
3235: return %ruletitles;
3236: }
3237:
3238: sub sparestype_titles {
3239: my %typestitles = &Apache::lonlocal::texthash (
3240: 'primary' => 'primary',
3241: 'default' => 'default',
3242: );
3243: return %typestitles;
3244: }
3245:
1.28 raeburn 3246: sub contact_titles {
3247: my %titles = &Apache::lonlocal::texthash (
3248: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3249: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3250: 'errormail' => 'Error reports to be e-mailed to',
3251: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3252: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3253: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3254: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3255: );
3256: my %short_titles = &Apache::lonlocal::texthash (
3257: adminemail => 'Admin E-mail address',
3258: supportemail => 'Support E-mail',
3259: );
3260: return (\%titles,\%short_titles);
3261: }
3262:
1.72 raeburn 3263: sub tool_titles {
3264: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3265: aboutme => 'Personal web page',
1.86 raeburn 3266: blog => 'Blog',
1.162 raeburn 3267: webdav => 'WebDAV',
1.86 raeburn 3268: portfolio => 'Portfolio',
1.88 bisitz 3269: official => 'Official courses (with institutional codes)',
3270: unofficial => 'Unofficial courses',
1.98 raeburn 3271: community => 'Communities',
1.86 raeburn 3272: );
1.72 raeburn 3273: return %titles;
3274: }
3275:
1.101 raeburn 3276: sub courserequest_titles {
3277: my %titles = &Apache::lonlocal::texthash (
3278: official => 'Official',
3279: unofficial => 'Unofficial',
3280: community => 'Communities',
3281: norequest => 'Not allowed',
1.104 raeburn 3282: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3283: validate => 'With validation',
3284: autolimit => 'Numerical limit',
1.103 raeburn 3285: unlimited => '(blank for unlimited)',
1.101 raeburn 3286: );
3287: return %titles;
3288: }
3289:
1.163 raeburn 3290: sub authorrequest_titles {
3291: my %titles = &Apache::lonlocal::texthash (
3292: norequest => 'Not allowed',
3293: approval => 'Approval by Dom. Coord.',
3294: automatic => 'Automatic approval',
3295: );
3296: return %titles;
3297: }
3298:
1.101 raeburn 3299: sub courserequest_conditions {
3300: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3301: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3302: validate => '(Processing of request subject to instittutional validation).',
3303: );
3304: return %conditions;
3305: }
3306:
3307:
1.27 raeburn 3308: sub print_usercreation {
1.30 raeburn 3309: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3310: my $numinrow = 4;
1.28 raeburn 3311: my $datatable;
3312: if ($position eq 'top') {
1.30 raeburn 3313: $$rowtotal ++;
1.34 raeburn 3314: my $rowcount = 0;
1.32 raeburn 3315: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3316: if (ref($rules) eq 'HASH') {
3317: if (keys(%{$rules}) > 0) {
1.32 raeburn 3318: $datatable .= &user_formats_row('username',$settings,$rules,
3319: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3320: $$rowtotal ++;
1.32 raeburn 3321: $rowcount ++;
3322: }
3323: }
3324: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3325: if (ref($idrules) eq 'HASH') {
3326: if (keys(%{$idrules}) > 0) {
3327: $datatable .= &user_formats_row('id',$settings,$idrules,
3328: $idruleorder,$numinrow,$rowcount);
3329: $$rowtotal ++;
3330: $rowcount ++;
1.28 raeburn 3331: }
3332: }
1.43 raeburn 3333: my ($emailrules,$emailruleorder) =
3334: &Apache::lonnet::inst_userrules($dom,'email');
3335: if (ref($emailrules) eq 'HASH') {
3336: if (keys(%{$emailrules}) > 0) {
3337: $datatable .= &user_formats_row('email',$settings,$emailrules,
3338: $emailruleorder,$numinrow,$rowcount);
3339: $$rowtotal ++;
3340: $rowcount ++;
3341: }
3342: }
1.39 raeburn 3343: if ($rowcount == 0) {
3344: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3345: $$rowtotal ++;
3346: $rowcount ++;
3347: }
1.34 raeburn 3348: } elsif ($position eq 'middle') {
1.100 raeburn 3349: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3350: my ($rules,$ruleorder) =
3351: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3352: my %lt = &usercreation_types();
3353: my %checked;
1.50 raeburn 3354: my @selfcreate;
1.34 raeburn 3355: if (ref($settings) eq 'HASH') {
3356: if (ref($settings->{'cancreate'}) eq 'HASH') {
3357: foreach my $item (@creators) {
3358: $checked{$item} = $settings->{'cancreate'}{$item};
3359: }
1.50 raeburn 3360: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3361: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3362: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3363: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3364: @selfcreate = ('email','login','sso');
3365: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3366: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3367: }
3368: }
1.34 raeburn 3369: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3370: foreach my $item (@creators) {
3371: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3372: $checked{$item} = 'none';
3373: }
3374: }
3375: }
3376: }
3377: my $rownum = 0;
3378: foreach my $item (@creators) {
3379: $rownum ++;
1.50 raeburn 3380: if ($item ne 'selfcreate') {
3381: if ($checked{$item} eq '') {
1.43 raeburn 3382: $checked{$item} = 'any';
3383: }
1.34 raeburn 3384: }
3385: my $css_class;
3386: if ($rownum%2) {
3387: $css_class = '';
3388: } else {
3389: $css_class = ' class="LC_odd_row" ';
3390: }
3391: $datatable .= '<tr'.$css_class.'>'.
3392: '<td><span class="LC_nobreak">'.$lt{$item}.
3393: '</span></td><td align="right">';
1.50 raeburn 3394: my @options;
1.45 raeburn 3395: if ($item eq 'selfcreate') {
1.43 raeburn 3396: push(@options,('email','login','sso'));
3397: } else {
1.50 raeburn 3398: @options = ('any');
1.43 raeburn 3399: if (ref($rules) eq 'HASH') {
3400: if (keys(%{$rules}) > 0) {
3401: push(@options,('official','unofficial'));
3402: }
1.37 raeburn 3403: }
1.50 raeburn 3404: push(@options,'none');
1.37 raeburn 3405: }
3406: foreach my $option (@options) {
1.50 raeburn 3407: my $type = 'radio';
1.34 raeburn 3408: my $check = ' ';
1.50 raeburn 3409: if ($item eq 'selfcreate') {
3410: $type = 'checkbox';
3411: if (grep(/^\Q$option\E$/,@selfcreate)) {
3412: $check = ' checked="checked" ';
3413: }
3414: } else {
3415: if ($checked{$item} eq $option) {
3416: $check = ' checked="checked" ';
3417: }
1.34 raeburn 3418: }
3419: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3420: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3421: $item.'" value="'.$option.'"'.$check.'/> '.
3422: $lt{$option}.'</label> </span>';
3423: }
3424: $datatable .= '</td></tr>';
3425: }
1.93 raeburn 3426: my ($othertitle,$usertypes,$types) =
3427: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3428: my $createsettings;
3429: if (ref($settings) eq 'HASH') {
3430: $createsettings = $settings->{cancreate};
3431: }
1.93 raeburn 3432: if (ref($usertypes) eq 'HASH') {
3433: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3434: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3435: $dom,$numinrow,$othertitle,
3436: 'statustocreate');
3437: $$rowtotal ++;
1.169 raeburn 3438: $rownum ++;
1.93 raeburn 3439: }
3440: }
1.169 raeburn 3441: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3442: } else {
3443: my @contexts = ('author','course','domain');
3444: my @authtypes = ('int','krb4','krb5','loc');
3445: my %checked;
3446: if (ref($settings) eq 'HASH') {
3447: if (ref($settings->{'authtypes'}) eq 'HASH') {
3448: foreach my $item (@contexts) {
3449: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3450: foreach my $auth (@authtypes) {
3451: if ($settings->{'authtypes'}{$item}{$auth}) {
3452: $checked{$item}{$auth} = ' checked="checked" ';
3453: }
3454: }
3455: }
3456: }
1.27 raeburn 3457: }
1.35 raeburn 3458: } else {
3459: foreach my $item (@contexts) {
1.36 raeburn 3460: foreach my $auth (@authtypes) {
1.35 raeburn 3461: $checked{$item}{$auth} = ' checked="checked" ';
3462: }
3463: }
1.27 raeburn 3464: }
1.28 raeburn 3465: my %title = &context_names();
3466: my %authname = &authtype_names();
3467: my $rownum = 0;
3468: my $css_class;
3469: foreach my $item (@contexts) {
3470: if ($rownum%2) {
3471: $css_class = '';
3472: } else {
3473: $css_class = ' class="LC_odd_row" ';
3474: }
1.30 raeburn 3475: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3476: '<td>'.$title{$item}.
3477: '</td><td class="LC_left_item">'.
3478: '<span class="LC_nobreak">';
3479: foreach my $auth (@authtypes) {
3480: $datatable .= '<label>'.
3481: '<input type="checkbox" name="'.$item.'_auth" '.
3482: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3483: $authname{$auth}.'</label> ';
3484: }
3485: $datatable .= '</span></td></tr>';
3486: $rownum ++;
1.27 raeburn 3487: }
1.30 raeburn 3488: $$rowtotal += $rownum;
1.27 raeburn 3489: }
3490: return $datatable;
3491: }
3492:
1.165 raeburn 3493: sub captcha_choice {
1.169 raeburn 3494: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3495: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3496: my %lt = &captcha_phrases();
3497: $keyentry = 'hidden';
3498: if ($context eq 'cancreate') {
3499: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3500: } elsif ($context eq 'login') {
3501: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3502: }
3503: if (ref($settings) eq 'HASH') {
3504: if ($settings->{'captcha'}) {
3505: $checked{$settings->{'captcha'}} = ' checked="checked"';
3506: } else {
3507: $checked{'original'} = ' checked="checked"';
3508: }
3509: if ($settings->{'captcha'} eq 'recaptcha') {
3510: $pubtext = $lt{'pub'};
3511: $privtext = $lt{'priv'};
3512: $keyentry = 'text';
3513: }
3514: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3515: $currpub = $settings->{'recaptchakeys'}{'public'};
3516: $currpriv = $settings->{'recaptchakeys'}{'private'};
3517: }
3518: } else {
3519: $checked{'original'} = ' checked="checked"';
3520: }
1.169 raeburn 3521: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3522: my $output = '<tr'.$css_class.'>'.
3523: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3524: '<table><tr><td>'."\n";
3525: foreach my $option ('original','recaptcha','notused') {
3526: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3527: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3528: $lt{$option}.'</label></span>';
3529: unless ($option eq 'notused') {
3530: $output .= (' 'x2)."\n";
3531: }
3532: }
3533: #
3534: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3535: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3536: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3537: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3538: #
3539: $output .= '</td></tr>'."\n".
3540: '<tr><td>'."\n".
3541: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3542: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3543: $currpub.'" size="40" /></span><br />'."\n".
3544: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3545: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3546: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3547: '</td></tr>';
3548: return $output;
3549: }
3550:
1.32 raeburn 3551: sub user_formats_row {
3552: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3553: my $output;
3554: my %text = (
3555: 'username' => 'new usernames',
3556: 'id' => 'IDs',
1.45 raeburn 3557: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3558: );
3559: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3560: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3561: '<td><span class="LC_nobreak">';
3562: if ($type eq 'email') {
3563: $output .= &mt("Formats disallowed for $text{$type}: ");
3564: } else {
3565: $output .= &mt("Format rules to check for $text{$type}: ");
3566: }
3567: $output .= '</span></td>'.
3568: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3569: my $rem;
3570: if (ref($ruleorder) eq 'ARRAY') {
3571: for (my $i=0; $i<@{$ruleorder}; $i++) {
3572: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3573: my $rem = $i%($numinrow);
3574: if ($rem == 0) {
3575: if ($i > 0) {
3576: $output .= '</tr>';
3577: }
3578: $output .= '<tr>';
3579: }
3580: my $check = ' ';
1.39 raeburn 3581: if (ref($settings) eq 'HASH') {
3582: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3583: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3584: $check = ' checked="checked" ';
3585: }
1.27 raeburn 3586: }
3587: }
3588: $output .= '<td class="LC_left_item">'.
3589: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3590: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3591: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3592: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3593: }
3594: }
3595: $rem = @{$ruleorder}%($numinrow);
3596: }
3597: my $colsleft = $numinrow - $rem;
3598: if ($colsleft > 1 ) {
3599: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3600: ' </td>';
3601: } elsif ($colsleft == 1) {
3602: $output .= '<td class="LC_left_item"> </td>';
3603: }
3604: $output .= '</tr></table></td></tr>';
3605: return $output;
3606: }
3607:
1.34 raeburn 3608: sub usercreation_types {
3609: my %lt = &Apache::lonlocal::texthash (
3610: author => 'When adding a co-author',
3611: course => 'When adding a user to a course',
1.100 raeburn 3612: requestcrs => 'When requesting a course',
1.45 raeburn 3613: selfcreate => 'User creates own account',
1.34 raeburn 3614: any => 'Any',
3615: official => 'Institutional only ',
3616: unofficial => 'Non-institutional only',
1.85 schafran 3617: email => 'E-mail address',
1.43 raeburn 3618: login => 'Institutional Login',
3619: sso => 'SSO',
1.34 raeburn 3620: none => 'None',
3621: );
3622: return %lt;
1.48 raeburn 3623: }
1.34 raeburn 3624:
1.28 raeburn 3625: sub authtype_names {
3626: my %lt = &Apache::lonlocal::texthash(
3627: int => 'Internal',
3628: krb4 => 'Kerberos 4',
3629: krb5 => 'Kerberos 5',
3630: loc => 'Local',
3631: );
3632: return %lt;
3633: }
3634:
3635: sub context_names {
3636: my %context_title = &Apache::lonlocal::texthash(
3637: author => 'Creating users when an Author',
3638: course => 'Creating users when in a course',
3639: domain => 'Creating users when a Domain Coordinator',
3640: );
3641: return %context_title;
3642: }
3643:
1.33 raeburn 3644: sub print_usermodification {
3645: my ($position,$dom,$settings,$rowtotal) = @_;
3646: my $numinrow = 4;
3647: my ($context,$datatable,$rowcount);
3648: if ($position eq 'top') {
3649: $rowcount = 0;
3650: $context = 'author';
3651: foreach my $role ('ca','aa') {
3652: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3653: $numinrow,$rowcount);
3654: $$rowtotal ++;
3655: $rowcount ++;
3656: }
1.63 raeburn 3657: } elsif ($position eq 'middle') {
1.33 raeburn 3658: $context = 'course';
3659: $rowcount = 0;
3660: foreach my $role ('st','ep','ta','in','cr') {
3661: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3662: $numinrow,$rowcount);
3663: $$rowtotal ++;
3664: $rowcount ++;
3665: }
1.63 raeburn 3666: } elsif ($position eq 'bottom') {
3667: $context = 'selfcreate';
3668: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3669: $usertypes->{'default'} = $othertitle;
3670: if (ref($types) eq 'ARRAY') {
3671: push(@{$types},'default');
3672: $usertypes->{'default'} = $othertitle;
3673: foreach my $status (@{$types}) {
3674: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3675: $numinrow,$rowcount,$usertypes);
3676: $$rowtotal ++;
3677: $rowcount ++;
3678: }
3679: }
1.33 raeburn 3680: }
3681: return $datatable;
3682: }
3683:
1.43 raeburn 3684: sub print_defaults {
3685: my ($dom,$rowtotal) = @_;
1.68 raeburn 3686: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3687: 'datelocale_def','portal_def');
1.43 raeburn 3688: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3689: my $titles = &defaults_titles($dom);
1.43 raeburn 3690: my $rownum = 0;
3691: my ($datatable,$css_class);
3692: foreach my $item (@items) {
3693: if ($rownum%2) {
3694: $css_class = '';
3695: } else {
3696: $css_class = ' class="LC_odd_row" ';
3697: }
3698: $datatable .= '<tr'.$css_class.'>'.
3699: '<td><span class="LC_nobreak">'.$titles->{$item}.
3700: '</span></td><td class="LC_right_item">';
3701: if ($item eq 'auth_def') {
3702: my @authtypes = ('internal','krb4','krb5','localauth');
3703: my %shortauth = (
3704: internal => 'int',
3705: krb4 => 'krb4',
3706: krb5 => 'krb5',
3707: localauth => 'loc'
3708: );
3709: my %authnames = &authtype_names();
3710: foreach my $auth (@authtypes) {
3711: my $checked = ' ';
3712: if ($domdefaults{$item} eq $auth) {
3713: $checked = ' checked="checked" ';
3714: }
3715: $datatable .= '<label><input type="radio" name="'.$item.
3716: '" value="'.$auth.'"'.$checked.'/>'.
3717: $authnames{$shortauth{$auth}}.'</label> ';
3718: }
1.54 raeburn 3719: } elsif ($item eq 'timezone_def') {
3720: my $includeempty = 1;
3721: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3722: } elsif ($item eq 'datelocale_def') {
3723: my $includeempty = 1;
3724: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3725: } elsif ($item eq 'lang_def') {
1.168 raeburn 3726: my %langchoices = &get_languages_hash();
3727: $langchoices{''} = 'No language preference';
1.167 raeburn 3728: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3729: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3730: \%langchoices);
1.43 raeburn 3731: } else {
1.141 raeburn 3732: my $size;
3733: if ($item eq 'portal_def') {
3734: $size = ' size="25"';
3735: }
1.43 raeburn 3736: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3737: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3738: }
3739: $datatable .= '</td></tr>';
3740: $rownum ++;
3741: }
3742: $$rowtotal += $rownum;
3743: return $datatable;
3744: }
3745:
1.168 raeburn 3746: sub get_languages_hash {
3747: my %langchoices;
3748: foreach my $id (&Apache::loncommon::languageids()) {
3749: my $code = &Apache::loncommon::supportedlanguagecode($id);
3750: if ($code ne '') {
3751: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3752: }
3753: }
3754: return %langchoices;
3755: }
3756:
1.43 raeburn 3757: sub defaults_titles {
1.141 raeburn 3758: my ($dom) = @_;
1.43 raeburn 3759: my %titles = &Apache::lonlocal::texthash (
3760: 'auth_def' => 'Default authentication type',
3761: 'auth_arg_def' => 'Default authentication argument',
3762: 'lang_def' => 'Default language',
1.54 raeburn 3763: 'timezone_def' => 'Default timezone',
1.68 raeburn 3764: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3765: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3766: );
1.141 raeburn 3767: if ($dom) {
3768: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3769: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3770: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3771: $protocol = 'http' if ($protocol ne 'https');
3772: if ($uint_dom) {
3773: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3774: $uint_dom);
3775: }
3776: }
1.43 raeburn 3777: return (\%titles);
3778: }
3779:
1.46 raeburn 3780: sub print_scantronformat {
3781: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3782: my $itemcount = 1;
1.60 raeburn 3783: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3784: %confhash);
1.46 raeburn 3785: my $switchserver = &check_switchserver($dom,$confname);
3786: my %lt = &Apache::lonlocal::texthash (
1.95 www 3787: default => 'Default bubblesheet format file error',
3788: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3789: );
3790: my %scantronfiles = (
3791: default => 'default.tab',
3792: custom => 'custom.tab',
3793: );
3794: foreach my $key (keys(%scantronfiles)) {
3795: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3796: .$scantronfiles{$key};
3797: }
3798: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3799: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3800: if (!$switchserver) {
3801: my $servadm = $r->dir_config('lonAdmEMail');
3802: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3803: if ($configuserok eq 'ok') {
3804: if ($author_ok eq 'ok') {
3805: my %legacyfile = (
3806: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3807: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3808: );
3809: my %md5chk;
3810: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3811: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3812: chomp($md5chk{$type});
1.46 raeburn 3813: }
3814: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3815: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3816: ($scantronurls{$type},my $error) =
1.46 raeburn 3817: &legacy_scantronformat($r,$dom,$confname,
3818: $type,$legacyfile{$type},
3819: $scantronurls{$type},
3820: $scantronfiles{$type});
1.60 raeburn 3821: if ($error ne '') {
3822: $error{$type} = $error;
3823: }
3824: }
3825: if (keys(%error) == 0) {
3826: $is_custom = 1;
3827: $confhash{'scantron'}{'scantronformat'} =
3828: $scantronurls{'custom'};
3829: my $putresult =
3830: &Apache::lonnet::put_dom('configuration',
3831: \%confhash,$dom);
3832: if ($putresult ne 'ok') {
3833: $error{'custom'} =
3834: '<span class="LC_error">'.
3835: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3836: }
1.46 raeburn 3837: }
3838: } else {
1.60 raeburn 3839: ($scantronurls{'default'},my $error) =
1.46 raeburn 3840: &legacy_scantronformat($r,$dom,$confname,
3841: 'default',$legacyfile{'default'},
3842: $scantronurls{'default'},
3843: $scantronfiles{'default'});
1.60 raeburn 3844: if ($error eq '') {
3845: $confhash{'scantron'}{'scantronformat'} = '';
3846: my $putresult =
3847: &Apache::lonnet::put_dom('configuration',
3848: \%confhash,$dom);
3849: if ($putresult ne 'ok') {
3850: $error{'default'} =
3851: '<span class="LC_error">'.
3852: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3853: }
3854: } else {
3855: $error{'default'} = $error;
3856: }
1.46 raeburn 3857: }
3858: }
3859: }
3860: } else {
1.95 www 3861: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3862: }
3863: }
3864: if (ref($settings) eq 'HASH') {
3865: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3866: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3867: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3868: $scantronurl = '';
3869: } else {
3870: $scantronurl = $settings->{'scantronformat'};
3871: }
3872: $is_custom = 1;
3873: } else {
3874: $scantronurl = $scantronurls{'default'};
3875: }
3876: } else {
1.60 raeburn 3877: if ($is_custom) {
3878: $scantronurl = $scantronurls{'custom'};
3879: } else {
3880: $scantronurl = $scantronurls{'default'};
3881: }
1.46 raeburn 3882: }
3883: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3884: $datatable .= '<tr'.$css_class.'>';
3885: if (!$is_custom) {
1.65 raeburn 3886: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3887: '<span class="LC_nobreak">';
1.46 raeburn 3888: if ($scantronurl) {
3889: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3890: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3891: } else {
3892: $datatable = &mt('File unavailable for display');
3893: }
1.65 raeburn 3894: $datatable .= '</span></td>';
1.60 raeburn 3895: if (keys(%error) == 0) {
3896: $datatable .= '<td valign="bottom">';
3897: if (!$switchserver) {
3898: $datatable .= &mt('Upload:').'<br />';
3899: }
3900: } else {
3901: my $errorstr;
3902: foreach my $key (sort(keys(%error))) {
3903: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3904: }
3905: $datatable .= '<td>'.$errorstr;
3906: }
1.46 raeburn 3907: } else {
3908: if (keys(%error) > 0) {
3909: my $errorstr;
3910: foreach my $key (sort(keys(%error))) {
3911: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3912: }
1.60 raeburn 3913: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3914: } elsif ($scantronurl) {
1.65 raeburn 3915: $datatable .= '<td><span class="LC_nobreak">'.
3916: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3917: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3918: '<input type="checkbox" name="scantronformat_del"'.
3919: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3920: '<td><span class="LC_nobreak"> '.
3921: &mt('Replace:').'</span><br />';
1.46 raeburn 3922: }
3923: }
3924: if (keys(%error) == 0) {
3925: if ($switchserver) {
3926: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3927: } else {
1.65 raeburn 3928: $datatable .='<span class="LC_nobreak"> '.
3929: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3930: }
3931: }
3932: $datatable .= '</td></tr>';
3933: $$rowtotal ++;
3934: return $datatable;
3935: }
3936:
3937: sub legacy_scantronformat {
3938: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3939: my ($url,$error);
3940: my @statinfo = &Apache::lonnet::stat_file($newurl);
3941: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3942: (my $result,$url) =
3943: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3944: '','',$newfile);
3945: if ($result ne 'ok') {
1.130 raeburn 3946: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3947: }
3948: }
3949: return ($url,$error);
3950: }
1.43 raeburn 3951:
1.49 raeburn 3952: sub print_coursecategories {
1.57 raeburn 3953: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3954: my $datatable;
3955: if ($position eq 'top') {
3956: my $toggle_cats_crs = ' ';
3957: my $toggle_cats_dom = ' checked="checked" ';
3958: my $can_cat_crs = ' ';
3959: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3960: my $toggle_catscomm_comm = ' ';
3961: my $toggle_catscomm_dom = ' checked="checked" ';
3962: my $can_catcomm_comm = ' ';
3963: my $can_catcomm_dom = ' checked="checked" ';
3964:
1.57 raeburn 3965: if (ref($settings) eq 'HASH') {
3966: if ($settings->{'togglecats'} eq 'crs') {
3967: $toggle_cats_crs = $toggle_cats_dom;
3968: $toggle_cats_dom = ' ';
3969: }
3970: if ($settings->{'categorize'} eq 'crs') {
3971: $can_cat_crs = $can_cat_dom;
3972: $can_cat_dom = ' ';
3973: }
1.120 raeburn 3974: if ($settings->{'togglecatscomm'} eq 'comm') {
3975: $toggle_catscomm_comm = $toggle_catscomm_dom;
3976: $toggle_catscomm_dom = ' ';
3977: }
3978: if ($settings->{'categorizecomm'} eq 'comm') {
3979: $can_catcomm_comm = $can_catcomm_dom;
3980: $can_catcomm_dom = ' ';
3981: }
1.57 raeburn 3982: }
3983: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3984: togglecats => 'Show/Hide a course in catalog',
3985: togglecatscomm => 'Show/Hide a community in catalog',
3986: categorize => 'Assign a category to a course',
3987: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3988: );
3989: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3990: dom => 'Set in Domain',
3991: crs => 'Set in Course',
3992: comm => 'Set in Community',
1.57 raeburn 3993: );
3994: $datatable = '<tr class="LC_odd_row">'.
3995: '<td>'.$title{'togglecats'}.'</td>'.
3996: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3997: '<input type="radio" name="togglecats"'.
3998: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3999: '<label><input type="radio" name="togglecats"'.
4000: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4001: '</tr><tr>'.
4002: '<td>'.$title{'categorize'}.'</td>'.
4003: '<td class="LC_right_item"><span class="LC_nobreak">'.
4004: '<label><input type="radio" name="categorize"'.
4005: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4006: '<label><input type="radio" name="categorize"'.
4007: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4008: '</tr><tr class="LC_odd_row">'.
4009: '<td>'.$title{'togglecatscomm'}.'</td>'.
4010: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4011: '<input type="radio" name="togglecatscomm"'.
4012: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4013: '<label><input type="radio" name="togglecatscomm"'.
4014: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4015: '</tr><tr>'.
4016: '<td>'.$title{'categorizecomm'}.'</td>'.
4017: '<td class="LC_right_item"><span class="LC_nobreak">'.
4018: '<label><input type="radio" name="categorizecomm"'.
4019: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4020: '<label><input type="radio" name="categorizecomm"'.
4021: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4022: '</tr>';
1.120 raeburn 4023: $$rowtotal += 4;
1.57 raeburn 4024: } else {
4025: my $css_class;
4026: my $itemcount = 1;
4027: my $cathash;
4028: if (ref($settings) eq 'HASH') {
4029: $cathash = $settings->{'cats'};
4030: }
4031: if (ref($cathash) eq 'HASH') {
4032: my (@cats,@trails,%allitems,%idx,@jsarray);
4033: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4034: \%allitems,\%idx,\@jsarray);
4035: my $maxdepth = scalar(@cats);
4036: my $colattrib = '';
4037: if ($maxdepth > 2) {
4038: $colattrib = ' colspan="2" ';
4039: }
4040: my @path;
4041: if (@cats > 0) {
4042: if (ref($cats[0]) eq 'ARRAY') {
4043: my $numtop = @{$cats[0]};
4044: my $maxnum = $numtop;
1.120 raeburn 4045: my %default_names = (
4046: instcode => &mt('Official courses'),
4047: communities => &mt('Communities'),
4048: );
4049:
4050: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4051: ($cathash->{'instcode::0'} eq '') ||
4052: (!grep(/^communities$/,@{$cats[0]})) ||
4053: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4054: $maxnum ++;
4055: }
4056: my $lastidx;
4057: for (my $i=0; $i<$numtop; $i++) {
4058: my $parent = $cats[0][$i];
4059: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4060: my $item = &escape($parent).'::0';
4061: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4062: $lastidx = $idx{$item};
4063: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4064: .'<select name="'.$item.'"'.$chgstr.'>';
4065: for (my $k=0; $k<=$maxnum; $k++) {
4066: my $vpos = $k+1;
4067: my $selstr;
4068: if ($k == $i) {
4069: $selstr = ' selected="selected" ';
4070: }
4071: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4072: }
4073: $datatable .= '</select></td><td>';
1.120 raeburn 4074: if ($parent eq 'instcode' || $parent eq 'communities') {
4075: $datatable .= '<span class="LC_nobreak">'
4076: .$default_names{$parent}.'</span>';
4077: if ($parent eq 'instcode') {
4078: $datatable .= '<br /><span class="LC_nobreak">('
4079: .&mt('with institutional codes')
4080: .')</span></td><td'.$colattrib.'>';
4081: } else {
4082: $datatable .= '<table><tr><td>';
4083: }
4084: $datatable .= '<span class="LC_nobreak">'
4085: .'<label><input type="radio" name="'
4086: .$parent.'" value="1" checked="checked" />'
4087: .&mt('Display').'</label>';
4088: if ($parent eq 'instcode') {
4089: $datatable .= ' ';
4090: } else {
4091: $datatable .= '</span></td></tr><tr><td>'
4092: .'<span class="LC_nobreak">';
4093: }
4094: $datatable .= '<label><input type="radio" name="'
4095: .$parent.'" value="0" />'
4096: .&mt('Do not display').'</label></span>';
4097: if ($parent eq 'communities') {
4098: $datatable .= '</td></tr></table>';
4099: }
4100: $datatable .= '</td>';
1.57 raeburn 4101: } else {
4102: $datatable .= $parent
4103: .' <label><input type="checkbox" name="deletecategory" '
4104: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4105: }
4106: my $depth = 1;
4107: push(@path,$parent);
4108: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4109: pop(@path);
4110: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4111: $itemcount ++;
4112: }
1.48 raeburn 4113: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4114: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4115: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4116: for (my $k=0; $k<=$maxnum; $k++) {
4117: my $vpos = $k+1;
4118: my $selstr;
1.57 raeburn 4119: if ($k == $numtop) {
1.48 raeburn 4120: $selstr = ' selected="selected" ';
4121: }
4122: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4123: }
1.59 bisitz 4124: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4125: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4126: .'</tr>'."\n";
1.48 raeburn 4127: $itemcount ++;
1.120 raeburn 4128: foreach my $default ('instcode','communities') {
4129: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4130: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4131: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4132: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4133: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4134: for (my $k=0; $k<=$maxnum; $k++) {
4135: my $vpos = $k+1;
4136: my $selstr;
4137: if ($k == $maxnum) {
4138: $selstr = ' selected="selected" ';
4139: }
4140: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4141: }
1.120 raeburn 4142: $datatable .= '</select></span></td>'.
4143: '<td><span class="LC_nobreak">'.
4144: $default_names{$default}.'</span>';
4145: if ($default eq 'instcode') {
4146: $datatable .= '<br /><span class="LC_nobreak">('
4147: .&mt('with institutional codes').')</span>';
4148: }
4149: $datatable .= '</td>'
4150: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4151: .&mt('Display').'</label> '
4152: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4153: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4154: }
4155: }
4156: }
1.57 raeburn 4157: } else {
4158: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4159: }
4160: } else {
1.57 raeburn 4161: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4162: .&initialize_categories($itemcount);
1.48 raeburn 4163: }
1.57 raeburn 4164: $$rowtotal += $itemcount;
1.48 raeburn 4165: }
4166: return $datatable;
4167: }
4168:
1.69 raeburn 4169: sub print_serverstatuses {
4170: my ($dom,$settings,$rowtotal) = @_;
4171: my $datatable;
4172: my @pages = &serverstatus_pages();
4173: my (%namedaccess,%machineaccess);
4174: foreach my $type (@pages) {
4175: $namedaccess{$type} = '';
4176: $machineaccess{$type}= '';
4177: }
4178: if (ref($settings) eq 'HASH') {
4179: foreach my $type (@pages) {
4180: if (exists($settings->{$type})) {
4181: if (ref($settings->{$type}) eq 'HASH') {
4182: foreach my $key (keys(%{$settings->{$type}})) {
4183: if ($key eq 'namedusers') {
4184: $namedaccess{$type} = $settings->{$type}->{$key};
4185: } elsif ($key eq 'machines') {
4186: $machineaccess{$type} = $settings->{$type}->{$key};
4187: }
4188: }
4189: }
4190: }
4191: }
4192: }
1.81 raeburn 4193: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4194: my $rownum = 0;
4195: my $css_class;
4196: foreach my $type (@pages) {
4197: $rownum ++;
4198: $css_class = $rownum%2?' class="LC_odd_row"':'';
4199: $datatable .= '<tr'.$css_class.'>'.
4200: '<td><span class="LC_nobreak">'.
4201: $titles->{$type}.'</span></td>'.
4202: '<td class="LC_left_item">'.
4203: '<input type="text" name="'.$type.'_namedusers" '.
4204: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4205: '<td class="LC_right_item">'.
4206: '<span class="LC_nobreak">'.
4207: '<input type="text" name="'.$type.'_machines" '.
4208: 'value="'.$machineaccess{$type}.'" size="10" />'.
4209: '</td></tr>'."\n";
4210: }
4211: $$rowtotal += $rownum;
4212: return $datatable;
4213: }
4214:
4215: sub serverstatus_pages {
4216: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4217: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4218: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4219: }
4220:
1.49 raeburn 4221: sub coursecategories_javascript {
4222: my ($settings) = @_;
1.57 raeburn 4223: my ($output,$jstext,$cathash);
1.49 raeburn 4224: if (ref($settings) eq 'HASH') {
1.57 raeburn 4225: $cathash = $settings->{'cats'};
4226: }
4227: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4228: my (@cats,@jsarray,%idx);
1.57 raeburn 4229: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4230: if (@jsarray > 0) {
4231: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4232: for (my $i=0; $i<@jsarray; $i++) {
4233: if (ref($jsarray[$i]) eq 'ARRAY') {
4234: my $catstr = join('","',@{$jsarray[$i]});
4235: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4236: }
4237: }
4238: }
4239: } else {
4240: $jstext = ' var categories = Array(1);'."\n".
4241: ' categories[0] = Array("instcode_pos");'."\n";
4242: }
1.120 raeburn 4243: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4244: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4245: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4246: $output = <<"ENDSCRIPT";
4247: <script type="text/javascript">
1.109 raeburn 4248: // <![CDATA[
1.49 raeburn 4249: function reorderCats(form,parent,item,idx) {
4250: var changedVal;
4251: $jstext
4252: var newpos = 'addcategory_pos';
4253: var current = new Array;
4254: if (parent == '') {
4255: var has_instcode = 0;
4256: var maxtop = categories[idx].length;
4257: for (var j=0; j<maxtop; j++) {
4258: if (categories[idx][j] == 'instcode::0') {
4259: has_instcode == 1;
4260: }
4261: }
4262: if (has_instcode == 0) {
4263: categories[idx][maxtop] = 'instcode_pos';
4264: }
4265: } else {
4266: newpos += '_'+parent;
4267: }
4268: var maxh = 1 + categories[idx].length;
4269: var current = new Array;
4270: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4271: if (item == newpos) {
4272: changedVal = newitemVal;
4273: } else {
4274: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4275: current[newitemVal] = newpos;
4276: }
4277: for (var i=0; i<categories[idx].length; i++) {
4278: var elementName = categories[idx][i];
4279: if (elementName != item) {
4280: if (form.elements[elementName]) {
4281: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4282: current[currVal] = elementName;
4283: }
4284: }
4285: }
4286: var oldVal;
4287: for (var j=0; j<maxh; j++) {
4288: if (current[j] == undefined) {
4289: oldVal = j;
4290: }
4291: }
4292: if (oldVal < changedVal) {
4293: for (var k=oldVal+1; k<=changedVal ; k++) {
4294: var elementName = current[k];
4295: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4296: }
4297: } else {
4298: for (var k=changedVal; k<oldVal; k++) {
4299: var elementName = current[k];
4300: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4301: }
4302: }
4303: return;
4304: }
1.120 raeburn 4305:
4306: function categoryCheck(form) {
4307: if (form.elements['addcategory_name'].value == 'instcode') {
4308: alert('$instcode_reserved\\n$choose_again');
4309: return false;
4310: }
4311: if (form.elements['addcategory_name'].value == 'communities') {
4312: alert('$communities_reserved\\n$choose_again');
4313: return false;
4314: }
4315: return true;
4316: }
4317:
1.109 raeburn 4318: // ]]>
1.49 raeburn 4319: </script>
4320:
4321: ENDSCRIPT
4322: return $output;
4323: }
4324:
1.48 raeburn 4325: sub initialize_categories {
4326: my ($itemcount) = @_;
1.120 raeburn 4327: my ($datatable,$css_class,$chgstr);
4328: my %default_names = (
4329: instcode => 'Official courses (with institutional codes)',
4330: communities => 'Communities',
4331: );
4332: my $select0 = ' selected="selected"';
4333: my $select1 = '';
4334: foreach my $default ('instcode','communities') {
4335: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4336: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4337: if ($default eq 'communities') {
4338: $select1 = $select0;
4339: $select0 = '';
4340: }
4341: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4342: .'<select name="'.$default.'_pos">'
4343: .'<option value="0"'.$select0.'>1</option>'
4344: .'<option value="1"'.$select1.'>2</option>'
4345: .'<option value="2">3</option></select> '
4346: .$default_names{$default}
4347: .'</span></td><td><span class="LC_nobreak">'
4348: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4349: .&mt('Display').'</label> <label>'
4350: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4351: .'</label></span></td></tr>';
1.120 raeburn 4352: $itemcount ++;
4353: }
1.48 raeburn 4354: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4355: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4356: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4357: .'<select name="addcategory_pos"'.$chgstr.'>'
4358: .'<option value="0">1</option>'
4359: .'<option value="1">2</option>'
4360: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4361: .&mt('Add category').'</td><td>'.&mt('Name:')
4362: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4363: return $datatable;
4364: }
4365:
4366: sub build_category_rows {
1.49 raeburn 4367: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4368: my ($text,$name,$item,$chgstr);
1.48 raeburn 4369: if (ref($cats) eq 'ARRAY') {
4370: my $maxdepth = scalar(@{$cats});
4371: if (ref($cats->[$depth]) eq 'HASH') {
4372: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4373: my $numchildren = @{$cats->[$depth]{$parent}};
4374: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4375: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4376: my ($idxnum,$parent_name,$parent_item);
4377: my $higher = $depth - 1;
4378: if ($higher == 0) {
4379: $parent_name = &escape($parent).'::'.$higher;
4380: } else {
4381: if (ref($path) eq 'ARRAY') {
4382: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4383: }
4384: }
4385: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4386: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4387: if ($j < $numchildren) {
1.48 raeburn 4388: $name = $cats->[$depth]{$parent}[$j];
4389: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4390: $idxnum = $idx->{$item};
4391: } else {
4392: $name = $parent_name;
4393: $item = $parent_item;
1.48 raeburn 4394: }
1.49 raeburn 4395: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4396: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4397: for (my $i=0; $i<=$numchildren; $i++) {
4398: my $vpos = $i+1;
4399: my $selstr;
4400: if ($j == $i) {
4401: $selstr = ' selected="selected" ';
4402: }
4403: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4404: }
4405: $text .= '</select> ';
4406: if ($j < $numchildren) {
4407: my $deeper = $depth+1;
4408: $text .= $name.' '
4409: .'<label><input type="checkbox" name="deletecategory" value="'
4410: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4411: if(ref($path) eq 'ARRAY') {
4412: push(@{$path},$name);
1.49 raeburn 4413: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4414: pop(@{$path});
4415: }
4416: } else {
1.59 bisitz 4417: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4418: if ($j == $numchildren) {
4419: $text .= $name;
4420: } else {
4421: $text .= $item;
4422: }
4423: $text .= '" value="" />';
4424: }
4425: $text .= '</td></tr>';
4426: }
4427: $text .= '</table></td>';
4428: } else {
4429: my $higher = $depth-1;
4430: if ($higher == 0) {
4431: $name = &escape($parent).'::'.$higher;
4432: } else {
4433: if (ref($path) eq 'ARRAY') {
4434: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4435: }
4436: }
4437: my $colspan;
4438: if ($parent ne 'instcode') {
4439: $colspan = $maxdepth - $depth - 1;
4440: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4441: }
4442: }
4443: }
4444: }
4445: return $text;
4446: }
4447:
1.33 raeburn 4448: sub modifiable_userdata_row {
1.63 raeburn 4449: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4450: my $rolename;
1.63 raeburn 4451: if ($context eq 'selfcreate') {
4452: if (ref($usertypes) eq 'HASH') {
4453: $rolename = $usertypes->{$role};
4454: } else {
4455: $rolename = $role;
4456: }
1.33 raeburn 4457: } else {
1.63 raeburn 4458: if ($role eq 'cr') {
4459: $rolename = &mt('Custom role');
4460: } else {
4461: $rolename = &Apache::lonnet::plaintext($role);
4462: }
1.33 raeburn 4463: }
4464: my @fields = ('lastname','firstname','middlename','generation',
4465: 'permanentemail','id');
4466: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4467: my $output;
4468: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4469: $output = '<tr '.$css_class.'>'.
4470: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4471: '<td class="LC_left_item" colspan="2"><table>';
4472: my $rem;
4473: my %checks;
4474: if (ref($settings) eq 'HASH') {
4475: if (ref($settings->{$context}) eq 'HASH') {
4476: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4477: foreach my $field (@fields) {
4478: if ($settings->{$context}->{$role}->{$field}) {
4479: $checks{$field} = ' checked="checked" ';
4480: }
4481: }
4482: }
4483: }
4484: }
4485: for (my $i=0; $i<@fields; $i++) {
4486: my $rem = $i%($numinrow);
4487: if ($rem == 0) {
4488: if ($i > 0) {
4489: $output .= '</tr>';
4490: }
4491: $output .= '<tr>';
4492: }
4493: my $check = ' ';
4494: if (exists($checks{$fields[$i]})) {
4495: $check = $checks{$fields[$i]}
4496: } else {
4497: if ($role eq 'st') {
4498: if (ref($settings) ne 'HASH') {
4499: $check = ' checked="checked" ';
4500: }
4501: }
4502: }
4503: $output .= '<td class="LC_left_item">'.
4504: '<span class="LC_nobreak"><label>'.
4505: '<input type="checkbox" name="canmodify_'.$role.'" '.
4506: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4507: '</label></span></td>';
4508: $rem = @fields%($numinrow);
4509: }
4510: my $colsleft = $numinrow - $rem;
4511: if ($colsleft > 1 ) {
4512: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4513: ' </td>';
4514: } elsif ($colsleft == 1) {
4515: $output .= '<td class="LC_left_item"> </td>';
4516: }
4517: $output .= '</tr></table></td></tr>';
4518: return $output;
4519: }
1.28 raeburn 4520:
1.93 raeburn 4521: sub insttypes_row {
4522: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4523: my %lt = &Apache::lonlocal::texthash (
4524: cansearch => 'Users allowed to search',
4525: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4526: lockablenames => 'User preference to lock name',
1.93 raeburn 4527: );
4528: my $showdom;
4529: if ($context eq 'cansearch') {
4530: $showdom = ' ('.$dom.')';
4531: }
1.165 raeburn 4532: my $class = 'LC_left_item';
4533: if ($context eq 'statustocreate') {
4534: $class = 'LC_right_item';
4535: }
1.25 raeburn 4536: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4537: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4538: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4539: my $rem;
4540: if (ref($types) eq 'ARRAY') {
4541: for (my $i=0; $i<@{$types}; $i++) {
4542: if (defined($usertypes->{$types->[$i]})) {
4543: my $rem = $i%($numinrow);
4544: if ($rem == 0) {
4545: if ($i > 0) {
4546: $output .= '</tr>';
4547: }
4548: $output .= '<tr>';
1.23 raeburn 4549: }
1.26 raeburn 4550: my $check = ' ';
1.99 raeburn 4551: if (ref($settings) eq 'HASH') {
4552: if (ref($settings->{$context}) eq 'ARRAY') {
4553: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4554: $check = ' checked="checked" ';
4555: }
4556: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4557: $check = ' checked="checked" ';
4558: }
1.23 raeburn 4559: }
1.26 raeburn 4560: $output .= '<td class="LC_left_item">'.
4561: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4562: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4563: 'value="'.$types->[$i].'"'.$check.'/>'.
4564: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4565: }
4566: }
1.26 raeburn 4567: $rem = @{$types}%($numinrow);
1.23 raeburn 4568: }
4569: my $colsleft = $numinrow - $rem;
1.131 raeburn 4570: if (($rem == 0) && (@{$types} > 0)) {
4571: $output .= '<tr>';
4572: }
1.23 raeburn 4573: if ($colsleft > 1) {
1.25 raeburn 4574: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4575: } else {
1.25 raeburn 4576: $output .= '<td class="LC_left_item">';
1.23 raeburn 4577: }
4578: my $defcheck = ' ';
1.99 raeburn 4579: if (ref($settings) eq 'HASH') {
4580: if (ref($settings->{$context}) eq 'ARRAY') {
4581: if (grep(/^default$/,@{$settings->{$context}})) {
4582: $defcheck = ' checked="checked" ';
4583: }
4584: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4585: $defcheck = ' checked="checked" ';
4586: }
1.23 raeburn 4587: }
1.25 raeburn 4588: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4589: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4590: 'value="default"'.$defcheck.'/>'.
4591: $othertitle.'</label></span></td>'.
4592: '</tr></table></td></tr>';
4593: return $output;
1.23 raeburn 4594: }
4595:
4596: sub sorted_searchtitles {
4597: my %searchtitles = &Apache::lonlocal::texthash(
4598: 'uname' => 'username',
4599: 'lastname' => 'last name',
4600: 'lastfirst' => 'last name, first name',
4601: );
4602: my @titleorder = ('uname','lastname','lastfirst');
4603: return (\%searchtitles,\@titleorder);
4604: }
4605:
1.25 raeburn 4606: sub sorted_searchtypes {
4607: my %srchtypes_desc = (
4608: exact => 'is exact match',
4609: contains => 'contains ..',
4610: begins => 'begins with ..',
4611: );
4612: my @srchtypeorder = ('exact','begins','contains');
4613: return (\%srchtypes_desc,\@srchtypeorder);
4614: }
4615:
1.3 raeburn 4616: sub usertype_update_row {
4617: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4618: my $datatable;
4619: my $numinrow = 4;
4620: foreach my $type (@{$types}) {
4621: if (defined($usertypes->{$type})) {
4622: $$rownums ++;
4623: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4624: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4625: '</td><td class="LC_left_item"><table>';
4626: for (my $i=0; $i<@{$fields}; $i++) {
4627: my $rem = $i%($numinrow);
4628: if ($rem == 0) {
4629: if ($i > 0) {
4630: $datatable .= '</tr>';
4631: }
4632: $datatable .= '<tr>';
4633: }
4634: my $check = ' ';
1.39 raeburn 4635: if (ref($settings) eq 'HASH') {
4636: if (ref($settings->{'fields'}) eq 'HASH') {
4637: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4638: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4639: $check = ' checked="checked" ';
4640: }
1.3 raeburn 4641: }
4642: }
4643: }
4644:
4645: if ($i == @{$fields}-1) {
4646: my $colsleft = $numinrow - $rem;
4647: if ($colsleft > 1) {
4648: $datatable .= '<td colspan="'.$colsleft.'">';
4649: } else {
4650: $datatable .= '<td>';
4651: }
4652: } else {
4653: $datatable .= '<td>';
4654: }
1.8 raeburn 4655: $datatable .= '<span class="LC_nobreak"><label>'.
4656: '<input type="checkbox" name="updateable_'.$type.
4657: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4658: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4659: }
4660: $datatable .= '</tr></table></td></tr>';
4661: }
4662: }
4663: return $datatable;
1.1 raeburn 4664: }
4665:
4666: sub modify_login {
1.9 raeburn 4667: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4668: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4669: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4670: %title = ( coursecatalog => 'Display course catalog',
4671: adminmail => 'Display administrator E-mail address',
4672: newuser => 'Link for visitors to create a user account',
4673: loginheader => 'Log-in box header');
4674: @offon = ('off','on');
1.112 raeburn 4675: if (ref($domconfig{login}) eq 'HASH') {
4676: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4677: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4678: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4679: }
4680: }
4681: }
1.9 raeburn 4682: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4683: \%domconfig,\%loginhash);
1.118 jms 4684: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4685: foreach my $item (@toggles) {
4686: $loginhash{login}{$item} = $env{'form.'.$item};
4687: }
1.41 raeburn 4688: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4689: if (ref($colchanges{'login'}) eq 'HASH') {
4690: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4691: \%loginhash);
4692: }
1.110 raeburn 4693:
1.149 raeburn 4694: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4695: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4696: if (keys(%servers) > 1) {
4697: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4698: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4699: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4700: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4701: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4702: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4703: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4704: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4705: $changes{'loginvia'}{$lonhost} = 1;
4706: } else {
4707: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4708: $changes{'loginvia'}{$lonhost} = 1;
4709: }
4710: } else {
4711: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4712: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4713: $changes{'loginvia'}{$lonhost} = 1;
4714: }
4715: }
4716: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4717: foreach my $item (@loginvia_attribs) {
4718: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4719: }
4720: } else {
4721: foreach my $item (@loginvia_attribs) {
4722: my $new = $env{'form.'.$lonhost.'_'.$item};
4723: if (($item eq 'serverpath') && ($new eq 'custom')) {
4724: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4725: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4726: $new = '/';
4727: }
4728: }
4729: if (($item eq 'custompath') &&
4730: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4731: $new = '';
4732: }
4733: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4734: $changes{'loginvia'}{$lonhost} = 1;
4735: }
4736: if ($item eq 'exempt') {
4737: $new =~ s/^\s+//;
4738: $new =~ s/\s+$//;
4739: my @poss_ips = split(/\s*[,:]\s*/,$new);
4740: my @okips;
4741: foreach my $ip (@poss_ips) {
4742: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4743: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4744: push(@okips,$ip);
4745: }
4746: }
4747: }
4748: if (@okips > 0) {
4749: $new = join(',',@okips);
4750: } else {
4751: $new = '';
4752: }
4753: }
4754: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4755: }
4756: }
1.112 raeburn 4757: } else {
1.128 raeburn 4758: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4759: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4760: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4761: foreach my $item (@loginvia_attribs) {
4762: my $new = $env{'form.'.$lonhost.'_'.$item};
4763: if (($item eq 'serverpath') && ($new eq 'custom')) {
4764: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4765: $new = '/';
4766: }
4767: }
4768: if (($item eq 'custompath') &&
4769: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4770: $new = '';
4771: }
4772: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4773: }
1.110 raeburn 4774: }
4775: }
4776: }
4777: }
1.119 raeburn 4778:
1.168 raeburn 4779: my $servadm = $r->dir_config('lonAdmEMail');
4780: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4781: if (ref($domconfig{'login'}) eq 'HASH') {
4782: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4783: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4784: if ($lang eq 'nolang') {
4785: push(@currlangs,$lang);
4786: } elsif (defined($langchoices{$lang})) {
4787: push(@currlangs,$lang);
4788: } else {
4789: next;
4790: }
4791: }
4792: }
4793: }
4794: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4795: if (@currlangs > 0) {
4796: foreach my $lang (@currlangs) {
4797: if (grep(/^\Q$lang\E$/,@delurls)) {
4798: $changes{'helpurl'}{$lang} = 1;
4799: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4800: $changes{'helpurl'}{$lang} = 1;
4801: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4802: push(@newlangs,$lang);
4803: } else {
4804: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4805: }
4806: }
4807: }
4808: unless (grep(/^nolang$/,@currlangs)) {
4809: if ($env{'form.loginhelpurl_nolang.filename'}) {
4810: $changes{'helpurl'}{'nolang'} = 1;
4811: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4812: push(@newlangs,'nolang');
4813: }
4814: }
4815: if ($env{'form.loginhelpurl_add_lang'}) {
4816: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4817: ($env{'form.loginhelpurl_add_file.filename'})) {
4818: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4819: $addedfile = $env{'form.loginhelpurl_add_lang'};
4820: }
4821: }
4822: if ((@newlangs > 0) || ($addedfile)) {
4823: my $error;
4824: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4825: if ($configuserok eq 'ok') {
4826: if ($switchserver) {
4827: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4828: } elsif ($author_ok eq 'ok') {
4829: my @allnew = @newlangs;
4830: if ($addedfile ne '') {
4831: push(@allnew,$addedfile);
4832: }
4833: foreach my $lang (@allnew) {
4834: my $formelem = 'loginhelpurl_'.$lang;
4835: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4836: $formelem = 'loginhelpurl_add_file';
4837: }
4838: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4839: "help/$lang",'','',$newfile{$lang});
4840: if ($result eq 'ok') {
4841: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4842: $changes{'helpurl'}{$lang} = 1;
4843: } else {
4844: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4845: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4846: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4847: (!grep(/^\Q$lang\E$/,@delurls))) {
4848:
4849: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4850: }
4851: }
4852: }
4853: } else {
4854: $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);
4855: }
4856: } else {
4857: $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);
4858: }
4859: if ($error) {
4860: &Apache::lonnet::logthis($error);
4861: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4862: }
4863: }
1.169 raeburn 4864: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4865:
4866: my $defaulthelpfile = '/adm/loginproblems.html';
4867: my $defaulttext = &mt('Default in use');
4868:
1.1 raeburn 4869: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4870: $dom);
4871: if ($putresult eq 'ok') {
1.118 jms 4872: my @toggles = ('coursecatalog','adminmail','newuser');
1.42 raeburn 4873: my %defaultchecked = (
4874: 'coursecatalog' => 'on',
4875: 'adminmail' => 'off',
1.43 raeburn 4876: 'newuser' => 'off',
1.42 raeburn 4877: );
1.55 raeburn 4878: if (ref($domconfig{'login'}) eq 'HASH') {
4879: foreach my $item (@toggles) {
4880: if ($defaultchecked{$item} eq 'on') {
4881: if (($domconfig{'login'}{$item} eq '0') &&
4882: ($env{'form.'.$item} eq '1')) {
4883: $changes{$item} = 1;
4884: } elsif (($domconfig{'login'}{$item} eq '' ||
4885: $domconfig{'login'}{$item} eq '1') &&
4886: ($env{'form.'.$item} eq '0')) {
4887: $changes{$item} = 1;
4888: }
4889: } elsif ($defaultchecked{$item} eq 'off') {
4890: if (($domconfig{'login'}{$item} eq '1') &&
4891: ($env{'form.'.$item} eq '0')) {
4892: $changes{$item} = 1;
4893: } elsif (($domconfig{'login'}{$item} eq '' ||
4894: $domconfig{'login'}{$item} eq '0') &&
4895: ($env{'form.'.$item} eq '1')) {
4896: $changes{$item} = 1;
4897: }
1.42 raeburn 4898: }
4899: }
1.41 raeburn 4900: }
1.6 raeburn 4901: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4902: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4903: $resulttext = &mt('Changes made:').'<ul>';
4904: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4905: if ($item eq 'loginvia') {
1.112 raeburn 4906: if (ref($changes{$item}) eq 'HASH') {
4907: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4908: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4909: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4910: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4911: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4912: $protocol = 'http' if ($protocol ne 'https');
4913: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4914:
4915: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4916: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4917: } else {
4918: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4919: }
4920: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4921: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4922: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4923: }
4924: $resulttext .= '</li>';
4925: } else {
4926: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4927: }
1.112 raeburn 4928: } else {
1.128 raeburn 4929: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4930: }
4931: }
1.128 raeburn 4932: $resulttext .= '</ul></li>';
1.112 raeburn 4933: }
1.168 raeburn 4934: } elsif ($item eq 'helpurl') {
4935: if (ref($changes{$item}) eq 'HASH') {
4936: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4937: if (grep(/^\Q$lang\E$/,@delurls)) {
4938: my ($chg,$link);
4939: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4940: if ($lang eq 'nolang') {
4941: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4942: } else {
4943: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4944: }
4945: $resulttext .= '<li>'.$chg.'</li>';
4946: } else {
4947: my $chg;
4948: if ($lang eq 'nolang') {
4949: $chg = &mt('custom log-in help file for no preferred language');
4950: } else {
4951: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4952: }
4953: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4954: $loginhash{'login'}{'helpurl'}{$lang}.
4955: '?inhibitmenu=yes',$chg,600,500).
4956: '</li>';
4957: }
4958: }
4959: }
1.169 raeburn 4960: } elsif ($item eq 'captcha') {
4961: if (ref($loginhash{'login'}) eq 'HASH') {
4962: my $chgtxt;
4963: if ($loginhash{'login'}{$item} eq 'notused') {
4964: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4965: } else {
4966: my %captchas = &captcha_phrases();
4967: if ($captchas{$loginhash{'login'}{$item}}) {
4968: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4969: } else {
4970: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4971: }
4972: }
4973: $resulttext .= '<li>'.$chgtxt.'</li>';
4974: }
4975: } elsif ($item eq 'recaptchakeys') {
4976: if (ref($loginhash{'login'}) eq 'HASH') {
4977: my ($privkey,$pubkey);
4978: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4979: $pubkey = $loginhash{'login'}{$item}{'public'};
4980: $privkey = $loginhash{'login'}{$item}{'private'};
4981: }
4982: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4983: if (!$pubkey) {
4984: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4985: } else {
4986: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4987: }
4988: if (!$privkey) {
4989: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4990: } else {
4991: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4992: }
4993: $chgtxt .= '</ul>';
4994: $resulttext .= '<li>'.$chgtxt.'</li>';
4995: }
1.41 raeburn 4996: } else {
4997: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4998: }
1.1 raeburn 4999: }
1.6 raeburn 5000: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5001: } else {
5002: $resulttext = &mt('No changes made to log-in page settings');
5003: }
5004: } else {
1.11 albertel 5005: $resulttext = '<span class="LC_error">'.
5006: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5007: }
1.6 raeburn 5008: if ($errors) {
1.9 raeburn 5009: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5010: $errors.'</ul>';
5011: }
5012: return $resulttext;
5013: }
5014:
5015: sub color_font_choices {
5016: my %choices =
5017: &Apache::lonlocal::texthash (
5018: img => "Header",
5019: bgs => "Background colors",
5020: links => "Link colors",
1.55 raeburn 5021: images => "Images",
1.6 raeburn 5022: font => "Font color",
1.97 tempelho 5023: fontmenu => "Font Menu",
1.76 raeburn 5024: pgbg => "Page",
1.6 raeburn 5025: tabbg => "Header",
5026: sidebg => "Border",
5027: link => "Link",
5028: alink => "Active link",
5029: vlink => "Visited link",
5030: );
5031: return %choices;
5032: }
5033:
5034: sub modify_rolecolors {
1.9 raeburn 5035: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5036: my ($resulttext,%rolehash);
5037: $rolehash{'rolecolors'} = {};
1.55 raeburn 5038: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5039: if ($domconfig{'rolecolors'} eq '') {
5040: $domconfig{'rolecolors'} = {};
5041: }
5042: }
1.9 raeburn 5043: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5044: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5045: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5046: $dom);
5047: if ($putresult eq 'ok') {
5048: if (keys(%changes) > 0) {
1.41 raeburn 5049: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5050: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5051: $rolehash{'rolecolors'});
5052: } else {
5053: $resulttext = &mt('No changes made to default color schemes');
5054: }
5055: } else {
1.11 albertel 5056: $resulttext = '<span class="LC_error">'.
5057: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5058: }
5059: if ($errors) {
5060: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5061: $errors.'</ul>';
5062: }
5063: return $resulttext;
5064: }
5065:
5066: sub modify_colors {
1.9 raeburn 5067: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5068: my (%changes,%choices);
1.51 raeburn 5069: my @bgs;
1.6 raeburn 5070: my @links = ('link','alink','vlink');
1.41 raeburn 5071: my @logintext;
1.6 raeburn 5072: my @images;
5073: my $servadm = $r->dir_config('lonAdmEMail');
5074: my $errors;
5075: foreach my $role (@{$roles}) {
5076: if ($role eq 'login') {
1.12 raeburn 5077: %choices = &login_choices();
1.41 raeburn 5078: @logintext = ('textcol','bgcol');
1.12 raeburn 5079: } else {
5080: %choices = &color_font_choices();
1.107 raeburn 5081: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5082: }
5083: if ($role eq 'login') {
1.41 raeburn 5084: @images = ('img','logo','domlogo','login');
1.51 raeburn 5085: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5086: } else {
5087: @images = ('img');
1.51 raeburn 5088: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5089: }
5090: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5091: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5092: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5093: }
1.46 raeburn 5094: my ($configuserok,$author_ok,$switchserver) =
5095: &config_check($dom,$confname,$servadm);
1.9 raeburn 5096: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5097: if (ref($domconfig->{$role}) ne 'HASH') {
5098: $domconfig->{$role} = {};
5099: }
1.8 raeburn 5100: foreach my $img (@images) {
1.70 raeburn 5101: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5102: if (defined($env{'form.login_showlogo_'.$img})) {
5103: $confhash->{$role}{'showlogo'}{$img} = 1;
5104: } else {
5105: $confhash->{$role}{'showlogo'}{$img} = 0;
5106: }
5107: }
1.18 albertel 5108: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5109: && !defined($domconfig->{$role}{$img})
5110: && !$env{'form.'.$role.'_del_'.$img}
5111: && $env{'form.'.$role.'_import_'.$img}) {
5112: # import the old configured image from the .tab setting
5113: # if they haven't provided a new one
5114: $domconfig->{$role}{$img} =
5115: $env{'form.'.$role.'_import_'.$img};
5116: }
1.6 raeburn 5117: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5118: my $error;
1.6 raeburn 5119: if ($configuserok eq 'ok') {
1.9 raeburn 5120: if ($switchserver) {
1.12 raeburn 5121: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5122: } else {
5123: if ($author_ok eq 'ok') {
5124: my ($result,$logourl) =
5125: &publishlogo($r,'upload',$role.'_'.$img,
5126: $dom,$confname,$img,$width,$height);
5127: if ($result eq 'ok') {
5128: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5129: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5130: } else {
1.12 raeburn 5131: $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 5132: }
5133: } else {
1.46 raeburn 5134: $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 5135: }
5136: }
5137: } else {
1.46 raeburn 5138: $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 5139: }
5140: if ($error) {
1.8 raeburn 5141: &Apache::lonnet::logthis($error);
1.11 albertel 5142: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5143: }
5144: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5145: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5146: my $error;
5147: if ($configuserok eq 'ok') {
5148: # is confname an author?
5149: if ($switchserver eq '') {
5150: if ($author_ok eq 'ok') {
5151: my ($result,$logourl) =
5152: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5153: $dom,$confname,$img,$width,$height);
5154: if ($result eq 'ok') {
5155: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5156: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5157: }
5158: }
5159: }
5160: }
1.6 raeburn 5161: }
5162: }
5163: }
5164: if (ref($domconfig) eq 'HASH') {
5165: if (ref($domconfig->{$role}) eq 'HASH') {
5166: foreach my $img (@images) {
5167: if ($domconfig->{$role}{$img} ne '') {
5168: if ($env{'form.'.$role.'_del_'.$img}) {
5169: $confhash->{$role}{$img} = '';
1.12 raeburn 5170: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5171: } else {
1.9 raeburn 5172: if ($confhash->{$role}{$img} eq '') {
5173: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5174: }
1.6 raeburn 5175: }
5176: } else {
5177: if ($env{'form.'.$role.'_del_'.$img}) {
5178: $confhash->{$role}{$img} = '';
1.12 raeburn 5179: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5180: }
5181: }
1.70 raeburn 5182: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5183: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5184: if ($confhash->{$role}{'showlogo'}{$img} ne
5185: $domconfig->{$role}{'showlogo'}{$img}) {
5186: $changes{$role}{'showlogo'}{$img} = 1;
5187: }
5188: } else {
5189: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5190: $changes{$role}{'showlogo'}{$img} = 1;
5191: }
5192: }
5193: }
5194: }
1.6 raeburn 5195: if ($domconfig->{$role}{'font'} ne '') {
5196: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5197: $changes{$role}{'font'} = 1;
5198: }
5199: } else {
5200: if ($confhash->{$role}{'font'}) {
5201: $changes{$role}{'font'} = 1;
5202: }
5203: }
1.107 raeburn 5204: if ($role ne 'login') {
5205: if ($domconfig->{$role}{'fontmenu'} ne '') {
5206: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5207: $changes{$role}{'fontmenu'} = 1;
5208: }
5209: } else {
5210: if ($confhash->{$role}{'fontmenu'}) {
5211: $changes{$role}{'fontmenu'} = 1;
5212: }
1.97 tempelho 5213: }
5214: }
1.6 raeburn 5215: foreach my $item (@bgs) {
5216: if ($domconfig->{$role}{$item} ne '') {
5217: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5218: $changes{$role}{'bgs'}{$item} = 1;
5219: }
5220: } else {
5221: if ($confhash->{$role}{$item}) {
5222: $changes{$role}{'bgs'}{$item} = 1;
5223: }
5224: }
5225: }
5226: foreach my $item (@links) {
5227: if ($domconfig->{$role}{$item} ne '') {
5228: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5229: $changes{$role}{'links'}{$item} = 1;
5230: }
5231: } else {
5232: if ($confhash->{$role}{$item}) {
5233: $changes{$role}{'links'}{$item} = 1;
5234: }
5235: }
5236: }
1.41 raeburn 5237: foreach my $item (@logintext) {
5238: if ($domconfig->{$role}{$item} ne '') {
5239: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5240: $changes{$role}{'logintext'}{$item} = 1;
5241: }
5242: } else {
5243: if ($confhash->{$role}{$item}) {
5244: $changes{$role}{'logintext'}{$item} = 1;
5245: }
5246: }
5247: }
1.6 raeburn 5248: } else {
5249: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5250: \@logintext,$confhash,\%changes);
1.6 raeburn 5251: }
5252: } else {
5253: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5254: \@logintext,$confhash,\%changes);
1.6 raeburn 5255: }
5256: }
5257: return ($errors,%changes);
5258: }
5259:
1.46 raeburn 5260: sub config_check {
5261: my ($dom,$confname,$servadm) = @_;
5262: my ($configuserok,$author_ok,$switchserver,%currroles);
5263: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5264: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5265: $confname,$servadm);
5266: if ($configuserok eq 'ok') {
5267: $switchserver = &check_switchserver($dom,$confname);
5268: if ($switchserver eq '') {
5269: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5270: }
5271: }
5272: return ($configuserok,$author_ok,$switchserver);
5273: }
5274:
1.6 raeburn 5275: sub default_change_checker {
1.41 raeburn 5276: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5277: foreach my $item (@{$links}) {
5278: if ($confhash->{$role}{$item}) {
5279: $changes->{$role}{'links'}{$item} = 1;
5280: }
5281: }
5282: foreach my $item (@{$bgs}) {
5283: if ($confhash->{$role}{$item}) {
5284: $changes->{$role}{'bgs'}{$item} = 1;
5285: }
5286: }
1.41 raeburn 5287: foreach my $item (@{$logintext}) {
5288: if ($confhash->{$role}{$item}) {
5289: $changes->{$role}{'logintext'}{$item} = 1;
5290: }
5291: }
1.6 raeburn 5292: foreach my $img (@{$images}) {
5293: if ($env{'form.'.$role.'_del_'.$img}) {
5294: $confhash->{$role}{$img} = '';
1.12 raeburn 5295: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5296: }
1.70 raeburn 5297: if ($role eq 'login') {
5298: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5299: $changes->{$role}{'showlogo'}{$img} = 1;
5300: }
5301: }
1.6 raeburn 5302: }
5303: if ($confhash->{$role}{'font'}) {
5304: $changes->{$role}{'font'} = 1;
5305: }
1.48 raeburn 5306: }
1.6 raeburn 5307:
5308: sub display_colorchgs {
5309: my ($dom,$changes,$roles,$confhash) = @_;
5310: my (%choices,$resulttext);
5311: if (!grep(/^login$/,@{$roles})) {
5312: $resulttext = &mt('Changes made:').'<br />';
5313: }
5314: foreach my $role (@{$roles}) {
5315: if ($role eq 'login') {
5316: %choices = &login_choices();
5317: } else {
5318: %choices = &color_font_choices();
5319: }
5320: if (ref($changes->{$role}) eq 'HASH') {
5321: if ($role ne 'login') {
5322: $resulttext .= '<h4>'.&mt($role).'</h4>';
5323: }
5324: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5325: if ($role ne 'login') {
5326: $resulttext .= '<ul>';
5327: }
5328: if (ref($changes->{$role}{$key}) eq 'HASH') {
5329: if ($role ne 'login') {
5330: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5331: }
5332: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5333: if (($role eq 'login') && ($key eq 'showlogo')) {
5334: if ($confhash->{$role}{$key}{$item}) {
5335: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5336: } else {
5337: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5338: }
5339: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5340: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5341: } else {
1.12 raeburn 5342: my $newitem = $confhash->{$role}{$item};
5343: if ($key eq 'images') {
5344: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5345: }
5346: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5347: }
5348: }
5349: if ($role ne 'login') {
5350: $resulttext .= '</ul></li>';
5351: }
5352: } else {
5353: if ($confhash->{$role}{$key} eq '') {
5354: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5355: } else {
5356: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5357: }
5358: }
5359: if ($role ne 'login') {
5360: $resulttext .= '</ul>';
5361: }
5362: }
5363: }
5364: }
1.3 raeburn 5365: return $resulttext;
1.1 raeburn 5366: }
5367:
1.9 raeburn 5368: sub thumb_dimensions {
5369: return ('200','50');
5370: }
5371:
1.16 raeburn 5372: sub check_dimensions {
5373: my ($inputfile) = @_;
5374: my ($fullwidth,$fullheight);
5375: if ($inputfile =~ m|^[/\w.\-]+$|) {
5376: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5377: my $imageinfo = <PIPE>;
5378: if (!close(PIPE)) {
5379: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5380: }
5381: chomp($imageinfo);
5382: my ($fullsize) =
1.21 raeburn 5383: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5384: if ($fullsize) {
5385: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5386: }
5387: }
5388: }
5389: return ($fullwidth,$fullheight);
5390: }
5391:
1.9 raeburn 5392: sub check_configuser {
5393: my ($uhome,$dom,$confname,$servadm) = @_;
5394: my ($configuserok,%currroles);
5395: if ($uhome eq 'no_host') {
5396: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5397: my $configpass = &LONCAPA::Enrollment::create_password();
5398: $configuserok =
5399: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5400: $configpass,'','','','','',undef,$servadm);
5401: } else {
5402: $configuserok = 'ok';
5403: %currroles =
5404: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5405: }
5406: return ($configuserok,%currroles);
5407: }
5408:
5409: sub check_authorstatus {
5410: my ($dom,$confname,%currroles) = @_;
5411: my $author_ok;
1.40 raeburn 5412: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5413: my $start = time;
5414: my $end = 0;
5415: $author_ok =
5416: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5417: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5418: } else {
5419: $author_ok = 'ok';
5420: }
5421: return $author_ok;
5422: }
5423:
5424: sub publishlogo {
1.46 raeburn 5425: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5426: my ($output,$fname,$logourl);
5427: if ($action eq 'upload') {
5428: $fname=$env{'form.'.$formname.'.filename'};
5429: chop($env{'form.'.$formname});
5430: } else {
5431: ($fname) = ($formname =~ /([^\/]+)$/);
5432: }
1.46 raeburn 5433: if ($savefileas ne '') {
5434: $fname = $savefileas;
5435: }
1.9 raeburn 5436: $fname=&Apache::lonnet::clean_filename($fname);
5437: # See if there is anything left
5438: unless ($fname) { return ('error: no uploaded file'); }
5439: $fname="$subdir/$fname";
1.164 raeburn 5440: my $docroot=$r->dir_config('lonDocRoot');
5441: my $filepath="$docroot/priv";
5442: my $relpath = "$dom/$confname";
1.9 raeburn 5443: my ($fnamepath,$file,$fetchthumb);
5444: $file=$fname;
5445: if ($fname=~m|/|) {
5446: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5447: }
1.164 raeburn 5448: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5449: my $count;
1.164 raeburn 5450: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5451: $filepath.="/$parts[$count]";
5452: if ((-e $filepath)!=1) {
5453: mkdir($filepath,02770);
5454: }
5455: }
5456: # Check for bad extension and disallow upload
5457: if ($file=~/\.(\w+)$/ &&
5458: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5459: $output =
5460: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5461: } elsif ($file=~/\.(\w+)$/ &&
5462: !defined(&Apache::loncommon::fileembstyle($1))) {
5463: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5464: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5465: $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 5466: } elsif (-d "$filepath/$file") {
5467: $output = &mt('File name is a directory name - rename the file and re-upload');
5468: } else {
5469: my $source = $filepath.'/'.$file;
5470: my $logfile;
5471: if (!open($logfile,">>$source".'.log')) {
5472: return (&mt('No write permission to Construction Space'));
5473: }
5474: print $logfile
5475: "\n================= Publish ".localtime()." ================\n".
5476: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5477: # Save the file
5478: if (!open(FH,'>'.$source)) {
5479: &Apache::lonnet::logthis('Failed to create '.$source);
5480: return (&mt('Failed to create file'));
5481: }
5482: if ($action eq 'upload') {
5483: if (!print FH ($env{'form.'.$formname})) {
5484: &Apache::lonnet::logthis('Failed to write to '.$source);
5485: return (&mt('Failed to write file'));
5486: }
5487: } else {
5488: my $original = &Apache::lonnet::filelocation('',$formname);
5489: if(!copy($original,$source)) {
5490: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5491: return (&mt('Failed to write file'));
5492: }
5493: }
5494: close(FH);
5495: chmod(0660, $source); # Permissions to rw-rw---.
5496:
5497: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5498: my $copyfile=$targetdir.'/'.$file;
5499:
5500: my @parts=split(/\//,$targetdir);
5501: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5502: for (my $count=5;$count<=$#parts;$count++) {
5503: $path.="/$parts[$count]";
5504: if (!-e $path) {
5505: print $logfile "\nCreating directory ".$path;
5506: mkdir($path,02770);
5507: }
5508: }
5509: my $versionresult;
5510: if (-e $copyfile) {
5511: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5512: } else {
5513: $versionresult = 'ok';
5514: }
5515: if ($versionresult eq 'ok') {
5516: if (copy($source,$copyfile)) {
5517: print $logfile "\nCopied original source to ".$copyfile."\n";
5518: $output = 'ok';
5519: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5520: push(@{$modified_urls},[$copyfile,$source]);
5521: my $metaoutput =
5522: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5523: unless ($registered_cleanup) {
5524: my $handlers = $r->get_handlers('PerlCleanupHandler');
5525: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5526: $registered_cleanup=1;
5527: }
1.9 raeburn 5528: } else {
5529: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5530: $output = &mt('Failed to copy file to RES space').", $!";
5531: }
5532: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5533: my $inputfile = $filepath.'/'.$file;
5534: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5535: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5536: if ($fullwidth ne '' && $fullheight ne '') {
5537: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5538: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5539: system("convert -sample $thumbsize $inputfile $outfile");
5540: chmod(0660, $filepath.'/tn-'.$file);
5541: if (-e $outfile) {
5542: my $copyfile=$targetdir.'/tn-'.$file;
5543: if (copy($outfile,$copyfile)) {
5544: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5545: my $thumb_metaoutput =
5546: &write_metadata($dom,$confname,$formname,
5547: $targetdir,'tn-'.$file,$logfile);
5548: push(@{$modified_urls},[$copyfile,$outfile]);
5549: unless ($registered_cleanup) {
5550: my $handlers = $r->get_handlers('PerlCleanupHandler');
5551: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5552: $registered_cleanup=1;
5553: }
1.16 raeburn 5554: } else {
5555: print $logfile "\nUnable to write ".$copyfile.
5556: ':'.$!."\n";
5557: }
5558: }
1.9 raeburn 5559: }
5560: }
5561: }
5562: } else {
5563: $output = $versionresult;
5564: }
5565: }
5566: return ($output,$logourl);
5567: }
5568:
5569: sub logo_versioning {
5570: my ($targetdir,$file,$logfile) = @_;
5571: my $target = $targetdir.'/'.$file;
5572: my ($maxversion,$fn,$extn,$output);
5573: $maxversion = 0;
5574: if ($file =~ /^(.+)\.(\w+)$/) {
5575: $fn=$1;
5576: $extn=$2;
5577: }
5578: opendir(DIR,$targetdir);
5579: while (my $filename=readdir(DIR)) {
5580: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5581: $maxversion=($1>$maxversion)?$1:$maxversion;
5582: }
5583: }
5584: $maxversion++;
5585: print $logfile "\nCreating old version ".$maxversion."\n";
5586: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5587: if (copy($target,$copyfile)) {
5588: print $logfile "Copied old target to ".$copyfile."\n";
5589: $copyfile=$copyfile.'.meta';
5590: if (copy($target.'.meta',$copyfile)) {
5591: print $logfile "Copied old target metadata to ".$copyfile."\n";
5592: $output = 'ok';
5593: } else {
5594: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5595: $output = &mt('Failed to copy old meta').", $!, ";
5596: }
5597: } else {
5598: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5599: $output = &mt('Failed to copy old target').", $!, ";
5600: }
5601: return $output;
5602: }
5603:
5604: sub write_metadata {
5605: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5606: my (%metadatafields,%metadatakeys,$output);
5607: $metadatafields{'title'}=$formname;
5608: $metadatafields{'creationdate'}=time;
5609: $metadatafields{'lastrevisiondate'}=time;
5610: $metadatafields{'copyright'}='public';
5611: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5612: $env{'user.domain'};
5613: $metadatafields{'authorspace'}=$confname.':'.$dom;
5614: $metadatafields{'domain'}=$dom;
5615: {
5616: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5617: my $mfh;
1.155 raeburn 5618: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 ! raeburn 5619: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5620: unless ($_=~/\./) {
5621: my $unikey=$_;
5622: $unikey=~/^([A-Za-z]+)/;
5623: my $tag=$1;
5624: $tag=~tr/A-Z/a-z/;
5625: print $mfh "\n\<$tag";
5626: foreach (split(/\,/,$metadatakeys{$unikey})) {
5627: my $value=$metadatafields{$unikey.'.'.$_};
5628: $value=~s/\"/\'\'/g;
5629: print $mfh ' '.$_.'="'.$value.'"';
5630: }
5631: print $mfh '>'.
5632: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5633: .'</'.$tag.'>';
5634: }
5635: }
5636: $output = 'ok';
5637: print $logfile "\nWrote metadata";
5638: close($mfh);
5639: } else {
5640: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5641: $output = &mt('Could not write metadata');
5642: }
5643: }
1.155 raeburn 5644: return $output;
5645: }
5646:
5647: sub notifysubscribed {
5648: foreach my $targetsource (@{$modified_urls}){
5649: next unless (ref($targetsource) eq 'ARRAY');
5650: my ($target,$source)=@{$targetsource};
5651: if ($source ne '') {
5652: if (open(my $logfh,'>>'.$source.'.log')) {
5653: print $logfh "\nCleanup phase: Notifications\n";
5654: my @subscribed=&subscribed_hosts($target);
5655: foreach my $subhost (@subscribed) {
5656: print $logfh "\nNotifying host ".$subhost.':';
5657: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5658: print $logfh $reply;
5659: }
5660: my @subscribedmeta=&subscribed_hosts("$target.meta");
5661: foreach my $subhost (@subscribedmeta) {
5662: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5663: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5664: $subhost);
5665: print $logfh $reply;
5666: }
5667: print $logfh "\n============ Done ============\n";
1.160 raeburn 5668: close($logfh);
1.155 raeburn 5669: }
5670: }
5671: }
5672: return OK;
5673: }
5674:
5675: sub subscribed_hosts {
5676: my ($target) = @_;
5677: my @subscribed;
5678: if (open(my $fh,"<$target.subscription")) {
5679: while (my $subline=<$fh>) {
5680: if ($subline =~ /^($match_lonid):/) {
5681: my $host = $1;
5682: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5683: unless (grep(/^\Q$host\E$/,@subscribed)) {
5684: push(@subscribed,$host);
5685: }
5686: }
5687: }
5688: }
5689: }
5690: return @subscribed;
1.9 raeburn 5691: }
5692:
5693: sub check_switchserver {
5694: my ($dom,$confname) = @_;
5695: my ($allowed,$switchserver);
5696: my $home = &Apache::lonnet::homeserver($confname,$dom);
5697: if ($home eq 'no_host') {
5698: $home = &Apache::lonnet::domain($dom,'primary');
5699: }
5700: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5701: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5702: if (!$allowed) {
1.180 raeburn 5703: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5704: }
5705: return $switchserver;
5706: }
5707:
1.1 raeburn 5708: sub modify_quotas {
1.86 raeburn 5709: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5710: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5711: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5712: if ($action eq 'quotas') {
5713: $context = 'tools';
1.163 raeburn 5714: } else {
1.86 raeburn 5715: $context = $action;
5716: }
5717: if ($context eq 'requestcourses') {
1.98 raeburn 5718: @usertools = ('official','unofficial','community');
1.106 raeburn 5719: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5720: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5721: %titles = &courserequest_titles();
5722: $toolregexp = join('|',@usertools);
5723: %conditions = &courserequest_conditions();
1.163 raeburn 5724: } elsif ($context eq 'requestauthor') {
5725: @usertools = ('author');
5726: %titles = &authorrequest_titles();
1.86 raeburn 5727: } else {
1.162 raeburn 5728: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5729: %titles = &tool_titles();
1.86 raeburn 5730: }
1.72 raeburn 5731: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5732: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5733: foreach my $key (keys(%env)) {
1.101 raeburn 5734: if ($context eq 'requestcourses') {
5735: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5736: my $item = $1;
5737: my $type = $2;
5738: if ($type =~ /^limit_(.+)/) {
5739: $limithash{$item}{$1} = $env{$key};
5740: } else {
5741: $confhash{$item}{$type} = $env{$key};
5742: }
5743: }
1.163 raeburn 5744: } elsif ($context eq 'requestauthor') {
5745: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5746: $confhash{$1} = $env{$key};
5747: }
1.101 raeburn 5748: } else {
1.86 raeburn 5749: if ($key =~ /^form\.quota_(.+)$/) {
5750: $confhash{'defaultquota'}{$1} = $env{$key};
5751: }
1.101 raeburn 5752: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5753: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5754: }
1.72 raeburn 5755: }
5756: }
1.163 raeburn 5757: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5758: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5759: @approvalnotify = sort(@approvalnotify);
5760: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5761: if (ref($domconfig{$action}) eq 'HASH') {
5762: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5763: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5764: $changes{'notify'}{'approval'} = 1;
5765: }
5766: } else {
1.144 raeburn 5767: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5768: $changes{'notify'}{'approval'} = 1;
5769: }
5770: }
5771: } else {
1.144 raeburn 5772: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5773: $changes{'notify'}{'approval'} = 1;
5774: }
5775: }
5776: } else {
1.86 raeburn 5777: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5778: }
1.72 raeburn 5779: foreach my $item (@usertools) {
5780: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5781: my $unset;
1.101 raeburn 5782: if ($context eq 'requestcourses') {
1.104 raeburn 5783: $unset = '0';
5784: if ($type eq '_LC_adv') {
5785: $unset = '';
5786: }
1.101 raeburn 5787: if ($confhash{$item}{$type} eq 'autolimit') {
5788: $confhash{$item}{$type} .= '=';
5789: unless ($limithash{$item}{$type} =~ /\D/) {
5790: $confhash{$item}{$type} .= $limithash{$item}{$type};
5791: }
5792: }
1.163 raeburn 5793: } elsif ($context eq 'requestauthor') {
5794: $unset = '0';
5795: if ($type eq '_LC_adv') {
5796: $unset = '';
5797: }
1.72 raeburn 5798: } else {
1.101 raeburn 5799: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5800: $confhash{$item}{$type} = 1;
5801: } else {
5802: $confhash{$item}{$type} = 0;
5803: }
1.72 raeburn 5804: }
1.86 raeburn 5805: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5806: if ($action eq 'requestauthor') {
5807: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5808: $changes{$type} = 1;
5809: }
5810: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5811: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5812: $changes{$item}{$type} = 1;
5813: }
5814: } else {
5815: if ($context eq 'requestcourses') {
1.104 raeburn 5816: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5817: $changes{$item}{$type} = 1;
5818: }
5819: } else {
5820: if (!$confhash{$item}{$type}) {
5821: $changes{$item}{$type} = 1;
5822: }
5823: }
5824: }
5825: } else {
5826: if ($context eq 'requestcourses') {
1.104 raeburn 5827: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5828: $changes{$item}{$type} = 1;
5829: }
1.163 raeburn 5830: } elsif ($context eq 'requestauthor') {
5831: if ($confhash{$type} ne $unset) {
5832: $changes{$type} = 1;
5833: }
1.72 raeburn 5834: } else {
5835: if (!$confhash{$item}{$type}) {
5836: $changes{$item}{$type} = 1;
5837: }
5838: }
5839: }
1.1 raeburn 5840: }
5841: }
1.163 raeburn 5842: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5843: if (ref($domconfig{'quotas'}) eq 'HASH') {
5844: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5845: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5846: if (exists($confhash{'defaultquota'}{$key})) {
5847: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5848: $changes{'defaultquota'}{$key} = 1;
5849: }
5850: } else {
5851: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5852: }
5853: }
1.86 raeburn 5854: } else {
5855: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5856: if (exists($confhash{'defaultquota'}{$key})) {
5857: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5858: $changes{'defaultquota'}{$key} = 1;
5859: }
5860: } else {
5861: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5862: }
1.1 raeburn 5863: }
5864: }
5865: }
1.86 raeburn 5866: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5867: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5868: if (ref($domconfig{'quotas'}) eq 'HASH') {
5869: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5870: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5871: $changes{'defaultquota'}{$key} = 1;
5872: }
5873: } else {
5874: if (!exists($domconfig{'quotas'}{$key})) {
5875: $changes{'defaultquota'}{$key} = 1;
5876: }
1.72 raeburn 5877: }
5878: } else {
1.86 raeburn 5879: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5880: }
1.1 raeburn 5881: }
5882: }
5883: }
1.72 raeburn 5884:
1.163 raeburn 5885: if ($context eq 'requestauthor') {
5886: $domdefaults{'requestauthor'} = \%confhash;
5887: } else {
5888: foreach my $key (keys(%confhash)) {
5889: $domdefaults{$key} = $confhash{$key};
5890: }
1.72 raeburn 5891: }
1.163 raeburn 5892:
1.1 raeburn 5893: my %quotahash = (
1.86 raeburn 5894: $action => { %confhash }
1.1 raeburn 5895: );
5896: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5897: $dom);
5898: if ($putresult eq 'ok') {
5899: if (keys(%changes) > 0) {
1.72 raeburn 5900: my $cachetime = 24*60*60;
5901: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5902:
1.1 raeburn 5903: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5904: unless (($context eq 'requestcourses') ||
5905: ($context eq 'requestauthor')) {
1.86 raeburn 5906: if (ref($changes{'defaultquota'}) eq 'HASH') {
5907: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5908: foreach my $type (@{$types},'default') {
5909: if (defined($changes{'defaultquota'}{$type})) {
5910: my $typetitle = $usertypes->{$type};
5911: if ($type eq 'default') {
5912: $typetitle = $othertitle;
5913: }
5914: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5915: }
5916: }
1.86 raeburn 5917: $resulttext .= '</ul></li>';
1.72 raeburn 5918: }
5919: }
1.80 raeburn 5920: my %newenv;
1.72 raeburn 5921: foreach my $item (@usertools) {
1.163 raeburn 5922: my (%haschgs,%inconf);
5923: if ($context eq 'requestauthor') {
5924: %haschgs = %changes;
5925: %inconf = %confhash;
5926: } else {
5927: if (ref($changes{$item}) eq 'HASH') {
5928: %haschgs = %{$changes{$item}};
5929: }
5930: if (ref($confhash{$item}) eq 'HASH') {
5931: %inconf = %{$confhash{$item}};
5932: }
5933: }
5934: if (keys(%haschgs) > 0) {
1.80 raeburn 5935: my $newacc =
5936: &Apache::lonnet::usertools_access($env{'user.name'},
5937: $env{'user.domain'},
1.86 raeburn 5938: $item,'reload',$context);
1.163 raeburn 5939: if (($context eq 'requestcourses') ||
5940: ($context eq 'requestauthor')) {
1.108 raeburn 5941: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5942: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5943: }
5944: } else {
5945: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5946: $newenv{'environment.availabletools.'.$item} = $newacc;
5947: }
1.80 raeburn 5948: }
1.163 raeburn 5949: unless ($context eq 'requestauthor') {
5950: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5951: }
1.72 raeburn 5952: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5953: if ($haschgs{$type}) {
1.72 raeburn 5954: my $typetitle = $usertypes->{$type};
5955: if ($type eq 'default') {
5956: $typetitle = $othertitle;
5957: } elsif ($type eq '_LC_adv') {
5958: $typetitle = 'LON-CAPA Advanced Users';
5959: }
1.163 raeburn 5960: if ($inconf{$type}) {
1.101 raeburn 5961: if ($context eq 'requestcourses') {
5962: my $cond;
1.163 raeburn 5963: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5964: if ($1 eq '') {
5965: $cond = &mt('(Automatic processing of any request).');
5966: } else {
5967: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5968: }
5969: } else {
1.163 raeburn 5970: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5971: }
5972: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5973: } elsif ($context eq 'requestauthor') {
5974: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5975: $titles{$inconf{$type}},$typetitle);
5976:
1.101 raeburn 5977: } else {
5978: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5979: }
1.72 raeburn 5980: } else {
1.104 raeburn 5981: if ($type eq '_LC_adv') {
1.163 raeburn 5982: if ($inconf{$type} eq '0') {
1.104 raeburn 5983: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5984: } else {
5985: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5986: }
5987: } else {
5988: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5989: }
1.72 raeburn 5990: }
5991: }
1.26 raeburn 5992: }
1.163 raeburn 5993: unless ($context eq 'requestauthor') {
5994: $resulttext .= '</ul></li>';
5995: }
1.26 raeburn 5996: }
1.1 raeburn 5997: }
1.163 raeburn 5998: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5999: if (ref($changes{'notify'}) eq 'HASH') {
6000: if ($changes{'notify'}{'approval'}) {
6001: if (ref($confhash{'notify'}) eq 'HASH') {
6002: if ($confhash{'notify'}{'approval'}) {
6003: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6004: } else {
1.163 raeburn 6005: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6006: }
6007: }
6008: }
6009: }
6010: }
1.1 raeburn 6011: $resulttext .= '</ul>';
1.80 raeburn 6012: if (keys(%newenv)) {
6013: &Apache::lonnet::appenv(\%newenv);
6014: }
1.1 raeburn 6015: } else {
1.86 raeburn 6016: if ($context eq 'requestcourses') {
6017: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6018: } elsif ($context eq 'requestauthor') {
6019: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6020: } else {
1.90 weissno 6021: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6022: }
1.1 raeburn 6023: }
6024: } else {
1.11 albertel 6025: $resulttext = '<span class="LC_error">'.
6026: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6027: }
1.3 raeburn 6028: return $resulttext;
1.1 raeburn 6029: }
6030:
1.3 raeburn 6031: sub modify_autoenroll {
6032: my ($dom,%domconfig) = @_;
1.1 raeburn 6033: my ($resulttext,%changes);
6034: my %currautoenroll;
6035: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6036: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6037: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6038: }
6039: }
6040: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6041: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6042: sender => 'Sender for notification messages',
6043: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6044: my @offon = ('off','on');
1.17 raeburn 6045: my $sender_uname = $env{'form.sender_uname'};
6046: my $sender_domain = $env{'form.sender_domain'};
6047: if ($sender_domain eq '') {
6048: $sender_uname = '';
6049: } elsif ($sender_uname eq '') {
6050: $sender_domain = '';
6051: }
1.129 raeburn 6052: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6053: my %autoenrollhash = (
1.129 raeburn 6054: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6055: 'sender_uname' => $sender_uname,
6056: 'sender_domain' => $sender_domain,
6057: 'co-owners' => $coowners,
1.1 raeburn 6058: }
6059: );
1.4 raeburn 6060: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6061: $dom);
1.1 raeburn 6062: if ($putresult eq 'ok') {
6063: if (exists($currautoenroll{'run'})) {
6064: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6065: $changes{'run'} = 1;
6066: }
6067: } elsif ($autorun) {
6068: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6069: $changes{'run'} = 1;
1.1 raeburn 6070: }
6071: }
1.17 raeburn 6072: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6073: $changes{'sender'} = 1;
6074: }
1.17 raeburn 6075: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6076: $changes{'sender'} = 1;
6077: }
1.129 raeburn 6078: if ($currautoenroll{'co-owners'} ne '') {
6079: if ($currautoenroll{'co-owners'} ne $coowners) {
6080: $changes{'coowners'} = 1;
6081: }
6082: } elsif ($coowners) {
6083: $changes{'coowners'} = 1;
6084: }
1.1 raeburn 6085: if (keys(%changes) > 0) {
6086: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6087: if ($changes{'run'}) {
1.1 raeburn 6088: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6089: }
6090: if ($changes{'sender'}) {
1.17 raeburn 6091: if ($sender_uname eq '' || $sender_domain eq '') {
6092: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6093: } else {
6094: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6095: }
1.1 raeburn 6096: }
1.129 raeburn 6097: if ($changes{'coowners'}) {
6098: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6099: &Apache::loncommon::devalidate_domconfig_cache($dom);
6100: }
1.1 raeburn 6101: $resulttext .= '</ul>';
6102: } else {
6103: $resulttext = &mt('No changes made to auto-enrollment settings');
6104: }
6105: } else {
1.11 albertel 6106: $resulttext = '<span class="LC_error">'.
6107: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6108: }
1.3 raeburn 6109: return $resulttext;
1.1 raeburn 6110: }
6111:
6112: sub modify_autoupdate {
1.3 raeburn 6113: my ($dom,%domconfig) = @_;
1.1 raeburn 6114: my ($resulttext,%currautoupdate,%fields,%changes);
6115: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6116: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6117: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6118: }
6119: }
6120: my @offon = ('off','on');
6121: my %title = &Apache::lonlocal::texthash (
6122: run => 'Auto-update:',
6123: classlists => 'Updates to user information in classlists?'
6124: );
1.44 raeburn 6125: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6126: my %fieldtitles = &Apache::lonlocal::texthash (
6127: id => 'Student/Employee ID',
1.20 raeburn 6128: permanentemail => 'E-mail address',
1.1 raeburn 6129: lastname => 'Last Name',
6130: firstname => 'First Name',
6131: middlename => 'Middle Name',
1.132 raeburn 6132: generation => 'Generation',
1.1 raeburn 6133: );
1.142 raeburn 6134: $othertitle = &mt('All users');
1.1 raeburn 6135: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6136: $othertitle = &mt('Other users');
1.1 raeburn 6137: }
6138: foreach my $key (keys(%env)) {
6139: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6140: my ($usertype,$item) = ($1,$2);
6141: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6142: if ($usertype eq 'default') {
6143: push(@{$fields{$1}},$2);
6144: } elsif (ref($types) eq 'ARRAY') {
6145: if (grep(/^\Q$usertype\E$/,@{$types})) {
6146: push(@{$fields{$1}},$2);
6147: }
6148: }
6149: }
1.1 raeburn 6150: }
6151: }
1.131 raeburn 6152: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6153: @lockablenames = sort(@lockablenames);
6154: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6155: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6156: if (@changed) {
6157: $changes{'lockablenames'} = 1;
6158: }
6159: } else {
6160: if (@lockablenames) {
6161: $changes{'lockablenames'} = 1;
6162: }
6163: }
1.1 raeburn 6164: my %updatehash = (
6165: autoupdate => { run => $env{'form.autoupdate_run'},
6166: classlists => $env{'form.classlists'},
6167: fields => {%fields},
1.131 raeburn 6168: lockablenames => \@lockablenames,
1.1 raeburn 6169: }
6170: );
6171: foreach my $key (keys(%currautoupdate)) {
6172: if (($key eq 'run') || ($key eq 'classlists')) {
6173: if (exists($updatehash{autoupdate}{$key})) {
6174: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6175: $changes{$key} = 1;
6176: }
6177: }
6178: } elsif ($key eq 'fields') {
6179: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6180: foreach my $item (@{$types},'default') {
1.1 raeburn 6181: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6182: my $change = 0;
6183: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6184: if (!exists($fields{$item})) {
6185: $change = 1;
1.132 raeburn 6186: last;
1.1 raeburn 6187: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6188: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6189: $change = 1;
1.132 raeburn 6190: last;
1.1 raeburn 6191: }
6192: }
6193: }
6194: if ($change) {
6195: push(@{$changes{$key}},$item);
6196: }
1.26 raeburn 6197: }
1.1 raeburn 6198: }
6199: }
1.131 raeburn 6200: } elsif ($key eq 'lockablenames') {
6201: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6202: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6203: if (@changed) {
6204: $changes{'lockablenames'} = 1;
6205: }
6206: } else {
6207: if (@lockablenames) {
6208: $changes{'lockablenames'} = 1;
6209: }
6210: }
6211: }
6212: }
6213: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6214: if (@lockablenames) {
6215: $changes{'lockablenames'} = 1;
1.1 raeburn 6216: }
6217: }
1.26 raeburn 6218: foreach my $item (@{$types},'default') {
6219: if (defined($fields{$item})) {
6220: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6221: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6222: my $change = 0;
6223: if (ref($fields{$item}) eq 'ARRAY') {
6224: foreach my $type (@{$fields{$item}}) {
6225: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6226: $change = 1;
6227: last;
6228: }
6229: }
6230: }
6231: if ($change) {
6232: push(@{$changes{'fields'}},$item);
6233: }
6234: } else {
1.26 raeburn 6235: push(@{$changes{'fields'}},$item);
6236: }
6237: } else {
6238: push(@{$changes{'fields'}},$item);
1.1 raeburn 6239: }
6240: }
6241: }
6242: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6243: $dom);
6244: if ($putresult eq 'ok') {
6245: if (keys(%changes) > 0) {
6246: $resulttext = &mt('Changes made:').'<ul>';
6247: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6248: if ($key eq 'lockablenames') {
6249: $resulttext .= '<li>';
6250: if (@lockablenames) {
6251: $usertypes->{'default'} = $othertitle;
6252: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6253: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6254: } else {
6255: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6256: }
6257: $resulttext .= '</li>';
6258: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6259: foreach my $item (@{$changes{$key}}) {
6260: my @newvalues;
6261: foreach my $type (@{$fields{$item}}) {
6262: push(@newvalues,$fieldtitles{$type});
6263: }
1.3 raeburn 6264: my $newvaluestr;
6265: if (@newvalues > 0) {
6266: $newvaluestr = join(', ',@newvalues);
6267: } else {
6268: $newvaluestr = &mt('none');
1.6 raeburn 6269: }
1.1 raeburn 6270: if ($item eq 'default') {
1.26 raeburn 6271: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6272: } else {
1.26 raeburn 6273: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6274: }
6275: }
6276: } else {
6277: my $newvalue;
6278: if ($key eq 'run') {
6279: $newvalue = $offon[$env{'form.autoupdate_run'}];
6280: } else {
6281: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6282: }
1.1 raeburn 6283: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6284: }
6285: }
6286: $resulttext .= '</ul>';
6287: } else {
1.3 raeburn 6288: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6289: }
6290: } else {
1.11 albertel 6291: $resulttext = '<span class="LC_error">'.
6292: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6293: }
1.3 raeburn 6294: return $resulttext;
1.1 raeburn 6295: }
6296:
1.125 raeburn 6297: sub modify_autocreate {
6298: my ($dom,%domconfig) = @_;
6299: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6300: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6301: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6302: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6303: }
6304: }
6305: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6306: req => 'Auto-creation of validated requests for official courses',
6307: xmldc => 'Identity of course creator of courses from XML files',
6308: );
6309: my @types = ('xml','req');
6310: foreach my $item (@types) {
6311: $newvals{$item} = $env{'form.autocreate_'.$item};
6312: $newvals{$item} =~ s/\D//g;
6313: $newvals{$item} = 0 if ($newvals{$item} eq '');
6314: }
6315: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6316: my %domcoords = &get_active_dcs($dom);
6317: unless (exists($domcoords{$newvals{'xmldc'}})) {
6318: $newvals{'xmldc'} = '';
6319: }
6320: %autocreatehash = (
6321: autocreate => { xml => $newvals{'xml'},
6322: req => $newvals{'req'},
6323: }
6324: );
6325: if ($newvals{'xmldc'} ne '') {
6326: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6327: }
6328: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6329: $dom);
6330: if ($putresult eq 'ok') {
6331: my @items = @types;
6332: if ($newvals{'xml'}) {
6333: push(@items,'xmldc');
6334: }
6335: foreach my $item (@items) {
6336: if (exists($currautocreate{$item})) {
6337: if ($currautocreate{$item} ne $newvals{$item}) {
6338: $changes{$item} = 1;
6339: }
6340: } elsif ($newvals{$item}) {
6341: $changes{$item} = 1;
6342: }
6343: }
6344: if (keys(%changes) > 0) {
6345: my @offon = ('off','on');
6346: $resulttext = &mt('Changes made:').'<ul>';
6347: foreach my $item (@types) {
6348: if ($changes{$item}) {
6349: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6350: $resulttext .= '<li>'.
6351: &mt("$title{$item} set to [_1]$newtxt [_2]",
6352: '<b>','</b>').
6353: '</li>';
1.125 raeburn 6354: }
6355: }
6356: if ($changes{'xmldc'}) {
6357: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6358: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6359: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6360: }
6361: $resulttext .= '</ul>';
6362: } else {
6363: $resulttext = &mt('No changes made to auto-creation settings');
6364: }
6365: } else {
6366: $resulttext = '<span class="LC_error">'.
6367: &mt('An error occurred: [_1]',$putresult).'</span>';
6368: }
6369: return $resulttext;
6370: }
6371:
1.23 raeburn 6372: sub modify_directorysrch {
6373: my ($dom,%domconfig) = @_;
6374: my ($resulttext,%changes);
6375: my %currdirsrch;
6376: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6377: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6378: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6379: }
6380: }
6381: my %title = ( available => 'Directory search available',
1.24 raeburn 6382: localonly => 'Other domains can search',
1.23 raeburn 6383: searchby => 'Search types',
6384: searchtypes => 'Search latitude');
6385: my @offon = ('off','on');
1.24 raeburn 6386: my @otherdoms = ('Yes','No');
1.23 raeburn 6387:
1.25 raeburn 6388: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6389: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6390: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6391:
1.44 raeburn 6392: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6393: if (keys(%{$usertypes}) == 0) {
6394: @cansearch = ('default');
6395: } else {
6396: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6397: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6398: if (!grep(/^\Q$type\E$/,@cansearch)) {
6399: push(@{$changes{'cansearch'}},$type);
6400: }
1.23 raeburn 6401: }
1.26 raeburn 6402: foreach my $type (@cansearch) {
6403: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6404: push(@{$changes{'cansearch'}},$type);
6405: }
1.23 raeburn 6406: }
1.26 raeburn 6407: } else {
6408: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6409: }
6410: }
6411:
6412: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6413: foreach my $by (@{$currdirsrch{'searchby'}}) {
6414: if (!grep(/^\Q$by\E$/,@searchby)) {
6415: push(@{$changes{'searchby'}},$by);
6416: }
6417: }
6418: foreach my $by (@searchby) {
6419: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6420: push(@{$changes{'searchby'}},$by);
6421: }
6422: }
6423: } else {
6424: push(@{$changes{'searchby'}},@searchby);
6425: }
1.25 raeburn 6426:
6427: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6428: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6429: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6430: push(@{$changes{'searchtypes'}},$type);
6431: }
6432: }
6433: foreach my $type (@searchtypes) {
6434: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6435: push(@{$changes{'searchtypes'}},$type);
6436: }
6437: }
6438: } else {
6439: if (exists($currdirsrch{'searchtypes'})) {
6440: foreach my $type (@searchtypes) {
6441: if ($type ne $currdirsrch{'searchtypes'}) {
6442: push(@{$changes{'searchtypes'}},$type);
6443: }
6444: }
6445: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6446: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6447: }
6448: } else {
6449: push(@{$changes{'searchtypes'}},@searchtypes);
6450: }
6451: }
6452:
1.23 raeburn 6453: my %dirsrch_hash = (
6454: directorysrch => { available => $env{'form.dirsrch_available'},
6455: cansearch => \@cansearch,
1.24 raeburn 6456: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6457: searchby => \@searchby,
1.25 raeburn 6458: searchtypes => \@searchtypes,
1.23 raeburn 6459: }
6460: );
6461: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6462: $dom);
6463: if ($putresult eq 'ok') {
6464: if (exists($currdirsrch{'available'})) {
6465: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6466: $changes{'available'} = 1;
6467: }
6468: } else {
6469: if ($env{'form.dirsrch_available'} eq '1') {
6470: $changes{'available'} = 1;
6471: }
6472: }
1.24 raeburn 6473: if (exists($currdirsrch{'localonly'})) {
6474: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6475: $changes{'localonly'} = 1;
6476: }
6477: } else {
6478: if ($env{'form.dirsrch_localonly'} eq '1') {
6479: $changes{'localonly'} = 1;
6480: }
6481: }
1.23 raeburn 6482: if (keys(%changes) > 0) {
6483: $resulttext = &mt('Changes made:').'<ul>';
6484: if ($changes{'available'}) {
6485: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6486: }
1.24 raeburn 6487: if ($changes{'localonly'}) {
6488: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6489: }
6490:
1.23 raeburn 6491: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6492: my $chgtext;
1.26 raeburn 6493: if (ref($usertypes) eq 'HASH') {
6494: if (keys(%{$usertypes}) > 0) {
6495: foreach my $type (@{$types}) {
6496: if (grep(/^\Q$type\E$/,@cansearch)) {
6497: $chgtext .= $usertypes->{$type}.'; ';
6498: }
6499: }
6500: if (grep(/^default$/,@cansearch)) {
6501: $chgtext .= $othertitle;
6502: } else {
6503: $chgtext =~ s/\; $//;
6504: }
1.178 raeburn 6505: $resulttext .=
6506: '<li>'.
6507: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6508: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6509: '</li>';
1.23 raeburn 6510: }
6511: }
6512: }
6513: if (ref($changes{'searchby'}) eq 'ARRAY') {
6514: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6515: my $chgtext;
6516: foreach my $type (@{$titleorder}) {
6517: if (grep(/^\Q$type\E$/,@searchby)) {
6518: if (defined($searchtitles->{$type})) {
6519: $chgtext .= $searchtitles->{$type}.'; ';
6520: }
6521: }
6522: }
6523: $chgtext =~ s/\; $//;
6524: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6525: }
1.25 raeburn 6526: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6527: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6528: my $chgtext;
6529: foreach my $type (@{$srchtypeorder}) {
6530: if (grep(/^\Q$type\E$/,@searchtypes)) {
6531: if (defined($srchtypes_desc->{$type})) {
6532: $chgtext .= $srchtypes_desc->{$type}.'; ';
6533: }
6534: }
6535: }
6536: $chgtext =~ s/\; $//;
1.178 raeburn 6537: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6538: }
6539: $resulttext .= '</ul>';
6540: } else {
6541: $resulttext = &mt('No changes made to institution directory search settings');
6542: }
6543: } else {
6544: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6545: &mt('An error occurred: [_1]',$putresult).'</span>';
6546: }
6547: return $resulttext;
6548: }
6549:
1.28 raeburn 6550: sub modify_contacts {
6551: my ($dom,%domconfig) = @_;
6552: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6553: if (ref($domconfig{'contacts'}) eq 'HASH') {
6554: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6555: $currsetting{$key} = $domconfig{'contacts'}{$key};
6556: }
6557: }
1.134 raeburn 6558: my (%others,%to,%bcc);
1.28 raeburn 6559: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6560: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6561: 'requestsmail');
1.28 raeburn 6562: foreach my $type (@mailings) {
6563: @{$newsetting{$type}} =
6564: &Apache::loncommon::get_env_multiple('form.'.$type);
6565: foreach my $item (@contacts) {
6566: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6567: $contacts_hash{contacts}{$type}{$item} = 1;
6568: } else {
6569: $contacts_hash{contacts}{$type}{$item} = 0;
6570: }
6571: }
6572: $others{$type} = $env{'form.'.$type.'_others'};
6573: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6574: if ($type eq 'helpdeskmail') {
6575: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6576: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6577: }
1.28 raeburn 6578: }
6579: foreach my $item (@contacts) {
6580: $to{$item} = $env{'form.'.$item};
6581: $contacts_hash{'contacts'}{$item} = $to{$item};
6582: }
6583: if (keys(%currsetting) > 0) {
6584: foreach my $item (@contacts) {
6585: if ($to{$item} ne $currsetting{$item}) {
6586: $changes{$item} = 1;
6587: }
6588: }
6589: foreach my $type (@mailings) {
6590: foreach my $item (@contacts) {
6591: if (ref($currsetting{$type}) eq 'HASH') {
6592: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6593: push(@{$changes{$type}},$item);
6594: }
6595: } else {
6596: push(@{$changes{$type}},@{$newsetting{$type}});
6597: }
6598: }
6599: if ($others{$type} ne $currsetting{$type}{'others'}) {
6600: push(@{$changes{$type}},'others');
6601: }
1.134 raeburn 6602: if ($type eq 'helpdeskmail') {
6603: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6604: push(@{$changes{$type}},'bcc');
6605: }
6606: }
1.28 raeburn 6607: }
6608: } else {
6609: my %default;
6610: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6611: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6612: $default{'errormail'} = 'adminemail';
6613: $default{'packagesmail'} = 'adminemail';
6614: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6615: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6616: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6617: foreach my $item (@contacts) {
6618: if ($to{$item} ne $default{$item}) {
6619: $changes{$item} = 1;
6620: }
6621: }
6622: foreach my $type (@mailings) {
6623: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6624:
6625: push(@{$changes{$type}},@{$newsetting{$type}});
6626: }
6627: if ($others{$type} ne '') {
6628: push(@{$changes{$type}},'others');
1.134 raeburn 6629: }
6630: if ($type eq 'helpdeskmail') {
6631: if ($bcc{$type} ne '') {
6632: push(@{$changes{$type}},'bcc');
6633: }
6634: }
1.28 raeburn 6635: }
6636: }
6637: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6638: $dom);
6639: if ($putresult eq 'ok') {
6640: if (keys(%changes) > 0) {
6641: my ($titles,$short_titles) = &contact_titles();
6642: $resulttext = &mt('Changes made:').'<ul>';
6643: foreach my $item (@contacts) {
6644: if ($changes{$item}) {
6645: $resulttext .= '<li>'.$titles->{$item}.
6646: &mt(' set to: ').
6647: '<span class="LC_cusr_emph">'.
6648: $to{$item}.'</span></li>';
6649: }
6650: }
6651: foreach my $type (@mailings) {
6652: if (ref($changes{$type}) eq 'ARRAY') {
6653: $resulttext .= '<li>'.$titles->{$type}.': ';
6654: my @text;
6655: foreach my $item (@{$newsetting{$type}}) {
6656: push(@text,$short_titles->{$item});
6657: }
6658: if ($others{$type} ne '') {
6659: push(@text,$others{$type});
6660: }
6661: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6662: join(', ',@text).'</span>';
6663: if ($type eq 'helpdeskmail') {
6664: if ($bcc{$type} ne '') {
6665: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6666: }
6667: }
6668: $resulttext .= '</li>';
1.28 raeburn 6669: }
6670: }
6671: $resulttext .= '</ul>';
6672: } else {
1.34 raeburn 6673: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6674: }
6675: } else {
6676: $resulttext = '<span class="LC_error">'.
6677: &mt('An error occurred: [_1].',$putresult).'</span>';
6678: }
6679: return $resulttext;
6680: }
6681:
6682: sub modify_usercreation {
1.27 raeburn 6683: my ($dom,%domconfig) = @_;
1.34 raeburn 6684: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6685: my $warningmsg;
1.27 raeburn 6686: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6687: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6688: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6689: }
6690: }
6691: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6692: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6693: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6694: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6695: foreach my $item(@contexts) {
1.45 raeburn 6696: if ($item eq 'selfcreate') {
1.50 raeburn 6697: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6698: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6699: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6700: if (ref($cancreate{$item}) eq 'ARRAY') {
6701: if (grep(/^login$/,@{$cancreate{$item}})) {
6702: $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.');
6703: }
1.43 raeburn 6704: }
6705: }
1.50 raeburn 6706: } else {
6707: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6708: }
1.34 raeburn 6709: }
1.93 raeburn 6710: my ($othertitle,$usertypes,$types) =
6711: &Apache::loncommon::sorted_inst_types($dom);
6712: if (ref($types) eq 'ARRAY') {
6713: if (@{$types} > 0) {
6714: @{$cancreate{'statustocreate'}} =
6715: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6716: } else {
6717: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6718: }
6719: push(@contexts,'statustocreate');
6720: }
1.165 raeburn 6721: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6722: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6723: foreach my $item (@contexts) {
1.93 raeburn 6724: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6725: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6726: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6727: if (ref($cancreate{$item}) eq 'ARRAY') {
6728: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6729: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6730: push(@{$changes{'cancreate'}},$item);
6731: }
1.50 raeburn 6732: }
6733: }
6734: }
6735: } else {
6736: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6737: if (@{$cancreate{$item}} > 0) {
6738: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6739: push(@{$changes{'cancreate'}},$item);
6740: }
6741: }
6742: } else {
6743: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6744: if (@{$cancreate{$item}} < 3) {
6745: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6746: push(@{$changes{'cancreate'}},$item);
6747: }
6748: }
6749: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6750: if (@{$cancreate{$item}} > 0) {
6751: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6752: push(@{$changes{'cancreate'}},$item);
6753: }
6754: }
6755: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6756: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6757: push(@{$changes{'cancreate'}},$item);
6758: }
6759: }
6760: }
6761: }
6762: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6763: foreach my $type (@{$cancreate{$item}}) {
6764: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6765: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6766: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6767: push(@{$changes{'cancreate'}},$item);
6768: }
6769: }
6770: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6771: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6772: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6773: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6774: push(@{$changes{'cancreate'}},$item);
6775: }
6776: }
6777: }
6778: }
6779: }
6780: } else {
6781: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6782: push(@{$changes{'cancreate'}},$item);
6783: }
6784: }
1.27 raeburn 6785: }
1.34 raeburn 6786: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6787: foreach my $item (@contexts) {
1.43 raeburn 6788: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6789: if ($cancreate{$item} ne 'any') {
6790: push(@{$changes{'cancreate'}},$item);
6791: }
6792: } else {
6793: if ($cancreate{$item} ne 'none') {
6794: push(@{$changes{'cancreate'}},$item);
6795: }
1.27 raeburn 6796: }
6797: }
6798: } else {
1.43 raeburn 6799: foreach my $item (@contexts) {
1.34 raeburn 6800: push(@{$changes{'cancreate'}},$item);
6801: }
1.27 raeburn 6802: }
1.34 raeburn 6803:
1.27 raeburn 6804: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6805: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6806: if (!grep(/^\Q$type\E$/,@username_rule)) {
6807: push(@{$changes{'username_rule'}},$type);
6808: }
6809: }
6810: foreach my $type (@username_rule) {
6811: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6812: push(@{$changes{'username_rule'}},$type);
6813: }
6814: }
6815: } else {
6816: push(@{$changes{'username_rule'}},@username_rule);
6817: }
6818:
1.32 raeburn 6819: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6820: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6821: if (!grep(/^\Q$type\E$/,@id_rule)) {
6822: push(@{$changes{'id_rule'}},$type);
6823: }
6824: }
6825: foreach my $type (@id_rule) {
6826: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6827: push(@{$changes{'id_rule'}},$type);
6828: }
6829: }
6830: } else {
6831: push(@{$changes{'id_rule'}},@id_rule);
6832: }
6833:
1.43 raeburn 6834: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6835: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6836: if (!grep(/^\Q$type\E$/,@email_rule)) {
6837: push(@{$changes{'email_rule'}},$type);
6838: }
6839: }
6840: foreach my $type (@email_rule) {
6841: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6842: push(@{$changes{'email_rule'}},$type);
6843: }
6844: }
6845: } else {
6846: push(@{$changes{'email_rule'}},@email_rule);
6847: }
6848:
6849: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6850: my @authtypes = ('int','krb4','krb5','loc');
6851: my %authhash;
1.43 raeburn 6852: foreach my $item (@authen_contexts) {
1.28 raeburn 6853: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6854: foreach my $auth (@authtypes) {
6855: if (grep(/^\Q$auth\E$/,@authallowed)) {
6856: $authhash{$item}{$auth} = 1;
6857: } else {
6858: $authhash{$item}{$auth} = 0;
6859: }
6860: }
6861: }
6862: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6863: foreach my $item (@authen_contexts) {
1.28 raeburn 6864: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6865: foreach my $auth (@authtypes) {
6866: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6867: push(@{$changes{'authtypes'}},$item);
6868: last;
6869: }
6870: }
6871: }
6872: }
6873: } else {
1.43 raeburn 6874: foreach my $item (@authen_contexts) {
1.28 raeburn 6875: push(@{$changes{'authtypes'}},$item);
6876: }
6877: }
6878:
1.27 raeburn 6879: my %usercreation_hash = (
1.28 raeburn 6880: usercreation => {
1.34 raeburn 6881: cancreate => \%cancreate,
1.27 raeburn 6882: username_rule => \@username_rule,
1.32 raeburn 6883: id_rule => \@id_rule,
1.43 raeburn 6884: email_rule => \@email_rule,
1.32 raeburn 6885: authtypes => \%authhash,
1.27 raeburn 6886: }
6887: );
6888:
6889: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6890: $dom);
1.50 raeburn 6891:
6892: my %selfcreatetypes = (
6893: sso => 'users authenticated by institutional single sign on',
6894: login => 'users authenticated by institutional log-in',
6895: email => 'users who provide a valid e-mail address for use as the username',
6896: );
1.27 raeburn 6897: if ($putresult eq 'ok') {
6898: if (keys(%changes) > 0) {
6899: $resulttext = &mt('Changes made:').'<ul>';
6900: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6901: my %lt = &usercreation_types();
6902: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6903: my $chgtext;
1.165 raeburn 6904: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6905: $chgtext = $lt{$type}.', ';
6906: }
1.45 raeburn 6907: if ($type eq 'selfcreate') {
1.50 raeburn 6908: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6909: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6910: } else {
1.100 raeburn 6911: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6912: foreach my $case (@{$cancreate{$type}}) {
6913: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6914: }
6915: $chgtext .= '</ul>';
1.100 raeburn 6916: if (ref($cancreate{$type}) eq 'ARRAY') {
6917: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6918: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6919: if (@{$cancreate{'statustocreate'}} == 0) {
6920: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6921: }
6922: }
6923: }
6924: }
1.43 raeburn 6925: }
1.93 raeburn 6926: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6927: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6928: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6929: if (@{$cancreate{'selfcreate'}} > 0) {
6930: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6931:
6932: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6933: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6934: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6935: }
1.96 raeburn 6936: } elsif (ref($usertypes) eq 'HASH') {
6937: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6938: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6939: } else {
6940: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6941: }
6942: $chgtext .= '<ul>';
6943: foreach my $case (@{$cancreate{$type}}) {
6944: if ($case eq 'default') {
6945: $chgtext .= '<li>'.$othertitle.'</li>';
6946: } else {
6947: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6948: }
6949: }
1.100 raeburn 6950: $chgtext .= '</ul>';
6951: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6952: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6953: }
6954: }
6955: } else {
6956: if (@{$cancreate{$type}} == 0) {
6957: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6958: } else {
6959: $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 6960: }
6961: }
6962: }
1.165 raeburn 6963: } elsif ($type eq 'captcha') {
6964: if ($cancreate{$type} eq 'notused') {
6965: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6966: } else {
6967: my %captchas = &captcha_phrases();
6968: if ($captchas{$cancreate{$type}}) {
6969: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6970: } else {
6971: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6972: }
6973: }
6974: } elsif ($type eq 'recaptchakeys') {
6975: my ($privkey,$pubkey);
6976: if (ref($cancreate{$type}) eq 'HASH') {
6977: $pubkey = $cancreate{$type}{'public'};
6978: $privkey = $cancreate{$type}{'private'};
6979: }
6980: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6981: if (!$pubkey) {
6982: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6983: } else {
6984: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6985: }
6986: if (!$privkey) {
6987: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6988: } else {
6989: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6990: }
6991: $chgtext .= '</ul>';
1.43 raeburn 6992: } else {
6993: if ($cancreate{$type} eq 'none') {
6994: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6995: } elsif ($cancreate{$type} eq 'any') {
6996: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6997: } elsif ($cancreate{$type} eq 'official') {
6998: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6999: } elsif ($cancreate{$type} eq 'unofficial') {
7000: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7001: }
1.34 raeburn 7002: }
7003: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7004: }
7005: }
7006: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7007: my ($rules,$ruleorder) =
7008: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7009: my $chgtext = '<ul>';
7010: foreach my $type (@username_rule) {
7011: if (ref($rules->{$type}) eq 'HASH') {
7012: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7013: }
7014: }
7015: $chgtext .= '</ul>';
7016: if (@username_rule > 0) {
7017: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7018: } else {
1.28 raeburn 7019: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7020: }
7021: }
1.32 raeburn 7022: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7023: my ($idrules,$idruleorder) =
7024: &Apache::lonnet::inst_userrules($dom,'id');
7025: my $chgtext = '<ul>';
7026: foreach my $type (@id_rule) {
7027: if (ref($idrules->{$type}) eq 'HASH') {
7028: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7029: }
7030: }
7031: $chgtext .= '</ul>';
7032: if (@id_rule > 0) {
7033: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7034: } else {
7035: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7036: }
7037: }
1.43 raeburn 7038: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7039: my ($emailrules,$emailruleorder) =
7040: &Apache::lonnet::inst_userrules($dom,'email');
7041: my $chgtext = '<ul>';
7042: foreach my $type (@email_rule) {
7043: if (ref($emailrules->{$type}) eq 'HASH') {
7044: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7045: }
7046: }
7047: $chgtext .= '</ul>';
7048: if (@email_rule > 0) {
7049: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7050: } else {
7051: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7052: }
7053: }
7054:
1.28 raeburn 7055: my %authname = &authtype_names();
7056: my %context_title = &context_names();
7057: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7058: my $chgtext = '<ul>';
7059: foreach my $type (@{$changes{'authtypes'}}) {
7060: my @allowed;
7061: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7062: foreach my $auth (@authtypes) {
7063: if ($authhash{$type}{$auth}) {
7064: push(@allowed,$authname{$auth});
7065: }
7066: }
1.43 raeburn 7067: if (@allowed > 0) {
7068: $chgtext .= join(', ',@allowed).'</li>';
7069: } else {
7070: $chgtext .= &mt('none').'</li>';
7071: }
1.28 raeburn 7072: }
7073: $chgtext .= '</ul>';
7074: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7075: $resulttext .= '</li>';
7076: }
1.27 raeburn 7077: $resulttext .= '</ul>';
7078: } else {
1.28 raeburn 7079: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7080: }
7081: } else {
7082: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7083: &mt('An error occurred: [_1]',$putresult).'</span>';
7084: }
1.43 raeburn 7085: if ($warningmsg ne '') {
7086: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7087: }
1.23 raeburn 7088: return $resulttext;
7089: }
7090:
1.165 raeburn 7091: sub process_captcha {
7092: my ($container,$changes,$newsettings,$current) = @_;
7093: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7094: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7095: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7096: $newsettings->{'captcha'} = 'original';
7097: }
7098: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7099: if ($container eq 'cancreate') {
7100: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7101: push(@{$changes->{'cancreate'}},'captcha');
7102: } elsif (!defined($changes->{'cancreate'})) {
7103: $changes->{'cancreate'} = ['captcha'];
7104: }
7105: } else {
7106: $changes->{'captcha'} = 1;
1.165 raeburn 7107: }
7108: }
7109: my ($newpub,$newpriv,$currpub,$currpriv);
7110: if ($newsettings->{'captcha'} eq 'recaptcha') {
7111: $newpub = $env{'form.'.$container.'_recaptchapub'};
7112: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7113: $newpub =~ s/\W//g;
7114: $newpriv =~ s/\W//g;
7115: $newsettings->{'recaptchakeys'} = {
7116: public => $newpub,
7117: private => $newpriv,
7118: };
1.165 raeburn 7119: }
7120: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7121: $currpub = $current->{'recaptchakeys'}{'public'};
7122: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7123: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7124: $newsettings->{'recaptchakeys'} = {
7125: public => '',
7126: private => '',
7127: }
7128: }
1.165 raeburn 7129: }
7130: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7131: if ($container eq 'cancreate') {
7132: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7133: push(@{$changes->{'cancreate'}},'recaptchakeys');
7134: } elsif (!defined($changes->{'cancreate'})) {
7135: $changes->{'cancreate'} = ['recaptchakeys'];
7136: }
7137: } else {
7138: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7139: }
7140: }
7141: return;
7142: }
7143:
1.33 raeburn 7144: sub modify_usermodification {
7145: my ($dom,%domconfig) = @_;
7146: my ($resulttext,%curr_usermodification,%changes);
7147: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7148: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7149: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7150: }
7151: }
1.63 raeburn 7152: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7153: my %context_title = (
7154: author => 'In author context',
7155: course => 'In course context',
1.63 raeburn 7156: selfcreate => 'When self creating account',
1.33 raeburn 7157: );
7158: my @fields = ('lastname','firstname','middlename','generation',
7159: 'permanentemail','id');
7160: my %roles = (
7161: author => ['ca','aa'],
7162: course => ['st','ep','ta','in','cr'],
7163: );
1.63 raeburn 7164: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7165: if (ref($types) eq 'ARRAY') {
7166: push(@{$types},'default');
7167: $usertypes->{'default'} = $othertitle;
7168: }
7169: $roles{'selfcreate'} = $types;
1.33 raeburn 7170: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7171: my %modifyhash;
7172: foreach my $context (@contexts) {
7173: foreach my $role (@{$roles{$context}}) {
7174: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7175: foreach my $item (@fields) {
7176: if (grep(/^\Q$item\E$/,@modifiable)) {
7177: $modifyhash{$context}{$role}{$item} = 1;
7178: } else {
7179: $modifyhash{$context}{$role}{$item} = 0;
7180: }
7181: }
7182: }
7183: if (ref($curr_usermodification{$context}) eq 'HASH') {
7184: foreach my $role (@{$roles{$context}}) {
7185: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7186: foreach my $field (@fields) {
7187: if ($modifyhash{$context}{$role}{$field} ne
7188: $curr_usermodification{$context}{$role}{$field}) {
7189: push(@{$changes{$context}},$role);
7190: last;
7191: }
7192: }
7193: }
7194: }
7195: } else {
7196: foreach my $context (@contexts) {
7197: foreach my $role (@{$roles{$context}}) {
7198: push(@{$changes{$context}},$role);
7199: }
7200: }
7201: }
7202: }
7203: my %usermodification_hash = (
7204: usermodification => \%modifyhash,
7205: );
7206: my $putresult = &Apache::lonnet::put_dom('configuration',
7207: \%usermodification_hash,$dom);
7208: if ($putresult eq 'ok') {
7209: if (keys(%changes) > 0) {
7210: $resulttext = &mt('Changes made: ').'<ul>';
7211: foreach my $context (@contexts) {
7212: if (ref($changes{$context}) eq 'ARRAY') {
7213: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7214: if (ref($changes{$context}) eq 'ARRAY') {
7215: foreach my $role (@{$changes{$context}}) {
7216: my $rolename;
1.63 raeburn 7217: if ($context eq 'selfcreate') {
7218: $rolename = $role;
7219: if (ref($usertypes) eq 'HASH') {
7220: if ($usertypes->{$role} ne '') {
7221: $rolename = $usertypes->{$role};
7222: }
7223: }
1.33 raeburn 7224: } else {
1.63 raeburn 7225: if ($role eq 'cr') {
7226: $rolename = &mt('Custom');
7227: } else {
7228: $rolename = &Apache::lonnet::plaintext($role);
7229: }
1.33 raeburn 7230: }
7231: my @modifiable;
1.63 raeburn 7232: if ($context eq 'selfcreate') {
1.126 bisitz 7233: $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 7234: } else {
7235: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7236: }
1.33 raeburn 7237: foreach my $field (@fields) {
7238: if ($modifyhash{$context}{$role}{$field}) {
7239: push(@modifiable,$fieldtitles{$field});
7240: }
7241: }
7242: if (@modifiable > 0) {
7243: $resulttext .= join(', ',@modifiable);
7244: } else {
7245: $resulttext .= &mt('none');
7246: }
7247: $resulttext .= '</li>';
7248: }
7249: $resulttext .= '</ul></li>';
7250: }
7251: }
7252: }
7253: $resulttext .= '</ul>';
7254: } else {
7255: $resulttext = &mt('No changes made to user modification settings');
7256: }
7257: } else {
7258: $resulttext = '<span class="LC_error">'.
7259: &mt('An error occurred: [_1]',$putresult).'</span>';
7260: }
7261: return $resulttext;
7262: }
7263:
1.43 raeburn 7264: sub modify_defaults {
7265: my ($dom,$r) = @_;
7266: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7267: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7268: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7269: my @authtypes = ('internal','krb4','krb5','localauth');
7270: foreach my $item (@items) {
7271: $newvalues{$item} = $env{'form.'.$item};
7272: if ($item eq 'auth_def') {
7273: if ($newvalues{$item} ne '') {
7274: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7275: push(@errors,$item);
7276: }
7277: }
7278: } elsif ($item eq 'lang_def') {
7279: if ($newvalues{$item} ne '') {
7280: if ($newvalues{$item} =~ /^(\w+)/) {
7281: my $langcode = $1;
1.103 raeburn 7282: if ($langcode ne 'x_chef') {
7283: if (code2language($langcode) eq '') {
7284: push(@errors,$item);
7285: }
1.43 raeburn 7286: }
7287: } else {
7288: push(@errors,$item);
7289: }
7290: }
1.54 raeburn 7291: } elsif ($item eq 'timezone_def') {
7292: if ($newvalues{$item} ne '') {
1.62 raeburn 7293: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7294: push(@errors,$item);
7295: }
7296: }
1.68 raeburn 7297: } elsif ($item eq 'datelocale_def') {
7298: if ($newvalues{$item} ne '') {
7299: my @datelocale_ids = DateTime::Locale->ids();
7300: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7301: push(@errors,$item);
7302: }
7303: }
1.141 raeburn 7304: } elsif ($item eq 'portal_def') {
7305: if ($newvalues{$item} ne '') {
7306: 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])\/?$/) {
7307: push(@errors,$item);
7308: }
7309: }
1.43 raeburn 7310: }
7311: if (grep(/^\Q$item\E$/,@errors)) {
7312: $newvalues{$item} = $domdefaults{$item};
7313: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7314: $changes{$item} = 1;
7315: }
1.72 raeburn 7316: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7317: }
7318: my %defaults_hash = (
1.72 raeburn 7319: defaults => \%newvalues,
7320: );
1.43 raeburn 7321: my $title = &defaults_titles();
7322: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7323: $dom);
7324: if ($putresult eq 'ok') {
7325: if (keys(%changes) > 0) {
7326: $resulttext = &mt('Changes made:').'<ul>';
7327: my $version = $r->dir_config('lonVersion');
7328: 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";
7329: foreach my $item (sort(keys(%changes))) {
7330: my $value = $env{'form.'.$item};
7331: if ($value eq '') {
7332: $value = &mt('none');
7333: } elsif ($item eq 'auth_def') {
7334: my %authnames = &authtype_names();
7335: my %shortauth = (
7336: internal => 'int',
7337: krb4 => 'krb4',
7338: krb5 => 'krb5',
7339: localauth => 'loc',
7340: );
7341: $value = $authnames{$shortauth{$value}};
7342: }
7343: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7344: $mailmsgtext .= "$title->{$item} set to $value\n";
7345: }
7346: $resulttext .= '</ul>';
7347: $mailmsgtext .= "\n";
7348: my $cachetime = 24*60*60;
1.72 raeburn 7349: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7350: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7351: my $sysmail = $r->dir_config('lonSysEMail');
7352: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7353: }
1.43 raeburn 7354: } else {
1.54 raeburn 7355: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7356: }
7357: } else {
7358: $resulttext = '<span class="LC_error">'.
7359: &mt('An error occurred: [_1]',$putresult).'</span>';
7360: }
7361: if (@errors > 0) {
7362: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7363: foreach my $item (@errors) {
7364: $resulttext .= ' "'.$title->{$item}.'",';
7365: }
7366: $resulttext =~ s/,$//;
7367: }
7368: return $resulttext;
7369: }
7370:
1.46 raeburn 7371: sub modify_scantron {
1.48 raeburn 7372: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7373: my ($resulttext,%confhash,%changes,$errors);
7374: my $custom = 'custom.tab';
7375: my $default = 'default.tab';
7376: my $servadm = $r->dir_config('lonAdmEMail');
7377: my ($configuserok,$author_ok,$switchserver) =
7378: &config_check($dom,$confname,$servadm);
7379: if ($env{'form.scantronformat.filename'} ne '') {
7380: my $error;
7381: if ($configuserok eq 'ok') {
7382: if ($switchserver) {
1.130 raeburn 7383: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7384: } else {
7385: if ($author_ok eq 'ok') {
7386: my ($result,$scantronurl) =
7387: &publishlogo($r,'upload','scantronformat',$dom,
7388: $confname,'scantron','','',$custom);
7389: if ($result eq 'ok') {
7390: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7391: $changes{'scantronformat'} = 1;
1.46 raeburn 7392: } else {
7393: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7394: }
7395: } else {
7396: $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);
7397: }
7398: }
7399: } else {
7400: $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);
7401: }
7402: if ($error) {
7403: &Apache::lonnet::logthis($error);
7404: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7405: }
7406: }
1.48 raeburn 7407: if (ref($domconfig{'scantron'}) eq 'HASH') {
7408: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7409: if ($env{'form.scantronformat_del'}) {
7410: $confhash{'scantron'}{'scantronformat'} = '';
7411: $changes{'scantronformat'} = 1;
1.46 raeburn 7412: }
7413: }
7414: }
7415: if (keys(%confhash) > 0) {
7416: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7417: $dom);
7418: if ($putresult eq 'ok') {
7419: if (keys(%changes) > 0) {
1.48 raeburn 7420: if (ref($confhash{'scantron'}) eq 'HASH') {
7421: $resulttext = &mt('Changes made:').'<ul>';
7422: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7423: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7424: } else {
1.130 raeburn 7425: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7426: }
1.48 raeburn 7427: $resulttext .= '</ul>';
7428: } else {
1.130 raeburn 7429: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7430: }
7431: $resulttext .= '</ul>';
7432: &Apache::loncommon::devalidate_domconfig_cache($dom);
7433: } else {
1.130 raeburn 7434: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7435: }
7436: } else {
7437: $resulttext = '<span class="LC_error">'.
7438: &mt('An error occurred: [_1]',$putresult).'</span>';
7439: }
7440: } else {
1.130 raeburn 7441: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7442: }
7443: if ($errors) {
7444: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7445: $errors.'</ul>';
7446: }
7447: return $resulttext;
7448: }
7449:
1.48 raeburn 7450: sub modify_coursecategories {
7451: my ($dom,%domconfig) = @_;
1.57 raeburn 7452: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7453: $cathash);
1.48 raeburn 7454: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7455: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7456: $cathash = $domconfig{'coursecategories'}{'cats'};
7457: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7458: $changes{'togglecats'} = 1;
7459: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7460: }
7461: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7462: $changes{'categorize'} = 1;
7463: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7464: }
1.120 raeburn 7465: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7466: $changes{'togglecatscomm'} = 1;
7467: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7468: }
7469: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7470: $changes{'categorizecomm'} = 1;
7471: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7472: }
1.57 raeburn 7473: } else {
7474: $changes{'togglecats'} = 1;
7475: $changes{'categorize'} = 1;
1.124 raeburn 7476: $changes{'togglecatscomm'} = 1;
7477: $changes{'categorizecomm'} = 1;
1.87 raeburn 7478: $domconfig{'coursecategories'} = {
7479: togglecats => $env{'form.togglecats'},
7480: categorize => $env{'form.categorize'},
1.124 raeburn 7481: togglecatscomm => $env{'form.togglecatscomm'},
7482: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7483: };
1.57 raeburn 7484: }
7485: if (ref($cathash) eq 'HASH') {
7486: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7487: push (@deletecategory,'instcode::0');
7488: }
1.120 raeburn 7489: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7490: push(@deletecategory,'communities::0');
7491: }
1.48 raeburn 7492: }
1.57 raeburn 7493: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7494: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7495: if (@deletecategory > 0) {
7496: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7497: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7498: foreach my $item (@deletecategory) {
1.57 raeburn 7499: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7500: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7501: $deletions{$item} = 1;
1.57 raeburn 7502: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7503: }
7504: }
7505: }
1.57 raeburn 7506: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7507: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7508: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7509: $reorderings{$item} = 1;
1.57 raeburn 7510: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7511: }
7512: if ($env{'form.addcategory_name_'.$item} ne '') {
7513: my $newcat = $env{'form.addcategory_name_'.$item};
7514: my $newdepth = $depth+1;
7515: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7516: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7517: $adds{$newitem} = 1;
7518: }
7519: if ($env{'form.subcat_'.$item} ne '') {
7520: my $newcat = $env{'form.subcat_'.$item};
7521: my $newdepth = $depth+1;
7522: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7523: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7524: $adds{$newitem} = 1;
7525: }
7526: }
7527: }
7528: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7529: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7530: my $newitem = 'instcode::0';
1.57 raeburn 7531: if ($cathash->{$newitem} eq '') {
7532: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7533: $adds{$newitem} = 1;
7534: }
7535: } else {
7536: my $newitem = 'instcode::0';
1.57 raeburn 7537: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7538: $adds{$newitem} = 1;
7539: }
7540: }
1.120 raeburn 7541: if ($env{'form.communities'} eq '1') {
7542: if (ref($cathash) eq 'HASH') {
7543: my $newitem = 'communities::0';
7544: if ($cathash->{$newitem} eq '') {
7545: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7546: $adds{$newitem} = 1;
7547: }
7548: } else {
7549: my $newitem = 'communities::0';
7550: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7551: $adds{$newitem} = 1;
7552: }
7553: }
1.48 raeburn 7554: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7555: if (($env{'form.addcategory_name'} ne 'instcode') &&
7556: ($env{'form.addcategory_name'} ne 'communities')) {
7557: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7558: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7559: $adds{$newitem} = 1;
7560: }
1.48 raeburn 7561: }
1.57 raeburn 7562: my $putresult;
1.48 raeburn 7563: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7564: if (keys(%deletions) > 0) {
7565: foreach my $key (keys(%deletions)) {
7566: if ($predelallitems{$key} ne '') {
7567: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7568: }
7569: }
7570: }
7571: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7572: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7573: if (ref($chkcats[0]) eq 'ARRAY') {
7574: my $depth = 0;
7575: my $chg = 0;
7576: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7577: my $name = $chkcats[0][$i];
7578: my $item;
7579: if ($name eq '') {
7580: $chg ++;
7581: } else {
7582: $item = &escape($name).'::0';
7583: if ($chg) {
1.57 raeburn 7584: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7585: }
7586: $depth ++;
1.57 raeburn 7587: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7588: $depth --;
7589: }
7590: }
7591: }
1.57 raeburn 7592: }
7593: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7594: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7595: if ($putresult eq 'ok') {
1.57 raeburn 7596: my %title = (
1.120 raeburn 7597: togglecats => 'Show/Hide a course in catalog',
7598: categorize => 'Assign a category to a course',
7599: togglecatscomm => 'Show/Hide a community in catalog',
7600: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7601: );
7602: my %level = (
1.120 raeburn 7603: dom => 'set in Domain ("Modify Course/Community")',
7604: crs => 'set in Course ("Course Configuration")',
7605: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7606: );
1.48 raeburn 7607: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7608: if ($changes{'togglecats'}) {
7609: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7610: }
7611: if ($changes{'categorize'}) {
7612: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7613: }
1.120 raeburn 7614: if ($changes{'togglecatscomm'}) {
7615: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7616: }
7617: if ($changes{'categorizecomm'}) {
7618: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7619: }
1.57 raeburn 7620: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7621: my $cathash;
7622: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7623: $cathash = $domconfig{'coursecategories'}{'cats'};
7624: } else {
7625: $cathash = {};
7626: }
7627: my (@cats,@trails,%allitems);
7628: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7629: if (keys(%deletions) > 0) {
7630: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7631: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7632: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7633: }
7634: $resulttext .= '</ul></li>';
7635: }
7636: if (keys(%reorderings) > 0) {
7637: my %sort_by_trail;
7638: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7639: foreach my $key (keys(%reorderings)) {
7640: if ($allitems{$key} ne '') {
7641: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7642: }
1.48 raeburn 7643: }
1.57 raeburn 7644: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7645: $resulttext .= '<li>'.$trails[$trail].'</li>';
7646: }
7647: $resulttext .= '</ul></li>';
1.48 raeburn 7648: }
1.57 raeburn 7649: if (keys(%adds) > 0) {
7650: my %sort_by_trail;
7651: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7652: foreach my $key (keys(%adds)) {
7653: if ($allitems{$key} ne '') {
7654: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7655: }
7656: }
7657: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7658: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7659: }
1.57 raeburn 7660: $resulttext .= '</ul></li>';
1.48 raeburn 7661: }
7662: }
7663: $resulttext .= '</ul>';
7664: } else {
7665: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7666: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7667: }
7668: } else {
1.120 raeburn 7669: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7670: }
7671: return $resulttext;
7672: }
7673:
1.69 raeburn 7674: sub modify_serverstatuses {
7675: my ($dom,%domconfig) = @_;
7676: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7677: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7678: %currserverstatus = %{$domconfig{'serverstatuses'}};
7679: }
7680: my @pages = &serverstatus_pages();
7681: foreach my $type (@pages) {
7682: $newserverstatus{$type}{'namedusers'} = '';
7683: $newserverstatus{$type}{'machines'} = '';
7684: if (defined($env{'form.'.$type.'_namedusers'})) {
7685: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7686: my @okusers;
7687: foreach my $user (@users) {
7688: my ($uname,$udom) = split(/:/,$user);
7689: if (($udom =~ /^$match_domain$/) &&
7690: (&Apache::lonnet::domain($udom)) &&
7691: ($uname =~ /^$match_username$/)) {
7692: if (!grep(/^\Q$user\E/,@okusers)) {
7693: push(@okusers,$user);
7694: }
7695: }
7696: }
7697: if (@okusers > 0) {
7698: @okusers = sort(@okusers);
7699: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7700: }
7701: }
7702: if (defined($env{'form.'.$type.'_machines'})) {
7703: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7704: my @okmachines;
7705: foreach my $ip (@machines) {
7706: my @parts = split(/\./,$ip);
7707: next if (@parts < 4);
7708: my $badip = 0;
7709: for (my $i=0; $i<4; $i++) {
7710: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7711: $badip = 1;
7712: last;
7713: }
7714: }
7715: if (!$badip) {
7716: push(@okmachines,$ip);
7717: }
7718: }
7719: @okmachines = sort(@okmachines);
7720: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7721: }
7722: }
7723: my %serverstatushash = (
7724: serverstatuses => \%newserverstatus,
7725: );
7726: foreach my $type (@pages) {
1.83 raeburn 7727: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7728: my (@current,@new);
1.83 raeburn 7729: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7730: if ($currserverstatus{$type}{$setting} ne '') {
7731: @current = split(/,/,$currserverstatus{$type}{$setting});
7732: }
7733: }
7734: if ($newserverstatus{$type}{$setting} ne '') {
7735: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7736: }
7737: if (@current > 0) {
7738: if (@new > 0) {
7739: foreach my $item (@current) {
7740: if (!grep(/^\Q$item\E$/,@new)) {
7741: $changes{$type}{$setting} = 1;
1.82 raeburn 7742: last;
7743: }
7744: }
1.84 raeburn 7745: foreach my $item (@new) {
7746: if (!grep(/^\Q$item\E$/,@current)) {
7747: $changes{$type}{$setting} = 1;
7748: last;
1.82 raeburn 7749: }
7750: }
7751: } else {
1.83 raeburn 7752: $changes{$type}{$setting} = 1;
1.69 raeburn 7753: }
1.83 raeburn 7754: } elsif (@new > 0) {
7755: $changes{$type}{$setting} = 1;
1.69 raeburn 7756: }
7757: }
7758: }
7759: if (keys(%changes) > 0) {
1.81 raeburn 7760: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7761: my $putresult = &Apache::lonnet::put_dom('configuration',
7762: \%serverstatushash,$dom);
7763: if ($putresult eq 'ok') {
7764: $resulttext .= &mt('Changes made:').'<ul>';
7765: foreach my $type (@pages) {
1.84 raeburn 7766: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7767: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7768: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7769: if ($newserverstatus{$type}{'namedusers'} eq '') {
7770: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7771: } else {
7772: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7773: }
1.84 raeburn 7774: }
7775: if ($changes{$type}{'machines'}) {
1.69 raeburn 7776: if ($newserverstatus{$type}{'machines'} eq '') {
7777: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7778: } else {
7779: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7780: }
7781:
7782: }
7783: $resulttext .= '</ul></li>';
7784: }
7785: }
7786: $resulttext .= '</ul>';
7787: } else {
7788: $resulttext = '<span class="LC_error">'.
7789: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7790:
7791: }
7792: } else {
7793: $resulttext = &mt('No changes made to access to server status pages');
7794: }
7795: return $resulttext;
7796: }
7797:
1.118 jms 7798: sub modify_helpsettings {
1.122 jms 7799: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7800: my ($resulttext,$errors,%changes,%helphash);
7801: my %defaultchecked = ('submitbugs' => 'on');
7802: my @offon = ('off','on');
1.118 jms 7803: my @toggles = ('submitbugs');
7804: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7805: foreach my $item (@toggles) {
1.166 raeburn 7806: if ($defaultchecked{$item} eq 'on') {
7807: if ($domconfig{'helpsettings'}{$item} eq '') {
7808: if ($env{'form.'.$item} eq '0') {
7809: $changes{$item} = 1;
7810: }
7811: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7812: $changes{$item} = 1;
7813: }
7814: } elsif ($defaultchecked{$item} eq 'off') {
7815: if ($domconfig{'helpsettings'}{$item} eq '') {
7816: if ($env{'form.'.$item} eq '1') {
7817: $changes{$item} = 1;
7818: }
7819: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7820: $changes{$item} = 1;
7821: }
7822: }
7823: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7824: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7825: }
7826: }
1.118 jms 7827: }
1.123 jms 7828: my $putresult;
7829: if (keys(%changes) > 0) {
1.166 raeburn 7830: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7831: if ($putresult eq 'ok') {
1.166 raeburn 7832: $resulttext = &mt('Changes made:').'<ul>';
7833: foreach my $item (sort(keys(%changes))) {
7834: if ($item eq 'submitbugs') {
7835: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7836: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7837: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7838: }
7839: }
7840: $resulttext .= '</ul>';
7841: } else {
7842: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7843: $errors .= '<li><span class="LC_error">'.
7844: &mt('An error occurred storing the settings: [_1]',
7845: $putresult).'</span></li>';
1.166 raeburn 7846: }
1.118 jms 7847: }
7848: if ($errors) {
1.168 raeburn 7849: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7850: $errors.'</ul>';
7851: }
7852: return $resulttext;
7853: }
7854:
1.121 raeburn 7855: sub modify_coursedefaults {
7856: my ($dom,%domconfig) = @_;
7857: my ($resulttext,$errors,%changes,%defaultshash);
7858: my %defaultchecked = ('canuse_pdfforms' => 'off');
7859: my @offon = ('off','on');
7860: my @toggles = ('canuse_pdfforms');
7861:
7862: $defaultshash{'coursedefaults'} = {};
7863:
7864: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7865: if ($domconfig{'coursedefaults'} eq '') {
7866: $domconfig{'coursedefaults'} = {};
7867: }
7868: }
7869:
7870: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7871: foreach my $item (@toggles) {
7872: if ($defaultchecked{$item} eq 'on') {
7873: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7874: ($env{'form.'.$item} eq '0')) {
7875: $changes{$item} = 1;
7876: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7877: $changes{$item} = 1;
7878: }
7879: } elsif ($defaultchecked{$item} eq 'off') {
7880: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7881: ($env{'form.'.$item} eq '1')) {
7882: $changes{$item} = 1;
7883: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7884: $changes{$item} = 1;
7885: }
7886: }
7887: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7888: }
1.139 raeburn 7889: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7890: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7891: $newdefresponder =~ s/\D//g;
7892: if ($newdefresponder eq '' || $newdefresponder < 1) {
7893: $newdefresponder = 1;
7894: }
7895: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7896: if ($currdefresponder ne $newdefresponder) {
7897: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7898: $changes{'anonsurvey_threshold'} = 1;
7899: }
7900: }
1.121 raeburn 7901: }
7902: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7903: $dom);
7904: if ($putresult eq 'ok') {
7905: if (keys(%changes) > 0) {
7906: if ($changes{'canuse_pdfforms'}) {
7907: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7908: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7909: my $cachetime = 24*60*60;
7910: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7911: }
7912: $resulttext = &mt('Changes made:').'<ul>';
7913: foreach my $item (sort(keys(%changes))) {
7914: if ($item eq 'canuse_pdfforms') {
7915: if ($env{'form.'.$item} eq '1') {
7916: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7917: } else {
7918: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7919: }
1.139 raeburn 7920: } elsif ($item eq 'anonsurvey_threshold') {
7921: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7922: }
1.121 raeburn 7923: }
7924: $resulttext .= '</ul>';
7925: } else {
7926: $resulttext = &mt('No changes made to course defaults');
7927: }
7928: } else {
7929: $resulttext = '<span class="LC_error">'.
7930: &mt('An error occurred: [_1]',$putresult).'</span>';
7931: }
7932: return $resulttext;
7933: }
7934:
1.137 raeburn 7935: sub modify_usersessions {
7936: my ($dom,%domconfig) = @_;
1.145 raeburn 7937: my @hostingtypes = ('version','excludedomain','includedomain');
7938: my @offloadtypes = ('primary','default');
7939: my %types = (
7940: remote => \@hostingtypes,
7941: hosted => \@hostingtypes,
7942: spares => \@offloadtypes,
7943: );
7944: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7945: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7946: my (%by_ip,%by_location,@intdoms);
7947: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7948: my @locations = sort(keys(%by_location));
1.137 raeburn 7949: my (%defaultshash,%changes);
7950: foreach my $prefix (@prefixes) {
7951: $defaultshash{'usersessions'}{$prefix} = {};
7952: }
7953: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7954: my $resulttext;
1.138 raeburn 7955: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7956: foreach my $prefix (@prefixes) {
1.145 raeburn 7957: next if ($prefix eq 'spares');
7958: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7959: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7960: if ($type eq 'version') {
7961: my $value = $env{'form.'.$prefix.'_'.$type};
7962: my $okvalue;
7963: if ($value ne '') {
7964: if (grep(/^\Q$value\E$/,@lcversions)) {
7965: $okvalue = $value;
7966: }
7967: }
7968: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7969: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7970: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7971: if ($inuse == 0) {
7972: $changes{$prefix}{$type} = 1;
7973: } else {
7974: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7975: $changes{$prefix}{$type} = 1;
7976: }
7977: if ($okvalue ne '') {
7978: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7979: }
7980: }
7981: } else {
7982: if (($inuse == 1) && ($okvalue ne '')) {
7983: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7984: $changes{$prefix}{$type} = 1;
7985: }
7986: }
7987: } else {
7988: if (($inuse == 1) && ($okvalue ne '')) {
7989: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7990: $changes{$prefix}{$type} = 1;
7991: }
7992: }
7993: } else {
7994: if (($inuse == 1) && ($okvalue ne '')) {
7995: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7996: $changes{$prefix}{$type} = 1;
7997: }
7998: }
7999: } else {
8000: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8001: my @okvals;
8002: foreach my $val (@vals) {
1.138 raeburn 8003: if ($val =~ /:/) {
8004: my @items = split(/:/,$val);
8005: foreach my $item (@items) {
8006: if (ref($by_location{$item}) eq 'ARRAY') {
8007: push(@okvals,$item);
8008: }
8009: }
8010: } else {
8011: if (ref($by_location{$val}) eq 'ARRAY') {
8012: push(@okvals,$val);
8013: }
1.137 raeburn 8014: }
8015: }
8016: @okvals = sort(@okvals);
8017: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8018: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8019: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8020: if ($inuse == 0) {
8021: $changes{$prefix}{$type} = 1;
8022: } else {
8023: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8024: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8025: if (@changed > 0) {
8026: $changes{$prefix}{$type} = 1;
8027: }
8028: }
8029: } else {
8030: if ($inuse == 1) {
8031: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8032: $changes{$prefix}{$type} = 1;
8033: }
8034: }
8035: } else {
8036: if ($inuse == 1) {
8037: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8038: $changes{$prefix}{$type} = 1;
8039: }
8040: }
8041: } else {
8042: if ($inuse == 1) {
8043: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8044: $changes{$prefix}{$type} = 1;
8045: }
8046: }
8047: }
8048: }
8049: }
1.145 raeburn 8050:
8051: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8052: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8053: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8054: my $savespares;
8055:
8056: foreach my $lonhost (sort(keys(%servers))) {
8057: my $serverhomeID =
8058: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8059: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8060: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8061: my %spareschg;
8062: foreach my $type (@{$types{'spares'}}) {
8063: my @okspares;
8064: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8065: foreach my $server (@checked) {
1.152 raeburn 8066: if (&Apache::lonnet::hostname($server) ne '') {
8067: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8068: unless (grep(/^\Q$server\E$/,@okspares)) {
8069: push(@okspares,$server);
8070: }
1.145 raeburn 8071: }
8072: }
8073: }
8074: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8075: my $newspare;
1.152 raeburn 8076: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8077: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8078: $newspare = $new;
8079: }
8080: }
1.152 raeburn 8081: my @spares;
8082: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8083: @spares = sort(@okspares,$newspare);
8084: } else {
8085: @spares = sort(@okspares);
8086: }
8087: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8088: if (ref($spareid{$lonhost}) eq 'HASH') {
8089: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8090: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8091: if (@diffs > 0) {
8092: $spareschg{$type} = 1;
8093: }
8094: }
8095: }
8096: }
8097: if (keys(%spareschg) > 0) {
8098: $changes{'spares'}{$lonhost} = \%spareschg;
8099: }
8100: }
8101:
8102: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8103: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8104: if (ref($changes{'spares'}) eq 'HASH') {
8105: if (keys(%{$changes{'spares'}}) > 0) {
8106: $savespares = 1;
8107: }
8108: }
8109: } else {
8110: $savespares = 1;
8111: }
8112: }
8113:
1.147 raeburn 8114: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8115: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8116: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8117: $dom);
8118: if ($putresult eq 'ok') {
8119: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8120: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8121: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8122: }
8123: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8124: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8125: }
8126: }
8127: my $cachetime = 24*60*60;
8128: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8129: if (keys(%changes) > 0) {
8130: my %lt = &usersession_titles();
8131: $resulttext = &mt('Changes made:').'<ul>';
8132: foreach my $prefix (@prefixes) {
8133: if (ref($changes{$prefix}) eq 'HASH') {
8134: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8135: if ($prefix eq 'spares') {
8136: if (ref($changes{$prefix}) eq 'HASH') {
8137: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8138: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8139: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8140: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8141: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8142: foreach my $type (@{$types{$prefix}}) {
8143: if ($changes{$prefix}{$lonhost}{$type}) {
8144: my $offloadto = &mt('None');
8145: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8146: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8147: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8148: }
1.145 raeburn 8149: }
1.147 raeburn 8150: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8151: }
1.137 raeburn 8152: }
8153: }
1.147 raeburn 8154: $resulttext .= '</li>';
1.137 raeburn 8155: }
8156: }
1.147 raeburn 8157: } else {
8158: foreach my $type (@{$types{$prefix}}) {
8159: if (defined($changes{$prefix}{$type})) {
8160: my $newvalue;
8161: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8162: if (ref($defaultshash{'usersessions'}{$prefix})) {
8163: if ($type eq 'version') {
8164: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8165: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8166: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8167: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8168: }
1.145 raeburn 8169: }
8170: }
8171: }
1.147 raeburn 8172: if ($newvalue eq '') {
8173: if ($type eq 'version') {
8174: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8175: } else {
8176: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8177: }
1.145 raeburn 8178: } else {
1.147 raeburn 8179: if ($type eq 'version') {
8180: $newvalue .= ' '.&mt('(or later)');
8181: }
8182: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8183: }
1.137 raeburn 8184: }
8185: }
8186: }
1.147 raeburn 8187: $resulttext .= '</ul>';
1.137 raeburn 8188: }
8189: }
1.147 raeburn 8190: $resulttext .= '</ul>';
8191: } else {
8192: $resulttext = $nochgmsg;
1.137 raeburn 8193: }
8194: } else {
8195: $resulttext = '<span class="LC_error">'.
8196: &mt('An error occurred: [_1]',$putresult).'</span>';
8197: }
8198: } else {
1.147 raeburn 8199: $resulttext = $nochgmsg;
1.137 raeburn 8200: }
8201: return $resulttext;
8202: }
8203:
1.150 raeburn 8204: sub modify_loadbalancing {
8205: my ($dom,%domconfig) = @_;
8206: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8207: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8208: my ($othertitle,$usertypes,$types) =
8209: &Apache::loncommon::sorted_inst_types($dom);
8210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8211: my @sparestypes = ('primary','default');
8212: my %typetitles = &sparestype_titles();
8213: my $resulttext;
1.171 raeburn 8214: my (%currbalancer,%currtargets,%currrules,%existing);
8215: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8216: %existing = %{$domconfig{'loadbalancing'}};
8217: }
8218: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8219: \%currtargets,\%currrules);
8220: my ($saveloadbalancing,%defaultshash,%changes);
8221: my ($alltypes,$othertypes,$titles) =
8222: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8223: my %ruletitles = &offloadtype_text();
8224: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8225: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8226: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8227: if ($balancer eq '') {
8228: next;
8229: }
8230: if (!exists($servers{$balancer})) {
8231: if (exists($currbalancer{$balancer})) {
8232: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8233: }
1.171 raeburn 8234: next;
8235: }
8236: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8237: push(@{$changes{'delete'}},$balancer);
8238: next;
8239: }
8240: if (!exists($currbalancer{$balancer})) {
8241: push(@{$changes{'add'}},$balancer);
8242: }
8243: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8244: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8245: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8246: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8247: $saveloadbalancing = 1;
8248: }
8249: foreach my $sparetype (@sparestypes) {
8250: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8251: my @offloadto;
8252: foreach my $target (@targets) {
8253: if (($servers{$target}) && ($target ne $balancer)) {
8254: if ($sparetype eq 'default') {
8255: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8256: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8257: }
8258: }
1.171 raeburn 8259: unless(grep(/^\Q$target\E$/,@offloadto)) {
8260: push(@offloadto,$target);
8261: }
1.150 raeburn 8262: }
1.171 raeburn 8263: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8264: }
8265: }
1.171 raeburn 8266: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8267: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8268: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8269: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8270: if (@targetdiffs > 0) {
1.171 raeburn 8271: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8272: }
1.171 raeburn 8273: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8274: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8275: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8276: }
8277: }
8278: }
8279: } else {
1.171 raeburn 8280: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8281: foreach my $sparetype (@sparestypes) {
8282: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8283: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8284: $changes{'curr'}{$balancer}{'targets'} = 1;
8285: }
1.150 raeburn 8286: }
8287: }
8288: }
8289: }
8290: my $ishomedom;
1.171 raeburn 8291: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8292: $ishomedom = 1;
1.150 raeburn 8293: }
8294: if (ref($alltypes) eq 'ARRAY') {
8295: foreach my $type (@{$alltypes}) {
8296: my $rule;
1.171 raeburn 8297: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8298: (!$ishomedom)) {
1.171 raeburn 8299: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8300: }
8301: if ($rule eq 'specific') {
8302: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8303: }
1.171 raeburn 8304: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8305: if (ref($currrules{$balancer}) eq 'HASH') {
8306: if ($rule ne $currrules{$balancer}{$type}) {
8307: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8308: }
8309: } elsif ($rule ne '') {
1.171 raeburn 8310: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8311: }
8312: }
8313: }
1.171 raeburn 8314: }
8315: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8316: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8317: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8318: $defaultshash{'loadbalancing'} = {};
8319: }
8320: my $putresult = &Apache::lonnet::put_dom('configuration',
8321: \%defaultshash,$dom);
8322:
8323: if ($putresult eq 'ok') {
8324: if (keys(%changes) > 0) {
8325: if (ref($changes{'delete'}) eq 'ARRAY') {
8326: foreach my $balancer (sort(@{$changes{'delete'}})) {
8327: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8328: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8329: }
1.171 raeburn 8330: }
8331: if (ref($changes{'add'}) eq 'ARRAY') {
8332: foreach my $balancer (sort(@{$changes{'add'}})) {
8333: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8334: }
8335: }
8336: if (ref($changes{'curr'}) eq 'HASH') {
8337: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8338: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8339: if ($changes{'curr'}{$balancer}{'targets'}) {
8340: my %offloadstr;
8341: foreach my $sparetype (@sparestypes) {
8342: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8343: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8344: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8345: }
8346: }
1.150 raeburn 8347: }
1.171 raeburn 8348: if (keys(%offloadstr) == 0) {
8349: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8350: } else {
1.171 raeburn 8351: my $showoffload;
8352: foreach my $sparetype (@sparestypes) {
8353: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8354: if (defined($offloadstr{$sparetype})) {
8355: $showoffload .= $offloadstr{$sparetype};
8356: } else {
8357: $showoffload .= &mt('None');
8358: }
8359: $showoffload .= (' 'x3);
8360: }
8361: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8362: }
8363: }
8364: }
1.171 raeburn 8365: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8366: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8367: foreach my $type (@{$alltypes}) {
8368: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8369: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8370: my $balancetext;
8371: if ($rule eq '') {
8372: $balancetext = $ruletitles{'default'};
8373: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8374: $balancetext = $ruletitles{$rule};
8375: } else {
8376: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8377: }
8378: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8379: }
8380: }
8381: }
8382: }
1.171 raeburn 8383: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8384: }
1.171 raeburn 8385: }
8386: if ($resulttext ne '') {
8387: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8388: } else {
8389: $resulttext = $nochgmsg;
8390: }
8391: } else {
1.171 raeburn 8392: $resulttext = $nochgmsg;
1.150 raeburn 8393: }
8394: } else {
1.171 raeburn 8395: $resulttext = '<span class="LC_error">'.
8396: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8397: }
8398: } else {
1.171 raeburn 8399: $resulttext = $nochgmsg;
1.150 raeburn 8400: }
8401: return $resulttext;
8402: }
8403:
1.48 raeburn 8404: sub recurse_check {
8405: my ($chkcats,$categories,$depth,$name) = @_;
8406: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8407: my $chg = 0;
8408: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8409: my $category = $chkcats->[$depth]{$name}[$j];
8410: my $item;
8411: if ($category eq '') {
8412: $chg ++;
8413: } else {
8414: my $deeper = $depth + 1;
8415: $item = &escape($category).':'.&escape($name).':'.$depth;
8416: if ($chg) {
8417: $categories->{$item} -= $chg;
8418: }
8419: &recurse_check($chkcats,$categories,$deeper,$category);
8420: $deeper --;
8421: }
8422: }
8423: }
8424: return;
8425: }
8426:
8427: sub recurse_cat_deletes {
8428: my ($item,$coursecategories,$deletions) = @_;
8429: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8430: my $subdepth = $depth + 1;
8431: if (ref($coursecategories) eq 'HASH') {
8432: foreach my $subitem (keys(%{$coursecategories})) {
8433: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8434: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8435: delete($coursecategories->{$subitem});
8436: $deletions->{$subitem} = 1;
8437: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8438: }
1.48 raeburn 8439: }
8440: }
8441: return;
8442: }
8443:
1.125 raeburn 8444: sub get_active_dcs {
8445: my ($dom) = @_;
8446: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8447: my %domcoords;
8448: my $numdcs = 0;
8449: my $now = time;
8450: foreach my $server (keys(%dompersonnel)) {
8451: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8452: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8453: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8454: if (($end eq '') || ($end == 0) || ($end > $now)) {
8455: if ($start <= $now) {
8456: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8457: }
8458: }
8459: }
8460: }
8461: return %domcoords;
8462: }
8463:
8464: sub active_dc_picker {
8465: my ($dom,$curr_dc) = @_;
8466: my %domcoords = &get_active_dcs($dom);
8467: my @dcs = sort(keys(%domcoords));
8468: my $numdcs = scalar(@dcs);
8469: my $datatable;
8470: my $numinrow = 2;
8471: if ($numdcs > 1) {
8472: $datatable = '<table>';
8473: for (my $i=0; $i<@dcs; $i++) {
8474: my $rem = $i%($numinrow);
8475: if ($rem == 0) {
8476: if ($i > 0) {
8477: $datatable .= '</tr>';
8478: }
8479: $datatable .= '<tr>';
8480: }
8481: my $check = ' ';
8482: if ($curr_dc eq '') {
8483: if (!$i) {
8484: $check = ' checked="checked" ';
8485: }
8486: } elsif ($dcs[$i] eq $curr_dc) {
8487: $check = ' checked="checked" ';
8488: }
8489: if ($i == @dcs - 1) {
8490: my $colsleft = $numinrow - $rem;
8491: if ($colsleft > 1) {
8492: $datatable .= '<td colspan="'.$colsleft.'">';
8493: } else {
8494: $datatable .= '<td>';
8495: }
8496: } else {
8497: $datatable .= '<td>';
8498: }
8499: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8500: $datatable .= '<span class="LC_nobreak"><label>'.
8501: '<input type="radio" name="autocreate_xmldc"'.
8502: ' value="'.$dcs[$i].'"'.$check.'/>'.
8503: &Apache::loncommon::plainname($dcname,$dcdom).
1.177 bisitz 8504: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8505: '</label></span></td>';
8506: }
8507: $datatable .= '</tr></table>';
8508: } elsif (@dcs) {
8509: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8510: $dcs[0].'" />';
8511: }
8512: return ($numdcs,$datatable);
8513: }
8514:
1.137 raeburn 8515: sub usersession_titles {
8516: return &Apache::lonlocal::texthash(
8517: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8518: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8519: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8520: version => 'LON-CAPA version requirement',
1.138 raeburn 8521: excludedomain => 'Allow all, but exclude specific domains',
8522: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8523: primary => 'Primary (checked first)',
1.154 raeburn 8524: default => 'Default',
1.137 raeburn 8525: );
8526: }
8527:
1.152 raeburn 8528: sub id_for_thisdom {
8529: my (%servers) = @_;
8530: my %altids;
8531: foreach my $server (keys(%servers)) {
8532: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8533: if ($serverhome ne $server) {
8534: $altids{$serverhome} = $server;
8535: }
8536: }
8537: return %altids;
8538: }
8539:
1.150 raeburn 8540: sub count_servers {
8541: my ($currbalancer,%servers) = @_;
8542: my (@spares,$numspares);
8543: foreach my $lonhost (sort(keys(%servers))) {
8544: next if ($currbalancer eq $lonhost);
8545: push(@spares,$lonhost);
8546: }
8547: if ($currbalancer) {
8548: $numspares = scalar(@spares);
8549: } else {
8550: $numspares = scalar(@spares) - 1;
8551: }
8552: return ($numspares,@spares);
8553: }
8554:
8555: sub lonbalance_targets_js {
1.171 raeburn 8556: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8557: my $select = &mt('Select');
8558: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8559: if (ref($servers) eq 'HASH') {
8560: $alltargets = join("','",sort(keys(%{$servers})));
8561: my @homedoms;
8562: foreach my $server (sort(keys(%{$servers}))) {
8563: if (&Apache::lonnet::host_domain($server) eq $dom) {
8564: push(@homedoms,'1');
8565: } else {
8566: push(@homedoms,'0');
8567: }
8568: }
8569: $allishome = join("','",@homedoms);
8570: }
8571: if (ref($types) eq 'ARRAY') {
8572: if (@{$types} > 0) {
8573: @alltypes = @{$types};
8574: }
8575: }
8576: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8577: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8578: my (%currbalancer,%currtargets,%currrules,%existing);
8579: if (ref($settings) eq 'HASH') {
8580: %existing = %{$settings};
8581: }
8582: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8583: \%currtargets,\%currrules);
8584: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8585: return <<"END";
8586:
8587: <script type="text/javascript">
8588: // <![CDATA[
8589:
1.171 raeburn 8590: currBalancers = new Array('$balancers');
8591:
8592: function toggleTargets(balnum) {
8593: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8594: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8595: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8596: var prevbalancer = prevhostitem.value;
8597: var baltotal = document.getElementById('loadbalancing_total').value;
8598: prevhostitem.value = balancer;
8599: if (prevbalancer != '') {
8600: var prevIdx = currBalancers.indexOf(prevbalancer);
8601: if (prevIdx != -1) {
8602: currBalancers.splice(prevIdx,1);
8603: }
8604: }
1.150 raeburn 8605: if (balancer == '') {
1.171 raeburn 8606: hideSpares(balnum);
1.150 raeburn 8607: } else {
1.171 raeburn 8608: var currIdx = currBalancers.indexOf(balancer);
8609: if (currIdx == -1) {
8610: currBalancers.push(balancer);
8611: }
1.150 raeburn 8612: var homedoms = new Array('$allishome');
1.171 raeburn 8613: var ishomedom = homedoms[lonhostitem.selectedIndex];
8614: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8615: }
1.171 raeburn 8616: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8617: return;
8618: }
8619:
1.171 raeburn 8620: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8621: var alltargets = new Array('$alltargets');
8622: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8623: var offloadtypes = new Array('primary','default');
8624:
1.171 raeburn 8625: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8626: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8627:
1.151 raeburn 8628: for (var i=0; i<offloadtypes.length; i++) {
8629: var count = 0;
8630: for (var j=0; j<alltargets.length; j++) {
8631: if (alltargets[j] != balancer) {
1.171 raeburn 8632: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8633: item.value = alltargets[j];
8634: item.style.textAlign='left';
8635: item.style.textFace='normal';
8636: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8637: if (currBalancers.indexOf(alltargets[j]) == -1) {
8638: item.disabled = '';
8639: } else {
8640: item.disabled = 'disabled';
8641: item.checked = false;
8642: }
1.151 raeburn 8643: count ++;
8644: }
1.150 raeburn 8645: }
8646: }
1.151 raeburn 8647: for (var k=0; k<insttypes.length; k++) {
8648: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8649: if (ishomedom == 1) {
1.171 raeburn 8650: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8651: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8652: } else {
1.171 raeburn 8653: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8654: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8655:
8656: }
8657: } else {
1.171 raeburn 8658: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8659: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8660: }
1.151 raeburn 8661: if ((insttypes[k] != '_LC_external') &&
8662: ((insttypes[k] != '_LC_internetdom') ||
8663: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8664: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8665: item.options.length = 0;
8666: item.options[0] = new Option("","",true,true);
8667: var idx = 0;
1.151 raeburn 8668: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8669: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8670: idx ++;
8671: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8672:
1.150 raeburn 8673: }
8674: }
8675: }
8676: }
8677: return;
8678: }
8679:
1.171 raeburn 8680: function hideSpares(balnum) {
1.150 raeburn 8681: var alltargets = new Array('$alltargets');
8682: var insttypes = new Array('$allinsttypes');
8683: var offloadtypes = new Array('primary','default');
8684:
1.171 raeburn 8685: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8686: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8687:
8688: var total = alltargets.length - 1;
8689: for (var i=0; i<offloadtypes; i++) {
8690: for (var j=0; j<total; j++) {
1.171 raeburn 8691: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8692: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8693: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8694: }
1.150 raeburn 8695: }
8696: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8697: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8698: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8699: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8700: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8701: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8702: }
8703: }
8704: return;
8705: }
8706:
1.171 raeburn 8707: function checkOffloads(item,balnum,type) {
1.150 raeburn 8708: var alltargets = new Array('$alltargets');
8709: var offloadtypes = new Array('primary','default');
8710: if (item.checked) {
8711: var total = alltargets.length - 1;
8712: var other;
8713: if (type == offloadtypes[0]) {
1.151 raeburn 8714: other = offloadtypes[1];
1.150 raeburn 8715: } else {
1.151 raeburn 8716: other = offloadtypes[0];
1.150 raeburn 8717: }
8718: for (var i=0; i<total; i++) {
1.171 raeburn 8719: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8720: if (server == item.value) {
1.171 raeburn 8721: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8722: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8723: }
8724: }
8725: }
8726: }
8727: return;
8728: }
8729:
1.171 raeburn 8730: function singleServerToggle(balnum,type) {
8731: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8732: if (offloadtoSelIdx == 0) {
1.171 raeburn 8733: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8734: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8735:
8736: } else {
1.171 raeburn 8737: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8738: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8739: }
8740: return;
8741: }
8742:
1.171 raeburn 8743: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8744: if (type == '_LC_external') {
1.171 raeburn 8745: return;
1.150 raeburn 8746: }
1.171 raeburn 8747: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8748: for (var i=0; i<typesRules.length; i++) {
8749: if (formname.elements[typesRules[i]].checked) {
8750: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8751: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8752: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8753: } else {
1.171 raeburn 8754: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8755: }
8756: }
8757: }
8758: return;
8759: }
8760:
8761: function balancerDeleteChange(balnum) {
8762: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8763: var baltotal = document.getElementById('loadbalancing_total').value;
8764: var addtarget;
8765: var removetarget;
8766: var action = 'delete';
8767: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8768: var lonhost = hostitem.value;
8769: var currIdx = currBalancers.indexOf(lonhost);
8770: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8771: if (currIdx != -1) {
8772: currBalancers.splice(currIdx,1);
8773: }
8774: addtarget = lonhost;
8775: } else {
8776: if (currIdx == -1) {
8777: currBalancers.push(lonhost);
8778: }
8779: removetarget = lonhost;
8780: action = 'undelete';
8781: }
8782: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8783: }
8784: return;
8785: }
8786:
8787: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8788: if (baltotal > 1) {
8789: var offloadtypes = new Array('primary','default');
8790: var alltargets = new Array('$alltargets');
8791: var insttypes = new Array('$allinsttypes');
8792: for (var i=0; i<baltotal; i++) {
8793: if (i != balnum) {
8794: for (var j=0; j<offloadtypes.length; j++) {
8795: var total = alltargets.length - 1;
8796: for (var k=0; k<total; k++) {
8797: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8798: var server = serveritem.value;
8799: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8800: if (server == addtarget) {
8801: serveritem.disabled = '';
8802: }
8803: }
8804: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8805: if (server == removetarget) {
8806: serveritem.disabled = 'disabled';
8807: serveritem.checked = false;
8808: }
8809: }
8810: }
8811: }
8812: for (var j=0; j<insttypes.length; j++) {
8813: if (insttypes[j] != '_LC_external') {
8814: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8815: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8816: var currSel = singleserver.selectedIndex;
8817: var currVal = singleserver.options[currSel].value;
8818: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8819: var numoptions = singleserver.options.length;
8820: var needsnew = 1;
8821: for (var k=0; k<numoptions; k++) {
8822: if (singleserver.options[k] == addtarget) {
8823: needsnew = 0;
8824: break;
8825: }
8826: }
8827: if (needsnew == 1) {
8828: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8829: }
8830: }
8831: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8832: singleserver.options.length = 0;
8833: if ((currVal) && (currVal != removetarget)) {
8834: singleserver.options[0] = new Option("","",false,false);
8835: } else {
8836: singleserver.options[0] = new Option("","",true,true);
8837: }
8838: var idx = 0;
8839: for (var m=0; m<alltargets.length; m++) {
8840: if (currBalancers.indexOf(alltargets[m]) == -1) {
8841: idx ++;
8842: if (currVal == alltargets[m]) {
8843: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8844: } else {
8845: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8846: }
8847: }
8848: }
8849: }
8850: }
8851: }
8852: }
1.150 raeburn 8853: }
8854: }
8855: }
8856: return;
8857: }
8858:
1.152 raeburn 8859: // ]]>
8860: </script>
8861:
8862: END
8863: }
8864:
8865: sub new_spares_js {
8866: my @sparestypes = ('primary','default');
8867: my $types = join("','",@sparestypes);
8868: my $select = &mt('Select');
8869: return <<"END";
8870:
8871: <script type="text/javascript">
8872: // <![CDATA[
8873:
8874: function updateNewSpares(formname,lonhost) {
8875: var types = new Array('$types');
8876: var include = new Array();
8877: var exclude = new Array();
8878: for (var i=0; i<types.length; i++) {
8879: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8880: for (var j=0; j<spareboxes.length; j++) {
8881: if (formname.elements[spareboxes[j]].checked) {
8882: exclude.push(formname.elements[spareboxes[j]].value);
8883: } else {
8884: include.push(formname.elements[spareboxes[j]].value);
8885: }
8886: }
8887: }
8888: for (var i=0; i<types.length; i++) {
8889: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8890: var selIdx = newSpare.selectedIndex;
8891: var currnew = newSpare.options[selIdx].value;
8892: var okSpares = new Array();
8893: for (var j=0; j<newSpare.options.length; j++) {
8894: var possible = newSpare.options[j].value;
8895: if (possible != '') {
8896: if (exclude.indexOf(possible) == -1) {
8897: okSpares.push(possible);
8898: } else {
8899: if (currnew == possible) {
8900: selIdx = 0;
8901: }
8902: }
8903: }
8904: }
8905: for (var k=0; k<include.length; k++) {
8906: if (okSpares.indexOf(include[k]) == -1) {
8907: okSpares.push(include[k]);
8908: }
8909: }
8910: okSpares.sort();
8911: newSpare.options.length = 0;
8912: if (selIdx == 0) {
8913: newSpare.options[0] = new Option("$select","",true,true);
8914: } else {
8915: newSpare.options[0] = new Option("$select","",false,false);
8916: }
8917: for (var m=0; m<okSpares.length; m++) {
8918: var idx = m+1;
8919: var selThis = 0;
8920: if (selIdx != 0) {
8921: if (okSpares[m] == currnew) {
8922: selThis = 1;
8923: }
8924: }
8925: if (selThis == 1) {
8926: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8927: } else {
8928: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8929: }
8930: }
8931: }
8932: return;
8933: }
8934:
8935: function checkNewSpares(lonhost,type) {
8936: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8937: var chosen = newSpare.options[newSpare.selectedIndex].value;
8938: if (chosen != '') {
8939: var othertype;
8940: var othernewSpare;
8941: if (type == 'primary') {
8942: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8943: }
8944: if (type == 'default') {
8945: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8946: }
8947: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8948: othernewSpare.selectedIndex = 0;
8949: }
8950: }
8951: return;
8952: }
8953:
8954: // ]]>
8955: </script>
8956:
8957: END
8958:
8959: }
8960:
8961: sub common_domprefs_js {
8962: return <<"END";
8963:
8964: <script type="text/javascript">
8965: // <![CDATA[
8966:
1.150 raeburn 8967: function getIndicesByName(formname,item) {
1.152 raeburn 8968: var group = new Array();
1.150 raeburn 8969: for (var i=0;i<formname.elements.length;i++) {
8970: if (formname.elements[i].name == item) {
1.152 raeburn 8971: group.push(formname.elements[i].id);
1.150 raeburn 8972: }
8973: }
1.152 raeburn 8974: return group;
1.150 raeburn 8975: }
8976:
8977: // ]]>
8978: </script>
8979:
8980: END
1.152 raeburn 8981:
1.150 raeburn 8982: }
8983:
1.165 raeburn 8984: sub recaptcha_js {
8985: my %lt = &captcha_phrases();
8986: return <<"END";
8987:
8988: <script type="text/javascript">
8989: // <![CDATA[
8990:
8991: function updateCaptcha(caller,context) {
8992: var privitem;
8993: var pubitem;
8994: var privtext;
8995: var pubtext;
8996: if (document.getElementById(context+'_recaptchapub')) {
8997: pubitem = document.getElementById(context+'_recaptchapub');
8998: } else {
8999: return;
9000: }
9001: if (document.getElementById(context+'_recaptchapriv')) {
9002: privitem = document.getElementById(context+'_recaptchapriv');
9003: } else {
9004: return;
9005: }
9006: if (document.getElementById(context+'_recaptchapubtxt')) {
9007: pubtext = document.getElementById(context+'_recaptchapubtxt');
9008: } else {
9009: return;
9010: }
9011: if (document.getElementById(context+'_recaptchaprivtxt')) {
9012: privtext = document.getElementById(context+'_recaptchaprivtxt');
9013: } else {
9014: return;
9015: }
9016: if (caller.checked) {
9017: if (caller.value == 'recaptcha') {
9018: pubitem.type = 'text';
9019: privitem.type = 'text';
9020: pubitem.size = '40';
9021: privitem.size = '40';
9022: pubtext.innerHTML = "$lt{'pub'}";
9023: privtext.innerHTML = "$lt{'priv'}";
9024: } else {
9025: pubitem.type = 'hidden';
9026: privitem.type = 'hidden';
9027: pubtext.innerHTML = '';
9028: privtext.innerHTML = '';
9029: }
9030: }
9031: return;
9032: }
9033:
9034: // ]]>
9035: </script>
9036:
9037: END
9038:
9039: }
9040:
9041: sub captcha_phrases {
9042: return &Apache::lonlocal::texthash (
9043: priv => 'Private key',
9044: pub => 'Public key',
9045: original => 'original (CAPTCHA)',
9046: recaptcha => 'successor (ReCAPTCHA)',
9047: notused => 'unused',
9048: );
9049: }
9050:
1.3 raeburn 9051: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>