Annotation of loncom/interface/domainprefs.pm, revision 1.188
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.188 ! raeburn 4: # $Id: domainprefs.pm,v 1.187 2013/01/09 21:34:26 raeburn Exp $
1.2 albertel 5: #
1.1 raeburn 6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA#
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: #
28: ###############################################################
29: ##############################################################
30:
1.101 raeburn 31: =pod
32:
33: =head1 NAME
34:
35: Apache::domainprefs.pm
36:
37: =head1 SYNOPSIS
38:
39: Handles configuration of a LON-CAPA domain.
40:
41: This is part of the LearningOnline Network with CAPA project
42: described at http://www.lon-capa.org.
43:
44:
45: =head1 OVERVIEW
46:
47: Each institution using LON-CAPA will typically have a single domain designated
1.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' =>
1.185 raeburn 389: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 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:
1.6 raeburn 410: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 411: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 412: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 413: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 414: text=>"Settings to display/modify"});
1.9 raeburn 415: my $confname = $dom.'-domainconfig';
1.174 foxr 416:
1.3 raeburn 417: if ($phase eq 'process') {
1.91 raeburn 418: &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,\@roles);
1.30 raeburn 419: } elsif ($phase eq 'display') {
1.165 raeburn 420: my $js = &recaptcha_js();
1.171 raeburn 421: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 422: my ($othertitle,$usertypes,$types) =
423: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 424: $js .= &lonbalance_targets_js($dom,$types,\%servers,
425: $domconfig{'loadbalancing'}).
1.170 raeburn 426: &new_spares_js().
427: &common_domprefs_js().
428: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 429: }
1.150 raeburn 430: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 431: } else {
1.180 raeburn 432: # check if domconfig user exists for the domain.
433: my $servadm = $r->dir_config('lonAdmEMail');
434: my ($configuserok,$author_ok,$switchserver) =
435: &config_check($dom,$confname,$servadm);
436: unless ($configuserok eq 'ok') {
1.181 raeburn 437: &Apache::lonconfigsettings::print_header($r,$phase,$context);
438: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
439: $confname).
440: '<br />'
441: );
1.180 raeburn 442: if ($switchserver) {
1.181 raeburn 443: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
444: '<br />'.
445: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
446: '<br />'.
447: &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).
448: '<br />'.
449: &mt('To do that now, use the following link: [_1]',$switchserver)
450: );
451: } else {
452: $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.').
453: '<br />'.
454: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
455: );
1.180 raeburn 456: }
457: $r->print(&Apache::loncommon::end_page());
458: return OK;
459: }
1.21 raeburn 460: if (keys(%domconfig) == 0) {
461: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 462: my @ids=&Apache::lonnet::current_machine_ids();
463: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 464: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 465: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 466: my $custom_img_count = 0;
467: foreach my $img (@loginimages) {
468: if ($designhash{$dom.'.login.'.$img} ne '') {
469: $custom_img_count ++;
470: }
471: }
472: foreach my $role (@roles) {
473: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
474: $custom_img_count ++;
475: }
476: }
477: if ($custom_img_count > 0) {
1.94 raeburn 478: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 479: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 480: $r->print(
481: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
482: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
483: &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 />'.
484: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
485: if ($switch_server) {
1.30 raeburn 486: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 487: }
1.91 raeburn 488: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 489: return OK;
490: }
491: }
492: }
1.91 raeburn 493: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 494: }
495: return OK;
496: }
497:
498: sub process_changes {
1.92 raeburn 499: my ($r,$dom,$confname,$action,$roles,$values) = @_;
500: my %domconfig;
501: if (ref($values) eq 'HASH') {
502: %domconfig = %{$values};
503: }
1.3 raeburn 504: my $output;
505: if ($action eq 'login') {
1.9 raeburn 506: $output = &modify_login($r,$dom,$confname,%domconfig);
1.6 raeburn 507: } elsif ($action eq 'rolecolors') {
1.9 raeburn 508: $output = &modify_rolecolors($r,$dom,$confname,$roles,
509: %domconfig);
1.3 raeburn 510: } elsif ($action eq 'quotas') {
1.86 raeburn 511: $output = &modify_quotas($dom,$action,%domconfig);
1.3 raeburn 512: } elsif ($action eq 'autoenroll') {
513: $output = &modify_autoenroll($dom,%domconfig);
514: } elsif ($action eq 'autoupdate') {
515: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 516: } elsif ($action eq 'autocreate') {
517: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 518: } elsif ($action eq 'directorysrch') {
519: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 520: } elsif ($action eq 'usercreation') {
1.28 raeburn 521: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 522: } elsif ($action eq 'usermodification') {
523: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 524: } elsif ($action eq 'contacts') {
525: $output = &modify_contacts($dom,%domconfig);
1.43 raeburn 526: } elsif ($action eq 'defaults') {
527: $output = &modify_defaults($dom,$r);
1.46 raeburn 528: } elsif ($action eq 'scantron') {
1.48 raeburn 529: $output = &modify_scantron($r,$dom,$confname,%domconfig);
530: } elsif ($action eq 'coursecategories') {
531: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 532: } elsif ($action eq 'serverstatuses') {
533: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 534: } elsif ($action eq 'requestcourses') {
535: $output = &modify_quotas($dom,$action,%domconfig);
1.163 raeburn 536: } elsif ($action eq 'requestauthor') {
537: $output = &modify_quotas($dom,$action,%domconfig);
1.118 jms 538: } elsif ($action eq 'helpsettings') {
1.122 jms 539: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 540: } elsif ($action eq 'coursedefaults') {
541: $output = &modify_coursedefaults($dom,%domconfig);
1.137 raeburn 542: } elsif ($action eq 'usersessions') {
543: $output = &modify_usersessions($dom,%domconfig);
1.150 raeburn 544: } elsif ($action eq 'loadbalancing') {
545: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 546: }
547: return $output;
548: }
549:
550: sub print_config_box {
1.9 raeburn 551: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 552: my $rowtotal = 0;
1.49 raeburn 553: my $output;
554: if ($action eq 'coursecategories') {
555: $output = &coursecategories_javascript($settings);
1.91 raeburn 556: }
1.49 raeburn 557: $output .=
1.30 raeburn 558: '<table class="LC_nested_outer">
1.3 raeburn 559: <tr>
1.66 raeburn 560: <th align="left" valign="middle"><span class="LC_nobreak">'.
561: &mt($item->{text}).' '.
562: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
563: '</tr>';
1.30 raeburn 564: $rowtotal ++;
1.110 raeburn 565: my $numheaders = 1;
566: if (ref($item->{'header'}) eq 'ARRAY') {
567: $numheaders = scalar(@{$item->{'header'}});
568: }
569: if ($numheaders > 1) {
1.64 raeburn 570: my $colspan = '';
1.145 raeburn 571: my $rightcolspan = '';
1.168 raeburn 572: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
573: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 574: $colspan = ' colspan="2"';
575: }
1.145 raeburn 576: if ($action eq 'usersessions') {
577: $rightcolspan = ' colspan="3"';
578: }
1.30 raeburn 579: $output .= '
1.3 raeburn 580: <tr>
581: <td>
582: <table class="LC_nested">
583: <tr class="LC_info_row">
1.59 bisitz 584: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 585: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 586: </tr>';
1.69 raeburn 587: $rowtotal ++;
1.6 raeburn 588: if ($action eq 'autoupdate') {
1.30 raeburn 589: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 590: } elsif ($action eq 'usercreation') {
1.33 raeburn 591: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
592: } elsif ($action eq 'usermodification') {
593: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 594: } elsif ($action eq 'coursecategories') {
595: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 596: } elsif ($action eq 'login') {
1.168 raeburn 597: if ($numheaders == 3) {
598: $colspan = ' colspan="2"';
599: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
600: } else {
601: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
602: }
1.102 raeburn 603: } elsif ($action eq 'requestcourses') {
604: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 605: } elsif ($action eq 'requestauthor') {
606: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 607: } elsif ($action eq 'usersessions') {
608: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 609: } elsif ($action eq 'rolecolors') {
1.30 raeburn 610: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 611: } elsif ($action eq 'coursedefaults') {
612: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 613: }
1.30 raeburn 614: $output .= '
1.6 raeburn 615: </table>
616: </td>
617: </tr>
618: <tr>
619: <td>
620: <table class="LC_nested">
621: <tr class="LC_info_row">
1.59 bisitz 622: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 623: $output .= '
1.59 bisitz 624: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 625: </tr>';
626: $rowtotal ++;
1.6 raeburn 627: if ($action eq 'autoupdate') {
1.131 raeburn 628: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
629: </table>
630: </td>
631: </tr>
632: <tr>
633: <td>
634: <table class="LC_nested">
635: <tr class="LC_info_row">
636: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
637: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
638: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
639: $rowtotal ++;
1.28 raeburn 640: } elsif ($action eq 'usercreation') {
1.34 raeburn 641: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
642: </table>
643: </td>
644: </tr>
645: <tr>
646: <td>
647: <table class="LC_nested">
648: <tr class="LC_info_row">
1.59 bisitz 649: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
650: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 651: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
652: $rowtotal ++;
1.33 raeburn 653: } elsif ($action eq 'usermodification') {
1.63 raeburn 654: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
655: </table>
656: </td>
657: </tr>
658: <tr>
659: <td>
660: <table class="LC_nested">
661: <tr class="LC_info_row">
662: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
663: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
664: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
665: $rowtotal ++;
1.57 raeburn 666: } elsif ($action eq 'coursecategories') {
667: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 668: } elsif ($action eq 'login') {
1.168 raeburn 669: if ($numheaders == 3) {
670: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
671: </table>
672: </td>
673: </tr>
674: <tr>
675: <td>
676: <table class="LC_nested">
677: <tr class="LC_info_row">
678: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
679: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
680: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
681: $rowtotal ++;
682: } else {
683: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
684: }
1.102 raeburn 685: } elsif ($action eq 'requestcourses') {
1.163 raeburn 686: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
687: } elsif ($action eq 'requestauthor') {
688: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 689: } elsif ($action eq 'usersessions') {
1.145 raeburn 690: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
691: </table>
692: </td>
693: </tr>
694: <tr>
695: <td>
696: <table class="LC_nested">
697: <tr class="LC_info_row">
698: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
699: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
700: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
701: $rowtotal ++;
1.139 raeburn 702: } elsif ($action eq 'coursedefaults') {
703: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 704: } elsif ($action eq 'rolecolors') {
1.30 raeburn 705: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 706: </table>
707: </td>
708: </tr>
709: <tr>
710: <td>
711: <table class="LC_nested">
712: <tr class="LC_info_row">
1.69 raeburn 713: <td class="LC_left_item"'.$colspan.' valign="top">'.
714: &mt($item->{'header'}->[2]->{'col1'}).'</td>
715: <td class="LC_right_item" valign="top">'.
716: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 717: </tr>'.
1.30 raeburn 718: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 719: </table>
720: </td>
721: </tr>
722: <tr>
723: <td>
724: <table class="LC_nested">
725: <tr class="LC_info_row">
1.59 bisitz 726: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
727: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 728: </tr>'.
1.30 raeburn 729: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
730: $rowtotal += 2;
1.6 raeburn 731: }
1.3 raeburn 732: } else {
1.30 raeburn 733: $output .= '
1.3 raeburn 734: <tr>
735: <td>
736: <table class="LC_nested">
1.30 raeburn 737: <tr class="LC_info_row">';
1.24 raeburn 738: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 739: $output .= '
1.59 bisitz 740: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 741: } elsif ($action eq 'serverstatuses') {
742: $output .= '
743: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
744: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
745:
1.6 raeburn 746: } else {
1.30 raeburn 747: $output .= '
1.69 raeburn 748: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
749: }
1.72 raeburn 750: if (defined($item->{'header'}->[0]->{'col3'})) {
751: $output .= '<td class="LC_left_item" valign="top">'.
752: &mt($item->{'header'}->[0]->{'col2'});
753: if ($action eq 'serverstatuses') {
754: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
755: }
1.69 raeburn 756: } else {
757: $output .= '<td class="LC_right_item" valign="top">'.
758: &mt($item->{'header'}->[0]->{'col2'});
759: }
760: $output .= '</td>';
761: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 762: if (defined($item->{'header'}->[0]->{'col4'})) {
763: $output .= '<td class="LC_left_item" valign="top">'.
764: &mt($item->{'header'}->[0]->{'col3'});
765: } else {
766: $output .= '<td class="LC_right_item" valign="top">'.
767: &mt($item->{'header'}->[0]->{'col3'});
768: }
1.69 raeburn 769: if ($action eq 'serverstatuses') {
770: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
771: }
772: $output .= '</td>';
1.6 raeburn 773: }
1.150 raeburn 774: if ($item->{'header'}->[0]->{'col4'}) {
775: $output .= '<td class="LC_right_item" valign="top">'.
776: &mt($item->{'header'}->[0]->{'col4'});
777: }
1.69 raeburn 778: $output .= '</tr>';
1.48 raeburn 779: $rowtotal ++;
1.168 raeburn 780: if ($action eq 'quotas') {
1.86 raeburn 781: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 782: } elsif ($action eq 'autoenroll') {
1.30 raeburn 783: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 784: } elsif ($action eq 'autocreate') {
785: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 786: } elsif ($action eq 'directorysrch') {
1.30 raeburn 787: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 788: } elsif ($action eq 'contacts') {
1.30 raeburn 789: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 790: } elsif ($action eq 'defaults') {
791: $output .= &print_defaults($dom,\$rowtotal);
1.46 raeburn 792: } elsif ($action eq 'scantron') {
793: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 794: } elsif ($action eq 'serverstatuses') {
795: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 796: } elsif ($action eq 'helpsettings') {
1.168 raeburn 797: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 798: } elsif ($action eq 'loadbalancing') {
799: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 800: }
1.3 raeburn 801: }
1.30 raeburn 802: $output .= '
1.3 raeburn 803: </table>
804: </td>
805: </tr>
1.30 raeburn 806: </table><br />';
807: return ($output,$rowtotal);
1.1 raeburn 808: }
809:
1.3 raeburn 810: sub print_login {
1.168 raeburn 811: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 812: my ($css_class,$datatable);
1.6 raeburn 813: my %choices = &login_choices();
1.110 raeburn 814:
1.168 raeburn 815: if ($caller eq 'service') {
1.149 raeburn 816: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 817: my $choice = $choices{'disallowlogin'};
818: $css_class = ' class="LC_odd_row"';
1.128 raeburn 819: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 820: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 821: '<th>'.$choices{'server'}.'</th>'.
822: '<th>'.$choices{'serverpath'}.'</th>'.
823: '<th>'.$choices{'custompath'}.'</th>'.
824: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 825: my %disallowed;
826: if (ref($settings) eq 'HASH') {
827: if (ref($settings->{'loginvia'}) eq 'HASH') {
828: %disallowed = %{$settings->{'loginvia'}};
829: }
830: }
831: foreach my $lonhost (sort(keys(%servers))) {
832: my $direct = 'selected="selected"';
1.128 raeburn 833: if (ref($disallowed{$lonhost}) eq 'HASH') {
834: if ($disallowed{$lonhost}{'server'} ne '') {
835: $direct = '';
836: }
1.110 raeburn 837: }
1.115 raeburn 838: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 839: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 840: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
841: '</option>';
1.184 raeburn 842: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 843: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 844: my $selected = '';
1.128 raeburn 845: if (ref($disallowed{$lonhost}) eq 'HASH') {
846: if ($hostid eq $disallowed{$lonhost}{'server'}) {
847: $selected = 'selected="selected"';
848: }
1.110 raeburn 849: }
850: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
851: $servers{$hostid}.'</option>';
852: }
1.128 raeburn 853: $datatable .= '</select></td>'.
854: '<td><select name="'.$lonhost.'_serverpath">';
855: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
856: my $pathname = $path;
857: if ($path eq 'custom') {
858: $pathname = &mt('Custom Path').' ->';
859: }
860: my $selected = '';
861: if (ref($disallowed{$lonhost}) eq 'HASH') {
862: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
863: $selected = 'selected="selected"';
864: }
865: } elsif ($path eq '') {
866: $selected = 'selected="selected"';
867: }
868: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
869: }
870: $datatable .= '</select></td>';
871: my ($custom,$exempt);
872: if (ref($disallowed{$lonhost}) eq 'HASH') {
873: $custom = $disallowed{$lonhost}{'custompath'};
874: $exempt = $disallowed{$lonhost}{'exempt'};
875: }
876: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
877: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
878: '</tr>';
1.110 raeburn 879: }
880: $datatable .= '</table></td></tr>';
881: return $datatable;
1.168 raeburn 882: } elsif ($caller eq 'page') {
883: my %defaultchecked = (
884: 'coursecatalog' => 'on',
1.188 ! raeburn 885: 'helpdesk' => 'on',
1.168 raeburn 886: 'adminmail' => 'off',
887: 'newuser' => 'off',
888: );
1.188 ! raeburn 889: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 890: my (%checkedon,%checkedoff);
1.42 raeburn 891: foreach my $item (@toggles) {
1.168 raeburn 892: if ($defaultchecked{$item} eq 'on') {
893: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 894: $checkedoff{$item} = ' ';
1.168 raeburn 895: } elsif ($defaultchecked{$item} eq 'off') {
896: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 897: $checkedon{$item} = ' ';
898: }
1.1 raeburn 899: }
1.168 raeburn 900: my @images = ('img','logo','domlogo','login');
901: my @logintext = ('textcol','bgcol');
902: my @bgs = ('pgbg','mainbg','sidebg');
903: my @links = ('link','alink','vlink');
904: my %designhash = &Apache::loncommon::get_domainconf($dom);
905: my %defaultdesign = %Apache::loncommon::defaultdesign;
906: my (%is_custom,%designs);
907: my %defaults = (
908: font => $defaultdesign{'login.font'},
909: );
1.6 raeburn 910: foreach my $item (@images) {
1.168 raeburn 911: $defaults{$item} = $defaultdesign{'login.'.$item};
912: $defaults{'showlogo'}{$item} = 1;
913: }
914: foreach my $item (@bgs) {
915: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 916: }
1.41 raeburn 917: foreach my $item (@logintext) {
1.168 raeburn 918: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 919: }
1.168 raeburn 920: foreach my $item (@links) {
921: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 922: }
1.168 raeburn 923: if (ref($settings) eq 'HASH') {
924: foreach my $item (@toggles) {
925: if ($settings->{$item} eq '1') {
926: $checkedon{$item} = ' checked="checked" ';
927: $checkedoff{$item} = ' ';
928: } elsif ($settings->{$item} eq '0') {
929: $checkedoff{$item} = ' checked="checked" ';
930: $checkedon{$item} = ' ';
931: }
932: }
933: foreach my $item (@images) {
934: if (defined($settings->{$item})) {
935: $designs{$item} = $settings->{$item};
936: $is_custom{$item} = 1;
937: }
938: if (defined($settings->{'showlogo'}{$item})) {
939: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
940: }
941: }
942: foreach my $item (@logintext) {
943: if ($settings->{$item} ne '') {
944: $designs{'logintext'}{$item} = $settings->{$item};
945: $is_custom{$item} = 1;
946: }
947: }
948: if ($settings->{'font'} ne '') {
949: $designs{'font'} = $settings->{'font'};
950: $is_custom{'font'} = 1;
951: }
952: foreach my $item (@bgs) {
953: if ($settings->{$item} ne '') {
954: $designs{'bgs'}{$item} = $settings->{$item};
955: $is_custom{$item} = 1;
956: }
957: }
958: foreach my $item (@links) {
959: if ($settings->{$item} ne '') {
960: $designs{'links'}{$item} = $settings->{$item};
961: $is_custom{$item} = 1;
962: }
963: }
964: } else {
965: if ($designhash{$dom.'.login.font'} ne '') {
966: $designs{'font'} = $designhash{$dom.'.login.font'};
967: $is_custom{'font'} = 1;
968: }
969: foreach my $item (@images) {
970: if ($designhash{$dom.'.login.'.$item} ne '') {
971: $designs{$item} = $designhash{$dom.'.login.'.$item};
972: $is_custom{$item} = 1;
973: }
974: }
975: foreach my $item (@bgs) {
976: if ($designhash{$dom.'.login.'.$item} ne '') {
977: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
978: $is_custom{$item} = 1;
979: }
1.6 raeburn 980: }
1.168 raeburn 981: foreach my $item (@links) {
982: if ($designhash{$dom.'.login.'.$item} ne '') {
983: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
984: $is_custom{$item} = 1;
985: }
1.6 raeburn 986: }
987: }
1.168 raeburn 988: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
989: logo => 'Institution Logo',
990: domlogo => 'Domain Logo',
991: login => 'Login box');
992: my $itemcount = 1;
993: foreach my $item (@toggles) {
994: $css_class = $itemcount%2?' class="LC_odd_row"':'';
995: $datatable .=
996: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
997: '</td><td>'.
998: '<span class="LC_nobreak"><label><input type="radio" name="'.
999: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1000: '</label> <label><input type="radio" name="'.$item.'"'.
1001: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1002: '</tr>';
1003: $itemcount ++;
1.6 raeburn 1004: }
1.168 raeburn 1005: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1006: $datatable .= '</tr></table></td></tr>';
1007: } elsif ($caller eq 'help') {
1008: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1009: my $switchserver = &check_switchserver($dom,$confname);
1010: my $itemcount = 1;
1011: $defaulturl = '/adm/loginproblems.html';
1012: $defaulttype = 'default';
1013: %lt = &Apache::lonlocal::texthash (
1014: del => 'Delete?',
1015: rep => 'Replace:',
1016: upl => 'Upload:',
1017: default => 'Default',
1018: custom => 'Custom',
1019: );
1020: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1021: my @currlangs;
1022: if (ref($settings) eq 'HASH') {
1023: if (ref($settings->{'helpurl'}) eq 'HASH') {
1024: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1025: next if ($settings->{'helpurl'}{$key} eq '');
1026: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1027: $type{$key} = 'custom';
1028: unless ($key eq 'nolang') {
1029: push(@currlangs,$key);
1030: }
1031: }
1032: } elsif ($settings->{'helpurl'} ne '') {
1033: $type{'nolang'} = 'custom';
1034: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1035: }
1036: }
1.168 raeburn 1037: foreach my $lang ('nolang',sort(@currlangs)) {
1038: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1039: $datatable .= '<tr'.$css_class.'>';
1040: if ($url{$lang} eq '') {
1041: $url{$lang} = $defaulturl;
1042: }
1043: if ($type{$lang} eq '') {
1044: $type{$lang} = $defaulttype;
1045: }
1046: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1047: if ($lang eq 'nolang') {
1048: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1049: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1050: } else {
1051: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1052: $langchoices{$lang},
1053: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1054: }
1055: $datatable .= '</span></td>'."\n".
1056: '<td class="LC_left_item">';
1057: if ($type{$lang} eq 'custom') {
1058: $datatable .= '<span class="LC_nobreak"><label>'.
1059: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1060: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1061: } else {
1062: $datatable .= $lt{'upl'};
1063: }
1064: $datatable .='<br />';
1065: if ($switchserver) {
1066: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1067: } else {
1068: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1069: }
1.168 raeburn 1070: $datatable .= '</td></tr>';
1071: $itemcount ++;
1.6 raeburn 1072: }
1.168 raeburn 1073: my @addlangs;
1074: foreach my $lang (sort(keys(%langchoices))) {
1075: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1076: push(@addlangs,$lang);
1077: }
1078: if (@addlangs > 0) {
1079: my %toadd;
1080: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1081: $toadd{''} = &mt('Select');
1082: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1083: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1084: &mt('Add log-in help page for a specific language:').' '.
1085: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1086: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1087: if ($switchserver) {
1088: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1089: } else {
1090: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1091: }
1.168 raeburn 1092: $datatable .= '</td></tr>';
1.169 raeburn 1093: $itemcount ++;
1.6 raeburn 1094: }
1.169 raeburn 1095: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1096: }
1.6 raeburn 1097: return $datatable;
1098: }
1099:
1100: sub login_choices {
1101: my %choices =
1102: &Apache::lonlocal::texthash (
1.116 bisitz 1103: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1104: adminmail => "Display Administrator's E-mail Address?",
1.188 ! raeburn 1105: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1106: disallowlogin => "Login page requests redirected",
1107: hostid => "Server",
1.128 raeburn 1108: server => "Redirect to:",
1109: serverpath => "Path",
1110: custompath => "Custom",
1111: exempt => "Exempt IP(s)",
1.110 raeburn 1112: directlogin => "No redirect",
1113: newuser => "Link to create a user account",
1114: img => "Header",
1115: logo => "Main Logo",
1116: domlogo => "Domain Logo",
1117: login => "Log-in Header",
1118: textcol => "Text color",
1119: bgcol => "Box color",
1120: bgs => "Background colors",
1121: links => "Link colors",
1122: font => "Font color",
1123: pgbg => "Header",
1124: mainbg => "Page",
1125: sidebg => "Login box",
1126: link => "Link",
1127: alink => "Active link",
1128: vlink => "Visited link",
1.6 raeburn 1129: );
1130: return %choices;
1131: }
1132:
1133: sub print_rolecolors {
1.30 raeburn 1134: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1135: my %choices = &color_font_choices();
1136: my @bgs = ('pgbg','tabbg','sidebg');
1137: my @links = ('link','alink','vlink');
1138: my @images = ('img');
1139: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1140: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1141: my %defaultdesign = %Apache::loncommon::defaultdesign;
1142: my (%is_custom,%designs);
1143: my %defaults = (
1144: img => $defaultdesign{$role.'.img'},
1145: font => $defaultdesign{$role.'.font'},
1.97 tempelho 1146: fontmenu => $defaultdesign{$role.'.fontmenu'},
1.6 raeburn 1147: );
1148: foreach my $item (@bgs) {
1149: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1150: }
1151: foreach my $item (@links) {
1152: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1153: }
1154: if (ref($settings) eq 'HASH') {
1155: if (ref($settings->{$role}) eq 'HASH') {
1156: if ($settings->{$role}->{'img'} ne '') {
1157: $designs{'img'} = $settings->{$role}->{'img'};
1158: $is_custom{'img'} = 1;
1159: }
1160: if ($settings->{$role}->{'font'} ne '') {
1161: $designs{'font'} = $settings->{$role}->{'font'};
1162: $is_custom{'font'} = 1;
1163: }
1.97 tempelho 1164: if ($settings->{$role}->{'fontmenu'} ne '') {
1165: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1166: $is_custom{'fontmenu'} = 1;
1167: }
1.6 raeburn 1168: foreach my $item (@bgs) {
1169: if ($settings->{$role}->{$item} ne '') {
1170: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1171: $is_custom{$item} = 1;
1172: }
1173: }
1174: foreach my $item (@links) {
1175: if ($settings->{$role}->{$item} ne '') {
1176: $designs{'links'}{$item} = $settings->{$role}->{$item};
1177: $is_custom{$item} = 1;
1178: }
1179: }
1180: }
1181: } else {
1182: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1183: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1184: $is_custom{'img'} = 1;
1185: }
1.97 tempelho 1186: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1187: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1188: $is_custom{'fontmenu'} = 1;
1189: }
1.6 raeburn 1190: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1191: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1192: $is_custom{'font'} = 1;
1193: }
1194: foreach my $item (@bgs) {
1195: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1196: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1197: $is_custom{$item} = 1;
1198:
1199: }
1200: }
1201: foreach my $item (@links) {
1202: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1203: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1204: $is_custom{$item} = 1;
1205: }
1206: }
1207: }
1208: my $itemcount = 1;
1.30 raeburn 1209: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1210: $datatable .= '</tr></table></td></tr>';
1211: return $datatable;
1212: }
1213:
1214: sub display_color_options {
1.9 raeburn 1215: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1216: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1217: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1218: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1219: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1220: '<td>'.$choices->{'font'}.'</td>';
1221: if (!$is_custom->{'font'}) {
1.30 raeburn 1222: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1223: } else {
1224: $datatable .= '<td> </td>';
1225: }
1.174 foxr 1226: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1227:
1.8 raeburn 1228: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1229: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1230: ' value="'.$current_color.'" /> '.
1231: ' </td></tr>';
1.107 raeburn 1232: unless ($role eq 'login') {
1233: $datatable .= '<tr'.$css_class.'>'.
1234: '<td>'.$choices->{'fontmenu'}.'</td>';
1235: if (!$is_custom->{'fontmenu'}) {
1236: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1237: } else {
1238: $datatable .= '<td> </td>';
1239: }
1.174 foxr 1240: $current_color = $designs->{'fontmenu'} ?
1241: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1242: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1243: '<input class="colorchooser" type="text" size="10" name="'
1244: .$role.'_fontmenu"'.
1245: ' value="'.$current_color.'" /> '.
1246: ' </td></tr>';
1.97 tempelho 1247: }
1.9 raeburn 1248: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1249: foreach my $img (@{$images}) {
1.18 albertel 1250: $itemcount ++;
1.6 raeburn 1251: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1252: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1253: '<td>'.$choices->{$img};
1.41 raeburn 1254: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1255: if ($role eq 'login') {
1256: if ($img eq 'login') {
1257: $login_hdr_pick =
1.135 bisitz 1258: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1259: $logincolors =
1260: &login_text_colors($img,$role,$logintext,$phase,$choices,
1261: $designs);
1262: } elsif ($img ne 'domlogo') {
1263: $datatable.= &logo_display_options($img,$defaults,$designs);
1264: }
1265: }
1266: $datatable .= '</td>';
1.6 raeburn 1267: if ($designs->{$img} ne '') {
1268: $imgfile = $designs->{$img};
1.18 albertel 1269: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1270: } else {
1271: $imgfile = $defaults->{$img};
1272: }
1273: if ($imgfile) {
1.9 raeburn 1274: my ($showfile,$fullsize);
1275: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1276: my $urldir = $1;
1277: my $filename = $2;
1278: my @info = &Apache::lonnet::stat_file($designs->{$img});
1279: if (@info) {
1280: my $thumbfile = 'tn-'.$filename;
1281: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1282: if (@thumb) {
1283: $showfile = $urldir.'/'.$thumbfile;
1284: } else {
1285: $showfile = $imgfile;
1286: }
1287: } else {
1288: $showfile = '';
1289: }
1290: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1291: $showfile = $imgfile;
1.6 raeburn 1292: my $imgdir = $1;
1293: my $filename = $2;
1.159 raeburn 1294: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1295: $showfile = "/$imgdir/tn-".$filename;
1296: } else {
1.159 raeburn 1297: my $input = $londocroot.$imgfile;
1298: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1299: if (!-e $output) {
1.9 raeburn 1300: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1301: my ($fullwidth,$fullheight) = &check_dimensions($input);
1302: if ($fullwidth ne '' && $fullheight ne '') {
1303: if ($fullwidth > $width && $fullheight > $height) {
1304: my $size = $width.'x'.$height;
1305: system("convert -sample $size $input $output");
1.159 raeburn 1306: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1307: }
1308: }
1.6 raeburn 1309: }
1310: }
1.16 raeburn 1311: }
1.6 raeburn 1312: if ($showfile) {
1.40 raeburn 1313: if ($showfile =~ m{^/(adm|res)/}) {
1314: if ($showfile =~ m{^/res/}) {
1315: my $local_showfile =
1316: &Apache::lonnet::filelocation('',$showfile);
1317: &Apache::lonnet::repcopy($local_showfile);
1318: }
1319: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1320: }
1321: if ($imgfile) {
1322: if ($imgfile =~ m{^/(adm|res)/}) {
1323: if ($imgfile =~ m{^/res/}) {
1324: my $local_imgfile =
1325: &Apache::lonnet::filelocation('',$imgfile);
1326: &Apache::lonnet::repcopy($local_imgfile);
1327: }
1328: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1329: } else {
1330: $fullsize = $imgfile;
1331: }
1332: }
1.41 raeburn 1333: $datatable .= '<td>';
1334: if ($img eq 'login') {
1.135 bisitz 1335: $datatable .= $login_hdr_pick;
1336: }
1.41 raeburn 1337: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1338: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1339: } else {
1340: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1341: &mt('Upload:');
1342: }
1343: } else {
1344: $datatable .= '<td colspan="2" class="LC_right_item"><br />'.
1345: &mt('Upload:');
1346: }
1.9 raeburn 1347: if ($switchserver) {
1348: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1349: } else {
1.135 bisitz 1350: if ($img ne 'login') { # suppress file selection for Log-in header
1351: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1352: }
1.9 raeburn 1353: }
1354: $datatable .= '</td></tr>';
1.6 raeburn 1355: }
1356: $itemcount ++;
1357: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1358: $datatable .= '<tr'.$css_class.'>'.
1359: '<td>'.$choices->{'bgs'}.'</td>';
1360: my $bgs_def;
1361: foreach my $item (@{$bgs}) {
1362: if (!$is_custom->{$item}) {
1.70 raeburn 1363: $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 1364: }
1365: }
1366: if ($bgs_def) {
1.8 raeburn 1367: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1368: } else {
1369: $datatable .= '<td> </td>';
1370: }
1371: $datatable .= '<td class="LC_right_item">'.
1372: '<table border="0"><tr>';
1.174 foxr 1373:
1.6 raeburn 1374: foreach my $item (@{$bgs}) {
1.174 foxr 1375: $datatable .= '<td align="center">';
1376: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1377: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1378: $datatable .= ' ';
1.6 raeburn 1379: }
1.174 foxr 1380: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1381: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1382: }
1383: $datatable .= '</tr></table></td></tr>';
1384: $itemcount ++;
1385: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1386: $datatable .= '<tr'.$css_class.'>'.
1387: '<td>'.$choices->{'links'}.'</td>';
1388: my $links_def;
1389: foreach my $item (@{$links}) {
1390: if (!$is_custom->{$item}) {
1.30 raeburn 1391: $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 1392: }
1393: }
1394: if ($links_def) {
1.8 raeburn 1395: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1396: } else {
1397: $datatable .= '<td> </td>';
1398: }
1399: $datatable .= '<td class="LC_right_item">'.
1400: '<table border="0"><tr>';
1401: foreach my $item (@{$links}) {
1.174 foxr 1402: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1403: $datatable .= '<td align="center">'."\n";
1404:
1.6 raeburn 1405: if ($designs->{'links'}{$item}) {
1.174 foxr 1406: $datatable.=' ';
1.6 raeburn 1407: }
1.174 foxr 1408: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1409: '" /></td>';
1410: }
1.30 raeburn 1411: $$rowtotal += $itemcount;
1.3 raeburn 1412: return $datatable;
1413: }
1414:
1.70 raeburn 1415: sub logo_display_options {
1416: my ($img,$defaults,$designs) = @_;
1417: my $checkedon;
1418: if (ref($defaults) eq 'HASH') {
1419: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1420: if ($defaults->{'showlogo'}{$img}) {
1421: $checkedon = 'checked="checked" ';
1422: }
1423: }
1424: }
1425: if (ref($designs) eq 'HASH') {
1426: if (ref($designs->{'showlogo'}) eq 'HASH') {
1427: if (defined($designs->{'showlogo'}{$img})) {
1428: if ($designs->{'showlogo'}{$img} == 0) {
1429: $checkedon = '';
1430: } elsif ($designs->{'showlogo'}{$img} == 1) {
1431: $checkedon = 'checked="checked" ';
1432: }
1433: }
1434: }
1435: }
1436: return '<br /><label> <input type="checkbox" name="'.
1437: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1438: &mt('show').'</label>'."\n";
1439: }
1440:
1.41 raeburn 1441: sub login_header_options {
1.135 bisitz 1442: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1443: my $output = '';
1.41 raeburn 1444: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1445: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1446: if (!$is_custom->{'textcol'}) {
1447: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1448: ' ';
1449: }
1450: if (!$is_custom->{'bgcol'}) {
1451: $output .= $choices->{'bgcol'}.': '.
1452: '<span id="css_'.$role.'_font" style="background-color: '.
1453: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1454: }
1455: $output .= '<br />';
1456: }
1457: $output .='<br />';
1458: return $output;
1459: }
1460:
1461: sub login_text_colors {
1462: my ($img,$role,$logintext,$phase,$choices,$designs) = @_;
1463: my $color_menu = '<table border="0"><tr>';
1464: foreach my $item (@{$logintext}) {
1465: my $link = &color_pick($phase,$role,$item,$choices->{$item},$designs->{'logintext'}{$item});
1466: $color_menu .= '<td align="center">'.$link;
1467: if ($designs->{'logintext'}{$item}) {
1468: $color_menu .= ' <span id="css_'.$role.'_'.$item.'" style="background-color: '.$designs->{'logintext'}{$item}.';"> </span>';
1469: }
1470: $color_menu .= '<br /><input type="text" size="8" name="'.$role.'_'.$item.'" value="'.
1471: $designs->{'logintext'}{$item}.'" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>'.
1472: '<td> </td>';
1473: }
1474: $color_menu .= '</tr></table><br />';
1475: return $color_menu;
1476: }
1477:
1478: sub image_changes {
1479: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1480: my $output;
1.135 bisitz 1481: if ($img eq 'login') {
1482: # suppress image for Log-in header
1483: } elsif (!$is_custom) {
1.70 raeburn 1484: if ($img ne 'domlogo') {
1.41 raeburn 1485: $output .= &mt('Default image:').'<br />';
1486: } else {
1487: $output .= &mt('Default in use:').'<br />';
1488: }
1489: }
1.135 bisitz 1490: if ($img eq 'login') { # suppress image for Log-in header
1491: $output .= '<td>'.$logincolors;
1.41 raeburn 1492: } else {
1.135 bisitz 1493: if ($img_import) {
1494: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1495: }
1496: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1497: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1498: if ($is_custom) {
1499: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1500: '<input type="checkbox" name="'.
1501: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1502: '</label> '.&mt('Replace:').'</span><br />';
1503: } else {
1504: $output .= '<td valign="bottom">'.$logincolors.&mt('Upload:').'<br />';
1505: }
1.41 raeburn 1506: }
1507: return $output;
1508: }
1509:
1.6 raeburn 1510: sub color_pick {
1511: my ($phase,$role,$item,$desc,$curcol) = @_;
1512: my $link = '<a href="javascript:pjump('."'color_custom','".$desc.
1513: "','".$curcol."','".$role.'_'.$item."','parmform.pres','psub'".
1514: ');">'.$desc.'</a>';
1515: return $link;
1516: }
1517:
1.3 raeburn 1518: sub print_quotas {
1.86 raeburn 1519: my ($dom,$settings,$rowtotal,$action) = @_;
1520: my $context;
1521: if ($action eq 'quotas') {
1522: $context = 'tools';
1523: } else {
1524: $context = $action;
1525: }
1.101 raeburn 1526: my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 1527: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1528: my $typecount = 0;
1.101 raeburn 1529: my ($css_class,%titles);
1.86 raeburn 1530: if ($context eq 'requestcourses') {
1.98 raeburn 1531: @usertools = ('official','unofficial','community');
1.106 raeburn 1532: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1533: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1534: %titles = &courserequest_titles();
1.163 raeburn 1535: } elsif ($context eq 'requestauthor') {
1536: @usertools = ('author');
1537: @options = ('norequest','approval','automatic');
1538: %titles = &authorrequest_titles();
1.86 raeburn 1539: } else {
1.162 raeburn 1540: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1541: %titles = &tool_titles();
1.86 raeburn 1542: }
1.26 raeburn 1543: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1544: foreach my $type (@{$types}) {
1.72 raeburn 1545: my $currdefquota;
1.163 raeburn 1546: unless (($context eq 'requestcourses') ||
1547: ($context eq 'requestauthor')) {
1.86 raeburn 1548: if (ref($settings) eq 'HASH') {
1549: if (ref($settings->{defaultquota}) eq 'HASH') {
1550: $currdefquota = $settings->{defaultquota}->{$type};
1551: } else {
1552: $currdefquota = $settings->{$type};
1553: }
1.78 raeburn 1554: }
1.72 raeburn 1555: }
1.3 raeburn 1556: if (defined($usertypes->{$type})) {
1557: $typecount ++;
1558: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1559: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1560: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1561: '<td class="LC_left_item">';
1.101 raeburn 1562: if ($context eq 'requestcourses') {
1563: $datatable .= '<table><tr>';
1564: }
1565: my %cell;
1.72 raeburn 1566: foreach my $item (@usertools) {
1.101 raeburn 1567: if ($context eq 'requestcourses') {
1568: my ($curroption,$currlimit);
1569: if (ref($settings) eq 'HASH') {
1570: if (ref($settings->{$item}) eq 'HASH') {
1571: $curroption = $settings->{$item}->{$type};
1572: if ($curroption =~ /^autolimit=(\d*)$/) {
1573: $currlimit = $1;
1574: }
1575: }
1576: }
1577: if (!$curroption) {
1578: $curroption = 'norequest';
1579: }
1580: $datatable .= '<th>'.$titles{$item}.'</th>';
1581: foreach my $option (@options) {
1582: my $val = $option;
1583: if ($option eq 'norequest') {
1584: $val = 0;
1585: }
1586: if ($option eq 'validate') {
1587: my $canvalidate = 0;
1588: if (ref($validations{$item}) eq 'HASH') {
1589: if ($validations{$item}{$type}) {
1590: $canvalidate = 1;
1591: }
1592: }
1593: next if (!$canvalidate);
1594: }
1595: my $checked = '';
1596: if ($option eq $curroption) {
1597: $checked = ' checked="checked"';
1598: } elsif ($option eq 'autolimit') {
1599: if ($curroption =~ /^autolimit/) {
1600: $checked = ' checked="checked"';
1601: }
1602: }
1603: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1604: '<input type="radio" name="crsreq_'.$item.
1605: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1606: $titles{$option}.'</label>';
1.101 raeburn 1607: if ($option eq 'autolimit') {
1.127 raeburn 1608: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1609: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1610: 'value="'.$currlimit.'" />';
1.101 raeburn 1611: }
1.127 raeburn 1612: $cell{$item} .= '</span> ';
1.103 raeburn 1613: if ($option eq 'autolimit') {
1.127 raeburn 1614: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1615: }
1.101 raeburn 1616: }
1.163 raeburn 1617: } elsif ($context eq 'requestauthor') {
1618: my $curroption;
1619: if (ref($settings) eq 'HASH') {
1620: $curroption = $settings->{$type};
1621: }
1622: if (!$curroption) {
1623: $curroption = 'norequest';
1624: }
1625: foreach my $option (@options) {
1626: my $val = $option;
1627: if ($option eq 'norequest') {
1628: $val = 0;
1629: }
1630: my $checked = '';
1631: if ($option eq $curroption) {
1632: $checked = ' checked="checked"';
1633: }
1634: $datatable .= '<span class="LC_nobreak"><label>'.
1635: '<input type="radio" name="authorreq_'.$type.
1636: '" value="'.$val.'"'.$checked.' />'.
1637: $titles{$option}.'</label></span> ';
1638: }
1.101 raeburn 1639: } else {
1640: my $checked = 'checked="checked" ';
1641: if (ref($settings) eq 'HASH') {
1642: if (ref($settings->{$item}) eq 'HASH') {
1643: if ($settings->{$item}->{$type} == 0) {
1644: $checked = '';
1645: } elsif ($settings->{$item}->{$type} == 1) {
1646: $checked = 'checked="checked" ';
1647: }
1.78 raeburn 1648: }
1.72 raeburn 1649: }
1.101 raeburn 1650: $datatable .= '<span class="LC_nobreak"><label>'.
1651: '<input type="checkbox" name="'.$context.'_'.$item.
1652: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1653: '</label></span> ';
1.72 raeburn 1654: }
1.101 raeburn 1655: }
1656: if ($context eq 'requestcourses') {
1657: $datatable .= '</tr><tr>';
1658: foreach my $item (@usertools) {
1.106 raeburn 1659: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1660: }
1661: $datatable .= '</tr></table>';
1.72 raeburn 1662: }
1.86 raeburn 1663: $datatable .= '</td>';
1.163 raeburn 1664: unless (($context eq 'requestcourses') ||
1665: ($context eq 'requestauthor')) {
1.86 raeburn 1666: $datatable .=
1667: '<td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 1668: '<input type="text" name="quota_'.$type.
1.72 raeburn 1669: '" value="'.$currdefquota.
1.86 raeburn 1670: '" size="5" /> Mb</span></td>';
1671: }
1672: $datatable .= '</tr>';
1.3 raeburn 1673: }
1674: }
1675: }
1.163 raeburn 1676: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1677: $defaultquota = '20';
1678: if (ref($settings) eq 'HASH') {
1679: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1680: $defaultquota = $settings->{'defaultquota'}->{'default'};
1681: } elsif (defined($settings->{'default'})) {
1682: $defaultquota = $settings->{'default'};
1683: }
1.3 raeburn 1684: }
1685: }
1686: $typecount ++;
1687: $css_class = $typecount%2?' class="LC_odd_row"':'';
1688: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1689: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1690: '<td class="LC_left_item">';
1.101 raeburn 1691: if ($context eq 'requestcourses') {
1692: $datatable .= '<table><tr>';
1693: }
1694: my %defcell;
1.72 raeburn 1695: foreach my $item (@usertools) {
1.101 raeburn 1696: if ($context eq 'requestcourses') {
1697: my ($curroption,$currlimit);
1698: if (ref($settings) eq 'HASH') {
1699: if (ref($settings->{$item}) eq 'HASH') {
1700: $curroption = $settings->{$item}->{'default'};
1701: if ($curroption =~ /^autolimit=(\d*)$/) {
1702: $currlimit = $1;
1703: }
1704: }
1705: }
1706: if (!$curroption) {
1707: $curroption = 'norequest';
1708: }
1709: $datatable .= '<th>'.$titles{$item}.'</th>';
1710: foreach my $option (@options) {
1711: my $val = $option;
1712: if ($option eq 'norequest') {
1713: $val = 0;
1714: }
1715: if ($option eq 'validate') {
1716: my $canvalidate = 0;
1717: if (ref($validations{$item}) eq 'HASH') {
1718: if ($validations{$item}{'default'}) {
1719: $canvalidate = 1;
1720: }
1721: }
1722: next if (!$canvalidate);
1723: }
1724: my $checked = '';
1725: if ($option eq $curroption) {
1726: $checked = ' checked="checked"';
1727: } elsif ($option eq 'autolimit') {
1728: if ($curroption =~ /^autolimit/) {
1729: $checked = ' checked="checked"';
1730: }
1731: }
1732: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1733: '<input type="radio" name="crsreq_'.$item.
1734: '_default" value="'.$val.'"'.$checked.' />'.
1735: $titles{$option}.'</label>';
1736: if ($option eq 'autolimit') {
1.127 raeburn 1737: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1738: $item.'_limit_default" size="1" '.
1739: 'value="'.$currlimit.'" />';
1740: }
1.127 raeburn 1741: $defcell{$item} .= '</span> ';
1.104 raeburn 1742: if ($option eq 'autolimit') {
1.127 raeburn 1743: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1744: }
1.101 raeburn 1745: }
1.163 raeburn 1746: } elsif ($context eq 'requestauthor') {
1747: my $curroption;
1748: if (ref($settings) eq 'HASH') {
1.172 raeburn 1749: $curroption = $settings->{'default'};
1.163 raeburn 1750: }
1751: if (!$curroption) {
1752: $curroption = 'norequest';
1753: }
1754: foreach my $option (@options) {
1755: my $val = $option;
1756: if ($option eq 'norequest') {
1757: $val = 0;
1758: }
1759: my $checked = '';
1760: if ($option eq $curroption) {
1761: $checked = ' checked="checked"';
1762: }
1763: $datatable .= '<span class="LC_nobreak"><label>'.
1764: '<input type="radio" name="authorreq_default"'.
1765: ' value="'.$val.'"'.$checked.' />'.
1766: $titles{$option}.'</label></span> ';
1767: }
1.101 raeburn 1768: } else {
1769: my $checked = 'checked="checked" ';
1770: if (ref($settings) eq 'HASH') {
1771: if (ref($settings->{$item}) eq 'HASH') {
1772: if ($settings->{$item}->{'default'} == 0) {
1773: $checked = '';
1774: } elsif ($settings->{$item}->{'default'} == 1) {
1775: $checked = 'checked="checked" ';
1776: }
1.78 raeburn 1777: }
1.72 raeburn 1778: }
1.101 raeburn 1779: $datatable .= '<span class="LC_nobreak"><label>'.
1780: '<input type="checkbox" name="'.$context.'_'.$item.
1781: '" value="default" '.$checked.'/>'.$titles{$item}.
1782: '</label></span> ';
1783: }
1784: }
1785: if ($context eq 'requestcourses') {
1786: $datatable .= '</tr><tr>';
1787: foreach my $item (@usertools) {
1.106 raeburn 1788: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1789: }
1.101 raeburn 1790: $datatable .= '</tr></table>';
1.72 raeburn 1791: }
1.86 raeburn 1792: $datatable .= '</td>';
1.163 raeburn 1793: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1794: $datatable .= '<td class="LC_right_item"><span class="LC_nobreak">'.
1795: '<input type="text" name="defaultquota" value="'.
1796: $defaultquota.'" size="5" /> Mb</span></td>';
1797: }
1798: $datatable .= '</tr>';
1.72 raeburn 1799: $typecount ++;
1800: $css_class = $typecount%2?' class="LC_odd_row"':'';
1801: $datatable .= '<tr'.$css_class.'>'.
1.104 raeburn 1802: '<td>'.&mt('LON-CAPA Advanced Users').' ';
1803: if ($context eq 'requestcourses') {
1.109 raeburn 1804: $datatable .= &mt('(overrides affiliation, if set)').
1805: '</td>'.
1806: '<td class="LC_left_item">'.
1807: '<table><tr>';
1.101 raeburn 1808: } else {
1.109 raeburn 1809: $datatable .= &mt('(overrides affiliation, if checked)').
1810: '</td>'.
1811: '<td class="LC_left_item" colspan="2">'.
1812: '<br />';
1.101 raeburn 1813: }
1814: my %advcell;
1.72 raeburn 1815: foreach my $item (@usertools) {
1.101 raeburn 1816: if ($context eq 'requestcourses') {
1817: my ($curroption,$currlimit);
1818: if (ref($settings) eq 'HASH') {
1819: if (ref($settings->{$item}) eq 'HASH') {
1820: $curroption = $settings->{$item}->{'_LC_adv'};
1821: if ($curroption =~ /^autolimit=(\d*)$/) {
1822: $currlimit = $1;
1823: }
1824: }
1825: }
1826: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1827: my $checked = '';
1828: if ($curroption eq '') {
1829: $checked = ' checked="checked"';
1830: }
1831: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1832: '<input type="radio" name="crsreq_'.$item.
1833: '__LC_adv" value=""'.$checked.' />'.
1834: &mt('No override set').'</label></span> ';
1.101 raeburn 1835: foreach my $option (@options) {
1836: my $val = $option;
1837: if ($option eq 'norequest') {
1838: $val = 0;
1839: }
1840: if ($option eq 'validate') {
1841: my $canvalidate = 0;
1842: if (ref($validations{$item}) eq 'HASH') {
1843: if ($validations{$item}{'_LC_adv'}) {
1844: $canvalidate = 1;
1845: }
1846: }
1847: next if (!$canvalidate);
1848: }
1849: my $checked = '';
1.104 raeburn 1850: if ($val eq $curroption) {
1.101 raeburn 1851: $checked = ' checked="checked"';
1852: } elsif ($option eq 'autolimit') {
1853: if ($curroption =~ /^autolimit/) {
1854: $checked = ' checked="checked"';
1855: }
1856: }
1857: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1858: '<input type="radio" name="crsreq_'.$item.
1859: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1860: $titles{$option}.'</label>';
1861: if ($option eq 'autolimit') {
1.127 raeburn 1862: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1863: $item.'_limit__LC_adv" size="1" '.
1864: 'value="'.$currlimit.'" />';
1865: }
1.127 raeburn 1866: $advcell{$item} .= '</span> ';
1.104 raeburn 1867: if ($option eq 'autolimit') {
1.127 raeburn 1868: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1869: }
1.101 raeburn 1870: }
1.163 raeburn 1871: } elsif ($context eq 'requestauthor') {
1872: my $curroption;
1873: if (ref($settings) eq 'HASH') {
1874: $curroption = $settings->{'_LC_adv'};
1875: }
1876: my $checked = '';
1877: if ($curroption eq '') {
1878: $checked = ' checked="checked"';
1879: }
1880: $datatable .= '<span class="LC_nobreak"><label>'.
1881: '<input type="radio" name="authorreq__LC_adv"'.
1882: ' value=""'.$checked.' />'.
1883: &mt('No override set').'</label></span> ';
1884: foreach my $option (@options) {
1885: my $val = $option;
1886: if ($option eq 'norequest') {
1887: $val = 0;
1888: }
1889: my $checked = '';
1890: if ($val eq $curroption) {
1891: $checked = ' checked="checked"';
1892: }
1893: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1894: '<input type="radio" name="authorreq__LC_adv"'.
1895: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1896: $titles{$option}.'</label></span> ';
1897: }
1.101 raeburn 1898: } else {
1899: my $checked = 'checked="checked" ';
1900: if (ref($settings) eq 'HASH') {
1901: if (ref($settings->{$item}) eq 'HASH') {
1902: if ($settings->{$item}->{'_LC_adv'} == 0) {
1903: $checked = '';
1904: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1905: $checked = 'checked="checked" ';
1906: }
1.79 raeburn 1907: }
1.72 raeburn 1908: }
1.101 raeburn 1909: $datatable .= '<span class="LC_nobreak"><label>'.
1910: '<input type="checkbox" name="'.$context.'_'.$item.
1911: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1912: '</label></span> ';
1913: }
1914: }
1915: if ($context eq 'requestcourses') {
1916: $datatable .= '</tr><tr>';
1917: foreach my $item (@usertools) {
1.106 raeburn 1918: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1919: }
1.101 raeburn 1920: $datatable .= '</tr></table>';
1.72 raeburn 1921: }
1.98 raeburn 1922: $datatable .= '</td></tr>';
1.30 raeburn 1923: $$rowtotal += $typecount;
1.3 raeburn 1924: return $datatable;
1925: }
1926:
1.163 raeburn 1927: sub print_requestmail {
1928: my ($dom,$action,$settings,$rowtotal) = @_;
1.104 raeburn 1929: my ($now,$datatable,%dompersonnel,@domcoord,@currapproval,$rows);
1.102 raeburn 1930: $now = time;
1931: $rows = 0;
1932: %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1933: foreach my $server (keys(%dompersonnel)) {
1934: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
1935: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1936: if (!grep(/^$uname:$udom$/,@domcoord)) {
1937: push(@domcoord,$uname.':'.$udom);
1938: }
1939: }
1940: }
1941: if (ref($settings) eq 'HASH') {
1942: if (ref($settings->{'notify'}) eq 'HASH') {
1943: if ($settings->{'notify'}{'approval'} ne '') {
1.104 raeburn 1944: @currapproval = split(',',$settings->{'notify'}{'approval'});
1.102 raeburn 1945: }
1946: }
1947: }
1.104 raeburn 1948: if (@currapproval) {
1949: foreach my $dc (@currapproval) {
1.102 raeburn 1950: unless (grep(/^\Q$dc\E$/,@domcoord)) {
1951: push(@domcoord,$dc);
1952: }
1953: }
1954: }
1955: @domcoord = sort(@domcoord);
1956: my $numinrow = 4;
1957: my $numdc = @domcoord;
1958: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1959: my $text;
1960: if ($action eq 'requestcourses') {
1961: $text = &mt('Receive notification of course requests requiring approval');
1962: } else {
1963: $text = &mt('Receive notification of authoring space requests requiring approval')
1964: }
1965: $datatable = '<tr '.$css_class.'>'.
1966: ' <td>'.$text.'</td>'.
1.102 raeburn 1967: ' <td class="LC_left_item">';
1968: if (@domcoord > 0) {
1969: $datatable .= '<table>';
1970: for (my $i=0; $i<$numdc; $i++) {
1971: my $rem = $i%($numinrow);
1972: if ($rem == 0) {
1973: if ($i > 0) {
1974: $datatable .= '</tr>';
1975: }
1976: $datatable .= '<tr>';
1977: $rows ++;
1978: }
1979: my $check = ' ';
1.104 raeburn 1980: if (grep(/^\Q$domcoord[$i]\E$/,@currapproval)) {
1.102 raeburn 1981: $check = ' checked="checked" ';
1982: }
1983: my ($uname,$udom) = split(':',$domcoord[$i]);
1984: my $fullname = &Apache::loncommon::plainname($uname,$udom);
1985: if ($i == $numdc-1) {
1986: my $colsleft = $numinrow-$rem;
1987: if ($colsleft > 1) {
1988: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1989: } else {
1990: $datatable .= '<td class="LC_left_item">';
1991: }
1992: } else {
1993: $datatable .= '<td class="LC_left_item">';
1994: }
1995: $datatable .= '<span class="LC_nobreak"><label>'.
1996: '<input type="checkbox" name="reqapprovalnotify" '.
1997: 'value="'.$domcoord[$i].'"'.$check.'/>'.
1.175 bisitz 1998: $fullname.' ('.$uname.':'.$udom.')</label></span></td>';
1.102 raeburn 1999: }
2000: $datatable .= '</tr></table>';
2001: } else {
2002: $datatable .= &mt('There are no active Domain Coordinators');
2003: $rows ++;
2004: }
2005: $datatable .='</td></tr>';
2006: $$rowtotal += $rows;
2007: return $datatable;
2008: }
2009:
1.3 raeburn 2010: sub print_autoenroll {
1.30 raeburn 2011: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2012: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2013: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2014: if (ref($settings) eq 'HASH') {
2015: if (exists($settings->{'run'})) {
2016: if ($settings->{'run'} eq '0') {
2017: $runoff = ' checked="checked" ';
2018: $runon = ' ';
2019: } else {
2020: $runon = ' checked="checked" ';
2021: $runoff = ' ';
2022: }
2023: } else {
2024: if ($autorun) {
2025: $runon = ' checked="checked" ';
2026: $runoff = ' ';
2027: } else {
2028: $runoff = ' checked="checked" ';
2029: $runon = ' ';
2030: }
2031: }
1.129 raeburn 2032: if (exists($settings->{'co-owners'})) {
2033: if ($settings->{'co-owners'} eq '0') {
2034: $coownersoff = ' checked="checked" ';
2035: $coownerson = ' ';
2036: } else {
2037: $coownerson = ' checked="checked" ';
2038: $coownersoff = ' ';
2039: }
2040: } else {
2041: $coownersoff = ' checked="checked" ';
2042: $coownerson = ' ';
2043: }
1.3 raeburn 2044: if (exists($settings->{'sender_domain'})) {
2045: $defdom = $settings->{'sender_domain'};
2046: }
1.14 raeburn 2047: } else {
2048: if ($autorun) {
2049: $runon = ' checked="checked" ';
2050: $runoff = ' ';
2051: } else {
2052: $runoff = ' checked="checked" ';
2053: $runon = ' ';
2054: }
1.3 raeburn 2055: }
2056: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2057: my $notif_sender;
2058: if (ref($settings) eq 'HASH') {
2059: $notif_sender = $settings->{'sender_uname'};
2060: }
1.3 raeburn 2061: my $datatable='<tr class="LC_odd_row">'.
2062: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2063: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2064: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2065: $runon.' value="1" />'.&mt('Yes').'</label> '.
2066: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2067: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2068: '</tr><tr>'.
2069: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2070: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2071: &mt('username').': '.
2072: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2073: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2074: ': '.$domform.'</span></td></tr>'.
2075: '<tr class="LC_odd_row">'.
2076: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2077: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2078: '<input type="radio" name="autoassign_coowners"'.
2079: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2080: '<label><input type="radio" name="autoassign_coowners"'.
2081: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2082: '</tr>';
2083: $$rowtotal += 3;
1.3 raeburn 2084: return $datatable;
2085: }
2086:
2087: sub print_autoupdate {
1.30 raeburn 2088: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2089: my $datatable;
2090: if ($position eq 'top') {
2091: my $updateon = ' ';
2092: my $updateoff = ' checked="checked" ';
2093: my $classlistson = ' ';
2094: my $classlistsoff = ' checked="checked" ';
2095: if (ref($settings) eq 'HASH') {
2096: if ($settings->{'run'} eq '1') {
2097: $updateon = $updateoff;
2098: $updateoff = ' ';
2099: }
2100: if ($settings->{'classlists'} eq '1') {
2101: $classlistson = $classlistsoff;
2102: $classlistsoff = ' ';
2103: }
2104: }
2105: my %title = (
2106: run => 'Auto-update active?',
2107: classlists => 'Update information in classlists?',
2108: );
2109: $datatable = '<tr class="LC_odd_row">'.
2110: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2111: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2112: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2113: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2114: '<label><input type="radio" name="autoupdate_run"'.
2115: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2116: '</tr><tr>'.
2117: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2118: '<td class="LC_right_item"><span class="LC_nobreak">'.
2119: '<label><input type="radio" name="classlists"'.
2120: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2121: '<label><input type="radio" name="classlists"'.
2122: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2123: '</tr>';
1.30 raeburn 2124: $$rowtotal += 2;
1.131 raeburn 2125: } elsif ($position eq 'middle') {
2126: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2127: my $numinrow = 3;
2128: my $locknamesettings;
2129: $datatable .= &insttypes_row($settings,$types,$usertypes,
2130: $dom,$numinrow,$othertitle,
2131: 'lockablenames');
2132: $$rowtotal ++;
1.3 raeburn 2133: } else {
1.44 raeburn 2134: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2135: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2136: 'permanentemail','id');
1.33 raeburn 2137: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2138: my $numrows = 0;
1.26 raeburn 2139: if (ref($types) eq 'ARRAY') {
2140: if (@{$types} > 0) {
2141: $datatable =
2142: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2143: \@fields,$types,\$numrows);
1.30 raeburn 2144: $$rowtotal += @{$types};
1.26 raeburn 2145: }
1.3 raeburn 2146: }
2147: $datatable .=
2148: &usertype_update_row($settings,{'default' => $othertitle},
2149: \%fieldtitles,\@fields,['default'],
2150: \$numrows);
1.30 raeburn 2151: $$rowtotal ++;
1.3 raeburn 2152: }
2153: return $datatable;
2154: }
2155:
1.125 raeburn 2156: sub print_autocreate {
2157: my ($dom,$settings,$rowtotal) = @_;
2158: my (%createon,%createoff);
2159: my $curr_dc;
2160: my @types = ('xml','req');
2161: if (ref($settings) eq 'HASH') {
2162: foreach my $item (@types) {
2163: $createoff{$item} = ' checked="checked" ';
2164: $createon{$item} = ' ';
2165: if (exists($settings->{$item})) {
2166: if ($settings->{$item}) {
2167: $createon{$item} = ' checked="checked" ';
2168: $createoff{$item} = ' ';
2169: }
2170: }
2171: }
2172: $curr_dc = $settings->{'xmldc'};
2173: } else {
2174: foreach my $item (@types) {
2175: $createoff{$item} = ' checked="checked" ';
2176: $createon{$item} = ' ';
2177: }
2178: }
2179: $$rowtotal += 2;
2180: my $datatable='<tr class="LC_odd_row">'.
2181: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2182: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2183: '<input type="radio" name="autocreate_xml"'.
2184: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2185: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2186: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2187: '</td></tr><tr>'.
2188: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2189: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2190: '<input type="radio" name="autocreate_req"'.
2191: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2192: '<label><input type="radio" name="autocreate_req"'.
2193: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.125 raeburn 2194: my ($numdc,$dctable) = &active_dc_picker($dom,$curr_dc);
2195: if ($numdc > 1) {
1.143 raeburn 2196: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2197: &mt('Course creation processed as: (choose Dom. Coord.)').
2198: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2199: $$rowtotal ++ ;
2200: } else {
1.143 raeburn 2201: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2202: }
2203: return $datatable;
2204: }
2205:
1.23 raeburn 2206: sub print_directorysrch {
1.30 raeburn 2207: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2208: my $srchon = ' ';
2209: my $srchoff = ' checked="checked" ';
1.25 raeburn 2210: my ($exacton,$containson,$beginson);
1.24 raeburn 2211: my $localon = ' ';
2212: my $localoff = ' checked="checked" ';
1.23 raeburn 2213: if (ref($settings) eq 'HASH') {
2214: if ($settings->{'available'} eq '1') {
2215: $srchon = $srchoff;
2216: $srchoff = ' ';
2217: }
1.24 raeburn 2218: if ($settings->{'localonly'} eq '1') {
2219: $localon = $localoff;
2220: $localoff = ' ';
2221: }
1.25 raeburn 2222: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2223: foreach my $type (@{$settings->{'searchtypes'}}) {
2224: if ($type eq 'exact') {
2225: $exacton = ' checked="checked" ';
2226: } elsif ($type eq 'contains') {
2227: $containson = ' checked="checked" ';
2228: } elsif ($type eq 'begins') {
2229: $beginson = ' checked="checked" ';
2230: }
2231: }
2232: } else {
2233: if ($settings->{'searchtypes'} eq 'exact') {
2234: $exacton = ' checked="checked" ';
2235: } elsif ($settings->{'searchtypes'} eq 'contains') {
2236: $containson = ' checked="checked" ';
2237: } elsif ($settings->{'searchtypes'} eq 'specify') {
2238: $exacton = ' checked="checked" ';
2239: $containson = ' checked="checked" ';
2240: }
1.23 raeburn 2241: }
2242: }
2243: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2244: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2245:
2246: my $numinrow = 4;
1.26 raeburn 2247: my $cansrchrow = 0;
1.23 raeburn 2248: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2249: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2250: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2251: '<input type="radio" name="dirsrch_available"'.
2252: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2253: '<label><input type="radio" name="dirsrch_available"'.
2254: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2255: '</tr><tr>'.
1.30 raeburn 2256: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2257: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2258: '<input type="radio" name="dirsrch_localonly"'.
2259: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2260: '<label><input type="radio" name="dirsrch_localonly"'.
2261: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2262: '</tr>';
1.30 raeburn 2263: $$rowtotal += 2;
1.26 raeburn 2264: if (ref($usertypes) eq 'HASH') {
2265: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2266: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2267: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2268: $cansrchrow = 1;
2269: }
2270: }
2271: if ($cansrchrow) {
1.30 raeburn 2272: $$rowtotal ++;
1.26 raeburn 2273: $datatable .= '<tr>';
2274: } else {
2275: $datatable .= '<tr class="LC_odd_row">';
2276: }
1.30 raeburn 2277: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2278: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2279: foreach my $title (@{$titleorder}) {
2280: if (defined($searchtitles->{$title})) {
2281: my $check = ' ';
1.93 raeburn 2282: if (ref($settings) eq 'HASH') {
1.39 raeburn 2283: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2284: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2285: $check = ' checked="checked" ';
2286: }
1.25 raeburn 2287: }
2288: }
2289: $datatable .= '<td class="LC_left_item">'.
2290: '<span class="LC_nobreak"><label>'.
2291: '<input type="checkbox" name="searchby" '.
2292: 'value="'.$title.'"'.$check.'/>'.
2293: $searchtitles->{$title}.'</label></span></td>';
2294: }
2295: }
1.26 raeburn 2296: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2297: $$rowtotal ++;
1.26 raeburn 2298: if ($cansrchrow) {
2299: $datatable .= '<tr class="LC_odd_row">';
2300: } else {
2301: $datatable .= '<tr>';
2302: }
1.30 raeburn 2303: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2304: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2305: '<span class="LC_nobreak"><label>'.
2306: '<input type="checkbox" name="searchtypes" '.
2307: $exacton.' value="exact" />'.&mt('Exact match').
2308: '</label> '.
2309: '<label><input type="checkbox" name="searchtypes" '.
2310: $beginson.' value="begins" />'.&mt('Begins with').
2311: '</label> '.
2312: '<label><input type="checkbox" name="searchtypes" '.
2313: $containson.' value="contains" />'.&mt('Contains').
2314: '</label></span></td></tr>';
1.30 raeburn 2315: $$rowtotal ++;
1.25 raeburn 2316: return $datatable;
2317: }
2318:
1.28 raeburn 2319: sub print_contacts {
1.30 raeburn 2320: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2321: my $datatable;
2322: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2323: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2324: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
2325: 'requestsmail');
1.28 raeburn 2326: foreach my $type (@mailings) {
2327: $otheremails{$type} = '';
2328: }
1.134 raeburn 2329: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2330: if (ref($settings) eq 'HASH') {
2331: foreach my $item (@contacts) {
2332: if (exists($settings->{$item})) {
2333: $to{$item} = $settings->{$item};
2334: }
2335: }
2336: foreach my $type (@mailings) {
2337: if (exists($settings->{$type})) {
2338: if (ref($settings->{$type}) eq 'HASH') {
2339: foreach my $item (@contacts) {
2340: if ($settings->{$type}{$item}) {
2341: $checked{$type}{$item} = ' checked="checked" ';
2342: }
2343: }
2344: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2345: if ($type eq 'helpdeskmail') {
2346: $bccemails{$type} = $settings->{$type}{'bcc'};
2347: }
1.28 raeburn 2348: }
1.89 raeburn 2349: } elsif ($type eq 'lonstatusmail') {
2350: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2351: }
2352: }
2353: } else {
2354: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2355: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2356: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2357: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2358: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2359: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2360: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2361: }
2362: my ($titles,$short_titles) = &contact_titles();
2363: my $rownum = 0;
2364: my $css_class;
2365: foreach my $item (@contacts) {
1.69 raeburn 2366: $rownum ++;
2367: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2368: $datatable .= '<tr'.$css_class.'>'.
2369: '<td><span class="LC_nobreak">'.$titles->{$item}.
2370: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2371: '<input type="text" name="'.$item.'" value="'.
2372: $to{$item}.'" /></td></tr>';
2373: }
2374: foreach my $type (@mailings) {
1.69 raeburn 2375: $rownum ++;
2376: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2377: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2378: '<td><span class="LC_nobreak">'.
2379: $titles->{$type}.': </span></td>'.
1.28 raeburn 2380: '<td class="LC_left_item">'.
2381: '<span class="LC_nobreak">';
2382: foreach my $item (@contacts) {
2383: $datatable .= '<label>'.
2384: '<input type="checkbox" name="'.$type.'"'.
2385: $checked{$type}{$item}.
2386: ' value="'.$item.'" />'.$short_titles->{$item}.
2387: '</label> ';
2388: }
2389: $datatable .= '</span><br />'.&mt('Others').': '.
2390: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2391: 'value="'.$otheremails{$type}.'" />';
2392: if ($type eq 'helpdeskmail') {
1.136 raeburn 2393: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2394: '<input type="text" name="'.$type.'_bcc" '.
2395: 'value="'.$bccemails{$type}.'" />';
2396: }
2397: $datatable .= '</td></tr>'."\n";
1.28 raeburn 2398: }
1.30 raeburn 2399: $$rowtotal += $rownum;
1.28 raeburn 2400: return $datatable;
2401: }
2402:
1.118 jms 2403: sub print_helpsettings {
1.168 raeburn 2404: my ($dom,$confname,$settings,$rowtotal) = @_;
2405: my ($datatable,$itemcount);
1.166 raeburn 2406: $itemcount = 1;
1.168 raeburn 2407: my (%choices,%defaultchecked,@toggles);
2408: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2409: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2410: &mt('LON-CAPA bug tracker'),600,500));
2411: %defaultchecked = ('submitbugs' => 'on');
2412: @toggles = ('submitbugs',);
1.166 raeburn 2413:
1.168 raeburn 2414: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2415: \%choices,$itemcount);
1.166 raeburn 2416: return $datatable;
1.121 raeburn 2417: }
2418:
2419: sub radiobutton_prefs {
2420: my ($settings,$toggles,$defaultchecked,$choices,$itemcount) = @_;
2421: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2422: (ref($choices) eq 'HASH'));
2423:
1.170 raeburn 2424: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2425:
2426: foreach my $item (@{$toggles}) {
2427: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2428: $checkedon{$item} = ' checked="checked" ';
2429: $checkedoff{$item} = ' ';
1.121 raeburn 2430: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2431: $checkedoff{$item} = ' checked="checked" ';
2432: $checkedon{$item} = ' ';
2433: }
2434: }
2435: if (ref($settings) eq 'HASH') {
1.121 raeburn 2436: foreach my $item (@{$toggles}) {
1.118 jms 2437: if ($settings->{$item} eq '1') {
2438: $checkedon{$item} = ' checked="checked" ';
2439: $checkedoff{$item} = ' ';
2440: } elsif ($settings->{$item} eq '0') {
2441: $checkedoff{$item} = ' checked="checked" ';
2442: $checkedon{$item} = ' ';
2443: }
2444: }
1.121 raeburn 2445: }
2446: foreach my $item (@{$toggles}) {
1.118 jms 2447: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2448: $datatable .=
2449: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2450: '</span></td>'.
2451: '<td class="LC_right_item"><span class="LC_nobreak">'.
2452: '<label><input type="radio" name="'.
2453: $item.'" '.$checkedon{$item}.' value="1" />'.&mt('Yes').
2454: '</label> <label><input type="radio" name="'.$item.'" '.
2455: $checkedoff{$item}.' value="0" />'.&mt('No').'</label>'.
2456: '</span></td>'.
2457: '</tr>';
2458: $itemcount ++;
1.121 raeburn 2459: }
2460: return ($datatable,$itemcount);
2461: }
2462:
2463: sub print_coursedefaults {
1.139 raeburn 2464: my ($position,$dom,$settings,$rowtotal) = @_;
1.121 raeburn 2465: my ($css_class,$datatable);
2466: my $itemcount = 1;
1.139 raeburn 2467: if ($position eq 'top') {
2468: my (%checkedon,%checkedoff,%choices,%defaultchecked,@toggles);
2469: %choices =
2470: &Apache::lonlocal::texthash (
2471: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
2472: );
2473: %defaultchecked = ('canuse_pdfforms' => 'off');
2474: @toggles = ('canuse_pdfforms',);
2475: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2476: \%choices,$itemcount);
1.139 raeburn 2477: $$rowtotal += $itemcount;
2478: } else {
2479: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2480: my %choices =
2481: &Apache::lonlocal::texthash (
2482: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2483: );
2484: my $currdefresponder;
2485: if (ref($settings) eq 'HASH') {
2486: $currdefresponder = $settings->{'anonsurvey_threshold'};
2487: }
2488: if (!$currdefresponder) {
2489: $currdefresponder = 10;
2490: } elsif ($currdefresponder < 1) {
2491: $currdefresponder = 1;
2492: }
2493: $datatable .=
2494: '<tr'.$css_class.'><td><span class="LC_nobreak">'.$choices{'anonsurvey_threshold'}.
2495: '</span></td>'.
2496: '<td class="LC_right_item"><span class="LC_nobreak">'.
2497: '<input type="text" name="anonsurvey_threshold"'.
2498: ' value="'.$currdefresponder.'" size="5" /></span>'.
2499: '</td></tr>';
2500: }
1.121 raeburn 2501: return $datatable;
1.118 jms 2502: }
2503:
1.137 raeburn 2504: sub print_usersessions {
2505: my ($position,$dom,$settings,$rowtotal) = @_;
2506: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2507: my (%by_ip,%by_location,@intdoms);
2508: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2509:
2510: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2511: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2512: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2513: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2514: my $itemcount = 1;
2515: if ($position eq 'top') {
1.152 raeburn 2516: if (keys(%serverhomes) > 1) {
1.145 raeburn 2517: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2518: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2519: } else {
1.140 raeburn 2520: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2521: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2522: }
1.137 raeburn 2523: } else {
1.145 raeburn 2524: if (keys(%by_location) == 0) {
2525: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2526: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2527: } else {
2528: my %lt = &usersession_titles();
2529: my $numinrow = 5;
2530: my $prefix;
2531: my @types;
2532: if ($position eq 'bottom') {
2533: $prefix = 'remote';
2534: @types = ('version','excludedomain','includedomain');
2535: } else {
2536: $prefix = 'hosted';
2537: @types = ('excludedomain','includedomain');
2538: }
2539: my (%current,%checkedon,%checkedoff);
2540: my @lcversions = &Apache::lonnet::all_loncaparevs();
2541: my @locations = sort(keys(%by_location));
2542: foreach my $type (@types) {
2543: $checkedon{$type} = '';
2544: $checkedoff{$type} = ' checked="checked"';
2545: }
2546: if (ref($settings) eq 'HASH') {
2547: if (ref($settings->{$prefix}) eq 'HASH') {
2548: foreach my $key (keys(%{$settings->{$prefix}})) {
2549: $current{$key} = $settings->{$prefix}{$key};
2550: if ($key eq 'version') {
2551: if ($current{$key} ne '') {
2552: $checkedon{$key} = ' checked="checked"';
2553: $checkedoff{$key} = '';
2554: }
2555: } elsif (ref($current{$key}) eq 'ARRAY') {
2556: $checkedon{$key} = ' checked="checked"';
2557: $checkedoff{$key} = '';
2558: }
1.137 raeburn 2559: }
2560: }
2561: }
1.145 raeburn 2562: foreach my $type (@types) {
2563: next if ($type ne 'version' && !@locations);
2564: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2565: $datatable .= '<tr'.$css_class.'>
2566: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2567: <span class="LC_nobreak">
2568: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2569: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2570: if ($type eq 'version') {
2571: my $selector = '<select name="'.$prefix.'_version">';
2572: foreach my $version (@lcversions) {
2573: my $selected = '';
2574: if ($current{'version'} eq $version) {
2575: $selected = ' selected="selected"';
2576: }
2577: $selector .= ' <option value="'.$version.'"'.
2578: $selected.'>'.$version.'</option>';
2579: }
2580: $selector .= '</select> ';
2581: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2582: } else {
2583: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2584: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2585: ' />'.(' 'x2).
2586: '<input type="button" value="'.&mt('uncheck all').'" '.
2587: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2588: "\n".
2589: '</div><div><table>';
2590: my $rem;
2591: for (my $i=0; $i<@locations; $i++) {
2592: my ($showloc,$value,$checkedtype);
2593: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2594: my $ip = $by_location{$locations[$i]}->[0];
2595: if (ref($by_ip{$ip}) eq 'ARRAY') {
2596: $value = join(':',@{$by_ip{$ip}});
2597: $showloc = join(', ',@{$by_ip{$ip}});
2598: if (ref($current{$type}) eq 'ARRAY') {
2599: foreach my $loc (@{$by_ip{$ip}}) {
2600: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2601: $checkedtype = ' checked="checked"';
2602: last;
2603: }
2604: }
1.138 raeburn 2605: }
2606: }
2607: }
1.145 raeburn 2608: $rem = $i%($numinrow);
2609: if ($rem == 0) {
2610: if ($i > 0) {
2611: $datatable .= '</tr>';
2612: }
2613: $datatable .= '<tr>';
2614: }
2615: $datatable .= '<td class="LC_left_item">'.
2616: '<span class="LC_nobreak"><label>'.
2617: '<input type="checkbox" name="'.$prefix.'_'.$type.
2618: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2619: '</label></span></td>';
1.137 raeburn 2620: }
1.145 raeburn 2621: $rem = @locations%($numinrow);
2622: my $colsleft = $numinrow - $rem;
2623: if ($colsleft > 1 ) {
2624: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2625: ' </td>';
2626: } elsif ($colsleft == 1) {
2627: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2628: }
1.145 raeburn 2629: $datatable .= '</tr></table>';
1.137 raeburn 2630: }
1.145 raeburn 2631: $datatable .= '</td></tr>';
2632: $itemcount ++;
1.137 raeburn 2633: }
2634: }
2635: }
2636: $$rowtotal += $itemcount;
2637: return $datatable;
2638: }
2639:
1.138 raeburn 2640: sub build_location_hashes {
2641: my ($intdoms,$by_ip,$by_location) = @_;
2642: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2643: (ref($by_location) eq 'HASH'));
2644: my %iphost = &Apache::lonnet::get_iphost();
2645: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2646: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2647: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2648: foreach my $id (@{$iphost{$primary_ip}}) {
2649: my $intdom = &Apache::lonnet::internet_dom($id);
2650: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2651: push(@{$intdoms},$intdom);
2652: }
2653: }
2654: }
2655: foreach my $ip (keys(%iphost)) {
2656: if (ref($iphost{$ip}) eq 'ARRAY') {
2657: foreach my $id (@{$iphost{$ip}}) {
2658: my $location = &Apache::lonnet::internet_dom($id);
2659: if ($location) {
2660: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2661: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2662: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2663: push(@{$by_ip->{$ip}},$location);
2664: }
2665: } else {
2666: $by_ip->{$ip} = [$location];
2667: }
2668: }
2669: }
2670: }
2671: }
2672: foreach my $ip (sort(keys(%{$by_ip}))) {
2673: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2674: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2675: my $first = $by_ip->{$ip}->[0];
2676: if (ref($by_location->{$first}) eq 'ARRAY') {
2677: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2678: push(@{$by_location->{$first}},$ip);
2679: }
2680: } else {
2681: $by_location->{$first} = [$ip];
2682: }
2683: }
2684: }
2685: return;
2686: }
2687:
1.145 raeburn 2688: sub current_offloads_to {
2689: my ($dom,$settings,$servers) = @_;
2690: my (%spareid,%otherdomconfigs);
1.152 raeburn 2691: if (ref($servers) eq 'HASH') {
1.145 raeburn 2692: foreach my $lonhost (sort(keys(%{$servers}))) {
2693: my $gotspares;
1.152 raeburn 2694: if (ref($settings) eq 'HASH') {
2695: if (ref($settings->{'spares'}) eq 'HASH') {
2696: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2697: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2698: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2699: $gotspares = 1;
2700: }
1.145 raeburn 2701: }
2702: }
2703: unless ($gotspares) {
2704: my $gotspares;
2705: my $serverhomeID =
2706: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2707: my $serverhomedom =
2708: &Apache::lonnet::host_domain($serverhomeID);
2709: if ($serverhomedom ne $dom) {
2710: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2711: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2712: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2713: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2714: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2715: $gotspares = 1;
2716: }
2717: }
2718: } else {
2719: $otherdomconfigs{$serverhomedom} =
2720: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2721: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2722: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2723: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2724: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2725: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2726: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2727: $gotspares = 1;
2728: }
2729: }
2730: }
2731: }
2732: }
2733: }
2734: }
2735: unless ($gotspares) {
2736: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2737: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2738: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2739: } else {
2740: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2741: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2742: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2743: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2744: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2745: } else {
1.150 raeburn 2746: my %what = (
2747: spareid => 1,
2748: );
2749: my ($result,$returnhash) =
2750: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2751: if ($result eq 'ok') {
2752: if (ref($returnhash) eq 'HASH') {
2753: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2754: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2755: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2756: }
2757: }
1.145 raeburn 2758: }
2759: }
2760: }
2761: }
2762: }
2763: }
2764: return %spareid;
2765: }
2766:
2767: sub spares_row {
1.152 raeburn 2768: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2769: my $css_class;
2770: my $numinrow = 4;
2771: my $itemcount = 1;
2772: my $datatable;
1.152 raeburn 2773: my %typetitles = &sparestype_titles();
2774: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2775: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2776: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2777: my ($othercontrol,$serverdom);
2778: if ($serverhome ne $server) {
2779: $serverdom = &Apache::lonnet::host_domain($serverhome);
2780: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2781: } else {
2782: $serverdom = &Apache::lonnet::host_domain($server);
2783: if ($serverdom ne $dom) {
2784: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2785: }
2786: }
2787: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2788: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2789: $datatable .= '<tr'.$css_class.'>
2790: <td rowspan="2">
1.183 bisitz 2791: <span class="LC_nobreak">'.
2792: &mt('[_1] when busy, offloads to:'
2793: ,'<b>'.$server.'</b>').
2794: "\n";
1.145 raeburn 2795: my (%current,%canselect);
1.152 raeburn 2796: my @choices =
2797: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2798: foreach my $type ('primary','default') {
2799: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2800: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2801: my @spares = @{$spareid->{$server}{$type}};
2802: if (@spares > 0) {
1.152 raeburn 2803: if ($othercontrol) {
2804: $current{$type} = join(', ',@spares);
2805: } else {
2806: $current{$type} .= '<table>';
2807: my $numspares = scalar(@spares);
2808: for (my $i=0; $i<@spares; $i++) {
2809: my $rem = $i%($numinrow);
2810: if ($rem == 0) {
2811: if ($i > 0) {
2812: $current{$type} .= '</tr>';
2813: }
2814: $current{$type} .= '<tr>';
1.145 raeburn 2815: }
1.152 raeburn 2816: $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'".');" /> '.
2817: $spareid->{$server}{$type}[$i].
2818: '</label></td>'."\n";
2819: }
2820: my $rem = @spares%($numinrow);
2821: my $colsleft = $numinrow - $rem;
2822: if ($colsleft > 1 ) {
2823: $current{$type} .= '<td colspan="'.$colsleft.
2824: '" class="LC_left_item">'.
2825: ' </td>';
2826: } elsif ($colsleft == 1) {
2827: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2828: }
1.152 raeburn 2829: $current{$type} .= '</tr></table>';
1.150 raeburn 2830: }
1.145 raeburn 2831: }
2832: }
2833: if ($current{$type} eq '') {
2834: $current{$type} = &mt('None specified');
2835: }
1.152 raeburn 2836: if ($othercontrol) {
2837: if ($type eq 'primary') {
2838: $canselect{$type} = $othercontrol;
2839: }
2840: } else {
2841: $canselect{$type} =
2842: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2843: '<select name="newspare_'.$type.'_'.$server.'" '.
2844: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2845: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2846: if (@choices > 0) {
2847: foreach my $lonhost (@choices) {
2848: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2849: }
2850: }
2851: $canselect{$type} .= '</select>'."\n";
2852: }
2853: } else {
2854: $current{$type} = &mt('Could not be determined');
2855: if ($type eq 'primary') {
2856: $canselect{$type} = $othercontrol;
2857: }
1.145 raeburn 2858: }
1.152 raeburn 2859: if ($type eq 'default') {
2860: $datatable .= '<tr'.$css_class.'>';
2861: }
2862: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2863: '<td>'.$current{$type}.'</td>'."\n".
2864: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2865: }
2866: $itemcount ++;
2867: }
2868: }
2869: $$rowtotal += $itemcount;
2870: return $datatable;
2871: }
2872:
1.152 raeburn 2873: sub possible_newspares {
2874: my ($server,$currspares,$serverhomes,$altids) = @_;
2875: my $serverhostname = &Apache::lonnet::hostname($server);
2876: my %excluded;
2877: if ($serverhostname ne '') {
2878: %excluded = (
2879: $serverhostname => 1,
2880: );
2881: }
2882: if (ref($currspares) eq 'HASH') {
2883: foreach my $type (keys(%{$currspares})) {
2884: if (ref($currspares->{$type}) eq 'ARRAY') {
2885: if (@{$currspares->{$type}} > 0) {
2886: foreach my $curr (@{$currspares->{$type}}) {
2887: my $hostname = &Apache::lonnet::hostname($curr);
2888: $excluded{$hostname} = 1;
2889: }
2890: }
2891: }
2892: }
2893: }
2894: my @choices;
2895: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2896: if (keys(%{$serverhomes}) > 1) {
2897: foreach my $name (sort(keys(%{$serverhomes}))) {
2898: unless ($excluded{$name}) {
2899: if (exists($altids->{$serverhomes->{$name}})) {
2900: push(@choices,$altids->{$serverhomes->{$name}});
2901: } else {
2902: push(@choices,$serverhomes->{$name});
1.145 raeburn 2903: }
2904: }
2905: }
2906: }
2907: }
1.152 raeburn 2908: return sort(@choices);
1.145 raeburn 2909: }
2910:
1.150 raeburn 2911: sub print_loadbalancing {
2912: my ($dom,$settings,$rowtotal) = @_;
2913: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2914: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2915: my $numinrow = 1;
2916: my $datatable;
2917: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2918: my (%currbalancer,%currtargets,%currrules,%existing);
2919: if (ref($settings) eq 'HASH') {
2920: %existing = %{$settings};
2921: }
2922: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2923: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2924: \%currtargets,\%currrules);
1.150 raeburn 2925: } else {
2926: return;
2927: }
2928: my ($othertitle,$usertypes,$types) =
2929: &Apache::loncommon::sorted_inst_types($dom);
2930: my $rownum = 6;
2931: if (ref($types) eq 'ARRAY') {
2932: $rownum += scalar(@{$types});
2933: }
1.171 raeburn 2934: my @css_class = ('LC_odd_row','LC_even_row');
2935: my $balnum = 0;
2936: my $islast;
2937: my (@toshow,$disabledtext);
2938: if (keys(%currbalancer) > 0) {
2939: @toshow = sort(keys(%currbalancer));
2940: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
2941: push(@toshow,'');
2942: }
2943: } else {
2944: @toshow = ('');
2945: $disabledtext = &mt('No existing load balancer');
2946: }
2947: foreach my $lonhost (@toshow) {
2948: if ($balnum == scalar(@toshow)-1) {
2949: $islast = 1;
2950: } else {
2951: $islast = 0;
2952: }
2953: my $cssidx = $balnum%2;
2954: my $targets_div_style = 'display: none';
2955: my $disabled_div_style = 'display: block';
2956: my $homedom_div_style = 'display: none';
2957: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
2958: '<td rowspan="'.$rownum.'" valign="top">'.
2959: '<p>';
2960: if ($lonhost eq '') {
2961: $datatable .= '<span class="LC_nobreak">';
2962: if (keys(%currbalancer) > 0) {
2963: $datatable .= &mt('Add balancer:');
2964: } else {
2965: $datatable .= &mt('Enable balancer:');
2966: }
2967: $datatable .= ' '.
2968: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
2969: ' id="loadbalancing_lonhost_'.$balnum.'"'.
2970: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
2971: '<option value="" selected="selected">'.&mt('None').
2972: '</option>'."\n";
2973: foreach my $server (sort(keys(%servers))) {
2974: next if ($currbalancer{$server});
2975: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
2976: }
2977: $datatable .=
2978: '</select>'."\n".
2979: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
2980: } else {
2981: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
2982: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
2983: &mt('Stop balancing').'</label>'.
2984: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
2985: $targets_div_style = 'display: block';
2986: $disabled_div_style = 'display: none';
2987: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
2988: $homedom_div_style = 'display: block';
2989: }
2990: }
2991: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
2992: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
2993: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
2994: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
2995: my ($numspares,@spares) = &count_servers($lonhost,%servers);
2996: my @sparestypes = ('primary','default');
2997: my %typetitles = &sparestype_titles();
2998: foreach my $sparetype (@sparestypes) {
2999: my $targettable;
3000: for (my $i=0; $i<$numspares; $i++) {
3001: my $checked;
3002: if (ref($currtargets{$lonhost}) eq 'HASH') {
3003: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3004: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3005: $checked = ' checked="checked"';
3006: }
3007: }
3008: }
3009: my ($chkboxval,$disabled);
3010: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3011: $chkboxval = $spares[$i];
3012: }
3013: if (exists($currbalancer{$spares[$i]})) {
3014: $disabled = ' disabled="disabled"';
3015: }
3016: $targettable .=
3017: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3018: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3019: '</span></label></td>';
3020: my $rem = $i%($numinrow);
3021: if ($rem == 0) {
3022: if (($i > 0) && ($i < $numspares-1)) {
3023: $targettable .= '</tr>';
3024: }
3025: if ($i < $numspares-1) {
3026: $targettable .= '<tr>';
1.150 raeburn 3027: }
3028: }
3029: }
1.171 raeburn 3030: if ($targettable ne '') {
3031: my $rem = $numspares%($numinrow);
3032: my $colsleft = $numinrow - $rem;
3033: if ($colsleft > 1 ) {
3034: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3035: ' </td>';
3036: } elsif ($colsleft == 1) {
3037: $targettable .= '<td class="LC_left_item"> </td>';
3038: }
3039: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3040: '<table><tr>'.$targettable.'</tr></table><br />';
3041: }
3042: }
3043: $datatable .= '</div></td></tr>'.
3044: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3045: $othertitle,$usertypes,$types,\%servers,
3046: \%currbalancer,$lonhost,
3047: $targets_div_style,$homedom_div_style,
3048: $css_class[$cssidx],$balnum,$islast);
3049: $$rowtotal += $rownum;
3050: $balnum ++;
3051: }
3052: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3053: return $datatable;
3054: }
3055:
3056: sub get_loadbalancers_config {
3057: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3058: return unless ((ref($servers) eq 'HASH') &&
3059: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3060: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3061: if (keys(%{$existing}) > 0) {
3062: my $oldlonhost;
3063: foreach my $key (sort(keys(%{$existing}))) {
3064: if ($key eq 'lonhost') {
3065: $oldlonhost = $existing->{'lonhost'};
3066: $currbalancer->{$oldlonhost} = 1;
3067: } elsif ($key eq 'targets') {
3068: if ($oldlonhost) {
3069: $currtargets->{$oldlonhost} = $existing->{'targets'};
3070: }
3071: } elsif ($key eq 'rules') {
3072: if ($oldlonhost) {
3073: $currrules->{$oldlonhost} = $existing->{'rules'};
3074: }
3075: } elsif (ref($existing->{$key}) eq 'HASH') {
3076: $currbalancer->{$key} = 1;
3077: $currtargets->{$key} = $existing->{$key}{'targets'};
3078: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3079: }
3080: }
1.171 raeburn 3081: } else {
3082: my ($balancerref,$targetsref) =
3083: &Apache::lonnet::get_lonbalancer_config($servers);
3084: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3085: foreach my $server (sort(keys(%{$balancerref}))) {
3086: $currbalancer->{$server} = 1;
3087: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3088: }
3089: }
3090: }
1.171 raeburn 3091: return;
1.150 raeburn 3092: }
3093:
3094: sub loadbalancing_rules {
3095: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3096: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3097: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3098: my $output;
1.171 raeburn 3099: my $num = 0;
1.150 raeburn 3100: my ($alltypes,$othertypes,$titles) =
3101: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3102: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3103: foreach my $type (@{$alltypes}) {
1.171 raeburn 3104: $num ++;
1.150 raeburn 3105: my $current;
3106: if (ref($currrules) eq 'HASH') {
3107: $current = $currrules->{$type};
3108: }
3109: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.171 raeburn 3110: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3111: $current = '';
3112: }
3113: }
3114: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3115: $servers,$currbalancer,$lonhost,$dom,
3116: $targets_div_style,$homedom_div_style,
3117: $css_class,$balnum,$num,$islast);
1.150 raeburn 3118: }
3119: }
3120: return $output;
3121: }
3122:
3123: sub loadbalancing_titles {
3124: my ($dom,$intdom,$usertypes,$types) = @_;
3125: my %othertypes = (
3126: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3127: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3128: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3129: '_LC_external' => &mt('Users not from [_1]',$intdom),
3130: );
3131: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external');
3132: if (ref($types) eq 'ARRAY') {
3133: unshift(@alltypes,@{$types},'default');
3134: }
3135: my %titles;
3136: foreach my $type (@alltypes) {
3137: if ($type =~ /^_LC_/) {
3138: $titles{$type} = $othertypes{$type};
3139: } elsif ($type eq 'default') {
3140: $titles{$type} = &mt('All users from [_1]',$dom);
3141: if (ref($types) eq 'ARRAY') {
3142: if (@{$types} > 0) {
3143: $titles{$type} = &mt('Other users from [_1]',$dom);
3144: }
3145: }
3146: } elsif (ref($usertypes) eq 'HASH') {
3147: $titles{$type} = $usertypes->{$type};
3148: }
3149: }
3150: return (\@alltypes,\%othertypes,\%titles);
3151: }
3152:
3153: sub loadbalance_rule_row {
1.171 raeburn 3154: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3155: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.150 raeburn 3156: my @rulenames = ('default','homeserver');
3157: my %ruletitles = &offloadtype_text();
3158: if ($type eq '_LC_external') {
3159: push(@rulenames,'externalbalancer');
3160: } else {
3161: push(@rulenames,'specific');
3162: }
1.161 raeburn 3163: push(@rulenames,'none');
1.150 raeburn 3164: my $style = $targets_div_style;
3165: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
3166: $style = $homedom_div_style;
3167: }
1.171 raeburn 3168: my $space;
3169: if ($islast && $num == 1) {
3170: $space = '<div display="inline-block"> </div>';
3171: }
1.150 raeburn 3172: my $output =
1.171 raeburn 3173: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3174: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3175: '<td valaign="top">'.$space.
3176: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3177: for (my $i=0; $i<@rulenames; $i++) {
3178: my $rule = $rulenames[$i];
3179: my ($checked,$extra);
3180: if ($rulenames[$i] eq 'default') {
3181: $rule = '';
3182: }
3183: if ($rulenames[$i] eq 'specific') {
3184: if (ref($servers) eq 'HASH') {
3185: my $default;
3186: if (($current ne '') && (exists($servers->{$current}))) {
3187: $checked = ' checked="checked"';
3188: }
3189: unless ($checked) {
3190: $default = ' selected="selected"';
3191: }
1.171 raeburn 3192: $extra =
3193: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3194: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3195: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3196: '<option value=""'.$default.'></option>'."\n";
3197: foreach my $server (sort(keys(%{$servers}))) {
3198: if (ref($currbalancer) eq 'HASH') {
3199: next if (exists($currbalancer->{$server}));
3200: }
1.150 raeburn 3201: my $selected;
1.171 raeburn 3202: if ($server eq $current) {
1.150 raeburn 3203: $selected = ' selected="selected"';
3204: }
1.171 raeburn 3205: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3206: }
3207: $extra .= '</select>';
3208: }
3209: } elsif ($rule eq $current) {
3210: $checked = ' checked="checked"';
3211: }
3212: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3213: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3214: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3215: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3216: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3217: '</label>'.$extra.'</span><br />'."\n";
3218: }
3219: $output .= '</div></td></tr>'."\n";
3220: return $output;
3221: }
3222:
3223: sub offloadtype_text {
3224: my %ruletitles = &Apache::lonlocal::texthash (
3225: 'default' => 'Offloads to default destinations',
3226: 'homeserver' => "Offloads to user's home server",
3227: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3228: 'specific' => 'Offloads to specific server',
1.161 raeburn 3229: 'none' => 'No offload',
1.150 raeburn 3230: );
3231: return %ruletitles;
3232: }
3233:
3234: sub sparestype_titles {
3235: my %typestitles = &Apache::lonlocal::texthash (
3236: 'primary' => 'primary',
3237: 'default' => 'default',
3238: );
3239: return %typestitles;
3240: }
3241:
1.28 raeburn 3242: sub contact_titles {
3243: my %titles = &Apache::lonlocal::texthash (
3244: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3245: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3246: 'errormail' => 'Error reports to be e-mailed to',
3247: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3248: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3249: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3250: 'requestsmail' => 'E-mail from course requests requiring approval',
1.28 raeburn 3251: );
3252: my %short_titles = &Apache::lonlocal::texthash (
3253: adminemail => 'Admin E-mail address',
3254: supportemail => 'Support E-mail',
3255: );
3256: return (\%titles,\%short_titles);
3257: }
3258:
1.72 raeburn 3259: sub tool_titles {
3260: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3261: aboutme => 'Personal web page',
1.86 raeburn 3262: blog => 'Blog',
1.162 raeburn 3263: webdav => 'WebDAV',
1.86 raeburn 3264: portfolio => 'Portfolio',
1.88 bisitz 3265: official => 'Official courses (with institutional codes)',
3266: unofficial => 'Unofficial courses',
1.98 raeburn 3267: community => 'Communities',
1.86 raeburn 3268: );
1.72 raeburn 3269: return %titles;
3270: }
3271:
1.101 raeburn 3272: sub courserequest_titles {
3273: my %titles = &Apache::lonlocal::texthash (
3274: official => 'Official',
3275: unofficial => 'Unofficial',
3276: community => 'Communities',
3277: norequest => 'Not allowed',
1.104 raeburn 3278: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3279: validate => 'With validation',
3280: autolimit => 'Numerical limit',
1.103 raeburn 3281: unlimited => '(blank for unlimited)',
1.101 raeburn 3282: );
3283: return %titles;
3284: }
3285:
1.163 raeburn 3286: sub authorrequest_titles {
3287: my %titles = &Apache::lonlocal::texthash (
3288: norequest => 'Not allowed',
3289: approval => 'Approval by Dom. Coord.',
3290: automatic => 'Automatic approval',
3291: );
3292: return %titles;
3293: }
3294:
1.101 raeburn 3295: sub courserequest_conditions {
3296: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3297: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.101 raeburn 3298: validate => '(Processing of request subject to instittutional validation).',
3299: );
3300: return %conditions;
3301: }
3302:
3303:
1.27 raeburn 3304: sub print_usercreation {
1.30 raeburn 3305: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3306: my $numinrow = 4;
1.28 raeburn 3307: my $datatable;
3308: if ($position eq 'top') {
1.30 raeburn 3309: $$rowtotal ++;
1.34 raeburn 3310: my $rowcount = 0;
1.32 raeburn 3311: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3312: if (ref($rules) eq 'HASH') {
3313: if (keys(%{$rules}) > 0) {
1.32 raeburn 3314: $datatable .= &user_formats_row('username',$settings,$rules,
3315: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3316: $$rowtotal ++;
1.32 raeburn 3317: $rowcount ++;
3318: }
3319: }
3320: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3321: if (ref($idrules) eq 'HASH') {
3322: if (keys(%{$idrules}) > 0) {
3323: $datatable .= &user_formats_row('id',$settings,$idrules,
3324: $idruleorder,$numinrow,$rowcount);
3325: $$rowtotal ++;
3326: $rowcount ++;
1.28 raeburn 3327: }
3328: }
1.43 raeburn 3329: my ($emailrules,$emailruleorder) =
3330: &Apache::lonnet::inst_userrules($dom,'email');
3331: if (ref($emailrules) eq 'HASH') {
3332: if (keys(%{$emailrules}) > 0) {
3333: $datatable .= &user_formats_row('email',$settings,$emailrules,
3334: $emailruleorder,$numinrow,$rowcount);
3335: $$rowtotal ++;
3336: $rowcount ++;
3337: }
3338: }
1.39 raeburn 3339: if ($rowcount == 0) {
3340: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3341: $$rowtotal ++;
3342: $rowcount ++;
3343: }
1.34 raeburn 3344: } elsif ($position eq 'middle') {
1.100 raeburn 3345: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3346: my ($rules,$ruleorder) =
3347: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3348: my %lt = &usercreation_types();
3349: my %checked;
1.50 raeburn 3350: my @selfcreate;
1.34 raeburn 3351: if (ref($settings) eq 'HASH') {
3352: if (ref($settings->{'cancreate'}) eq 'HASH') {
3353: foreach my $item (@creators) {
3354: $checked{$item} = $settings->{'cancreate'}{$item};
3355: }
1.50 raeburn 3356: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3357: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3358: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3359: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3360: @selfcreate = ('email','login','sso');
3361: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3362: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3363: }
3364: }
1.34 raeburn 3365: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3366: foreach my $item (@creators) {
3367: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3368: $checked{$item} = 'none';
3369: }
3370: }
3371: }
3372: }
3373: my $rownum = 0;
3374: foreach my $item (@creators) {
3375: $rownum ++;
1.50 raeburn 3376: if ($item ne 'selfcreate') {
3377: if ($checked{$item} eq '') {
1.43 raeburn 3378: $checked{$item} = 'any';
3379: }
1.34 raeburn 3380: }
3381: my $css_class;
3382: if ($rownum%2) {
3383: $css_class = '';
3384: } else {
3385: $css_class = ' class="LC_odd_row" ';
3386: }
3387: $datatable .= '<tr'.$css_class.'>'.
3388: '<td><span class="LC_nobreak">'.$lt{$item}.
3389: '</span></td><td align="right">';
1.50 raeburn 3390: my @options;
1.45 raeburn 3391: if ($item eq 'selfcreate') {
1.43 raeburn 3392: push(@options,('email','login','sso'));
3393: } else {
1.50 raeburn 3394: @options = ('any');
1.43 raeburn 3395: if (ref($rules) eq 'HASH') {
3396: if (keys(%{$rules}) > 0) {
3397: push(@options,('official','unofficial'));
3398: }
1.37 raeburn 3399: }
1.50 raeburn 3400: push(@options,'none');
1.37 raeburn 3401: }
3402: foreach my $option (@options) {
1.50 raeburn 3403: my $type = 'radio';
1.34 raeburn 3404: my $check = ' ';
1.50 raeburn 3405: if ($item eq 'selfcreate') {
3406: $type = 'checkbox';
3407: if (grep(/^\Q$option\E$/,@selfcreate)) {
3408: $check = ' checked="checked" ';
3409: }
3410: } else {
3411: if ($checked{$item} eq $option) {
3412: $check = ' checked="checked" ';
3413: }
1.34 raeburn 3414: }
3415: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3416: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3417: $item.'" value="'.$option.'"'.$check.'/> '.
3418: $lt{$option}.'</label> </span>';
3419: }
3420: $datatable .= '</td></tr>';
3421: }
1.93 raeburn 3422: my ($othertitle,$usertypes,$types) =
3423: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3424: my $createsettings;
3425: if (ref($settings) eq 'HASH') {
3426: $createsettings = $settings->{cancreate};
3427: }
1.93 raeburn 3428: if (ref($usertypes) eq 'HASH') {
3429: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3430: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3431: $dom,$numinrow,$othertitle,
3432: 'statustocreate');
3433: $$rowtotal ++;
1.169 raeburn 3434: $rownum ++;
1.93 raeburn 3435: }
3436: }
1.169 raeburn 3437: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3438: } else {
3439: my @contexts = ('author','course','domain');
3440: my @authtypes = ('int','krb4','krb5','loc');
3441: my %checked;
3442: if (ref($settings) eq 'HASH') {
3443: if (ref($settings->{'authtypes'}) eq 'HASH') {
3444: foreach my $item (@contexts) {
3445: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3446: foreach my $auth (@authtypes) {
3447: if ($settings->{'authtypes'}{$item}{$auth}) {
3448: $checked{$item}{$auth} = ' checked="checked" ';
3449: }
3450: }
3451: }
3452: }
1.27 raeburn 3453: }
1.35 raeburn 3454: } else {
3455: foreach my $item (@contexts) {
1.36 raeburn 3456: foreach my $auth (@authtypes) {
1.35 raeburn 3457: $checked{$item}{$auth} = ' checked="checked" ';
3458: }
3459: }
1.27 raeburn 3460: }
1.28 raeburn 3461: my %title = &context_names();
3462: my %authname = &authtype_names();
3463: my $rownum = 0;
3464: my $css_class;
3465: foreach my $item (@contexts) {
3466: if ($rownum%2) {
3467: $css_class = '';
3468: } else {
3469: $css_class = ' class="LC_odd_row" ';
3470: }
1.30 raeburn 3471: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3472: '<td>'.$title{$item}.
3473: '</td><td class="LC_left_item">'.
3474: '<span class="LC_nobreak">';
3475: foreach my $auth (@authtypes) {
3476: $datatable .= '<label>'.
3477: '<input type="checkbox" name="'.$item.'_auth" '.
3478: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3479: $authname{$auth}.'</label> ';
3480: }
3481: $datatable .= '</span></td></tr>';
3482: $rownum ++;
1.27 raeburn 3483: }
1.30 raeburn 3484: $$rowtotal += $rownum;
1.27 raeburn 3485: }
3486: return $datatable;
3487: }
3488:
1.165 raeburn 3489: sub captcha_choice {
1.169 raeburn 3490: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3491: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3492: my %lt = &captcha_phrases();
3493: $keyentry = 'hidden';
3494: if ($context eq 'cancreate') {
3495: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3496: } elsif ($context eq 'login') {
3497: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3498: }
3499: if (ref($settings) eq 'HASH') {
3500: if ($settings->{'captcha'}) {
3501: $checked{$settings->{'captcha'}} = ' checked="checked"';
3502: } else {
3503: $checked{'original'} = ' checked="checked"';
3504: }
3505: if ($settings->{'captcha'} eq 'recaptcha') {
3506: $pubtext = $lt{'pub'};
3507: $privtext = $lt{'priv'};
3508: $keyentry = 'text';
3509: }
3510: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3511: $currpub = $settings->{'recaptchakeys'}{'public'};
3512: $currpriv = $settings->{'recaptchakeys'}{'private'};
3513: }
3514: } else {
3515: $checked{'original'} = ' checked="checked"';
3516: }
1.169 raeburn 3517: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3518: my $output = '<tr'.$css_class.'>'.
3519: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3520: '<table><tr><td>'."\n";
3521: foreach my $option ('original','recaptcha','notused') {
3522: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3523: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3524: $lt{$option}.'</label></span>';
3525: unless ($option eq 'notused') {
3526: $output .= (' 'x2)."\n";
3527: }
3528: }
3529: #
3530: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3531: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
3532: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
3533: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
3534: #
3535: $output .= '</td></tr>'."\n".
3536: '<tr><td>'."\n".
3537: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3538: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3539: $currpub.'" size="40" /></span><br />'."\n".
3540: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3541: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3542: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3543: '</td></tr>';
3544: return $output;
3545: }
3546:
1.32 raeburn 3547: sub user_formats_row {
3548: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3549: my $output;
3550: my %text = (
3551: 'username' => 'new usernames',
3552: 'id' => 'IDs',
1.45 raeburn 3553: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3554: );
3555: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3556: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3557: '<td><span class="LC_nobreak">';
3558: if ($type eq 'email') {
3559: $output .= &mt("Formats disallowed for $text{$type}: ");
3560: } else {
3561: $output .= &mt("Format rules to check for $text{$type}: ");
3562: }
3563: $output .= '</span></td>'.
3564: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3565: my $rem;
3566: if (ref($ruleorder) eq 'ARRAY') {
3567: for (my $i=0; $i<@{$ruleorder}; $i++) {
3568: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3569: my $rem = $i%($numinrow);
3570: if ($rem == 0) {
3571: if ($i > 0) {
3572: $output .= '</tr>';
3573: }
3574: $output .= '<tr>';
3575: }
3576: my $check = ' ';
1.39 raeburn 3577: if (ref($settings) eq 'HASH') {
3578: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3579: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3580: $check = ' checked="checked" ';
3581: }
1.27 raeburn 3582: }
3583: }
3584: $output .= '<td class="LC_left_item">'.
3585: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3586: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3587: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3588: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3589: }
3590: }
3591: $rem = @{$ruleorder}%($numinrow);
3592: }
3593: my $colsleft = $numinrow - $rem;
3594: if ($colsleft > 1 ) {
3595: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3596: ' </td>';
3597: } elsif ($colsleft == 1) {
3598: $output .= '<td class="LC_left_item"> </td>';
3599: }
3600: $output .= '</tr></table></td></tr>';
3601: return $output;
3602: }
3603:
1.34 raeburn 3604: sub usercreation_types {
3605: my %lt = &Apache::lonlocal::texthash (
3606: author => 'When adding a co-author',
3607: course => 'When adding a user to a course',
1.100 raeburn 3608: requestcrs => 'When requesting a course',
1.45 raeburn 3609: selfcreate => 'User creates own account',
1.34 raeburn 3610: any => 'Any',
3611: official => 'Institutional only ',
3612: unofficial => 'Non-institutional only',
1.85 schafran 3613: email => 'E-mail address',
1.43 raeburn 3614: login => 'Institutional Login',
3615: sso => 'SSO',
1.34 raeburn 3616: none => 'None',
3617: );
3618: return %lt;
1.48 raeburn 3619: }
1.34 raeburn 3620:
1.28 raeburn 3621: sub authtype_names {
3622: my %lt = &Apache::lonlocal::texthash(
3623: int => 'Internal',
3624: krb4 => 'Kerberos 4',
3625: krb5 => 'Kerberos 5',
3626: loc => 'Local',
3627: );
3628: return %lt;
3629: }
3630:
3631: sub context_names {
3632: my %context_title = &Apache::lonlocal::texthash(
3633: author => 'Creating users when an Author',
3634: course => 'Creating users when in a course',
3635: domain => 'Creating users when a Domain Coordinator',
3636: );
3637: return %context_title;
3638: }
3639:
1.33 raeburn 3640: sub print_usermodification {
3641: my ($position,$dom,$settings,$rowtotal) = @_;
3642: my $numinrow = 4;
3643: my ($context,$datatable,$rowcount);
3644: if ($position eq 'top') {
3645: $rowcount = 0;
3646: $context = 'author';
3647: foreach my $role ('ca','aa') {
3648: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3649: $numinrow,$rowcount);
3650: $$rowtotal ++;
3651: $rowcount ++;
3652: }
1.63 raeburn 3653: } elsif ($position eq 'middle') {
1.33 raeburn 3654: $context = 'course';
3655: $rowcount = 0;
3656: foreach my $role ('st','ep','ta','in','cr') {
3657: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3658: $numinrow,$rowcount);
3659: $$rowtotal ++;
3660: $rowcount ++;
3661: }
1.63 raeburn 3662: } elsif ($position eq 'bottom') {
3663: $context = 'selfcreate';
3664: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3665: $usertypes->{'default'} = $othertitle;
3666: if (ref($types) eq 'ARRAY') {
3667: push(@{$types},'default');
3668: $usertypes->{'default'} = $othertitle;
3669: foreach my $status (@{$types}) {
3670: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3671: $numinrow,$rowcount,$usertypes);
3672: $$rowtotal ++;
3673: $rowcount ++;
3674: }
3675: }
1.33 raeburn 3676: }
3677: return $datatable;
3678: }
3679:
1.43 raeburn 3680: sub print_defaults {
3681: my ($dom,$rowtotal) = @_;
1.68 raeburn 3682: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3683: 'datelocale_def','portal_def');
1.43 raeburn 3684: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 3685: my $titles = &defaults_titles($dom);
1.43 raeburn 3686: my $rownum = 0;
3687: my ($datatable,$css_class);
3688: foreach my $item (@items) {
3689: if ($rownum%2) {
3690: $css_class = '';
3691: } else {
3692: $css_class = ' class="LC_odd_row" ';
3693: }
3694: $datatable .= '<tr'.$css_class.'>'.
3695: '<td><span class="LC_nobreak">'.$titles->{$item}.
3696: '</span></td><td class="LC_right_item">';
3697: if ($item eq 'auth_def') {
3698: my @authtypes = ('internal','krb4','krb5','localauth');
3699: my %shortauth = (
3700: internal => 'int',
3701: krb4 => 'krb4',
3702: krb5 => 'krb5',
3703: localauth => 'loc'
3704: );
3705: my %authnames = &authtype_names();
3706: foreach my $auth (@authtypes) {
3707: my $checked = ' ';
3708: if ($domdefaults{$item} eq $auth) {
3709: $checked = ' checked="checked" ';
3710: }
3711: $datatable .= '<label><input type="radio" name="'.$item.
3712: '" value="'.$auth.'"'.$checked.'/>'.
3713: $authnames{$shortauth{$auth}}.'</label> ';
3714: }
1.54 raeburn 3715: } elsif ($item eq 'timezone_def') {
3716: my $includeempty = 1;
3717: $datatable .= &Apache::loncommon::select_timezone($item,$domdefaults{$item},undef,$includeempty);
1.68 raeburn 3718: } elsif ($item eq 'datelocale_def') {
3719: my $includeempty = 1;
3720: $datatable .= &Apache::loncommon::select_datelocale($item,$domdefaults{$item},undef,$includeempty);
1.167 raeburn 3721: } elsif ($item eq 'lang_def') {
1.168 raeburn 3722: my %langchoices = &get_languages_hash();
3723: $langchoices{''} = 'No language preference';
1.167 raeburn 3724: %langchoices = &Apache::lonlocal::texthash(%langchoices);
3725: $datatable .= &Apache::loncommon::select_form($domdefaults{$item},$item,
3726: \%langchoices);
1.43 raeburn 3727: } else {
1.141 raeburn 3728: my $size;
3729: if ($item eq 'portal_def') {
3730: $size = ' size="25"';
3731: }
1.43 raeburn 3732: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.141 raeburn 3733: $domdefaults{$item}.'"'.$size.' />';
1.43 raeburn 3734: }
3735: $datatable .= '</td></tr>';
3736: $rownum ++;
3737: }
3738: $$rowtotal += $rownum;
3739: return $datatable;
3740: }
3741:
1.168 raeburn 3742: sub get_languages_hash {
3743: my %langchoices;
3744: foreach my $id (&Apache::loncommon::languageids()) {
3745: my $code = &Apache::loncommon::supportedlanguagecode($id);
3746: if ($code ne '') {
3747: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3748: }
3749: }
3750: return %langchoices;
3751: }
3752:
1.43 raeburn 3753: sub defaults_titles {
1.141 raeburn 3754: my ($dom) = @_;
1.43 raeburn 3755: my %titles = &Apache::lonlocal::texthash (
3756: 'auth_def' => 'Default authentication type',
3757: 'auth_arg_def' => 'Default authentication argument',
3758: 'lang_def' => 'Default language',
1.54 raeburn 3759: 'timezone_def' => 'Default timezone',
1.68 raeburn 3760: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3761: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3762: );
1.141 raeburn 3763: if ($dom) {
3764: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3765: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3766: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3767: $protocol = 'http' if ($protocol ne 'https');
3768: if ($uint_dom) {
3769: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3770: $uint_dom);
3771: }
3772: }
1.43 raeburn 3773: return (\%titles);
3774: }
3775:
1.46 raeburn 3776: sub print_scantronformat {
3777: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3778: my $itemcount = 1;
1.60 raeburn 3779: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3780: %confhash);
1.46 raeburn 3781: my $switchserver = &check_switchserver($dom,$confname);
3782: my %lt = &Apache::lonlocal::texthash (
1.95 www 3783: default => 'Default bubblesheet format file error',
3784: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3785: );
3786: my %scantronfiles = (
3787: default => 'default.tab',
3788: custom => 'custom.tab',
3789: );
3790: foreach my $key (keys(%scantronfiles)) {
3791: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3792: .$scantronfiles{$key};
3793: }
3794: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3795: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3796: if (!$switchserver) {
3797: my $servadm = $r->dir_config('lonAdmEMail');
3798: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3799: if ($configuserok eq 'ok') {
3800: if ($author_ok eq 'ok') {
3801: my %legacyfile = (
3802: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3803: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3804: );
3805: my %md5chk;
3806: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3807: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3808: chomp($md5chk{$type});
1.46 raeburn 3809: }
3810: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3811: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3812: ($scantronurls{$type},my $error) =
1.46 raeburn 3813: &legacy_scantronformat($r,$dom,$confname,
3814: $type,$legacyfile{$type},
3815: $scantronurls{$type},
3816: $scantronfiles{$type});
1.60 raeburn 3817: if ($error ne '') {
3818: $error{$type} = $error;
3819: }
3820: }
3821: if (keys(%error) == 0) {
3822: $is_custom = 1;
3823: $confhash{'scantron'}{'scantronformat'} =
3824: $scantronurls{'custom'};
3825: my $putresult =
3826: &Apache::lonnet::put_dom('configuration',
3827: \%confhash,$dom);
3828: if ($putresult ne 'ok') {
3829: $error{'custom'} =
3830: '<span class="LC_error">'.
3831: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3832: }
1.46 raeburn 3833: }
3834: } else {
1.60 raeburn 3835: ($scantronurls{'default'},my $error) =
1.46 raeburn 3836: &legacy_scantronformat($r,$dom,$confname,
3837: 'default',$legacyfile{'default'},
3838: $scantronurls{'default'},
3839: $scantronfiles{'default'});
1.60 raeburn 3840: if ($error eq '') {
3841: $confhash{'scantron'}{'scantronformat'} = '';
3842: my $putresult =
3843: &Apache::lonnet::put_dom('configuration',
3844: \%confhash,$dom);
3845: if ($putresult ne 'ok') {
3846: $error{'default'} =
3847: '<span class="LC_error">'.
3848: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3849: }
3850: } else {
3851: $error{'default'} = $error;
3852: }
1.46 raeburn 3853: }
3854: }
3855: }
3856: } else {
1.95 www 3857: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3858: }
3859: }
3860: if (ref($settings) eq 'HASH') {
3861: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3862: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3863: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3864: $scantronurl = '';
3865: } else {
3866: $scantronurl = $settings->{'scantronformat'};
3867: }
3868: $is_custom = 1;
3869: } else {
3870: $scantronurl = $scantronurls{'default'};
3871: }
3872: } else {
1.60 raeburn 3873: if ($is_custom) {
3874: $scantronurl = $scantronurls{'custom'};
3875: } else {
3876: $scantronurl = $scantronurls{'default'};
3877: }
1.46 raeburn 3878: }
3879: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3880: $datatable .= '<tr'.$css_class.'>';
3881: if (!$is_custom) {
1.65 raeburn 3882: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3883: '<span class="LC_nobreak">';
1.46 raeburn 3884: if ($scantronurl) {
3885: $datatable .= '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3886: &mt('Default bubblesheet format file').'</a>';
1.46 raeburn 3887: } else {
3888: $datatable = &mt('File unavailable for display');
3889: }
1.65 raeburn 3890: $datatable .= '</span></td>';
1.60 raeburn 3891: if (keys(%error) == 0) {
3892: $datatable .= '<td valign="bottom">';
3893: if (!$switchserver) {
3894: $datatable .= &mt('Upload:').'<br />';
3895: }
3896: } else {
3897: my $errorstr;
3898: foreach my $key (sort(keys(%error))) {
3899: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3900: }
3901: $datatable .= '<td>'.$errorstr;
3902: }
1.46 raeburn 3903: } else {
3904: if (keys(%error) > 0) {
3905: my $errorstr;
3906: foreach my $key (sort(keys(%error))) {
3907: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3908: }
1.60 raeburn 3909: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 3910: } elsif ($scantronurl) {
1.65 raeburn 3911: $datatable .= '<td><span class="LC_nobreak">'.
3912: '<a href="'.$scantronurl.'" target="_blank">'.
1.130 raeburn 3913: &mt('Custom bubblesheet format file').'</a><label>'.
1.65 raeburn 3914: '<input type="checkbox" name="scantronformat_del"'.
3915: '" value="1" />'.&mt('Delete?').'</label></span></td>'.
3916: '<td><span class="LC_nobreak"> '.
3917: &mt('Replace:').'</span><br />';
1.46 raeburn 3918: }
3919: }
3920: if (keys(%error) == 0) {
3921: if ($switchserver) {
3922: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
3923: } else {
1.65 raeburn 3924: $datatable .='<span class="LC_nobreak"> '.
3925: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 3926: }
3927: }
3928: $datatable .= '</td></tr>';
3929: $$rowtotal ++;
3930: return $datatable;
3931: }
3932:
3933: sub legacy_scantronformat {
3934: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
3935: my ($url,$error);
3936: my @statinfo = &Apache::lonnet::stat_file($newurl);
3937: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
3938: (my $result,$url) =
3939: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
3940: '','',$newfile);
3941: if ($result ne 'ok') {
1.130 raeburn 3942: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 3943: }
3944: }
3945: return ($url,$error);
3946: }
1.43 raeburn 3947:
1.49 raeburn 3948: sub print_coursecategories {
1.57 raeburn 3949: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
3950: my $datatable;
3951: if ($position eq 'top') {
3952: my $toggle_cats_crs = ' ';
3953: my $toggle_cats_dom = ' checked="checked" ';
3954: my $can_cat_crs = ' ';
3955: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 3956: my $toggle_catscomm_comm = ' ';
3957: my $toggle_catscomm_dom = ' checked="checked" ';
3958: my $can_catcomm_comm = ' ';
3959: my $can_catcomm_dom = ' checked="checked" ';
3960:
1.57 raeburn 3961: if (ref($settings) eq 'HASH') {
3962: if ($settings->{'togglecats'} eq 'crs') {
3963: $toggle_cats_crs = $toggle_cats_dom;
3964: $toggle_cats_dom = ' ';
3965: }
3966: if ($settings->{'categorize'} eq 'crs') {
3967: $can_cat_crs = $can_cat_dom;
3968: $can_cat_dom = ' ';
3969: }
1.120 raeburn 3970: if ($settings->{'togglecatscomm'} eq 'comm') {
3971: $toggle_catscomm_comm = $toggle_catscomm_dom;
3972: $toggle_catscomm_dom = ' ';
3973: }
3974: if ($settings->{'categorizecomm'} eq 'comm') {
3975: $can_catcomm_comm = $can_catcomm_dom;
3976: $can_catcomm_dom = ' ';
3977: }
1.57 raeburn 3978: }
3979: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 3980: togglecats => 'Show/Hide a course in catalog',
3981: togglecatscomm => 'Show/Hide a community in catalog',
3982: categorize => 'Assign a category to a course',
3983: categorizecomm => 'Assign a category to a community',
1.57 raeburn 3984: );
3985: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 3986: dom => 'Set in Domain',
3987: crs => 'Set in Course',
3988: comm => 'Set in Community',
1.57 raeburn 3989: );
3990: $datatable = '<tr class="LC_odd_row">'.
3991: '<td>'.$title{'togglecats'}.'</td>'.
3992: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3993: '<input type="radio" name="togglecats"'.
3994: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
3995: '<label><input type="radio" name="togglecats"'.
3996: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
3997: '</tr><tr>'.
3998: '<td>'.$title{'categorize'}.'</td>'.
3999: '<td class="LC_right_item"><span class="LC_nobreak">'.
4000: '<label><input type="radio" name="categorize"'.
4001: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4002: '<label><input type="radio" name="categorize"'.
4003: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4004: '</tr><tr class="LC_odd_row">'.
4005: '<td>'.$title{'togglecatscomm'}.'</td>'.
4006: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4007: '<input type="radio" name="togglecatscomm"'.
4008: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4009: '<label><input type="radio" name="togglecatscomm"'.
4010: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4011: '</tr><tr>'.
4012: '<td>'.$title{'categorizecomm'}.'</td>'.
4013: '<td class="LC_right_item"><span class="LC_nobreak">'.
4014: '<label><input type="radio" name="categorizecomm"'.
4015: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4016: '<label><input type="radio" name="categorizecomm"'.
4017: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4018: '</tr>';
1.120 raeburn 4019: $$rowtotal += 4;
1.57 raeburn 4020: } else {
4021: my $css_class;
4022: my $itemcount = 1;
4023: my $cathash;
4024: if (ref($settings) eq 'HASH') {
4025: $cathash = $settings->{'cats'};
4026: }
4027: if (ref($cathash) eq 'HASH') {
4028: my (@cats,@trails,%allitems,%idx,@jsarray);
4029: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4030: \%allitems,\%idx,\@jsarray);
4031: my $maxdepth = scalar(@cats);
4032: my $colattrib = '';
4033: if ($maxdepth > 2) {
4034: $colattrib = ' colspan="2" ';
4035: }
4036: my @path;
4037: if (@cats > 0) {
4038: if (ref($cats[0]) eq 'ARRAY') {
4039: my $numtop = @{$cats[0]};
4040: my $maxnum = $numtop;
1.120 raeburn 4041: my %default_names = (
4042: instcode => &mt('Official courses'),
4043: communities => &mt('Communities'),
4044: );
4045:
4046: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4047: ($cathash->{'instcode::0'} eq '') ||
4048: (!grep(/^communities$/,@{$cats[0]})) ||
4049: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4050: $maxnum ++;
4051: }
4052: my $lastidx;
4053: for (my $i=0; $i<$numtop; $i++) {
4054: my $parent = $cats[0][$i];
4055: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4056: my $item = &escape($parent).'::0';
4057: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4058: $lastidx = $idx{$item};
4059: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4060: .'<select name="'.$item.'"'.$chgstr.'>';
4061: for (my $k=0; $k<=$maxnum; $k++) {
4062: my $vpos = $k+1;
4063: my $selstr;
4064: if ($k == $i) {
4065: $selstr = ' selected="selected" ';
4066: }
4067: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4068: }
4069: $datatable .= '</select></td><td>';
1.120 raeburn 4070: if ($parent eq 'instcode' || $parent eq 'communities') {
4071: $datatable .= '<span class="LC_nobreak">'
4072: .$default_names{$parent}.'</span>';
4073: if ($parent eq 'instcode') {
4074: $datatable .= '<br /><span class="LC_nobreak">('
4075: .&mt('with institutional codes')
4076: .')</span></td><td'.$colattrib.'>';
4077: } else {
4078: $datatable .= '<table><tr><td>';
4079: }
4080: $datatable .= '<span class="LC_nobreak">'
4081: .'<label><input type="radio" name="'
4082: .$parent.'" value="1" checked="checked" />'
4083: .&mt('Display').'</label>';
4084: if ($parent eq 'instcode') {
4085: $datatable .= ' ';
4086: } else {
4087: $datatable .= '</span></td></tr><tr><td>'
4088: .'<span class="LC_nobreak">';
4089: }
4090: $datatable .= '<label><input type="radio" name="'
4091: .$parent.'" value="0" />'
4092: .&mt('Do not display').'</label></span>';
4093: if ($parent eq 'communities') {
4094: $datatable .= '</td></tr></table>';
4095: }
4096: $datatable .= '</td>';
1.57 raeburn 4097: } else {
4098: $datatable .= $parent
4099: .' <label><input type="checkbox" name="deletecategory" '
4100: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4101: }
4102: my $depth = 1;
4103: push(@path,$parent);
4104: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4105: pop(@path);
4106: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4107: $itemcount ++;
4108: }
1.48 raeburn 4109: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4110: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4111: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4112: for (my $k=0; $k<=$maxnum; $k++) {
4113: my $vpos = $k+1;
4114: my $selstr;
1.57 raeburn 4115: if ($k == $numtop) {
1.48 raeburn 4116: $selstr = ' selected="selected" ';
4117: }
4118: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4119: }
1.59 bisitz 4120: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4121: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4122: .'</tr>'."\n";
1.48 raeburn 4123: $itemcount ++;
1.120 raeburn 4124: foreach my $default ('instcode','communities') {
4125: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4127: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4128: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4129: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4130: for (my $k=0; $k<=$maxnum; $k++) {
4131: my $vpos = $k+1;
4132: my $selstr;
4133: if ($k == $maxnum) {
4134: $selstr = ' selected="selected" ';
4135: }
4136: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4137: }
1.120 raeburn 4138: $datatable .= '</select></span></td>'.
4139: '<td><span class="LC_nobreak">'.
4140: $default_names{$default}.'</span>';
4141: if ($default eq 'instcode') {
4142: $datatable .= '<br /><span class="LC_nobreak">('
4143: .&mt('with institutional codes').')</span>';
4144: }
4145: $datatable .= '</td>'
4146: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4147: .&mt('Display').'</label> '
4148: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4149: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4150: }
4151: }
4152: }
1.57 raeburn 4153: } else {
4154: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4155: }
4156: } else {
1.57 raeburn 4157: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4158: .&initialize_categories($itemcount);
1.48 raeburn 4159: }
1.57 raeburn 4160: $$rowtotal += $itemcount;
1.48 raeburn 4161: }
4162: return $datatable;
4163: }
4164:
1.69 raeburn 4165: sub print_serverstatuses {
4166: my ($dom,$settings,$rowtotal) = @_;
4167: my $datatable;
4168: my @pages = &serverstatus_pages();
4169: my (%namedaccess,%machineaccess);
4170: foreach my $type (@pages) {
4171: $namedaccess{$type} = '';
4172: $machineaccess{$type}= '';
4173: }
4174: if (ref($settings) eq 'HASH') {
4175: foreach my $type (@pages) {
4176: if (exists($settings->{$type})) {
4177: if (ref($settings->{$type}) eq 'HASH') {
4178: foreach my $key (keys(%{$settings->{$type}})) {
4179: if ($key eq 'namedusers') {
4180: $namedaccess{$type} = $settings->{$type}->{$key};
4181: } elsif ($key eq 'machines') {
4182: $machineaccess{$type} = $settings->{$type}->{$key};
4183: }
4184: }
4185: }
4186: }
4187: }
4188: }
1.81 raeburn 4189: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4190: my $rownum = 0;
4191: my $css_class;
4192: foreach my $type (@pages) {
4193: $rownum ++;
4194: $css_class = $rownum%2?' class="LC_odd_row"':'';
4195: $datatable .= '<tr'.$css_class.'>'.
4196: '<td><span class="LC_nobreak">'.
4197: $titles->{$type}.'</span></td>'.
4198: '<td class="LC_left_item">'.
4199: '<input type="text" name="'.$type.'_namedusers" '.
4200: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4201: '<td class="LC_right_item">'.
4202: '<span class="LC_nobreak">'.
4203: '<input type="text" name="'.$type.'_machines" '.
4204: 'value="'.$machineaccess{$type}.'" size="10" />'.
4205: '</td></tr>'."\n";
4206: }
4207: $$rowtotal += $rownum;
4208: return $datatable;
4209: }
4210:
4211: sub serverstatus_pages {
4212: return ('userstatus','lonstatus','loncron','server-status','codeversions',
4213: 'clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4214: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4215: }
4216:
1.49 raeburn 4217: sub coursecategories_javascript {
4218: my ($settings) = @_;
1.57 raeburn 4219: my ($output,$jstext,$cathash);
1.49 raeburn 4220: if (ref($settings) eq 'HASH') {
1.57 raeburn 4221: $cathash = $settings->{'cats'};
4222: }
4223: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4224: my (@cats,@jsarray,%idx);
1.57 raeburn 4225: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4226: if (@jsarray > 0) {
4227: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4228: for (my $i=0; $i<@jsarray; $i++) {
4229: if (ref($jsarray[$i]) eq 'ARRAY') {
4230: my $catstr = join('","',@{$jsarray[$i]});
4231: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4232: }
4233: }
4234: }
4235: } else {
4236: $jstext = ' var categories = Array(1);'."\n".
4237: ' categories[0] = Array("instcode_pos");'."\n";
4238: }
1.120 raeburn 4239: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4240: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4241: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4242: $output = <<"ENDSCRIPT";
4243: <script type="text/javascript">
1.109 raeburn 4244: // <![CDATA[
1.49 raeburn 4245: function reorderCats(form,parent,item,idx) {
4246: var changedVal;
4247: $jstext
4248: var newpos = 'addcategory_pos';
4249: var current = new Array;
4250: if (parent == '') {
4251: var has_instcode = 0;
4252: var maxtop = categories[idx].length;
4253: for (var j=0; j<maxtop; j++) {
4254: if (categories[idx][j] == 'instcode::0') {
4255: has_instcode == 1;
4256: }
4257: }
4258: if (has_instcode == 0) {
4259: categories[idx][maxtop] = 'instcode_pos';
4260: }
4261: } else {
4262: newpos += '_'+parent;
4263: }
4264: var maxh = 1 + categories[idx].length;
4265: var current = new Array;
4266: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4267: if (item == newpos) {
4268: changedVal = newitemVal;
4269: } else {
4270: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4271: current[newitemVal] = newpos;
4272: }
4273: for (var i=0; i<categories[idx].length; i++) {
4274: var elementName = categories[idx][i];
4275: if (elementName != item) {
4276: if (form.elements[elementName]) {
4277: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4278: current[currVal] = elementName;
4279: }
4280: }
4281: }
4282: var oldVal;
4283: for (var j=0; j<maxh; j++) {
4284: if (current[j] == undefined) {
4285: oldVal = j;
4286: }
4287: }
4288: if (oldVal < changedVal) {
4289: for (var k=oldVal+1; k<=changedVal ; k++) {
4290: var elementName = current[k];
4291: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4292: }
4293: } else {
4294: for (var k=changedVal; k<oldVal; k++) {
4295: var elementName = current[k];
4296: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4297: }
4298: }
4299: return;
4300: }
1.120 raeburn 4301:
4302: function categoryCheck(form) {
4303: if (form.elements['addcategory_name'].value == 'instcode') {
4304: alert('$instcode_reserved\\n$choose_again');
4305: return false;
4306: }
4307: if (form.elements['addcategory_name'].value == 'communities') {
4308: alert('$communities_reserved\\n$choose_again');
4309: return false;
4310: }
4311: return true;
4312: }
4313:
1.109 raeburn 4314: // ]]>
1.49 raeburn 4315: </script>
4316:
4317: ENDSCRIPT
4318: return $output;
4319: }
4320:
1.48 raeburn 4321: sub initialize_categories {
4322: my ($itemcount) = @_;
1.120 raeburn 4323: my ($datatable,$css_class,$chgstr);
4324: my %default_names = (
4325: instcode => 'Official courses (with institutional codes)',
4326: communities => 'Communities',
4327: );
4328: my $select0 = ' selected="selected"';
4329: my $select1 = '';
4330: foreach my $default ('instcode','communities') {
4331: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4332: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4333: if ($default eq 'communities') {
4334: $select1 = $select0;
4335: $select0 = '';
4336: }
4337: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4338: .'<select name="'.$default.'_pos">'
4339: .'<option value="0"'.$select0.'>1</option>'
4340: .'<option value="1"'.$select1.'>2</option>'
4341: .'<option value="2">3</option></select> '
4342: .$default_names{$default}
4343: .'</span></td><td><span class="LC_nobreak">'
4344: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4345: .&mt('Display').'</label> <label>'
4346: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4347: .'</label></span></td></tr>';
1.120 raeburn 4348: $itemcount ++;
4349: }
1.48 raeburn 4350: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4351: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4352: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4353: .'<select name="addcategory_pos"'.$chgstr.'>'
4354: .'<option value="0">1</option>'
4355: .'<option value="1">2</option>'
4356: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4357: .&mt('Add category').'</td><td>'.&mt('Name:')
4358: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4359: return $datatable;
4360: }
4361:
4362: sub build_category_rows {
1.49 raeburn 4363: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4364: my ($text,$name,$item,$chgstr);
1.48 raeburn 4365: if (ref($cats) eq 'ARRAY') {
4366: my $maxdepth = scalar(@{$cats});
4367: if (ref($cats->[$depth]) eq 'HASH') {
4368: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4369: my $numchildren = @{$cats->[$depth]{$parent}};
4370: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
4371: $text .= '<td><table class="LC_datatable">';
1.49 raeburn 4372: my ($idxnum,$parent_name,$parent_item);
4373: my $higher = $depth - 1;
4374: if ($higher == 0) {
4375: $parent_name = &escape($parent).'::'.$higher;
4376: } else {
4377: if (ref($path) eq 'ARRAY') {
4378: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4379: }
4380: }
4381: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4382: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4383: if ($j < $numchildren) {
1.48 raeburn 4384: $name = $cats->[$depth]{$parent}[$j];
4385: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4386: $idxnum = $idx->{$item};
4387: } else {
4388: $name = $parent_name;
4389: $item = $parent_item;
1.48 raeburn 4390: }
1.49 raeburn 4391: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4392: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4393: for (my $i=0; $i<=$numchildren; $i++) {
4394: my $vpos = $i+1;
4395: my $selstr;
4396: if ($j == $i) {
4397: $selstr = ' selected="selected" ';
4398: }
4399: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4400: }
4401: $text .= '</select> ';
4402: if ($j < $numchildren) {
4403: my $deeper = $depth+1;
4404: $text .= $name.' '
4405: .'<label><input type="checkbox" name="deletecategory" value="'
4406: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4407: if(ref($path) eq 'ARRAY') {
4408: push(@{$path},$name);
1.49 raeburn 4409: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4410: pop(@{$path});
4411: }
4412: } else {
1.59 bisitz 4413: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4414: if ($j == $numchildren) {
4415: $text .= $name;
4416: } else {
4417: $text .= $item;
4418: }
4419: $text .= '" value="" />';
4420: }
4421: $text .= '</td></tr>';
4422: }
4423: $text .= '</table></td>';
4424: } else {
4425: my $higher = $depth-1;
4426: if ($higher == 0) {
4427: $name = &escape($parent).'::'.$higher;
4428: } else {
4429: if (ref($path) eq 'ARRAY') {
4430: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4431: }
4432: }
4433: my $colspan;
4434: if ($parent ne 'instcode') {
4435: $colspan = $maxdepth - $depth - 1;
4436: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4437: }
4438: }
4439: }
4440: }
4441: return $text;
4442: }
4443:
1.33 raeburn 4444: sub modifiable_userdata_row {
1.63 raeburn 4445: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4446: my $rolename;
1.63 raeburn 4447: if ($context eq 'selfcreate') {
4448: if (ref($usertypes) eq 'HASH') {
4449: $rolename = $usertypes->{$role};
4450: } else {
4451: $rolename = $role;
4452: }
1.33 raeburn 4453: } else {
1.63 raeburn 4454: if ($role eq 'cr') {
4455: $rolename = &mt('Custom role');
4456: } else {
4457: $rolename = &Apache::lonnet::plaintext($role);
4458: }
1.33 raeburn 4459: }
4460: my @fields = ('lastname','firstname','middlename','generation',
4461: 'permanentemail','id');
4462: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4463: my $output;
4464: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4465: $output = '<tr '.$css_class.'>'.
4466: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4467: '<td class="LC_left_item" colspan="2"><table>';
4468: my $rem;
4469: my %checks;
4470: if (ref($settings) eq 'HASH') {
4471: if (ref($settings->{$context}) eq 'HASH') {
4472: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4473: foreach my $field (@fields) {
4474: if ($settings->{$context}->{$role}->{$field}) {
4475: $checks{$field} = ' checked="checked" ';
4476: }
4477: }
4478: }
4479: }
4480: }
4481: for (my $i=0; $i<@fields; $i++) {
4482: my $rem = $i%($numinrow);
4483: if ($rem == 0) {
4484: if ($i > 0) {
4485: $output .= '</tr>';
4486: }
4487: $output .= '<tr>';
4488: }
4489: my $check = ' ';
4490: if (exists($checks{$fields[$i]})) {
4491: $check = $checks{$fields[$i]}
4492: } else {
4493: if ($role eq 'st') {
4494: if (ref($settings) ne 'HASH') {
4495: $check = ' checked="checked" ';
4496: }
4497: }
4498: }
4499: $output .= '<td class="LC_left_item">'.
4500: '<span class="LC_nobreak"><label>'.
4501: '<input type="checkbox" name="canmodify_'.$role.'" '.
4502: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4503: '</label></span></td>';
4504: $rem = @fields%($numinrow);
4505: }
4506: my $colsleft = $numinrow - $rem;
4507: if ($colsleft > 1 ) {
4508: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4509: ' </td>';
4510: } elsif ($colsleft == 1) {
4511: $output .= '<td class="LC_left_item"> </td>';
4512: }
4513: $output .= '</tr></table></td></tr>';
4514: return $output;
4515: }
1.28 raeburn 4516:
1.93 raeburn 4517: sub insttypes_row {
4518: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4519: my %lt = &Apache::lonlocal::texthash (
4520: cansearch => 'Users allowed to search',
4521: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4522: lockablenames => 'User preference to lock name',
1.93 raeburn 4523: );
4524: my $showdom;
4525: if ($context eq 'cansearch') {
4526: $showdom = ' ('.$dom.')';
4527: }
1.165 raeburn 4528: my $class = 'LC_left_item';
4529: if ($context eq 'statustocreate') {
4530: $class = 'LC_right_item';
4531: }
1.25 raeburn 4532: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4533: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4534: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4535: my $rem;
4536: if (ref($types) eq 'ARRAY') {
4537: for (my $i=0; $i<@{$types}; $i++) {
4538: if (defined($usertypes->{$types->[$i]})) {
4539: my $rem = $i%($numinrow);
4540: if ($rem == 0) {
4541: if ($i > 0) {
4542: $output .= '</tr>';
4543: }
4544: $output .= '<tr>';
1.23 raeburn 4545: }
1.26 raeburn 4546: my $check = ' ';
1.99 raeburn 4547: if (ref($settings) eq 'HASH') {
4548: if (ref($settings->{$context}) eq 'ARRAY') {
4549: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4550: $check = ' checked="checked" ';
4551: }
4552: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4553: $check = ' checked="checked" ';
4554: }
1.23 raeburn 4555: }
1.26 raeburn 4556: $output .= '<td class="LC_left_item">'.
4557: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4558: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4559: 'value="'.$types->[$i].'"'.$check.'/>'.
4560: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4561: }
4562: }
1.26 raeburn 4563: $rem = @{$types}%($numinrow);
1.23 raeburn 4564: }
4565: my $colsleft = $numinrow - $rem;
1.131 raeburn 4566: if (($rem == 0) && (@{$types} > 0)) {
4567: $output .= '<tr>';
4568: }
1.23 raeburn 4569: if ($colsleft > 1) {
1.25 raeburn 4570: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4571: } else {
1.25 raeburn 4572: $output .= '<td class="LC_left_item">';
1.23 raeburn 4573: }
4574: my $defcheck = ' ';
1.99 raeburn 4575: if (ref($settings) eq 'HASH') {
4576: if (ref($settings->{$context}) eq 'ARRAY') {
4577: if (grep(/^default$/,@{$settings->{$context}})) {
4578: $defcheck = ' checked="checked" ';
4579: }
4580: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4581: $defcheck = ' checked="checked" ';
4582: }
1.23 raeburn 4583: }
1.25 raeburn 4584: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4585: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4586: 'value="default"'.$defcheck.'/>'.
4587: $othertitle.'</label></span></td>'.
4588: '</tr></table></td></tr>';
4589: return $output;
1.23 raeburn 4590: }
4591:
4592: sub sorted_searchtitles {
4593: my %searchtitles = &Apache::lonlocal::texthash(
4594: 'uname' => 'username',
4595: 'lastname' => 'last name',
4596: 'lastfirst' => 'last name, first name',
4597: );
4598: my @titleorder = ('uname','lastname','lastfirst');
4599: return (\%searchtitles,\@titleorder);
4600: }
4601:
1.25 raeburn 4602: sub sorted_searchtypes {
4603: my %srchtypes_desc = (
4604: exact => 'is exact match',
4605: contains => 'contains ..',
4606: begins => 'begins with ..',
4607: );
4608: my @srchtypeorder = ('exact','begins','contains');
4609: return (\%srchtypes_desc,\@srchtypeorder);
4610: }
4611:
1.3 raeburn 4612: sub usertype_update_row {
4613: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4614: my $datatable;
4615: my $numinrow = 4;
4616: foreach my $type (@{$types}) {
4617: if (defined($usertypes->{$type})) {
4618: $$rownums ++;
4619: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4620: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4621: '</td><td class="LC_left_item"><table>';
4622: for (my $i=0; $i<@{$fields}; $i++) {
4623: my $rem = $i%($numinrow);
4624: if ($rem == 0) {
4625: if ($i > 0) {
4626: $datatable .= '</tr>';
4627: }
4628: $datatable .= '<tr>';
4629: }
4630: my $check = ' ';
1.39 raeburn 4631: if (ref($settings) eq 'HASH') {
4632: if (ref($settings->{'fields'}) eq 'HASH') {
4633: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4634: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4635: $check = ' checked="checked" ';
4636: }
1.3 raeburn 4637: }
4638: }
4639: }
4640:
4641: if ($i == @{$fields}-1) {
4642: my $colsleft = $numinrow - $rem;
4643: if ($colsleft > 1) {
4644: $datatable .= '<td colspan="'.$colsleft.'">';
4645: } else {
4646: $datatable .= '<td>';
4647: }
4648: } else {
4649: $datatable .= '<td>';
4650: }
1.8 raeburn 4651: $datatable .= '<span class="LC_nobreak"><label>'.
4652: '<input type="checkbox" name="updateable_'.$type.
4653: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4654: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4655: }
4656: $datatable .= '</tr></table></td></tr>';
4657: }
4658: }
4659: return $datatable;
1.1 raeburn 4660: }
4661:
4662: sub modify_login {
1.9 raeburn 4663: my ($r,$dom,$confname,%domconfig) = @_;
1.168 raeburn 4664: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4665: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4666: %title = ( coursecatalog => 'Display course catalog',
4667: adminmail => 'Display administrator E-mail address',
1.188 ! raeburn 4668: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 4669: newuser => 'Link for visitors to create a user account',
4670: loginheader => 'Log-in box header');
4671: @offon = ('off','on');
1.112 raeburn 4672: if (ref($domconfig{login}) eq 'HASH') {
4673: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4674: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4675: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4676: }
4677: }
4678: }
1.9 raeburn 4679: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4680: \%domconfig,\%loginhash);
1.188 ! raeburn 4681: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4682: foreach my $item (@toggles) {
4683: $loginhash{login}{$item} = $env{'form.'.$item};
4684: }
1.41 raeburn 4685: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4686: if (ref($colchanges{'login'}) eq 'HASH') {
4687: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4688: \%loginhash);
4689: }
1.110 raeburn 4690:
1.149 raeburn 4691: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4692: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4693: if (keys(%servers) > 1) {
4694: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4695: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4696: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4697: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4698: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4699: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4700: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4701: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4702: $changes{'loginvia'}{$lonhost} = 1;
4703: } else {
4704: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4705: $changes{'loginvia'}{$lonhost} = 1;
4706: }
4707: } else {
4708: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4709: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4710: $changes{'loginvia'}{$lonhost} = 1;
4711: }
4712: }
4713: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4714: foreach my $item (@loginvia_attribs) {
4715: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4716: }
4717: } else {
4718: foreach my $item (@loginvia_attribs) {
4719: my $new = $env{'form.'.$lonhost.'_'.$item};
4720: if (($item eq 'serverpath') && ($new eq 'custom')) {
4721: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4722: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4723: $new = '/';
4724: }
4725: }
4726: if (($item eq 'custompath') &&
4727: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4728: $new = '';
4729: }
4730: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4731: $changes{'loginvia'}{$lonhost} = 1;
4732: }
4733: if ($item eq 'exempt') {
4734: $new =~ s/^\s+//;
4735: $new =~ s/\s+$//;
4736: my @poss_ips = split(/\s*[,:]\s*/,$new);
4737: my @okips;
4738: foreach my $ip (@poss_ips) {
4739: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4740: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4741: push(@okips,$ip);
4742: }
4743: }
4744: }
4745: if (@okips > 0) {
4746: $new = join(',',@okips);
4747: } else {
4748: $new = '';
4749: }
4750: }
4751: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4752: }
4753: }
1.112 raeburn 4754: } else {
1.128 raeburn 4755: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4756: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4757: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4758: foreach my $item (@loginvia_attribs) {
4759: my $new = $env{'form.'.$lonhost.'_'.$item};
4760: if (($item eq 'serverpath') && ($new eq 'custom')) {
4761: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4762: $new = '/';
4763: }
4764: }
4765: if (($item eq 'custompath') &&
4766: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4767: $new = '';
4768: }
4769: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4770: }
1.110 raeburn 4771: }
4772: }
4773: }
4774: }
1.119 raeburn 4775:
1.168 raeburn 4776: my $servadm = $r->dir_config('lonAdmEMail');
4777: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4778: if (ref($domconfig{'login'}) eq 'HASH') {
4779: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4780: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4781: if ($lang eq 'nolang') {
4782: push(@currlangs,$lang);
4783: } elsif (defined($langchoices{$lang})) {
4784: push(@currlangs,$lang);
4785: } else {
4786: next;
4787: }
4788: }
4789: }
4790: }
4791: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4792: if (@currlangs > 0) {
4793: foreach my $lang (@currlangs) {
4794: if (grep(/^\Q$lang\E$/,@delurls)) {
4795: $changes{'helpurl'}{$lang} = 1;
4796: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4797: $changes{'helpurl'}{$lang} = 1;
4798: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4799: push(@newlangs,$lang);
4800: } else {
4801: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4802: }
4803: }
4804: }
4805: unless (grep(/^nolang$/,@currlangs)) {
4806: if ($env{'form.loginhelpurl_nolang.filename'}) {
4807: $changes{'helpurl'}{'nolang'} = 1;
4808: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4809: push(@newlangs,'nolang');
4810: }
4811: }
4812: if ($env{'form.loginhelpurl_add_lang'}) {
4813: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4814: ($env{'form.loginhelpurl_add_file.filename'})) {
4815: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4816: $addedfile = $env{'form.loginhelpurl_add_lang'};
4817: }
4818: }
4819: if ((@newlangs > 0) || ($addedfile)) {
4820: my $error;
4821: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4822: if ($configuserok eq 'ok') {
4823: if ($switchserver) {
4824: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4825: } elsif ($author_ok eq 'ok') {
4826: my @allnew = @newlangs;
4827: if ($addedfile ne '') {
4828: push(@allnew,$addedfile);
4829: }
4830: foreach my $lang (@allnew) {
4831: my $formelem = 'loginhelpurl_'.$lang;
4832: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4833: $formelem = 'loginhelpurl_add_file';
4834: }
4835: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4836: "help/$lang",'','',$newfile{$lang});
4837: if ($result eq 'ok') {
4838: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4839: $changes{'helpurl'}{$lang} = 1;
4840: } else {
4841: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4842: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
4843: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
4844: (!grep(/^\Q$lang\E$/,@delurls))) {
4845:
4846: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4847: }
4848: }
4849: }
4850: } else {
4851: $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);
4852: }
4853: } else {
4854: $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);
4855: }
4856: if ($error) {
4857: &Apache::lonnet::logthis($error);
4858: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4859: }
4860: }
1.169 raeburn 4861: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4862:
4863: my $defaulthelpfile = '/adm/loginproblems.html';
4864: my $defaulttext = &mt('Default in use');
4865:
1.1 raeburn 4866: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4867: $dom);
4868: if ($putresult eq 'ok') {
1.188 ! raeburn 4869: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4870: my %defaultchecked = (
4871: 'coursecatalog' => 'on',
1.188 ! raeburn 4872: 'helpdesk' => 'on',
1.42 raeburn 4873: 'adminmail' => 'off',
1.43 raeburn 4874: 'newuser' => 'off',
1.42 raeburn 4875: );
1.55 raeburn 4876: if (ref($domconfig{'login'}) eq 'HASH') {
4877: foreach my $item (@toggles) {
4878: if ($defaultchecked{$item} eq 'on') {
4879: if (($domconfig{'login'}{$item} eq '0') &&
4880: ($env{'form.'.$item} eq '1')) {
4881: $changes{$item} = 1;
4882: } elsif (($domconfig{'login'}{$item} eq '' ||
4883: $domconfig{'login'}{$item} eq '1') &&
4884: ($env{'form.'.$item} eq '0')) {
4885: $changes{$item} = 1;
4886: }
4887: } elsif ($defaultchecked{$item} eq 'off') {
4888: if (($domconfig{'login'}{$item} eq '1') &&
4889: ($env{'form.'.$item} eq '0')) {
4890: $changes{$item} = 1;
4891: } elsif (($domconfig{'login'}{$item} eq '' ||
4892: $domconfig{'login'}{$item} eq '0') &&
4893: ($env{'form.'.$item} eq '1')) {
4894: $changes{$item} = 1;
4895: }
1.42 raeburn 4896: }
4897: }
1.41 raeburn 4898: }
1.6 raeburn 4899: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4900: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.1 raeburn 4901: $resulttext = &mt('Changes made:').'<ul>';
4902: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4903: if ($item eq 'loginvia') {
1.112 raeburn 4904: if (ref($changes{$item}) eq 'HASH') {
4905: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
4906: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 4907: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
4908: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
4909: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
4910: $protocol = 'http' if ($protocol ne 'https');
4911: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
4912:
4913: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
4914: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
4915: } else {
4916: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
4917: }
4918: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
4919: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
4920: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
4921: }
4922: $resulttext .= '</li>';
4923: } else {
4924: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
4925: }
1.112 raeburn 4926: } else {
1.128 raeburn 4927: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 4928: }
4929: }
1.128 raeburn 4930: $resulttext .= '</ul></li>';
1.112 raeburn 4931: }
1.168 raeburn 4932: } elsif ($item eq 'helpurl') {
4933: if (ref($changes{$item}) eq 'HASH') {
4934: foreach my $lang (sort(keys(%{$changes{$item}}))) {
4935: if (grep(/^\Q$lang\E$/,@delurls)) {
4936: my ($chg,$link);
4937: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
4938: if ($lang eq 'nolang') {
4939: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
4940: } else {
4941: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
4942: }
4943: $resulttext .= '<li>'.$chg.'</li>';
4944: } else {
4945: my $chg;
4946: if ($lang eq 'nolang') {
4947: $chg = &mt('custom log-in help file for no preferred language');
4948: } else {
4949: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
4950: }
4951: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
4952: $loginhash{'login'}{'helpurl'}{$lang}.
4953: '?inhibitmenu=yes',$chg,600,500).
4954: '</li>';
4955: }
4956: }
4957: }
1.169 raeburn 4958: } elsif ($item eq 'captcha') {
4959: if (ref($loginhash{'login'}) eq 'HASH') {
4960: my $chgtxt;
4961: if ($loginhash{'login'}{$item} eq 'notused') {
4962: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
4963: } else {
4964: my %captchas = &captcha_phrases();
4965: if ($captchas{$loginhash{'login'}{$item}}) {
4966: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
4967: } else {
4968: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
4969: }
4970: }
4971: $resulttext .= '<li>'.$chgtxt.'</li>';
4972: }
4973: } elsif ($item eq 'recaptchakeys') {
4974: if (ref($loginhash{'login'}) eq 'HASH') {
4975: my ($privkey,$pubkey);
4976: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
4977: $pubkey = $loginhash{'login'}{$item}{'public'};
4978: $privkey = $loginhash{'login'}{$item}{'private'};
4979: }
4980: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
4981: if (!$pubkey) {
4982: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
4983: } else {
4984: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
4985: }
4986: if (!$privkey) {
4987: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
4988: } else {
4989: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
4990: }
4991: $chgtxt .= '</ul>';
4992: $resulttext .= '<li>'.$chgtxt.'</li>';
4993: }
1.41 raeburn 4994: } else {
4995: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
4996: }
1.1 raeburn 4997: }
1.6 raeburn 4998: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 4999: } else {
5000: $resulttext = &mt('No changes made to log-in page settings');
5001: }
5002: } else {
1.11 albertel 5003: $resulttext = '<span class="LC_error">'.
5004: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5005: }
1.6 raeburn 5006: if ($errors) {
1.9 raeburn 5007: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5008: $errors.'</ul>';
5009: }
5010: return $resulttext;
5011: }
5012:
5013: sub color_font_choices {
5014: my %choices =
5015: &Apache::lonlocal::texthash (
5016: img => "Header",
5017: bgs => "Background colors",
5018: links => "Link colors",
1.55 raeburn 5019: images => "Images",
1.6 raeburn 5020: font => "Font color",
1.97 tempelho 5021: fontmenu => "Font Menu",
1.76 raeburn 5022: pgbg => "Page",
1.6 raeburn 5023: tabbg => "Header",
5024: sidebg => "Border",
5025: link => "Link",
5026: alink => "Active link",
5027: vlink => "Visited link",
5028: );
5029: return %choices;
5030: }
5031:
5032: sub modify_rolecolors {
1.9 raeburn 5033: my ($r,$dom,$confname,$roles,%domconfig) = @_;
1.6 raeburn 5034: my ($resulttext,%rolehash);
5035: $rolehash{'rolecolors'} = {};
1.55 raeburn 5036: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5037: if ($domconfig{'rolecolors'} eq '') {
5038: $domconfig{'rolecolors'} = {};
5039: }
5040: }
1.9 raeburn 5041: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5042: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5043: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5044: $dom);
5045: if ($putresult eq 'ok') {
5046: if (keys(%changes) > 0) {
1.41 raeburn 5047: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.6 raeburn 5048: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5049: $rolehash{'rolecolors'});
5050: } else {
5051: $resulttext = &mt('No changes made to default color schemes');
5052: }
5053: } else {
1.11 albertel 5054: $resulttext = '<span class="LC_error">'.
5055: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5056: }
5057: if ($errors) {
5058: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5059: $errors.'</ul>';
5060: }
5061: return $resulttext;
5062: }
5063:
5064: sub modify_colors {
1.9 raeburn 5065: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5066: my (%changes,%choices);
1.51 raeburn 5067: my @bgs;
1.6 raeburn 5068: my @links = ('link','alink','vlink');
1.41 raeburn 5069: my @logintext;
1.6 raeburn 5070: my @images;
5071: my $servadm = $r->dir_config('lonAdmEMail');
5072: my $errors;
5073: foreach my $role (@{$roles}) {
5074: if ($role eq 'login') {
1.12 raeburn 5075: %choices = &login_choices();
1.41 raeburn 5076: @logintext = ('textcol','bgcol');
1.12 raeburn 5077: } else {
5078: %choices = &color_font_choices();
1.107 raeburn 5079: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
1.12 raeburn 5080: }
5081: if ($role eq 'login') {
1.41 raeburn 5082: @images = ('img','logo','domlogo','login');
1.51 raeburn 5083: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5084: } else {
5085: @images = ('img');
1.51 raeburn 5086: @bgs = ('pgbg','tabbg','sidebg');
1.6 raeburn 5087: }
5088: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
1.41 raeburn 5089: foreach my $item (@bgs,@links,@logintext) {
1.6 raeburn 5090: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5091: }
1.46 raeburn 5092: my ($configuserok,$author_ok,$switchserver) =
5093: &config_check($dom,$confname,$servadm);
1.9 raeburn 5094: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5095: if (ref($domconfig->{$role}) ne 'HASH') {
5096: $domconfig->{$role} = {};
5097: }
1.8 raeburn 5098: foreach my $img (@images) {
1.70 raeburn 5099: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5100: if (defined($env{'form.login_showlogo_'.$img})) {
5101: $confhash->{$role}{'showlogo'}{$img} = 1;
5102: } else {
5103: $confhash->{$role}{'showlogo'}{$img} = 0;
5104: }
5105: }
1.18 albertel 5106: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5107: && !defined($domconfig->{$role}{$img})
5108: && !$env{'form.'.$role.'_del_'.$img}
5109: && $env{'form.'.$role.'_import_'.$img}) {
5110: # import the old configured image from the .tab setting
5111: # if they haven't provided a new one
5112: $domconfig->{$role}{$img} =
5113: $env{'form.'.$role.'_import_'.$img};
5114: }
1.6 raeburn 5115: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5116: my $error;
1.6 raeburn 5117: if ($configuserok eq 'ok') {
1.9 raeburn 5118: if ($switchserver) {
1.12 raeburn 5119: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5120: } else {
5121: if ($author_ok eq 'ok') {
5122: my ($result,$logourl) =
5123: &publishlogo($r,'upload',$role.'_'.$img,
5124: $dom,$confname,$img,$width,$height);
5125: if ($result eq 'ok') {
5126: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5127: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5128: } else {
1.12 raeburn 5129: $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 5130: }
5131: } else {
1.46 raeburn 5132: $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 5133: }
5134: }
5135: } else {
1.46 raeburn 5136: $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 5137: }
5138: if ($error) {
1.8 raeburn 5139: &Apache::lonnet::logthis($error);
1.11 albertel 5140: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5141: }
5142: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5143: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5144: my $error;
5145: if ($configuserok eq 'ok') {
5146: # is confname an author?
5147: if ($switchserver eq '') {
5148: if ($author_ok eq 'ok') {
5149: my ($result,$logourl) =
5150: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5151: $dom,$confname,$img,$width,$height);
5152: if ($result eq 'ok') {
5153: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5154: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5155: }
5156: }
5157: }
5158: }
1.6 raeburn 5159: }
5160: }
5161: }
5162: if (ref($domconfig) eq 'HASH') {
5163: if (ref($domconfig->{$role}) eq 'HASH') {
5164: foreach my $img (@images) {
5165: if ($domconfig->{$role}{$img} ne '') {
5166: if ($env{'form.'.$role.'_del_'.$img}) {
5167: $confhash->{$role}{$img} = '';
1.12 raeburn 5168: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5169: } else {
1.9 raeburn 5170: if ($confhash->{$role}{$img} eq '') {
5171: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5172: }
1.6 raeburn 5173: }
5174: } else {
5175: if ($env{'form.'.$role.'_del_'.$img}) {
5176: $confhash->{$role}{$img} = '';
1.12 raeburn 5177: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5178: }
5179: }
1.70 raeburn 5180: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5181: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5182: if ($confhash->{$role}{'showlogo'}{$img} ne
5183: $domconfig->{$role}{'showlogo'}{$img}) {
5184: $changes{$role}{'showlogo'}{$img} = 1;
5185: }
5186: } else {
5187: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5188: $changes{$role}{'showlogo'}{$img} = 1;
5189: }
5190: }
5191: }
5192: }
1.6 raeburn 5193: if ($domconfig->{$role}{'font'} ne '') {
5194: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5195: $changes{$role}{'font'} = 1;
5196: }
5197: } else {
5198: if ($confhash->{$role}{'font'}) {
5199: $changes{$role}{'font'} = 1;
5200: }
5201: }
1.107 raeburn 5202: if ($role ne 'login') {
5203: if ($domconfig->{$role}{'fontmenu'} ne '') {
5204: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5205: $changes{$role}{'fontmenu'} = 1;
5206: }
5207: } else {
5208: if ($confhash->{$role}{'fontmenu'}) {
5209: $changes{$role}{'fontmenu'} = 1;
5210: }
1.97 tempelho 5211: }
5212: }
1.6 raeburn 5213: foreach my $item (@bgs) {
5214: if ($domconfig->{$role}{$item} ne '') {
5215: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5216: $changes{$role}{'bgs'}{$item} = 1;
5217: }
5218: } else {
5219: if ($confhash->{$role}{$item}) {
5220: $changes{$role}{'bgs'}{$item} = 1;
5221: }
5222: }
5223: }
5224: foreach my $item (@links) {
5225: if ($domconfig->{$role}{$item} ne '') {
5226: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5227: $changes{$role}{'links'}{$item} = 1;
5228: }
5229: } else {
5230: if ($confhash->{$role}{$item}) {
5231: $changes{$role}{'links'}{$item} = 1;
5232: }
5233: }
5234: }
1.41 raeburn 5235: foreach my $item (@logintext) {
5236: if ($domconfig->{$role}{$item} ne '') {
5237: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5238: $changes{$role}{'logintext'}{$item} = 1;
5239: }
5240: } else {
5241: if ($confhash->{$role}{$item}) {
5242: $changes{$role}{'logintext'}{$item} = 1;
5243: }
5244: }
5245: }
1.6 raeburn 5246: } else {
5247: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5248: \@logintext,$confhash,\%changes);
1.6 raeburn 5249: }
5250: } else {
5251: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5252: \@logintext,$confhash,\%changes);
1.6 raeburn 5253: }
5254: }
5255: return ($errors,%changes);
5256: }
5257:
1.46 raeburn 5258: sub config_check {
5259: my ($dom,$confname,$servadm) = @_;
5260: my ($configuserok,$author_ok,$switchserver,%currroles);
5261: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5262: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5263: $confname,$servadm);
5264: if ($configuserok eq 'ok') {
5265: $switchserver = &check_switchserver($dom,$confname);
5266: if ($switchserver eq '') {
5267: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5268: }
5269: }
5270: return ($configuserok,$author_ok,$switchserver);
5271: }
5272:
1.6 raeburn 5273: sub default_change_checker {
1.41 raeburn 5274: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5275: foreach my $item (@{$links}) {
5276: if ($confhash->{$role}{$item}) {
5277: $changes->{$role}{'links'}{$item} = 1;
5278: }
5279: }
5280: foreach my $item (@{$bgs}) {
5281: if ($confhash->{$role}{$item}) {
5282: $changes->{$role}{'bgs'}{$item} = 1;
5283: }
5284: }
1.41 raeburn 5285: foreach my $item (@{$logintext}) {
5286: if ($confhash->{$role}{$item}) {
5287: $changes->{$role}{'logintext'}{$item} = 1;
5288: }
5289: }
1.6 raeburn 5290: foreach my $img (@{$images}) {
5291: if ($env{'form.'.$role.'_del_'.$img}) {
5292: $confhash->{$role}{$img} = '';
1.12 raeburn 5293: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5294: }
1.70 raeburn 5295: if ($role eq 'login') {
5296: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5297: $changes->{$role}{'showlogo'}{$img} = 1;
5298: }
5299: }
1.6 raeburn 5300: }
5301: if ($confhash->{$role}{'font'}) {
5302: $changes->{$role}{'font'} = 1;
5303: }
1.48 raeburn 5304: }
1.6 raeburn 5305:
5306: sub display_colorchgs {
5307: my ($dom,$changes,$roles,$confhash) = @_;
5308: my (%choices,$resulttext);
5309: if (!grep(/^login$/,@{$roles})) {
5310: $resulttext = &mt('Changes made:').'<br />';
5311: }
5312: foreach my $role (@{$roles}) {
5313: if ($role eq 'login') {
5314: %choices = &login_choices();
5315: } else {
5316: %choices = &color_font_choices();
5317: }
5318: if (ref($changes->{$role}) eq 'HASH') {
5319: if ($role ne 'login') {
5320: $resulttext .= '<h4>'.&mt($role).'</h4>';
5321: }
5322: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5323: if ($role ne 'login') {
5324: $resulttext .= '<ul>';
5325: }
5326: if (ref($changes->{$role}{$key}) eq 'HASH') {
5327: if ($role ne 'login') {
5328: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5329: }
5330: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5331: if (($role eq 'login') && ($key eq 'showlogo')) {
5332: if ($confhash->{$role}{$key}{$item}) {
5333: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5334: } else {
5335: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5336: }
5337: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5338: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5339: } else {
1.12 raeburn 5340: my $newitem = $confhash->{$role}{$item};
5341: if ($key eq 'images') {
5342: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5343: }
5344: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5345: }
5346: }
5347: if ($role ne 'login') {
5348: $resulttext .= '</ul></li>';
5349: }
5350: } else {
5351: if ($confhash->{$role}{$key} eq '') {
5352: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5353: } else {
5354: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5355: }
5356: }
5357: if ($role ne 'login') {
5358: $resulttext .= '</ul>';
5359: }
5360: }
5361: }
5362: }
1.3 raeburn 5363: return $resulttext;
1.1 raeburn 5364: }
5365:
1.9 raeburn 5366: sub thumb_dimensions {
5367: return ('200','50');
5368: }
5369:
1.16 raeburn 5370: sub check_dimensions {
5371: my ($inputfile) = @_;
5372: my ($fullwidth,$fullheight);
5373: if ($inputfile =~ m|^[/\w.\-]+$|) {
5374: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5375: my $imageinfo = <PIPE>;
5376: if (!close(PIPE)) {
5377: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5378: }
5379: chomp($imageinfo);
5380: my ($fullsize) =
1.21 raeburn 5381: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5382: if ($fullsize) {
5383: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5384: }
5385: }
5386: }
5387: return ($fullwidth,$fullheight);
5388: }
5389:
1.9 raeburn 5390: sub check_configuser {
5391: my ($uhome,$dom,$confname,$servadm) = @_;
5392: my ($configuserok,%currroles);
5393: if ($uhome eq 'no_host') {
5394: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5395: my $configpass = &LONCAPA::Enrollment::create_password();
5396: $configuserok =
5397: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5398: $configpass,'','','','','',undef,$servadm);
5399: } else {
5400: $configuserok = 'ok';
5401: %currroles =
5402: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5403: }
5404: return ($configuserok,%currroles);
5405: }
5406:
5407: sub check_authorstatus {
5408: my ($dom,$confname,%currroles) = @_;
5409: my $author_ok;
1.40 raeburn 5410: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5411: my $start = time;
5412: my $end = 0;
5413: $author_ok =
5414: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5415: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5416: } else {
5417: $author_ok = 'ok';
5418: }
5419: return $author_ok;
5420: }
5421:
5422: sub publishlogo {
1.46 raeburn 5423: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5424: my ($output,$fname,$logourl);
5425: if ($action eq 'upload') {
5426: $fname=$env{'form.'.$formname.'.filename'};
5427: chop($env{'form.'.$formname});
5428: } else {
5429: ($fname) = ($formname =~ /([^\/]+)$/);
5430: }
1.46 raeburn 5431: if ($savefileas ne '') {
5432: $fname = $savefileas;
5433: }
1.9 raeburn 5434: $fname=&Apache::lonnet::clean_filename($fname);
5435: # See if there is anything left
5436: unless ($fname) { return ('error: no uploaded file'); }
5437: $fname="$subdir/$fname";
1.164 raeburn 5438: my $docroot=$r->dir_config('lonDocRoot');
5439: my $filepath="$docroot/priv";
5440: my $relpath = "$dom/$confname";
1.9 raeburn 5441: my ($fnamepath,$file,$fetchthumb);
5442: $file=$fname;
5443: if ($fname=~m|/|) {
5444: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5445: }
1.164 raeburn 5446: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5447: my $count;
1.164 raeburn 5448: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5449: $filepath.="/$parts[$count]";
5450: if ((-e $filepath)!=1) {
5451: mkdir($filepath,02770);
5452: }
5453: }
5454: # Check for bad extension and disallow upload
5455: if ($file=~/\.(\w+)$/ &&
5456: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5457: $output =
5458: &mt('Invalid file extension ([_1]) - reserved for LONCAPA use.',$1);
5459: } elsif ($file=~/\.(\w+)$/ &&
5460: !defined(&Apache::loncommon::fileembstyle($1))) {
5461: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5462: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.46 raeburn 5463: $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 5464: } elsif (-d "$filepath/$file") {
5465: $output = &mt('File name is a directory name - rename the file and re-upload');
5466: } else {
5467: my $source = $filepath.'/'.$file;
5468: my $logfile;
5469: if (!open($logfile,">>$source".'.log')) {
5470: return (&mt('No write permission to Construction Space'));
5471: }
5472: print $logfile
5473: "\n================= Publish ".localtime()." ================\n".
5474: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5475: # Save the file
5476: if (!open(FH,'>'.$source)) {
5477: &Apache::lonnet::logthis('Failed to create '.$source);
5478: return (&mt('Failed to create file'));
5479: }
5480: if ($action eq 'upload') {
5481: if (!print FH ($env{'form.'.$formname})) {
5482: &Apache::lonnet::logthis('Failed to write to '.$source);
5483: return (&mt('Failed to write file'));
5484: }
5485: } else {
5486: my $original = &Apache::lonnet::filelocation('',$formname);
5487: if(!copy($original,$source)) {
5488: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5489: return (&mt('Failed to write file'));
5490: }
5491: }
5492: close(FH);
5493: chmod(0660, $source); # Permissions to rw-rw---.
5494:
5495: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5496: my $copyfile=$targetdir.'/'.$file;
5497:
5498: my @parts=split(/\//,$targetdir);
5499: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5500: for (my $count=5;$count<=$#parts;$count++) {
5501: $path.="/$parts[$count]";
5502: if (!-e $path) {
5503: print $logfile "\nCreating directory ".$path;
5504: mkdir($path,02770);
5505: }
5506: }
5507: my $versionresult;
5508: if (-e $copyfile) {
5509: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5510: } else {
5511: $versionresult = 'ok';
5512: }
5513: if ($versionresult eq 'ok') {
5514: if (copy($source,$copyfile)) {
5515: print $logfile "\nCopied original source to ".$copyfile."\n";
5516: $output = 'ok';
5517: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5518: push(@{$modified_urls},[$copyfile,$source]);
5519: my $metaoutput =
5520: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5521: unless ($registered_cleanup) {
5522: my $handlers = $r->get_handlers('PerlCleanupHandler');
5523: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5524: $registered_cleanup=1;
5525: }
1.9 raeburn 5526: } else {
5527: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5528: $output = &mt('Failed to copy file to RES space').", $!";
5529: }
5530: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5531: my $inputfile = $filepath.'/'.$file;
5532: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5533: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5534: if ($fullwidth ne '' && $fullheight ne '') {
5535: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5536: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5537: system("convert -sample $thumbsize $inputfile $outfile");
5538: chmod(0660, $filepath.'/tn-'.$file);
5539: if (-e $outfile) {
5540: my $copyfile=$targetdir.'/tn-'.$file;
5541: if (copy($outfile,$copyfile)) {
5542: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5543: my $thumb_metaoutput =
5544: &write_metadata($dom,$confname,$formname,
5545: $targetdir,'tn-'.$file,$logfile);
5546: push(@{$modified_urls},[$copyfile,$outfile]);
5547: unless ($registered_cleanup) {
5548: my $handlers = $r->get_handlers('PerlCleanupHandler');
5549: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5550: $registered_cleanup=1;
5551: }
1.16 raeburn 5552: } else {
5553: print $logfile "\nUnable to write ".$copyfile.
5554: ':'.$!."\n";
5555: }
5556: }
1.9 raeburn 5557: }
5558: }
5559: }
5560: } else {
5561: $output = $versionresult;
5562: }
5563: }
5564: return ($output,$logourl);
5565: }
5566:
5567: sub logo_versioning {
5568: my ($targetdir,$file,$logfile) = @_;
5569: my $target = $targetdir.'/'.$file;
5570: my ($maxversion,$fn,$extn,$output);
5571: $maxversion = 0;
5572: if ($file =~ /^(.+)\.(\w+)$/) {
5573: $fn=$1;
5574: $extn=$2;
5575: }
5576: opendir(DIR,$targetdir);
5577: while (my $filename=readdir(DIR)) {
5578: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5579: $maxversion=($1>$maxversion)?$1:$maxversion;
5580: }
5581: }
5582: $maxversion++;
5583: print $logfile "\nCreating old version ".$maxversion."\n";
5584: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5585: if (copy($target,$copyfile)) {
5586: print $logfile "Copied old target to ".$copyfile."\n";
5587: $copyfile=$copyfile.'.meta';
5588: if (copy($target.'.meta',$copyfile)) {
5589: print $logfile "Copied old target metadata to ".$copyfile."\n";
5590: $output = 'ok';
5591: } else {
5592: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5593: $output = &mt('Failed to copy old meta').", $!, ";
5594: }
5595: } else {
5596: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5597: $output = &mt('Failed to copy old target').", $!, ";
5598: }
5599: return $output;
5600: }
5601:
5602: sub write_metadata {
5603: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5604: my (%metadatafields,%metadatakeys,$output);
5605: $metadatafields{'title'}=$formname;
5606: $metadatafields{'creationdate'}=time;
5607: $metadatafields{'lastrevisiondate'}=time;
5608: $metadatafields{'copyright'}='public';
5609: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5610: $env{'user.domain'};
5611: $metadatafields{'authorspace'}=$confname.':'.$dom;
5612: $metadatafields{'domain'}=$dom;
5613: {
5614: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5615: my $mfh;
1.155 raeburn 5616: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5617: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5618: unless ($_=~/\./) {
5619: my $unikey=$_;
5620: $unikey=~/^([A-Za-z]+)/;
5621: my $tag=$1;
5622: $tag=~tr/A-Z/a-z/;
5623: print $mfh "\n\<$tag";
5624: foreach (split(/\,/,$metadatakeys{$unikey})) {
5625: my $value=$metadatafields{$unikey.'.'.$_};
5626: $value=~s/\"/\'\'/g;
5627: print $mfh ' '.$_.'="'.$value.'"';
5628: }
5629: print $mfh '>'.
5630: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5631: .'</'.$tag.'>';
5632: }
5633: }
5634: $output = 'ok';
5635: print $logfile "\nWrote metadata";
5636: close($mfh);
5637: } else {
5638: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5639: $output = &mt('Could not write metadata');
5640: }
5641: }
1.155 raeburn 5642: return $output;
5643: }
5644:
5645: sub notifysubscribed {
5646: foreach my $targetsource (@{$modified_urls}){
5647: next unless (ref($targetsource) eq 'ARRAY');
5648: my ($target,$source)=@{$targetsource};
5649: if ($source ne '') {
5650: if (open(my $logfh,'>>'.$source.'.log')) {
5651: print $logfh "\nCleanup phase: Notifications\n";
5652: my @subscribed=&subscribed_hosts($target);
5653: foreach my $subhost (@subscribed) {
5654: print $logfh "\nNotifying host ".$subhost.':';
5655: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5656: print $logfh $reply;
5657: }
5658: my @subscribedmeta=&subscribed_hosts("$target.meta");
5659: foreach my $subhost (@subscribedmeta) {
5660: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5661: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5662: $subhost);
5663: print $logfh $reply;
5664: }
5665: print $logfh "\n============ Done ============\n";
1.160 raeburn 5666: close($logfh);
1.155 raeburn 5667: }
5668: }
5669: }
5670: return OK;
5671: }
5672:
5673: sub subscribed_hosts {
5674: my ($target) = @_;
5675: my @subscribed;
5676: if (open(my $fh,"<$target.subscription")) {
5677: while (my $subline=<$fh>) {
5678: if ($subline =~ /^($match_lonid):/) {
5679: my $host = $1;
5680: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5681: unless (grep(/^\Q$host\E$/,@subscribed)) {
5682: push(@subscribed,$host);
5683: }
5684: }
5685: }
5686: }
5687: }
5688: return @subscribed;
1.9 raeburn 5689: }
5690:
5691: sub check_switchserver {
5692: my ($dom,$confname) = @_;
5693: my ($allowed,$switchserver);
5694: my $home = &Apache::lonnet::homeserver($confname,$dom);
5695: if ($home eq 'no_host') {
5696: $home = &Apache::lonnet::domain($dom,'primary');
5697: }
5698: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5699: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5700: if (!$allowed) {
1.180 raeburn 5701: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5702: }
5703: return $switchserver;
5704: }
5705:
1.1 raeburn 5706: sub modify_quotas {
1.86 raeburn 5707: my ($dom,$action,%domconfig) = @_;
1.101 raeburn 5708: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5709: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5710: if ($action eq 'quotas') {
5711: $context = 'tools';
1.163 raeburn 5712: } else {
1.86 raeburn 5713: $context = $action;
5714: }
5715: if ($context eq 'requestcourses') {
1.98 raeburn 5716: @usertools = ('official','unofficial','community');
1.106 raeburn 5717: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5718: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5719: %titles = &courserequest_titles();
5720: $toolregexp = join('|',@usertools);
5721: %conditions = &courserequest_conditions();
1.163 raeburn 5722: } elsif ($context eq 'requestauthor') {
5723: @usertools = ('author');
5724: %titles = &authorrequest_titles();
1.86 raeburn 5725: } else {
1.162 raeburn 5726: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5727: %titles = &tool_titles();
1.86 raeburn 5728: }
1.72 raeburn 5729: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.44 raeburn 5730: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5731: foreach my $key (keys(%env)) {
1.101 raeburn 5732: if ($context eq 'requestcourses') {
5733: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5734: my $item = $1;
5735: my $type = $2;
5736: if ($type =~ /^limit_(.+)/) {
5737: $limithash{$item}{$1} = $env{$key};
5738: } else {
5739: $confhash{$item}{$type} = $env{$key};
5740: }
5741: }
1.163 raeburn 5742: } elsif ($context eq 'requestauthor') {
5743: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5744: $confhash{$1} = $env{$key};
5745: }
1.101 raeburn 5746: } else {
1.86 raeburn 5747: if ($key =~ /^form\.quota_(.+)$/) {
5748: $confhash{'defaultquota'}{$1} = $env{$key};
5749: }
1.101 raeburn 5750: if ($key =~ /^form\.\Q$context\E_(.+)$/) {
5751: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5752: }
1.72 raeburn 5753: }
5754: }
1.163 raeburn 5755: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5756: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5757: @approvalnotify = sort(@approvalnotify);
5758: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5759: if (ref($domconfig{$action}) eq 'HASH') {
5760: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5761: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5762: $changes{'notify'}{'approval'} = 1;
5763: }
5764: } else {
1.144 raeburn 5765: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5766: $changes{'notify'}{'approval'} = 1;
5767: }
5768: }
5769: } else {
1.144 raeburn 5770: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5771: $changes{'notify'}{'approval'} = 1;
5772: }
5773: }
5774: } else {
1.86 raeburn 5775: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
5776: }
1.72 raeburn 5777: foreach my $item (@usertools) {
5778: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5779: my $unset;
1.101 raeburn 5780: if ($context eq 'requestcourses') {
1.104 raeburn 5781: $unset = '0';
5782: if ($type eq '_LC_adv') {
5783: $unset = '';
5784: }
1.101 raeburn 5785: if ($confhash{$item}{$type} eq 'autolimit') {
5786: $confhash{$item}{$type} .= '=';
5787: unless ($limithash{$item}{$type} =~ /\D/) {
5788: $confhash{$item}{$type} .= $limithash{$item}{$type};
5789: }
5790: }
1.163 raeburn 5791: } elsif ($context eq 'requestauthor') {
5792: $unset = '0';
5793: if ($type eq '_LC_adv') {
5794: $unset = '';
5795: }
1.72 raeburn 5796: } else {
1.101 raeburn 5797: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5798: $confhash{$item}{$type} = 1;
5799: } else {
5800: $confhash{$item}{$type} = 0;
5801: }
1.72 raeburn 5802: }
1.86 raeburn 5803: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5804: if ($action eq 'requestauthor') {
5805: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5806: $changes{$type} = 1;
5807: }
5808: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5809: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5810: $changes{$item}{$type} = 1;
5811: }
5812: } else {
5813: if ($context eq 'requestcourses') {
1.104 raeburn 5814: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5815: $changes{$item}{$type} = 1;
5816: }
5817: } else {
5818: if (!$confhash{$item}{$type}) {
5819: $changes{$item}{$type} = 1;
5820: }
5821: }
5822: }
5823: } else {
5824: if ($context eq 'requestcourses') {
1.104 raeburn 5825: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5826: $changes{$item}{$type} = 1;
5827: }
1.163 raeburn 5828: } elsif ($context eq 'requestauthor') {
5829: if ($confhash{$type} ne $unset) {
5830: $changes{$type} = 1;
5831: }
1.72 raeburn 5832: } else {
5833: if (!$confhash{$item}{$type}) {
5834: $changes{$item}{$type} = 1;
5835: }
5836: }
5837: }
1.1 raeburn 5838: }
5839: }
1.163 raeburn 5840: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5841: if (ref($domconfig{'quotas'}) eq 'HASH') {
5842: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5843: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5844: if (exists($confhash{'defaultquota'}{$key})) {
5845: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5846: $changes{'defaultquota'}{$key} = 1;
5847: }
5848: } else {
5849: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5850: }
5851: }
1.86 raeburn 5852: } else {
5853: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5854: if (exists($confhash{'defaultquota'}{$key})) {
5855: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5856: $changes{'defaultquota'}{$key} = 1;
5857: }
5858: } else {
5859: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5860: }
1.1 raeburn 5861: }
5862: }
5863: }
1.86 raeburn 5864: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5865: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5866: if (ref($domconfig{'quotas'}) eq 'HASH') {
5867: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5868: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
5869: $changes{'defaultquota'}{$key} = 1;
5870: }
5871: } else {
5872: if (!exists($domconfig{'quotas'}{$key})) {
5873: $changes{'defaultquota'}{$key} = 1;
5874: }
1.72 raeburn 5875: }
5876: } else {
1.86 raeburn 5877: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 5878: }
1.1 raeburn 5879: }
5880: }
5881: }
1.72 raeburn 5882:
1.163 raeburn 5883: if ($context eq 'requestauthor') {
5884: $domdefaults{'requestauthor'} = \%confhash;
5885: } else {
5886: foreach my $key (keys(%confhash)) {
5887: $domdefaults{$key} = $confhash{$key};
5888: }
1.72 raeburn 5889: }
1.163 raeburn 5890:
1.1 raeburn 5891: my %quotahash = (
1.86 raeburn 5892: $action => { %confhash }
1.1 raeburn 5893: );
5894: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
5895: $dom);
5896: if ($putresult eq 'ok') {
5897: if (keys(%changes) > 0) {
1.72 raeburn 5898: my $cachetime = 24*60*60;
5899: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
5900:
1.1 raeburn 5901: $resulttext = &mt('Changes made:').'<ul>';
1.163 raeburn 5902: unless (($context eq 'requestcourses') ||
5903: ($context eq 'requestauthor')) {
1.86 raeburn 5904: if (ref($changes{'defaultquota'}) eq 'HASH') {
5905: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
5906: foreach my $type (@{$types},'default') {
5907: if (defined($changes{'defaultquota'}{$type})) {
5908: my $typetitle = $usertypes->{$type};
5909: if ($type eq 'default') {
5910: $typetitle = $othertitle;
5911: }
5912: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 5913: }
5914: }
1.86 raeburn 5915: $resulttext .= '</ul></li>';
1.72 raeburn 5916: }
5917: }
1.80 raeburn 5918: my %newenv;
1.72 raeburn 5919: foreach my $item (@usertools) {
1.163 raeburn 5920: my (%haschgs,%inconf);
5921: if ($context eq 'requestauthor') {
5922: %haschgs = %changes;
5923: %inconf = %confhash;
5924: } else {
5925: if (ref($changes{$item}) eq 'HASH') {
5926: %haschgs = %{$changes{$item}};
5927: }
5928: if (ref($confhash{$item}) eq 'HASH') {
5929: %inconf = %{$confhash{$item}};
5930: }
5931: }
5932: if (keys(%haschgs) > 0) {
1.80 raeburn 5933: my $newacc =
5934: &Apache::lonnet::usertools_access($env{'user.name'},
5935: $env{'user.domain'},
1.86 raeburn 5936: $item,'reload',$context);
1.163 raeburn 5937: if (($context eq 'requestcourses') ||
5938: ($context eq 'requestauthor')) {
1.108 raeburn 5939: if ($env{'environment.canrequest.'.$item} ne $newacc) {
5940: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 5941: }
5942: } else {
5943: if ($env{'environment.availabletools.'.$item} ne $newacc) {
5944: $newenv{'environment.availabletools.'.$item} = $newacc;
5945: }
1.80 raeburn 5946: }
1.163 raeburn 5947: unless ($context eq 'requestauthor') {
5948: $resulttext .= '<li>'.$titles{$item}.'<ul>';
5949: }
1.72 raeburn 5950: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 5951: if ($haschgs{$type}) {
1.72 raeburn 5952: my $typetitle = $usertypes->{$type};
5953: if ($type eq 'default') {
5954: $typetitle = $othertitle;
5955: } elsif ($type eq '_LC_adv') {
5956: $typetitle = 'LON-CAPA Advanced Users';
5957: }
1.163 raeburn 5958: if ($inconf{$type}) {
1.101 raeburn 5959: if ($context eq 'requestcourses') {
5960: my $cond;
1.163 raeburn 5961: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 5962: if ($1 eq '') {
5963: $cond = &mt('(Automatic processing of any request).');
5964: } else {
5965: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
5966: }
5967: } else {
1.163 raeburn 5968: $cond = $conditions{$inconf{$type}};
1.101 raeburn 5969: }
5970: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 5971: } elsif ($context eq 'requestauthor') {
5972: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
5973: $titles{$inconf{$type}},$typetitle);
5974:
1.101 raeburn 5975: } else {
5976: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
5977: }
1.72 raeburn 5978: } else {
1.104 raeburn 5979: if ($type eq '_LC_adv') {
1.163 raeburn 5980: if ($inconf{$type} eq '0') {
1.104 raeburn 5981: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5982: } else {
5983: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
5984: }
5985: } else {
5986: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
5987: }
1.72 raeburn 5988: }
5989: }
1.26 raeburn 5990: }
1.163 raeburn 5991: unless ($context eq 'requestauthor') {
5992: $resulttext .= '</ul></li>';
5993: }
1.26 raeburn 5994: }
1.1 raeburn 5995: }
1.163 raeburn 5996: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 5997: if (ref($changes{'notify'}) eq 'HASH') {
5998: if ($changes{'notify'}{'approval'}) {
5999: if (ref($confhash{'notify'}) eq 'HASH') {
6000: if ($confhash{'notify'}{'approval'}) {
6001: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6002: } else {
1.163 raeburn 6003: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6004: }
6005: }
6006: }
6007: }
6008: }
1.1 raeburn 6009: $resulttext .= '</ul>';
1.80 raeburn 6010: if (keys(%newenv)) {
6011: &Apache::lonnet::appenv(\%newenv);
6012: }
1.1 raeburn 6013: } else {
1.86 raeburn 6014: if ($context eq 'requestcourses') {
6015: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6016: } elsif ($context eq 'requestauthor') {
6017: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6018: } else {
1.90 weissno 6019: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6020: }
1.1 raeburn 6021: }
6022: } else {
1.11 albertel 6023: $resulttext = '<span class="LC_error">'.
6024: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6025: }
1.3 raeburn 6026: return $resulttext;
1.1 raeburn 6027: }
6028:
1.3 raeburn 6029: sub modify_autoenroll {
6030: my ($dom,%domconfig) = @_;
1.1 raeburn 6031: my ($resulttext,%changes);
6032: my %currautoenroll;
6033: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6034: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6035: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6036: }
6037: }
6038: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6039: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6040: sender => 'Sender for notification messages',
6041: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6042: my @offon = ('off','on');
1.17 raeburn 6043: my $sender_uname = $env{'form.sender_uname'};
6044: my $sender_domain = $env{'form.sender_domain'};
6045: if ($sender_domain eq '') {
6046: $sender_uname = '';
6047: } elsif ($sender_uname eq '') {
6048: $sender_domain = '';
6049: }
1.129 raeburn 6050: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6051: my %autoenrollhash = (
1.129 raeburn 6052: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6053: 'sender_uname' => $sender_uname,
6054: 'sender_domain' => $sender_domain,
6055: 'co-owners' => $coowners,
1.1 raeburn 6056: }
6057: );
1.4 raeburn 6058: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6059: $dom);
1.1 raeburn 6060: if ($putresult eq 'ok') {
6061: if (exists($currautoenroll{'run'})) {
6062: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6063: $changes{'run'} = 1;
6064: }
6065: } elsif ($autorun) {
6066: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6067: $changes{'run'} = 1;
1.1 raeburn 6068: }
6069: }
1.17 raeburn 6070: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6071: $changes{'sender'} = 1;
6072: }
1.17 raeburn 6073: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6074: $changes{'sender'} = 1;
6075: }
1.129 raeburn 6076: if ($currautoenroll{'co-owners'} ne '') {
6077: if ($currautoenroll{'co-owners'} ne $coowners) {
6078: $changes{'coowners'} = 1;
6079: }
6080: } elsif ($coowners) {
6081: $changes{'coowners'} = 1;
6082: }
1.1 raeburn 6083: if (keys(%changes) > 0) {
6084: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6085: if ($changes{'run'}) {
1.1 raeburn 6086: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6087: }
6088: if ($changes{'sender'}) {
1.17 raeburn 6089: if ($sender_uname eq '' || $sender_domain eq '') {
6090: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6091: } else {
6092: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6093: }
1.1 raeburn 6094: }
1.129 raeburn 6095: if ($changes{'coowners'}) {
6096: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6097: &Apache::loncommon::devalidate_domconfig_cache($dom);
6098: }
1.1 raeburn 6099: $resulttext .= '</ul>';
6100: } else {
6101: $resulttext = &mt('No changes made to auto-enrollment settings');
6102: }
6103: } else {
1.11 albertel 6104: $resulttext = '<span class="LC_error">'.
6105: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6106: }
1.3 raeburn 6107: return $resulttext;
1.1 raeburn 6108: }
6109:
6110: sub modify_autoupdate {
1.3 raeburn 6111: my ($dom,%domconfig) = @_;
1.1 raeburn 6112: my ($resulttext,%currautoupdate,%fields,%changes);
6113: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6114: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6115: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6116: }
6117: }
6118: my @offon = ('off','on');
6119: my %title = &Apache::lonlocal::texthash (
6120: run => 'Auto-update:',
6121: classlists => 'Updates to user information in classlists?'
6122: );
1.44 raeburn 6123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6124: my %fieldtitles = &Apache::lonlocal::texthash (
6125: id => 'Student/Employee ID',
1.20 raeburn 6126: permanentemail => 'E-mail address',
1.1 raeburn 6127: lastname => 'Last Name',
6128: firstname => 'First Name',
6129: middlename => 'Middle Name',
1.132 raeburn 6130: generation => 'Generation',
1.1 raeburn 6131: );
1.142 raeburn 6132: $othertitle = &mt('All users');
1.1 raeburn 6133: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6134: $othertitle = &mt('Other users');
1.1 raeburn 6135: }
6136: foreach my $key (keys(%env)) {
6137: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6138: my ($usertype,$item) = ($1,$2);
6139: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6140: if ($usertype eq 'default') {
6141: push(@{$fields{$1}},$2);
6142: } elsif (ref($types) eq 'ARRAY') {
6143: if (grep(/^\Q$usertype\E$/,@{$types})) {
6144: push(@{$fields{$1}},$2);
6145: }
6146: }
6147: }
1.1 raeburn 6148: }
6149: }
1.131 raeburn 6150: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6151: @lockablenames = sort(@lockablenames);
6152: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6153: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6154: if (@changed) {
6155: $changes{'lockablenames'} = 1;
6156: }
6157: } else {
6158: if (@lockablenames) {
6159: $changes{'lockablenames'} = 1;
6160: }
6161: }
1.1 raeburn 6162: my %updatehash = (
6163: autoupdate => { run => $env{'form.autoupdate_run'},
6164: classlists => $env{'form.classlists'},
6165: fields => {%fields},
1.131 raeburn 6166: lockablenames => \@lockablenames,
1.1 raeburn 6167: }
6168: );
6169: foreach my $key (keys(%currautoupdate)) {
6170: if (($key eq 'run') || ($key eq 'classlists')) {
6171: if (exists($updatehash{autoupdate}{$key})) {
6172: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6173: $changes{$key} = 1;
6174: }
6175: }
6176: } elsif ($key eq 'fields') {
6177: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6178: foreach my $item (@{$types},'default') {
1.1 raeburn 6179: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6180: my $change = 0;
6181: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6182: if (!exists($fields{$item})) {
6183: $change = 1;
1.132 raeburn 6184: last;
1.1 raeburn 6185: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6186: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6187: $change = 1;
1.132 raeburn 6188: last;
1.1 raeburn 6189: }
6190: }
6191: }
6192: if ($change) {
6193: push(@{$changes{$key}},$item);
6194: }
1.26 raeburn 6195: }
1.1 raeburn 6196: }
6197: }
1.131 raeburn 6198: } elsif ($key eq 'lockablenames') {
6199: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6200: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6201: if (@changed) {
6202: $changes{'lockablenames'} = 1;
6203: }
6204: } else {
6205: if (@lockablenames) {
6206: $changes{'lockablenames'} = 1;
6207: }
6208: }
6209: }
6210: }
6211: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6212: if (@lockablenames) {
6213: $changes{'lockablenames'} = 1;
1.1 raeburn 6214: }
6215: }
1.26 raeburn 6216: foreach my $item (@{$types},'default') {
6217: if (defined($fields{$item})) {
6218: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6219: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6220: my $change = 0;
6221: if (ref($fields{$item}) eq 'ARRAY') {
6222: foreach my $type (@{$fields{$item}}) {
6223: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6224: $change = 1;
6225: last;
6226: }
6227: }
6228: }
6229: if ($change) {
6230: push(@{$changes{'fields'}},$item);
6231: }
6232: } else {
1.26 raeburn 6233: push(@{$changes{'fields'}},$item);
6234: }
6235: } else {
6236: push(@{$changes{'fields'}},$item);
1.1 raeburn 6237: }
6238: }
6239: }
6240: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6241: $dom);
6242: if ($putresult eq 'ok') {
6243: if (keys(%changes) > 0) {
6244: $resulttext = &mt('Changes made:').'<ul>';
6245: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6246: if ($key eq 'lockablenames') {
6247: $resulttext .= '<li>';
6248: if (@lockablenames) {
6249: $usertypes->{'default'} = $othertitle;
6250: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6251: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6252: } else {
6253: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6254: }
6255: $resulttext .= '</li>';
6256: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6257: foreach my $item (@{$changes{$key}}) {
6258: my @newvalues;
6259: foreach my $type (@{$fields{$item}}) {
6260: push(@newvalues,$fieldtitles{$type});
6261: }
1.3 raeburn 6262: my $newvaluestr;
6263: if (@newvalues > 0) {
6264: $newvaluestr = join(', ',@newvalues);
6265: } else {
6266: $newvaluestr = &mt('none');
1.6 raeburn 6267: }
1.1 raeburn 6268: if ($item eq 'default') {
1.26 raeburn 6269: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6270: } else {
1.26 raeburn 6271: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6272: }
6273: }
6274: } else {
6275: my $newvalue;
6276: if ($key eq 'run') {
6277: $newvalue = $offon[$env{'form.autoupdate_run'}];
6278: } else {
6279: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6280: }
1.1 raeburn 6281: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6282: }
6283: }
6284: $resulttext .= '</ul>';
6285: } else {
1.3 raeburn 6286: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6287: }
6288: } else {
1.11 albertel 6289: $resulttext = '<span class="LC_error">'.
6290: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6291: }
1.3 raeburn 6292: return $resulttext;
1.1 raeburn 6293: }
6294:
1.125 raeburn 6295: sub modify_autocreate {
6296: my ($dom,%domconfig) = @_;
6297: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6298: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6299: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6300: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6301: }
6302: }
6303: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6304: req => 'Auto-creation of validated requests for official courses',
6305: xmldc => 'Identity of course creator of courses from XML files',
6306: );
6307: my @types = ('xml','req');
6308: foreach my $item (@types) {
6309: $newvals{$item} = $env{'form.autocreate_'.$item};
6310: $newvals{$item} =~ s/\D//g;
6311: $newvals{$item} = 0 if ($newvals{$item} eq '');
6312: }
6313: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6314: my %domcoords = &get_active_dcs($dom);
6315: unless (exists($domcoords{$newvals{'xmldc'}})) {
6316: $newvals{'xmldc'} = '';
6317: }
6318: %autocreatehash = (
6319: autocreate => { xml => $newvals{'xml'},
6320: req => $newvals{'req'},
6321: }
6322: );
6323: if ($newvals{'xmldc'} ne '') {
6324: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6325: }
6326: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6327: $dom);
6328: if ($putresult eq 'ok') {
6329: my @items = @types;
6330: if ($newvals{'xml'}) {
6331: push(@items,'xmldc');
6332: }
6333: foreach my $item (@items) {
6334: if (exists($currautocreate{$item})) {
6335: if ($currautocreate{$item} ne $newvals{$item}) {
6336: $changes{$item} = 1;
6337: }
6338: } elsif ($newvals{$item}) {
6339: $changes{$item} = 1;
6340: }
6341: }
6342: if (keys(%changes) > 0) {
6343: my @offon = ('off','on');
6344: $resulttext = &mt('Changes made:').'<ul>';
6345: foreach my $item (@types) {
6346: if ($changes{$item}) {
6347: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6348: $resulttext .= '<li>'.
6349: &mt("$title{$item} set to [_1]$newtxt [_2]",
6350: '<b>','</b>').
6351: '</li>';
1.125 raeburn 6352: }
6353: }
6354: if ($changes{'xmldc'}) {
6355: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6356: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6357: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6358: }
6359: $resulttext .= '</ul>';
6360: } else {
6361: $resulttext = &mt('No changes made to auto-creation settings');
6362: }
6363: } else {
6364: $resulttext = '<span class="LC_error">'.
6365: &mt('An error occurred: [_1]',$putresult).'</span>';
6366: }
6367: return $resulttext;
6368: }
6369:
1.23 raeburn 6370: sub modify_directorysrch {
6371: my ($dom,%domconfig) = @_;
6372: my ($resulttext,%changes);
6373: my %currdirsrch;
6374: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6375: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6376: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6377: }
6378: }
6379: my %title = ( available => 'Directory search available',
1.24 raeburn 6380: localonly => 'Other domains can search',
1.23 raeburn 6381: searchby => 'Search types',
6382: searchtypes => 'Search latitude');
6383: my @offon = ('off','on');
1.24 raeburn 6384: my @otherdoms = ('Yes','No');
1.23 raeburn 6385:
1.25 raeburn 6386: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6387: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6388: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6389:
1.44 raeburn 6390: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6391: if (keys(%{$usertypes}) == 0) {
6392: @cansearch = ('default');
6393: } else {
6394: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6395: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6396: if (!grep(/^\Q$type\E$/,@cansearch)) {
6397: push(@{$changes{'cansearch'}},$type);
6398: }
1.23 raeburn 6399: }
1.26 raeburn 6400: foreach my $type (@cansearch) {
6401: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6402: push(@{$changes{'cansearch'}},$type);
6403: }
1.23 raeburn 6404: }
1.26 raeburn 6405: } else {
6406: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6407: }
6408: }
6409:
6410: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6411: foreach my $by (@{$currdirsrch{'searchby'}}) {
6412: if (!grep(/^\Q$by\E$/,@searchby)) {
6413: push(@{$changes{'searchby'}},$by);
6414: }
6415: }
6416: foreach my $by (@searchby) {
6417: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6418: push(@{$changes{'searchby'}},$by);
6419: }
6420: }
6421: } else {
6422: push(@{$changes{'searchby'}},@searchby);
6423: }
1.25 raeburn 6424:
6425: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6426: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6427: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6428: push(@{$changes{'searchtypes'}},$type);
6429: }
6430: }
6431: foreach my $type (@searchtypes) {
6432: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6433: push(@{$changes{'searchtypes'}},$type);
6434: }
6435: }
6436: } else {
6437: if (exists($currdirsrch{'searchtypes'})) {
6438: foreach my $type (@searchtypes) {
6439: if ($type ne $currdirsrch{'searchtypes'}) {
6440: push(@{$changes{'searchtypes'}},$type);
6441: }
6442: }
6443: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6444: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6445: }
6446: } else {
6447: push(@{$changes{'searchtypes'}},@searchtypes);
6448: }
6449: }
6450:
1.23 raeburn 6451: my %dirsrch_hash = (
6452: directorysrch => { available => $env{'form.dirsrch_available'},
6453: cansearch => \@cansearch,
1.24 raeburn 6454: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6455: searchby => \@searchby,
1.25 raeburn 6456: searchtypes => \@searchtypes,
1.23 raeburn 6457: }
6458: );
6459: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6460: $dom);
6461: if ($putresult eq 'ok') {
6462: if (exists($currdirsrch{'available'})) {
6463: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6464: $changes{'available'} = 1;
6465: }
6466: } else {
6467: if ($env{'form.dirsrch_available'} eq '1') {
6468: $changes{'available'} = 1;
6469: }
6470: }
1.24 raeburn 6471: if (exists($currdirsrch{'localonly'})) {
6472: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6473: $changes{'localonly'} = 1;
6474: }
6475: } else {
6476: if ($env{'form.dirsrch_localonly'} eq '1') {
6477: $changes{'localonly'} = 1;
6478: }
6479: }
1.23 raeburn 6480: if (keys(%changes) > 0) {
6481: $resulttext = &mt('Changes made:').'<ul>';
6482: if ($changes{'available'}) {
6483: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6484: }
1.24 raeburn 6485: if ($changes{'localonly'}) {
6486: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6487: }
6488:
1.23 raeburn 6489: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6490: my $chgtext;
1.26 raeburn 6491: if (ref($usertypes) eq 'HASH') {
6492: if (keys(%{$usertypes}) > 0) {
6493: foreach my $type (@{$types}) {
6494: if (grep(/^\Q$type\E$/,@cansearch)) {
6495: $chgtext .= $usertypes->{$type}.'; ';
6496: }
6497: }
6498: if (grep(/^default$/,@cansearch)) {
6499: $chgtext .= $othertitle;
6500: } else {
6501: $chgtext =~ s/\; $//;
6502: }
1.178 raeburn 6503: $resulttext .=
6504: '<li>'.
6505: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6506: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6507: '</li>';
1.23 raeburn 6508: }
6509: }
6510: }
6511: if (ref($changes{'searchby'}) eq 'ARRAY') {
6512: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6513: my $chgtext;
6514: foreach my $type (@{$titleorder}) {
6515: if (grep(/^\Q$type\E$/,@searchby)) {
6516: if (defined($searchtitles->{$type})) {
6517: $chgtext .= $searchtitles->{$type}.'; ';
6518: }
6519: }
6520: }
6521: $chgtext =~ s/\; $//;
6522: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6523: }
1.25 raeburn 6524: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6525: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6526: my $chgtext;
6527: foreach my $type (@{$srchtypeorder}) {
6528: if (grep(/^\Q$type\E$/,@searchtypes)) {
6529: if (defined($srchtypes_desc->{$type})) {
6530: $chgtext .= $srchtypes_desc->{$type}.'; ';
6531: }
6532: }
6533: }
6534: $chgtext =~ s/\; $//;
1.178 raeburn 6535: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6536: }
6537: $resulttext .= '</ul>';
6538: } else {
6539: $resulttext = &mt('No changes made to institution directory search settings');
6540: }
6541: } else {
6542: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6543: &mt('An error occurred: [_1]',$putresult).'</span>';
6544: }
6545: return $resulttext;
6546: }
6547:
1.28 raeburn 6548: sub modify_contacts {
6549: my ($dom,%domconfig) = @_;
6550: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6551: if (ref($domconfig{'contacts'}) eq 'HASH') {
6552: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6553: $currsetting{$key} = $domconfig{'contacts'}{$key};
6554: }
6555: }
1.134 raeburn 6556: my (%others,%to,%bcc);
1.28 raeburn 6557: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6558: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
6559: 'requestsmail');
1.28 raeburn 6560: foreach my $type (@mailings) {
6561: @{$newsetting{$type}} =
6562: &Apache::loncommon::get_env_multiple('form.'.$type);
6563: foreach my $item (@contacts) {
6564: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6565: $contacts_hash{contacts}{$type}{$item} = 1;
6566: } else {
6567: $contacts_hash{contacts}{$type}{$item} = 0;
6568: }
6569: }
6570: $others{$type} = $env{'form.'.$type.'_others'};
6571: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6572: if ($type eq 'helpdeskmail') {
6573: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6574: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6575: }
1.28 raeburn 6576: }
6577: foreach my $item (@contacts) {
6578: $to{$item} = $env{'form.'.$item};
6579: $contacts_hash{'contacts'}{$item} = $to{$item};
6580: }
6581: if (keys(%currsetting) > 0) {
6582: foreach my $item (@contacts) {
6583: if ($to{$item} ne $currsetting{$item}) {
6584: $changes{$item} = 1;
6585: }
6586: }
6587: foreach my $type (@mailings) {
6588: foreach my $item (@contacts) {
6589: if (ref($currsetting{$type}) eq 'HASH') {
6590: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6591: push(@{$changes{$type}},$item);
6592: }
6593: } else {
6594: push(@{$changes{$type}},@{$newsetting{$type}});
6595: }
6596: }
6597: if ($others{$type} ne $currsetting{$type}{'others'}) {
6598: push(@{$changes{$type}},'others');
6599: }
1.134 raeburn 6600: if ($type eq 'helpdeskmail') {
6601: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6602: push(@{$changes{$type}},'bcc');
6603: }
6604: }
1.28 raeburn 6605: }
6606: } else {
6607: my %default;
6608: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6609: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6610: $default{'errormail'} = 'adminemail';
6611: $default{'packagesmail'} = 'adminemail';
6612: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6613: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6614: $default{'requestsmail'} = 'adminemail';
1.28 raeburn 6615: foreach my $item (@contacts) {
6616: if ($to{$item} ne $default{$item}) {
6617: $changes{$item} = 1;
6618: }
6619: }
6620: foreach my $type (@mailings) {
6621: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6622:
6623: push(@{$changes{$type}},@{$newsetting{$type}});
6624: }
6625: if ($others{$type} ne '') {
6626: push(@{$changes{$type}},'others');
1.134 raeburn 6627: }
6628: if ($type eq 'helpdeskmail') {
6629: if ($bcc{$type} ne '') {
6630: push(@{$changes{$type}},'bcc');
6631: }
6632: }
1.28 raeburn 6633: }
6634: }
6635: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6636: $dom);
6637: if ($putresult eq 'ok') {
6638: if (keys(%changes) > 0) {
6639: my ($titles,$short_titles) = &contact_titles();
6640: $resulttext = &mt('Changes made:').'<ul>';
6641: foreach my $item (@contacts) {
6642: if ($changes{$item}) {
6643: $resulttext .= '<li>'.$titles->{$item}.
6644: &mt(' set to: ').
6645: '<span class="LC_cusr_emph">'.
6646: $to{$item}.'</span></li>';
6647: }
6648: }
6649: foreach my $type (@mailings) {
6650: if (ref($changes{$type}) eq 'ARRAY') {
6651: $resulttext .= '<li>'.$titles->{$type}.': ';
6652: my @text;
6653: foreach my $item (@{$newsetting{$type}}) {
6654: push(@text,$short_titles->{$item});
6655: }
6656: if ($others{$type} ne '') {
6657: push(@text,$others{$type});
6658: }
6659: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6660: join(', ',@text).'</span>';
6661: if ($type eq 'helpdeskmail') {
6662: if ($bcc{$type} ne '') {
6663: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6664: }
6665: }
6666: $resulttext .= '</li>';
1.28 raeburn 6667: }
6668: }
6669: $resulttext .= '</ul>';
6670: } else {
1.34 raeburn 6671: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6672: }
6673: } else {
6674: $resulttext = '<span class="LC_error">'.
6675: &mt('An error occurred: [_1].',$putresult).'</span>';
6676: }
6677: return $resulttext;
6678: }
6679:
6680: sub modify_usercreation {
1.27 raeburn 6681: my ($dom,%domconfig) = @_;
1.34 raeburn 6682: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6683: my $warningmsg;
1.27 raeburn 6684: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6685: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6686: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6687: }
6688: }
6689: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6690: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6691: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6692: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6693: foreach my $item(@contexts) {
1.45 raeburn 6694: if ($item eq 'selfcreate') {
1.50 raeburn 6695: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.43 raeburn 6696: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
6697: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6698: if (ref($cancreate{$item}) eq 'ARRAY') {
6699: if (grep(/^login$/,@{$cancreate{$item}})) {
6700: $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.');
6701: }
1.43 raeburn 6702: }
6703: }
1.50 raeburn 6704: } else {
6705: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6706: }
1.34 raeburn 6707: }
1.93 raeburn 6708: my ($othertitle,$usertypes,$types) =
6709: &Apache::loncommon::sorted_inst_types($dom);
6710: if (ref($types) eq 'ARRAY') {
6711: if (@{$types} > 0) {
6712: @{$cancreate{'statustocreate'}} =
6713: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6714: } else {
6715: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6716: }
6717: push(@contexts,'statustocreate');
6718: }
1.165 raeburn 6719: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6720: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6721: foreach my $item (@contexts) {
1.93 raeburn 6722: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6723: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6724: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6725: if (ref($cancreate{$item}) eq 'ARRAY') {
6726: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6727: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6728: push(@{$changes{'cancreate'}},$item);
6729: }
1.50 raeburn 6730: }
6731: }
6732: }
6733: } else {
6734: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6735: if (@{$cancreate{$item}} > 0) {
6736: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6737: push(@{$changes{'cancreate'}},$item);
6738: }
6739: }
6740: } else {
6741: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6742: if (@{$cancreate{$item}} < 3) {
6743: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6744: push(@{$changes{'cancreate'}},$item);
6745: }
6746: }
6747: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6748: if (@{$cancreate{$item}} > 0) {
6749: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6750: push(@{$changes{'cancreate'}},$item);
6751: }
6752: }
6753: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6754: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6755: push(@{$changes{'cancreate'}},$item);
6756: }
6757: }
6758: }
6759: }
6760: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6761: foreach my $type (@{$cancreate{$item}}) {
6762: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6763: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6764: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6765: push(@{$changes{'cancreate'}},$item);
6766: }
6767: }
6768: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6769: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6770: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6771: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6772: push(@{$changes{'cancreate'}},$item);
6773: }
6774: }
6775: }
6776: }
6777: }
6778: } else {
6779: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6780: push(@{$changes{'cancreate'}},$item);
6781: }
6782: }
1.27 raeburn 6783: }
1.34 raeburn 6784: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6785: foreach my $item (@contexts) {
1.43 raeburn 6786: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6787: if ($cancreate{$item} ne 'any') {
6788: push(@{$changes{'cancreate'}},$item);
6789: }
6790: } else {
6791: if ($cancreate{$item} ne 'none') {
6792: push(@{$changes{'cancreate'}},$item);
6793: }
1.27 raeburn 6794: }
6795: }
6796: } else {
1.43 raeburn 6797: foreach my $item (@contexts) {
1.34 raeburn 6798: push(@{$changes{'cancreate'}},$item);
6799: }
1.27 raeburn 6800: }
1.34 raeburn 6801:
1.27 raeburn 6802: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
6803: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
6804: if (!grep(/^\Q$type\E$/,@username_rule)) {
6805: push(@{$changes{'username_rule'}},$type);
6806: }
6807: }
6808: foreach my $type (@username_rule) {
6809: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
6810: push(@{$changes{'username_rule'}},$type);
6811: }
6812: }
6813: } else {
6814: push(@{$changes{'username_rule'}},@username_rule);
6815: }
6816:
1.32 raeburn 6817: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
6818: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
6819: if (!grep(/^\Q$type\E$/,@id_rule)) {
6820: push(@{$changes{'id_rule'}},$type);
6821: }
6822: }
6823: foreach my $type (@id_rule) {
6824: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
6825: push(@{$changes{'id_rule'}},$type);
6826: }
6827: }
6828: } else {
6829: push(@{$changes{'id_rule'}},@id_rule);
6830: }
6831:
1.43 raeburn 6832: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
6833: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
6834: if (!grep(/^\Q$type\E$/,@email_rule)) {
6835: push(@{$changes{'email_rule'}},$type);
6836: }
6837: }
6838: foreach my $type (@email_rule) {
6839: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
6840: push(@{$changes{'email_rule'}},$type);
6841: }
6842: }
6843: } else {
6844: push(@{$changes{'email_rule'}},@email_rule);
6845: }
6846:
6847: my @authen_contexts = ('author','course','domain');
1.28 raeburn 6848: my @authtypes = ('int','krb4','krb5','loc');
6849: my %authhash;
1.43 raeburn 6850: foreach my $item (@authen_contexts) {
1.28 raeburn 6851: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
6852: foreach my $auth (@authtypes) {
6853: if (grep(/^\Q$auth\E$/,@authallowed)) {
6854: $authhash{$item}{$auth} = 1;
6855: } else {
6856: $authhash{$item}{$auth} = 0;
6857: }
6858: }
6859: }
6860: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 6861: foreach my $item (@authen_contexts) {
1.28 raeburn 6862: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
6863: foreach my $auth (@authtypes) {
6864: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
6865: push(@{$changes{'authtypes'}},$item);
6866: last;
6867: }
6868: }
6869: }
6870: }
6871: } else {
1.43 raeburn 6872: foreach my $item (@authen_contexts) {
1.28 raeburn 6873: push(@{$changes{'authtypes'}},$item);
6874: }
6875: }
6876:
1.27 raeburn 6877: my %usercreation_hash = (
1.28 raeburn 6878: usercreation => {
1.34 raeburn 6879: cancreate => \%cancreate,
1.27 raeburn 6880: username_rule => \@username_rule,
1.32 raeburn 6881: id_rule => \@id_rule,
1.43 raeburn 6882: email_rule => \@email_rule,
1.32 raeburn 6883: authtypes => \%authhash,
1.27 raeburn 6884: }
6885: );
6886:
6887: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
6888: $dom);
1.50 raeburn 6889:
6890: my %selfcreatetypes = (
6891: sso => 'users authenticated by institutional single sign on',
6892: login => 'users authenticated by institutional log-in',
6893: email => 'users who provide a valid e-mail address for use as the username',
6894: );
1.27 raeburn 6895: if ($putresult eq 'ok') {
6896: if (keys(%changes) > 0) {
6897: $resulttext = &mt('Changes made:').'<ul>';
6898: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 6899: my %lt = &usercreation_types();
6900: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 6901: my $chgtext;
1.165 raeburn 6902: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 6903: $chgtext = $lt{$type}.', ';
6904: }
1.45 raeburn 6905: if ($type eq 'selfcreate') {
1.50 raeburn 6906: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 6907: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 6908: } else {
1.100 raeburn 6909: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 6910: foreach my $case (@{$cancreate{$type}}) {
6911: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
6912: }
6913: $chgtext .= '</ul>';
1.100 raeburn 6914: if (ref($cancreate{$type}) eq 'ARRAY') {
6915: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
6916: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
6917: if (@{$cancreate{'statustocreate'}} == 0) {
6918: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6919: }
6920: }
6921: }
6922: }
1.43 raeburn 6923: }
1.93 raeburn 6924: } elsif ($type eq 'statustocreate') {
1.96 raeburn 6925: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
6926: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
6927: if (@{$cancreate{'selfcreate'}} > 0) {
6928: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 6929:
6930: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 6931: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6932: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
6933: }
1.96 raeburn 6934: } elsif (ref($usertypes) eq 'HASH') {
6935: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 6936: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
6937: } else {
6938: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
6939: }
6940: $chgtext .= '<ul>';
6941: foreach my $case (@{$cancreate{$type}}) {
6942: if ($case eq 'default') {
6943: $chgtext .= '<li>'.$othertitle.'</li>';
6944: } else {
6945: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 6946: }
6947: }
1.100 raeburn 6948: $chgtext .= '</ul>';
6949: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
6950: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
6951: }
6952: }
6953: } else {
6954: if (@{$cancreate{$type}} == 0) {
6955: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
6956: } else {
6957: $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 6958: }
6959: }
6960: }
1.165 raeburn 6961: } elsif ($type eq 'captcha') {
6962: if ($cancreate{$type} eq 'notused') {
6963: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
6964: } else {
6965: my %captchas = &captcha_phrases();
6966: if ($captchas{$cancreate{$type}}) {
6967: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
6968: } else {
6969: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
6970: }
6971: }
6972: } elsif ($type eq 'recaptchakeys') {
6973: my ($privkey,$pubkey);
6974: if (ref($cancreate{$type}) eq 'HASH') {
6975: $pubkey = $cancreate{$type}{'public'};
6976: $privkey = $cancreate{$type}{'private'};
6977: }
6978: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
6979: if (!$pubkey) {
6980: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
6981: } else {
6982: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
6983: }
6984: if (!$privkey) {
6985: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
6986: } else {
6987: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
6988: }
6989: $chgtext .= '</ul>';
1.43 raeburn 6990: } else {
6991: if ($cancreate{$type} eq 'none') {
6992: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
6993: } elsif ($cancreate{$type} eq 'any') {
6994: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
6995: } elsif ($cancreate{$type} eq 'official') {
6996: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
6997: } elsif ($cancreate{$type} eq 'unofficial') {
6998: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
6999: }
1.34 raeburn 7000: }
7001: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7002: }
7003: }
7004: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7005: my ($rules,$ruleorder) =
7006: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7007: my $chgtext = '<ul>';
7008: foreach my $type (@username_rule) {
7009: if (ref($rules->{$type}) eq 'HASH') {
7010: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7011: }
7012: }
7013: $chgtext .= '</ul>';
7014: if (@username_rule > 0) {
7015: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7016: } else {
1.28 raeburn 7017: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7018: }
7019: }
1.32 raeburn 7020: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7021: my ($idrules,$idruleorder) =
7022: &Apache::lonnet::inst_userrules($dom,'id');
7023: my $chgtext = '<ul>';
7024: foreach my $type (@id_rule) {
7025: if (ref($idrules->{$type}) eq 'HASH') {
7026: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7027: }
7028: }
7029: $chgtext .= '</ul>';
7030: if (@id_rule > 0) {
7031: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7032: } else {
7033: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7034: }
7035: }
1.43 raeburn 7036: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7037: my ($emailrules,$emailruleorder) =
7038: &Apache::lonnet::inst_userrules($dom,'email');
7039: my $chgtext = '<ul>';
7040: foreach my $type (@email_rule) {
7041: if (ref($emailrules->{$type}) eq 'HASH') {
7042: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7043: }
7044: }
7045: $chgtext .= '</ul>';
7046: if (@email_rule > 0) {
7047: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7048: } else {
7049: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7050: }
7051: }
7052:
1.28 raeburn 7053: my %authname = &authtype_names();
7054: my %context_title = &context_names();
7055: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7056: my $chgtext = '<ul>';
7057: foreach my $type (@{$changes{'authtypes'}}) {
7058: my @allowed;
7059: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7060: foreach my $auth (@authtypes) {
7061: if ($authhash{$type}{$auth}) {
7062: push(@allowed,$authname{$auth});
7063: }
7064: }
1.43 raeburn 7065: if (@allowed > 0) {
7066: $chgtext .= join(', ',@allowed).'</li>';
7067: } else {
7068: $chgtext .= &mt('none').'</li>';
7069: }
1.28 raeburn 7070: }
7071: $chgtext .= '</ul>';
7072: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7073: $resulttext .= '</li>';
7074: }
1.27 raeburn 7075: $resulttext .= '</ul>';
7076: } else {
1.28 raeburn 7077: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7078: }
7079: } else {
7080: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7081: &mt('An error occurred: [_1]',$putresult).'</span>';
7082: }
1.43 raeburn 7083: if ($warningmsg ne '') {
7084: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7085: }
1.23 raeburn 7086: return $resulttext;
7087: }
7088:
1.165 raeburn 7089: sub process_captcha {
7090: my ($container,$changes,$newsettings,$current) = @_;
7091: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7092: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7093: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7094: $newsettings->{'captcha'} = 'original';
7095: }
7096: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.169 raeburn 7097: if ($container eq 'cancreate') {
7098: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7099: push(@{$changes->{'cancreate'}},'captcha');
7100: } elsif (!defined($changes->{'cancreate'})) {
7101: $changes->{'cancreate'} = ['captcha'];
7102: }
7103: } else {
7104: $changes->{'captcha'} = 1;
1.165 raeburn 7105: }
7106: }
7107: my ($newpub,$newpriv,$currpub,$currpriv);
7108: if ($newsettings->{'captcha'} eq 'recaptcha') {
7109: $newpub = $env{'form.'.$container.'_recaptchapub'};
7110: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7111: $newpub =~ s/\W//g;
7112: $newpriv =~ s/\W//g;
7113: $newsettings->{'recaptchakeys'} = {
7114: public => $newpub,
7115: private => $newpriv,
7116: };
1.165 raeburn 7117: }
7118: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7119: $currpub = $current->{'recaptchakeys'}{'public'};
7120: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7121: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7122: $newsettings->{'recaptchakeys'} = {
7123: public => '',
7124: private => '',
7125: }
7126: }
1.165 raeburn 7127: }
7128: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7129: if ($container eq 'cancreate') {
7130: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7131: push(@{$changes->{'cancreate'}},'recaptchakeys');
7132: } elsif (!defined($changes->{'cancreate'})) {
7133: $changes->{'cancreate'} = ['recaptchakeys'];
7134: }
7135: } else {
7136: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7137: }
7138: }
7139: return;
7140: }
7141:
1.33 raeburn 7142: sub modify_usermodification {
7143: my ($dom,%domconfig) = @_;
7144: my ($resulttext,%curr_usermodification,%changes);
7145: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7146: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7147: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7148: }
7149: }
1.63 raeburn 7150: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7151: my %context_title = (
7152: author => 'In author context',
7153: course => 'In course context',
1.63 raeburn 7154: selfcreate => 'When self creating account',
1.33 raeburn 7155: );
7156: my @fields = ('lastname','firstname','middlename','generation',
7157: 'permanentemail','id');
7158: my %roles = (
7159: author => ['ca','aa'],
7160: course => ['st','ep','ta','in','cr'],
7161: );
1.63 raeburn 7162: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7163: if (ref($types) eq 'ARRAY') {
7164: push(@{$types},'default');
7165: $usertypes->{'default'} = $othertitle;
7166: }
7167: $roles{'selfcreate'} = $types;
1.33 raeburn 7168: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7169: my %modifyhash;
7170: foreach my $context (@contexts) {
7171: foreach my $role (@{$roles{$context}}) {
7172: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7173: foreach my $item (@fields) {
7174: if (grep(/^\Q$item\E$/,@modifiable)) {
7175: $modifyhash{$context}{$role}{$item} = 1;
7176: } else {
7177: $modifyhash{$context}{$role}{$item} = 0;
7178: }
7179: }
7180: }
7181: if (ref($curr_usermodification{$context}) eq 'HASH') {
7182: foreach my $role (@{$roles{$context}}) {
7183: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7184: foreach my $field (@fields) {
7185: if ($modifyhash{$context}{$role}{$field} ne
7186: $curr_usermodification{$context}{$role}{$field}) {
7187: push(@{$changes{$context}},$role);
7188: last;
7189: }
7190: }
7191: }
7192: }
7193: } else {
7194: foreach my $context (@contexts) {
7195: foreach my $role (@{$roles{$context}}) {
7196: push(@{$changes{$context}},$role);
7197: }
7198: }
7199: }
7200: }
7201: my %usermodification_hash = (
7202: usermodification => \%modifyhash,
7203: );
7204: my $putresult = &Apache::lonnet::put_dom('configuration',
7205: \%usermodification_hash,$dom);
7206: if ($putresult eq 'ok') {
7207: if (keys(%changes) > 0) {
7208: $resulttext = &mt('Changes made: ').'<ul>';
7209: foreach my $context (@contexts) {
7210: if (ref($changes{$context}) eq 'ARRAY') {
7211: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7212: if (ref($changes{$context}) eq 'ARRAY') {
7213: foreach my $role (@{$changes{$context}}) {
7214: my $rolename;
1.63 raeburn 7215: if ($context eq 'selfcreate') {
7216: $rolename = $role;
7217: if (ref($usertypes) eq 'HASH') {
7218: if ($usertypes->{$role} ne '') {
7219: $rolename = $usertypes->{$role};
7220: }
7221: }
1.33 raeburn 7222: } else {
1.63 raeburn 7223: if ($role eq 'cr') {
7224: $rolename = &mt('Custom');
7225: } else {
7226: $rolename = &Apache::lonnet::plaintext($role);
7227: }
1.33 raeburn 7228: }
7229: my @modifiable;
1.63 raeburn 7230: if ($context eq 'selfcreate') {
1.126 bisitz 7231: $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 7232: } else {
7233: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7234: }
1.33 raeburn 7235: foreach my $field (@fields) {
7236: if ($modifyhash{$context}{$role}{$field}) {
7237: push(@modifiable,$fieldtitles{$field});
7238: }
7239: }
7240: if (@modifiable > 0) {
7241: $resulttext .= join(', ',@modifiable);
7242: } else {
7243: $resulttext .= &mt('none');
7244: }
7245: $resulttext .= '</li>';
7246: }
7247: $resulttext .= '</ul></li>';
7248: }
7249: }
7250: }
7251: $resulttext .= '</ul>';
7252: } else {
7253: $resulttext = &mt('No changes made to user modification settings');
7254: }
7255: } else {
7256: $resulttext = '<span class="LC_error">'.
7257: &mt('An error occurred: [_1]',$putresult).'</span>';
7258: }
7259: return $resulttext;
7260: }
7261:
1.43 raeburn 7262: sub modify_defaults {
7263: my ($dom,$r) = @_;
7264: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
7265: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.141 raeburn 7266: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7267: my @authtypes = ('internal','krb4','krb5','localauth');
7268: foreach my $item (@items) {
7269: $newvalues{$item} = $env{'form.'.$item};
7270: if ($item eq 'auth_def') {
7271: if ($newvalues{$item} ne '') {
7272: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7273: push(@errors,$item);
7274: }
7275: }
7276: } elsif ($item eq 'lang_def') {
7277: if ($newvalues{$item} ne '') {
7278: if ($newvalues{$item} =~ /^(\w+)/) {
7279: my $langcode = $1;
1.103 raeburn 7280: if ($langcode ne 'x_chef') {
7281: if (code2language($langcode) eq '') {
7282: push(@errors,$item);
7283: }
1.43 raeburn 7284: }
7285: } else {
7286: push(@errors,$item);
7287: }
7288: }
1.54 raeburn 7289: } elsif ($item eq 'timezone_def') {
7290: if ($newvalues{$item} ne '') {
1.62 raeburn 7291: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7292: push(@errors,$item);
7293: }
7294: }
1.68 raeburn 7295: } elsif ($item eq 'datelocale_def') {
7296: if ($newvalues{$item} ne '') {
7297: my @datelocale_ids = DateTime::Locale->ids();
7298: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7299: push(@errors,$item);
7300: }
7301: }
1.141 raeburn 7302: } elsif ($item eq 'portal_def') {
7303: if ($newvalues{$item} ne '') {
7304: 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])\/?$/) {
7305: push(@errors,$item);
7306: }
7307: }
1.43 raeburn 7308: }
7309: if (grep(/^\Q$item\E$/,@errors)) {
7310: $newvalues{$item} = $domdefaults{$item};
7311: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7312: $changes{$item} = 1;
7313: }
1.72 raeburn 7314: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7315: }
7316: my %defaults_hash = (
1.72 raeburn 7317: defaults => \%newvalues,
7318: );
1.43 raeburn 7319: my $title = &defaults_titles();
7320: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7321: $dom);
7322: if ($putresult eq 'ok') {
7323: if (keys(%changes) > 0) {
7324: $resulttext = &mt('Changes made:').'<ul>';
7325: my $version = $r->dir_config('lonVersion');
7326: 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";
7327: foreach my $item (sort(keys(%changes))) {
7328: my $value = $env{'form.'.$item};
7329: if ($value eq '') {
7330: $value = &mt('none');
7331: } elsif ($item eq 'auth_def') {
7332: my %authnames = &authtype_names();
7333: my %shortauth = (
7334: internal => 'int',
7335: krb4 => 'krb4',
7336: krb5 => 'krb5',
7337: localauth => 'loc',
7338: );
7339: $value = $authnames{$shortauth{$value}};
7340: }
7341: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7342: $mailmsgtext .= "$title->{$item} set to $value\n";
7343: }
7344: $resulttext .= '</ul>';
7345: $mailmsgtext .= "\n";
7346: my $cachetime = 24*60*60;
1.72 raeburn 7347: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.68 raeburn 7348: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.54 raeburn 7349: my $sysmail = $r->dir_config('lonSysEMail');
7350: &Apache::lonmsg::sendemail($sysmail,"LON-CAPA Domain Settings Change - $dom",$mailmsgtext);
7351: }
1.43 raeburn 7352: } else {
1.54 raeburn 7353: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7354: }
7355: } else {
7356: $resulttext = '<span class="LC_error">'.
7357: &mt('An error occurred: [_1]',$putresult).'</span>';
7358: }
7359: if (@errors > 0) {
7360: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7361: foreach my $item (@errors) {
7362: $resulttext .= ' "'.$title->{$item}.'",';
7363: }
7364: $resulttext =~ s/,$//;
7365: }
7366: return $resulttext;
7367: }
7368:
1.46 raeburn 7369: sub modify_scantron {
1.48 raeburn 7370: my ($r,$dom,$confname,%domconfig) = @_;
1.46 raeburn 7371: my ($resulttext,%confhash,%changes,$errors);
7372: my $custom = 'custom.tab';
7373: my $default = 'default.tab';
7374: my $servadm = $r->dir_config('lonAdmEMail');
7375: my ($configuserok,$author_ok,$switchserver) =
7376: &config_check($dom,$confname,$servadm);
7377: if ($env{'form.scantronformat.filename'} ne '') {
7378: my $error;
7379: if ($configuserok eq 'ok') {
7380: if ($switchserver) {
1.130 raeburn 7381: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7382: } else {
7383: if ($author_ok eq 'ok') {
7384: my ($result,$scantronurl) =
7385: &publishlogo($r,'upload','scantronformat',$dom,
7386: $confname,'scantron','','',$custom);
7387: if ($result eq 'ok') {
7388: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7389: $changes{'scantronformat'} = 1;
1.46 raeburn 7390: } else {
7391: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7392: }
7393: } else {
7394: $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);
7395: }
7396: }
7397: } else {
7398: $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);
7399: }
7400: if ($error) {
7401: &Apache::lonnet::logthis($error);
7402: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7403: }
7404: }
1.48 raeburn 7405: if (ref($domconfig{'scantron'}) eq 'HASH') {
7406: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7407: if ($env{'form.scantronformat_del'}) {
7408: $confhash{'scantron'}{'scantronformat'} = '';
7409: $changes{'scantronformat'} = 1;
1.46 raeburn 7410: }
7411: }
7412: }
7413: if (keys(%confhash) > 0) {
7414: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7415: $dom);
7416: if ($putresult eq 'ok') {
7417: if (keys(%changes) > 0) {
1.48 raeburn 7418: if (ref($confhash{'scantron'}) eq 'HASH') {
7419: $resulttext = &mt('Changes made:').'<ul>';
7420: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7421: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7422: } else {
1.130 raeburn 7423: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7424: }
1.48 raeburn 7425: $resulttext .= '</ul>';
7426: } else {
1.130 raeburn 7427: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7428: }
7429: $resulttext .= '</ul>';
7430: &Apache::loncommon::devalidate_domconfig_cache($dom);
7431: } else {
1.130 raeburn 7432: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7433: }
7434: } else {
7435: $resulttext = '<span class="LC_error">'.
7436: &mt('An error occurred: [_1]',$putresult).'</span>';
7437: }
7438: } else {
1.130 raeburn 7439: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7440: }
7441: if ($errors) {
7442: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7443: $errors.'</ul>';
7444: }
7445: return $resulttext;
7446: }
7447:
1.48 raeburn 7448: sub modify_coursecategories {
7449: my ($dom,%domconfig) = @_;
1.57 raeburn 7450: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7451: $cathash);
1.48 raeburn 7452: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7453: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7454: $cathash = $domconfig{'coursecategories'}{'cats'};
7455: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7456: $changes{'togglecats'} = 1;
7457: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7458: }
7459: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7460: $changes{'categorize'} = 1;
7461: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7462: }
1.120 raeburn 7463: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7464: $changes{'togglecatscomm'} = 1;
7465: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7466: }
7467: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7468: $changes{'categorizecomm'} = 1;
7469: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7470: }
1.57 raeburn 7471: } else {
7472: $changes{'togglecats'} = 1;
7473: $changes{'categorize'} = 1;
1.124 raeburn 7474: $changes{'togglecatscomm'} = 1;
7475: $changes{'categorizecomm'} = 1;
1.87 raeburn 7476: $domconfig{'coursecategories'} = {
7477: togglecats => $env{'form.togglecats'},
7478: categorize => $env{'form.categorize'},
1.124 raeburn 7479: togglecatscomm => $env{'form.togglecatscomm'},
7480: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7481: };
1.57 raeburn 7482: }
7483: if (ref($cathash) eq 'HASH') {
7484: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7485: push (@deletecategory,'instcode::0');
7486: }
1.120 raeburn 7487: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7488: push(@deletecategory,'communities::0');
7489: }
1.48 raeburn 7490: }
1.57 raeburn 7491: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7492: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7493: if (@deletecategory > 0) {
7494: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7495: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7496: foreach my $item (@deletecategory) {
1.57 raeburn 7497: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7498: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7499: $deletions{$item} = 1;
1.57 raeburn 7500: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7501: }
7502: }
7503: }
1.57 raeburn 7504: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7505: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7506: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7507: $reorderings{$item} = 1;
1.57 raeburn 7508: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7509: }
7510: if ($env{'form.addcategory_name_'.$item} ne '') {
7511: my $newcat = $env{'form.addcategory_name_'.$item};
7512: my $newdepth = $depth+1;
7513: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7514: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7515: $adds{$newitem} = 1;
7516: }
7517: if ($env{'form.subcat_'.$item} ne '') {
7518: my $newcat = $env{'form.subcat_'.$item};
7519: my $newdepth = $depth+1;
7520: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7521: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7522: $adds{$newitem} = 1;
7523: }
7524: }
7525: }
7526: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7527: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7528: my $newitem = 'instcode::0';
1.57 raeburn 7529: if ($cathash->{$newitem} eq '') {
7530: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7531: $adds{$newitem} = 1;
7532: }
7533: } else {
7534: my $newitem = 'instcode::0';
1.57 raeburn 7535: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7536: $adds{$newitem} = 1;
7537: }
7538: }
1.120 raeburn 7539: if ($env{'form.communities'} eq '1') {
7540: if (ref($cathash) eq 'HASH') {
7541: my $newitem = 'communities::0';
7542: if ($cathash->{$newitem} eq '') {
7543: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7544: $adds{$newitem} = 1;
7545: }
7546: } else {
7547: my $newitem = 'communities::0';
7548: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7549: $adds{$newitem} = 1;
7550: }
7551: }
1.48 raeburn 7552: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7553: if (($env{'form.addcategory_name'} ne 'instcode') &&
7554: ($env{'form.addcategory_name'} ne 'communities')) {
7555: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7556: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7557: $adds{$newitem} = 1;
7558: }
1.48 raeburn 7559: }
1.57 raeburn 7560: my $putresult;
1.48 raeburn 7561: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7562: if (keys(%deletions) > 0) {
7563: foreach my $key (keys(%deletions)) {
7564: if ($predelallitems{$key} ne '') {
7565: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7566: }
7567: }
7568: }
7569: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7570: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7571: if (ref($chkcats[0]) eq 'ARRAY') {
7572: my $depth = 0;
7573: my $chg = 0;
7574: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7575: my $name = $chkcats[0][$i];
7576: my $item;
7577: if ($name eq '') {
7578: $chg ++;
7579: } else {
7580: $item = &escape($name).'::0';
7581: if ($chg) {
1.57 raeburn 7582: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7583: }
7584: $depth ++;
1.57 raeburn 7585: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7586: $depth --;
7587: }
7588: }
7589: }
1.57 raeburn 7590: }
7591: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7592: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7593: if ($putresult eq 'ok') {
1.57 raeburn 7594: my %title = (
1.120 raeburn 7595: togglecats => 'Show/Hide a course in catalog',
7596: categorize => 'Assign a category to a course',
7597: togglecatscomm => 'Show/Hide a community in catalog',
7598: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7599: );
7600: my %level = (
1.120 raeburn 7601: dom => 'set in Domain ("Modify Course/Community")',
7602: crs => 'set in Course ("Course Configuration")',
7603: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7604: );
1.48 raeburn 7605: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7606: if ($changes{'togglecats'}) {
7607: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7608: }
7609: if ($changes{'categorize'}) {
7610: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7611: }
1.120 raeburn 7612: if ($changes{'togglecatscomm'}) {
7613: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7614: }
7615: if ($changes{'categorizecomm'}) {
7616: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7617: }
1.57 raeburn 7618: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7619: my $cathash;
7620: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7621: $cathash = $domconfig{'coursecategories'}{'cats'};
7622: } else {
7623: $cathash = {};
7624: }
7625: my (@cats,@trails,%allitems);
7626: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7627: if (keys(%deletions) > 0) {
7628: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7629: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7630: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7631: }
7632: $resulttext .= '</ul></li>';
7633: }
7634: if (keys(%reorderings) > 0) {
7635: my %sort_by_trail;
7636: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7637: foreach my $key (keys(%reorderings)) {
7638: if ($allitems{$key} ne '') {
7639: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7640: }
1.48 raeburn 7641: }
1.57 raeburn 7642: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7643: $resulttext .= '<li>'.$trails[$trail].'</li>';
7644: }
7645: $resulttext .= '</ul></li>';
1.48 raeburn 7646: }
1.57 raeburn 7647: if (keys(%adds) > 0) {
7648: my %sort_by_trail;
7649: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7650: foreach my $key (keys(%adds)) {
7651: if ($allitems{$key} ne '') {
7652: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7653: }
7654: }
7655: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7656: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7657: }
1.57 raeburn 7658: $resulttext .= '</ul></li>';
1.48 raeburn 7659: }
7660: }
7661: $resulttext .= '</ul>';
7662: } else {
7663: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7664: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7665: }
7666: } else {
1.120 raeburn 7667: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7668: }
7669: return $resulttext;
7670: }
7671:
1.69 raeburn 7672: sub modify_serverstatuses {
7673: my ($dom,%domconfig) = @_;
7674: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7675: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7676: %currserverstatus = %{$domconfig{'serverstatuses'}};
7677: }
7678: my @pages = &serverstatus_pages();
7679: foreach my $type (@pages) {
7680: $newserverstatus{$type}{'namedusers'} = '';
7681: $newserverstatus{$type}{'machines'} = '';
7682: if (defined($env{'form.'.$type.'_namedusers'})) {
7683: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7684: my @okusers;
7685: foreach my $user (@users) {
7686: my ($uname,$udom) = split(/:/,$user);
7687: if (($udom =~ /^$match_domain$/) &&
7688: (&Apache::lonnet::domain($udom)) &&
7689: ($uname =~ /^$match_username$/)) {
7690: if (!grep(/^\Q$user\E/,@okusers)) {
7691: push(@okusers,$user);
7692: }
7693: }
7694: }
7695: if (@okusers > 0) {
7696: @okusers = sort(@okusers);
7697: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7698: }
7699: }
7700: if (defined($env{'form.'.$type.'_machines'})) {
7701: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7702: my @okmachines;
7703: foreach my $ip (@machines) {
7704: my @parts = split(/\./,$ip);
7705: next if (@parts < 4);
7706: my $badip = 0;
7707: for (my $i=0; $i<4; $i++) {
7708: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7709: $badip = 1;
7710: last;
7711: }
7712: }
7713: if (!$badip) {
7714: push(@okmachines,$ip);
7715: }
7716: }
7717: @okmachines = sort(@okmachines);
7718: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7719: }
7720: }
7721: my %serverstatushash = (
7722: serverstatuses => \%newserverstatus,
7723: );
7724: foreach my $type (@pages) {
1.83 raeburn 7725: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7726: my (@current,@new);
1.83 raeburn 7727: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7728: if ($currserverstatus{$type}{$setting} ne '') {
7729: @current = split(/,/,$currserverstatus{$type}{$setting});
7730: }
7731: }
7732: if ($newserverstatus{$type}{$setting} ne '') {
7733: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7734: }
7735: if (@current > 0) {
7736: if (@new > 0) {
7737: foreach my $item (@current) {
7738: if (!grep(/^\Q$item\E$/,@new)) {
7739: $changes{$type}{$setting} = 1;
1.82 raeburn 7740: last;
7741: }
7742: }
1.84 raeburn 7743: foreach my $item (@new) {
7744: if (!grep(/^\Q$item\E$/,@current)) {
7745: $changes{$type}{$setting} = 1;
7746: last;
1.82 raeburn 7747: }
7748: }
7749: } else {
1.83 raeburn 7750: $changes{$type}{$setting} = 1;
1.69 raeburn 7751: }
1.83 raeburn 7752: } elsif (@new > 0) {
7753: $changes{$type}{$setting} = 1;
1.69 raeburn 7754: }
7755: }
7756: }
7757: if (keys(%changes) > 0) {
1.81 raeburn 7758: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7759: my $putresult = &Apache::lonnet::put_dom('configuration',
7760: \%serverstatushash,$dom);
7761: if ($putresult eq 'ok') {
7762: $resulttext .= &mt('Changes made:').'<ul>';
7763: foreach my $type (@pages) {
1.84 raeburn 7764: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7765: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7766: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7767: if ($newserverstatus{$type}{'namedusers'} eq '') {
7768: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7769: } else {
7770: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7771: }
1.84 raeburn 7772: }
7773: if ($changes{$type}{'machines'}) {
1.69 raeburn 7774: if ($newserverstatus{$type}{'machines'} eq '') {
7775: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7776: } else {
7777: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7778: }
7779:
7780: }
7781: $resulttext .= '</ul></li>';
7782: }
7783: }
7784: $resulttext .= '</ul>';
7785: } else {
7786: $resulttext = '<span class="LC_error">'.
7787: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
7788:
7789: }
7790: } else {
7791: $resulttext = &mt('No changes made to access to server status pages');
7792: }
7793: return $resulttext;
7794: }
7795:
1.118 jms 7796: sub modify_helpsettings {
1.122 jms 7797: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 7798: my ($resulttext,$errors,%changes,%helphash);
7799: my %defaultchecked = ('submitbugs' => 'on');
7800: my @offon = ('off','on');
1.118 jms 7801: my @toggles = ('submitbugs');
7802: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
7803: foreach my $item (@toggles) {
1.166 raeburn 7804: if ($defaultchecked{$item} eq 'on') {
7805: if ($domconfig{'helpsettings'}{$item} eq '') {
7806: if ($env{'form.'.$item} eq '0') {
7807: $changes{$item} = 1;
7808: }
7809: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7810: $changes{$item} = 1;
7811: }
7812: } elsif ($defaultchecked{$item} eq 'off') {
7813: if ($domconfig{'helpsettings'}{$item} eq '') {
7814: if ($env{'form.'.$item} eq '1') {
7815: $changes{$item} = 1;
7816: }
7817: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
7818: $changes{$item} = 1;
7819: }
7820: }
7821: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
7822: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
7823: }
7824: }
1.118 jms 7825: }
1.123 jms 7826: my $putresult;
7827: if (keys(%changes) > 0) {
1.166 raeburn 7828: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 7829: if ($putresult eq 'ok') {
1.166 raeburn 7830: $resulttext = &mt('Changes made:').'<ul>';
7831: foreach my $item (sort(keys(%changes))) {
7832: if ($item eq 'submitbugs') {
7833: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
7834: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
7835: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
7836: }
7837: }
7838: $resulttext .= '</ul>';
7839: } else {
7840: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 7841: $errors .= '<li><span class="LC_error">'.
7842: &mt('An error occurred storing the settings: [_1]',
7843: $putresult).'</span></li>';
1.166 raeburn 7844: }
1.118 jms 7845: }
7846: if ($errors) {
1.168 raeburn 7847: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 7848: $errors.'</ul>';
7849: }
7850: return $resulttext;
7851: }
7852:
1.121 raeburn 7853: sub modify_coursedefaults {
7854: my ($dom,%domconfig) = @_;
7855: my ($resulttext,$errors,%changes,%defaultshash);
7856: my %defaultchecked = ('canuse_pdfforms' => 'off');
7857: my @offon = ('off','on');
7858: my @toggles = ('canuse_pdfforms');
7859:
7860: $defaultshash{'coursedefaults'} = {};
7861:
7862: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
7863: if ($domconfig{'coursedefaults'} eq '') {
7864: $domconfig{'coursedefaults'} = {};
7865: }
7866: }
7867:
7868: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
7869: foreach my $item (@toggles) {
7870: if ($defaultchecked{$item} eq 'on') {
7871: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7872: ($env{'form.'.$item} eq '0')) {
7873: $changes{$item} = 1;
7874: } elsif ($domconfig{'coursdefaults'}{$item} ne $env{'form.'.$item}) {
7875: $changes{$item} = 1;
7876: }
7877: } elsif ($defaultchecked{$item} eq 'off') {
7878: if (($domconfig{'coursedefaults'}{$item} eq '') &&
7879: ($env{'form.'.$item} eq '1')) {
7880: $changes{$item} = 1;
7881: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
7882: $changes{$item} = 1;
7883: }
7884: }
7885: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
7886: }
1.139 raeburn 7887: my $currdefresponder = $domconfig{'coursedefaults'}{'anonsurvey_threshold'};
7888: my $newdefresponder = $env{'form.anonsurvey_threshold'};
7889: $newdefresponder =~ s/\D//g;
7890: if ($newdefresponder eq '' || $newdefresponder < 1) {
7891: $newdefresponder = 1;
7892: }
7893: $defaultshash{'coursedefaults'}{'anonsurvey_threshold'} = $newdefresponder;
7894: if ($currdefresponder ne $newdefresponder) {
7895: unless ($currdefresponder eq '' && $newdefresponder == 10) {
7896: $changes{'anonsurvey_threshold'} = 1;
7897: }
7898: }
1.121 raeburn 7899: }
7900: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
7901: $dom);
7902: if ($putresult eq 'ok') {
7903: if (keys(%changes) > 0) {
7904: if ($changes{'canuse_pdfforms'}) {
7905: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7906: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
7907: my $cachetime = 24*60*60;
7908: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
7909: }
7910: $resulttext = &mt('Changes made:').'<ul>';
7911: foreach my $item (sort(keys(%changes))) {
7912: if ($item eq 'canuse_pdfforms') {
7913: if ($env{'form.'.$item} eq '1') {
7914: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
7915: } else {
7916: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
7917: }
1.139 raeburn 7918: } elsif ($item eq 'anonsurvey_threshold') {
7919: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.140 raeburn 7920: }
1.121 raeburn 7921: }
7922: $resulttext .= '</ul>';
7923: } else {
7924: $resulttext = &mt('No changes made to course defaults');
7925: }
7926: } else {
7927: $resulttext = '<span class="LC_error">'.
7928: &mt('An error occurred: [_1]',$putresult).'</span>';
7929: }
7930: return $resulttext;
7931: }
7932:
1.137 raeburn 7933: sub modify_usersessions {
7934: my ($dom,%domconfig) = @_;
1.145 raeburn 7935: my @hostingtypes = ('version','excludedomain','includedomain');
7936: my @offloadtypes = ('primary','default');
7937: my %types = (
7938: remote => \@hostingtypes,
7939: hosted => \@hostingtypes,
7940: spares => \@offloadtypes,
7941: );
7942: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 7943: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 7944: my (%by_ip,%by_location,@intdoms);
7945: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
7946: my @locations = sort(keys(%by_location));
1.137 raeburn 7947: my (%defaultshash,%changes);
7948: foreach my $prefix (@prefixes) {
7949: $defaultshash{'usersessions'}{$prefix} = {};
7950: }
7951: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
7952: my $resulttext;
1.138 raeburn 7953: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 7954: foreach my $prefix (@prefixes) {
1.145 raeburn 7955: next if ($prefix eq 'spares');
7956: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 7957: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
7958: if ($type eq 'version') {
7959: my $value = $env{'form.'.$prefix.'_'.$type};
7960: my $okvalue;
7961: if ($value ne '') {
7962: if (grep(/^\Q$value\E$/,@lcversions)) {
7963: $okvalue = $value;
7964: }
7965: }
7966: if (ref($domconfig{'usersessions'}) eq 'HASH') {
7967: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
7968: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
7969: if ($inuse == 0) {
7970: $changes{$prefix}{$type} = 1;
7971: } else {
7972: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
7973: $changes{$prefix}{$type} = 1;
7974: }
7975: if ($okvalue ne '') {
7976: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7977: }
7978: }
7979: } else {
7980: if (($inuse == 1) && ($okvalue ne '')) {
7981: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7982: $changes{$prefix}{$type} = 1;
7983: }
7984: }
7985: } else {
7986: if (($inuse == 1) && ($okvalue ne '')) {
7987: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7988: $changes{$prefix}{$type} = 1;
7989: }
7990: }
7991: } else {
7992: if (($inuse == 1) && ($okvalue ne '')) {
7993: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
7994: $changes{$prefix}{$type} = 1;
7995: }
7996: }
7997: } else {
7998: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
7999: my @okvals;
8000: foreach my $val (@vals) {
1.138 raeburn 8001: if ($val =~ /:/) {
8002: my @items = split(/:/,$val);
8003: foreach my $item (@items) {
8004: if (ref($by_location{$item}) eq 'ARRAY') {
8005: push(@okvals,$item);
8006: }
8007: }
8008: } else {
8009: if (ref($by_location{$val}) eq 'ARRAY') {
8010: push(@okvals,$val);
8011: }
1.137 raeburn 8012: }
8013: }
8014: @okvals = sort(@okvals);
8015: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8016: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8017: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8018: if ($inuse == 0) {
8019: $changes{$prefix}{$type} = 1;
8020: } else {
8021: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8022: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8023: if (@changed > 0) {
8024: $changes{$prefix}{$type} = 1;
8025: }
8026: }
8027: } else {
8028: if ($inuse == 1) {
8029: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8030: $changes{$prefix}{$type} = 1;
8031: }
8032: }
8033: } else {
8034: if ($inuse == 1) {
8035: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8036: $changes{$prefix}{$type} = 1;
8037: }
8038: }
8039: } else {
8040: if ($inuse == 1) {
8041: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8042: $changes{$prefix}{$type} = 1;
8043: }
8044: }
8045: }
8046: }
8047: }
1.145 raeburn 8048:
8049: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8050: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8051: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8052: my $savespares;
8053:
8054: foreach my $lonhost (sort(keys(%servers))) {
8055: my $serverhomeID =
8056: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8057: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8058: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8059: my %spareschg;
8060: foreach my $type (@{$types{'spares'}}) {
8061: my @okspares;
8062: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8063: foreach my $server (@checked) {
1.152 raeburn 8064: if (&Apache::lonnet::hostname($server) ne '') {
8065: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8066: unless (grep(/^\Q$server\E$/,@okspares)) {
8067: push(@okspares,$server);
8068: }
1.145 raeburn 8069: }
8070: }
8071: }
8072: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8073: my $newspare;
1.152 raeburn 8074: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8075: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8076: $newspare = $new;
8077: }
8078: }
1.152 raeburn 8079: my @spares;
8080: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8081: @spares = sort(@okspares,$newspare);
8082: } else {
8083: @spares = sort(@okspares);
8084: }
8085: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8086: if (ref($spareid{$lonhost}) eq 'HASH') {
8087: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8088: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8089: if (@diffs > 0) {
8090: $spareschg{$type} = 1;
8091: }
8092: }
8093: }
8094: }
8095: if (keys(%spareschg) > 0) {
8096: $changes{'spares'}{$lonhost} = \%spareschg;
8097: }
8098: }
8099:
8100: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8101: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8102: if (ref($changes{'spares'}) eq 'HASH') {
8103: if (keys(%{$changes{'spares'}}) > 0) {
8104: $savespares = 1;
8105: }
8106: }
8107: } else {
8108: $savespares = 1;
8109: }
8110: }
8111:
1.147 raeburn 8112: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8113: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8114: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8115: $dom);
8116: if ($putresult eq 'ok') {
8117: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8118: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8119: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8120: }
8121: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8122: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8123: }
8124: }
8125: my $cachetime = 24*60*60;
8126: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.147 raeburn 8127: if (keys(%changes) > 0) {
8128: my %lt = &usersession_titles();
8129: $resulttext = &mt('Changes made:').'<ul>';
8130: foreach my $prefix (@prefixes) {
8131: if (ref($changes{$prefix}) eq 'HASH') {
8132: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8133: if ($prefix eq 'spares') {
8134: if (ref($changes{$prefix}) eq 'HASH') {
8135: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8136: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8137: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
8138: &Apache::lonnet::remote_devalidate_cache($lonhost,'spares',$lonhostdom);
1.147 raeburn 8139: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8140: foreach my $type (@{$types{$prefix}}) {
8141: if ($changes{$prefix}{$lonhost}{$type}) {
8142: my $offloadto = &mt('None');
8143: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8144: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8145: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8146: }
1.145 raeburn 8147: }
1.147 raeburn 8148: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8149: }
1.137 raeburn 8150: }
8151: }
1.147 raeburn 8152: $resulttext .= '</li>';
1.137 raeburn 8153: }
8154: }
1.147 raeburn 8155: } else {
8156: foreach my $type (@{$types{$prefix}}) {
8157: if (defined($changes{$prefix}{$type})) {
8158: my $newvalue;
8159: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8160: if (ref($defaultshash{'usersessions'}{$prefix})) {
8161: if ($type eq 'version') {
8162: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8163: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8164: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8165: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8166: }
1.145 raeburn 8167: }
8168: }
8169: }
1.147 raeburn 8170: if ($newvalue eq '') {
8171: if ($type eq 'version') {
8172: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8173: } else {
8174: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8175: }
1.145 raeburn 8176: } else {
1.147 raeburn 8177: if ($type eq 'version') {
8178: $newvalue .= ' '.&mt('(or later)');
8179: }
8180: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8181: }
1.137 raeburn 8182: }
8183: }
8184: }
1.147 raeburn 8185: $resulttext .= '</ul>';
1.137 raeburn 8186: }
8187: }
1.147 raeburn 8188: $resulttext .= '</ul>';
8189: } else {
8190: $resulttext = $nochgmsg;
1.137 raeburn 8191: }
8192: } else {
8193: $resulttext = '<span class="LC_error">'.
8194: &mt('An error occurred: [_1]',$putresult).'</span>';
8195: }
8196: } else {
1.147 raeburn 8197: $resulttext = $nochgmsg;
1.137 raeburn 8198: }
8199: return $resulttext;
8200: }
8201:
1.150 raeburn 8202: sub modify_loadbalancing {
8203: my ($dom,%domconfig) = @_;
8204: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8205: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8206: my ($othertitle,$usertypes,$types) =
8207: &Apache::loncommon::sorted_inst_types($dom);
8208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8209: my @sparestypes = ('primary','default');
8210: my %typetitles = &sparestype_titles();
8211: my $resulttext;
1.171 raeburn 8212: my (%currbalancer,%currtargets,%currrules,%existing);
8213: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8214: %existing = %{$domconfig{'loadbalancing'}};
8215: }
8216: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8217: \%currtargets,\%currrules);
8218: my ($saveloadbalancing,%defaultshash,%changes);
8219: my ($alltypes,$othertypes,$titles) =
8220: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8221: my %ruletitles = &offloadtype_text();
8222: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8223: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8224: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8225: if ($balancer eq '') {
8226: next;
8227: }
8228: if (!exists($servers{$balancer})) {
8229: if (exists($currbalancer{$balancer})) {
8230: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8231: }
1.171 raeburn 8232: next;
8233: }
8234: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8235: push(@{$changes{'delete'}},$balancer);
8236: next;
8237: }
8238: if (!exists($currbalancer{$balancer})) {
8239: push(@{$changes{'add'}},$balancer);
8240: }
8241: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8242: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8243: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8244: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8245: $saveloadbalancing = 1;
8246: }
8247: foreach my $sparetype (@sparestypes) {
8248: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8249: my @offloadto;
8250: foreach my $target (@targets) {
8251: if (($servers{$target}) && ($target ne $balancer)) {
8252: if ($sparetype eq 'default') {
8253: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8254: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8255: }
8256: }
1.171 raeburn 8257: unless(grep(/^\Q$target\E$/,@offloadto)) {
8258: push(@offloadto,$target);
8259: }
1.150 raeburn 8260: }
1.171 raeburn 8261: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8262: }
8263: }
1.171 raeburn 8264: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8265: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8266: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8267: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8268: if (@targetdiffs > 0) {
1.171 raeburn 8269: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8270: }
1.171 raeburn 8271: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8272: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8273: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8274: }
8275: }
8276: }
8277: } else {
1.171 raeburn 8278: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
8279: foreach my $sparetype (@sparestypes) {
8280: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8281: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8282: $changes{'curr'}{$balancer}{'targets'} = 1;
8283: }
1.150 raeburn 8284: }
8285: }
8286: }
8287: }
8288: my $ishomedom;
1.171 raeburn 8289: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8290: $ishomedom = 1;
1.150 raeburn 8291: }
8292: if (ref($alltypes) eq 'ARRAY') {
8293: foreach my $type (@{$alltypes}) {
8294: my $rule;
1.171 raeburn 8295: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8296: (!$ishomedom)) {
1.171 raeburn 8297: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8298: }
8299: if ($rule eq 'specific') {
8300: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8301: }
1.171 raeburn 8302: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8303: if (ref($currrules{$balancer}) eq 'HASH') {
8304: if ($rule ne $currrules{$balancer}{$type}) {
8305: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8306: }
8307: } elsif ($rule ne '') {
1.171 raeburn 8308: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8309: }
8310: }
8311: }
1.171 raeburn 8312: }
8313: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8314: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8315: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8316: $defaultshash{'loadbalancing'} = {};
8317: }
8318: my $putresult = &Apache::lonnet::put_dom('configuration',
8319: \%defaultshash,$dom);
8320:
8321: if ($putresult eq 'ok') {
8322: if (keys(%changes) > 0) {
8323: if (ref($changes{'delete'}) eq 'ARRAY') {
8324: foreach my $balancer (sort(@{$changes{'delete'}})) {
8325: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.150 raeburn 8326: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
8327: }
1.171 raeburn 8328: }
8329: if (ref($changes{'add'}) eq 'ARRAY') {
8330: foreach my $balancer (sort(@{$changes{'add'}})) {
8331: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8332: }
8333: }
8334: if (ref($changes{'curr'}) eq 'HASH') {
8335: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8336: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8337: if ($changes{'curr'}{$balancer}{'targets'}) {
8338: my %offloadstr;
8339: foreach my $sparetype (@sparestypes) {
8340: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8341: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8342: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8343: }
8344: }
1.150 raeburn 8345: }
1.171 raeburn 8346: if (keys(%offloadstr) == 0) {
8347: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8348: } else {
1.171 raeburn 8349: my $showoffload;
8350: foreach my $sparetype (@sparestypes) {
8351: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8352: if (defined($offloadstr{$sparetype})) {
8353: $showoffload .= $offloadstr{$sparetype};
8354: } else {
8355: $showoffload .= &mt('None');
8356: }
8357: $showoffload .= (' 'x3);
8358: }
8359: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8360: }
8361: }
8362: }
1.171 raeburn 8363: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8364: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8365: foreach my $type (@{$alltypes}) {
8366: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8367: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8368: my $balancetext;
8369: if ($rule eq '') {
8370: $balancetext = $ruletitles{'default'};
8371: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer')) {
8372: $balancetext = $ruletitles{$rule};
8373: } else {
8374: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8375: }
8376: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8377: }
8378: }
8379: }
8380: }
1.171 raeburn 8381: &Apache::lonnet::remote_devalidate_cache($balancer,'loadbalancing',$dom);
1.150 raeburn 8382: }
1.171 raeburn 8383: }
8384: if ($resulttext ne '') {
8385: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8386: } else {
8387: $resulttext = $nochgmsg;
8388: }
8389: } else {
1.171 raeburn 8390: $resulttext = $nochgmsg;
1.150 raeburn 8391: }
8392: } else {
1.171 raeburn 8393: $resulttext = '<span class="LC_error">'.
8394: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8395: }
8396: } else {
1.171 raeburn 8397: $resulttext = $nochgmsg;
1.150 raeburn 8398: }
8399: return $resulttext;
8400: }
8401:
1.48 raeburn 8402: sub recurse_check {
8403: my ($chkcats,$categories,$depth,$name) = @_;
8404: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8405: my $chg = 0;
8406: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8407: my $category = $chkcats->[$depth]{$name}[$j];
8408: my $item;
8409: if ($category eq '') {
8410: $chg ++;
8411: } else {
8412: my $deeper = $depth + 1;
8413: $item = &escape($category).':'.&escape($name).':'.$depth;
8414: if ($chg) {
8415: $categories->{$item} -= $chg;
8416: }
8417: &recurse_check($chkcats,$categories,$deeper,$category);
8418: $deeper --;
8419: }
8420: }
8421: }
8422: return;
8423: }
8424:
8425: sub recurse_cat_deletes {
8426: my ($item,$coursecategories,$deletions) = @_;
8427: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8428: my $subdepth = $depth + 1;
8429: if (ref($coursecategories) eq 'HASH') {
8430: foreach my $subitem (keys(%{$coursecategories})) {
8431: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8432: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8433: delete($coursecategories->{$subitem});
8434: $deletions->{$subitem} = 1;
8435: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8436: }
1.48 raeburn 8437: }
8438: }
8439: return;
8440: }
8441:
1.125 raeburn 8442: sub get_active_dcs {
8443: my ($dom) = @_;
8444: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc']);
8445: my %domcoords;
8446: my $numdcs = 0;
8447: my $now = time;
8448: foreach my $server (keys(%dompersonnel)) {
8449: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8450: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
8451: my ($end,$start) = split(':',$dompersonnel{$server}{$user});
8452: if (($end eq '') || ($end == 0) || ($end > $now)) {
8453: if ($start <= $now) {
8454: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
8455: }
8456: }
8457: }
8458: }
8459: return %domcoords;
8460: }
8461:
8462: sub active_dc_picker {
8463: my ($dom,$curr_dc) = @_;
8464: my %domcoords = &get_active_dcs($dom);
8465: my @dcs = sort(keys(%domcoords));
8466: my $numdcs = scalar(@dcs);
8467: my $datatable;
8468: my $numinrow = 2;
8469: if ($numdcs > 1) {
8470: $datatable = '<table>';
8471: for (my $i=0; $i<@dcs; $i++) {
8472: my $rem = $i%($numinrow);
8473: if ($rem == 0) {
8474: if ($i > 0) {
8475: $datatable .= '</tr>';
8476: }
8477: $datatable .= '<tr>';
8478: }
8479: my $check = ' ';
8480: if ($curr_dc eq '') {
8481: if (!$i) {
8482: $check = ' checked="checked" ';
8483: }
8484: } elsif ($dcs[$i] eq $curr_dc) {
8485: $check = ' checked="checked" ';
8486: }
8487: if ($i == @dcs - 1) {
8488: my $colsleft = $numinrow - $rem;
8489: if ($colsleft > 1) {
8490: $datatable .= '<td colspan="'.$colsleft.'">';
8491: } else {
8492: $datatable .= '<td>';
8493: }
8494: } else {
8495: $datatable .= '<td>';
8496: }
8497: my ($dcname,$dcdom) = split(':',$dcs[$i]);
8498: $datatable .= '<span class="LC_nobreak"><label>'.
8499: '<input type="radio" name="autocreate_xmldc"'.
8500: ' value="'.$dcs[$i].'"'.$check.'/>'.
8501: &Apache::loncommon::plainname($dcname,$dcdom).
1.177 bisitz 8502: ' ('.$dcname.':'.$dcdom.')'.
1.125 raeburn 8503: '</label></span></td>';
8504: }
8505: $datatable .= '</tr></table>';
8506: } elsif (@dcs) {
8507: $datatable .= '<input type="hidden" name="autocreate_dc" value="'.
8508: $dcs[0].'" />';
8509: }
8510: return ($numdcs,$datatable);
8511: }
8512:
1.137 raeburn 8513: sub usersession_titles {
8514: return &Apache::lonlocal::texthash(
8515: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8516: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8517: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8518: version => 'LON-CAPA version requirement',
1.138 raeburn 8519: excludedomain => 'Allow all, but exclude specific domains',
8520: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8521: primary => 'Primary (checked first)',
1.154 raeburn 8522: default => 'Default',
1.137 raeburn 8523: );
8524: }
8525:
1.152 raeburn 8526: sub id_for_thisdom {
8527: my (%servers) = @_;
8528: my %altids;
8529: foreach my $server (keys(%servers)) {
8530: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8531: if ($serverhome ne $server) {
8532: $altids{$serverhome} = $server;
8533: }
8534: }
8535: return %altids;
8536: }
8537:
1.150 raeburn 8538: sub count_servers {
8539: my ($currbalancer,%servers) = @_;
8540: my (@spares,$numspares);
8541: foreach my $lonhost (sort(keys(%servers))) {
8542: next if ($currbalancer eq $lonhost);
8543: push(@spares,$lonhost);
8544: }
8545: if ($currbalancer) {
8546: $numspares = scalar(@spares);
8547: } else {
8548: $numspares = scalar(@spares) - 1;
8549: }
8550: return ($numspares,@spares);
8551: }
8552:
8553: sub lonbalance_targets_js {
1.171 raeburn 8554: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8555: my $select = &mt('Select');
8556: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8557: if (ref($servers) eq 'HASH') {
8558: $alltargets = join("','",sort(keys(%{$servers})));
8559: my @homedoms;
8560: foreach my $server (sort(keys(%{$servers}))) {
8561: if (&Apache::lonnet::host_domain($server) eq $dom) {
8562: push(@homedoms,'1');
8563: } else {
8564: push(@homedoms,'0');
8565: }
8566: }
8567: $allishome = join("','",@homedoms);
8568: }
8569: if (ref($types) eq 'ARRAY') {
8570: if (@{$types} > 0) {
8571: @alltypes = @{$types};
8572: }
8573: }
8574: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8575: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8576: my (%currbalancer,%currtargets,%currrules,%existing);
8577: if (ref($settings) eq 'HASH') {
8578: %existing = %{$settings};
8579: }
8580: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8581: \%currtargets,\%currrules);
8582: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8583: return <<"END";
8584:
8585: <script type="text/javascript">
8586: // <![CDATA[
8587:
1.171 raeburn 8588: currBalancers = new Array('$balancers');
8589:
8590: function toggleTargets(balnum) {
8591: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8592: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8593: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8594: var prevbalancer = prevhostitem.value;
8595: var baltotal = document.getElementById('loadbalancing_total').value;
8596: prevhostitem.value = balancer;
8597: if (prevbalancer != '') {
8598: var prevIdx = currBalancers.indexOf(prevbalancer);
8599: if (prevIdx != -1) {
8600: currBalancers.splice(prevIdx,1);
8601: }
8602: }
1.150 raeburn 8603: if (balancer == '') {
1.171 raeburn 8604: hideSpares(balnum);
1.150 raeburn 8605: } else {
1.171 raeburn 8606: var currIdx = currBalancers.indexOf(balancer);
8607: if (currIdx == -1) {
8608: currBalancers.push(balancer);
8609: }
1.150 raeburn 8610: var homedoms = new Array('$allishome');
1.171 raeburn 8611: var ishomedom = homedoms[lonhostitem.selectedIndex];
8612: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8613: }
1.171 raeburn 8614: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8615: return;
8616: }
8617:
1.171 raeburn 8618: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8619: var alltargets = new Array('$alltargets');
8620: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8621: var offloadtypes = new Array('primary','default');
8622:
1.171 raeburn 8623: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8624: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8625:
1.151 raeburn 8626: for (var i=0; i<offloadtypes.length; i++) {
8627: var count = 0;
8628: for (var j=0; j<alltargets.length; j++) {
8629: if (alltargets[j] != balancer) {
1.171 raeburn 8630: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8631: item.value = alltargets[j];
8632: item.style.textAlign='left';
8633: item.style.textFace='normal';
8634: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8635: if (currBalancers.indexOf(alltargets[j]) == -1) {
8636: item.disabled = '';
8637: } else {
8638: item.disabled = 'disabled';
8639: item.checked = false;
8640: }
1.151 raeburn 8641: count ++;
8642: }
1.150 raeburn 8643: }
8644: }
1.151 raeburn 8645: for (var k=0; k<insttypes.length; k++) {
8646: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8647: if (ishomedom == 1) {
1.171 raeburn 8648: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8649: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8650: } else {
1.171 raeburn 8651: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8652: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8653:
8654: }
8655: } else {
1.171 raeburn 8656: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8657: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8658: }
1.151 raeburn 8659: if ((insttypes[k] != '_LC_external') &&
8660: ((insttypes[k] != '_LC_internetdom') ||
8661: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8662: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8663: item.options.length = 0;
8664: item.options[0] = new Option("","",true,true);
8665: var idx = 0;
1.151 raeburn 8666: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8667: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8668: idx ++;
8669: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8670:
1.150 raeburn 8671: }
8672: }
8673: }
8674: }
8675: return;
8676: }
8677:
1.171 raeburn 8678: function hideSpares(balnum) {
1.150 raeburn 8679: var alltargets = new Array('$alltargets');
8680: var insttypes = new Array('$allinsttypes');
8681: var offloadtypes = new Array('primary','default');
8682:
1.171 raeburn 8683: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
8684: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 8685:
8686: var total = alltargets.length - 1;
8687: for (var i=0; i<offloadtypes; i++) {
8688: for (var j=0; j<total; j++) {
1.171 raeburn 8689: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
8690: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
8691: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 8692: }
1.150 raeburn 8693: }
8694: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 8695: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8696: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 8697: if (insttypes[k] != '_LC_external') {
1.171 raeburn 8698: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
8699: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 8700: }
8701: }
8702: return;
8703: }
8704:
1.171 raeburn 8705: function checkOffloads(item,balnum,type) {
1.150 raeburn 8706: var alltargets = new Array('$alltargets');
8707: var offloadtypes = new Array('primary','default');
8708: if (item.checked) {
8709: var total = alltargets.length - 1;
8710: var other;
8711: if (type == offloadtypes[0]) {
1.151 raeburn 8712: other = offloadtypes[1];
1.150 raeburn 8713: } else {
1.151 raeburn 8714: other = offloadtypes[0];
1.150 raeburn 8715: }
8716: for (var i=0; i<total; i++) {
1.171 raeburn 8717: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 8718: if (server == item.value) {
1.171 raeburn 8719: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
8720: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 8721: }
8722: }
8723: }
8724: }
8725: return;
8726: }
8727:
1.171 raeburn 8728: function singleServerToggle(balnum,type) {
8729: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 8730: if (offloadtoSelIdx == 0) {
1.171 raeburn 8731: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
8732: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8733:
8734: } else {
1.171 raeburn 8735: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
8736: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 8737: }
8738: return;
8739: }
8740:
1.171 raeburn 8741: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 8742: if (type == '_LC_external') {
1.171 raeburn 8743: return;
1.150 raeburn 8744: }
1.171 raeburn 8745: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 8746: for (var i=0; i<typesRules.length; i++) {
8747: if (formname.elements[typesRules[i]].checked) {
8748: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 8749: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
8750: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 8751: } else {
1.171 raeburn 8752: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
8753: }
8754: }
8755: }
8756: return;
8757: }
8758:
8759: function balancerDeleteChange(balnum) {
8760: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8761: var baltotal = document.getElementById('loadbalancing_total').value;
8762: var addtarget;
8763: var removetarget;
8764: var action = 'delete';
8765: if (document.getElementById('loadbalancing_delete_'+balnum)) {
8766: var lonhost = hostitem.value;
8767: var currIdx = currBalancers.indexOf(lonhost);
8768: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
8769: if (currIdx != -1) {
8770: currBalancers.splice(currIdx,1);
8771: }
8772: addtarget = lonhost;
8773: } else {
8774: if (currIdx == -1) {
8775: currBalancers.push(lonhost);
8776: }
8777: removetarget = lonhost;
8778: action = 'undelete';
8779: }
8780: balancerChange(balnum,baltotal,action,addtarget,removetarget);
8781: }
8782: return;
8783: }
8784:
8785: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
8786: if (baltotal > 1) {
8787: var offloadtypes = new Array('primary','default');
8788: var alltargets = new Array('$alltargets');
8789: var insttypes = new Array('$allinsttypes');
8790: for (var i=0; i<baltotal; i++) {
8791: if (i != balnum) {
8792: for (var j=0; j<offloadtypes.length; j++) {
8793: var total = alltargets.length - 1;
8794: for (var k=0; k<total; k++) {
8795: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
8796: var server = serveritem.value;
8797: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8798: if (server == addtarget) {
8799: serveritem.disabled = '';
8800: }
8801: }
8802: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8803: if (server == removetarget) {
8804: serveritem.disabled = 'disabled';
8805: serveritem.checked = false;
8806: }
8807: }
8808: }
8809: }
8810: for (var j=0; j<insttypes.length; j++) {
8811: if (insttypes[j] != '_LC_external') {
8812: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
8813: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
8814: var currSel = singleserver.selectedIndex;
8815: var currVal = singleserver.options[currSel].value;
8816: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
8817: var numoptions = singleserver.options.length;
8818: var needsnew = 1;
8819: for (var k=0; k<numoptions; k++) {
8820: if (singleserver.options[k] == addtarget) {
8821: needsnew = 0;
8822: break;
8823: }
8824: }
8825: if (needsnew == 1) {
8826: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
8827: }
8828: }
8829: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
8830: singleserver.options.length = 0;
8831: if ((currVal) && (currVal != removetarget)) {
8832: singleserver.options[0] = new Option("","",false,false);
8833: } else {
8834: singleserver.options[0] = new Option("","",true,true);
8835: }
8836: var idx = 0;
8837: for (var m=0; m<alltargets.length; m++) {
8838: if (currBalancers.indexOf(alltargets[m]) == -1) {
8839: idx ++;
8840: if (currVal == alltargets[m]) {
8841: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
8842: } else {
8843: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
8844: }
8845: }
8846: }
8847: }
8848: }
8849: }
8850: }
1.150 raeburn 8851: }
8852: }
8853: }
8854: return;
8855: }
8856:
1.152 raeburn 8857: // ]]>
8858: </script>
8859:
8860: END
8861: }
8862:
8863: sub new_spares_js {
8864: my @sparestypes = ('primary','default');
8865: my $types = join("','",@sparestypes);
8866: my $select = &mt('Select');
8867: return <<"END";
8868:
8869: <script type="text/javascript">
8870: // <![CDATA[
8871:
8872: function updateNewSpares(formname,lonhost) {
8873: var types = new Array('$types');
8874: var include = new Array();
8875: var exclude = new Array();
8876: for (var i=0; i<types.length; i++) {
8877: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
8878: for (var j=0; j<spareboxes.length; j++) {
8879: if (formname.elements[spareboxes[j]].checked) {
8880: exclude.push(formname.elements[spareboxes[j]].value);
8881: } else {
8882: include.push(formname.elements[spareboxes[j]].value);
8883: }
8884: }
8885: }
8886: for (var i=0; i<types.length; i++) {
8887: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
8888: var selIdx = newSpare.selectedIndex;
8889: var currnew = newSpare.options[selIdx].value;
8890: var okSpares = new Array();
8891: for (var j=0; j<newSpare.options.length; j++) {
8892: var possible = newSpare.options[j].value;
8893: if (possible != '') {
8894: if (exclude.indexOf(possible) == -1) {
8895: okSpares.push(possible);
8896: } else {
8897: if (currnew == possible) {
8898: selIdx = 0;
8899: }
8900: }
8901: }
8902: }
8903: for (var k=0; k<include.length; k++) {
8904: if (okSpares.indexOf(include[k]) == -1) {
8905: okSpares.push(include[k]);
8906: }
8907: }
8908: okSpares.sort();
8909: newSpare.options.length = 0;
8910: if (selIdx == 0) {
8911: newSpare.options[0] = new Option("$select","",true,true);
8912: } else {
8913: newSpare.options[0] = new Option("$select","",false,false);
8914: }
8915: for (var m=0; m<okSpares.length; m++) {
8916: var idx = m+1;
8917: var selThis = 0;
8918: if (selIdx != 0) {
8919: if (okSpares[m] == currnew) {
8920: selThis = 1;
8921: }
8922: }
8923: if (selThis == 1) {
8924: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
8925: } else {
8926: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
8927: }
8928: }
8929: }
8930: return;
8931: }
8932:
8933: function checkNewSpares(lonhost,type) {
8934: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
8935: var chosen = newSpare.options[newSpare.selectedIndex].value;
8936: if (chosen != '') {
8937: var othertype;
8938: var othernewSpare;
8939: if (type == 'primary') {
8940: othernewSpare = document.getElementById('newspare_default_'+lonhost);
8941: }
8942: if (type == 'default') {
8943: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
8944: }
8945: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
8946: othernewSpare.selectedIndex = 0;
8947: }
8948: }
8949: return;
8950: }
8951:
8952: // ]]>
8953: </script>
8954:
8955: END
8956:
8957: }
8958:
8959: sub common_domprefs_js {
8960: return <<"END";
8961:
8962: <script type="text/javascript">
8963: // <![CDATA[
8964:
1.150 raeburn 8965: function getIndicesByName(formname,item) {
1.152 raeburn 8966: var group = new Array();
1.150 raeburn 8967: for (var i=0;i<formname.elements.length;i++) {
8968: if (formname.elements[i].name == item) {
1.152 raeburn 8969: group.push(formname.elements[i].id);
1.150 raeburn 8970: }
8971: }
1.152 raeburn 8972: return group;
1.150 raeburn 8973: }
8974:
8975: // ]]>
8976: </script>
8977:
8978: END
1.152 raeburn 8979:
1.150 raeburn 8980: }
8981:
1.165 raeburn 8982: sub recaptcha_js {
8983: my %lt = &captcha_phrases();
8984: return <<"END";
8985:
8986: <script type="text/javascript">
8987: // <![CDATA[
8988:
8989: function updateCaptcha(caller,context) {
8990: var privitem;
8991: var pubitem;
8992: var privtext;
8993: var pubtext;
8994: if (document.getElementById(context+'_recaptchapub')) {
8995: pubitem = document.getElementById(context+'_recaptchapub');
8996: } else {
8997: return;
8998: }
8999: if (document.getElementById(context+'_recaptchapriv')) {
9000: privitem = document.getElementById(context+'_recaptchapriv');
9001: } else {
9002: return;
9003: }
9004: if (document.getElementById(context+'_recaptchapubtxt')) {
9005: pubtext = document.getElementById(context+'_recaptchapubtxt');
9006: } else {
9007: return;
9008: }
9009: if (document.getElementById(context+'_recaptchaprivtxt')) {
9010: privtext = document.getElementById(context+'_recaptchaprivtxt');
9011: } else {
9012: return;
9013: }
9014: if (caller.checked) {
9015: if (caller.value == 'recaptcha') {
9016: pubitem.type = 'text';
9017: privitem.type = 'text';
9018: pubitem.size = '40';
9019: privitem.size = '40';
9020: pubtext.innerHTML = "$lt{'pub'}";
9021: privtext.innerHTML = "$lt{'priv'}";
9022: } else {
9023: pubitem.type = 'hidden';
9024: privitem.type = 'hidden';
9025: pubtext.innerHTML = '';
9026: privtext.innerHTML = '';
9027: }
9028: }
9029: return;
9030: }
9031:
9032: // ]]>
9033: </script>
9034:
9035: END
9036:
9037: }
9038:
9039: sub captcha_phrases {
9040: return &Apache::lonlocal::texthash (
9041: priv => 'Private key',
9042: pub => 'Public key',
9043: original => 'original (CAPTCHA)',
9044: recaptcha => 'successor (ReCAPTCHA)',
9045: notused => 'unused',
9046: );
9047: }
9048:
1.3 raeburn 9049: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>