Annotation of loncom/interface/domainprefs.pm, revision 1.212
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.212 ! raeburn 4: # $Id: domainprefs.pm,v 1.211 2013/10/06 20:33:45 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.210 raeburn 89: number of rows displayed on the page, and $action is the context (quotas,
1.163 raeburn 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,
1.197 raeburn 97: used by course owners to request creation of a course, and to display/store
98: default quota sizes for authoring spaces.
1.101 raeburn 99:
100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
106: (official, unofficial and community). In each case the radio buttons allow the
107: selection of one of four values:
108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.69 raeburn 167: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 168: use LONCAPA::Enrollment;
1.81 raeburn 169: use LONCAPA::lonauthcgi();
1.9 raeburn 170: use File::Copy;
1.43 raeburn 171: use Locale::Language;
1.62 raeburn 172: use DateTime::TimeZone;
1.68 raeburn 173: use DateTime::Locale;
1.1 raeburn 174:
1.155 raeburn 175: my $registered_cleanup;
176: my $modified_urls;
177:
1.1 raeburn 178: sub handler {
179: my $r=shift;
180: if ($r->header_only) {
181: &Apache::loncommon::content_type($r,'text/html');
182: $r->send_http_header;
183: return OK;
184: }
185:
1.91 raeburn 186: my $context = 'domain';
1.1 raeburn 187: my $dom = $env{'request.role.domain'};
1.5 albertel 188: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 189: if (&Apache::lonnet::allowed('mau',$dom)) {
190: &Apache::loncommon::content_type($r,'text/html');
191: $r->send_http_header;
192: } else {
193: $env{'user.error.msg'}=
194: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
195: return HTTP_NOT_ACCEPTABLE;
196: }
1.155 raeburn 197:
198: $registered_cleanup=0;
199: @{$modified_urls}=();
200:
1.1 raeburn 201: &Apache::lonhtmlcommon::clear_breadcrumbs();
202: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 203: ['phase','actions']);
1.30 raeburn 204: my $phase = 'pickactions';
1.3 raeburn 205: if ( exists($env{'form.phase'}) ) {
206: $phase = $env{'form.phase'};
207: }
1.150 raeburn 208: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 209: my %domconfig =
1.6 raeburn 210: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 211: 'quotas','autoenroll','autoupdate','autocreate',
212: 'directorysrch','usercreation','usermodification',
213: 'contacts','defaults','scantron','coursecategories',
214: 'serverstatuses','requestcourses','helpsettings',
1.163 raeburn 215: 'coursedefaults','usersessions','loadbalancing',
216: 'requestauthor'],$dom);
1.43 raeburn 217: my @prefs_order = ('rolecolors','login','defaults','quotas','autoenroll',
1.125 raeburn 218: 'autoupdate','autocreate','directorysrch','contacts',
1.48 raeburn 219: 'usercreation','usermodification','scantron',
1.163 raeburn 220: 'requestcourses','requestauthor','coursecategories',
221: 'serverstatuses','helpsettings',
1.137 raeburn 222: 'coursedefaults','usersessions');
1.171 raeburn 223: my %existing;
224: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
225: %existing = %{$domconfig{'loadbalancing'}};
226: }
227: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 228: push(@prefs_order,'loadbalancing');
229: }
1.30 raeburn 230: my %prefs = (
231: 'rolecolors' =>
232: { text => 'Default color schemes',
1.67 raeburn 233: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 234: header => [{col1 => 'Student Settings',
235: col2 => '',},
236: {col1 => 'Coordinator Settings',
237: col2 => '',},
238: {col1 => 'Author Settings',
239: col2 => '',},
240: {col1 => 'Administrator Settings',
241: col2 => '',}],
242: },
1.110 raeburn 243: 'login' =>
1.30 raeburn 244: { text => 'Log-in page options',
1.67 raeburn 245: help => 'Domain_Configuration_Login_Page',
1.168 raeburn 246: header => [{col1 => 'Log-in Page Items',
247: col2 => '',},
248: {col1 => 'Log-in Help',
249: col2 => 'Value'}],
1.30 raeburn 250: },
1.43 raeburn 251: 'defaults' =>
1.141 raeburn 252: { text => 'Default authentication/language/timezone/portal',
1.67 raeburn 253: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 254: header => [{col1 => 'Setting',
255: col2 => 'Value'}],
256: },
1.30 raeburn 257: 'quotas' =>
1.197 raeburn 258: { text => 'Blogs, personal web pages, webDAV/quotas, portfolios',
1.67 raeburn 259: help => 'Domain_Configuration_Quotas',
1.77 raeburn 260: header => [{col1 => 'User affiliation',
1.72 raeburn 261: col2 => 'Available tools',
1.197 raeburn 262: col3 => 'Quotas, Mb; (Authoring requires role)',}],
1.30 raeburn 263: },
264: 'autoenroll' =>
265: { text => 'Auto-enrollment settings',
1.67 raeburn 266: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 267: header => [{col1 => 'Configuration setting',
268: col2 => 'Value(s)'}],
269: },
270: 'autoupdate' =>
271: { text => 'Auto-update settings',
1.67 raeburn 272: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 273: header => [{col1 => 'Setting',
274: col2 => 'Value',},
1.131 raeburn 275: {col1 => 'Setting',
276: col2 => 'Affiliation'},
1.43 raeburn 277: {col1 => 'User population',
1.131 raeburn 278: col2 => 'Updateable user data'}],
1.30 raeburn 279: },
1.125 raeburn 280: 'autocreate' =>
281: { text => 'Auto-course creation settings',
282: help => 'Domain_Configuration_Auto_Creation',
283: header => [{col1 => 'Configuration Setting',
284: col2 => 'Value',}],
285: },
1.30 raeburn 286: 'directorysrch' =>
287: { text => 'Institutional directory searches',
1.67 raeburn 288: help => 'Domain_Configuration_InstDirectory_Search',
1.30 raeburn 289: header => [{col1 => 'Setting',
290: col2 => 'Value',}],
291: },
292: 'contacts' =>
293: { text => 'Contact Information',
1.67 raeburn 294: help => 'Domain_Configuration_Contact_Info',
1.30 raeburn 295: header => [{col1 => 'Setting',
296: col2 => 'Value',}],
297: },
298:
299: 'usercreation' =>
300: { text => 'User creation',
1.67 raeburn 301: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 302: header => [{col1 => 'Format rule type',
303: col2 => 'Format rules in force'},
1.34 raeburn 304: {col1 => 'User account creation',
305: col2 => 'Usernames which may be created',},
1.30 raeburn 306: {col1 => 'Context',
1.43 raeburn 307: col2 => 'Assignable authentication types'}],
1.30 raeburn 308: },
1.69 raeburn 309: 'usermodification' =>
1.33 raeburn 310: { text => 'User modification',
1.67 raeburn 311: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 312: header => [{col1 => 'Target user has role',
313: col2 => 'User information updateable in author context'},
314: {col1 => 'Target user has role',
1.63 raeburn 315: col2 => 'User information updateable in course context'},
316: {col1 => "Status of user",
317: col2 => 'Information settable when self-creating account (if directory data blank)'}],
1.33 raeburn 318: },
1.69 raeburn 319: 'scantron' =>
1.95 www 320: { text => 'Bubblesheet format file',
1.67 raeburn 321: help => 'Domain_Configuration_Scantron_Format',
1.46 raeburn 322: header => [ {col1 => 'Item',
323: col2 => '',
324: }],
325: },
1.86 raeburn 326: 'requestcourses' =>
327: {text => 'Request creation of courses',
328: help => 'Domain_Configuration_Request_Courses',
329: header => [{col1 => 'User affiliation',
1.102 raeburn 330: col2 => 'Availability/Processing of requests',},
331: {col1 => 'Setting',
332: col2 => 'Value'}],
1.86 raeburn 333: },
1.163 raeburn 334: 'requestauthor' =>
335: {text => 'Request authoring space',
336: help => 'Domain_Configuration_Request_Author',
337: header => [{col1 => 'User affiliation',
338: col2 => 'Availability/Processing of requests',},
339: {col1 => 'Setting',
340: col2 => 'Value'}],
341: },
1.69 raeburn 342: 'coursecategories' =>
1.120 raeburn 343: { text => 'Cataloging of courses/communities',
1.67 raeburn 344: help => 'Domain_Configuration_Cataloging_Courses',
1.69 raeburn 345: header => [{col1 => 'Category settings',
1.57 raeburn 346: col2 => '',},
347: {col1 => 'Categories',
348: col2 => '',
349: }],
1.69 raeburn 350: },
351: 'serverstatuses' =>
1.77 raeburn 352: {text => 'Access to server status pages',
1.69 raeburn 353: help => 'Domain_Configuration_Server_Status',
354: header => [{col1 => 'Status Page',
355: col2 => 'Other named users',
356: col3 => 'Specific IPs',
357: }],
358: },
1.118 jms 359: 'helpsettings' =>
360: {text => 'Help page settings',
361: help => 'Domain_Configuration_Help_Settings',
1.166 raeburn 362: header => [{col1 => 'Help Settings (logged-in users)',
363: col2 => 'Value'}],
1.118 jms 364: },
1.121 raeburn 365: 'coursedefaults' =>
366: {text => 'Course/Community defaults',
367: help => 'Domain_Configuration_Course_Defaults',
1.139 raeburn 368: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
369: col2 => 'Value',},
370: {col1 => 'Defaults which can be overridden for each course by a DC',
371: col2 => 'Value',},],
1.121 raeburn 372: },
1.120 raeburn 373: 'privacy' =>
374: {text => 'User Privacy',
375: help => 'Domain_Configuration_User_Privacy',
376: header => [{col1 => 'Setting',
377: col2 => 'Value',}],
378: },
1.141 raeburn 379: 'usersessions' =>
1.145 raeburn 380: {text => 'User session hosting/offloading',
1.137 raeburn 381: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 382: header => [{col1 => 'Domain server',
383: col2 => 'Servers to offload sessions to when busy'},
384: {col1 => 'Hosting of users from other domains',
1.137 raeburn 385: col2 => 'Rules'},
386: {col1 => "Hosting domain's own users elsewhere",
387: col2 => 'Rules'}],
388: },
1.150 raeburn 389: 'loadbalancing' =>
1.185 raeburn 390: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 391: help => 'Domain_Configuration_Load_Balancing',
1.171 raeburn 392: header => [{col1 => 'Balancers',
1.150 raeburn 393: col2 => 'Default destinations',
1.183 bisitz 394: col3 => 'User affiliation',
1.150 raeburn 395: col4 => 'Overrides'},
396: ],
397: },
1.3 raeburn 398: );
1.110 raeburn 399: if (keys(%servers) > 1) {
400: $prefs{'login'} = { text => 'Log-in page options',
401: help => 'Domain_Configuration_Login_Page',
402: header => [{col1 => 'Log-in Service',
403: col2 => 'Server Setting',},
404: {col1 => 'Log-in Page Items',
1.168 raeburn 405: col2 => ''},
406: {col1 => 'Log-in Help',
407: col2 => 'Value'}],
1.110 raeburn 408: };
409: }
1.174 foxr 410:
1.6 raeburn 411: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 412: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 413: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 414: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 415: text=>"Settings to display/modify"});
1.9 raeburn 416: my $confname = $dom.'-domainconfig';
1.174 foxr 417:
1.3 raeburn 418: if ($phase eq 'process') {
1.212 ! raeburn 419: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
! 420: \%prefs,\%domconfig,$confname,\@roles);
! 421: if (ref($result) eq 'HASH') {
1.205 raeburn 422: $r->rflush();
1.212 ! raeburn 423: &devalidate_remote_domconfs($dom,$result);
1.205 raeburn 424: }
1.30 raeburn 425: } elsif ($phase eq 'display') {
1.192 raeburn 426: my $js = &recaptcha_js().
427: &credits_js();
1.171 raeburn 428: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 429: my ($othertitle,$usertypes,$types) =
430: &Apache::loncommon::sorted_inst_types($dom);
1.171 raeburn 431: $js .= &lonbalance_targets_js($dom,$types,\%servers,
432: $domconfig{'loadbalancing'}).
1.170 raeburn 433: &new_spares_js().
434: &common_domprefs_js().
435: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 436: }
1.150 raeburn 437: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 438: } else {
1.180 raeburn 439: # check if domconfig user exists for the domain.
440: my $servadm = $r->dir_config('lonAdmEMail');
441: my ($configuserok,$author_ok,$switchserver) =
442: &config_check($dom,$confname,$servadm);
443: unless ($configuserok eq 'ok') {
1.181 raeburn 444: &Apache::lonconfigsettings::print_header($r,$phase,$context);
445: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
1.210 raeburn 446: $confname).
1.181 raeburn 447: '<br />'
448: );
1.180 raeburn 449: if ($switchserver) {
1.181 raeburn 450: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
451: '<br />'.
452: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
453: '<br />'.
454: &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).
455: '<br />'.
456: &mt('To do that now, use the following link: [_1]',$switchserver)
457: );
458: } else {
459: $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.').
460: '<br />'.
461: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
462: );
1.180 raeburn 463: }
464: $r->print(&Apache::loncommon::end_page());
465: return OK;
466: }
1.21 raeburn 467: if (keys(%domconfig) == 0) {
468: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 469: my @ids=&Apache::lonnet::current_machine_ids();
470: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 471: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 472: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 473: my $custom_img_count = 0;
474: foreach my $img (@loginimages) {
475: if ($designhash{$dom.'.login.'.$img} ne '') {
476: $custom_img_count ++;
477: }
478: }
479: foreach my $role (@roles) {
480: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
481: $custom_img_count ++;
482: }
483: }
484: if ($custom_img_count > 0) {
1.94 raeburn 485: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 486: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 487: $r->print(
488: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
489: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
490: &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 />'.
491: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
492: if ($switch_server) {
1.30 raeburn 493: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 494: }
1.91 raeburn 495: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 496: return OK;
497: }
498: }
499: }
1.91 raeburn 500: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 501: }
502: return OK;
503: }
504:
505: sub process_changes {
1.205 raeburn 506: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 507: my %domconfig;
508: if (ref($values) eq 'HASH') {
509: %domconfig = %{$values};
510: }
1.3 raeburn 511: my $output;
512: if ($action eq 'login') {
1.205 raeburn 513: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 514: } elsif ($action eq 'rolecolors') {
1.9 raeburn 515: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.205 raeburn 516: $lastactref,%domconfig);
1.3 raeburn 517: } elsif ($action eq 'quotas') {
1.212 ! raeburn 518: $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
1.3 raeburn 519: } elsif ($action eq 'autoenroll') {
1.205 raeburn 520: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 521: } elsif ($action eq 'autoupdate') {
522: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 523: } elsif ($action eq 'autocreate') {
524: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 525: } elsif ($action eq 'directorysrch') {
526: $output = &modify_directorysrch($dom,%domconfig);
1.27 raeburn 527: } elsif ($action eq 'usercreation') {
1.28 raeburn 528: $output = &modify_usercreation($dom,%domconfig);
1.33 raeburn 529: } elsif ($action eq 'usermodification') {
530: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 531: } elsif ($action eq 'contacts') {
1.205 raeburn 532: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 533: } elsif ($action eq 'defaults') {
1.212 ! raeburn 534: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 535: } elsif ($action eq 'scantron') {
1.205 raeburn 536: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 537: } elsif ($action eq 'coursecategories') {
538: $output = &modify_coursecategories($dom,%domconfig);
1.69 raeburn 539: } elsif ($action eq 'serverstatuses') {
540: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 541: } elsif ($action eq 'requestcourses') {
1.212 ! raeburn 542: $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
1.163 raeburn 543: } elsif ($action eq 'requestauthor') {
1.212 ! raeburn 544: $output = &modify_quotas($dom,$action,$lastactref,%domconfig);
1.118 jms 545: } elsif ($action eq 'helpsettings') {
1.122 jms 546: $output = &modify_helpsettings($r,$dom,$confname,%domconfig);
1.121 raeburn 547: } elsif ($action eq 'coursedefaults') {
1.212 ! raeburn 548: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.137 raeburn 549: } elsif ($action eq 'usersessions') {
1.212 ! raeburn 550: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 551: } elsif ($action eq 'loadbalancing') {
552: $output = &modify_loadbalancing($dom,%domconfig);
1.3 raeburn 553: }
554: return $output;
555: }
556:
557: sub print_config_box {
1.9 raeburn 558: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 559: my $rowtotal = 0;
1.49 raeburn 560: my $output;
561: if ($action eq 'coursecategories') {
562: $output = &coursecategories_javascript($settings);
1.91 raeburn 563: }
1.49 raeburn 564: $output .=
1.30 raeburn 565: '<table class="LC_nested_outer">
1.3 raeburn 566: <tr>
1.66 raeburn 567: <th align="left" valign="middle"><span class="LC_nobreak">'.
568: &mt($item->{text}).' '.
569: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
570: '</tr>';
1.30 raeburn 571: $rowtotal ++;
1.110 raeburn 572: my $numheaders = 1;
573: if (ref($item->{'header'}) eq 'ARRAY') {
574: $numheaders = scalar(@{$item->{'header'}});
575: }
576: if ($numheaders > 1) {
1.64 raeburn 577: my $colspan = '';
1.145 raeburn 578: my $rightcolspan = '';
1.210 raeburn 579: if (($action eq 'rolecolors') || ($action eq 'coursecategories') ||
1.168 raeburn 580: (($action eq 'login') && ($numheaders < 3))) {
1.64 raeburn 581: $colspan = ' colspan="2"';
582: }
1.145 raeburn 583: if ($action eq 'usersessions') {
584: $rightcolspan = ' colspan="3"';
585: }
1.30 raeburn 586: $output .= '
1.3 raeburn 587: <tr>
588: <td>
589: <table class="LC_nested">
590: <tr class="LC_info_row">
1.59 bisitz 591: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 592: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 593: </tr>';
1.69 raeburn 594: $rowtotal ++;
1.6 raeburn 595: if ($action eq 'autoupdate') {
1.30 raeburn 596: $output .= &print_autoupdate('top',$dom,$settings,\$rowtotal);
1.28 raeburn 597: } elsif ($action eq 'usercreation') {
1.33 raeburn 598: $output .= &print_usercreation('top',$dom,$settings,\$rowtotal);
599: } elsif ($action eq 'usermodification') {
600: $output .= &print_usermodification('top',$dom,$settings,\$rowtotal);
1.57 raeburn 601: } elsif ($action eq 'coursecategories') {
602: $output .= &print_coursecategories('top',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 603: } elsif ($action eq 'login') {
1.168 raeburn 604: if ($numheaders == 3) {
605: $colspan = ' colspan="2"';
606: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
607: } else {
608: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
609: }
1.102 raeburn 610: } elsif ($action eq 'requestcourses') {
611: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.163 raeburn 612: } elsif ($action eq 'requestauthor') {
613: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.137 raeburn 614: } elsif ($action eq 'usersessions') {
615: $output .= &print_usersessions('top',$dom,$settings,\$rowtotal);
1.122 jms 616: } elsif ($action eq 'rolecolors') {
1.30 raeburn 617: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.139 raeburn 618: } elsif ($action eq 'coursedefaults') {
619: $output .= &print_coursedefaults('top',$dom,$settings,\$rowtotal);
1.6 raeburn 620: }
1.30 raeburn 621: $output .= '
1.6 raeburn 622: </table>
623: </td>
624: </tr>
625: <tr>
626: <td>
627: <table class="LC_nested">
628: <tr class="LC_info_row">
1.59 bisitz 629: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>';
1.57 raeburn 630: $output .= '
1.59 bisitz 631: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 632: </tr>';
633: $rowtotal ++;
1.6 raeburn 634: if ($action eq 'autoupdate') {
1.131 raeburn 635: $output .= &print_autoupdate('middle',$dom,$settings,\$rowtotal).'
636: </table>
637: </td>
638: </tr>
639: <tr>
640: <td>
641: <table class="LC_nested">
642: <tr class="LC_info_row">
643: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
644: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
645: &print_autoupdate('bottom',$dom,$settings,\$rowtotal);
646: $rowtotal ++;
1.28 raeburn 647: } elsif ($action eq 'usercreation') {
1.34 raeburn 648: $output .= &print_usercreation('middle',$dom,$settings,\$rowtotal).'
649: </table>
650: </td>
651: </tr>
652: <tr>
653: <td>
654: <table class="LC_nested">
655: <tr class="LC_info_row">
1.59 bisitz 656: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
657: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.34 raeburn 658: &print_usercreation('bottom',$dom,$settings,\$rowtotal);
659: $rowtotal ++;
1.33 raeburn 660: } elsif ($action eq 'usermodification') {
1.63 raeburn 661: $output .= &print_usermodification('middle',$dom,$settings,\$rowtotal).'
662: </table>
663: </td>
664: </tr>
665: <tr>
666: <td>
667: <table class="LC_nested">
668: <tr class="LC_info_row">
669: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
670: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
671: &print_usermodification('bottom',$dom,$settings,\$rowtotal);
672: $rowtotal ++;
1.57 raeburn 673: } elsif ($action eq 'coursecategories') {
674: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.110 raeburn 675: } elsif ($action eq 'login') {
1.168 raeburn 676: if ($numheaders == 3) {
677: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
678: </table>
679: </td>
680: </tr>
681: <tr>
682: <td>
683: <table class="LC_nested">
684: <tr class="LC_info_row">
685: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
686: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
687: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
688: $rowtotal ++;
689: } else {
690: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
691: }
1.102 raeburn 692: } elsif ($action eq 'requestcourses') {
1.163 raeburn 693: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
694: } elsif ($action eq 'requestauthor') {
695: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.137 raeburn 696: } elsif ($action eq 'usersessions') {
1.145 raeburn 697: $output .= &print_usersessions('middle',$dom,$settings,\$rowtotal).'
698: </table>
699: </td>
700: </tr>
701: <tr>
702: <td>
703: <table class="LC_nested">
704: <tr class="LC_info_row">
705: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
706: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
707: &print_usersessions('bottom',$dom,$settings,\$rowtotal);
708: $rowtotal ++;
1.139 raeburn 709: } elsif ($action eq 'coursedefaults') {
710: $output .= &print_coursedefaults('bottom',$dom,$settings,\$rowtotal);
1.122 jms 711: } elsif ($action eq 'rolecolors') {
1.30 raeburn 712: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 713: </table>
714: </td>
715: </tr>
716: <tr>
717: <td>
718: <table class="LC_nested">
719: <tr class="LC_info_row">
1.69 raeburn 720: <td class="LC_left_item"'.$colspan.' valign="top">'.
721: &mt($item->{'header'}->[2]->{'col1'}).'</td>
722: <td class="LC_right_item" valign="top">'.
723: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 724: </tr>'.
1.30 raeburn 725: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 726: </table>
727: </td>
728: </tr>
729: <tr>
730: <td>
731: <table class="LC_nested">
732: <tr class="LC_info_row">
1.59 bisitz 733: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
734: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 735: </tr>'.
1.30 raeburn 736: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
737: $rowtotal += 2;
1.6 raeburn 738: }
1.3 raeburn 739: } else {
1.30 raeburn 740: $output .= '
1.3 raeburn 741: <tr>
742: <td>
743: <table class="LC_nested">
1.30 raeburn 744: <tr class="LC_info_row">';
1.24 raeburn 745: if (($action eq 'login') || ($action eq 'directorysrch')) {
1.30 raeburn 746: $output .= '
1.59 bisitz 747: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 748: } elsif ($action eq 'serverstatuses') {
749: $output .= '
750: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
751: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
752:
1.6 raeburn 753: } else {
1.30 raeburn 754: $output .= '
1.69 raeburn 755: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
756: }
1.72 raeburn 757: if (defined($item->{'header'}->[0]->{'col3'})) {
758: $output .= '<td class="LC_left_item" valign="top">'.
759: &mt($item->{'header'}->[0]->{'col2'});
760: if ($action eq 'serverstatuses') {
761: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
762: }
1.69 raeburn 763: } else {
764: $output .= '<td class="LC_right_item" valign="top">'.
765: &mt($item->{'header'}->[0]->{'col2'});
766: }
767: $output .= '</td>';
768: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 769: if (defined($item->{'header'}->[0]->{'col4'})) {
770: $output .= '<td class="LC_left_item" valign="top">'.
771: &mt($item->{'header'}->[0]->{'col3'});
772: } else {
773: $output .= '<td class="LC_right_item" valign="top">'.
774: &mt($item->{'header'}->[0]->{'col3'});
775: }
1.69 raeburn 776: if ($action eq 'serverstatuses') {
777: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
778: }
779: $output .= '</td>';
1.6 raeburn 780: }
1.150 raeburn 781: if ($item->{'header'}->[0]->{'col4'}) {
782: $output .= '<td class="LC_right_item" valign="top">'.
783: &mt($item->{'header'}->[0]->{'col4'});
784: }
1.69 raeburn 785: $output .= '</tr>';
1.48 raeburn 786: $rowtotal ++;
1.168 raeburn 787: if ($action eq 'quotas') {
1.86 raeburn 788: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.3 raeburn 789: } elsif ($action eq 'autoenroll') {
1.30 raeburn 790: $output .= &print_autoenroll($dom,$settings,\$rowtotal);
1.125 raeburn 791: } elsif ($action eq 'autocreate') {
792: $output .= &print_autocreate($dom,$settings,\$rowtotal);
1.23 raeburn 793: } elsif ($action eq 'directorysrch') {
1.30 raeburn 794: $output .= &print_directorysrch($dom,$settings,\$rowtotal);
1.28 raeburn 795: } elsif ($action eq 'contacts') {
1.30 raeburn 796: $output .= &print_contacts($dom,$settings,\$rowtotal);
1.43 raeburn 797: } elsif ($action eq 'defaults') {
1.212 ! raeburn 798: $output .= &print_defaults($dom,$settings,\$rowtotal);
1.46 raeburn 799: } elsif ($action eq 'scantron') {
800: $output .= &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
1.69 raeburn 801: } elsif ($action eq 'serverstatuses') {
802: $output .= &print_serverstatuses($dom,$settings,\$rowtotal);
1.118 jms 803: } elsif ($action eq 'helpsettings') {
1.168 raeburn 804: $output .= &print_helpsettings($dom,$confname,$settings,\$rowtotal);
1.150 raeburn 805: } elsif ($action eq 'loadbalancing') {
806: $output .= &print_loadbalancing($dom,$settings,\$rowtotal);
1.121 raeburn 807: }
1.3 raeburn 808: }
1.30 raeburn 809: $output .= '
1.3 raeburn 810: </table>
811: </td>
812: </tr>
1.30 raeburn 813: </table><br />';
814: return ($output,$rowtotal);
1.1 raeburn 815: }
816:
1.3 raeburn 817: sub print_login {
1.168 raeburn 818: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.110 raeburn 819: my ($css_class,$datatable);
1.6 raeburn 820: my %choices = &login_choices();
1.110 raeburn 821:
1.168 raeburn 822: if ($caller eq 'service') {
1.149 raeburn 823: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 824: my $choice = $choices{'disallowlogin'};
825: $css_class = ' class="LC_odd_row"';
1.128 raeburn 826: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 827: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 828: '<th>'.$choices{'server'}.'</th>'.
829: '<th>'.$choices{'serverpath'}.'</th>'.
830: '<th>'.$choices{'custompath'}.'</th>'.
831: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 832: my %disallowed;
833: if (ref($settings) eq 'HASH') {
834: if (ref($settings->{'loginvia'}) eq 'HASH') {
835: %disallowed = %{$settings->{'loginvia'}};
836: }
837: }
838: foreach my $lonhost (sort(keys(%servers))) {
839: my $direct = 'selected="selected"';
1.128 raeburn 840: if (ref($disallowed{$lonhost}) eq 'HASH') {
841: if ($disallowed{$lonhost}{'server'} ne '') {
842: $direct = '';
843: }
1.110 raeburn 844: }
1.115 raeburn 845: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 846: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 847: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
848: '</option>';
1.184 raeburn 849: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 850: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 851: my $selected = '';
1.128 raeburn 852: if (ref($disallowed{$lonhost}) eq 'HASH') {
853: if ($hostid eq $disallowed{$lonhost}{'server'}) {
854: $selected = 'selected="selected"';
855: }
1.110 raeburn 856: }
857: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
858: $servers{$hostid}.'</option>';
859: }
1.128 raeburn 860: $datatable .= '</select></td>'.
861: '<td><select name="'.$lonhost.'_serverpath">';
862: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
863: my $pathname = $path;
864: if ($path eq 'custom') {
865: $pathname = &mt('Custom Path').' ->';
866: }
867: my $selected = '';
868: if (ref($disallowed{$lonhost}) eq 'HASH') {
869: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
870: $selected = 'selected="selected"';
871: }
872: } elsif ($path eq '') {
873: $selected = 'selected="selected"';
874: }
875: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
876: }
877: $datatable .= '</select></td>';
878: my ($custom,$exempt);
879: if (ref($disallowed{$lonhost}) eq 'HASH') {
880: $custom = $disallowed{$lonhost}{'custompath'};
881: $exempt = $disallowed{$lonhost}{'exempt'};
882: }
883: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
884: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
885: '</tr>';
1.110 raeburn 886: }
887: $datatable .= '</table></td></tr>';
888: return $datatable;
1.168 raeburn 889: } elsif ($caller eq 'page') {
890: my %defaultchecked = (
891: 'coursecatalog' => 'on',
1.188 raeburn 892: 'helpdesk' => 'on',
1.168 raeburn 893: 'adminmail' => 'off',
894: 'newuser' => 'off',
895: );
1.188 raeburn 896: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.168 raeburn 897: my (%checkedon,%checkedoff);
1.42 raeburn 898: foreach my $item (@toggles) {
1.168 raeburn 899: if ($defaultchecked{$item} eq 'on') {
900: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 901: $checkedoff{$item} = ' ';
1.168 raeburn 902: } elsif ($defaultchecked{$item} eq 'off') {
903: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 904: $checkedon{$item} = ' ';
905: }
1.1 raeburn 906: }
1.168 raeburn 907: my @images = ('img','logo','domlogo','login');
908: my @logintext = ('textcol','bgcol');
909: my @bgs = ('pgbg','mainbg','sidebg');
910: my @links = ('link','alink','vlink');
911: my %designhash = &Apache::loncommon::get_domainconf($dom);
912: my %defaultdesign = %Apache::loncommon::defaultdesign;
913: my (%is_custom,%designs);
914: my %defaults = (
915: font => $defaultdesign{'login.font'},
916: );
1.6 raeburn 917: foreach my $item (@images) {
1.168 raeburn 918: $defaults{$item} = $defaultdesign{'login.'.$item};
919: $defaults{'showlogo'}{$item} = 1;
920: }
921: foreach my $item (@bgs) {
922: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 923: }
1.41 raeburn 924: foreach my $item (@logintext) {
1.168 raeburn 925: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 926: }
1.168 raeburn 927: foreach my $item (@links) {
928: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 929: }
1.168 raeburn 930: if (ref($settings) eq 'HASH') {
931: foreach my $item (@toggles) {
932: if ($settings->{$item} eq '1') {
933: $checkedon{$item} = ' checked="checked" ';
934: $checkedoff{$item} = ' ';
935: } elsif ($settings->{$item} eq '0') {
936: $checkedoff{$item} = ' checked="checked" ';
937: $checkedon{$item} = ' ';
938: }
939: }
940: foreach my $item (@images) {
941: if (defined($settings->{$item})) {
942: $designs{$item} = $settings->{$item};
943: $is_custom{$item} = 1;
944: }
945: if (defined($settings->{'showlogo'}{$item})) {
946: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
947: }
948: }
949: foreach my $item (@logintext) {
950: if ($settings->{$item} ne '') {
951: $designs{'logintext'}{$item} = $settings->{$item};
952: $is_custom{$item} = 1;
953: }
954: }
955: if ($settings->{'font'} ne '') {
956: $designs{'font'} = $settings->{'font'};
957: $is_custom{'font'} = 1;
958: }
959: foreach my $item (@bgs) {
960: if ($settings->{$item} ne '') {
961: $designs{'bgs'}{$item} = $settings->{$item};
962: $is_custom{$item} = 1;
963: }
964: }
965: foreach my $item (@links) {
966: if ($settings->{$item} ne '') {
967: $designs{'links'}{$item} = $settings->{$item};
968: $is_custom{$item} = 1;
969: }
970: }
971: } else {
972: if ($designhash{$dom.'.login.font'} ne '') {
973: $designs{'font'} = $designhash{$dom.'.login.font'};
974: $is_custom{'font'} = 1;
975: }
976: foreach my $item (@images) {
977: if ($designhash{$dom.'.login.'.$item} ne '') {
978: $designs{$item} = $designhash{$dom.'.login.'.$item};
979: $is_custom{$item} = 1;
980: }
981: }
982: foreach my $item (@bgs) {
983: if ($designhash{$dom.'.login.'.$item} ne '') {
984: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
985: $is_custom{$item} = 1;
986: }
1.6 raeburn 987: }
1.168 raeburn 988: foreach my $item (@links) {
989: if ($designhash{$dom.'.login.'.$item} ne '') {
990: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
991: $is_custom{$item} = 1;
992: }
1.6 raeburn 993: }
994: }
1.168 raeburn 995: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
996: logo => 'Institution Logo',
997: domlogo => 'Domain Logo',
998: login => 'Login box');
999: my $itemcount = 1;
1000: foreach my $item (@toggles) {
1001: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1002: $datatable .=
1003: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1004: '</td><td>'.
1005: '<span class="LC_nobreak"><label><input type="radio" name="'.
1006: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1007: '</label> <label><input type="radio" name="'.$item.'"'.
1008: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1009: '</tr>';
1010: $itemcount ++;
1.6 raeburn 1011: }
1.168 raeburn 1012: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1013: $datatable .= '</tr></table></td></tr>';
1014: } elsif ($caller eq 'help') {
1015: my ($defaulturl,$defaulttype,%url,%type,%lt,%langchoices);
1016: my $switchserver = &check_switchserver($dom,$confname);
1017: my $itemcount = 1;
1018: $defaulturl = '/adm/loginproblems.html';
1019: $defaulttype = 'default';
1020: %lt = &Apache::lonlocal::texthash (
1021: del => 'Delete?',
1022: rep => 'Replace:',
1023: upl => 'Upload:',
1024: default => 'Default',
1025: custom => 'Custom',
1026: );
1027: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1028: my @currlangs;
1029: if (ref($settings) eq 'HASH') {
1030: if (ref($settings->{'helpurl'}) eq 'HASH') {
1031: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1032: next if ($settings->{'helpurl'}{$key} eq '');
1033: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1034: $type{$key} = 'custom';
1035: unless ($key eq 'nolang') {
1036: push(@currlangs,$key);
1037: }
1038: }
1039: } elsif ($settings->{'helpurl'} ne '') {
1040: $type{'nolang'} = 'custom';
1041: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1042: }
1043: }
1.168 raeburn 1044: foreach my $lang ('nolang',sort(@currlangs)) {
1045: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1046: $datatable .= '<tr'.$css_class.'>';
1047: if ($url{$lang} eq '') {
1048: $url{$lang} = $defaulturl;
1049: }
1050: if ($type{$lang} eq '') {
1051: $type{$lang} = $defaulttype;
1052: }
1053: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1054: if ($lang eq 'nolang') {
1055: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1056: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1057: } else {
1058: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1059: $langchoices{$lang},
1060: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1061: }
1062: $datatable .= '</span></td>'."\n".
1063: '<td class="LC_left_item">';
1064: if ($type{$lang} eq 'custom') {
1065: $datatable .= '<span class="LC_nobreak"><label>'.
1066: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1067: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1068: } else {
1069: $datatable .= $lt{'upl'};
1070: }
1071: $datatable .='<br />';
1072: if ($switchserver) {
1073: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1074: } else {
1075: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1076: }
1.168 raeburn 1077: $datatable .= '</td></tr>';
1078: $itemcount ++;
1.6 raeburn 1079: }
1.168 raeburn 1080: my @addlangs;
1081: foreach my $lang (sort(keys(%langchoices))) {
1082: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1083: push(@addlangs,$lang);
1084: }
1085: if (@addlangs > 0) {
1086: my %toadd;
1087: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1088: $toadd{''} = &mt('Select');
1089: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1090: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1091: &mt('Add log-in help page for a specific language:').' '.
1092: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1093: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1094: if ($switchserver) {
1095: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1096: } else {
1097: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1098: }
1.168 raeburn 1099: $datatable .= '</td></tr>';
1.169 raeburn 1100: $itemcount ++;
1.6 raeburn 1101: }
1.169 raeburn 1102: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.1 raeburn 1103: }
1.6 raeburn 1104: return $datatable;
1105: }
1106:
1107: sub login_choices {
1108: my %choices =
1109: &Apache::lonlocal::texthash (
1.116 bisitz 1110: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1111: adminmail => "Display Administrator's E-mail Address?",
1.188 raeburn 1112: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1113: disallowlogin => "Login page requests redirected",
1114: hostid => "Server",
1.128 raeburn 1115: server => "Redirect to:",
1116: serverpath => "Path",
1117: custompath => "Custom",
1118: exempt => "Exempt IP(s)",
1.110 raeburn 1119: directlogin => "No redirect",
1120: newuser => "Link to create a user account",
1121: img => "Header",
1122: logo => "Main Logo",
1123: domlogo => "Domain Logo",
1124: login => "Log-in Header",
1125: textcol => "Text color",
1126: bgcol => "Box color",
1127: bgs => "Background colors",
1128: links => "Link colors",
1129: font => "Font color",
1130: pgbg => "Header",
1131: mainbg => "Page",
1132: sidebg => "Login box",
1133: link => "Link",
1134: alink => "Active link",
1135: vlink => "Visited link",
1.6 raeburn 1136: );
1137: return %choices;
1138: }
1139:
1140: sub print_rolecolors {
1.30 raeburn 1141: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1142: my %choices = &color_font_choices();
1143: my @bgs = ('pgbg','tabbg','sidebg');
1144: my @links = ('link','alink','vlink');
1145: my @images = ('img');
1146: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1147: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1148: my %defaultdesign = %Apache::loncommon::defaultdesign;
1149: my (%is_custom,%designs);
1.200 raeburn 1150: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1151: if (ref($settings) eq 'HASH') {
1152: if (ref($settings->{$role}) eq 'HASH') {
1153: if ($settings->{$role}->{'img'} ne '') {
1154: $designs{'img'} = $settings->{$role}->{'img'};
1155: $is_custom{'img'} = 1;
1156: }
1157: if ($settings->{$role}->{'font'} ne '') {
1158: $designs{'font'} = $settings->{$role}->{'font'};
1159: $is_custom{'font'} = 1;
1160: }
1.97 tempelho 1161: if ($settings->{$role}->{'fontmenu'} ne '') {
1162: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1163: $is_custom{'fontmenu'} = 1;
1164: }
1.6 raeburn 1165: foreach my $item (@bgs) {
1166: if ($settings->{$role}->{$item} ne '') {
1167: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1168: $is_custom{$item} = 1;
1169: }
1170: }
1171: foreach my $item (@links) {
1172: if ($settings->{$role}->{$item} ne '') {
1173: $designs{'links'}{$item} = $settings->{$role}->{$item};
1174: $is_custom{$item} = 1;
1175: }
1176: }
1177: }
1178: } else {
1179: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1180: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1181: $is_custom{'img'} = 1;
1182: }
1.97 tempelho 1183: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1184: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1185: $is_custom{'fontmenu'} = 1;
1186: }
1.6 raeburn 1187: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1188: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1189: $is_custom{'font'} = 1;
1190: }
1191: foreach my $item (@bgs) {
1192: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1193: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1194: $is_custom{$item} = 1;
1195:
1196: }
1197: }
1198: foreach my $item (@links) {
1199: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1200: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1201: $is_custom{$item} = 1;
1202: }
1203: }
1204: }
1205: my $itemcount = 1;
1.30 raeburn 1206: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1207: $datatable .= '</tr></table></td></tr>';
1208: return $datatable;
1209: }
1210:
1.200 raeburn 1211: sub role_defaults {
1212: my ($role,$bgs,$links,$images,$logintext) = @_;
1.202 raeburn 1213: my %defaults;
1214: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1.200 raeburn 1215: return %defaults;
1216: }
1217: my %defaultdesign = %Apache::loncommon::defaultdesign;
1218: if ($role eq 'login') {
1219: %defaults = (
1220: font => $defaultdesign{$role.'.font'},
1221: );
1222: if (ref($logintext) eq 'ARRAY') {
1223: foreach my $item (@{$logintext}) {
1224: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1225: }
1226: }
1227: foreach my $item (@{$images}) {
1228: $defaults{'showlogo'}{$item} = 1;
1229: }
1230: } else {
1231: %defaults = (
1232: img => $defaultdesign{$role.'.img'},
1233: font => $defaultdesign{$role.'.font'},
1234: fontmenu => $defaultdesign{$role.'.fontmenu'},
1235: );
1236: }
1237: foreach my $item (@{$bgs}) {
1238: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1239: }
1240: foreach my $item (@{$links}) {
1241: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1242: }
1243: foreach my $item (@{$images}) {
1244: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1245: }
1246: return %defaults;
1247: }
1248:
1.6 raeburn 1249: sub display_color_options {
1.9 raeburn 1250: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1251: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1252: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1253: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.176 raeburn 1254: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1255: '<td>'.$choices->{'font'}.'</td>';
1256: if (!$is_custom->{'font'}) {
1.30 raeburn 1257: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1258: } else {
1259: $datatable .= '<td> </td>';
1260: }
1.174 foxr 1261: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1262:
1.8 raeburn 1263: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1264: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1.202 raeburn 1265: ' value="'.$current_color.'" /> '.
1.174 foxr 1266: ' </td></tr>';
1.107 raeburn 1267: unless ($role eq 'login') {
1268: $datatable .= '<tr'.$css_class.'>'.
1269: '<td>'.$choices->{'fontmenu'}.'</td>';
1270: if (!$is_custom->{'fontmenu'}) {
1271: $datatable .= '<td>'.&mt('Default in use:').' <span id="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1272: } else {
1273: $datatable .= '<td> </td>';
1274: }
1.202 raeburn 1275: $current_color = $designs->{'fontmenu'} ?
1.174 foxr 1276: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1277: $datatable .= '<td><span class="LC_nobreak">'.
1.174 foxr 1278: '<input class="colorchooser" type="text" size="10" name="'
1279: .$role.'_fontmenu"'.
1280: ' value="'.$current_color.'" /> '.
1281: ' </td></tr>';
1.97 tempelho 1282: }
1.9 raeburn 1283: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1284: foreach my $img (@{$images}) {
1.18 albertel 1285: $itemcount ++;
1.6 raeburn 1286: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1287: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1288: '<td>'.$choices->{$img};
1.41 raeburn 1289: my ($imgfile,$img_import,$login_hdr_pick,$logincolors);
1.70 raeburn 1290: if ($role eq 'login') {
1291: if ($img eq 'login') {
1292: $login_hdr_pick =
1.135 bisitz 1293: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1294: $logincolors =
1295: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.201 raeburn 1296: $designs,$defaults);
1.70 raeburn 1297: } elsif ($img ne 'domlogo') {
1298: $datatable.= &logo_display_options($img,$defaults,$designs);
1299: }
1300: }
1301: $datatable .= '</td>';
1.6 raeburn 1302: if ($designs->{$img} ne '') {
1303: $imgfile = $designs->{$img};
1.18 albertel 1304: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 1305: } else {
1306: $imgfile = $defaults->{$img};
1307: }
1308: if ($imgfile) {
1.9 raeburn 1309: my ($showfile,$fullsize);
1310: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 1311: my $urldir = $1;
1312: my $filename = $2;
1313: my @info = &Apache::lonnet::stat_file($designs->{$img});
1314: if (@info) {
1315: my $thumbfile = 'tn-'.$filename;
1316: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
1317: if (@thumb) {
1318: $showfile = $urldir.'/'.$thumbfile;
1319: } else {
1320: $showfile = $imgfile;
1321: }
1322: } else {
1323: $showfile = '';
1324: }
1325: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 1326: $showfile = $imgfile;
1.6 raeburn 1327: my $imgdir = $1;
1328: my $filename = $2;
1.159 raeburn 1329: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 1330: $showfile = "/$imgdir/tn-".$filename;
1331: } else {
1.159 raeburn 1332: my $input = $londocroot.$imgfile;
1333: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 1334: if (!-e $output) {
1.9 raeburn 1335: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 1336: my ($fullwidth,$fullheight) = &check_dimensions($input);
1337: if ($fullwidth ne '' && $fullheight ne '') {
1338: if ($fullwidth > $width && $fullheight > $height) {
1339: my $size = $width.'x'.$height;
1340: system("convert -sample $size $input $output");
1.159 raeburn 1341: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 1342: }
1343: }
1.6 raeburn 1344: }
1345: }
1.16 raeburn 1346: }
1.6 raeburn 1347: if ($showfile) {
1.40 raeburn 1348: if ($showfile =~ m{^/(adm|res)/}) {
1349: if ($showfile =~ m{^/res/}) {
1350: my $local_showfile =
1351: &Apache::lonnet::filelocation('',$showfile);
1352: &Apache::lonnet::repcopy($local_showfile);
1353: }
1354: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
1355: }
1356: if ($imgfile) {
1357: if ($imgfile =~ m{^/(adm|res)/}) {
1358: if ($imgfile =~ m{^/res/}) {
1359: my $local_imgfile =
1360: &Apache::lonnet::filelocation('',$imgfile);
1361: &Apache::lonnet::repcopy($local_imgfile);
1362: }
1363: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
1364: } else {
1365: $fullsize = $imgfile;
1366: }
1367: }
1.41 raeburn 1368: $datatable .= '<td>';
1369: if ($img eq 'login') {
1.135 bisitz 1370: $datatable .= $login_hdr_pick;
1371: }
1.41 raeburn 1372: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
1373: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 1374: } else {
1.201 raeburn 1375: $datatable .= '<td> </td><td class="LC_left_item">'.
1376: &mt('Upload:').'<br />';
1.6 raeburn 1377: }
1378: } else {
1.201 raeburn 1379: $datatable .= '<td> </td><td class="LC_left_item">'.
1380: &mt('Upload:').'<br />';
1.6 raeburn 1381: }
1.9 raeburn 1382: if ($switchserver) {
1383: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1384: } else {
1.135 bisitz 1385: if ($img ne 'login') { # suppress file selection for Log-in header
1386: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
1387: }
1.9 raeburn 1388: }
1389: $datatable .= '</td></tr>';
1.6 raeburn 1390: }
1391: $itemcount ++;
1392: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1393: $datatable .= '<tr'.$css_class.'>'.
1394: '<td>'.$choices->{'bgs'}.'</td>';
1395: my $bgs_def;
1396: foreach my $item (@{$bgs}) {
1397: if (!$is_custom->{$item}) {
1.70 raeburn 1398: $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 1399: }
1400: }
1401: if ($bgs_def) {
1.8 raeburn 1402: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 1403: } else {
1404: $datatable .= '<td> </td>';
1405: }
1406: $datatable .= '<td class="LC_right_item">'.
1407: '<table border="0"><tr>';
1.174 foxr 1408:
1.6 raeburn 1409: foreach my $item (@{$bgs}) {
1.201 raeburn 1410: $datatable .= '<td align="center">'.$choices->{$item};
1.174 foxr 1411: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 1412: if ($designs->{'bgs'}{$item}) {
1.174 foxr 1413: $datatable .= ' ';
1.6 raeburn 1414: }
1.174 foxr 1415: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 1416: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 1417: }
1418: $datatable .= '</tr></table></td></tr>';
1419: $itemcount ++;
1420: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1421: $datatable .= '<tr'.$css_class.'>'.
1422: '<td>'.$choices->{'links'}.'</td>';
1423: my $links_def;
1424: foreach my $item (@{$links}) {
1425: if (!$is_custom->{$item}) {
1.30 raeburn 1426: $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 1427: }
1428: }
1429: if ($links_def) {
1.8 raeburn 1430: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 1431: } else {
1432: $datatable .= '<td> </td>';
1433: }
1434: $datatable .= '<td class="LC_right_item">'.
1435: '<table border="0"><tr>';
1436: foreach my $item (@{$links}) {
1.174 foxr 1437: my $color = $designs->{'link'}{$item} ? $designs->{'link'}{$item} : $defaults->{'links'}{$item};
1.201 raeburn 1438: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 1439: if ($designs->{'links'}{$item}) {
1.174 foxr 1440: $datatable.=' ';
1.6 raeburn 1441: }
1.174 foxr 1442: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 1443: '" /></td>';
1444: }
1.30 raeburn 1445: $$rowtotal += $itemcount;
1.3 raeburn 1446: return $datatable;
1447: }
1448:
1.70 raeburn 1449: sub logo_display_options {
1450: my ($img,$defaults,$designs) = @_;
1451: my $checkedon;
1452: if (ref($defaults) eq 'HASH') {
1453: if (ref($defaults->{'showlogo'}) eq 'HASH') {
1454: if ($defaults->{'showlogo'}{$img}) {
1455: $checkedon = 'checked="checked" ';
1456: }
1457: }
1458: }
1459: if (ref($designs) eq 'HASH') {
1460: if (ref($designs->{'showlogo'}) eq 'HASH') {
1461: if (defined($designs->{'showlogo'}{$img})) {
1462: if ($designs->{'showlogo'}{$img} == 0) {
1463: $checkedon = '';
1464: } elsif ($designs->{'showlogo'}{$img} == 1) {
1465: $checkedon = 'checked="checked" ';
1466: }
1467: }
1468: }
1469: }
1470: return '<br /><label> <input type="checkbox" name="'.
1471: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
1472: &mt('show').'</label>'."\n";
1473: }
1474:
1.41 raeburn 1475: sub login_header_options {
1.135 bisitz 1476: my ($img,$role,$defaults,$is_custom,$choices) = @_;
1477: my $output = '';
1.41 raeburn 1478: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 1479: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 1480: if (!$is_custom->{'textcol'}) {
1481: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
1482: ' ';
1483: }
1484: if (!$is_custom->{'bgcol'}) {
1485: $output .= $choices->{'bgcol'}.': '.
1486: '<span id="css_'.$role.'_font" style="background-color: '.
1487: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
1488: }
1489: $output .= '<br />';
1490: }
1491: $output .='<br />';
1492: return $output;
1493: }
1494:
1495: sub login_text_colors {
1.201 raeburn 1496: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 1497: my $color_menu = '<table border="0"><tr>';
1498: foreach my $item (@{$logintext}) {
1.201 raeburn 1499: $color_menu .= '<td align="center">'.$choices->{$item};
1500: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
1501: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1502: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 1503: }
1504: $color_menu .= '</tr></table><br />';
1505: return $color_menu;
1506: }
1507:
1508: sub image_changes {
1509: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
1510: my $output;
1.135 bisitz 1511: if ($img eq 'login') {
1512: # suppress image for Log-in header
1513: } elsif (!$is_custom) {
1.70 raeburn 1514: if ($img ne 'domlogo') {
1.41 raeburn 1515: $output .= &mt('Default image:').'<br />';
1516: } else {
1517: $output .= &mt('Default in use:').'<br />';
1518: }
1519: }
1.135 bisitz 1520: if ($img eq 'login') { # suppress image for Log-in header
1521: $output .= '<td>'.$logincolors;
1.41 raeburn 1522: } else {
1.135 bisitz 1523: if ($img_import) {
1524: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
1525: }
1526: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
1527: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
1528: if ($is_custom) {
1529: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
1530: '<input type="checkbox" name="'.
1531: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
1532: '</label> '.&mt('Replace:').'</span><br />';
1533: } else {
1.201 raeburn 1534: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 1535: }
1.41 raeburn 1536: }
1537: return $output;
1538: }
1539:
1.3 raeburn 1540: sub print_quotas {
1.86 raeburn 1541: my ($dom,$settings,$rowtotal,$action) = @_;
1542: my $context;
1543: if ($action eq 'quotas') {
1544: $context = 'tools';
1545: } else {
1546: $context = $action;
1547: }
1.197 raeburn 1548: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 1549: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 1550: my $typecount = 0;
1.101 raeburn 1551: my ($css_class,%titles);
1.86 raeburn 1552: if ($context eq 'requestcourses') {
1.98 raeburn 1553: @usertools = ('official','unofficial','community');
1.106 raeburn 1554: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 1555: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
1556: %titles = &courserequest_titles();
1.163 raeburn 1557: } elsif ($context eq 'requestauthor') {
1558: @usertools = ('author');
1559: @options = ('norequest','approval','automatic');
1.210 raeburn 1560: %titles = &authorrequest_titles();
1.86 raeburn 1561: } else {
1.162 raeburn 1562: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 1563: %titles = &tool_titles();
1.86 raeburn 1564: }
1.26 raeburn 1565: if (ref($types) eq 'ARRAY') {
1.23 raeburn 1566: foreach my $type (@{$types}) {
1.197 raeburn 1567: my ($currdefquota,$currauthorquota);
1.163 raeburn 1568: unless (($context eq 'requestcourses') ||
1569: ($context eq 'requestauthor')) {
1.86 raeburn 1570: if (ref($settings) eq 'HASH') {
1571: if (ref($settings->{defaultquota}) eq 'HASH') {
1.197 raeburn 1572: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 1573: } else {
1574: $currdefquota = $settings->{$type};
1575: }
1.197 raeburn 1576: if (ref($settings->{authorquota}) eq 'HASH') {
1577: $currauthorquota = $settings->{authorquota}->{$type};
1578: }
1.78 raeburn 1579: }
1.72 raeburn 1580: }
1.3 raeburn 1581: if (defined($usertypes->{$type})) {
1582: $typecount ++;
1583: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 1584: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 1585: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 1586: '<td class="LC_left_item">';
1.101 raeburn 1587: if ($context eq 'requestcourses') {
1588: $datatable .= '<table><tr>';
1589: }
1590: my %cell;
1.72 raeburn 1591: foreach my $item (@usertools) {
1.101 raeburn 1592: if ($context eq 'requestcourses') {
1593: my ($curroption,$currlimit);
1594: if (ref($settings) eq 'HASH') {
1595: if (ref($settings->{$item}) eq 'HASH') {
1596: $curroption = $settings->{$item}->{$type};
1597: if ($curroption =~ /^autolimit=(\d*)$/) {
1598: $currlimit = $1;
1599: }
1600: }
1601: }
1602: if (!$curroption) {
1603: $curroption = 'norequest';
1604: }
1605: $datatable .= '<th>'.$titles{$item}.'</th>';
1606: foreach my $option (@options) {
1607: my $val = $option;
1608: if ($option eq 'norequest') {
1609: $val = 0;
1610: }
1611: if ($option eq 'validate') {
1612: my $canvalidate = 0;
1613: if (ref($validations{$item}) eq 'HASH') {
1614: if ($validations{$item}{$type}) {
1615: $canvalidate = 1;
1616: }
1617: }
1618: next if (!$canvalidate);
1619: }
1620: my $checked = '';
1621: if ($option eq $curroption) {
1622: $checked = ' checked="checked"';
1623: } elsif ($option eq 'autolimit') {
1624: if ($curroption =~ /^autolimit/) {
1625: $checked = ' checked="checked"';
1626: }
1627: }
1628: $cell{$item} .= '<span class="LC_nobreak"><label>'.
1629: '<input type="radio" name="crsreq_'.$item.
1630: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 1631: $titles{$option}.'</label>';
1.101 raeburn 1632: if ($option eq 'autolimit') {
1.127 raeburn 1633: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1634: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 1635: 'value="'.$currlimit.'" />';
1.101 raeburn 1636: }
1.127 raeburn 1637: $cell{$item} .= '</span> ';
1.103 raeburn 1638: if ($option eq 'autolimit') {
1.127 raeburn 1639: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 1640: }
1.101 raeburn 1641: }
1.163 raeburn 1642: } elsif ($context eq 'requestauthor') {
1643: my $curroption;
1644: if (ref($settings) eq 'HASH') {
1645: $curroption = $settings->{$type};
1646: }
1647: if (!$curroption) {
1648: $curroption = 'norequest';
1649: }
1650: foreach my $option (@options) {
1651: my $val = $option;
1652: if ($option eq 'norequest') {
1653: $val = 0;
1654: }
1655: my $checked = '';
1656: if ($option eq $curroption) {
1657: $checked = ' checked="checked"';
1658: }
1659: $datatable .= '<span class="LC_nobreak"><label>'.
1660: '<input type="radio" name="authorreq_'.$type.
1661: '" value="'.$val.'"'.$checked.' />'.
1662: $titles{$option}.'</label></span> ';
1663: }
1.101 raeburn 1664: } else {
1665: my $checked = 'checked="checked" ';
1666: if (ref($settings) eq 'HASH') {
1667: if (ref($settings->{$item}) eq 'HASH') {
1668: if ($settings->{$item}->{$type} == 0) {
1669: $checked = '';
1670: } elsif ($settings->{$item}->{$type} == 1) {
1671: $checked = 'checked="checked" ';
1672: }
1.78 raeburn 1673: }
1.72 raeburn 1674: }
1.101 raeburn 1675: $datatable .= '<span class="LC_nobreak"><label>'.
1676: '<input type="checkbox" name="'.$context.'_'.$item.
1677: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
1678: '</label></span> ';
1.72 raeburn 1679: }
1.101 raeburn 1680: }
1681: if ($context eq 'requestcourses') {
1682: $datatable .= '</tr><tr>';
1683: foreach my $item (@usertools) {
1.106 raeburn 1684: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 1685: }
1686: $datatable .= '</tr></table>';
1.72 raeburn 1687: }
1.86 raeburn 1688: $datatable .= '</td>';
1.163 raeburn 1689: unless (($context eq 'requestcourses') ||
1690: ($context eq 'requestauthor')) {
1.86 raeburn 1691: $datatable .=
1.197 raeburn 1692: '<td class="LC_right_item">'.
1693: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 1694: '<input type="text" name="quota_'.$type.
1.72 raeburn 1695: '" value="'.$currdefquota.
1.197 raeburn 1696: '" size="5" /></span>'.(' ' x 2).
1697: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1698: '<input type="text" name="authorquota_'.$type.
1699: '" value="'.$currauthorquota.
1700: '" size="5" /></span></td>';
1.86 raeburn 1701: }
1702: $datatable .= '</tr>';
1.3 raeburn 1703: }
1704: }
1705: }
1.163 raeburn 1706: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 1707: $defaultquota = '20';
1.197 raeburn 1708: $authorquota = '500';
1.86 raeburn 1709: if (ref($settings) eq 'HASH') {
1710: if (ref($settings->{'defaultquota'}) eq 'HASH') {
1711: $defaultquota = $settings->{'defaultquota'}->{'default'};
1712: } elsif (defined($settings->{'default'})) {
1713: $defaultquota = $settings->{'default'};
1714: }
1.197 raeburn 1715: if (ref($settings->{'authorquota'}) eq 'HASH') {
1716: $authorquota = $settings->{'authorquota'}->{'default'};
1717: }
1.3 raeburn 1718: }
1719: }
1720: $typecount ++;
1721: $css_class = $typecount%2?' class="LC_odd_row"':'';
1722: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 1723: '<td>'.$othertitle.'</td>'.
1.72 raeburn 1724: '<td class="LC_left_item">';
1.101 raeburn 1725: if ($context eq 'requestcourses') {
1726: $datatable .= '<table><tr>';
1727: }
1728: my %defcell;
1.72 raeburn 1729: foreach my $item (@usertools) {
1.101 raeburn 1730: if ($context eq 'requestcourses') {
1731: my ($curroption,$currlimit);
1732: if (ref($settings) eq 'HASH') {
1733: if (ref($settings->{$item}) eq 'HASH') {
1734: $curroption = $settings->{$item}->{'default'};
1735: if ($curroption =~ /^autolimit=(\d*)$/) {
1736: $currlimit = $1;
1737: }
1738: }
1739: }
1740: if (!$curroption) {
1741: $curroption = 'norequest';
1742: }
1743: $datatable .= '<th>'.$titles{$item}.'</th>';
1744: foreach my $option (@options) {
1745: my $val = $option;
1746: if ($option eq 'norequest') {
1747: $val = 0;
1748: }
1749: if ($option eq 'validate') {
1750: my $canvalidate = 0;
1751: if (ref($validations{$item}) eq 'HASH') {
1752: if ($validations{$item}{'default'}) {
1753: $canvalidate = 1;
1754: }
1755: }
1756: next if (!$canvalidate);
1757: }
1758: my $checked = '';
1759: if ($option eq $curroption) {
1760: $checked = ' checked="checked"';
1761: } elsif ($option eq 'autolimit') {
1762: if ($curroption =~ /^autolimit/) {
1763: $checked = ' checked="checked"';
1764: }
1765: }
1766: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
1767: '<input type="radio" name="crsreq_'.$item.
1768: '_default" value="'.$val.'"'.$checked.' />'.
1769: $titles{$option}.'</label>';
1770: if ($option eq 'autolimit') {
1.127 raeburn 1771: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1772: $item.'_limit_default" size="1" '.
1773: 'value="'.$currlimit.'" />';
1774: }
1.127 raeburn 1775: $defcell{$item} .= '</span> ';
1.104 raeburn 1776: if ($option eq 'autolimit') {
1.127 raeburn 1777: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1778: }
1.101 raeburn 1779: }
1.163 raeburn 1780: } elsif ($context eq 'requestauthor') {
1781: my $curroption;
1782: if (ref($settings) eq 'HASH') {
1.172 raeburn 1783: $curroption = $settings->{'default'};
1.163 raeburn 1784: }
1785: if (!$curroption) {
1786: $curroption = 'norequest';
1787: }
1788: foreach my $option (@options) {
1789: my $val = $option;
1790: if ($option eq 'norequest') {
1791: $val = 0;
1792: }
1793: my $checked = '';
1794: if ($option eq $curroption) {
1795: $checked = ' checked="checked"';
1796: }
1797: $datatable .= '<span class="LC_nobreak"><label>'.
1798: '<input type="radio" name="authorreq_default"'.
1799: ' value="'.$val.'"'.$checked.' />'.
1800: $titles{$option}.'</label></span> ';
1801: }
1.101 raeburn 1802: } else {
1803: my $checked = 'checked="checked" ';
1804: if (ref($settings) eq 'HASH') {
1805: if (ref($settings->{$item}) eq 'HASH') {
1806: if ($settings->{$item}->{'default'} == 0) {
1807: $checked = '';
1808: } elsif ($settings->{$item}->{'default'} == 1) {
1809: $checked = 'checked="checked" ';
1810: }
1.78 raeburn 1811: }
1.72 raeburn 1812: }
1.101 raeburn 1813: $datatable .= '<span class="LC_nobreak"><label>'.
1814: '<input type="checkbox" name="'.$context.'_'.$item.
1815: '" value="default" '.$checked.'/>'.$titles{$item}.
1816: '</label></span> ';
1817: }
1818: }
1819: if ($context eq 'requestcourses') {
1820: $datatable .= '</tr><tr>';
1821: foreach my $item (@usertools) {
1.106 raeburn 1822: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 1823: }
1.101 raeburn 1824: $datatable .= '</tr></table>';
1.72 raeburn 1825: }
1.86 raeburn 1826: $datatable .= '</td>';
1.163 raeburn 1827: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.197 raeburn 1828: $datatable .= '<td class="LC_right_item">'.
1829: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 1830: '<input type="text" name="defaultquota" value="'.
1.197 raeburn 1831: $defaultquota.'" size="5" /></span>'.(' ' x2).
1832: '<span class="LC_nobreak">'.&mt('Authoring').': '.
1833: '<input type="text" name="authorquota" value="'.
1834: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 1835: }
1836: $datatable .= '</tr>';
1.72 raeburn 1837: $typecount ++;
1838: $css_class = $typecount%2?' class="LC_odd_row"':'';
1839: $datatable .= '<tr'.$css_class.'>'.
1.197 raeburn 1840: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 1841: if ($context eq 'requestcourses') {
1.109 raeburn 1842: $datatable .= &mt('(overrides affiliation, if set)').
1843: '</td>'.
1844: '<td class="LC_left_item">'.
1845: '<table><tr>';
1.101 raeburn 1846: } else {
1.109 raeburn 1847: $datatable .= &mt('(overrides affiliation, if checked)').
1848: '</td>'.
1849: '<td class="LC_left_item" colspan="2">'.
1850: '<br />';
1.101 raeburn 1851: }
1852: my %advcell;
1.72 raeburn 1853: foreach my $item (@usertools) {
1.101 raeburn 1854: if ($context eq 'requestcourses') {
1855: my ($curroption,$currlimit);
1856: if (ref($settings) eq 'HASH') {
1857: if (ref($settings->{$item}) eq 'HASH') {
1858: $curroption = $settings->{$item}->{'_LC_adv'};
1859: if ($curroption =~ /^autolimit=(\d*)$/) {
1860: $currlimit = $1;
1861: }
1862: }
1863: }
1864: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 1865: my $checked = '';
1866: if ($curroption eq '') {
1867: $checked = ' checked="checked"';
1868: }
1869: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1870: '<input type="radio" name="crsreq_'.$item.
1871: '__LC_adv" value=""'.$checked.' />'.
1872: &mt('No override set').'</label></span> ';
1.101 raeburn 1873: foreach my $option (@options) {
1874: my $val = $option;
1875: if ($option eq 'norequest') {
1876: $val = 0;
1877: }
1878: if ($option eq 'validate') {
1879: my $canvalidate = 0;
1880: if (ref($validations{$item}) eq 'HASH') {
1881: if ($validations{$item}{'_LC_adv'}) {
1882: $canvalidate = 1;
1883: }
1884: }
1885: next if (!$canvalidate);
1886: }
1887: my $checked = '';
1.104 raeburn 1888: if ($val eq $curroption) {
1.101 raeburn 1889: $checked = ' checked="checked"';
1890: } elsif ($option eq 'autolimit') {
1891: if ($curroption =~ /^autolimit/) {
1892: $checked = ' checked="checked"';
1893: }
1894: }
1895: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
1896: '<input type="radio" name="crsreq_'.$item.
1897: '__LC_adv" value="'.$val.'"'.$checked.' />'.
1898: $titles{$option}.'</label>';
1899: if ($option eq 'autolimit') {
1.127 raeburn 1900: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 1901: $item.'_limit__LC_adv" size="1" '.
1902: 'value="'.$currlimit.'" />';
1903: }
1.127 raeburn 1904: $advcell{$item} .= '</span> ';
1.104 raeburn 1905: if ($option eq 'autolimit') {
1.127 raeburn 1906: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 1907: }
1.101 raeburn 1908: }
1.163 raeburn 1909: } elsif ($context eq 'requestauthor') {
1910: my $curroption;
1911: if (ref($settings) eq 'HASH') {
1912: $curroption = $settings->{'_LC_adv'};
1913: }
1914: my $checked = '';
1915: if ($curroption eq '') {
1916: $checked = ' checked="checked"';
1917: }
1918: $datatable .= '<span class="LC_nobreak"><label>'.
1919: '<input type="radio" name="authorreq__LC_adv"'.
1920: ' value=""'.$checked.' />'.
1921: &mt('No override set').'</label></span> ';
1922: foreach my $option (@options) {
1923: my $val = $option;
1924: if ($option eq 'norequest') {
1925: $val = 0;
1926: }
1927: my $checked = '';
1928: if ($val eq $curroption) {
1929: $checked = ' checked="checked"';
1930: }
1931: $datatable .= '<span class="LC_nobreak"><label>'.
1.173 raeburn 1932: '<input type="radio" name="authorreq__LC_adv"'.
1933: ' value="'.$val.'"'.$checked.' />'.
1.163 raeburn 1934: $titles{$option}.'</label></span> ';
1935: }
1.101 raeburn 1936: } else {
1937: my $checked = 'checked="checked" ';
1938: if (ref($settings) eq 'HASH') {
1939: if (ref($settings->{$item}) eq 'HASH') {
1940: if ($settings->{$item}->{'_LC_adv'} == 0) {
1941: $checked = '';
1942: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
1943: $checked = 'checked="checked" ';
1944: }
1.79 raeburn 1945: }
1.72 raeburn 1946: }
1.101 raeburn 1947: $datatable .= '<span class="LC_nobreak"><label>'.
1948: '<input type="checkbox" name="'.$context.'_'.$item.
1949: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
1950: '</label></span> ';
1951: }
1952: }
1953: if ($context eq 'requestcourses') {
1954: $datatable .= '</tr><tr>';
1955: foreach my $item (@usertools) {
1.106 raeburn 1956: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 1957: }
1.101 raeburn 1958: $datatable .= '</tr></table>';
1.72 raeburn 1959: }
1.98 raeburn 1960: $datatable .= '</td></tr>';
1.30 raeburn 1961: $$rowtotal += $typecount;
1.3 raeburn 1962: return $datatable;
1963: }
1964:
1.163 raeburn 1965: sub print_requestmail {
1966: my ($dom,$action,$settings,$rowtotal) = @_;
1.208 raeburn 1967: my ($now,$datatable,%currapp);
1.102 raeburn 1968: $now = time;
1969: if (ref($settings) eq 'HASH') {
1970: if (ref($settings->{'notify'}) eq 'HASH') {
1971: if ($settings->{'notify'}{'approval'} ne '') {
1.191 raeburn 1972: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 1973: }
1974: }
1975: }
1.191 raeburn 1976: my $numinrow = 2;
1.102 raeburn 1977: my $css_class = 'class="LC_odd_row"';
1.163 raeburn 1978: my $text;
1979: if ($action eq 'requestcourses') {
1980: $text = &mt('Receive notification of course requests requiring approval');
1981: } else {
1982: $text = &mt('Receive notification of authoring space requests requiring approval')
1983: }
1984: $datatable = '<tr '.$css_class.'>'.
1985: ' <td>'.$text.'</td>'.
1.102 raeburn 1986: ' <td class="LC_left_item">';
1.191 raeburn 1987: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1988: 'reqapprovalnotify',%currapp);
1989: if ($numdc > 0) {
1990: $datatable .= $table;
1.102 raeburn 1991: } else {
1992: $datatable .= &mt('There are no active Domain Coordinators');
1993: }
1994: $datatable .='</td></tr>';
1995: $$rowtotal += $rows;
1996: return $datatable;
1997: }
1998:
1.3 raeburn 1999: sub print_autoenroll {
1.30 raeburn 2000: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 2001: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.129 raeburn 2002: my ($defdom,$runon,$runoff,$coownerson,$coownersoff);
1.3 raeburn 2003: if (ref($settings) eq 'HASH') {
2004: if (exists($settings->{'run'})) {
2005: if ($settings->{'run'} eq '0') {
2006: $runoff = ' checked="checked" ';
2007: $runon = ' ';
2008: } else {
2009: $runon = ' checked="checked" ';
2010: $runoff = ' ';
2011: }
2012: } else {
2013: if ($autorun) {
2014: $runon = ' checked="checked" ';
2015: $runoff = ' ';
2016: } else {
2017: $runoff = ' checked="checked" ';
2018: $runon = ' ';
2019: }
2020: }
1.129 raeburn 2021: if (exists($settings->{'co-owners'})) {
2022: if ($settings->{'co-owners'} eq '0') {
2023: $coownersoff = ' checked="checked" ';
2024: $coownerson = ' ';
2025: } else {
2026: $coownerson = ' checked="checked" ';
2027: $coownersoff = ' ';
2028: }
2029: } else {
2030: $coownersoff = ' checked="checked" ';
2031: $coownerson = ' ';
2032: }
1.3 raeburn 2033: if (exists($settings->{'sender_domain'})) {
2034: $defdom = $settings->{'sender_domain'};
2035: }
1.14 raeburn 2036: } else {
2037: if ($autorun) {
2038: $runon = ' checked="checked" ';
2039: $runoff = ' ';
2040: } else {
2041: $runoff = ' checked="checked" ';
2042: $runon = ' ';
2043: }
1.3 raeburn 2044: }
2045: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 2046: my $notif_sender;
2047: if (ref($settings) eq 'HASH') {
2048: $notif_sender = $settings->{'sender_uname'};
2049: }
1.3 raeburn 2050: my $datatable='<tr class="LC_odd_row">'.
2051: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 2052: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2053: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 2054: $runon.' value="1" />'.&mt('Yes').'</label> '.
2055: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 2056: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2057: '</tr><tr>'.
2058: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 2059: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 2060: &mt('username').': '.
2061: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 2062: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 2063: ': '.$domform.'</span></td></tr>'.
2064: '<tr class="LC_odd_row">'.
2065: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
2066: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2067: '<input type="radio" name="autoassign_coowners"'.
2068: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
2069: '<label><input type="radio" name="autoassign_coowners"'.
2070: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
2071: '</tr>';
2072: $$rowtotal += 3;
1.3 raeburn 2073: return $datatable;
2074: }
2075:
2076: sub print_autoupdate {
1.30 raeburn 2077: my ($position,$dom,$settings,$rowtotal) = @_;
1.3 raeburn 2078: my $datatable;
2079: if ($position eq 'top') {
2080: my $updateon = ' ';
2081: my $updateoff = ' checked="checked" ';
2082: my $classlistson = ' ';
2083: my $classlistsoff = ' checked="checked" ';
2084: if (ref($settings) eq 'HASH') {
2085: if ($settings->{'run'} eq '1') {
2086: $updateon = $updateoff;
2087: $updateoff = ' ';
2088: }
2089: if ($settings->{'classlists'} eq '1') {
2090: $classlistson = $classlistsoff;
2091: $classlistsoff = ' ';
2092: }
2093: }
2094: my %title = (
2095: run => 'Auto-update active?',
2096: classlists => 'Update information in classlists?',
2097: );
2098: $datatable = '<tr class="LC_odd_row">'.
2099: '<td>'.&mt($title{'run'}).'</td>'.
1.8 raeburn 2100: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 2101: '<input type="radio" name="autoupdate_run"'.
1.8 raeburn 2102: $updateon.' value="1" />'.&mt('Yes').'</label> '.
2103: '<label><input type="radio" name="autoupdate_run"'.
2104: $updateoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2105: '</tr><tr>'.
2106: '<td>'.&mt($title{'classlists'}).'</td>'.
1.8 raeburn 2107: '<td class="LC_right_item"><span class="LC_nobreak">'.
2108: '<label><input type="radio" name="classlists"'.
2109: $classlistson.' value="1" />'.&mt('Yes').'</label> '.
2110: '<label><input type="radio" name="classlists"'.
2111: $classlistsoff.'value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 2112: '</tr>';
1.30 raeburn 2113: $$rowtotal += 2;
1.131 raeburn 2114: } elsif ($position eq 'middle') {
2115: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
2116: my $numinrow = 3;
2117: my $locknamesettings;
2118: $datatable .= &insttypes_row($settings,$types,$usertypes,
2119: $dom,$numinrow,$othertitle,
2120: 'lockablenames');
2121: $$rowtotal ++;
1.3 raeburn 2122: } else {
1.44 raeburn 2123: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 2124: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 2125: 'permanentemail','id');
1.33 raeburn 2126: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 2127: my $numrows = 0;
1.26 raeburn 2128: if (ref($types) eq 'ARRAY') {
2129: if (@{$types} > 0) {
2130: $datatable =
2131: &usertype_update_row($settings,$usertypes,\%fieldtitles,
2132: \@fields,$types,\$numrows);
1.30 raeburn 2133: $$rowtotal += @{$types};
1.26 raeburn 2134: }
1.3 raeburn 2135: }
2136: $datatable .=
2137: &usertype_update_row($settings,{'default' => $othertitle},
2138: \%fieldtitles,\@fields,['default'],
2139: \$numrows);
1.30 raeburn 2140: $$rowtotal ++;
1.3 raeburn 2141: }
2142: return $datatable;
2143: }
2144:
1.125 raeburn 2145: sub print_autocreate {
2146: my ($dom,$settings,$rowtotal) = @_;
1.191 raeburn 2147: my (%createon,%createoff,%currhash);
1.125 raeburn 2148: my @types = ('xml','req');
2149: if (ref($settings) eq 'HASH') {
2150: foreach my $item (@types) {
2151: $createoff{$item} = ' checked="checked" ';
2152: $createon{$item} = ' ';
2153: if (exists($settings->{$item})) {
2154: if ($settings->{$item}) {
2155: $createon{$item} = ' checked="checked" ';
2156: $createoff{$item} = ' ';
2157: }
2158: }
2159: }
1.210 raeburn 2160: if ($settings->{'xmldc'} ne '') {
1.191 raeburn 2161: $currhash{$settings->{'xmldc'}} = 1;
2162: }
1.125 raeburn 2163: } else {
2164: foreach my $item (@types) {
2165: $createoff{$item} = ' checked="checked" ';
2166: $createon{$item} = ' ';
2167: }
2168: }
2169: $$rowtotal += 2;
1.191 raeburn 2170: my $numinrow = 2;
1.125 raeburn 2171: my $datatable='<tr class="LC_odd_row">'.
2172: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
2173: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2174: '<input type="radio" name="autocreate_xml"'.
2175: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
2176: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 2177: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
2178: '</td></tr><tr>'.
2179: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
2180: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2181: '<input type="radio" name="autocreate_req"'.
2182: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
2183: '<label><input type="radio" name="autocreate_req"'.
2184: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.191 raeburn 2185: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
2186: 'autocreate_xmldc',%currhash);
1.125 raeburn 2187: if ($numdc > 1) {
1.143 raeburn 2188: $datatable .= '</td></tr><tr class="LC_odd_row"><td>'.
2189: &mt('Course creation processed as: (choose Dom. Coord.)').
2190: '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.125 raeburn 2191: } else {
1.143 raeburn 2192: $datatable .= $dctable.'</td></tr>';
1.125 raeburn 2193: }
1.191 raeburn 2194: $$rowtotal += $rows;
1.125 raeburn 2195: return $datatable;
2196: }
2197:
1.23 raeburn 2198: sub print_directorysrch {
1.30 raeburn 2199: my ($dom,$settings,$rowtotal) = @_;
1.23 raeburn 2200: my $srchon = ' ';
2201: my $srchoff = ' checked="checked" ';
1.25 raeburn 2202: my ($exacton,$containson,$beginson);
1.24 raeburn 2203: my $localon = ' ';
2204: my $localoff = ' checked="checked" ';
1.23 raeburn 2205: if (ref($settings) eq 'HASH') {
2206: if ($settings->{'available'} eq '1') {
2207: $srchon = $srchoff;
2208: $srchoff = ' ';
2209: }
1.24 raeburn 2210: if ($settings->{'localonly'} eq '1') {
2211: $localon = $localoff;
2212: $localoff = ' ';
2213: }
1.25 raeburn 2214: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
2215: foreach my $type (@{$settings->{'searchtypes'}}) {
2216: if ($type eq 'exact') {
2217: $exacton = ' checked="checked" ';
2218: } elsif ($type eq 'contains') {
2219: $containson = ' checked="checked" ';
2220: } elsif ($type eq 'begins') {
2221: $beginson = ' checked="checked" ';
2222: }
2223: }
2224: } else {
2225: if ($settings->{'searchtypes'} eq 'exact') {
2226: $exacton = ' checked="checked" ';
2227: } elsif ($settings->{'searchtypes'} eq 'contains') {
2228: $containson = ' checked="checked" ';
2229: } elsif ($settings->{'searchtypes'} eq 'specify') {
2230: $exacton = ' checked="checked" ';
2231: $containson = ' checked="checked" ';
2232: }
1.23 raeburn 2233: }
2234: }
2235: my ($searchtitles,$titleorder) = &sorted_searchtitles();
1.45 raeburn 2236: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 2237:
2238: my $numinrow = 4;
1.26 raeburn 2239: my $cansrchrow = 0;
1.23 raeburn 2240: my $datatable='<tr class="LC_odd_row">'.
1.30 raeburn 2241: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Directory search available?').'</span></td>'.
1.23 raeburn 2242: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2243: '<input type="radio" name="dirsrch_available"'.
2244: $srchon.' value="1" />'.&mt('Yes').'</label> '.
2245: '<label><input type="radio" name="dirsrch_available"'.
2246: $srchoff.' value="0" />'.&mt('No').'</label></span></td>'.
2247: '</tr><tr>'.
1.30 raeburn 2248: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search?').'</span></td>'.
1.24 raeburn 2249: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
2250: '<input type="radio" name="dirsrch_localonly"'.
2251: $localoff.' value="0" />'.&mt('Yes').'</label> '.
2252: '<label><input type="radio" name="dirsrch_localonly"'.
2253: $localon.' value="1" />'.&mt('No').'</label></span></td>'.
1.25 raeburn 2254: '</tr>';
1.30 raeburn 2255: $$rowtotal += 2;
1.26 raeburn 2256: if (ref($usertypes) eq 'HASH') {
2257: if (keys(%{$usertypes}) > 0) {
1.93 raeburn 2258: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
2259: $numinrow,$othertitle,'cansearch');
1.26 raeburn 2260: $cansrchrow = 1;
2261: }
2262: }
2263: if ($cansrchrow) {
1.30 raeburn 2264: $$rowtotal ++;
1.26 raeburn 2265: $datatable .= '<tr>';
2266: } else {
2267: $datatable .= '<tr class="LC_odd_row">';
2268: }
1.30 raeburn 2269: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
2270: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
1.25 raeburn 2271: foreach my $title (@{$titleorder}) {
2272: if (defined($searchtitles->{$title})) {
2273: my $check = ' ';
1.93 raeburn 2274: if (ref($settings) eq 'HASH') {
1.39 raeburn 2275: if (ref($settings->{'searchby'}) eq 'ARRAY') {
2276: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
2277: $check = ' checked="checked" ';
2278: }
1.25 raeburn 2279: }
2280: }
2281: $datatable .= '<td class="LC_left_item">'.
2282: '<span class="LC_nobreak"><label>'.
2283: '<input type="checkbox" name="searchby" '.
2284: 'value="'.$title.'"'.$check.'/>'.
2285: $searchtitles->{$title}.'</label></span></td>';
2286: }
2287: }
1.26 raeburn 2288: $datatable .= '</tr></table></td></tr>';
1.30 raeburn 2289: $$rowtotal ++;
1.26 raeburn 2290: if ($cansrchrow) {
2291: $datatable .= '<tr class="LC_odd_row">';
2292: } else {
2293: $datatable .= '<tr>';
2294: }
1.30 raeburn 2295: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
1.26 raeburn 2296: '<td class="LC_left_item" colspan="2">'.
1.25 raeburn 2297: '<span class="LC_nobreak"><label>'.
2298: '<input type="checkbox" name="searchtypes" '.
2299: $exacton.' value="exact" />'.&mt('Exact match').
2300: '</label> '.
2301: '<label><input type="checkbox" name="searchtypes" '.
2302: $beginson.' value="begins" />'.&mt('Begins with').
2303: '</label> '.
2304: '<label><input type="checkbox" name="searchtypes" '.
2305: $containson.' value="contains" />'.&mt('Contains').
2306: '</label></span></td></tr>';
1.30 raeburn 2307: $$rowtotal ++;
1.25 raeburn 2308: return $datatable;
2309: }
2310:
1.28 raeburn 2311: sub print_contacts {
1.30 raeburn 2312: my ($dom,$settings,$rowtotal) = @_;
1.28 raeburn 2313: my $datatable;
2314: my @contacts = ('adminemail','supportemail');
1.134 raeburn 2315: my (%checked,%to,%otheremails,%bccemails);
1.102 raeburn 2316: my @mailings = ('errormail','packagesmail','lonstatusmail','helpdeskmail',
1.203 raeburn 2317: 'requestsmail','updatesmail','idconflictsmail');
1.28 raeburn 2318: foreach my $type (@mailings) {
2319: $otheremails{$type} = '';
2320: }
1.134 raeburn 2321: $bccemails{'helpdeskmail'} = '';
1.28 raeburn 2322: if (ref($settings) eq 'HASH') {
2323: foreach my $item (@contacts) {
2324: if (exists($settings->{$item})) {
2325: $to{$item} = $settings->{$item};
2326: }
2327: }
2328: foreach my $type (@mailings) {
2329: if (exists($settings->{$type})) {
2330: if (ref($settings->{$type}) eq 'HASH') {
2331: foreach my $item (@contacts) {
2332: if ($settings->{$type}{$item}) {
2333: $checked{$type}{$item} = ' checked="checked" ';
2334: }
2335: }
2336: $otheremails{$type} = $settings->{$type}{'others'};
1.134 raeburn 2337: if ($type eq 'helpdeskmail') {
2338: $bccemails{$type} = $settings->{$type}{'bcc'};
2339: }
1.28 raeburn 2340: }
1.89 raeburn 2341: } elsif ($type eq 'lonstatusmail') {
2342: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2343: }
2344: }
2345: } else {
2346: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
2347: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
2348: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
2349: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
1.89 raeburn 2350: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
2351: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
1.102 raeburn 2352: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
1.190 raeburn 2353: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
1.203 raeburn 2354: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.28 raeburn 2355: }
2356: my ($titles,$short_titles) = &contact_titles();
2357: my $rownum = 0;
2358: my $css_class;
2359: foreach my $item (@contacts) {
1.69 raeburn 2360: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.30 raeburn 2361: $datatable .= '<tr'.$css_class.'>'.
2362: '<td><span class="LC_nobreak">'.$titles->{$item}.
2363: '</span></td><td class="LC_right_item">'.
1.28 raeburn 2364: '<input type="text" name="'.$item.'" value="'.
2365: $to{$item}.'" /></td></tr>';
1.203 raeburn 2366: $rownum ++;
1.28 raeburn 2367: }
2368: foreach my $type (@mailings) {
1.69 raeburn 2369: $css_class = $rownum%2?' class="LC_odd_row"':'';
1.28 raeburn 2370: $datatable .= '<tr'.$css_class.'>'.
1.30 raeburn 2371: '<td><span class="LC_nobreak">'.
2372: $titles->{$type}.': </span></td>'.
1.28 raeburn 2373: '<td class="LC_left_item">'.
2374: '<span class="LC_nobreak">';
2375: foreach my $item (@contacts) {
2376: $datatable .= '<label>'.
2377: '<input type="checkbox" name="'.$type.'"'.
2378: $checked{$type}{$item}.
2379: ' value="'.$item.'" />'.$short_titles->{$item}.
2380: '</label> ';
2381: }
2382: $datatable .= '</span><br />'.&mt('Others').': '.
2383: '<input type="text" name="'.$type.'_others" '.
1.134 raeburn 2384: 'value="'.$otheremails{$type}.'" />';
2385: if ($type eq 'helpdeskmail') {
1.136 raeburn 2386: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
1.134 raeburn 2387: '<input type="text" name="'.$type.'_bcc" '.
2388: 'value="'.$bccemails{$type}.'" />';
2389: }
2390: $datatable .= '</td></tr>'."\n";
1.203 raeburn 2391: $rownum ++;
1.28 raeburn 2392: }
1.203 raeburn 2393: my %choices;
2394: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',
2395: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2396: &mt('LON-CAPA core group - MSU'),600,500));
2397: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
2398: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
2399: &mt('LON-CAPA core group - MSU'),600,500));
2400: my @toggles = ('reporterrors','reportupdates');
2401: my %defaultchecked = ('reporterrors' => 'on',
2402: 'reportupdates' => 'on');
2403: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2404: \%choices,$rownum);
2405: $datatable .= $reports;
1.30 raeburn 2406: $$rowtotal += $rownum;
1.28 raeburn 2407: return $datatable;
2408: }
2409:
1.118 jms 2410: sub print_helpsettings {
1.168 raeburn 2411: my ($dom,$confname,$settings,$rowtotal) = @_;
2412: my ($datatable,$itemcount);
1.166 raeburn 2413: $itemcount = 1;
1.168 raeburn 2414: my (%choices,%defaultchecked,@toggles);
2415: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
2416: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
2417: &mt('LON-CAPA bug tracker'),600,500));
2418: %defaultchecked = ('submitbugs' => 'on');
2419: @toggles = ('submitbugs',);
1.166 raeburn 2420:
1.168 raeburn 2421: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
2422: \%choices,$itemcount);
1.166 raeburn 2423: return $datatable;
1.121 raeburn 2424: }
2425:
2426: sub radiobutton_prefs {
1.192 raeburn 2427: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
2428: $additional) = @_;
1.121 raeburn 2429: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
2430: (ref($choices) eq 'HASH'));
2431:
1.170 raeburn 2432: my (%checkedon,%checkedoff,$datatable,$css_class);
1.121 raeburn 2433:
2434: foreach my $item (@{$toggles}) {
2435: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 2436: $checkedon{$item} = ' checked="checked" ';
2437: $checkedoff{$item} = ' ';
1.121 raeburn 2438: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 2439: $checkedoff{$item} = ' checked="checked" ';
2440: $checkedon{$item} = ' ';
2441: }
2442: }
2443: if (ref($settings) eq 'HASH') {
1.121 raeburn 2444: foreach my $item (@{$toggles}) {
1.118 jms 2445: if ($settings->{$item} eq '1') {
2446: $checkedon{$item} = ' checked="checked" ';
2447: $checkedoff{$item} = ' ';
2448: } elsif ($settings->{$item} eq '0') {
2449: $checkedoff{$item} = ' checked="checked" ';
2450: $checkedon{$item} = ' ';
2451: }
2452: }
1.121 raeburn 2453: }
1.192 raeburn 2454: if ($onclick) {
2455: $onclick = ' onclick="'.$onclick.'"';
2456: }
1.121 raeburn 2457: foreach my $item (@{$toggles}) {
1.118 jms 2458: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 2459: $datatable .=
1.192 raeburn 2460: '<tr'.$css_class.'><td valign="top">'.
2461: '<span class="LC_nobreak">'.$choices->{$item}.
1.118 jms 2462: '</span></td>'.
2463: '<td class="LC_right_item"><span class="LC_nobreak">'.
2464: '<label><input type="radio" name="'.
1.192 raeburn 2465: $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
1.118 jms 2466: '</label> <label><input type="radio" name="'.$item.'" '.
1.192 raeburn 2467: $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>'.
2468: '</span>'.$additional.
2469: '</td>'.
1.118 jms 2470: '</tr>';
2471: $itemcount ++;
1.121 raeburn 2472: }
2473: return ($datatable,$itemcount);
2474: }
2475:
2476: sub print_coursedefaults {
1.139 raeburn 2477: my ($position,$dom,$settings,$rowtotal) = @_;
1.192 raeburn 2478: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 2479: my $itemcount = 1;
1.192 raeburn 2480: my %choices = &Apache::lonlocal::texthash (
2481: canuse_pdfforms => 'Course/Community users can create/upload PDF forms',
1.198 raeburn 2482: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.192 raeburn 2483: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
2484: coursecredits => 'Credits can be specified for courses',
2485: );
1.198 raeburn 2486: my %staticdefaults = (
2487: anonsurvey_threshold => 10,
2488: uploadquota => 500,
2489: );
1.139 raeburn 2490: if ($position eq 'top') {
2491: %defaultchecked = ('canuse_pdfforms' => 'off');
1.192 raeburn 2492: @toggles = ('canuse_pdfforms');
1.139 raeburn 2493: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.121 raeburn 2494: \%choices,$itemcount);
1.139 raeburn 2495: } else {
2496: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.198 raeburn 2497: my ($currdefresponder,$def_official_credits,$def_unofficial_credits,%curruploadquota);
1.192 raeburn 2498: my $currusecredits = 0;
1.198 raeburn 2499: my @types = ('official','unofficial','community');
1.139 raeburn 2500: if (ref($settings) eq 'HASH') {
2501: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.198 raeburn 2502: if (ref($settings->{'uploadquota'}) eq 'HASH') {
2503: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
2504: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
2505: }
2506: }
1.192 raeburn 2507: if (ref($settings->{'coursecredits'}) eq 'HASH') {
2508: $def_official_credits = $settings->{'coursecredits'}->{'official'};
2509: $def_unofficial_credits = $settings->{'coursecredits'}->{'unofficial'};
2510: if (($def_official_credits ne '') || ($def_unofficial_credits ne '')) {
2511: $currusecredits = 1;
2512: }
2513: }
1.139 raeburn 2514: }
2515: if (!$currdefresponder) {
1.198 raeburn 2516: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 2517: } elsif ($currdefresponder < 1) {
2518: $currdefresponder = 1;
2519: }
1.198 raeburn 2520: foreach my $type (@types) {
2521: if ($curruploadquota{$type} eq '') {
2522: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
2523: }
2524: }
1.139 raeburn 2525: $datatable .=
1.192 raeburn 2526: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
2527: $choices{'anonsurvey_threshold'}.
1.139 raeburn 2528: '</span></td>'.
2529: '<td class="LC_right_item"><span class="LC_nobreak">'.
2530: '<input type="text" name="anonsurvey_threshold"'.
2531: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.198 raeburn 2532: '</td></tr>'."\n".
2533: '<tr><td><span class="LC_nobreak">'.
2534: $choices{'uploadquota'}.
2535: '</span></td>'.
2536: '<td align="right" class="LC_right_item">'.
2537: '<table><tr>';
2538: foreach my $type (@types) {
2539: $datatable .= '<td align="center">'.&mt($type).'<br />'.
2540: '<input type="text" name="uploadquota_'.$type.'"'.
2541: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
2542: }
2543: $datatable .= '</tr></table></td></tr>'."\n";
2544: $itemcount += 2;
1.192 raeburn 2545: my $onclick = 'toggleCredits(this.form);';
1.210 raeburn 2546: my $display = 'none';
1.192 raeburn 2547: if ($currusecredits) {
2548: $display = 'block';
2549: }
2550: my $additional = '<div id="credits" style="display: '.$display.'">'.
2551: '<span class="LC_nobreak">'.
2552: &mt('Default credits for official courses [_1]',
2553: '<input type="text" name="official_credits" value="'.
2554: $def_official_credits.'" size="3" />').
2555: '</span><br />'.
2556: '<span class="LC_nobreak">'.
2557: &mt('Default credits for unofficial courses [_1]',
2558: '<input type="text" name="unofficial_credits" value="'.
2559: $def_unofficial_credits.'" size="3" />').
2560: '</span></div>'."\n";
2561: %defaultchecked = ('coursecredits' => 'off');
2562: @toggles = ('coursecredits');
2563: my $current = {
2564: 'coursecredits' => $currusecredits,
2565: };
2566: (my $table,$itemcount) =
2567: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
2568: \%choices,$itemcount,$onclick,$additional);
2569: $datatable .= $table;
1.139 raeburn 2570: }
1.192 raeburn 2571: $$rowtotal += $itemcount;
1.121 raeburn 2572: return $datatable;
1.118 jms 2573: }
2574:
1.137 raeburn 2575: sub print_usersessions {
2576: my ($position,$dom,$settings,$rowtotal) = @_;
2577: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 2578: my (%by_ip,%by_location,@intdoms);
2579: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 2580:
2581: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 2582: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 2583: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 2584: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 2585: my $itemcount = 1;
2586: if ($position eq 'top') {
1.152 raeburn 2587: if (keys(%serverhomes) > 1) {
1.145 raeburn 2588: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.152 raeburn 2589: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,$rowtotal);
1.145 raeburn 2590: } else {
1.140 raeburn 2591: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2592: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.');
1.140 raeburn 2593: }
1.137 raeburn 2594: } else {
1.145 raeburn 2595: if (keys(%by_location) == 0) {
2596: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.150 raeburn 2597: &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.');
1.145 raeburn 2598: } else {
2599: my %lt = &usersession_titles();
2600: my $numinrow = 5;
2601: my $prefix;
2602: my @types;
2603: if ($position eq 'bottom') {
2604: $prefix = 'remote';
2605: @types = ('version','excludedomain','includedomain');
2606: } else {
2607: $prefix = 'hosted';
2608: @types = ('excludedomain','includedomain');
2609: }
2610: my (%current,%checkedon,%checkedoff);
2611: my @lcversions = &Apache::lonnet::all_loncaparevs();
2612: my @locations = sort(keys(%by_location));
2613: foreach my $type (@types) {
2614: $checkedon{$type} = '';
2615: $checkedoff{$type} = ' checked="checked"';
2616: }
2617: if (ref($settings) eq 'HASH') {
2618: if (ref($settings->{$prefix}) eq 'HASH') {
2619: foreach my $key (keys(%{$settings->{$prefix}})) {
2620: $current{$key} = $settings->{$prefix}{$key};
2621: if ($key eq 'version') {
2622: if ($current{$key} ne '') {
2623: $checkedon{$key} = ' checked="checked"';
2624: $checkedoff{$key} = '';
2625: }
2626: } elsif (ref($current{$key}) eq 'ARRAY') {
2627: $checkedon{$key} = ' checked="checked"';
2628: $checkedoff{$key} = '';
2629: }
1.137 raeburn 2630: }
2631: }
2632: }
1.145 raeburn 2633: foreach my $type (@types) {
2634: next if ($type ne 'version' && !@locations);
2635: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2636: $datatable .= '<tr'.$css_class.'>
2637: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
2638: <span class="LC_nobreak">
2639: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
2640: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
2641: if ($type eq 'version') {
2642: my $selector = '<select name="'.$prefix.'_version">';
2643: foreach my $version (@lcversions) {
2644: my $selected = '';
2645: if ($current{'version'} eq $version) {
2646: $selected = ' selected="selected"';
2647: }
2648: $selector .= ' <option value="'.$version.'"'.
2649: $selected.'>'.$version.'</option>';
2650: }
2651: $selector .= '</select> ';
2652: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
2653: } else {
2654: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
2655: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
2656: ' />'.(' 'x2).
2657: '<input type="button" value="'.&mt('uncheck all').'" '.
2658: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
2659: "\n".
2660: '</div><div><table>';
2661: my $rem;
2662: for (my $i=0; $i<@locations; $i++) {
2663: my ($showloc,$value,$checkedtype);
2664: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
2665: my $ip = $by_location{$locations[$i]}->[0];
2666: if (ref($by_ip{$ip}) eq 'ARRAY') {
2667: $value = join(':',@{$by_ip{$ip}});
2668: $showloc = join(', ',@{$by_ip{$ip}});
2669: if (ref($current{$type}) eq 'ARRAY') {
2670: foreach my $loc (@{$by_ip{$ip}}) {
2671: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
2672: $checkedtype = ' checked="checked"';
2673: last;
2674: }
2675: }
1.138 raeburn 2676: }
2677: }
2678: }
1.145 raeburn 2679: $rem = $i%($numinrow);
2680: if ($rem == 0) {
2681: if ($i > 0) {
2682: $datatable .= '</tr>';
2683: }
2684: $datatable .= '<tr>';
2685: }
2686: $datatable .= '<td class="LC_left_item">'.
2687: '<span class="LC_nobreak"><label>'.
2688: '<input type="checkbox" name="'.$prefix.'_'.$type.
2689: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
2690: '</label></span></td>';
1.137 raeburn 2691: }
1.145 raeburn 2692: $rem = @locations%($numinrow);
2693: my $colsleft = $numinrow - $rem;
2694: if ($colsleft > 1 ) {
2695: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
2696: ' </td>';
2697: } elsif ($colsleft == 1) {
2698: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 2699: }
1.145 raeburn 2700: $datatable .= '</tr></table>';
1.137 raeburn 2701: }
1.145 raeburn 2702: $datatable .= '</td></tr>';
2703: $itemcount ++;
1.137 raeburn 2704: }
2705: }
2706: }
2707: $$rowtotal += $itemcount;
2708: return $datatable;
2709: }
2710:
1.138 raeburn 2711: sub build_location_hashes {
2712: my ($intdoms,$by_ip,$by_location) = @_;
2713: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
2714: (ref($by_location) eq 'HASH'));
2715: my %iphost = &Apache::lonnet::get_iphost();
2716: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
2717: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
2718: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
2719: foreach my $id (@{$iphost{$primary_ip}}) {
2720: my $intdom = &Apache::lonnet::internet_dom($id);
2721: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
2722: push(@{$intdoms},$intdom);
2723: }
2724: }
2725: }
2726: foreach my $ip (keys(%iphost)) {
2727: if (ref($iphost{$ip}) eq 'ARRAY') {
2728: foreach my $id (@{$iphost{$ip}}) {
2729: my $location = &Apache::lonnet::internet_dom($id);
2730: if ($location) {
2731: next if (grep(/^\Q$location\E$/,@{$intdoms}));
2732: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2733: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
2734: push(@{$by_ip->{$ip}},$location);
2735: }
2736: } else {
2737: $by_ip->{$ip} = [$location];
2738: }
2739: }
2740: }
2741: }
2742: }
2743: foreach my $ip (sort(keys(%{$by_ip}))) {
2744: if (ref($by_ip->{$ip}) eq 'ARRAY') {
2745: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
2746: my $first = $by_ip->{$ip}->[0];
2747: if (ref($by_location->{$first}) eq 'ARRAY') {
2748: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
2749: push(@{$by_location->{$first}},$ip);
2750: }
2751: } else {
2752: $by_location->{$first} = [$ip];
2753: }
2754: }
2755: }
2756: return;
2757: }
2758:
1.145 raeburn 2759: sub current_offloads_to {
2760: my ($dom,$settings,$servers) = @_;
2761: my (%spareid,%otherdomconfigs);
1.152 raeburn 2762: if (ref($servers) eq 'HASH') {
1.145 raeburn 2763: foreach my $lonhost (sort(keys(%{$servers}))) {
2764: my $gotspares;
1.152 raeburn 2765: if (ref($settings) eq 'HASH') {
2766: if (ref($settings->{'spares'}) eq 'HASH') {
2767: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
2768: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
2769: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
2770: $gotspares = 1;
2771: }
1.145 raeburn 2772: }
2773: }
2774: unless ($gotspares) {
2775: my $gotspares;
2776: my $serverhomeID =
2777: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
2778: my $serverhomedom =
2779: &Apache::lonnet::host_domain($serverhomeID);
2780: if ($serverhomedom ne $dom) {
2781: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
2782: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2783: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2784: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2785: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2786: $gotspares = 1;
2787: }
2788: }
2789: } else {
2790: $otherdomconfigs{$serverhomedom} =
2791: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
2792: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
2793: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
2794: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
2795: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
2796: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
2797: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
2798: $gotspares = 1;
2799: }
2800: }
2801: }
2802: }
2803: }
2804: }
2805: }
2806: unless ($gotspares) {
2807: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
2808: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2809: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2810: } else {
2811: my $server_hostname = &Apache::lonnet::hostname($lonhost);
2812: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
2813: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
2814: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
2815: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
2816: } else {
1.150 raeburn 2817: my %what = (
2818: spareid => 1,
2819: );
2820: my ($result,$returnhash) =
2821: &Apache::lonnet::get_remote_globals($lonhost,\%what);
2822: if ($result eq 'ok') {
2823: if (ref($returnhash) eq 'HASH') {
2824: if (ref($returnhash->{'spareid'}) eq 'HASH') {
2825: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
2826: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
2827: }
2828: }
1.145 raeburn 2829: }
2830: }
2831: }
2832: }
2833: }
2834: }
2835: return %spareid;
2836: }
2837:
2838: sub spares_row {
1.152 raeburn 2839: my ($dom,$servers,$spareid,$serverhomes,$altids,$rowtotal) = @_;
1.145 raeburn 2840: my $css_class;
2841: my $numinrow = 4;
2842: my $itemcount = 1;
2843: my $datatable;
1.152 raeburn 2844: my %typetitles = &sparestype_titles();
2845: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 2846: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 2847: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
2848: my ($othercontrol,$serverdom);
2849: if ($serverhome ne $server) {
2850: $serverdom = &Apache::lonnet::host_domain($serverhome);
2851: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2852: } else {
2853: $serverdom = &Apache::lonnet::host_domain($server);
2854: if ($serverdom ne $dom) {
2855: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
2856: }
2857: }
2858: next unless (ref($spareid->{$server}) eq 'HASH');
1.145 raeburn 2859: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
2860: $datatable .= '<tr'.$css_class.'>
2861: <td rowspan="2">
1.183 bisitz 2862: <span class="LC_nobreak">'.
2863: &mt('[_1] when busy, offloads to:'
2864: ,'<b>'.$server.'</b>').
2865: "\n";
1.145 raeburn 2866: my (%current,%canselect);
1.152 raeburn 2867: my @choices =
2868: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
2869: foreach my $type ('primary','default') {
2870: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 2871: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
2872: my @spares = @{$spareid->{$server}{$type}};
2873: if (@spares > 0) {
1.152 raeburn 2874: if ($othercontrol) {
2875: $current{$type} = join(', ',@spares);
2876: } else {
2877: $current{$type} .= '<table>';
2878: my $numspares = scalar(@spares);
2879: for (my $i=0; $i<@spares; $i++) {
2880: my $rem = $i%($numinrow);
2881: if ($rem == 0) {
2882: if ($i > 0) {
2883: $current{$type} .= '</tr>';
2884: }
2885: $current{$type} .= '<tr>';
1.145 raeburn 2886: }
1.152 raeburn 2887: $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'".');" /> '.
2888: $spareid->{$server}{$type}[$i].
2889: '</label></td>'."\n";
2890: }
2891: my $rem = @spares%($numinrow);
2892: my $colsleft = $numinrow - $rem;
2893: if ($colsleft > 1 ) {
2894: $current{$type} .= '<td colspan="'.$colsleft.
2895: '" class="LC_left_item">'.
2896: ' </td>';
2897: } elsif ($colsleft == 1) {
2898: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 2899: }
1.152 raeburn 2900: $current{$type} .= '</tr></table>';
1.150 raeburn 2901: }
1.145 raeburn 2902: }
2903: }
2904: if ($current{$type} eq '') {
2905: $current{$type} = &mt('None specified');
2906: }
1.152 raeburn 2907: if ($othercontrol) {
2908: if ($type eq 'primary') {
2909: $canselect{$type} = $othercontrol;
2910: }
2911: } else {
2912: $canselect{$type} =
2913: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
2914: '<select name="newspare_'.$type.'_'.$server.'" '.
2915: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
2916: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
2917: if (@choices > 0) {
2918: foreach my $lonhost (@choices) {
2919: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
2920: }
2921: }
2922: $canselect{$type} .= '</select>'."\n";
2923: }
2924: } else {
2925: $current{$type} = &mt('Could not be determined');
2926: if ($type eq 'primary') {
2927: $canselect{$type} = $othercontrol;
2928: }
1.145 raeburn 2929: }
1.152 raeburn 2930: if ($type eq 'default') {
2931: $datatable .= '<tr'.$css_class.'>';
2932: }
2933: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
2934: '<td>'.$current{$type}.'</td>'."\n".
2935: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 2936: }
2937: $itemcount ++;
2938: }
2939: }
2940: $$rowtotal += $itemcount;
2941: return $datatable;
2942: }
2943:
1.152 raeburn 2944: sub possible_newspares {
2945: my ($server,$currspares,$serverhomes,$altids) = @_;
2946: my $serverhostname = &Apache::lonnet::hostname($server);
2947: my %excluded;
2948: if ($serverhostname ne '') {
2949: %excluded = (
2950: $serverhostname => 1,
2951: );
2952: }
2953: if (ref($currspares) eq 'HASH') {
2954: foreach my $type (keys(%{$currspares})) {
2955: if (ref($currspares->{$type}) eq 'ARRAY') {
2956: if (@{$currspares->{$type}} > 0) {
2957: foreach my $curr (@{$currspares->{$type}}) {
2958: my $hostname = &Apache::lonnet::hostname($curr);
2959: $excluded{$hostname} = 1;
2960: }
2961: }
2962: }
2963: }
2964: }
2965: my @choices;
2966: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
2967: if (keys(%{$serverhomes}) > 1) {
2968: foreach my $name (sort(keys(%{$serverhomes}))) {
2969: unless ($excluded{$name}) {
2970: if (exists($altids->{$serverhomes->{$name}})) {
2971: push(@choices,$altids->{$serverhomes->{$name}});
2972: } else {
2973: push(@choices,$serverhomes->{$name});
1.145 raeburn 2974: }
2975: }
2976: }
2977: }
2978: }
1.152 raeburn 2979: return sort(@choices);
1.145 raeburn 2980: }
2981:
1.150 raeburn 2982: sub print_loadbalancing {
2983: my ($dom,$settings,$rowtotal) = @_;
2984: my $primary_id = &Apache::lonnet::domain($dom,'primary');
2985: my $intdom = &Apache::lonnet::internet_dom($primary_id);
2986: my $numinrow = 1;
2987: my $datatable;
2988: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.171 raeburn 2989: my (%currbalancer,%currtargets,%currrules,%existing);
2990: if (ref($settings) eq 'HASH') {
2991: %existing = %{$settings};
2992: }
2993: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
2994: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
2995: \%currtargets,\%currrules);
1.150 raeburn 2996: } else {
2997: return;
2998: }
2999: my ($othertitle,$usertypes,$types) =
3000: &Apache::loncommon::sorted_inst_types($dom);
1.209 raeburn 3001: my $rownum = 8;
1.150 raeburn 3002: if (ref($types) eq 'ARRAY') {
3003: $rownum += scalar(@{$types});
3004: }
1.171 raeburn 3005: my @css_class = ('LC_odd_row','LC_even_row');
3006: my $balnum = 0;
3007: my $islast;
3008: my (@toshow,$disabledtext);
3009: if (keys(%currbalancer) > 0) {
3010: @toshow = sort(keys(%currbalancer));
3011: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
3012: push(@toshow,'');
3013: }
3014: } else {
3015: @toshow = ('');
3016: $disabledtext = &mt('No existing load balancer');
3017: }
3018: foreach my $lonhost (@toshow) {
3019: if ($balnum == scalar(@toshow)-1) {
3020: $islast = 1;
3021: } else {
3022: $islast = 0;
3023: }
3024: my $cssidx = $balnum%2;
3025: my $targets_div_style = 'display: none';
3026: my $disabled_div_style = 'display: block';
3027: my $homedom_div_style = 'display: none';
3028: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
3029: '<td rowspan="'.$rownum.'" valign="top">'.
3030: '<p>';
3031: if ($lonhost eq '') {
1.210 raeburn 3032: $datatable .= '<span class="LC_nobreak">';
1.171 raeburn 3033: if (keys(%currbalancer) > 0) {
3034: $datatable .= &mt('Add balancer:');
3035: } else {
3036: $datatable .= &mt('Enable balancer:');
3037: }
3038: $datatable .= ' '.
3039: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
3040: ' id="loadbalancing_lonhost_'.$balnum.'"'.
3041: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
3042: '<option value="" selected="selected">'.&mt('None').
3043: '</option>'."\n";
3044: foreach my $server (sort(keys(%servers))) {
3045: next if ($currbalancer{$server});
3046: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
3047: }
1.210 raeburn 3048: $datatable .=
1.171 raeburn 3049: '</select>'."\n".
3050: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
3051: } else {
3052: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
3053: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
3054: &mt('Stop balancing').'</label>'.
3055: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
3056: $targets_div_style = 'display: block';
3057: $disabled_div_style = 'display: none';
3058: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
3059: $homedom_div_style = 'display: block';
3060: }
3061: }
3062: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
3063: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
3064: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
3065: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
3066: my ($numspares,@spares) = &count_servers($lonhost,%servers);
3067: my @sparestypes = ('primary','default');
3068: my %typetitles = &sparestype_titles();
3069: foreach my $sparetype (@sparestypes) {
3070: my $targettable;
3071: for (my $i=0; $i<$numspares; $i++) {
3072: my $checked;
3073: if (ref($currtargets{$lonhost}) eq 'HASH') {
3074: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
3075: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
3076: $checked = ' checked="checked"';
3077: }
3078: }
3079: }
3080: my ($chkboxval,$disabled);
3081: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
3082: $chkboxval = $spares[$i];
3083: }
3084: if (exists($currbalancer{$spares[$i]})) {
3085: $disabled = ' disabled="disabled"';
3086: }
1.210 raeburn 3087: $targettable .=
1.171 raeburn 3088: '<td><label><input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
3089: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
3090: '</span></label></td>';
3091: my $rem = $i%($numinrow);
3092: if ($rem == 0) {
3093: if (($i > 0) && ($i < $numspares-1)) {
3094: $targettable .= '</tr>';
3095: }
3096: if ($i < $numspares-1) {
3097: $targettable .= '<tr>';
1.150 raeburn 3098: }
3099: }
3100: }
1.171 raeburn 3101: if ($targettable ne '') {
3102: my $rem = $numspares%($numinrow);
3103: my $colsleft = $numinrow - $rem;
3104: if ($colsleft > 1 ) {
3105: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3106: ' </td>';
3107: } elsif ($colsleft == 1) {
3108: $targettable .= '<td class="LC_left_item"> </td>';
3109: }
3110: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
3111: '<table><tr>'.$targettable.'</tr></table><br />';
3112: }
3113: }
3114: $datatable .= '</div></td></tr>'.
3115: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
3116: $othertitle,$usertypes,$types,\%servers,
3117: \%currbalancer,$lonhost,
3118: $targets_div_style,$homedom_div_style,
3119: $css_class[$cssidx],$balnum,$islast);
3120: $$rowtotal += $rownum;
3121: $balnum ++;
3122: }
3123: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
3124: return $datatable;
3125: }
3126:
3127: sub get_loadbalancers_config {
3128: my ($servers,$existing,$currbalancer,$currtargets,$currrules) = @_;
3129: return unless ((ref($servers) eq 'HASH') &&
3130: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
3131: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH'));
3132: if (keys(%{$existing}) > 0) {
3133: my $oldlonhost;
3134: foreach my $key (sort(keys(%{$existing}))) {
3135: if ($key eq 'lonhost') {
3136: $oldlonhost = $existing->{'lonhost'};
3137: $currbalancer->{$oldlonhost} = 1;
3138: } elsif ($key eq 'targets') {
3139: if ($oldlonhost) {
3140: $currtargets->{$oldlonhost} = $existing->{'targets'};
3141: }
3142: } elsif ($key eq 'rules') {
3143: if ($oldlonhost) {
3144: $currrules->{$oldlonhost} = $existing->{'rules'};
3145: }
3146: } elsif (ref($existing->{$key}) eq 'HASH') {
3147: $currbalancer->{$key} = 1;
3148: $currtargets->{$key} = $existing->{$key}{'targets'};
3149: $currrules->{$key} = $existing->{$key}{'rules'};
1.150 raeburn 3150: }
3151: }
1.171 raeburn 3152: } else {
3153: my ($balancerref,$targetsref) =
3154: &Apache::lonnet::get_lonbalancer_config($servers);
3155: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
3156: foreach my $server (sort(keys(%{$balancerref}))) {
3157: $currbalancer->{$server} = 1;
3158: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 3159: }
3160: }
3161: }
1.171 raeburn 3162: return;
1.150 raeburn 3163: }
3164:
3165: sub loadbalancing_rules {
3166: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.171 raeburn 3167: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
3168: $css_class,$balnum,$islast) = @_;
1.150 raeburn 3169: my $output;
1.171 raeburn 3170: my $num = 0;
1.210 raeburn 3171: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 3172: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
3173: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
3174: foreach my $type (@{$alltypes}) {
1.171 raeburn 3175: $num ++;
1.150 raeburn 3176: my $current;
3177: if (ref($currrules) eq 'HASH') {
3178: $current = $currrules->{$type};
3179: }
1.209 raeburn 3180: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.171 raeburn 3181: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 3182: $current = '';
3183: }
3184: }
3185: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.171 raeburn 3186: $servers,$currbalancer,$lonhost,$dom,
3187: $targets_div_style,$homedom_div_style,
3188: $css_class,$balnum,$num,$islast);
1.150 raeburn 3189: }
3190: }
3191: return $output;
3192: }
3193:
3194: sub loadbalancing_titles {
3195: my ($dom,$intdom,$usertypes,$types) = @_;
3196: my %othertypes = (
3197: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
3198: '_LC_author' => &mt('Users from [_1] with author role',$dom),
3199: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
3200: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.209 raeburn 3201: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
3202: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 3203: );
1.209 raeburn 3204: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.150 raeburn 3205: if (ref($types) eq 'ARRAY') {
3206: unshift(@alltypes,@{$types},'default');
3207: }
3208: my %titles;
3209: foreach my $type (@alltypes) {
3210: if ($type =~ /^_LC_/) {
3211: $titles{$type} = $othertypes{$type};
3212: } elsif ($type eq 'default') {
3213: $titles{$type} = &mt('All users from [_1]',$dom);
3214: if (ref($types) eq 'ARRAY') {
3215: if (@{$types} > 0) {
3216: $titles{$type} = &mt('Other users from [_1]',$dom);
3217: }
3218: }
3219: } elsif (ref($usertypes) eq 'HASH') {
3220: $titles{$type} = $usertypes->{$type};
3221: }
3222: }
3223: return (\@alltypes,\%othertypes,\%titles);
3224: }
3225:
3226: sub loadbalance_rule_row {
1.171 raeburn 3227: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
3228: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.209 raeburn 3229: my @rulenames;
1.150 raeburn 3230: my %ruletitles = &offloadtype_text();
1.209 raeburn 3231: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
3232: @rulenames = ('balancer','offloadedto');
1.150 raeburn 3233: } else {
1.209 raeburn 3234: @rulenames = ('default','homeserver');
3235: if ($type eq '_LC_external') {
3236: push(@rulenames,'externalbalancer');
3237: } else {
3238: push(@rulenames,'specific');
3239: }
3240: push(@rulenames,'none');
1.150 raeburn 3241: }
3242: my $style = $targets_div_style;
1.209 raeburn 3243: if (($type eq '_LC_external') || ($type eq '_LC_internetdom') || ($type eq '_LC_ipchange')) {
1.150 raeburn 3244: $style = $homedom_div_style;
3245: }
1.171 raeburn 3246: my $space;
3247: if ($islast && $num == 1) {
3248: $space = '<div display="inline-block"> </div>';
3249: }
1.210 raeburn 3250: my $output =
1.171 raeburn 3251: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
3252: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
3253: '<td valaign="top">'.$space.
3254: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 3255: for (my $i=0; $i<@rulenames; $i++) {
3256: my $rule = $rulenames[$i];
3257: my ($checked,$extra);
3258: if ($rulenames[$i] eq 'default') {
3259: $rule = '';
3260: }
3261: if ($rulenames[$i] eq 'specific') {
3262: if (ref($servers) eq 'HASH') {
3263: my $default;
3264: if (($current ne '') && (exists($servers->{$current}))) {
3265: $checked = ' checked="checked"';
3266: }
3267: unless ($checked) {
3268: $default = ' selected="selected"';
3269: }
1.210 raeburn 3270: $extra =
1.171 raeburn 3271: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
3272: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
3273: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
3274: '<option value=""'.$default.'></option>'."\n";
3275: foreach my $server (sort(keys(%{$servers}))) {
3276: if (ref($currbalancer) eq 'HASH') {
3277: next if (exists($currbalancer->{$server}));
3278: }
1.150 raeburn 3279: my $selected;
1.171 raeburn 3280: if ($server eq $current) {
1.150 raeburn 3281: $selected = ' selected="selected"';
3282: }
1.171 raeburn 3283: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 3284: }
3285: $extra .= '</select>';
3286: }
3287: } elsif ($rule eq $current) {
3288: $checked = ' checked="checked"';
3289: }
3290: $output .= '<span class="LC_nobreak"><label>'.
1.171 raeburn 3291: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
3292: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
3293: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.150 raeburn 3294: ')"'.$checked.' /> '.$ruletitles{$rulenames[$i]}.
3295: '</label>'.$extra.'</span><br />'."\n";
3296: }
3297: $output .= '</div></td></tr>'."\n";
3298: return $output;
3299: }
3300:
3301: sub offloadtype_text {
3302: my %ruletitles = &Apache::lonlocal::texthash (
3303: 'default' => 'Offloads to default destinations',
3304: 'homeserver' => "Offloads to user's home server",
3305: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
3306: 'specific' => 'Offloads to specific server',
1.161 raeburn 3307: 'none' => 'No offload',
1.209 raeburn 3308: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
3309: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.150 raeburn 3310: );
3311: return %ruletitles;
3312: }
3313:
3314: sub sparestype_titles {
3315: my %typestitles = &Apache::lonlocal::texthash (
3316: 'primary' => 'primary',
3317: 'default' => 'default',
3318: );
3319: return %typestitles;
3320: }
3321:
1.28 raeburn 3322: sub contact_titles {
3323: my %titles = &Apache::lonlocal::texthash (
3324: 'supportemail' => 'Support E-mail address',
1.69 raeburn 3325: 'adminemail' => 'Default Server Admin E-mail address',
1.28 raeburn 3326: 'errormail' => 'Error reports to be e-mailed to',
3327: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.89 raeburn 3328: 'helpdeskmail' => 'Helpdesk requests to be e-mailed to',
3329: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
1.102 raeburn 3330: 'requestsmail' => 'E-mail from course requests requiring approval',
1.190 raeburn 3331: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.203 raeburn 3332: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.28 raeburn 3333: );
3334: my %short_titles = &Apache::lonlocal::texthash (
3335: adminemail => 'Admin E-mail address',
3336: supportemail => 'Support E-mail',
3337: );
3338: return (\%titles,\%short_titles);
3339: }
3340:
1.72 raeburn 3341: sub tool_titles {
3342: my %titles = &Apache::lonlocal::texthash (
1.162 raeburn 3343: aboutme => 'Personal web page',
1.86 raeburn 3344: blog => 'Blog',
1.162 raeburn 3345: webdav => 'WebDAV',
1.86 raeburn 3346: portfolio => 'Portfolio',
1.88 bisitz 3347: official => 'Official courses (with institutional codes)',
3348: unofficial => 'Unofficial courses',
1.98 raeburn 3349: community => 'Communities',
1.86 raeburn 3350: );
1.72 raeburn 3351: return %titles;
3352: }
3353:
1.101 raeburn 3354: sub courserequest_titles {
3355: my %titles = &Apache::lonlocal::texthash (
3356: official => 'Official',
3357: unofficial => 'Unofficial',
3358: community => 'Communities',
3359: norequest => 'Not allowed',
1.104 raeburn 3360: approval => 'Approval by Dom. Coord.',
1.101 raeburn 3361: validate => 'With validation',
3362: autolimit => 'Numerical limit',
1.103 raeburn 3363: unlimited => '(blank for unlimited)',
1.101 raeburn 3364: );
3365: return %titles;
3366: }
3367:
1.163 raeburn 3368: sub authorrequest_titles {
3369: my %titles = &Apache::lonlocal::texthash (
3370: norequest => 'Not allowed',
3371: approval => 'Approval by Dom. Coord.',
3372: automatic => 'Automatic approval',
3373: );
3374: return %titles;
1.210 raeburn 3375: }
1.163 raeburn 3376:
1.101 raeburn 3377: sub courserequest_conditions {
3378: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 3379: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.193 bisitz 3380: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 3381: );
3382: return %conditions;
3383: }
3384:
3385:
1.27 raeburn 3386: sub print_usercreation {
1.30 raeburn 3387: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 3388: my $numinrow = 4;
1.28 raeburn 3389: my $datatable;
3390: if ($position eq 'top') {
1.30 raeburn 3391: $$rowtotal ++;
1.34 raeburn 3392: my $rowcount = 0;
1.32 raeburn 3393: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 3394: if (ref($rules) eq 'HASH') {
3395: if (keys(%{$rules}) > 0) {
1.32 raeburn 3396: $datatable .= &user_formats_row('username',$settings,$rules,
3397: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 3398: $$rowtotal ++;
1.32 raeburn 3399: $rowcount ++;
3400: }
3401: }
3402: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
3403: if (ref($idrules) eq 'HASH') {
3404: if (keys(%{$idrules}) > 0) {
3405: $datatable .= &user_formats_row('id',$settings,$idrules,
3406: $idruleorder,$numinrow,$rowcount);
3407: $$rowtotal ++;
3408: $rowcount ++;
1.28 raeburn 3409: }
3410: }
1.43 raeburn 3411: my ($emailrules,$emailruleorder) =
3412: &Apache::lonnet::inst_userrules($dom,'email');
3413: if (ref($emailrules) eq 'HASH') {
3414: if (keys(%{$emailrules}) > 0) {
3415: $datatable .= &user_formats_row('email',$settings,$emailrules,
3416: $emailruleorder,$numinrow,$rowcount);
3417: $$rowtotal ++;
3418: $rowcount ++;
3419: }
3420: }
1.39 raeburn 3421: if ($rowcount == 0) {
3422: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
3423: $$rowtotal ++;
3424: $rowcount ++;
3425: }
1.34 raeburn 3426: } elsif ($position eq 'middle') {
1.100 raeburn 3427: my @creators = ('author','course','requestcrs','selfcreate');
1.37 raeburn 3428: my ($rules,$ruleorder) =
3429: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 3430: my %lt = &usercreation_types();
3431: my %checked;
1.50 raeburn 3432: my @selfcreate;
1.34 raeburn 3433: if (ref($settings) eq 'HASH') {
3434: if (ref($settings->{'cancreate'}) eq 'HASH') {
3435: foreach my $item (@creators) {
3436: $checked{$item} = $settings->{'cancreate'}{$item};
3437: }
1.50 raeburn 3438: if (ref($settings->{'cancreate'}{'selfcreate'}) eq 'ARRAY') {
3439: @selfcreate = @{$settings->{'cancreate'}{'selfcreate'}};
3440: } elsif ($settings->{'cancreate'}{'selfcreate'} ne '') {
3441: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
3442: @selfcreate = ('email','login','sso');
3443: } elsif ($settings->{'cancreate'}{'selfcreate'} ne 'none') {
3444: @selfcreate = ($settings->{'cancreate'}{'selfcreate'});
3445: }
3446: }
1.34 raeburn 3447: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
3448: foreach my $item (@creators) {
3449: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
3450: $checked{$item} = 'none';
3451: }
3452: }
3453: }
3454: }
3455: my $rownum = 0;
3456: foreach my $item (@creators) {
3457: $rownum ++;
1.50 raeburn 3458: if ($item ne 'selfcreate') {
3459: if ($checked{$item} eq '') {
1.43 raeburn 3460: $checked{$item} = 'any';
3461: }
1.34 raeburn 3462: }
3463: my $css_class;
3464: if ($rownum%2) {
3465: $css_class = '';
3466: } else {
3467: $css_class = ' class="LC_odd_row" ';
3468: }
3469: $datatable .= '<tr'.$css_class.'>'.
3470: '<td><span class="LC_nobreak">'.$lt{$item}.
3471: '</span></td><td align="right">';
1.50 raeburn 3472: my @options;
1.45 raeburn 3473: if ($item eq 'selfcreate') {
1.43 raeburn 3474: push(@options,('email','login','sso'));
3475: } else {
1.50 raeburn 3476: @options = ('any');
1.43 raeburn 3477: if (ref($rules) eq 'HASH') {
3478: if (keys(%{$rules}) > 0) {
3479: push(@options,('official','unofficial'));
3480: }
1.37 raeburn 3481: }
1.50 raeburn 3482: push(@options,'none');
1.37 raeburn 3483: }
3484: foreach my $option (@options) {
1.50 raeburn 3485: my $type = 'radio';
1.34 raeburn 3486: my $check = ' ';
1.50 raeburn 3487: if ($item eq 'selfcreate') {
3488: $type = 'checkbox';
3489: if (grep(/^\Q$option\E$/,@selfcreate)) {
3490: $check = ' checked="checked" ';
3491: }
3492: } else {
3493: if ($checked{$item} eq $option) {
3494: $check = ' checked="checked" ';
3495: }
1.34 raeburn 3496: }
3497: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 3498: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 3499: $item.'" value="'.$option.'"'.$check.'/> '.
3500: $lt{$option}.'</label> </span>';
3501: }
3502: $datatable .= '</td></tr>';
3503: }
1.93 raeburn 3504: my ($othertitle,$usertypes,$types) =
3505: &Apache::loncommon::sorted_inst_types($dom);
1.165 raeburn 3506: my $createsettings;
3507: if (ref($settings) eq 'HASH') {
3508: $createsettings = $settings->{cancreate};
3509: }
1.93 raeburn 3510: if (ref($usertypes) eq 'HASH') {
3511: if (keys(%{$usertypes}) > 0) {
1.99 raeburn 3512: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
1.93 raeburn 3513: $dom,$numinrow,$othertitle,
3514: 'statustocreate');
3515: $$rowtotal ++;
1.169 raeburn 3516: $rownum ++;
1.93 raeburn 3517: }
3518: }
1.169 raeburn 3519: $datatable .= &captcha_choice('cancreate',$createsettings,$rownum);
1.28 raeburn 3520: } else {
3521: my @contexts = ('author','course','domain');
3522: my @authtypes = ('int','krb4','krb5','loc');
3523: my %checked;
3524: if (ref($settings) eq 'HASH') {
3525: if (ref($settings->{'authtypes'}) eq 'HASH') {
3526: foreach my $item (@contexts) {
3527: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
3528: foreach my $auth (@authtypes) {
3529: if ($settings->{'authtypes'}{$item}{$auth}) {
3530: $checked{$item}{$auth} = ' checked="checked" ';
3531: }
3532: }
3533: }
3534: }
1.27 raeburn 3535: }
1.35 raeburn 3536: } else {
3537: foreach my $item (@contexts) {
1.36 raeburn 3538: foreach my $auth (@authtypes) {
1.35 raeburn 3539: $checked{$item}{$auth} = ' checked="checked" ';
3540: }
3541: }
1.27 raeburn 3542: }
1.28 raeburn 3543: my %title = &context_names();
3544: my %authname = &authtype_names();
3545: my $rownum = 0;
3546: my $css_class;
3547: foreach my $item (@contexts) {
3548: if ($rownum%2) {
3549: $css_class = '';
3550: } else {
3551: $css_class = ' class="LC_odd_row" ';
3552: }
1.30 raeburn 3553: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 3554: '<td>'.$title{$item}.
3555: '</td><td class="LC_left_item">'.
3556: '<span class="LC_nobreak">';
3557: foreach my $auth (@authtypes) {
3558: $datatable .= '<label>'.
3559: '<input type="checkbox" name="'.$item.'_auth" '.
3560: $checked{$item}{$auth}.' value="'.$auth.'" />'.
3561: $authname{$auth}.'</label> ';
3562: }
3563: $datatable .= '</span></td></tr>';
3564: $rownum ++;
1.27 raeburn 3565: }
1.30 raeburn 3566: $$rowtotal += $rownum;
1.27 raeburn 3567: }
3568: return $datatable;
3569: }
3570:
1.165 raeburn 3571: sub captcha_choice {
1.169 raeburn 3572: my ($context,$settings,$itemcount) = @_;
1.165 raeburn 3573: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext);
3574: my %lt = &captcha_phrases();
3575: $keyentry = 'hidden';
3576: if ($context eq 'cancreate') {
3577: $rowname = &mt('CAPTCHA validation (e-mail as username)');
1.169 raeburn 3578: } elsif ($context eq 'login') {
3579: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.165 raeburn 3580: }
3581: if (ref($settings) eq 'HASH') {
3582: if ($settings->{'captcha'}) {
3583: $checked{$settings->{'captcha'}} = ' checked="checked"';
3584: } else {
3585: $checked{'original'} = ' checked="checked"';
3586: }
3587: if ($settings->{'captcha'} eq 'recaptcha') {
3588: $pubtext = $lt{'pub'};
3589: $privtext = $lt{'priv'};
3590: $keyentry = 'text';
3591: }
3592: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
3593: $currpub = $settings->{'recaptchakeys'}{'public'};
3594: $currpriv = $settings->{'recaptchakeys'}{'private'};
3595: }
3596: } else {
3597: $checked{'original'} = ' checked="checked"';
3598: }
1.169 raeburn 3599: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3600: my $output = '<tr'.$css_class.'>'.
3601: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="2">'."\n".
1.165 raeburn 3602: '<table><tr><td>'."\n";
3603: foreach my $option ('original','recaptcha','notused') {
3604: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
3605: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
3606: $lt{$option}.'</label></span>';
3607: unless ($option eq 'notused') {
3608: $output .= (' 'x2)."\n";
3609: }
3610: }
3611: #
3612: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
3613: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
1.210 raeburn 3614: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
1.165 raeburn 3615: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
1.210 raeburn 3616: #
1.165 raeburn 3617: $output .= '</td></tr>'."\n".
3618: '<tr><td>'."\n".
3619: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
3620: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
3621: $currpub.'" size="40" /></span><br />'."\n".
3622: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
3623: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
3624: $currpriv.'" size="40" /></span></td></tr></table>'."\n".
3625: '</td></tr>';
3626: return $output;
3627: }
3628:
1.32 raeburn 3629: sub user_formats_row {
3630: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount) = @_;
3631: my $output;
3632: my %text = (
3633: 'username' => 'new usernames',
3634: 'id' => 'IDs',
1.45 raeburn 3635: 'email' => 'self-created accounts (e-mail)',
1.32 raeburn 3636: );
3637: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
3638: $output = '<tr '.$css_class.'>'.
1.63 raeburn 3639: '<td><span class="LC_nobreak">';
3640: if ($type eq 'email') {
3641: $output .= &mt("Formats disallowed for $text{$type}: ");
3642: } else {
3643: $output .= &mt("Format rules to check for $text{$type}: ");
3644: }
3645: $output .= '</span></td>'.
3646: '<td class="LC_left_item" colspan="2"><table>';
1.27 raeburn 3647: my $rem;
3648: if (ref($ruleorder) eq 'ARRAY') {
3649: for (my $i=0; $i<@{$ruleorder}; $i++) {
3650: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
3651: my $rem = $i%($numinrow);
3652: if ($rem == 0) {
3653: if ($i > 0) {
3654: $output .= '</tr>';
3655: }
3656: $output .= '<tr>';
3657: }
3658: my $check = ' ';
1.39 raeburn 3659: if (ref($settings) eq 'HASH') {
3660: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
3661: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
3662: $check = ' checked="checked" ';
3663: }
1.27 raeburn 3664: }
3665: }
3666: $output .= '<td class="LC_left_item">'.
3667: '<span class="LC_nobreak"><label>'.
1.32 raeburn 3668: '<input type="checkbox" name="'.$type.'_rule" '.
1.27 raeburn 3669: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
3670: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
3671: }
3672: }
3673: $rem = @{$ruleorder}%($numinrow);
3674: }
3675: my $colsleft = $numinrow - $rem;
3676: if ($colsleft > 1 ) {
3677: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
3678: ' </td>';
3679: } elsif ($colsleft == 1) {
3680: $output .= '<td class="LC_left_item"> </td>';
3681: }
3682: $output .= '</tr></table></td></tr>';
3683: return $output;
3684: }
3685:
1.34 raeburn 3686: sub usercreation_types {
3687: my %lt = &Apache::lonlocal::texthash (
3688: author => 'When adding a co-author',
3689: course => 'When adding a user to a course',
1.100 raeburn 3690: requestcrs => 'When requesting a course',
1.45 raeburn 3691: selfcreate => 'User creates own account',
1.34 raeburn 3692: any => 'Any',
3693: official => 'Institutional only ',
3694: unofficial => 'Non-institutional only',
1.85 schafran 3695: email => 'E-mail address',
1.43 raeburn 3696: login => 'Institutional Login',
3697: sso => 'SSO',
1.34 raeburn 3698: none => 'None',
3699: );
3700: return %lt;
1.48 raeburn 3701: }
1.34 raeburn 3702:
1.28 raeburn 3703: sub authtype_names {
3704: my %lt = &Apache::lonlocal::texthash(
3705: int => 'Internal',
3706: krb4 => 'Kerberos 4',
3707: krb5 => 'Kerberos 5',
3708: loc => 'Local',
3709: );
3710: return %lt;
3711: }
3712:
3713: sub context_names {
3714: my %context_title = &Apache::lonlocal::texthash(
3715: author => 'Creating users when an Author',
3716: course => 'Creating users when in a course',
3717: domain => 'Creating users when a Domain Coordinator',
3718: );
3719: return %context_title;
3720: }
3721:
1.33 raeburn 3722: sub print_usermodification {
3723: my ($position,$dom,$settings,$rowtotal) = @_;
3724: my $numinrow = 4;
3725: my ($context,$datatable,$rowcount);
3726: if ($position eq 'top') {
3727: $rowcount = 0;
3728: $context = 'author';
3729: foreach my $role ('ca','aa') {
3730: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3731: $numinrow,$rowcount);
3732: $$rowtotal ++;
3733: $rowcount ++;
3734: }
1.63 raeburn 3735: } elsif ($position eq 'middle') {
1.33 raeburn 3736: $context = 'course';
3737: $rowcount = 0;
3738: foreach my $role ('st','ep','ta','in','cr') {
3739: $datatable .= &modifiable_userdata_row($context,$role,$settings,
3740: $numinrow,$rowcount);
3741: $$rowtotal ++;
3742: $rowcount ++;
3743: }
1.63 raeburn 3744: } elsif ($position eq 'bottom') {
3745: $context = 'selfcreate';
3746: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3747: $usertypes->{'default'} = $othertitle;
3748: if (ref($types) eq 'ARRAY') {
3749: push(@{$types},'default');
3750: $usertypes->{'default'} = $othertitle;
3751: foreach my $status (@{$types}) {
3752: $datatable .= &modifiable_userdata_row($context,$status,$settings,
3753: $numinrow,$rowcount,$usertypes);
3754: $$rowtotal ++;
3755: $rowcount ++;
3756: }
3757: }
1.33 raeburn 3758: }
3759: return $datatable;
3760: }
3761:
1.43 raeburn 3762: sub print_defaults {
1.212 ! raeburn 3763: my ($dom,$settings,$rowtotal) = @_;
1.68 raeburn 3764: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
1.141 raeburn 3765: 'datelocale_def','portal_def');
1.212 ! raeburn 3766: my %defaults;
! 3767: if (ref($settings) eq 'HASH') {
! 3768: %defaults = %{$settings};
! 3769: } else {
! 3770: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
! 3771: foreach my $item (@items) {
! 3772: $defaults{$item} = $domdefaults{$item};
! 3773: }
! 3774: }
1.141 raeburn 3775: my $titles = &defaults_titles($dom);
1.43 raeburn 3776: my $rownum = 0;
3777: my ($datatable,$css_class);
3778: foreach my $item (@items) {
3779: if ($rownum%2) {
3780: $css_class = '';
3781: } else {
3782: $css_class = ' class="LC_odd_row" ';
3783: }
3784: $datatable .= '<tr'.$css_class.'>'.
3785: '<td><span class="LC_nobreak">'.$titles->{$item}.
3786: '</span></td><td class="LC_right_item">';
3787: if ($item eq 'auth_def') {
3788: my @authtypes = ('internal','krb4','krb5','localauth');
3789: my %shortauth = (
3790: internal => 'int',
3791: krb4 => 'krb4',
3792: krb5 => 'krb5',
3793: localauth => 'loc'
3794: );
3795: my %authnames = &authtype_names();
3796: foreach my $auth (@authtypes) {
3797: my $checked = ' ';
1.212 ! raeburn 3798: if ($defaults{$item} eq $auth) {
1.43 raeburn 3799: $checked = ' checked="checked" ';
3800: }
3801: $datatable .= '<label><input type="radio" name="'.$item.
3802: '" value="'.$auth.'"'.$checked.'/>'.
3803: $authnames{$shortauth{$auth}}.'</label> ';
3804: }
1.54 raeburn 3805: } elsif ($item eq 'timezone_def') {
3806: my $includeempty = 1;
1.212 ! raeburn 3807: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
1.68 raeburn 3808: } elsif ($item eq 'datelocale_def') {
3809: my $includeempty = 1;
1.212 ! raeburn 3810: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
1.167 raeburn 3811: } elsif ($item eq 'lang_def') {
1.168 raeburn 3812: my %langchoices = &get_languages_hash();
3813: $langchoices{''} = 'No language preference';
1.167 raeburn 3814: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.212 ! raeburn 3815: $datatable .= &Apache::loncommon::select_form($defaults{$item},$item,
1.167 raeburn 3816: \%langchoices);
1.43 raeburn 3817: } else {
1.141 raeburn 3818: my $size;
3819: if ($item eq 'portal_def') {
3820: $size = ' size="25"';
3821: }
1.43 raeburn 3822: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.212 ! raeburn 3823: $defaults{$item}.'"'.$size.' />';
1.43 raeburn 3824: }
3825: $datatable .= '</td></tr>';
3826: $rownum ++;
3827: }
3828: $$rowtotal += $rownum;
3829: return $datatable;
3830: }
3831:
1.168 raeburn 3832: sub get_languages_hash {
3833: my %langchoices;
3834: foreach my $id (&Apache::loncommon::languageids()) {
3835: my $code = &Apache::loncommon::supportedlanguagecode($id);
3836: if ($code ne '') {
3837: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
3838: }
3839: }
3840: return %langchoices;
3841: }
3842:
1.43 raeburn 3843: sub defaults_titles {
1.141 raeburn 3844: my ($dom) = @_;
1.43 raeburn 3845: my %titles = &Apache::lonlocal::texthash (
3846: 'auth_def' => 'Default authentication type',
3847: 'auth_arg_def' => 'Default authentication argument',
3848: 'lang_def' => 'Default language',
1.54 raeburn 3849: 'timezone_def' => 'Default timezone',
1.68 raeburn 3850: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 3851: 'portal_def' => 'Portal/Default URL',
1.43 raeburn 3852: );
1.141 raeburn 3853: if ($dom) {
3854: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
3855: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
3856: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
3857: $protocol = 'http' if ($protocol ne 'https');
3858: if ($uint_dom) {
3859: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
3860: $uint_dom);
3861: }
3862: }
1.43 raeburn 3863: return (\%titles);
3864: }
3865:
1.46 raeburn 3866: sub print_scantronformat {
3867: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
3868: my $itemcount = 1;
1.60 raeburn 3869: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
3870: %confhash);
1.46 raeburn 3871: my $switchserver = &check_switchserver($dom,$confname);
3872: my %lt = &Apache::lonlocal::texthash (
1.95 www 3873: default => 'Default bubblesheet format file error',
3874: custom => 'Custom bubblesheet format file error',
1.46 raeburn 3875: );
3876: my %scantronfiles = (
3877: default => 'default.tab',
3878: custom => 'custom.tab',
3879: );
3880: foreach my $key (keys(%scantronfiles)) {
3881: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
3882: .$scantronfiles{$key};
3883: }
3884: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
3885: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
3886: if (!$switchserver) {
3887: my $servadm = $r->dir_config('lonAdmEMail');
3888: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
3889: if ($configuserok eq 'ok') {
3890: if ($author_ok eq 'ok') {
3891: my %legacyfile = (
3892: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
3893: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
3894: );
3895: my %md5chk;
3896: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3897: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
3898: chomp($md5chk{$type});
1.46 raeburn 3899: }
3900: if ($md5chk{'default'} ne $md5chk{'custom'}) {
3901: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 3902: ($scantronurls{$type},my $error) =
1.46 raeburn 3903: &legacy_scantronformat($r,$dom,$confname,
3904: $type,$legacyfile{$type},
3905: $scantronurls{$type},
3906: $scantronfiles{$type});
1.60 raeburn 3907: if ($error ne '') {
3908: $error{$type} = $error;
3909: }
3910: }
3911: if (keys(%error) == 0) {
3912: $is_custom = 1;
3913: $confhash{'scantron'}{'scantronformat'} =
3914: $scantronurls{'custom'};
3915: my $putresult =
3916: &Apache::lonnet::put_dom('configuration',
3917: \%confhash,$dom);
3918: if ($putresult ne 'ok') {
3919: $error{'custom'} =
3920: '<span class="LC_error">'.
3921: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3922: }
1.46 raeburn 3923: }
3924: } else {
1.60 raeburn 3925: ($scantronurls{'default'},my $error) =
1.46 raeburn 3926: &legacy_scantronformat($r,$dom,$confname,
3927: 'default',$legacyfile{'default'},
3928: $scantronurls{'default'},
3929: $scantronfiles{'default'});
1.60 raeburn 3930: if ($error eq '') {
3931: $confhash{'scantron'}{'scantronformat'} = '';
3932: my $putresult =
3933: &Apache::lonnet::put_dom('configuration',
3934: \%confhash,$dom);
3935: if ($putresult ne 'ok') {
3936: $error{'default'} =
3937: '<span class="LC_error">'.
3938: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
3939: }
3940: } else {
3941: $error{'default'} = $error;
3942: }
1.46 raeburn 3943: }
3944: }
3945: }
3946: } else {
1.95 www 3947: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 3948: }
3949: }
3950: if (ref($settings) eq 'HASH') {
3951: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
3952: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
3953: if ((!@info) || ($info[0] eq 'no_such_dir')) {
3954: $scantronurl = '';
3955: } else {
3956: $scantronurl = $settings->{'scantronformat'};
3957: }
3958: $is_custom = 1;
3959: } else {
3960: $scantronurl = $scantronurls{'default'};
3961: }
3962: } else {
1.60 raeburn 3963: if ($is_custom) {
3964: $scantronurl = $scantronurls{'custom'};
3965: } else {
3966: $scantronurl = $scantronurls{'default'};
3967: }
1.46 raeburn 3968: }
3969: $css_class = $itemcount%2?' class="LC_odd_row"':'';
3970: $datatable .= '<tr'.$css_class.'>';
3971: if (!$is_custom) {
1.65 raeburn 3972: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
3973: '<span class="LC_nobreak">';
1.46 raeburn 3974: if ($scantronurl) {
1.199 raeburn 3975: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
3976: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 3977: } else {
3978: $datatable = &mt('File unavailable for display');
3979: }
1.65 raeburn 3980: $datatable .= '</span></td>';
1.60 raeburn 3981: if (keys(%error) == 0) {
3982: $datatable .= '<td valign="bottom">';
3983: if (!$switchserver) {
3984: $datatable .= &mt('Upload:').'<br />';
3985: }
3986: } else {
3987: my $errorstr;
3988: foreach my $key (sort(keys(%error))) {
3989: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3990: }
3991: $datatable .= '<td>'.$errorstr;
3992: }
1.46 raeburn 3993: } else {
3994: if (keys(%error) > 0) {
3995: my $errorstr;
3996: foreach my $key (sort(keys(%error))) {
3997: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
3998: }
1.60 raeburn 3999: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 4000: } elsif ($scantronurl) {
1.199 raeburn 4001: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
4002: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 4003: $datatable .= '<td><span class="LC_nobreak">'.
1.199 raeburn 4004: $link.
4005: '<label><input type="checkbox" name="scantronformat_del"'.
4006: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 4007: '<td><span class="LC_nobreak"> '.
4008: &mt('Replace:').'</span><br />';
1.46 raeburn 4009: }
4010: }
4011: if (keys(%error) == 0) {
4012: if ($switchserver) {
4013: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
4014: } else {
1.65 raeburn 4015: $datatable .='<span class="LC_nobreak"> '.
4016: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 4017: }
4018: }
4019: $datatable .= '</td></tr>';
4020: $$rowtotal ++;
4021: return $datatable;
4022: }
4023:
4024: sub legacy_scantronformat {
4025: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
4026: my ($url,$error);
4027: my @statinfo = &Apache::lonnet::stat_file($newurl);
4028: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
4029: (my $result,$url) =
4030: &publishlogo($r,'copy',$legacyfile,$dom,$confname,'scantron',
4031: '','',$newfile);
4032: if ($result ne 'ok') {
1.130 raeburn 4033: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 4034: }
4035: }
4036: return ($url,$error);
4037: }
1.43 raeburn 4038:
1.49 raeburn 4039: sub print_coursecategories {
1.57 raeburn 4040: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
4041: my $datatable;
4042: if ($position eq 'top') {
4043: my $toggle_cats_crs = ' ';
4044: my $toggle_cats_dom = ' checked="checked" ';
4045: my $can_cat_crs = ' ';
4046: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 4047: my $toggle_catscomm_comm = ' ';
4048: my $toggle_catscomm_dom = ' checked="checked" ';
4049: my $can_catcomm_comm = ' ';
4050: my $can_catcomm_dom = ' checked="checked" ';
4051:
1.57 raeburn 4052: if (ref($settings) eq 'HASH') {
4053: if ($settings->{'togglecats'} eq 'crs') {
4054: $toggle_cats_crs = $toggle_cats_dom;
4055: $toggle_cats_dom = ' ';
4056: }
4057: if ($settings->{'categorize'} eq 'crs') {
4058: $can_cat_crs = $can_cat_dom;
4059: $can_cat_dom = ' ';
4060: }
1.120 raeburn 4061: if ($settings->{'togglecatscomm'} eq 'comm') {
4062: $toggle_catscomm_comm = $toggle_catscomm_dom;
4063: $toggle_catscomm_dom = ' ';
4064: }
4065: if ($settings->{'categorizecomm'} eq 'comm') {
4066: $can_catcomm_comm = $can_catcomm_dom;
4067: $can_catcomm_dom = ' ';
4068: }
1.57 raeburn 4069: }
4070: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 4071: togglecats => 'Show/Hide a course in catalog',
4072: togglecatscomm => 'Show/Hide a community in catalog',
4073: categorize => 'Assign a category to a course',
4074: categorizecomm => 'Assign a category to a community',
1.57 raeburn 4075: );
4076: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 4077: dom => 'Set in Domain',
4078: crs => 'Set in Course',
4079: comm => 'Set in Community',
1.57 raeburn 4080: );
4081: $datatable = '<tr class="LC_odd_row">'.
4082: '<td>'.$title{'togglecats'}.'</td>'.
4083: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4084: '<input type="radio" name="togglecats"'.
4085: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4086: '<label><input type="radio" name="togglecats"'.
4087: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
4088: '</tr><tr>'.
4089: '<td>'.$title{'categorize'}.'</td>'.
4090: '<td class="LC_right_item"><span class="LC_nobreak">'.
4091: '<label><input type="radio" name="categorize"'.
4092: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4093: '<label><input type="radio" name="categorize"'.
4094: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 4095: '</tr><tr class="LC_odd_row">'.
4096: '<td>'.$title{'togglecatscomm'}.'</td>'.
4097: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4098: '<input type="radio" name="togglecatscomm"'.
4099: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4100: '<label><input type="radio" name="togglecatscomm"'.
4101: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
4102: '</tr><tr>'.
4103: '<td>'.$title{'categorizecomm'}.'</td>'.
4104: '<td class="LC_right_item"><span class="LC_nobreak">'.
4105: '<label><input type="radio" name="categorizecomm"'.
4106: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
4107: '<label><input type="radio" name="categorizecomm"'.
4108: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 4109: '</tr>';
1.120 raeburn 4110: $$rowtotal += 4;
1.57 raeburn 4111: } else {
4112: my $css_class;
4113: my $itemcount = 1;
4114: my $cathash;
4115: if (ref($settings) eq 'HASH') {
4116: $cathash = $settings->{'cats'};
4117: }
4118: if (ref($cathash) eq 'HASH') {
4119: my (@cats,@trails,%allitems,%idx,@jsarray);
4120: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
4121: \%allitems,\%idx,\@jsarray);
4122: my $maxdepth = scalar(@cats);
4123: my $colattrib = '';
4124: if ($maxdepth > 2) {
4125: $colattrib = ' colspan="2" ';
4126: }
4127: my @path;
4128: if (@cats > 0) {
4129: if (ref($cats[0]) eq 'ARRAY') {
4130: my $numtop = @{$cats[0]};
4131: my $maxnum = $numtop;
1.120 raeburn 4132: my %default_names = (
4133: instcode => &mt('Official courses'),
4134: communities => &mt('Communities'),
4135: );
4136:
4137: if ((!grep(/^instcode$/,@{$cats[0]})) ||
4138: ($cathash->{'instcode::0'} eq '') ||
4139: (!grep(/^communities$/,@{$cats[0]})) ||
4140: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 4141: $maxnum ++;
4142: }
4143: my $lastidx;
4144: for (my $i=0; $i<$numtop; $i++) {
4145: my $parent = $cats[0][$i];
4146: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4147: my $item = &escape($parent).'::0';
4148: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
4149: $lastidx = $idx{$item};
4150: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4151: .'<select name="'.$item.'"'.$chgstr.'>';
4152: for (my $k=0; $k<=$maxnum; $k++) {
4153: my $vpos = $k+1;
4154: my $selstr;
4155: if ($k == $i) {
4156: $selstr = ' selected="selected" ';
4157: }
4158: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4159: }
4160: $datatable .= '</select></td><td>';
1.120 raeburn 4161: if ($parent eq 'instcode' || $parent eq 'communities') {
4162: $datatable .= '<span class="LC_nobreak">'
4163: .$default_names{$parent}.'</span>';
4164: if ($parent eq 'instcode') {
4165: $datatable .= '<br /><span class="LC_nobreak">('
4166: .&mt('with institutional codes')
4167: .')</span></td><td'.$colattrib.'>';
4168: } else {
4169: $datatable .= '<table><tr><td>';
4170: }
4171: $datatable .= '<span class="LC_nobreak">'
4172: .'<label><input type="radio" name="'
4173: .$parent.'" value="1" checked="checked" />'
4174: .&mt('Display').'</label>';
4175: if ($parent eq 'instcode') {
4176: $datatable .= ' ';
4177: } else {
4178: $datatable .= '</span></td></tr><tr><td>'
4179: .'<span class="LC_nobreak">';
4180: }
4181: $datatable .= '<label><input type="radio" name="'
4182: .$parent.'" value="0" />'
4183: .&mt('Do not display').'</label></span>';
4184: if ($parent eq 'communities') {
4185: $datatable .= '</td></tr></table>';
4186: }
4187: $datatable .= '</td>';
1.57 raeburn 4188: } else {
4189: $datatable .= $parent
4190: .' <label><input type="checkbox" name="deletecategory" '
4191: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
4192: }
4193: my $depth = 1;
4194: push(@path,$parent);
4195: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
4196: pop(@path);
4197: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
4198: $itemcount ++;
4199: }
1.48 raeburn 4200: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 4201: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
4202: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 4203: for (my $k=0; $k<=$maxnum; $k++) {
4204: my $vpos = $k+1;
4205: my $selstr;
1.57 raeburn 4206: if ($k == $numtop) {
1.48 raeburn 4207: $selstr = ' selected="selected" ';
4208: }
4209: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4210: }
1.59 bisitz 4211: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 4212: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
4213: .'</tr>'."\n";
1.48 raeburn 4214: $itemcount ++;
1.120 raeburn 4215: foreach my $default ('instcode','communities') {
4216: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
4217: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4218: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
4219: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
4220: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
4221: for (my $k=0; $k<=$maxnum; $k++) {
4222: my $vpos = $k+1;
4223: my $selstr;
4224: if ($k == $maxnum) {
4225: $selstr = ' selected="selected" ';
4226: }
4227: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 4228: }
1.120 raeburn 4229: $datatable .= '</select></span></td>'.
4230: '<td><span class="LC_nobreak">'.
4231: $default_names{$default}.'</span>';
4232: if ($default eq 'instcode') {
4233: $datatable .= '<br /><span class="LC_nobreak">('
4234: .&mt('with institutional codes').')</span>';
4235: }
4236: $datatable .= '</td>'
4237: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
4238: .&mt('Display').'</label> '
4239: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
4240: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 4241: }
4242: }
4243: }
1.57 raeburn 4244: } else {
4245: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 4246: }
4247: } else {
1.57 raeburn 4248: $datatable .= '<td class="LC_right_item">'.$hdritem->{'header'}->[0]->{'col2'}.'</td>'
4249: .&initialize_categories($itemcount);
1.48 raeburn 4250: }
1.57 raeburn 4251: $$rowtotal += $itemcount;
1.48 raeburn 4252: }
4253: return $datatable;
4254: }
4255:
1.69 raeburn 4256: sub print_serverstatuses {
4257: my ($dom,$settings,$rowtotal) = @_;
4258: my $datatable;
4259: my @pages = &serverstatus_pages();
4260: my (%namedaccess,%machineaccess);
4261: foreach my $type (@pages) {
4262: $namedaccess{$type} = '';
4263: $machineaccess{$type}= '';
4264: }
4265: if (ref($settings) eq 'HASH') {
4266: foreach my $type (@pages) {
4267: if (exists($settings->{$type})) {
4268: if (ref($settings->{$type}) eq 'HASH') {
4269: foreach my $key (keys(%{$settings->{$type}})) {
4270: if ($key eq 'namedusers') {
4271: $namedaccess{$type} = $settings->{$type}->{$key};
4272: } elsif ($key eq 'machines') {
4273: $machineaccess{$type} = $settings->{$type}->{$key};
4274: }
4275: }
4276: }
4277: }
4278: }
4279: }
1.81 raeburn 4280: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 4281: my $rownum = 0;
4282: my $css_class;
4283: foreach my $type (@pages) {
4284: $rownum ++;
4285: $css_class = $rownum%2?' class="LC_odd_row"':'';
4286: $datatable .= '<tr'.$css_class.'>'.
4287: '<td><span class="LC_nobreak">'.
4288: $titles->{$type}.'</span></td>'.
4289: '<td class="LC_left_item">'.
4290: '<input type="text" name="'.$type.'_namedusers" '.
4291: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
4292: '<td class="LC_right_item">'.
4293: '<span class="LC_nobreak">'.
4294: '<input type="text" name="'.$type.'_machines" '.
4295: 'value="'.$machineaccess{$type}.'" size="10" />'.
4296: '</td></tr>'."\n";
4297: }
4298: $$rowtotal += $rownum;
4299: return $datatable;
4300: }
4301:
4302: sub serverstatus_pages {
4303: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.189 raeburn 4304: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.156 raeburn 4305: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf');
1.69 raeburn 4306: }
4307:
1.49 raeburn 4308: sub coursecategories_javascript {
4309: my ($settings) = @_;
1.57 raeburn 4310: my ($output,$jstext,$cathash);
1.49 raeburn 4311: if (ref($settings) eq 'HASH') {
1.57 raeburn 4312: $cathash = $settings->{'cats'};
4313: }
4314: if (ref($cathash) eq 'HASH') {
1.49 raeburn 4315: my (@cats,@jsarray,%idx);
1.57 raeburn 4316: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 4317: if (@jsarray > 0) {
4318: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
4319: for (my $i=0; $i<@jsarray; $i++) {
4320: if (ref($jsarray[$i]) eq 'ARRAY') {
4321: my $catstr = join('","',@{$jsarray[$i]});
4322: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
4323: }
4324: }
4325: }
4326: } else {
4327: $jstext = ' var categories = Array(1);'."\n".
4328: ' categories[0] = Array("instcode_pos");'."\n";
4329: }
1.120 raeburn 4330: my $instcode_reserved = &mt('The name: "instcode" is a reserved category');
4331: my $communities_reserved = &mt('The name: "communities" is a reserved category');
4332: my $choose_again = '\\n'.&mt('Please use a different name for the new top level category');
1.49 raeburn 4333: $output = <<"ENDSCRIPT";
4334: <script type="text/javascript">
1.109 raeburn 4335: // <![CDATA[
1.49 raeburn 4336: function reorderCats(form,parent,item,idx) {
4337: var changedVal;
4338: $jstext
4339: var newpos = 'addcategory_pos';
4340: var current = new Array;
4341: if (parent == '') {
4342: var has_instcode = 0;
4343: var maxtop = categories[idx].length;
4344: for (var j=0; j<maxtop; j++) {
4345: if (categories[idx][j] == 'instcode::0') {
4346: has_instcode == 1;
4347: }
4348: }
4349: if (has_instcode == 0) {
4350: categories[idx][maxtop] = 'instcode_pos';
4351: }
4352: } else {
4353: newpos += '_'+parent;
4354: }
4355: var maxh = 1 + categories[idx].length;
4356: var current = new Array;
4357: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4358: if (item == newpos) {
4359: changedVal = newitemVal;
4360: } else {
4361: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4362: current[newitemVal] = newpos;
4363: }
4364: for (var i=0; i<categories[idx].length; i++) {
4365: var elementName = categories[idx][i];
4366: if (elementName != item) {
4367: if (form.elements[elementName]) {
4368: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4369: current[currVal] = elementName;
4370: }
4371: }
4372: }
4373: var oldVal;
4374: for (var j=0; j<maxh; j++) {
4375: if (current[j] == undefined) {
4376: oldVal = j;
4377: }
4378: }
4379: if (oldVal < changedVal) {
4380: for (var k=oldVal+1; k<=changedVal ; k++) {
4381: var elementName = current[k];
4382: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4383: }
4384: } else {
4385: for (var k=changedVal; k<oldVal; k++) {
4386: var elementName = current[k];
4387: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4388: }
4389: }
4390: return;
4391: }
1.120 raeburn 4392:
4393: function categoryCheck(form) {
4394: if (form.elements['addcategory_name'].value == 'instcode') {
4395: alert('$instcode_reserved\\n$choose_again');
4396: return false;
4397: }
4398: if (form.elements['addcategory_name'].value == 'communities') {
4399: alert('$communities_reserved\\n$choose_again');
4400: return false;
4401: }
4402: return true;
4403: }
4404:
1.109 raeburn 4405: // ]]>
1.49 raeburn 4406: </script>
4407:
4408: ENDSCRIPT
4409: return $output;
4410: }
4411:
1.48 raeburn 4412: sub initialize_categories {
4413: my ($itemcount) = @_;
1.120 raeburn 4414: my ($datatable,$css_class,$chgstr);
4415: my %default_names = (
4416: instcode => 'Official courses (with institutional codes)',
4417: communities => 'Communities',
4418: );
4419: my $select0 = ' selected="selected"';
4420: my $select1 = '';
4421: foreach my $default ('instcode','communities') {
4422: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4423: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'',$default"."_pos','0'".');"';
4424: if ($default eq 'communities') {
4425: $select1 = $select0;
4426: $select0 = '';
4427: }
4428: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
4429: .'<select name="'.$default.'_pos">'
4430: .'<option value="0"'.$select0.'>1</option>'
4431: .'<option value="1"'.$select1.'>2</option>'
4432: .'<option value="2">3</option></select> '
4433: .$default_names{$default}
4434: .'</span></td><td><span class="LC_nobreak">'
4435: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
4436: .&mt('Display').'</label> <label>'
4437: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 4438: .'</label></span></td></tr>';
1.120 raeburn 4439: $itemcount ++;
4440: }
1.48 raeburn 4441: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 4442: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 4443: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 4444: .'<select name="addcategory_pos"'.$chgstr.'>'
4445: .'<option value="0">1</option>'
4446: .'<option value="1">2</option>'
4447: .'<option value="2" selected="selected">3</option></select> '
1.48 raeburn 4448: .&mt('Add category').'</td><td>'.&mt('Name:')
4449: .' <input type="text" size="20" name="addcategory_name" value="" /></td></tr>';
4450: return $datatable;
4451: }
4452:
4453: sub build_category_rows {
1.49 raeburn 4454: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
4455: my ($text,$name,$item,$chgstr);
1.48 raeburn 4456: if (ref($cats) eq 'ARRAY') {
4457: my $maxdepth = scalar(@{$cats});
4458: if (ref($cats->[$depth]) eq 'HASH') {
4459: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
4460: my $numchildren = @{$cats->[$depth]{$parent}};
4461: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.204 raeburn 4462: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 4463: my ($idxnum,$parent_name,$parent_item);
4464: my $higher = $depth - 1;
4465: if ($higher == 0) {
4466: $parent_name = &escape($parent).'::'.$higher;
4467: } else {
4468: if (ref($path) eq 'ARRAY') {
4469: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4470: }
4471: }
4472: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 4473: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 4474: if ($j < $numchildren) {
1.48 raeburn 4475: $name = $cats->[$depth]{$parent}[$j];
4476: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 4477: $idxnum = $idx->{$item};
4478: } else {
4479: $name = $parent_name;
4480: $item = $parent_item;
1.48 raeburn 4481: }
1.49 raeburn 4482: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
4483: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 4484: for (my $i=0; $i<=$numchildren; $i++) {
4485: my $vpos = $i+1;
4486: my $selstr;
4487: if ($j == $i) {
4488: $selstr = ' selected="selected" ';
4489: }
4490: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
4491: }
4492: $text .= '</select> ';
4493: if ($j < $numchildren) {
4494: my $deeper = $depth+1;
4495: $text .= $name.' '
4496: .'<label><input type="checkbox" name="deletecategory" value="'
4497: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
4498: if(ref($path) eq 'ARRAY') {
4499: push(@{$path},$name);
1.49 raeburn 4500: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 4501: pop(@{$path});
4502: }
4503: } else {
1.59 bisitz 4504: $text .= &mt('Add subcategory:').' </span><input type="textbox" size="20" name="addcategory_name_';
1.48 raeburn 4505: if ($j == $numchildren) {
4506: $text .= $name;
4507: } else {
4508: $text .= $item;
4509: }
4510: $text .= '" value="" />';
4511: }
4512: $text .= '</td></tr>';
4513: }
4514: $text .= '</table></td>';
4515: } else {
4516: my $higher = $depth-1;
4517: if ($higher == 0) {
4518: $name = &escape($parent).'::'.$higher;
4519: } else {
4520: if (ref($path) eq 'ARRAY') {
4521: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
4522: }
4523: }
4524: my $colspan;
4525: if ($parent ne 'instcode') {
4526: $colspan = $maxdepth - $depth - 1;
4527: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="textbox" size="20" name="subcat_'.$name.'" value="" /></td>';
4528: }
4529: }
4530: }
4531: }
4532: return $text;
4533: }
4534:
1.33 raeburn 4535: sub modifiable_userdata_row {
1.63 raeburn 4536: my ($context,$role,$settings,$numinrow,$rowcount,$usertypes) = @_;
1.33 raeburn 4537: my $rolename;
1.63 raeburn 4538: if ($context eq 'selfcreate') {
4539: if (ref($usertypes) eq 'HASH') {
4540: $rolename = $usertypes->{$role};
4541: } else {
4542: $rolename = $role;
4543: }
1.33 raeburn 4544: } else {
1.63 raeburn 4545: if ($role eq 'cr') {
4546: $rolename = &mt('Custom role');
4547: } else {
4548: $rolename = &Apache::lonnet::plaintext($role);
4549: }
1.33 raeburn 4550: }
4551: my @fields = ('lastname','firstname','middlename','generation',
4552: 'permanentemail','id');
4553: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
4554: my $output;
4555: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
4556: $output = '<tr '.$css_class.'>'.
4557: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
4558: '<td class="LC_left_item" colspan="2"><table>';
4559: my $rem;
4560: my %checks;
4561: if (ref($settings) eq 'HASH') {
4562: if (ref($settings->{$context}) eq 'HASH') {
4563: if (ref($settings->{$context}->{$role}) eq 'HASH') {
4564: foreach my $field (@fields) {
4565: if ($settings->{$context}->{$role}->{$field}) {
4566: $checks{$field} = ' checked="checked" ';
4567: }
4568: }
4569: }
4570: }
4571: }
4572: for (my $i=0; $i<@fields; $i++) {
4573: my $rem = $i%($numinrow);
4574: if ($rem == 0) {
4575: if ($i > 0) {
4576: $output .= '</tr>';
4577: }
4578: $output .= '<tr>';
4579: }
4580: my $check = ' ';
4581: if (exists($checks{$fields[$i]})) {
4582: $check = $checks{$fields[$i]}
4583: } else {
4584: if ($role eq 'st') {
4585: if (ref($settings) ne 'HASH') {
4586: $check = ' checked="checked" ';
4587: }
4588: }
4589: }
4590: $output .= '<td class="LC_left_item">'.
4591: '<span class="LC_nobreak"><label>'.
4592: '<input type="checkbox" name="canmodify_'.$role.'" '.
4593: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
4594: '</label></span></td>';
4595: $rem = @fields%($numinrow);
4596: }
4597: my $colsleft = $numinrow - $rem;
4598: if ($colsleft > 1 ) {
4599: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4600: ' </td>';
4601: } elsif ($colsleft == 1) {
4602: $output .= '<td class="LC_left_item"> </td>';
4603: }
4604: $output .= '</tr></table></td></tr>';
4605: return $output;
4606: }
1.28 raeburn 4607:
1.93 raeburn 4608: sub insttypes_row {
4609: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context) = @_;
4610: my %lt = &Apache::lonlocal::texthash (
4611: cansearch => 'Users allowed to search',
4612: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 4613: lockablenames => 'User preference to lock name',
1.93 raeburn 4614: );
4615: my $showdom;
4616: if ($context eq 'cansearch') {
4617: $showdom = ' ('.$dom.')';
4618: }
1.165 raeburn 4619: my $class = 'LC_left_item';
4620: if ($context eq 'statustocreate') {
4621: $class = 'LC_right_item';
4622: }
1.25 raeburn 4623: my $output = '<tr class="LC_odd_row">'.
1.93 raeburn 4624: '<td>'.$lt{$context}.$showdom.
1.165 raeburn 4625: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 4626: my $rem;
4627: if (ref($types) eq 'ARRAY') {
4628: for (my $i=0; $i<@{$types}; $i++) {
4629: if (defined($usertypes->{$types->[$i]})) {
4630: my $rem = $i%($numinrow);
4631: if ($rem == 0) {
4632: if ($i > 0) {
4633: $output .= '</tr>';
4634: }
4635: $output .= '<tr>';
1.23 raeburn 4636: }
1.26 raeburn 4637: my $check = ' ';
1.99 raeburn 4638: if (ref($settings) eq 'HASH') {
4639: if (ref($settings->{$context}) eq 'ARRAY') {
4640: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
4641: $check = ' checked="checked" ';
4642: }
4643: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4644: $check = ' checked="checked" ';
4645: }
1.23 raeburn 4646: }
1.26 raeburn 4647: $output .= '<td class="LC_left_item">'.
4648: '<span class="LC_nobreak"><label>'.
1.93 raeburn 4649: '<input type="checkbox" name="'.$context.'" '.
1.26 raeburn 4650: 'value="'.$types->[$i].'"'.$check.'/>'.
4651: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 4652: }
4653: }
1.26 raeburn 4654: $rem = @{$types}%($numinrow);
1.23 raeburn 4655: }
4656: my $colsleft = $numinrow - $rem;
1.131 raeburn 4657: if (($rem == 0) && (@{$types} > 0)) {
4658: $output .= '<tr>';
4659: }
1.23 raeburn 4660: if ($colsleft > 1) {
1.25 raeburn 4661: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
1.23 raeburn 4662: } else {
1.25 raeburn 4663: $output .= '<td class="LC_left_item">';
1.23 raeburn 4664: }
4665: my $defcheck = ' ';
1.99 raeburn 4666: if (ref($settings) eq 'HASH') {
4667: if (ref($settings->{$context}) eq 'ARRAY') {
4668: if (grep(/^default$/,@{$settings->{$context}})) {
4669: $defcheck = ' checked="checked" ';
4670: }
4671: } elsif ($context eq 'statustocreate') {
1.26 raeburn 4672: $defcheck = ' checked="checked" ';
4673: }
1.23 raeburn 4674: }
1.25 raeburn 4675: $output .= '<span class="LC_nobreak"><label>'.
1.93 raeburn 4676: '<input type="checkbox" name="'.$context.'" '.
1.25 raeburn 4677: 'value="default"'.$defcheck.'/>'.
4678: $othertitle.'</label></span></td>'.
4679: '</tr></table></td></tr>';
4680: return $output;
1.23 raeburn 4681: }
4682:
4683: sub sorted_searchtitles {
4684: my %searchtitles = &Apache::lonlocal::texthash(
4685: 'uname' => 'username',
4686: 'lastname' => 'last name',
4687: 'lastfirst' => 'last name, first name',
4688: );
4689: my @titleorder = ('uname','lastname','lastfirst');
4690: return (\%searchtitles,\@titleorder);
4691: }
4692:
1.25 raeburn 4693: sub sorted_searchtypes {
4694: my %srchtypes_desc = (
4695: exact => 'is exact match',
4696: contains => 'contains ..',
4697: begins => 'begins with ..',
4698: );
4699: my @srchtypeorder = ('exact','begins','contains');
4700: return (\%srchtypes_desc,\@srchtypeorder);
4701: }
4702:
1.3 raeburn 4703: sub usertype_update_row {
4704: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
4705: my $datatable;
4706: my $numinrow = 4;
4707: foreach my $type (@{$types}) {
4708: if (defined($usertypes->{$type})) {
4709: $$rownums ++;
4710: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
4711: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
4712: '</td><td class="LC_left_item"><table>';
4713: for (my $i=0; $i<@{$fields}; $i++) {
4714: my $rem = $i%($numinrow);
4715: if ($rem == 0) {
4716: if ($i > 0) {
4717: $datatable .= '</tr>';
4718: }
4719: $datatable .= '<tr>';
4720: }
4721: my $check = ' ';
1.39 raeburn 4722: if (ref($settings) eq 'HASH') {
4723: if (ref($settings->{'fields'}) eq 'HASH') {
4724: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
4725: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
4726: $check = ' checked="checked" ';
4727: }
1.3 raeburn 4728: }
4729: }
4730: }
4731:
4732: if ($i == @{$fields}-1) {
4733: my $colsleft = $numinrow - $rem;
4734: if ($colsleft > 1) {
4735: $datatable .= '<td colspan="'.$colsleft.'">';
4736: } else {
4737: $datatable .= '<td>';
4738: }
4739: } else {
4740: $datatable .= '<td>';
4741: }
1.8 raeburn 4742: $datatable .= '<span class="LC_nobreak"><label>'.
4743: '<input type="checkbox" name="updateable_'.$type.
4744: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
4745: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 4746: }
4747: $datatable .= '</tr></table></td></tr>';
4748: }
4749: }
4750: return $datatable;
1.1 raeburn 4751: }
4752:
4753: sub modify_login {
1.205 raeburn 4754: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.168 raeburn 4755: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
4756: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon);
4757: %title = ( coursecatalog => 'Display course catalog',
4758: adminmail => 'Display administrator E-mail address',
1.188 raeburn 4759: helpdesk => 'Display "Contact Helpdesk" link',
1.168 raeburn 4760: newuser => 'Link for visitors to create a user account',
4761: loginheader => 'Log-in box header');
4762: @offon = ('off','on');
1.112 raeburn 4763: if (ref($domconfig{login}) eq 'HASH') {
4764: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
4765: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
4766: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
4767: }
4768: }
4769: }
1.9 raeburn 4770: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
4771: \%domconfig,\%loginhash);
1.188 raeburn 4772: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4773: foreach my $item (@toggles) {
4774: $loginhash{login}{$item} = $env{'form.'.$item};
4775: }
1.41 raeburn 4776: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 4777: if (ref($colchanges{'login'}) eq 'HASH') {
4778: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
4779: \%loginhash);
4780: }
1.110 raeburn 4781:
1.149 raeburn 4782: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.128 raeburn 4783: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 4784: if (keys(%servers) > 1) {
4785: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 4786: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
4787: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
4788: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
4789: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
4790: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
4791: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4792: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4793: $changes{'loginvia'}{$lonhost} = 1;
4794: } else {
4795: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
4796: $changes{'loginvia'}{$lonhost} = 1;
4797: }
4798: } else {
4799: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4800: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
4801: $changes{'loginvia'}{$lonhost} = 1;
4802: }
4803: }
4804: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
4805: foreach my $item (@loginvia_attribs) {
4806: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
4807: }
4808: } else {
4809: foreach my $item (@loginvia_attribs) {
4810: my $new = $env{'form.'.$lonhost.'_'.$item};
4811: if (($item eq 'serverpath') && ($new eq 'custom')) {
4812: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
4813: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4814: $new = '/';
4815: }
4816: }
4817: if (($item eq 'custompath') &&
4818: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4819: $new = '';
4820: }
4821: if ($new ne $curr_loginvia{$lonhost}{$item}) {
4822: $changes{'loginvia'}{$lonhost} = 1;
4823: }
4824: if ($item eq 'exempt') {
4825: $new =~ s/^\s+//;
4826: $new =~ s/\s+$//;
4827: my @poss_ips = split(/\s*[,:]\s*/,$new);
4828: my @okips;
4829: foreach my $ip (@poss_ips) {
4830: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
4831: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
4832: push(@okips,$ip);
4833: }
4834: }
4835: }
4836: if (@okips > 0) {
4837: $new = join(',',@okips);
4838: } else {
4839: $new = '';
4840: }
4841: }
4842: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4843: }
4844: }
1.112 raeburn 4845: } else {
1.128 raeburn 4846: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
4847: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 4848: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 4849: foreach my $item (@loginvia_attribs) {
4850: my $new = $env{'form.'.$lonhost.'_'.$item};
4851: if (($item eq 'serverpath') && ($new eq 'custom')) {
4852: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
4853: $new = '/';
4854: }
4855: }
4856: if (($item eq 'custompath') &&
4857: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
4858: $new = '';
4859: }
4860: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
4861: }
1.110 raeburn 4862: }
4863: }
4864: }
4865: }
1.119 raeburn 4866:
1.168 raeburn 4867: my $servadm = $r->dir_config('lonAdmEMail');
4868: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
4869: if (ref($domconfig{'login'}) eq 'HASH') {
4870: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
4871: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
4872: if ($lang eq 'nolang') {
4873: push(@currlangs,$lang);
4874: } elsif (defined($langchoices{$lang})) {
4875: push(@currlangs,$lang);
4876: } else {
4877: next;
4878: }
4879: }
4880: }
4881: }
4882: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
4883: if (@currlangs > 0) {
4884: foreach my $lang (@currlangs) {
4885: if (grep(/^\Q$lang\E$/,@delurls)) {
4886: $changes{'helpurl'}{$lang} = 1;
4887: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
4888: $changes{'helpurl'}{$lang} = 1;
4889: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
4890: push(@newlangs,$lang);
4891: } else {
4892: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4893: }
4894: }
4895: }
4896: unless (grep(/^nolang$/,@currlangs)) {
4897: if ($env{'form.loginhelpurl_nolang.filename'}) {
4898: $changes{'helpurl'}{'nolang'} = 1;
4899: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
4900: push(@newlangs,'nolang');
4901: }
4902: }
4903: if ($env{'form.loginhelpurl_add_lang'}) {
4904: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
4905: ($env{'form.loginhelpurl_add_file.filename'})) {
4906: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
4907: $addedfile = $env{'form.loginhelpurl_add_lang'};
4908: }
4909: }
4910: if ((@newlangs > 0) || ($addedfile)) {
4911: my $error;
4912: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
4913: if ($configuserok eq 'ok') {
4914: if ($switchserver) {
4915: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
4916: } elsif ($author_ok eq 'ok') {
4917: my @allnew = @newlangs;
4918: if ($addedfile ne '') {
4919: push(@allnew,$addedfile);
4920: }
4921: foreach my $lang (@allnew) {
4922: my $formelem = 'loginhelpurl_'.$lang;
4923: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
4924: $formelem = 'loginhelpurl_add_file';
4925: }
4926: (my $result,$newurl{$lang}) = &publishlogo($r,'upload',$formelem,$dom,$confname,
4927: "help/$lang",'','',$newfile{$lang});
4928: if ($result eq 'ok') {
4929: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
4930: $changes{'helpurl'}{$lang} = 1;
4931: } else {
4932: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
4933: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
1.210 raeburn 4934: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
1.168 raeburn 4935: (!grep(/^\Q$lang\E$/,@delurls))) {
4936:
4937: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
4938: }
4939: }
4940: }
4941: } else {
4942: $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);
4943: }
4944: } else {
4945: $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);
4946: }
4947: if ($error) {
4948: &Apache::lonnet::logthis($error);
4949: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
4950: }
4951: }
1.169 raeburn 4952: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
1.168 raeburn 4953:
4954: my $defaulthelpfile = '/adm/loginproblems.html';
4955: my $defaulttext = &mt('Default in use');
4956:
1.1 raeburn 4957: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
4958: $dom);
4959: if ($putresult eq 'ok') {
1.188 raeburn 4960: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 4961: my %defaultchecked = (
4962: 'coursecatalog' => 'on',
1.188 raeburn 4963: 'helpdesk' => 'on',
1.42 raeburn 4964: 'adminmail' => 'off',
1.43 raeburn 4965: 'newuser' => 'off',
1.42 raeburn 4966: );
1.55 raeburn 4967: if (ref($domconfig{'login'}) eq 'HASH') {
4968: foreach my $item (@toggles) {
4969: if ($defaultchecked{$item} eq 'on') {
4970: if (($domconfig{'login'}{$item} eq '0') &&
4971: ($env{'form.'.$item} eq '1')) {
4972: $changes{$item} = 1;
4973: } elsif (($domconfig{'login'}{$item} eq '' ||
4974: $domconfig{'login'}{$item} eq '1') &&
4975: ($env{'form.'.$item} eq '0')) {
4976: $changes{$item} = 1;
4977: }
4978: } elsif ($defaultchecked{$item} eq 'off') {
4979: if (($domconfig{'login'}{$item} eq '1') &&
4980: ($env{'form.'.$item} eq '0')) {
4981: $changes{$item} = 1;
4982: } elsif (($domconfig{'login'}{$item} eq '' ||
4983: $domconfig{'login'}{$item} eq '0') &&
4984: ($env{'form.'.$item} eq '1')) {
4985: $changes{$item} = 1;
4986: }
1.42 raeburn 4987: }
4988: }
1.41 raeburn 4989: }
1.6 raeburn 4990: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 4991: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 ! raeburn 4992: if (ref($lastactref) eq 'HASH') {
! 4993: $lastactref->{'domainconfig'} = 1;
! 4994: }
1.1 raeburn 4995: $resulttext = &mt('Changes made:').'<ul>';
4996: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 4997: if ($item eq 'loginvia') {
1.112 raeburn 4998: if (ref($changes{$item}) eq 'HASH') {
4999: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
5000: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 5001: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
5002: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
5003: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
5004: $protocol = 'http' if ($protocol ne 'https');
5005: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
5006:
5007: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
5008: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
5009: } else {
5010: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
5011: }
5012: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
5013: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
5014: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
5015: }
5016: $resulttext .= '</li>';
5017: } else {
5018: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
5019: }
1.112 raeburn 5020: } else {
1.128 raeburn 5021: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 5022: }
5023: }
1.128 raeburn 5024: $resulttext .= '</ul></li>';
1.112 raeburn 5025: }
1.168 raeburn 5026: } elsif ($item eq 'helpurl') {
5027: if (ref($changes{$item}) eq 'HASH') {
5028: foreach my $lang (sort(keys(%{$changes{$item}}))) {
5029: if (grep(/^\Q$lang\E$/,@delurls)) {
5030: my ($chg,$link);
5031: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
5032: if ($lang eq 'nolang') {
5033: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
5034: } else {
5035: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
5036: }
5037: $resulttext .= '<li>'.$chg.'</li>';
5038: } else {
5039: my $chg;
5040: if ($lang eq 'nolang') {
5041: $chg = &mt('custom log-in help file for no preferred language');
5042: } else {
5043: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
5044: }
5045: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
5046: $loginhash{'login'}{'helpurl'}{$lang}.
5047: '?inhibitmenu=yes',$chg,600,500).
5048: '</li>';
5049: }
5050: }
5051: }
1.169 raeburn 5052: } elsif ($item eq 'captcha') {
5053: if (ref($loginhash{'login'}) eq 'HASH') {
1.210 raeburn 5054: my $chgtxt;
1.169 raeburn 5055: if ($loginhash{'login'}{$item} eq 'notused') {
5056: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
5057: } else {
5058: my %captchas = &captcha_phrases();
5059: if ($captchas{$loginhash{'login'}{$item}}) {
5060: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
5061: } else {
5062: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
5063: }
5064: }
5065: $resulttext .= '<li>'.$chgtxt.'</li>';
5066: }
5067: } elsif ($item eq 'recaptchakeys') {
5068: if (ref($loginhash{'login'}) eq 'HASH') {
5069: my ($privkey,$pubkey);
5070: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
5071: $pubkey = $loginhash{'login'}{$item}{'public'};
5072: $privkey = $loginhash{'login'}{$item}{'private'};
5073: }
5074: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
5075: if (!$pubkey) {
5076: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
5077: } else {
5078: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
5079: }
5080: if (!$privkey) {
5081: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
5082: } else {
5083: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
5084: }
5085: $chgtxt .= '</ul>';
5086: $resulttext .= '<li>'.$chgtxt.'</li>';
5087: }
1.41 raeburn 5088: } else {
5089: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
5090: }
1.1 raeburn 5091: }
1.6 raeburn 5092: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 5093: } else {
5094: $resulttext = &mt('No changes made to log-in page settings');
5095: }
5096: } else {
1.11 albertel 5097: $resulttext = '<span class="LC_error">'.
5098: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 5099: }
1.6 raeburn 5100: if ($errors) {
1.9 raeburn 5101: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 5102: $errors.'</ul>';
5103: }
5104: return $resulttext;
5105: }
5106:
5107: sub color_font_choices {
5108: my %choices =
5109: &Apache::lonlocal::texthash (
5110: img => "Header",
5111: bgs => "Background colors",
5112: links => "Link colors",
1.55 raeburn 5113: images => "Images",
1.6 raeburn 5114: font => "Font color",
1.201 raeburn 5115: fontmenu => "Font menu",
1.76 raeburn 5116: pgbg => "Page",
1.6 raeburn 5117: tabbg => "Header",
5118: sidebg => "Border",
5119: link => "Link",
5120: alink => "Active link",
5121: vlink => "Visited link",
5122: );
5123: return %choices;
5124: }
5125:
5126: sub modify_rolecolors {
1.205 raeburn 5127: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 5128: my ($resulttext,%rolehash);
5129: $rolehash{'rolecolors'} = {};
1.55 raeburn 5130: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
5131: if ($domconfig{'rolecolors'} eq '') {
5132: $domconfig{'rolecolors'} = {};
5133: }
5134: }
1.9 raeburn 5135: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 5136: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
5137: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
5138: $dom);
5139: if ($putresult eq 'ok') {
5140: if (keys(%changes) > 0) {
1.41 raeburn 5141: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 ! raeburn 5142: if (ref($lastactref) eq 'HASH') {
! 5143: $lastactref->{'domainconfig'} = 1;
! 5144: }
1.6 raeburn 5145: $resulttext = &display_colorchgs($dom,\%changes,$roles,
5146: $rolehash{'rolecolors'});
5147: } else {
5148: $resulttext = &mt('No changes made to default color schemes');
5149: }
5150: } else {
1.11 albertel 5151: $resulttext = '<span class="LC_error">'.
5152: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 5153: }
5154: if ($errors) {
5155: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
5156: $errors.'</ul>';
5157: }
5158: return $resulttext;
5159: }
5160:
5161: sub modify_colors {
1.9 raeburn 5162: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 5163: my (%changes,%choices);
1.51 raeburn 5164: my @bgs;
1.6 raeburn 5165: my @links = ('link','alink','vlink');
1.41 raeburn 5166: my @logintext;
1.6 raeburn 5167: my @images;
5168: my $servadm = $r->dir_config('lonAdmEMail');
5169: my $errors;
1.200 raeburn 5170: my %defaults;
1.6 raeburn 5171: foreach my $role (@{$roles}) {
5172: if ($role eq 'login') {
1.12 raeburn 5173: %choices = &login_choices();
1.41 raeburn 5174: @logintext = ('textcol','bgcol');
1.12 raeburn 5175: } else {
5176: %choices = &color_font_choices();
5177: }
5178: if ($role eq 'login') {
1.41 raeburn 5179: @images = ('img','logo','domlogo','login');
1.51 raeburn 5180: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 5181: } else {
5182: @images = ('img');
1.200 raeburn 5183: @bgs = ('pgbg','tabbg','sidebg');
5184: }
5185: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
5186: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
5187: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
5188: }
5189: if ($role eq 'login') {
5190: foreach my $item (@logintext) {
5191: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'logintext'}{$item}) {
5192: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5193: }
5194: }
5195: } else {
5196: unless($env{'form.'.$role.'_fontmenu'} eq $defaults{'fontmenu'}) {
5197: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
5198: }
1.6 raeburn 5199: }
1.200 raeburn 5200: foreach my $item (@bgs) {
5201: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'bgs'}{$item} ) {
5202: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5203: }
5204: }
5205: foreach my $item (@links) {
5206: unless ($env{'form.'.$role.'_'.$item} eq $defaults{'links'}{$item}) {
5207: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
5208: }
1.6 raeburn 5209: }
1.46 raeburn 5210: my ($configuserok,$author_ok,$switchserver) =
5211: &config_check($dom,$confname,$servadm);
1.9 raeburn 5212: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 5213: if (ref($domconfig->{$role}) ne 'HASH') {
5214: $domconfig->{$role} = {};
5215: }
1.8 raeburn 5216: foreach my $img (@images) {
1.70 raeburn 5217: if (($role eq 'login') && (($img eq 'img') || ($img eq 'logo'))) {
5218: if (defined($env{'form.login_showlogo_'.$img})) {
5219: $confhash->{$role}{'showlogo'}{$img} = 1;
5220: } else {
5221: $confhash->{$role}{'showlogo'}{$img} = 0;
5222: }
5223: }
1.18 albertel 5224: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
5225: && !defined($domconfig->{$role}{$img})
5226: && !$env{'form.'.$role.'_del_'.$img}
5227: && $env{'form.'.$role.'_import_'.$img}) {
5228: # import the old configured image from the .tab setting
5229: # if they haven't provided a new one
5230: $domconfig->{$role}{$img} =
5231: $env{'form.'.$role.'_import_'.$img};
5232: }
1.6 raeburn 5233: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 5234: my $error;
1.6 raeburn 5235: if ($configuserok eq 'ok') {
1.9 raeburn 5236: if ($switchserver) {
1.12 raeburn 5237: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 5238: } else {
5239: if ($author_ok eq 'ok') {
5240: my ($result,$logourl) =
5241: &publishlogo($r,'upload',$role.'_'.$img,
5242: $dom,$confname,$img,$width,$height);
5243: if ($result eq 'ok') {
5244: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 5245: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5246: } else {
1.12 raeburn 5247: $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 5248: }
5249: } else {
1.46 raeburn 5250: $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 5251: }
5252: }
5253: } else {
1.46 raeburn 5254: $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 5255: }
5256: if ($error) {
1.8 raeburn 5257: &Apache::lonnet::logthis($error);
1.11 albertel 5258: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 5259: }
5260: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 5261: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
5262: my $error;
5263: if ($configuserok eq 'ok') {
5264: # is confname an author?
5265: if ($switchserver eq '') {
5266: if ($author_ok eq 'ok') {
5267: my ($result,$logourl) =
5268: &publishlogo($r,'copy',$domconfig->{$role}{$img},
5269: $dom,$confname,$img,$width,$height);
5270: if ($result eq 'ok') {
5271: $confhash->{$role}{$img} = $logourl;
1.18 albertel 5272: $changes{$role}{'images'}{$img} = 1;
1.9 raeburn 5273: }
5274: }
5275: }
5276: }
1.6 raeburn 5277: }
5278: }
5279: }
5280: if (ref($domconfig) eq 'HASH') {
5281: if (ref($domconfig->{$role}) eq 'HASH') {
5282: foreach my $img (@images) {
5283: if ($domconfig->{$role}{$img} ne '') {
5284: if ($env{'form.'.$role.'_del_'.$img}) {
5285: $confhash->{$role}{$img} = '';
1.12 raeburn 5286: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5287: } else {
1.9 raeburn 5288: if ($confhash->{$role}{$img} eq '') {
5289: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
5290: }
1.6 raeburn 5291: }
5292: } else {
5293: if ($env{'form.'.$role.'_del_'.$img}) {
5294: $confhash->{$role}{$img} = '';
1.12 raeburn 5295: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 5296: }
5297: }
1.70 raeburn 5298: if (($role eq 'login') && (($img eq 'logo') || ($img eq 'img'))) {
5299: if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
5300: if ($confhash->{$role}{'showlogo'}{$img} ne
5301: $domconfig->{$role}{'showlogo'}{$img}) {
5302: $changes{$role}{'showlogo'}{$img} = 1;
5303: }
5304: } else {
5305: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5306: $changes{$role}{'showlogo'}{$img} = 1;
5307: }
5308: }
5309: }
5310: }
1.6 raeburn 5311: if ($domconfig->{$role}{'font'} ne '') {
5312: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
5313: $changes{$role}{'font'} = 1;
5314: }
5315: } else {
5316: if ($confhash->{$role}{'font'}) {
5317: $changes{$role}{'font'} = 1;
5318: }
5319: }
1.107 raeburn 5320: if ($role ne 'login') {
5321: if ($domconfig->{$role}{'fontmenu'} ne '') {
5322: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
5323: $changes{$role}{'fontmenu'} = 1;
5324: }
5325: } else {
5326: if ($confhash->{$role}{'fontmenu'}) {
5327: $changes{$role}{'fontmenu'} = 1;
5328: }
1.97 tempelho 5329: }
5330: }
1.6 raeburn 5331: foreach my $item (@bgs) {
5332: if ($domconfig->{$role}{$item} ne '') {
5333: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5334: $changes{$role}{'bgs'}{$item} = 1;
5335: }
5336: } else {
5337: if ($confhash->{$role}{$item}) {
5338: $changes{$role}{'bgs'}{$item} = 1;
5339: }
5340: }
5341: }
5342: foreach my $item (@links) {
5343: if ($domconfig->{$role}{$item} ne '') {
5344: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5345: $changes{$role}{'links'}{$item} = 1;
5346: }
5347: } else {
5348: if ($confhash->{$role}{$item}) {
5349: $changes{$role}{'links'}{$item} = 1;
5350: }
5351: }
5352: }
1.41 raeburn 5353: foreach my $item (@logintext) {
5354: if ($domconfig->{$role}{$item} ne '') {
5355: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
5356: $changes{$role}{'logintext'}{$item} = 1;
5357: }
5358: } else {
5359: if ($confhash->{$role}{$item}) {
5360: $changes{$role}{'logintext'}{$item} = 1;
5361: }
5362: }
5363: }
1.6 raeburn 5364: } else {
5365: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5366: \@logintext,$confhash,\%changes);
1.6 raeburn 5367: }
5368: } else {
5369: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 5370: \@logintext,$confhash,\%changes);
1.6 raeburn 5371: }
5372: }
5373: return ($errors,%changes);
5374: }
5375:
1.46 raeburn 5376: sub config_check {
5377: my ($dom,$confname,$servadm) = @_;
5378: my ($configuserok,$author_ok,$switchserver,%currroles);
5379: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
5380: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
5381: $confname,$servadm);
5382: if ($configuserok eq 'ok') {
5383: $switchserver = &check_switchserver($dom,$confname);
5384: if ($switchserver eq '') {
5385: $author_ok = &check_authorstatus($dom,$confname,%currroles);
5386: }
5387: }
5388: return ($configuserok,$author_ok,$switchserver);
5389: }
5390:
1.6 raeburn 5391: sub default_change_checker {
1.41 raeburn 5392: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 5393: foreach my $item (@{$links}) {
5394: if ($confhash->{$role}{$item}) {
5395: $changes->{$role}{'links'}{$item} = 1;
5396: }
5397: }
5398: foreach my $item (@{$bgs}) {
5399: if ($confhash->{$role}{$item}) {
5400: $changes->{$role}{'bgs'}{$item} = 1;
5401: }
5402: }
1.41 raeburn 5403: foreach my $item (@{$logintext}) {
5404: if ($confhash->{$role}{$item}) {
5405: $changes->{$role}{'logintext'}{$item} = 1;
5406: }
5407: }
1.6 raeburn 5408: foreach my $img (@{$images}) {
5409: if ($env{'form.'.$role.'_del_'.$img}) {
5410: $confhash->{$role}{$img} = '';
1.12 raeburn 5411: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 5412: }
1.70 raeburn 5413: if ($role eq 'login') {
5414: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
5415: $changes->{$role}{'showlogo'}{$img} = 1;
5416: }
5417: }
1.6 raeburn 5418: }
5419: if ($confhash->{$role}{'font'}) {
5420: $changes->{$role}{'font'} = 1;
5421: }
1.48 raeburn 5422: }
1.6 raeburn 5423:
5424: sub display_colorchgs {
5425: my ($dom,$changes,$roles,$confhash) = @_;
5426: my (%choices,$resulttext);
5427: if (!grep(/^login$/,@{$roles})) {
5428: $resulttext = &mt('Changes made:').'<br />';
5429: }
5430: foreach my $role (@{$roles}) {
5431: if ($role eq 'login') {
5432: %choices = &login_choices();
5433: } else {
5434: %choices = &color_font_choices();
5435: }
5436: if (ref($changes->{$role}) eq 'HASH') {
5437: if ($role ne 'login') {
5438: $resulttext .= '<h4>'.&mt($role).'</h4>';
5439: }
5440: foreach my $key (sort(keys(%{$changes->{$role}}))) {
5441: if ($role ne 'login') {
5442: $resulttext .= '<ul>';
5443: }
5444: if (ref($changes->{$role}{$key}) eq 'HASH') {
5445: if ($role ne 'login') {
5446: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
5447: }
5448: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 5449: if (($role eq 'login') && ($key eq 'showlogo')) {
5450: if ($confhash->{$role}{$key}{$item}) {
5451: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
5452: } else {
5453: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
5454: }
5455: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 5456: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
5457: } else {
1.12 raeburn 5458: my $newitem = $confhash->{$role}{$item};
5459: if ($key eq 'images') {
5460: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
5461: }
5462: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 5463: }
5464: }
5465: if ($role ne 'login') {
5466: $resulttext .= '</ul></li>';
5467: }
5468: } else {
5469: if ($confhash->{$role}{$key} eq '') {
5470: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
5471: } else {
5472: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
5473: }
5474: }
5475: if ($role ne 'login') {
5476: $resulttext .= '</ul>';
5477: }
5478: }
5479: }
5480: }
1.3 raeburn 5481: return $resulttext;
1.1 raeburn 5482: }
5483:
1.9 raeburn 5484: sub thumb_dimensions {
5485: return ('200','50');
5486: }
5487:
1.16 raeburn 5488: sub check_dimensions {
5489: my ($inputfile) = @_;
5490: my ($fullwidth,$fullheight);
5491: if ($inputfile =~ m|^[/\w.\-]+$|) {
5492: if (open(PIPE,"identify $inputfile 2>&1 |")) {
5493: my $imageinfo = <PIPE>;
5494: if (!close(PIPE)) {
5495: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
5496: }
5497: chomp($imageinfo);
5498: my ($fullsize) =
1.21 raeburn 5499: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 5500: if ($fullsize) {
5501: ($fullwidth,$fullheight) = split(/x/,$fullsize);
5502: }
5503: }
5504: }
5505: return ($fullwidth,$fullheight);
5506: }
5507:
1.9 raeburn 5508: sub check_configuser {
5509: my ($uhome,$dom,$confname,$servadm) = @_;
5510: my ($configuserok,%currroles);
5511: if ($uhome eq 'no_host') {
5512: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
5513: my $configpass = &LONCAPA::Enrollment::create_password();
5514: $configuserok =
5515: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
5516: $configpass,'','','','','',undef,$servadm);
5517: } else {
5518: $configuserok = 'ok';
5519: %currroles =
5520: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
5521: }
5522: return ($configuserok,%currroles);
5523: }
5524:
5525: sub check_authorstatus {
5526: my ($dom,$confname,%currroles) = @_;
5527: my $author_ok;
1.40 raeburn 5528: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 5529: my $start = time;
5530: my $end = 0;
5531: $author_ok =
5532: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 5533: 'au',$end,$start,'','','domconfig');
1.9 raeburn 5534: } else {
5535: $author_ok = 'ok';
5536: }
5537: return $author_ok;
5538: }
5539:
5540: sub publishlogo {
1.46 raeburn 5541: my ($r,$action,$formname,$dom,$confname,$subdir,$thumbwidth,$thumbheight,$savefileas) = @_;
1.9 raeburn 5542: my ($output,$fname,$logourl);
5543: if ($action eq 'upload') {
5544: $fname=$env{'form.'.$formname.'.filename'};
5545: chop($env{'form.'.$formname});
5546: } else {
5547: ($fname) = ($formname =~ /([^\/]+)$/);
5548: }
1.46 raeburn 5549: if ($savefileas ne '') {
5550: $fname = $savefileas;
5551: }
1.9 raeburn 5552: $fname=&Apache::lonnet::clean_filename($fname);
5553: # See if there is anything left
5554: unless ($fname) { return ('error: no uploaded file'); }
5555: $fname="$subdir/$fname";
1.210 raeburn 5556: my $docroot=$r->dir_config('lonDocRoot');
1.164 raeburn 5557: my $filepath="$docroot/priv";
5558: my $relpath = "$dom/$confname";
1.9 raeburn 5559: my ($fnamepath,$file,$fetchthumb);
5560: $file=$fname;
5561: if ($fname=~m|/|) {
5562: ($fnamepath,$file) = ($fname =~ m|^(.*)/([^/]+)$|);
5563: }
1.164 raeburn 5564: my @parts=split(/\//,"$filepath/$relpath/$fnamepath");
1.9 raeburn 5565: my $count;
1.164 raeburn 5566: for ($count=5;$count<=$#parts;$count++) {
1.9 raeburn 5567: $filepath.="/$parts[$count]";
5568: if ((-e $filepath)!=1) {
5569: mkdir($filepath,02770);
5570: }
5571: }
5572: # Check for bad extension and disallow upload
5573: if ($file=~/\.(\w+)$/ &&
5574: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
5575: $output =
1.207 bisitz 5576: &mt('Invalid file extension ([_1]) - reserved for internal use.',$1);
1.9 raeburn 5577: } elsif ($file=~/\.(\w+)$/ &&
5578: !defined(&Apache::loncommon::fileembstyle($1))) {
5579: $output = &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1);
5580: } elsif ($file=~/\.(\d+)\.(\w+)$/) {
1.195 bisitz 5581: $output = &mt('Filename not allowed - rename the file to remove the number immediately before the file extension([_1]) and re-upload.',$2);
1.9 raeburn 5582: } elsif (-d "$filepath/$file") {
1.195 bisitz 5583: $output = &mt('Filename is a directory name - rename the file and re-upload');
1.9 raeburn 5584: } else {
5585: my $source = $filepath.'/'.$file;
5586: my $logfile;
5587: if (!open($logfile,">>$source".'.log')) {
1.196 raeburn 5588: return (&mt('No write permission to Authoring Space'));
1.9 raeburn 5589: }
5590: print $logfile
5591: "\n================= Publish ".localtime()." ================\n".
5592: $env{'user.name'}.':'.$env{'user.domain'}."\n";
5593: # Save the file
5594: if (!open(FH,'>'.$source)) {
5595: &Apache::lonnet::logthis('Failed to create '.$source);
5596: return (&mt('Failed to create file'));
5597: }
5598: if ($action eq 'upload') {
5599: if (!print FH ($env{'form.'.$formname})) {
5600: &Apache::lonnet::logthis('Failed to write to '.$source);
5601: return (&mt('Failed to write file'));
5602: }
5603: } else {
5604: my $original = &Apache::lonnet::filelocation('',$formname);
5605: if(!copy($original,$source)) {
5606: &Apache::lonnet::logthis('Failed to copy '.$original.' to '.$source);
5607: return (&mt('Failed to write file'));
5608: }
5609: }
5610: close(FH);
5611: chmod(0660, $source); # Permissions to rw-rw---.
5612:
5613: my $targetdir=$docroot.'/res/'.$dom.'/'.$confname .'/'.$fnamepath;
5614: my $copyfile=$targetdir.'/'.$file;
5615:
5616: my @parts=split(/\//,$targetdir);
5617: my $path="/$parts[1]/$parts[2]/$parts[3]/$parts[4]";
5618: for (my $count=5;$count<=$#parts;$count++) {
5619: $path.="/$parts[$count]";
5620: if (!-e $path) {
5621: print $logfile "\nCreating directory ".$path;
5622: mkdir($path,02770);
5623: }
5624: }
5625: my $versionresult;
5626: if (-e $copyfile) {
5627: $versionresult = &logo_versioning($targetdir,$file,$logfile);
5628: } else {
5629: $versionresult = 'ok';
5630: }
5631: if ($versionresult eq 'ok') {
5632: if (copy($source,$copyfile)) {
5633: print $logfile "\nCopied original source to ".$copyfile."\n";
5634: $output = 'ok';
5635: $logourl = '/res/'.$dom.'/'.$confname.'/'.$fname;
1.155 raeburn 5636: push(@{$modified_urls},[$copyfile,$source]);
5637: my $metaoutput =
5638: &write_metadata($dom,$confname,$formname,$targetdir,$file,$logfile);
5639: unless ($registered_cleanup) {
5640: my $handlers = $r->get_handlers('PerlCleanupHandler');
5641: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5642: $registered_cleanup=1;
5643: }
1.9 raeburn 5644: } else {
5645: print $logfile "\nUnable to write ".$copyfile.':'.$!."\n";
5646: $output = &mt('Failed to copy file to RES space').", $!";
5647: }
5648: if (($thumbwidth =~ /^\d+$/) && ($thumbheight =~ /^\d+$/)) {
5649: my $inputfile = $filepath.'/'.$file;
5650: my $outfile = $filepath.'/'.'tn-'.$file;
1.16 raeburn 5651: my ($fullwidth,$fullheight) = &check_dimensions($inputfile);
5652: if ($fullwidth ne '' && $fullheight ne '') {
5653: if ($fullwidth > $thumbwidth && $fullheight > $thumbheight) {
5654: my $thumbsize = $thumbwidth.'x'.$thumbheight;
5655: system("convert -sample $thumbsize $inputfile $outfile");
5656: chmod(0660, $filepath.'/tn-'.$file);
5657: if (-e $outfile) {
5658: my $copyfile=$targetdir.'/tn-'.$file;
5659: if (copy($outfile,$copyfile)) {
5660: print $logfile "\nCopied source to ".$copyfile."\n";
1.155 raeburn 5661: my $thumb_metaoutput =
5662: &write_metadata($dom,$confname,$formname,
5663: $targetdir,'tn-'.$file,$logfile);
5664: push(@{$modified_urls},[$copyfile,$outfile]);
5665: unless ($registered_cleanup) {
5666: my $handlers = $r->get_handlers('PerlCleanupHandler');
5667: $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
5668: $registered_cleanup=1;
5669: }
1.16 raeburn 5670: } else {
5671: print $logfile "\nUnable to write ".$copyfile.
5672: ':'.$!."\n";
5673: }
5674: }
1.9 raeburn 5675: }
5676: }
5677: }
5678: } else {
5679: $output = $versionresult;
5680: }
5681: }
5682: return ($output,$logourl);
5683: }
5684:
5685: sub logo_versioning {
5686: my ($targetdir,$file,$logfile) = @_;
5687: my $target = $targetdir.'/'.$file;
5688: my ($maxversion,$fn,$extn,$output);
5689: $maxversion = 0;
5690: if ($file =~ /^(.+)\.(\w+)$/) {
5691: $fn=$1;
5692: $extn=$2;
5693: }
5694: opendir(DIR,$targetdir);
5695: while (my $filename=readdir(DIR)) {
5696: if ($filename=~/\Q$fn\E\.(\d+)\.\Q$extn\E$/) {
5697: $maxversion=($1>$maxversion)?$1:$maxversion;
5698: }
5699: }
5700: $maxversion++;
5701: print $logfile "\nCreating old version ".$maxversion."\n";
5702: my $copyfile=$targetdir.'/'.$fn.'.'.$maxversion.'.'.$extn;
5703: if (copy($target,$copyfile)) {
5704: print $logfile "Copied old target to ".$copyfile."\n";
5705: $copyfile=$copyfile.'.meta';
5706: if (copy($target.'.meta',$copyfile)) {
5707: print $logfile "Copied old target metadata to ".$copyfile."\n";
5708: $output = 'ok';
5709: } else {
5710: print $logfile "Unable to write metadata ".$copyfile.':'.$!."\n";
5711: $output = &mt('Failed to copy old meta').", $!, ";
5712: }
5713: } else {
5714: print $logfile "Unable to write ".$copyfile.':'.$!."\n";
5715: $output = &mt('Failed to copy old target').", $!, ";
5716: }
5717: return $output;
5718: }
5719:
5720: sub write_metadata {
5721: my ($dom,$confname,$formname,$targetdir,$file,$logfile) = @_;
5722: my (%metadatafields,%metadatakeys,$output);
5723: $metadatafields{'title'}=$formname;
5724: $metadatafields{'creationdate'}=time;
5725: $metadatafields{'lastrevisiondate'}=time;
5726: $metadatafields{'copyright'}='public';
5727: $metadatafields{'modifyinguser'}=$env{'user.name'}.':'.
5728: $env{'user.domain'};
5729: $metadatafields{'authorspace'}=$confname.':'.$dom;
5730: $metadatafields{'domain'}=$dom;
5731: {
5732: print $logfile "\nWrite metadata file for ".$targetdir.'/'.$file;
5733: my $mfh;
1.155 raeburn 5734: if (open($mfh,'>'.$targetdir.'/'.$file.'.meta')) {
1.184 raeburn 5735: foreach (sort(keys(%metadatafields))) {
1.155 raeburn 5736: unless ($_=~/\./) {
5737: my $unikey=$_;
5738: $unikey=~/^([A-Za-z]+)/;
5739: my $tag=$1;
5740: $tag=~tr/A-Z/a-z/;
5741: print $mfh "\n\<$tag";
5742: foreach (split(/\,/,$metadatakeys{$unikey})) {
5743: my $value=$metadatafields{$unikey.'.'.$_};
5744: $value=~s/\"/\'\'/g;
5745: print $mfh ' '.$_.'="'.$value.'"';
5746: }
5747: print $mfh '>'.
5748: &HTML::Entities::encode($metadatafields{$unikey},'<>&"')
5749: .'</'.$tag.'>';
5750: }
5751: }
5752: $output = 'ok';
5753: print $logfile "\nWrote metadata";
5754: close($mfh);
5755: } else {
5756: print $logfile "\nFailed to open metadata file";
1.9 raeburn 5757: $output = &mt('Could not write metadata');
5758: }
5759: }
1.155 raeburn 5760: return $output;
5761: }
5762:
5763: sub notifysubscribed {
5764: foreach my $targetsource (@{$modified_urls}){
5765: next unless (ref($targetsource) eq 'ARRAY');
5766: my ($target,$source)=@{$targetsource};
5767: if ($source ne '') {
5768: if (open(my $logfh,'>>'.$source.'.log')) {
5769: print $logfh "\nCleanup phase: Notifications\n";
5770: my @subscribed=&subscribed_hosts($target);
5771: foreach my $subhost (@subscribed) {
5772: print $logfh "\nNotifying host ".$subhost.':';
5773: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
5774: print $logfh $reply;
5775: }
5776: my @subscribedmeta=&subscribed_hosts("$target.meta");
5777: foreach my $subhost (@subscribedmeta) {
5778: print $logfh "\nNotifying host for metadata only ".$subhost.':';
5779: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
5780: $subhost);
5781: print $logfh $reply;
5782: }
5783: print $logfh "\n============ Done ============\n";
1.160 raeburn 5784: close($logfh);
1.155 raeburn 5785: }
5786: }
5787: }
5788: return OK;
5789: }
5790:
5791: sub subscribed_hosts {
5792: my ($target) = @_;
5793: my @subscribed;
5794: if (open(my $fh,"<$target.subscription")) {
5795: while (my $subline=<$fh>) {
5796: if ($subline =~ /^($match_lonid):/) {
5797: my $host = $1;
5798: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
5799: unless (grep(/^\Q$host\E$/,@subscribed)) {
5800: push(@subscribed,$host);
5801: }
5802: }
5803: }
5804: }
5805: }
5806: return @subscribed;
1.9 raeburn 5807: }
5808:
5809: sub check_switchserver {
5810: my ($dom,$confname) = @_;
5811: my ($allowed,$switchserver);
5812: my $home = &Apache::lonnet::homeserver($confname,$dom);
5813: if ($home eq 'no_host') {
5814: $home = &Apache::lonnet::domain($dom,'primary');
5815: }
5816: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 5817: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
5818: if (!$allowed) {
1.180 raeburn 5819: $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role=dc./'.$dom.'/&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 5820: }
5821: return $switchserver;
5822: }
5823:
1.1 raeburn 5824: sub modify_quotas {
1.212 ! raeburn 5825: my ($dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 5826: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
5827: %limithash,$toolregexp,%conditions,$resulttext,%changes);
1.86 raeburn 5828: if ($action eq 'quotas') {
5829: $context = 'tools';
1.163 raeburn 5830: } else {
1.86 raeburn 5831: $context = $action;
5832: }
5833: if ($context eq 'requestcourses') {
1.98 raeburn 5834: @usertools = ('official','unofficial','community');
1.106 raeburn 5835: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 5836: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
5837: %titles = &courserequest_titles();
5838: $toolregexp = join('|',@usertools);
5839: %conditions = &courserequest_conditions();
1.163 raeburn 5840: } elsif ($context eq 'requestauthor') {
5841: @usertools = ('author');
5842: %titles = &authorrequest_titles();
1.86 raeburn 5843: } else {
1.162 raeburn 5844: @usertools = ('aboutme','blog','webdav','portfolio');
1.101 raeburn 5845: %titles = &tool_titles();
1.86 raeburn 5846: }
1.212 ! raeburn 5847: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 5848: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 5849: foreach my $key (keys(%env)) {
1.101 raeburn 5850: if ($context eq 'requestcourses') {
5851: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
5852: my $item = $1;
5853: my $type = $2;
5854: if ($type =~ /^limit_(.+)/) {
5855: $limithash{$item}{$1} = $env{$key};
5856: } else {
5857: $confhash{$item}{$type} = $env{$key};
5858: }
5859: }
1.163 raeburn 5860: } elsif ($context eq 'requestauthor') {
5861: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
5862: $confhash{$1} = $env{$key};
5863: }
1.101 raeburn 5864: } else {
1.86 raeburn 5865: if ($key =~ /^form\.quota_(.+)$/) {
5866: $confhash{'defaultquota'}{$1} = $env{$key};
1.197 raeburn 5867: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
5868: $confhash{'authorquota'}{$1} = $env{$key};
5869: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 5870: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
5871: }
1.72 raeburn 5872: }
5873: }
1.163 raeburn 5874: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.102 raeburn 5875: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.reqapprovalnotify');
5876: @approvalnotify = sort(@approvalnotify);
5877: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
5878: if (ref($domconfig{$action}) eq 'HASH') {
5879: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
5880: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
5881: $changes{'notify'}{'approval'} = 1;
5882: }
5883: } else {
1.144 raeburn 5884: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5885: $changes{'notify'}{'approval'} = 1;
5886: }
5887: }
5888: } else {
1.144 raeburn 5889: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 5890: $changes{'notify'}{'approval'} = 1;
5891: }
5892: }
5893: } else {
1.86 raeburn 5894: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.197 raeburn 5895: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 5896: }
1.72 raeburn 5897: foreach my $item (@usertools) {
5898: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 5899: my $unset;
1.101 raeburn 5900: if ($context eq 'requestcourses') {
1.104 raeburn 5901: $unset = '0';
5902: if ($type eq '_LC_adv') {
5903: $unset = '';
5904: }
1.101 raeburn 5905: if ($confhash{$item}{$type} eq 'autolimit') {
5906: $confhash{$item}{$type} .= '=';
5907: unless ($limithash{$item}{$type} =~ /\D/) {
5908: $confhash{$item}{$type} .= $limithash{$item}{$type};
5909: }
5910: }
1.163 raeburn 5911: } elsif ($context eq 'requestauthor') {
5912: $unset = '0';
5913: if ($type eq '_LC_adv') {
5914: $unset = '';
5915: }
1.72 raeburn 5916: } else {
1.101 raeburn 5917: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
5918: $confhash{$item}{$type} = 1;
5919: } else {
5920: $confhash{$item}{$type} = 0;
5921: }
1.72 raeburn 5922: }
1.86 raeburn 5923: if (ref($domconfig{$action}) eq 'HASH') {
1.163 raeburn 5924: if ($action eq 'requestauthor') {
5925: if ($domconfig{$action}{$type} ne $confhash{$type}) {
5926: $changes{$type} = 1;
5927: }
5928: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 5929: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
5930: $changes{$item}{$type} = 1;
5931: }
5932: } else {
5933: if ($context eq 'requestcourses') {
1.104 raeburn 5934: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 5935: $changes{$item}{$type} = 1;
5936: }
5937: } else {
5938: if (!$confhash{$item}{$type}) {
5939: $changes{$item}{$type} = 1;
5940: }
5941: }
5942: }
5943: } else {
5944: if ($context eq 'requestcourses') {
1.104 raeburn 5945: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 5946: $changes{$item}{$type} = 1;
5947: }
1.163 raeburn 5948: } elsif ($context eq 'requestauthor') {
5949: if ($confhash{$type} ne $unset) {
5950: $changes{$type} = 1;
5951: }
1.72 raeburn 5952: } else {
5953: if (!$confhash{$item}{$type}) {
5954: $changes{$item}{$type} = 1;
5955: }
5956: }
5957: }
1.1 raeburn 5958: }
5959: }
1.163 raeburn 5960: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 5961: if (ref($domconfig{'quotas'}) eq 'HASH') {
5962: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5963: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
5964: if (exists($confhash{'defaultquota'}{$key})) {
5965: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
5966: $changes{'defaultquota'}{$key} = 1;
5967: }
5968: } else {
5969: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 5970: }
5971: }
1.86 raeburn 5972: } else {
5973: foreach my $key (keys(%{$domconfig{'quotas'}})) {
5974: if (exists($confhash{'defaultquota'}{$key})) {
5975: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
5976: $changes{'defaultquota'}{$key} = 1;
5977: }
5978: } else {
5979: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 5980: }
1.1 raeburn 5981: }
5982: }
1.197 raeburn 5983: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
5984: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
5985: if (exists($confhash{'authorquota'}{$key})) {
5986: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
5987: $changes{'authorquota'}{$key} = 1;
5988: }
5989: } else {
5990: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
5991: }
5992: }
5993: }
1.1 raeburn 5994: }
1.86 raeburn 5995: if (ref($confhash{'defaultquota'}) eq 'HASH') {
5996: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
5997: if (ref($domconfig{'quotas'}) eq 'HASH') {
5998: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
5999: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
6000: $changes{'defaultquota'}{$key} = 1;
6001: }
6002: } else {
6003: if (!exists($domconfig{'quotas'}{$key})) {
6004: $changes{'defaultquota'}{$key} = 1;
6005: }
1.72 raeburn 6006: }
6007: } else {
1.86 raeburn 6008: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 6009: }
1.1 raeburn 6010: }
6011: }
1.197 raeburn 6012: if (ref($confhash{'authorquota'}) eq 'HASH') {
6013: foreach my $key (keys(%{$confhash{'authorquota'}})) {
6014: if (ref($domconfig{'quotas'}) eq 'HASH') {
6015: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
6016: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
6017: $changes{'authorquota'}{$key} = 1;
6018: }
6019: } else {
6020: $changes{'authorquota'}{$key} = 1;
6021: }
6022: } else {
6023: $changes{'authorquota'}{$key} = 1;
6024: }
6025: }
6026: }
1.1 raeburn 6027: }
1.72 raeburn 6028:
1.163 raeburn 6029: if ($context eq 'requestauthor') {
6030: $domdefaults{'requestauthor'} = \%confhash;
6031: } else {
6032: foreach my $key (keys(%confhash)) {
6033: $domdefaults{$key} = $confhash{$key};
6034: }
1.72 raeburn 6035: }
1.163 raeburn 6036:
1.1 raeburn 6037: my %quotahash = (
1.86 raeburn 6038: $action => { %confhash }
1.1 raeburn 6039: );
6040: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
6041: $dom);
6042: if ($putresult eq 'ok') {
6043: if (keys(%changes) > 0) {
1.72 raeburn 6044: my $cachetime = 24*60*60;
6045: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 ! raeburn 6046: if (ref($lastactref) eq 'HASH') {
! 6047: $lastactref->{'domdefaults'} = 1;
! 6048: }
1.1 raeburn 6049: $resulttext = &mt('Changes made:').'<ul>';
1.210 raeburn 6050: unless (($context eq 'requestcourses') ||
1.163 raeburn 6051: ($context eq 'requestauthor')) {
1.86 raeburn 6052: if (ref($changes{'defaultquota'}) eq 'HASH') {
6053: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
6054: foreach my $type (@{$types},'default') {
6055: if (defined($changes{'defaultquota'}{$type})) {
6056: my $typetitle = $usertypes->{$type};
6057: if ($type eq 'default') {
6058: $typetitle = $othertitle;
6059: }
6060: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 6061: }
6062: }
1.86 raeburn 6063: $resulttext .= '</ul></li>';
1.72 raeburn 6064: }
1.197 raeburn 6065: if (ref($changes{'authorquota'}) eq 'HASH') {
6066: $resulttext .= '<li>'.&mt('Authoring space default quotas').'<ul>';
6067: foreach my $type (@{$types},'default') {
6068: if (defined($changes{'authorquota'}{$type})) {
6069: my $typetitle = $usertypes->{$type};
6070: if ($type eq 'default') {
6071: $typetitle = $othertitle;
6072: }
6073: $resulttext .= '<li>'.&mt('[_1] set to [_2] Mb',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
6074: }
6075: }
6076: $resulttext .= '</ul></li>';
6077: }
1.72 raeburn 6078: }
1.80 raeburn 6079: my %newenv;
1.72 raeburn 6080: foreach my $item (@usertools) {
1.163 raeburn 6081: my (%haschgs,%inconf);
6082: if ($context eq 'requestauthor') {
6083: %haschgs = %changes;
1.210 raeburn 6084: %inconf = %confhash;
1.163 raeburn 6085: } else {
6086: if (ref($changes{$item}) eq 'HASH') {
6087: %haschgs = %{$changes{$item}};
6088: }
6089: if (ref($confhash{$item}) eq 'HASH') {
6090: %inconf = %{$confhash{$item}};
6091: }
6092: }
6093: if (keys(%haschgs) > 0) {
1.80 raeburn 6094: my $newacc =
6095: &Apache::lonnet::usertools_access($env{'user.name'},
6096: $env{'user.domain'},
1.86 raeburn 6097: $item,'reload',$context);
1.210 raeburn 6098: if (($context eq 'requestcourses') ||
1.163 raeburn 6099: ($context eq 'requestauthor')) {
1.108 raeburn 6100: if ($env{'environment.canrequest.'.$item} ne $newacc) {
6101: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 6102: }
6103: } else {
6104: if ($env{'environment.availabletools.'.$item} ne $newacc) {
6105: $newenv{'environment.availabletools.'.$item} = $newacc;
6106: }
1.80 raeburn 6107: }
1.163 raeburn 6108: unless ($context eq 'requestauthor') {
6109: $resulttext .= '<li>'.$titles{$item}.'<ul>';
6110: }
1.72 raeburn 6111: foreach my $type (@{$types},'default','_LC_adv') {
1.163 raeburn 6112: if ($haschgs{$type}) {
1.72 raeburn 6113: my $typetitle = $usertypes->{$type};
6114: if ($type eq 'default') {
6115: $typetitle = $othertitle;
6116: } elsif ($type eq '_LC_adv') {
6117: $typetitle = 'LON-CAPA Advanced Users';
6118: }
1.163 raeburn 6119: if ($inconf{$type}) {
1.101 raeburn 6120: if ($context eq 'requestcourses') {
6121: my $cond;
1.163 raeburn 6122: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 6123: if ($1 eq '') {
6124: $cond = &mt('(Automatic processing of any request).');
6125: } else {
6126: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
6127: }
6128: } else {
1.163 raeburn 6129: $cond = $conditions{$inconf{$type}};
1.101 raeburn 6130: }
6131: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.172 raeburn 6132: } elsif ($context eq 'requestauthor') {
6133: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
6134: $titles{$inconf{$type}},$typetitle);
6135:
1.101 raeburn 6136: } else {
6137: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
6138: }
1.72 raeburn 6139: } else {
1.104 raeburn 6140: if ($type eq '_LC_adv') {
1.163 raeburn 6141: if ($inconf{$type} eq '0') {
1.104 raeburn 6142: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6143: } else {
6144: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
6145: }
6146: } else {
6147: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
6148: }
1.72 raeburn 6149: }
6150: }
1.26 raeburn 6151: }
1.163 raeburn 6152: unless ($context eq 'requestauthor') {
6153: $resulttext .= '</ul></li>';
6154: }
1.26 raeburn 6155: }
1.1 raeburn 6156: }
1.163 raeburn 6157: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 6158: if (ref($changes{'notify'}) eq 'HASH') {
6159: if ($changes{'notify'}{'approval'}) {
6160: if (ref($confhash{'notify'}) eq 'HASH') {
6161: if ($confhash{'notify'}{'approval'}) {
6162: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
6163: } else {
1.163 raeburn 6164: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 6165: }
6166: }
6167: }
6168: }
6169: }
1.1 raeburn 6170: $resulttext .= '</ul>';
1.80 raeburn 6171: if (keys(%newenv)) {
6172: &Apache::lonnet::appenv(\%newenv);
6173: }
1.1 raeburn 6174: } else {
1.86 raeburn 6175: if ($context eq 'requestcourses') {
6176: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.163 raeburn 6177: } elsif ($context eq 'requestauthor') {
6178: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 6179: } else {
1.90 weissno 6180: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 6181: }
1.1 raeburn 6182: }
6183: } else {
1.11 albertel 6184: $resulttext = '<span class="LC_error">'.
6185: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6186: }
1.3 raeburn 6187: return $resulttext;
1.1 raeburn 6188: }
6189:
1.3 raeburn 6190: sub modify_autoenroll {
1.205 raeburn 6191: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 6192: my ($resulttext,%changes);
6193: my %currautoenroll;
6194: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
6195: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
6196: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
6197: }
6198: }
6199: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
6200: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 6201: sender => 'Sender for notification messages',
6202: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)');
1.1 raeburn 6203: my @offon = ('off','on');
1.17 raeburn 6204: my $sender_uname = $env{'form.sender_uname'};
6205: my $sender_domain = $env{'form.sender_domain'};
6206: if ($sender_domain eq '') {
6207: $sender_uname = '';
6208: } elsif ($sender_uname eq '') {
6209: $sender_domain = '';
6210: }
1.129 raeburn 6211: my $coowners = $env{'form.autoassign_coowners'};
1.1 raeburn 6212: my %autoenrollhash = (
1.129 raeburn 6213: autoenroll => { 'run' => $env{'form.autoenroll_run'},
6214: 'sender_uname' => $sender_uname,
6215: 'sender_domain' => $sender_domain,
6216: 'co-owners' => $coowners,
1.1 raeburn 6217: }
6218: );
1.4 raeburn 6219: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
6220: $dom);
1.1 raeburn 6221: if ($putresult eq 'ok') {
6222: if (exists($currautoenroll{'run'})) {
6223: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
6224: $changes{'run'} = 1;
6225: }
6226: } elsif ($autorun) {
6227: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 6228: $changes{'run'} = 1;
1.1 raeburn 6229: }
6230: }
1.17 raeburn 6231: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 6232: $changes{'sender'} = 1;
6233: }
1.17 raeburn 6234: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 6235: $changes{'sender'} = 1;
6236: }
1.129 raeburn 6237: if ($currautoenroll{'co-owners'} ne '') {
6238: if ($currautoenroll{'co-owners'} ne $coowners) {
6239: $changes{'coowners'} = 1;
6240: }
6241: } elsif ($coowners) {
6242: $changes{'coowners'} = 1;
6243: }
1.1 raeburn 6244: if (keys(%changes) > 0) {
6245: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 6246: if ($changes{'run'}) {
1.1 raeburn 6247: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
6248: }
6249: if ($changes{'sender'}) {
1.17 raeburn 6250: if ($sender_uname eq '' || $sender_domain eq '') {
6251: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
6252: } else {
6253: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
6254: }
1.1 raeburn 6255: }
1.129 raeburn 6256: if ($changes{'coowners'}) {
6257: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
6258: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 ! raeburn 6259: if (ref($lastactref) eq 'HASH') {
! 6260: $lastactref->{'domainconfig'} = 1;
! 6261: }
1.129 raeburn 6262: }
1.1 raeburn 6263: $resulttext .= '</ul>';
6264: } else {
6265: $resulttext = &mt('No changes made to auto-enrollment settings');
6266: }
6267: } else {
1.11 albertel 6268: $resulttext = '<span class="LC_error">'.
6269: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6270: }
1.3 raeburn 6271: return $resulttext;
1.1 raeburn 6272: }
6273:
6274: sub modify_autoupdate {
1.3 raeburn 6275: my ($dom,%domconfig) = @_;
1.1 raeburn 6276: my ($resulttext,%currautoupdate,%fields,%changes);
6277: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
6278: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
6279: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
6280: }
6281: }
6282: my @offon = ('off','on');
6283: my %title = &Apache::lonlocal::texthash (
6284: run => 'Auto-update:',
6285: classlists => 'Updates to user information in classlists?'
6286: );
1.44 raeburn 6287: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 6288: my %fieldtitles = &Apache::lonlocal::texthash (
6289: id => 'Student/Employee ID',
1.20 raeburn 6290: permanentemail => 'E-mail address',
1.1 raeburn 6291: lastname => 'Last Name',
6292: firstname => 'First Name',
6293: middlename => 'Middle Name',
1.132 raeburn 6294: generation => 'Generation',
1.1 raeburn 6295: );
1.142 raeburn 6296: $othertitle = &mt('All users');
1.1 raeburn 6297: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 6298: $othertitle = &mt('Other users');
1.1 raeburn 6299: }
6300: foreach my $key (keys(%env)) {
6301: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 6302: my ($usertype,$item) = ($1,$2);
6303: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
6304: if ($usertype eq 'default') {
6305: push(@{$fields{$1}},$2);
6306: } elsif (ref($types) eq 'ARRAY') {
6307: if (grep(/^\Q$usertype\E$/,@{$types})) {
6308: push(@{$fields{$1}},$2);
6309: }
6310: }
6311: }
1.1 raeburn 6312: }
6313: }
1.131 raeburn 6314: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
6315: @lockablenames = sort(@lockablenames);
6316: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
6317: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6318: if (@changed) {
6319: $changes{'lockablenames'} = 1;
6320: }
6321: } else {
6322: if (@lockablenames) {
6323: $changes{'lockablenames'} = 1;
6324: }
6325: }
1.1 raeburn 6326: my %updatehash = (
6327: autoupdate => { run => $env{'form.autoupdate_run'},
6328: classlists => $env{'form.classlists'},
6329: fields => {%fields},
1.131 raeburn 6330: lockablenames => \@lockablenames,
1.1 raeburn 6331: }
6332: );
6333: foreach my $key (keys(%currautoupdate)) {
6334: if (($key eq 'run') || ($key eq 'classlists')) {
6335: if (exists($updatehash{autoupdate}{$key})) {
6336: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
6337: $changes{$key} = 1;
6338: }
6339: }
6340: } elsif ($key eq 'fields') {
6341: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 6342: foreach my $item (@{$types},'default') {
1.1 raeburn 6343: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
6344: my $change = 0;
6345: foreach my $type (@{$currautoupdate{$key}{$item}}) {
6346: if (!exists($fields{$item})) {
6347: $change = 1;
1.132 raeburn 6348: last;
1.1 raeburn 6349: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 6350: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 6351: $change = 1;
1.132 raeburn 6352: last;
1.1 raeburn 6353: }
6354: }
6355: }
6356: if ($change) {
6357: push(@{$changes{$key}},$item);
6358: }
1.26 raeburn 6359: }
1.1 raeburn 6360: }
6361: }
1.131 raeburn 6362: } elsif ($key eq 'lockablenames') {
6363: if (ref($currautoupdate{$key}) eq 'ARRAY') {
6364: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
6365: if (@changed) {
6366: $changes{'lockablenames'} = 1;
6367: }
6368: } else {
6369: if (@lockablenames) {
6370: $changes{'lockablenames'} = 1;
6371: }
6372: }
6373: }
6374: }
6375: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
6376: if (@lockablenames) {
6377: $changes{'lockablenames'} = 1;
1.1 raeburn 6378: }
6379: }
1.26 raeburn 6380: foreach my $item (@{$types},'default') {
6381: if (defined($fields{$item})) {
6382: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 6383: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
6384: my $change = 0;
6385: if (ref($fields{$item}) eq 'ARRAY') {
6386: foreach my $type (@{$fields{$item}}) {
6387: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
6388: $change = 1;
6389: last;
6390: }
6391: }
6392: }
6393: if ($change) {
6394: push(@{$changes{'fields'}},$item);
6395: }
6396: } else {
1.26 raeburn 6397: push(@{$changes{'fields'}},$item);
6398: }
6399: } else {
6400: push(@{$changes{'fields'}},$item);
1.1 raeburn 6401: }
6402: }
6403: }
6404: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
6405: $dom);
6406: if ($putresult eq 'ok') {
6407: if (keys(%changes) > 0) {
6408: $resulttext = &mt('Changes made:').'<ul>';
6409: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 6410: if ($key eq 'lockablenames') {
6411: $resulttext .= '<li>';
6412: if (@lockablenames) {
6413: $usertypes->{'default'} = $othertitle;
6414: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
6415: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
6416: } else {
6417: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
6418: }
6419: $resulttext .= '</li>';
6420: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 6421: foreach my $item (@{$changes{$key}}) {
6422: my @newvalues;
6423: foreach my $type (@{$fields{$item}}) {
6424: push(@newvalues,$fieldtitles{$type});
6425: }
1.3 raeburn 6426: my $newvaluestr;
6427: if (@newvalues > 0) {
6428: $newvaluestr = join(', ',@newvalues);
6429: } else {
6430: $newvaluestr = &mt('none');
1.6 raeburn 6431: }
1.1 raeburn 6432: if ($item eq 'default') {
1.26 raeburn 6433: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 6434: } else {
1.26 raeburn 6435: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 6436: }
6437: }
6438: } else {
6439: my $newvalue;
6440: if ($key eq 'run') {
6441: $newvalue = $offon[$env{'form.autoupdate_run'}];
6442: } else {
6443: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 6444: }
1.1 raeburn 6445: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
6446: }
6447: }
6448: $resulttext .= '</ul>';
6449: } else {
1.3 raeburn 6450: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 6451: }
6452: } else {
1.11 albertel 6453: $resulttext = '<span class="LC_error">'.
6454: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 6455: }
1.3 raeburn 6456: return $resulttext;
1.1 raeburn 6457: }
6458:
1.125 raeburn 6459: sub modify_autocreate {
6460: my ($dom,%domconfig) = @_;
6461: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
6462: if (ref($domconfig{'autocreate'}) eq 'HASH') {
6463: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
6464: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
6465: }
6466: }
6467: my %title= ( xml => 'Auto-creation of courses in XML course description files',
6468: req => 'Auto-creation of validated requests for official courses',
6469: xmldc => 'Identity of course creator of courses from XML files',
6470: );
6471: my @types = ('xml','req');
6472: foreach my $item (@types) {
6473: $newvals{$item} = $env{'form.autocreate_'.$item};
6474: $newvals{$item} =~ s/\D//g;
6475: $newvals{$item} = 0 if ($newvals{$item} eq '');
6476: }
6477: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
6478: my %domcoords = &get_active_dcs($dom);
6479: unless (exists($domcoords{$newvals{'xmldc'}})) {
6480: $newvals{'xmldc'} = '';
6481: }
6482: %autocreatehash = (
6483: autocreate => { xml => $newvals{'xml'},
6484: req => $newvals{'req'},
6485: }
6486: );
6487: if ($newvals{'xmldc'} ne '') {
6488: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
6489: }
6490: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
6491: $dom);
6492: if ($putresult eq 'ok') {
6493: my @items = @types;
6494: if ($newvals{'xml'}) {
6495: push(@items,'xmldc');
6496: }
6497: foreach my $item (@items) {
6498: if (exists($currautocreate{$item})) {
6499: if ($currautocreate{$item} ne $newvals{$item}) {
6500: $changes{$item} = 1;
6501: }
6502: } elsif ($newvals{$item}) {
6503: $changes{$item} = 1;
6504: }
6505: }
6506: if (keys(%changes) > 0) {
6507: my @offon = ('off','on');
6508: $resulttext = &mt('Changes made:').'<ul>';
6509: foreach my $item (@types) {
6510: if ($changes{$item}) {
6511: my $newtxt = $offon[$newvals{$item}];
1.178 raeburn 6512: $resulttext .= '<li>'.
6513: &mt("$title{$item} set to [_1]$newtxt [_2]",
6514: '<b>','</b>').
6515: '</li>';
1.125 raeburn 6516: }
6517: }
6518: if ($changes{'xmldc'}) {
6519: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
6520: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.178 raeburn 6521: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 6522: }
6523: $resulttext .= '</ul>';
6524: } else {
6525: $resulttext = &mt('No changes made to auto-creation settings');
6526: }
6527: } else {
6528: $resulttext = '<span class="LC_error">'.
6529: &mt('An error occurred: [_1]',$putresult).'</span>';
6530: }
6531: return $resulttext;
6532: }
6533:
1.23 raeburn 6534: sub modify_directorysrch {
6535: my ($dom,%domconfig) = @_;
6536: my ($resulttext,%changes);
6537: my %currdirsrch;
6538: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
6539: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
6540: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
6541: }
6542: }
6543: my %title = ( available => 'Directory search available',
1.24 raeburn 6544: localonly => 'Other domains can search',
1.23 raeburn 6545: searchby => 'Search types',
6546: searchtypes => 'Search latitude');
6547: my @offon = ('off','on');
1.24 raeburn 6548: my @otherdoms = ('Yes','No');
1.23 raeburn 6549:
1.25 raeburn 6550: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 6551: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
6552: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
6553:
1.44 raeburn 6554: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 6555: if (keys(%{$usertypes}) == 0) {
6556: @cansearch = ('default');
6557: } else {
6558: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
6559: foreach my $type (@{$currdirsrch{'cansearch'}}) {
6560: if (!grep(/^\Q$type\E$/,@cansearch)) {
6561: push(@{$changes{'cansearch'}},$type);
6562: }
1.23 raeburn 6563: }
1.26 raeburn 6564: foreach my $type (@cansearch) {
6565: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
6566: push(@{$changes{'cansearch'}},$type);
6567: }
1.23 raeburn 6568: }
1.26 raeburn 6569: } else {
6570: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 6571: }
6572: }
6573:
6574: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
6575: foreach my $by (@{$currdirsrch{'searchby'}}) {
6576: if (!grep(/^\Q$by\E$/,@searchby)) {
6577: push(@{$changes{'searchby'}},$by);
6578: }
6579: }
6580: foreach my $by (@searchby) {
6581: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
6582: push(@{$changes{'searchby'}},$by);
6583: }
6584: }
6585: } else {
6586: push(@{$changes{'searchby'}},@searchby);
6587: }
1.25 raeburn 6588:
6589: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
6590: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
6591: if (!grep(/^\Q$type\E$/,@searchtypes)) {
6592: push(@{$changes{'searchtypes'}},$type);
6593: }
6594: }
6595: foreach my $type (@searchtypes) {
6596: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
6597: push(@{$changes{'searchtypes'}},$type);
6598: }
6599: }
6600: } else {
6601: if (exists($currdirsrch{'searchtypes'})) {
6602: foreach my $type (@searchtypes) {
6603: if ($type ne $currdirsrch{'searchtypes'}) {
6604: push(@{$changes{'searchtypes'}},$type);
6605: }
6606: }
6607: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
6608: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
6609: }
6610: } else {
6611: push(@{$changes{'searchtypes'}},@searchtypes);
6612: }
6613: }
6614:
1.23 raeburn 6615: my %dirsrch_hash = (
6616: directorysrch => { available => $env{'form.dirsrch_available'},
6617: cansearch => \@cansearch,
1.24 raeburn 6618: localonly => $env{'form.dirsrch_localonly'},
1.23 raeburn 6619: searchby => \@searchby,
1.25 raeburn 6620: searchtypes => \@searchtypes,
1.23 raeburn 6621: }
6622: );
6623: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
6624: $dom);
6625: if ($putresult eq 'ok') {
6626: if (exists($currdirsrch{'available'})) {
6627: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
6628: $changes{'available'} = 1;
6629: }
6630: } else {
6631: if ($env{'form.dirsrch_available'} eq '1') {
6632: $changes{'available'} = 1;
6633: }
6634: }
1.24 raeburn 6635: if (exists($currdirsrch{'localonly'})) {
6636: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_localonly'}) {
6637: $changes{'localonly'} = 1;
6638: }
6639: } else {
6640: if ($env{'form.dirsrch_localonly'} eq '1') {
6641: $changes{'localonly'} = 1;
6642: }
6643: }
1.23 raeburn 6644: if (keys(%changes) > 0) {
6645: $resulttext = &mt('Changes made:').'<ul>';
6646: if ($changes{'available'}) {
6647: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
6648: }
1.24 raeburn 6649: if ($changes{'localonly'}) {
6650: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_localonly'}]").'</li>';
6651: }
6652:
1.23 raeburn 6653: if (ref($changes{'cansearch'}) eq 'ARRAY') {
6654: my $chgtext;
1.26 raeburn 6655: if (ref($usertypes) eq 'HASH') {
6656: if (keys(%{$usertypes}) > 0) {
6657: foreach my $type (@{$types}) {
6658: if (grep(/^\Q$type\E$/,@cansearch)) {
6659: $chgtext .= $usertypes->{$type}.'; ';
6660: }
6661: }
6662: if (grep(/^default$/,@cansearch)) {
6663: $chgtext .= $othertitle;
6664: } else {
6665: $chgtext =~ s/\; $//;
6666: }
1.210 raeburn 6667: $resulttext .=
1.178 raeburn 6668: '<li>'.
6669: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
6670: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
6671: '</li>';
1.23 raeburn 6672: }
6673: }
6674: }
6675: if (ref($changes{'searchby'}) eq 'ARRAY') {
6676: my ($searchtitles,$titleorder) = &sorted_searchtitles();
6677: my $chgtext;
6678: foreach my $type (@{$titleorder}) {
6679: if (grep(/^\Q$type\E$/,@searchby)) {
6680: if (defined($searchtitles->{$type})) {
6681: $chgtext .= $searchtitles->{$type}.'; ';
6682: }
6683: }
6684: }
6685: $chgtext =~ s/\; $//;
6686: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
6687: }
1.25 raeburn 6688: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
6689: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
6690: my $chgtext;
6691: foreach my $type (@{$srchtypeorder}) {
6692: if (grep(/^\Q$type\E$/,@searchtypes)) {
6693: if (defined($srchtypes_desc->{$type})) {
6694: $chgtext .= $srchtypes_desc->{$type}.'; ';
6695: }
6696: }
6697: }
6698: $chgtext =~ s/\; $//;
1.178 raeburn 6699: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 6700: }
6701: $resulttext .= '</ul>';
6702: } else {
6703: $resulttext = &mt('No changes made to institution directory search settings');
6704: }
6705: } else {
6706: $resulttext = '<span class="LC_error">'.
1.27 raeburn 6707: &mt('An error occurred: [_1]',$putresult).'</span>';
6708: }
6709: return $resulttext;
6710: }
6711:
1.28 raeburn 6712: sub modify_contacts {
1.205 raeburn 6713: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 6714: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
6715: if (ref($domconfig{'contacts'}) eq 'HASH') {
6716: foreach my $key (keys(%{$domconfig{'contacts'}})) {
6717: $currsetting{$key} = $domconfig{'contacts'}{$key};
6718: }
6719: }
1.134 raeburn 6720: my (%others,%to,%bcc);
1.28 raeburn 6721: my @contacts = ('supportemail','adminemail');
1.102 raeburn 6722: my @mailings = ('errormail','packagesmail','helpdeskmail','lonstatusmail',
1.203 raeburn 6723: 'requestsmail','updatesmail','idconflictsmail');
6724: my @toggles = ('reporterrors','reportupdates');
1.28 raeburn 6725: foreach my $type (@mailings) {
6726: @{$newsetting{$type}} =
6727: &Apache::loncommon::get_env_multiple('form.'.$type);
6728: foreach my $item (@contacts) {
6729: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
6730: $contacts_hash{contacts}{$type}{$item} = 1;
6731: } else {
6732: $contacts_hash{contacts}{$type}{$item} = 0;
6733: }
6734: }
6735: $others{$type} = $env{'form.'.$type.'_others'};
6736: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.134 raeburn 6737: if ($type eq 'helpdeskmail') {
6738: $bcc{$type} = $env{'form.'.$type.'_bcc'};
6739: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
6740: }
1.28 raeburn 6741: }
6742: foreach my $item (@contacts) {
6743: $to{$item} = $env{'form.'.$item};
6744: $contacts_hash{'contacts'}{$item} = $to{$item};
6745: }
1.203 raeburn 6746: foreach my $item (@toggles) {
6747: if ($env{'form.'.$item} =~ /^(0|1)$/) {
6748: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
6749: }
6750: }
1.28 raeburn 6751: if (keys(%currsetting) > 0) {
6752: foreach my $item (@contacts) {
6753: if ($to{$item} ne $currsetting{$item}) {
6754: $changes{$item} = 1;
6755: }
6756: }
6757: foreach my $type (@mailings) {
6758: foreach my $item (@contacts) {
6759: if (ref($currsetting{$type}) eq 'HASH') {
6760: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
6761: push(@{$changes{$type}},$item);
6762: }
6763: } else {
6764: push(@{$changes{$type}},@{$newsetting{$type}});
6765: }
6766: }
6767: if ($others{$type} ne $currsetting{$type}{'others'}) {
6768: push(@{$changes{$type}},'others');
6769: }
1.134 raeburn 6770: if ($type eq 'helpdeskmail') {
6771: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
6772: push(@{$changes{$type}},'bcc');
6773: }
6774: }
1.28 raeburn 6775: }
6776: } else {
6777: my %default;
6778: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
6779: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
6780: $default{'errormail'} = 'adminemail';
6781: $default{'packagesmail'} = 'adminemail';
6782: $default{'helpdeskmail'} = 'supportemail';
1.89 raeburn 6783: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 6784: $default{'requestsmail'} = 'adminemail';
1.190 raeburn 6785: $default{'updatesmail'} = 'adminemail';
1.28 raeburn 6786: foreach my $item (@contacts) {
6787: if ($to{$item} ne $default{$item}) {
6788: $changes{$item} = 1;
1.203 raeburn 6789: }
1.28 raeburn 6790: }
6791: foreach my $type (@mailings) {
6792: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
6793:
6794: push(@{$changes{$type}},@{$newsetting{$type}});
6795: }
6796: if ($others{$type} ne '') {
6797: push(@{$changes{$type}},'others');
1.134 raeburn 6798: }
6799: if ($type eq 'helpdeskmail') {
6800: if ($bcc{$type} ne '') {
6801: push(@{$changes{$type}},'bcc');
6802: }
6803: }
1.28 raeburn 6804: }
6805: }
1.203 raeburn 6806: foreach my $item (@toggles) {
6807: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
6808: $changes{$item} = 1;
6809: } elsif ((!$env{'form.'.$item}) &&
6810: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
6811: $changes{$item} = 1;
6812: }
6813: }
1.28 raeburn 6814: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
6815: $dom);
6816: if ($putresult eq 'ok') {
6817: if (keys(%changes) > 0) {
1.205 raeburn 6818: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 ! raeburn 6819: if (ref($lastactref) eq 'HASH') {
! 6820: $lastactref->{'domainconfig'} = 1;
! 6821: }
1.28 raeburn 6822: my ($titles,$short_titles) = &contact_titles();
6823: $resulttext = &mt('Changes made:').'<ul>';
6824: foreach my $item (@contacts) {
6825: if ($changes{$item}) {
6826: $resulttext .= '<li>'.$titles->{$item}.
6827: &mt(' set to: ').
6828: '<span class="LC_cusr_emph">'.
6829: $to{$item}.'</span></li>';
6830: }
6831: }
6832: foreach my $type (@mailings) {
6833: if (ref($changes{$type}) eq 'ARRAY') {
6834: $resulttext .= '<li>'.$titles->{$type}.': ';
6835: my @text;
6836: foreach my $item (@{$newsetting{$type}}) {
6837: push(@text,$short_titles->{$item});
6838: }
6839: if ($others{$type} ne '') {
6840: push(@text,$others{$type});
6841: }
6842: $resulttext .= '<span class="LC_cusr_emph">'.
1.134 raeburn 6843: join(', ',@text).'</span>';
6844: if ($type eq 'helpdeskmail') {
6845: if ($bcc{$type} ne '') {
6846: $resulttext .= ' '.&mt('with Bcc to').': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
6847: }
6848: }
6849: $resulttext .= '</li>';
1.28 raeburn 6850: }
6851: }
1.203 raeburn 6852: my @offon = ('off','on');
6853: if ($changes{'reporterrors'}) {
6854: $resulttext .= '<li>'.
6855: &mt('E-mail error reports to [_1] set to "'.
6856: $offon[$env{'form.reporterrors'}].'".',
6857: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
6858: &mt('LON-CAPA core group - MSU'),600,500)).
6859: '</li>';
6860: }
6861: if ($changes{'reportupdates'}) {
6862: $resulttext .= '<li>'.
6863: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
6864: $offon[$env{'form.reportupdates'}].'".',
6865: &Apache::loncommon::modal_link('http://loncapa.org/core.html',
6866: &mt('LON-CAPA core group - MSU'),600,500)).
6867: '</li>';
6868: }
1.28 raeburn 6869: $resulttext .= '</ul>';
6870: } else {
1.34 raeburn 6871: $resulttext = &mt('No changes made to contact information');
1.28 raeburn 6872: }
6873: } else {
6874: $resulttext = '<span class="LC_error">'.
6875: &mt('An error occurred: [_1].',$putresult).'</span>';
6876: }
6877: return $resulttext;
6878: }
6879:
6880: sub modify_usercreation {
1.27 raeburn 6881: my ($dom,%domconfig) = @_;
1.34 raeburn 6882: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate);
1.43 raeburn 6883: my $warningmsg;
1.27 raeburn 6884: if (ref($domconfig{'usercreation'}) eq 'HASH') {
6885: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
6886: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
6887: }
6888: }
6889: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
1.32 raeburn 6890: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
1.43 raeburn 6891: my @email_rule = &Apache::loncommon::get_env_multiple('form.email_rule');
1.100 raeburn 6892: my @contexts = ('author','course','requestcrs','selfcreate');
1.34 raeburn 6893: foreach my $item(@contexts) {
1.45 raeburn 6894: if ($item eq 'selfcreate') {
1.50 raeburn 6895: @{$cancreate{$item}} = &Apache::loncommon::get_env_multiple('form.can_createuser_'.$item);
1.212 ! raeburn 6896: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.43 raeburn 6897: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) || ($domdefaults{'auth_def'} eq 'localauth'))) {
1.50 raeburn 6898: if (ref($cancreate{$item}) eq 'ARRAY') {
6899: if (grep(/^login$/,@{$cancreate{$item}})) {
6900: $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.');
6901: }
1.43 raeburn 6902: }
6903: }
1.50 raeburn 6904: } else {
6905: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.43 raeburn 6906: }
1.34 raeburn 6907: }
1.93 raeburn 6908: my ($othertitle,$usertypes,$types) =
6909: &Apache::loncommon::sorted_inst_types($dom);
6910: if (ref($types) eq 'ARRAY') {
6911: if (@{$types} > 0) {
6912: @{$cancreate{'statustocreate'}} =
6913: &Apache::loncommon::get_env_multiple('form.statustocreate');
1.103 raeburn 6914: } else {
6915: @{$cancreate{'statustocreate'}} = ();
1.93 raeburn 6916: }
6917: push(@contexts,'statustocreate');
6918: }
1.165 raeburn 6919: &process_captcha('cancreate',\%changes,\%cancreate,\%curr_usercreation);
1.34 raeburn 6920: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
6921: foreach my $item (@contexts) {
1.93 raeburn 6922: if (($item eq 'selfcreate') || ($item eq 'statustocreate')) {
6923: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
1.50 raeburn 6924: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
1.103 raeburn 6925: if (ref($cancreate{$item}) eq 'ARRAY') {
6926: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
6927: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6928: push(@{$changes{'cancreate'}},$item);
6929: }
1.50 raeburn 6930: }
6931: }
6932: }
6933: } else {
6934: if ($curr_usercreation{'cancreate'}{$item} eq '') {
6935: if (@{$cancreate{$item}} > 0) {
6936: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6937: push(@{$changes{'cancreate'}},$item);
6938: }
6939: }
6940: } else {
6941: if ($curr_usercreation{'cancreate'}{$item} eq 'any') {
6942: if (@{$cancreate{$item}} < 3) {
6943: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6944: push(@{$changes{'cancreate'}},$item);
6945: }
6946: }
6947: } elsif ($curr_usercreation{'cancreate'}{$item} eq 'none') {
6948: if (@{$cancreate{$item}} > 0) {
6949: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6950: push(@{$changes{'cancreate'}},$item);
6951: }
6952: }
6953: } elsif (!grep(/^$curr_usercreation{'cancreate'}{$item}$/,@{$cancreate{$item}})) {
6954: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6955: push(@{$changes{'cancreate'}},$item);
6956: }
6957: }
6958: }
6959: }
6960: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6961: foreach my $type (@{$cancreate{$item}}) {
6962: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
6963: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
6964: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6965: push(@{$changes{'cancreate'}},$item);
6966: }
6967: }
6968: } elsif (($curr_usercreation{'cancreate'}{$item} ne 'any') &&
6969: ($curr_usercreation{'cancreate'}{$item} ne 'none')) {
6970: if ($curr_usercreation{'cancreate'}{$item} ne $type) {
6971: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
6972: push(@{$changes{'cancreate'}},$item);
6973: }
6974: }
6975: }
6976: }
6977: }
6978: } else {
6979: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
6980: push(@{$changes{'cancreate'}},$item);
6981: }
6982: }
1.27 raeburn 6983: }
1.34 raeburn 6984: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
6985: foreach my $item (@contexts) {
1.43 raeburn 6986: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 6987: if ($cancreate{$item} ne 'any') {
6988: push(@{$changes{'cancreate'}},$item);
6989: }
6990: } else {
6991: if ($cancreate{$item} ne 'none') {
6992: push(@{$changes{'cancreate'}},$item);
6993: }
1.27 raeburn 6994: }
6995: }
6996: } else {
1.43 raeburn 6997: foreach my $item (@contexts) {
1.34 raeburn 6998: push(@{$changes{'cancreate'}},$item);
6999: }
1.27 raeburn 7000: }
1.34 raeburn 7001:
1.27 raeburn 7002: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
7003: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
7004: if (!grep(/^\Q$type\E$/,@username_rule)) {
7005: push(@{$changes{'username_rule'}},$type);
7006: }
7007: }
7008: foreach my $type (@username_rule) {
7009: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
7010: push(@{$changes{'username_rule'}},$type);
7011: }
7012: }
7013: } else {
7014: push(@{$changes{'username_rule'}},@username_rule);
7015: }
7016:
1.32 raeburn 7017: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
7018: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
7019: if (!grep(/^\Q$type\E$/,@id_rule)) {
7020: push(@{$changes{'id_rule'}},$type);
7021: }
7022: }
7023: foreach my $type (@id_rule) {
7024: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
7025: push(@{$changes{'id_rule'}},$type);
7026: }
7027: }
7028: } else {
7029: push(@{$changes{'id_rule'}},@id_rule);
7030: }
7031:
1.43 raeburn 7032: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
7033: foreach my $type (@{$curr_usercreation{'email_rule'}}) {
7034: if (!grep(/^\Q$type\E$/,@email_rule)) {
7035: push(@{$changes{'email_rule'}},$type);
7036: }
7037: }
7038: foreach my $type (@email_rule) {
7039: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'email_rule'}})) {
7040: push(@{$changes{'email_rule'}},$type);
7041: }
7042: }
7043: } else {
7044: push(@{$changes{'email_rule'}},@email_rule);
7045: }
7046:
7047: my @authen_contexts = ('author','course','domain');
1.28 raeburn 7048: my @authtypes = ('int','krb4','krb5','loc');
7049: my %authhash;
1.43 raeburn 7050: foreach my $item (@authen_contexts) {
1.28 raeburn 7051: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
7052: foreach my $auth (@authtypes) {
7053: if (grep(/^\Q$auth\E$/,@authallowed)) {
7054: $authhash{$item}{$auth} = 1;
7055: } else {
7056: $authhash{$item}{$auth} = 0;
7057: }
7058: }
7059: }
7060: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 7061: foreach my $item (@authen_contexts) {
1.28 raeburn 7062: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
7063: foreach my $auth (@authtypes) {
7064: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
7065: push(@{$changes{'authtypes'}},$item);
7066: last;
7067: }
7068: }
7069: }
7070: }
7071: } else {
1.43 raeburn 7072: foreach my $item (@authen_contexts) {
1.28 raeburn 7073: push(@{$changes{'authtypes'}},$item);
7074: }
7075: }
7076:
1.27 raeburn 7077: my %usercreation_hash = (
1.28 raeburn 7078: usercreation => {
1.34 raeburn 7079: cancreate => \%cancreate,
1.27 raeburn 7080: username_rule => \@username_rule,
1.32 raeburn 7081: id_rule => \@id_rule,
1.43 raeburn 7082: email_rule => \@email_rule,
1.32 raeburn 7083: authtypes => \%authhash,
1.27 raeburn 7084: }
7085: );
7086:
7087: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
7088: $dom);
1.50 raeburn 7089:
7090: my %selfcreatetypes = (
7091: sso => 'users authenticated by institutional single sign on',
7092: login => 'users authenticated by institutional log-in',
7093: email => 'users who provide a valid e-mail address for use as the username',
7094: );
1.27 raeburn 7095: if ($putresult eq 'ok') {
7096: if (keys(%changes) > 0) {
7097: $resulttext = &mt('Changes made:').'<ul>';
7098: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.34 raeburn 7099: my %lt = &usercreation_types();
7100: foreach my $type (@{$changes{'cancreate'}}) {
1.100 raeburn 7101: my $chgtext;
1.165 raeburn 7102: unless (($type eq 'statustocreate') || ($type eq 'captcha') || ($type eq 'recaptchakeys')) {
1.100 raeburn 7103: $chgtext = $lt{$type}.', ';
7104: }
1.45 raeburn 7105: if ($type eq 'selfcreate') {
1.50 raeburn 7106: if (@{$cancreate{$type}} == 0) {
1.43 raeburn 7107: $chgtext .= &mt('creation of a new user account is not permitted.');
1.50 raeburn 7108: } else {
1.100 raeburn 7109: $chgtext .= &mt('creation of a new account is permitted for:').'<ul>';
1.50 raeburn 7110: foreach my $case (@{$cancreate{$type}}) {
7111: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
7112: }
7113: $chgtext .= '</ul>';
1.100 raeburn 7114: if (ref($cancreate{$type}) eq 'ARRAY') {
7115: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
7116: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
7117: if (@{$cancreate{'statustocreate'}} == 0) {
7118: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7119: }
7120: }
7121: }
7122: }
1.43 raeburn 7123: }
1.93 raeburn 7124: } elsif ($type eq 'statustocreate') {
1.96 raeburn 7125: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
7126: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
7127: if (@{$cancreate{'selfcreate'}} > 0) {
7128: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 7129:
7130: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 7131: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7132: $chgtext .= '<br /><span class="LC_warning">'.&mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").'</span>';
7133: }
1.96 raeburn 7134: } elsif (ref($usertypes) eq 'HASH') {
7135: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 7136: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
7137: } else {
7138: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
7139: }
7140: $chgtext .= '<ul>';
7141: foreach my $case (@{$cancreate{$type}}) {
7142: if ($case eq 'default') {
7143: $chgtext .= '<li>'.$othertitle.'</li>';
7144: } else {
7145: $chgtext .= '<li>'.$usertypes->{$case}.'</li>';
1.93 raeburn 7146: }
7147: }
1.100 raeburn 7148: $chgtext .= '</ul>';
7149: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
7150: $chgtext .= '<br /><span class="LC_warning">'.&mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').'</span>';
7151: }
7152: }
7153: } else {
7154: if (@{$cancreate{$type}} == 0) {
7155: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
7156: } else {
7157: $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 7158: }
7159: }
7160: }
1.165 raeburn 7161: } elsif ($type eq 'captcha') {
7162: if ($cancreate{$type} eq 'notused') {
7163: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
7164: } else {
7165: my %captchas = &captcha_phrases();
7166: if ($captchas{$cancreate{$type}}) {
7167: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$cancreate{$type}}.");
7168: } else {
1.210 raeburn 7169: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
1.165 raeburn 7170: }
7171: }
7172: } elsif ($type eq 'recaptchakeys') {
7173: my ($privkey,$pubkey);
7174: if (ref($cancreate{$type}) eq 'HASH') {
7175: $pubkey = $cancreate{$type}{'public'};
7176: $privkey = $cancreate{$type}{'private'};
7177: }
7178: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
7179: if (!$pubkey) {
7180: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
7181: } else {
7182: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
7183: }
7184: if (!$privkey) {
7185: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
7186: } else {
7187: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
7188: }
7189: $chgtext .= '</ul>';
1.43 raeburn 7190: } else {
7191: if ($cancreate{$type} eq 'none') {
7192: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
7193: } elsif ($cancreate{$type} eq 'any') {
7194: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
7195: } elsif ($cancreate{$type} eq 'official') {
7196: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
7197: } elsif ($cancreate{$type} eq 'unofficial') {
7198: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
7199: }
1.34 raeburn 7200: }
7201: $resulttext .= '<li>'.$chgtext.'</li>';
1.27 raeburn 7202: }
7203: }
7204: if (ref($changes{'username_rule'}) eq 'ARRAY') {
1.32 raeburn 7205: my ($rules,$ruleorder) =
7206: &Apache::lonnet::inst_userrules($dom,'username');
1.27 raeburn 7207: my $chgtext = '<ul>';
7208: foreach my $type (@username_rule) {
7209: if (ref($rules->{$type}) eq 'HASH') {
7210: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
7211: }
7212: }
7213: $chgtext .= '</ul>';
7214: if (@username_rule > 0) {
7215: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7216: } else {
1.28 raeburn 7217: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
1.27 raeburn 7218: }
7219: }
1.32 raeburn 7220: if (ref($changes{'id_rule'}) eq 'ARRAY') {
7221: my ($idrules,$idruleorder) =
7222: &Apache::lonnet::inst_userrules($dom,'id');
7223: my $chgtext = '<ul>';
7224: foreach my $type (@id_rule) {
7225: if (ref($idrules->{$type}) eq 'HASH') {
7226: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
7227: }
7228: }
7229: $chgtext .= '</ul>';
7230: if (@id_rule > 0) {
7231: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
7232: } else {
7233: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
7234: }
7235: }
1.43 raeburn 7236: if (ref($changes{'email_rule'}) eq 'ARRAY') {
7237: my ($emailrules,$emailruleorder) =
7238: &Apache::lonnet::inst_userrules($dom,'email');
7239: my $chgtext = '<ul>';
7240: foreach my $type (@email_rule) {
7241: if (ref($emailrules->{$type}) eq 'HASH') {
7242: $chgtext .= '<li>'.$emailrules->{$type}{'name'}.'</li>';
7243: }
7244: }
7245: $chgtext .= '</ul>';
7246: if (@email_rule > 0) {
7247: $resulttext .= '<li>'.&mt('Accounts may not be created by users self-enrolling with e-mail addresses of the following types: ').$chgtext.'</li>';
7248: } else {
7249: $resulttext .= '<li>'.&mt('There are now no restrictions on e-mail addresses which may be used as a username when self-enrolling.').'</li>';
7250: }
7251: }
7252:
1.28 raeburn 7253: my %authname = &authtype_names();
7254: my %context_title = &context_names();
7255: if (ref($changes{'authtypes'}) eq 'ARRAY') {
7256: my $chgtext = '<ul>';
7257: foreach my $type (@{$changes{'authtypes'}}) {
7258: my @allowed;
7259: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
7260: foreach my $auth (@authtypes) {
7261: if ($authhash{$type}{$auth}) {
7262: push(@allowed,$authname{$auth});
7263: }
7264: }
1.43 raeburn 7265: if (@allowed > 0) {
7266: $chgtext .= join(', ',@allowed).'</li>';
7267: } else {
7268: $chgtext .= &mt('none').'</li>';
7269: }
1.28 raeburn 7270: }
7271: $chgtext .= '</ul>';
7272: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
7273: $resulttext .= '</li>';
7274: }
1.27 raeburn 7275: $resulttext .= '</ul>';
7276: } else {
1.28 raeburn 7277: $resulttext = &mt('No changes made to user creation settings');
1.27 raeburn 7278: }
7279: } else {
7280: $resulttext = '<span class="LC_error">'.
1.23 raeburn 7281: &mt('An error occurred: [_1]',$putresult).'</span>';
7282: }
1.43 raeburn 7283: if ($warningmsg ne '') {
7284: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
7285: }
1.23 raeburn 7286: return $resulttext;
7287: }
7288:
1.165 raeburn 7289: sub process_captcha {
7290: my ($container,$changes,$newsettings,$current) = @_;
7291: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH') || (ref($current) eq 'HASH'));
7292: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
7293: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
7294: $newsettings->{'captcha'} = 'original';
7295: }
7296: if ($current->{'captcha'} ne $newsettings->{'captcha'}) {
1.210 raeburn 7297: if ($container eq 'cancreate') {
1.169 raeburn 7298: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7299: push(@{$changes->{'cancreate'}},'captcha');
7300: } elsif (!defined($changes->{'cancreate'})) {
7301: $changes->{'cancreate'} = ['captcha'];
7302: }
7303: } else {
7304: $changes->{'captcha'} = 1;
1.165 raeburn 7305: }
7306: }
7307: my ($newpub,$newpriv,$currpub,$currpriv);
7308: if ($newsettings->{'captcha'} eq 'recaptcha') {
7309: $newpub = $env{'form.'.$container.'_recaptchapub'};
7310: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.169 raeburn 7311: $newpub =~ s/\W//g;
7312: $newpriv =~ s/\W//g;
7313: $newsettings->{'recaptchakeys'} = {
7314: public => $newpub,
7315: private => $newpriv,
7316: };
1.165 raeburn 7317: }
7318: if (ref($current->{'recaptchakeys'}) eq 'HASH') {
7319: $currpub = $current->{'recaptchakeys'}{'public'};
7320: $currpriv = $current->{'recaptchakeys'}{'private'};
1.179 raeburn 7321: unless ($newsettings->{'captcha'} eq 'recaptcha') {
7322: $newsettings->{'recaptchakeys'} = {
7323: public => '',
7324: private => '',
7325: }
7326: }
1.165 raeburn 7327: }
7328: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
1.169 raeburn 7329: if ($container eq 'cancreate') {
7330: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
7331: push(@{$changes->{'cancreate'}},'recaptchakeys');
7332: } elsif (!defined($changes->{'cancreate'})) {
7333: $changes->{'cancreate'} = ['recaptchakeys'];
7334: }
7335: } else {
1.210 raeburn 7336: $changes->{'recaptchakeys'} = 1;
1.165 raeburn 7337: }
7338: }
7339: return;
7340: }
7341:
1.33 raeburn 7342: sub modify_usermodification {
7343: my ($dom,%domconfig) = @_;
7344: my ($resulttext,%curr_usermodification,%changes);
7345: if (ref($domconfig{'usermodification'}) eq 'HASH') {
7346: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
7347: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
7348: }
7349: }
1.63 raeburn 7350: my @contexts = ('author','course','selfcreate');
1.33 raeburn 7351: my %context_title = (
7352: author => 'In author context',
7353: course => 'In course context',
1.63 raeburn 7354: selfcreate => 'When self creating account',
1.33 raeburn 7355: );
7356: my @fields = ('lastname','firstname','middlename','generation',
7357: 'permanentemail','id');
7358: my %roles = (
7359: author => ['ca','aa'],
7360: course => ['st','ep','ta','in','cr'],
7361: );
1.63 raeburn 7362: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7363: if (ref($types) eq 'ARRAY') {
7364: push(@{$types},'default');
7365: $usertypes->{'default'} = $othertitle;
7366: }
7367: $roles{'selfcreate'} = $types;
1.33 raeburn 7368: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
7369: my %modifyhash;
7370: foreach my $context (@contexts) {
7371: foreach my $role (@{$roles{$context}}) {
7372: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
7373: foreach my $item (@fields) {
7374: if (grep(/^\Q$item\E$/,@modifiable)) {
7375: $modifyhash{$context}{$role}{$item} = 1;
7376: } else {
7377: $modifyhash{$context}{$role}{$item} = 0;
7378: }
7379: }
7380: }
7381: if (ref($curr_usermodification{$context}) eq 'HASH') {
7382: foreach my $role (@{$roles{$context}}) {
7383: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
7384: foreach my $field (@fields) {
7385: if ($modifyhash{$context}{$role}{$field} ne
7386: $curr_usermodification{$context}{$role}{$field}) {
7387: push(@{$changes{$context}},$role);
7388: last;
7389: }
7390: }
7391: }
7392: }
7393: } else {
7394: foreach my $context (@contexts) {
7395: foreach my $role (@{$roles{$context}}) {
7396: push(@{$changes{$context}},$role);
7397: }
7398: }
7399: }
7400: }
7401: my %usermodification_hash = (
7402: usermodification => \%modifyhash,
7403: );
7404: my $putresult = &Apache::lonnet::put_dom('configuration',
7405: \%usermodification_hash,$dom);
7406: if ($putresult eq 'ok') {
7407: if (keys(%changes) > 0) {
7408: $resulttext = &mt('Changes made: ').'<ul>';
7409: foreach my $context (@contexts) {
7410: if (ref($changes{$context}) eq 'ARRAY') {
7411: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
7412: if (ref($changes{$context}) eq 'ARRAY') {
7413: foreach my $role (@{$changes{$context}}) {
7414: my $rolename;
1.63 raeburn 7415: if ($context eq 'selfcreate') {
7416: $rolename = $role;
7417: if (ref($usertypes) eq 'HASH') {
7418: if ($usertypes->{$role} ne '') {
7419: $rolename = $usertypes->{$role};
7420: }
7421: }
1.33 raeburn 7422: } else {
1.63 raeburn 7423: if ($role eq 'cr') {
7424: $rolename = &mt('Custom');
7425: } else {
7426: $rolename = &Apache::lonnet::plaintext($role);
7427: }
1.33 raeburn 7428: }
7429: my @modifiable;
1.63 raeburn 7430: if ($context eq 'selfcreate') {
1.126 bisitz 7431: $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 7432: } else {
7433: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
7434: }
1.33 raeburn 7435: foreach my $field (@fields) {
7436: if ($modifyhash{$context}{$role}{$field}) {
7437: push(@modifiable,$fieldtitles{$field});
7438: }
7439: }
7440: if (@modifiable > 0) {
7441: $resulttext .= join(', ',@modifiable);
7442: } else {
7443: $resulttext .= &mt('none');
7444: }
7445: $resulttext .= '</li>';
7446: }
7447: $resulttext .= '</ul></li>';
7448: }
7449: }
7450: }
7451: $resulttext .= '</ul>';
7452: } else {
7453: $resulttext = &mt('No changes made to user modification settings');
7454: }
7455: } else {
7456: $resulttext = '<span class="LC_error">'.
7457: &mt('An error occurred: [_1]',$putresult).'</span>';
7458: }
7459: return $resulttext;
7460: }
7461:
1.43 raeburn 7462: sub modify_defaults {
1.212 ! raeburn 7463: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 7464: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.212 ! raeburn 7465: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.141 raeburn 7466: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def','portal_def');
1.43 raeburn 7467: my @authtypes = ('internal','krb4','krb5','localauth');
7468: foreach my $item (@items) {
7469: $newvalues{$item} = $env{'form.'.$item};
7470: if ($item eq 'auth_def') {
7471: if ($newvalues{$item} ne '') {
7472: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
7473: push(@errors,$item);
7474: }
7475: }
7476: } elsif ($item eq 'lang_def') {
7477: if ($newvalues{$item} ne '') {
7478: if ($newvalues{$item} =~ /^(\w+)/) {
7479: my $langcode = $1;
1.103 raeburn 7480: if ($langcode ne 'x_chef') {
7481: if (code2language($langcode) eq '') {
7482: push(@errors,$item);
7483: }
1.43 raeburn 7484: }
7485: } else {
7486: push(@errors,$item);
7487: }
7488: }
1.54 raeburn 7489: } elsif ($item eq 'timezone_def') {
7490: if ($newvalues{$item} ne '') {
1.62 raeburn 7491: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 7492: push(@errors,$item);
7493: }
7494: }
1.68 raeburn 7495: } elsif ($item eq 'datelocale_def') {
7496: if ($newvalues{$item} ne '') {
7497: my @datelocale_ids = DateTime::Locale->ids();
7498: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
7499: push(@errors,$item);
7500: }
7501: }
1.141 raeburn 7502: } elsif ($item eq 'portal_def') {
7503: if ($newvalues{$item} ne '') {
7504: 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])\/?$/) {
7505: push(@errors,$item);
7506: }
7507: }
1.43 raeburn 7508: }
7509: if (grep(/^\Q$item\E$/,@errors)) {
7510: $newvalues{$item} = $domdefaults{$item};
7511: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
7512: $changes{$item} = 1;
7513: }
1.72 raeburn 7514: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 7515: }
7516: my %defaults_hash = (
1.72 raeburn 7517: defaults => \%newvalues,
7518: );
1.43 raeburn 7519: my $title = &defaults_titles();
7520: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
7521: $dom);
7522: if ($putresult eq 'ok') {
7523: if (keys(%changes) > 0) {
7524: $resulttext = &mt('Changes made:').'<ul>';
1.212 ! raeburn 7525: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 7526: 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";
7527: foreach my $item (sort(keys(%changes))) {
7528: my $value = $env{'form.'.$item};
7529: if ($value eq '') {
7530: $value = &mt('none');
7531: } elsif ($item eq 'auth_def') {
7532: my %authnames = &authtype_names();
7533: my %shortauth = (
7534: internal => 'int',
7535: krb4 => 'krb4',
7536: krb5 => 'krb5',
7537: localauth => 'loc',
7538: );
7539: $value = $authnames{$shortauth{$value}};
7540: }
7541: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
7542: $mailmsgtext .= "$title->{$item} set to $value\n";
7543: }
7544: $resulttext .= '</ul>';
7545: $mailmsgtext .= "\n";
7546: my $cachetime = 24*60*60;
1.72 raeburn 7547: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 ! raeburn 7548: if (ref($lastactref) eq 'HASH') {
! 7549: $lastactref->{'domdefaults'} = 1;
! 7550: }
1.68 raeburn 7551: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.203 raeburn 7552: my $notify = 1;
7553: if (ref($domconfig{'contacts'}) eq 'HASH') {
7554: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
7555: $notify = 0;
7556: }
7557: }
7558: if ($notify) {
7559: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
7560: "LON-CAPA Domain Settings Change - $dom",
7561: $mailmsgtext);
7562: }
1.54 raeburn 7563: }
1.43 raeburn 7564: } else {
1.54 raeburn 7565: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 7566: }
7567: } else {
7568: $resulttext = '<span class="LC_error">'.
7569: &mt('An error occurred: [_1]',$putresult).'</span>';
7570: }
7571: if (@errors > 0) {
7572: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
7573: foreach my $item (@errors) {
7574: $resulttext .= ' "'.$title->{$item}.'",';
7575: }
7576: $resulttext =~ s/,$//;
7577: }
7578: return $resulttext;
7579: }
7580:
1.46 raeburn 7581: sub modify_scantron {
1.205 raeburn 7582: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 7583: my ($resulttext,%confhash,%changes,$errors);
7584: my $custom = 'custom.tab';
7585: my $default = 'default.tab';
7586: my $servadm = $r->dir_config('lonAdmEMail');
7587: my ($configuserok,$author_ok,$switchserver) =
7588: &config_check($dom,$confname,$servadm);
7589: if ($env{'form.scantronformat.filename'} ne '') {
7590: my $error;
7591: if ($configuserok eq 'ok') {
7592: if ($switchserver) {
1.130 raeburn 7593: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 7594: } else {
7595: if ($author_ok eq 'ok') {
7596: my ($result,$scantronurl) =
7597: &publishlogo($r,'upload','scantronformat',$dom,
7598: $confname,'scantron','','',$custom);
7599: if ($result eq 'ok') {
7600: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 7601: $changes{'scantronformat'} = 1;
1.46 raeburn 7602: } else {
7603: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
7604: }
7605: } else {
7606: $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);
7607: }
7608: }
7609: } else {
7610: $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);
7611: }
7612: if ($error) {
7613: &Apache::lonnet::logthis($error);
7614: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
7615: }
7616: }
1.48 raeburn 7617: if (ref($domconfig{'scantron'}) eq 'HASH') {
7618: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
7619: if ($env{'form.scantronformat_del'}) {
7620: $confhash{'scantron'}{'scantronformat'} = '';
7621: $changes{'scantronformat'} = 1;
1.46 raeburn 7622: }
7623: }
7624: }
7625: if (keys(%confhash) > 0) {
7626: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
7627: $dom);
7628: if ($putresult eq 'ok') {
7629: if (keys(%changes) > 0) {
1.48 raeburn 7630: if (ref($confhash{'scantron'}) eq 'HASH') {
7631: $resulttext = &mt('Changes made:').'<ul>';
7632: if ($confhash{'scantron'}{'scantronformat'} eq '') {
1.130 raeburn 7633: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
1.48 raeburn 7634: } else {
1.130 raeburn 7635: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
1.46 raeburn 7636: }
1.48 raeburn 7637: $resulttext .= '</ul>';
7638: } else {
1.130 raeburn 7639: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 7640: }
7641: $resulttext .= '</ul>';
7642: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.212 ! raeburn 7643: if (ref($lastactref) eq 'HASH') {
! 7644: $lastactref->{'domainconfig'} = 1;
! 7645: }
1.46 raeburn 7646: } else {
1.130 raeburn 7647: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7648: }
7649: } else {
7650: $resulttext = '<span class="LC_error">'.
7651: &mt('An error occurred: [_1]',$putresult).'</span>';
7652: }
7653: } else {
1.130 raeburn 7654: $resulttext = &mt('No changes made to bubblesheet format file');
1.46 raeburn 7655: }
7656: if ($errors) {
7657: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
7658: $errors.'</ul>';
7659: }
7660: return $resulttext;
7661: }
7662:
1.48 raeburn 7663: sub modify_coursecategories {
7664: my ($dom,%domconfig) = @_;
1.57 raeburn 7665: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
7666: $cathash);
1.48 raeburn 7667: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.55 raeburn 7668: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 7669: $cathash = $domconfig{'coursecategories'}{'cats'};
7670: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
7671: $changes{'togglecats'} = 1;
7672: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
7673: }
7674: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
7675: $changes{'categorize'} = 1;
7676: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
7677: }
1.120 raeburn 7678: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
7679: $changes{'togglecatscomm'} = 1;
7680: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
7681: }
7682: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
7683: $changes{'categorizecomm'} = 1;
7684: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
7685: }
1.57 raeburn 7686: } else {
7687: $changes{'togglecats'} = 1;
7688: $changes{'categorize'} = 1;
1.124 raeburn 7689: $changes{'togglecatscomm'} = 1;
7690: $changes{'categorizecomm'} = 1;
1.87 raeburn 7691: $domconfig{'coursecategories'} = {
7692: togglecats => $env{'form.togglecats'},
7693: categorize => $env{'form.categorize'},
1.124 raeburn 7694: togglecatscomm => $env{'form.togglecatscomm'},
7695: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 7696: };
1.57 raeburn 7697: }
7698: if (ref($cathash) eq 'HASH') {
7699: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 7700: push (@deletecategory,'instcode::0');
7701: }
1.120 raeburn 7702: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
7703: push(@deletecategory,'communities::0');
7704: }
1.48 raeburn 7705: }
1.57 raeburn 7706: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
7707: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7708: if (@deletecategory > 0) {
7709: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 7710: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 7711: foreach my $item (@deletecategory) {
1.57 raeburn 7712: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
7713: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 7714: $deletions{$item} = 1;
1.57 raeburn 7715: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 7716: }
7717: }
7718: }
1.57 raeburn 7719: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 7720: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 7721: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 7722: $reorderings{$item} = 1;
1.57 raeburn 7723: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 7724: }
7725: if ($env{'form.addcategory_name_'.$item} ne '') {
7726: my $newcat = $env{'form.addcategory_name_'.$item};
7727: my $newdepth = $depth+1;
7728: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7729: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 7730: $adds{$newitem} = 1;
7731: }
7732: if ($env{'form.subcat_'.$item} ne '') {
7733: my $newcat = $env{'form.subcat_'.$item};
7734: my $newdepth = $depth+1;
7735: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 7736: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 7737: $adds{$newitem} = 1;
7738: }
7739: }
7740: }
7741: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 7742: if (ref($cathash) eq 'HASH') {
1.48 raeburn 7743: my $newitem = 'instcode::0';
1.57 raeburn 7744: if ($cathash->{$newitem} eq '') {
7745: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7746: $adds{$newitem} = 1;
7747: }
7748: } else {
7749: my $newitem = 'instcode::0';
1.57 raeburn 7750: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 7751: $adds{$newitem} = 1;
7752: }
7753: }
1.120 raeburn 7754: if ($env{'form.communities'} eq '1') {
7755: if (ref($cathash) eq 'HASH') {
7756: my $newitem = 'communities::0';
7757: if ($cathash->{$newitem} eq '') {
7758: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7759: $adds{$newitem} = 1;
7760: }
7761: } else {
7762: my $newitem = 'communities::0';
7763: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
7764: $adds{$newitem} = 1;
7765: }
7766: }
1.48 raeburn 7767: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 7768: if (($env{'form.addcategory_name'} ne 'instcode') &&
7769: ($env{'form.addcategory_name'} ne 'communities')) {
7770: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
7771: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
7772: $adds{$newitem} = 1;
7773: }
1.48 raeburn 7774: }
1.57 raeburn 7775: my $putresult;
1.48 raeburn 7776: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7777: if (keys(%deletions) > 0) {
7778: foreach my $key (keys(%deletions)) {
7779: if ($predelallitems{$key} ne '') {
7780: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
7781: }
7782: }
7783: }
7784: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 7785: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 7786: if (ref($chkcats[0]) eq 'ARRAY') {
7787: my $depth = 0;
7788: my $chg = 0;
7789: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
7790: my $name = $chkcats[0][$i];
7791: my $item;
7792: if ($name eq '') {
7793: $chg ++;
7794: } else {
7795: $item = &escape($name).'::0';
7796: if ($chg) {
1.57 raeburn 7797: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 7798: }
7799: $depth ++;
1.57 raeburn 7800: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 7801: $depth --;
7802: }
7803: }
7804: }
1.57 raeburn 7805: }
7806: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7807: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 7808: if ($putresult eq 'ok') {
1.57 raeburn 7809: my %title = (
1.120 raeburn 7810: togglecats => 'Show/Hide a course in catalog',
7811: categorize => 'Assign a category to a course',
7812: togglecatscomm => 'Show/Hide a community in catalog',
7813: categorizecomm => 'Assign a category to a community',
1.57 raeburn 7814: );
7815: my %level = (
1.120 raeburn 7816: dom => 'set in Domain ("Modify Course/Community")',
7817: crs => 'set in Course ("Course Configuration")',
7818: comm => 'set in Community ("Community Configuration")',
1.57 raeburn 7819: );
1.48 raeburn 7820: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 7821: if ($changes{'togglecats'}) {
7822: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
7823: }
7824: if ($changes{'categorize'}) {
7825: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 7826: }
1.120 raeburn 7827: if ($changes{'togglecatscomm'}) {
7828: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
7829: }
7830: if ($changes{'categorizecomm'}) {
7831: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
7832: }
1.57 raeburn 7833: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
7834: my $cathash;
7835: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
7836: $cathash = $domconfig{'coursecategories'}{'cats'};
7837: } else {
7838: $cathash = {};
7839: }
7840: my (@cats,@trails,%allitems);
7841: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
7842: if (keys(%deletions) > 0) {
7843: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
7844: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
7845: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
7846: }
7847: $resulttext .= '</ul></li>';
7848: }
7849: if (keys(%reorderings) > 0) {
7850: my %sort_by_trail;
7851: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
7852: foreach my $key (keys(%reorderings)) {
7853: if ($allitems{$key} ne '') {
7854: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7855: }
1.48 raeburn 7856: }
1.57 raeburn 7857: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7858: $resulttext .= '<li>'.$trails[$trail].'</li>';
7859: }
7860: $resulttext .= '</ul></li>';
1.48 raeburn 7861: }
1.57 raeburn 7862: if (keys(%adds) > 0) {
7863: my %sort_by_trail;
7864: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
7865: foreach my $key (keys(%adds)) {
7866: if ($allitems{$key} ne '') {
7867: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
7868: }
7869: }
7870: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
7871: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 7872: }
1.57 raeburn 7873: $resulttext .= '</ul></li>';
1.48 raeburn 7874: }
7875: }
7876: $resulttext .= '</ul>';
7877: } else {
7878: $resulttext = '<span class="LC_error">'.
1.57 raeburn 7879: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 7880: }
7881: } else {
1.120 raeburn 7882: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 7883: }
7884: return $resulttext;
7885: }
7886:
1.69 raeburn 7887: sub modify_serverstatuses {
7888: my ($dom,%domconfig) = @_;
7889: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
7890: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
7891: %currserverstatus = %{$domconfig{'serverstatuses'}};
7892: }
7893: my @pages = &serverstatus_pages();
7894: foreach my $type (@pages) {
7895: $newserverstatus{$type}{'namedusers'} = '';
7896: $newserverstatus{$type}{'machines'} = '';
7897: if (defined($env{'form.'.$type.'_namedusers'})) {
7898: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
7899: my @okusers;
7900: foreach my $user (@users) {
7901: my ($uname,$udom) = split(/:/,$user);
7902: if (($udom =~ /^$match_domain$/) &&
7903: (&Apache::lonnet::domain($udom)) &&
7904: ($uname =~ /^$match_username$/)) {
7905: if (!grep(/^\Q$user\E/,@okusers)) {
7906: push(@okusers,$user);
7907: }
7908: }
7909: }
7910: if (@okusers > 0) {
7911: @okusers = sort(@okusers);
7912: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
7913: }
7914: }
7915: if (defined($env{'form.'.$type.'_machines'})) {
7916: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
7917: my @okmachines;
7918: foreach my $ip (@machines) {
7919: my @parts = split(/\./,$ip);
7920: next if (@parts < 4);
7921: my $badip = 0;
7922: for (my $i=0; $i<4; $i++) {
7923: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
7924: $badip = 1;
7925: last;
7926: }
7927: }
7928: if (!$badip) {
7929: push(@okmachines,$ip);
7930: }
7931: }
7932: @okmachines = sort(@okmachines);
7933: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
7934: }
7935: }
7936: my %serverstatushash = (
7937: serverstatuses => \%newserverstatus,
7938: );
7939: foreach my $type (@pages) {
1.83 raeburn 7940: foreach my $setting ('namedusers','machines') {
1.84 raeburn 7941: my (@current,@new);
1.83 raeburn 7942: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 7943: if ($currserverstatus{$type}{$setting} ne '') {
7944: @current = split(/,/,$currserverstatus{$type}{$setting});
7945: }
7946: }
7947: if ($newserverstatus{$type}{$setting} ne '') {
7948: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 7949: }
7950: if (@current > 0) {
7951: if (@new > 0) {
7952: foreach my $item (@current) {
7953: if (!grep(/^\Q$item\E$/,@new)) {
7954: $changes{$type}{$setting} = 1;
1.82 raeburn 7955: last;
7956: }
7957: }
1.84 raeburn 7958: foreach my $item (@new) {
7959: if (!grep(/^\Q$item\E$/,@current)) {
7960: $changes{$type}{$setting} = 1;
7961: last;
1.82 raeburn 7962: }
7963: }
7964: } else {
1.83 raeburn 7965: $changes{$type}{$setting} = 1;
1.69 raeburn 7966: }
1.83 raeburn 7967: } elsif (@new > 0) {
7968: $changes{$type}{$setting} = 1;
1.69 raeburn 7969: }
7970: }
7971: }
7972: if (keys(%changes) > 0) {
1.81 raeburn 7973: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 7974: my $putresult = &Apache::lonnet::put_dom('configuration',
7975: \%serverstatushash,$dom);
7976: if ($putresult eq 'ok') {
7977: $resulttext .= &mt('Changes made:').'<ul>';
7978: foreach my $type (@pages) {
1.84 raeburn 7979: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 7980: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 7981: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 7982: if ($newserverstatus{$type}{'namedusers'} eq '') {
7983: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
7984: } else {
7985: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
7986: }
1.84 raeburn 7987: }
7988: if ($changes{$type}{'machines'}) {
1.69 raeburn 7989: if ($newserverstatus{$type}{'machines'} eq '') {
7990: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
7991: } else {
7992: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
7993: }
7994:
7995: }
7996: $resulttext .= '</ul></li>';
7997: }
7998: }
7999: $resulttext .= '</ul>';
8000: } else {
8001: $resulttext = '<span class="LC_error">'.
8002: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
8003:
8004: }
8005: } else {
8006: $resulttext = &mt('No changes made to access to server status pages');
8007: }
8008: return $resulttext;
8009: }
8010:
1.118 jms 8011: sub modify_helpsettings {
1.122 jms 8012: my ($r,$dom,$confname,%domconfig) = @_;
1.166 raeburn 8013: my ($resulttext,$errors,%changes,%helphash);
8014: my %defaultchecked = ('submitbugs' => 'on');
8015: my @offon = ('off','on');
1.118 jms 8016: my @toggles = ('submitbugs');
8017: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
8018: foreach my $item (@toggles) {
1.166 raeburn 8019: if ($defaultchecked{$item} eq 'on') {
8020: if ($domconfig{'helpsettings'}{$item} eq '') {
8021: if ($env{'form.'.$item} eq '0') {
8022: $changes{$item} = 1;
8023: }
8024: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8025: $changes{$item} = 1;
8026: }
8027: } elsif ($defaultchecked{$item} eq 'off') {
8028: if ($domconfig{'helpsettings'}{$item} eq '') {
8029: if ($env{'form.'.$item} eq '1') {
8030: $changes{$item} = 1;
8031: }
8032: } elsif ($domconfig{'helpsettings'}{$item} ne $env{'form.'.$item}) {
8033: $changes{$item} = 1;
8034: }
8035: }
1.210 raeburn 8036: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
1.166 raeburn 8037: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
8038: }
8039: }
1.118 jms 8040: }
1.123 jms 8041: my $putresult;
8042: if (keys(%changes) > 0) {
1.166 raeburn 8043: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
1.168 raeburn 8044: if ($putresult eq 'ok') {
1.166 raeburn 8045: $resulttext = &mt('Changes made:').'<ul>';
8046: foreach my $item (sort(keys(%changes))) {
8047: if ($item eq 'submitbugs') {
8048: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
8049: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
8050: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
8051: }
8052: }
8053: $resulttext .= '</ul>';
8054: } else {
8055: $resulttext = &mt('No changes made to help settings');
1.168 raeburn 8056: $errors .= '<li><span class="LC_error">'.
8057: &mt('An error occurred storing the settings: [_1]',
8058: $putresult).'</span></li>';
1.166 raeburn 8059: }
1.118 jms 8060: }
8061: if ($errors) {
1.168 raeburn 8062: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.118 jms 8063: $errors.'</ul>';
8064: }
8065: return $resulttext;
8066: }
8067:
1.121 raeburn 8068: sub modify_coursedefaults {
1.212 ! raeburn 8069: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 8070: my ($resulttext,$errors,%changes,%defaultshash);
8071: my %defaultchecked = ('canuse_pdfforms' => 'off');
8072: my @toggles = ('canuse_pdfforms');
1.198 raeburn 8073: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
8074: 'uploadquota_community');
8075: my @types = ('official','unofficial','community');
8076: my %staticdefaults = (
8077: anonsurvey_threshold => 10,
8078: uploadquota => 500,
8079: );
1.121 raeburn 8080:
8081: $defaultshash{'coursedefaults'} = {};
8082:
8083: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
8084: if ($domconfig{'coursedefaults'} eq '') {
8085: $domconfig{'coursedefaults'} = {};
8086: }
8087: }
8088:
8089: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
8090: foreach my $item (@toggles) {
8091: if ($defaultchecked{$item} eq 'on') {
8092: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8093: ($env{'form.'.$item} eq '0')) {
8094: $changes{$item} = 1;
1.192 raeburn 8095: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 8096: $changes{$item} = 1;
8097: }
8098: } elsif ($defaultchecked{$item} eq 'off') {
8099: if (($domconfig{'coursedefaults'}{$item} eq '') &&
8100: ($env{'form.'.$item} eq '1')) {
8101: $changes{$item} = 1;
8102: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
8103: $changes{$item} = 1;
8104: }
8105: }
8106: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
8107: }
1.198 raeburn 8108: foreach my $item (@numbers) {
8109: my ($currdef,$newdef);
1.208 raeburn 8110: $newdef = $env{'form.'.$item};
1.198 raeburn 8111: if ($item eq 'anonsurvey_threshold') {
8112: $currdef = $domconfig{'coursedefaults'}{$item};
8113: $newdef =~ s/\D//g;
8114: if ($newdef eq '' || $newdef < 1) {
8115: $newdef = 1;
8116: }
8117: $defaultshash{'coursedefaults'}{$item} = $newdef;
8118: } else {
8119: my ($type) = ($item =~ /^\Quploadquota_\E(\w+)$/);
8120: if (ref($domconfig{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8121: $currdef = $domconfig{'coursedefaults'}{'uploadquota'}{$type};
8122: }
8123: $newdef =~ s/[^\w.\-]//g;
8124: $defaultshash{'coursedefaults'}{'uploadquota'}{$type} = $newdef;
8125: }
8126: if ($currdef ne $newdef) {
8127: my $staticdef;
8128: if ($item eq 'anonsurvey_threshold') {
8129: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
8130: $changes{$item} = 1;
8131: }
8132: } else {
8133: unless (($currdef eq '') && ($newdef == $staticdefaults{'uploadquota'})) {
8134: $changes{'uploadquota'} = 1;
8135: }
8136: }
1.139 raeburn 8137: }
8138: }
1.192 raeburn 8139: my $officialcreds = $env{'form.official_credits'};
8140: $officialcreds =~ s/^[^\d\.]//g;
8141: my $unofficialcreds = $env{'form.unofficial_credits'};
8142: $unofficialcreds =~ s/^[^\d\.]//g;
8143: if (ref($domconfig{'coursedefaults'}{'coursecredits'} ne 'HASH') &&
8144: ($env{'form.coursecredits'} eq '1')) {
8145: $changes{'coursecredits'} = 1;
8146: } else {
8147: if (($domconfig{'coursedefaults'}{'coursecredits'}{'official'} ne $officialcreds) ||
8148: ($domconfig{'coursedefaults'}{'coursecredits'}{'unofficial'} ne $unofficialcreds)) {
8149: $changes{'coursecredits'} = 1;
8150: }
8151: }
8152: $defaultshash{'coursedefaults'}{'coursecredits'} = {
8153: official => $officialcreds,
8154: unofficial => $unofficialcreds,
8155: }
1.121 raeburn 8156: }
8157: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8158: $dom);
8159: if ($putresult eq 'ok') {
8160: if (keys(%changes) > 0) {
1.212 ! raeburn 8161: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.198 raeburn 8162: if (($changes{'canuse_pdfforms'}) || ($changes{'coursecredits'}) || ($changes{'uploadquota'})) {
1.192 raeburn 8163: if ($changes{'canuse_pdfforms'}) {
8164: $domdefaults{'canuse_pdfforms'}=$defaultshash{'coursedefaults'}{'canuse_pdfforms'};
8165: }
8166: if ($changes{'coursecredits'}) {
8167: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8168: $domdefaults{'officialcredits'} =
8169: $defaultshash{'coursedefaults'}{'coursecredits'}{'official'};
8170: $domdefaults{'unofficialcredits'} =
8171: $defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'};
8172: }
8173: }
1.198 raeburn 8174: if ($changes{'uploadquota'}) {
8175: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8176: foreach my $type (@types) {
8177: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
8178: }
8179: }
8180: }
1.121 raeburn 8181: my $cachetime = 24*60*60;
8182: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 ! raeburn 8183: if (ref($lastactref) eq 'HASH') {
! 8184: $lastactref->{'domdefaults'} = 1;
! 8185: }
1.121 raeburn 8186: }
8187: $resulttext = &mt('Changes made:').'<ul>';
8188: foreach my $item (sort(keys(%changes))) {
8189: if ($item eq 'canuse_pdfforms') {
8190: if ($env{'form.'.$item} eq '1') {
8191: $resulttext .= '<li>'.&mt("Course/Community users can create/upload PDF forms set to 'on'").'</li>';
8192: } else {
8193: $resulttext .= '<li>'.&mt('Course/Community users can create/upload PDF forms set to "off"').'</li>';
8194: }
1.139 raeburn 8195: } elsif ($item eq 'anonsurvey_threshold') {
1.192 raeburn 8196: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.198 raeburn 8197: } elsif ($item eq 'uploadquota') {
8198: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
8199: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
8200: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
8201: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
8202: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
8203: '</ul>'.
8204: '</li>';
8205: } else {
8206: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
8207: }
1.192 raeburn 8208: } elsif ($item eq 'coursecredits') {
8209: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
8210: if (($domdefaults{'officialcredits'} eq '') &&
8211: ($domdefaults{'unofficialcredits'} eq '')) {
8212: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8213: } else {
8214: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
8215: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
8216: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
8217: '</ul>'.
8218: '</li>';
8219: }
8220: } else {
8221: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
8222: }
1.140 raeburn 8223: }
1.121 raeburn 8224: }
8225: $resulttext .= '</ul>';
8226: } else {
8227: $resulttext = &mt('No changes made to course defaults');
8228: }
8229: } else {
8230: $resulttext = '<span class="LC_error">'.
8231: &mt('An error occurred: [_1]',$putresult).'</span>';
8232: }
8233: return $resulttext;
8234: }
8235:
1.137 raeburn 8236: sub modify_usersessions {
1.212 ! raeburn 8237: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 8238: my @hostingtypes = ('version','excludedomain','includedomain');
8239: my @offloadtypes = ('primary','default');
8240: my %types = (
8241: remote => \@hostingtypes,
8242: hosted => \@hostingtypes,
8243: spares => \@offloadtypes,
8244: );
8245: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 8246: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 8247: my (%by_ip,%by_location,@intdoms);
8248: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
8249: my @locations = sort(keys(%by_location));
1.137 raeburn 8250: my (%defaultshash,%changes);
8251: foreach my $prefix (@prefixes) {
8252: $defaultshash{'usersessions'}{$prefix} = {};
8253: }
1.212 ! raeburn 8254: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 8255: my $resulttext;
1.138 raeburn 8256: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 8257: foreach my $prefix (@prefixes) {
1.145 raeburn 8258: next if ($prefix eq 'spares');
8259: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 8260: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
8261: if ($type eq 'version') {
8262: my $value = $env{'form.'.$prefix.'_'.$type};
8263: my $okvalue;
8264: if ($value ne '') {
8265: if (grep(/^\Q$value\E$/,@lcversions)) {
8266: $okvalue = $value;
8267: }
8268: }
8269: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8270: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8271: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
8272: if ($inuse == 0) {
8273: $changes{$prefix}{$type} = 1;
8274: } else {
8275: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
8276: $changes{$prefix}{$type} = 1;
8277: }
8278: if ($okvalue ne '') {
8279: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8280: }
8281: }
8282: } else {
8283: if (($inuse == 1) && ($okvalue ne '')) {
8284: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8285: $changes{$prefix}{$type} = 1;
8286: }
8287: }
8288: } else {
8289: if (($inuse == 1) && ($okvalue ne '')) {
8290: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8291: $changes{$prefix}{$type} = 1;
8292: }
8293: }
8294: } else {
8295: if (($inuse == 1) && ($okvalue ne '')) {
8296: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
8297: $changes{$prefix}{$type} = 1;
8298: }
8299: }
8300: } else {
8301: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
8302: my @okvals;
8303: foreach my $val (@vals) {
1.138 raeburn 8304: if ($val =~ /:/) {
8305: my @items = split(/:/,$val);
8306: foreach my $item (@items) {
8307: if (ref($by_location{$item}) eq 'ARRAY') {
8308: push(@okvals,$item);
8309: }
8310: }
8311: } else {
8312: if (ref($by_location{$val}) eq 'ARRAY') {
8313: push(@okvals,$val);
8314: }
1.137 raeburn 8315: }
8316: }
8317: @okvals = sort(@okvals);
8318: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8319: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
8320: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8321: if ($inuse == 0) {
8322: $changes{$prefix}{$type} = 1;
8323: } else {
8324: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8325: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
8326: if (@changed > 0) {
8327: $changes{$prefix}{$type} = 1;
8328: }
8329: }
8330: } else {
8331: if ($inuse == 1) {
8332: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8333: $changes{$prefix}{$type} = 1;
8334: }
8335: }
8336: } else {
8337: if ($inuse == 1) {
8338: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8339: $changes{$prefix}{$type} = 1;
8340: }
8341: }
8342: } else {
8343: if ($inuse == 1) {
8344: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
8345: $changes{$prefix}{$type} = 1;
8346: }
8347: }
8348: }
8349: }
8350: }
1.145 raeburn 8351:
8352: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 8353: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 8354: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
8355: my $savespares;
8356:
8357: foreach my $lonhost (sort(keys(%servers))) {
8358: my $serverhomeID =
8359: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 8360: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 8361: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
8362: my %spareschg;
8363: foreach my $type (@{$types{'spares'}}) {
8364: my @okspares;
8365: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
8366: foreach my $server (@checked) {
1.152 raeburn 8367: if (&Apache::lonnet::hostname($server) ne '') {
8368: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
8369: unless (grep(/^\Q$server\E$/,@okspares)) {
8370: push(@okspares,$server);
8371: }
1.145 raeburn 8372: }
8373: }
8374: }
8375: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
8376: my $newspare;
1.152 raeburn 8377: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
8378: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 8379: $newspare = $new;
8380: }
8381: }
1.152 raeburn 8382: my @spares;
8383: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
8384: @spares = sort(@okspares,$newspare);
8385: } else {
8386: @spares = sort(@okspares);
8387: }
8388: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 8389: if (ref($spareid{$lonhost}) eq 'HASH') {
8390: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 8391: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 8392: if (@diffs > 0) {
8393: $spareschg{$type} = 1;
8394: }
8395: }
8396: }
8397: }
8398: if (keys(%spareschg) > 0) {
8399: $changes{'spares'}{$lonhost} = \%spareschg;
8400: }
8401: }
8402:
8403: if (ref($domconfig{'usersessions'}) eq 'HASH') {
8404: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
8405: if (ref($changes{'spares'}) eq 'HASH') {
8406: if (keys(%{$changes{'spares'}}) > 0) {
8407: $savespares = 1;
8408: }
8409: }
8410: } else {
8411: $savespares = 1;
8412: }
8413: }
8414:
1.147 raeburn 8415: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
8416: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 8417: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
8418: $dom);
8419: if ($putresult eq 'ok') {
8420: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8421: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
8422: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
8423: }
8424: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
8425: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
8426: }
8427: }
8428: my $cachetime = 24*60*60;
8429: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.212 ! raeburn 8430: if (ref($lastactref) eq 'HASH') {
! 8431: $lastactref->{'domdefaults'} = 1;
! 8432: }
1.147 raeburn 8433: if (keys(%changes) > 0) {
8434: my %lt = &usersession_titles();
8435: $resulttext = &mt('Changes made:').'<ul>';
8436: foreach my $prefix (@prefixes) {
8437: if (ref($changes{$prefix}) eq 'HASH') {
8438: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
8439: if ($prefix eq 'spares') {
8440: if (ref($changes{$prefix}) eq 'HASH') {
8441: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
8442: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 8443: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.211 raeburn 8444: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
8445: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 8446: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
8447: foreach my $type (@{$types{$prefix}}) {
8448: if ($changes{$prefix}{$lonhost}{$type}) {
8449: my $offloadto = &mt('None');
8450: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
8451: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
8452: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
8453: }
1.145 raeburn 8454: }
1.147 raeburn 8455: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 8456: }
1.137 raeburn 8457: }
8458: }
1.147 raeburn 8459: $resulttext .= '</li>';
1.137 raeburn 8460: }
8461: }
1.147 raeburn 8462: } else {
8463: foreach my $type (@{$types{$prefix}}) {
8464: if (defined($changes{$prefix}{$type})) {
8465: my $newvalue;
8466: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
8467: if (ref($defaultshash{'usersessions'}{$prefix})) {
8468: if ($type eq 'version') {
8469: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
8470: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
8471: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
8472: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
8473: }
1.145 raeburn 8474: }
8475: }
8476: }
1.147 raeburn 8477: if ($newvalue eq '') {
8478: if ($type eq 'version') {
8479: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
8480: } else {
8481: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
8482: }
1.145 raeburn 8483: } else {
1.147 raeburn 8484: if ($type eq 'version') {
8485: $newvalue .= ' '.&mt('(or later)');
8486: }
8487: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 8488: }
1.137 raeburn 8489: }
8490: }
8491: }
1.147 raeburn 8492: $resulttext .= '</ul>';
1.137 raeburn 8493: }
8494: }
1.147 raeburn 8495: $resulttext .= '</ul>';
8496: } else {
8497: $resulttext = $nochgmsg;
1.137 raeburn 8498: }
8499: } else {
8500: $resulttext = '<span class="LC_error">'.
8501: &mt('An error occurred: [_1]',$putresult).'</span>';
8502: }
8503: } else {
1.147 raeburn 8504: $resulttext = $nochgmsg;
1.137 raeburn 8505: }
8506: return $resulttext;
8507: }
8508:
1.150 raeburn 8509: sub modify_loadbalancing {
8510: my ($dom,%domconfig) = @_;
8511: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8512: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8513: my ($othertitle,$usertypes,$types) =
8514: &Apache::loncommon::sorted_inst_types($dom);
8515: my %servers = &Apache::lonnet::internet_dom_servers($dom);
8516: my @sparestypes = ('primary','default');
8517: my %typetitles = &sparestype_titles();
8518: my $resulttext;
1.171 raeburn 8519: my (%currbalancer,%currtargets,%currrules,%existing);
8520: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8521: %existing = %{$domconfig{'loadbalancing'}};
8522: }
8523: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
8524: \%currtargets,\%currrules);
8525: my ($saveloadbalancing,%defaultshash,%changes);
8526: my ($alltypes,$othertypes,$titles) =
8527: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8528: my %ruletitles = &offloadtype_text();
8529: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
8530: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
8531: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
8532: if ($balancer eq '') {
8533: next;
8534: }
1.210 raeburn 8535: if (!exists($servers{$balancer})) {
1.171 raeburn 8536: if (exists($currbalancer{$balancer})) {
8537: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 8538: }
1.171 raeburn 8539: next;
8540: }
8541: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
8542: push(@{$changes{'delete'}},$balancer);
8543: next;
8544: }
8545: if (!exists($currbalancer{$balancer})) {
8546: push(@{$changes{'add'}},$balancer);
8547: }
8548: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
8549: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
8550: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
8551: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
8552: $saveloadbalancing = 1;
8553: }
8554: foreach my $sparetype (@sparestypes) {
8555: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
8556: my @offloadto;
8557: foreach my $target (@targets) {
8558: if (($servers{$target}) && ($target ne $balancer)) {
8559: if ($sparetype eq 'default') {
8560: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
8561: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 8562: }
8563: }
1.171 raeburn 8564: unless(grep(/^\Q$target\E$/,@offloadto)) {
8565: push(@offloadto,$target);
8566: }
1.150 raeburn 8567: }
1.171 raeburn 8568: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 8569: }
8570: }
1.171 raeburn 8571: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 8572: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8573: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
8574: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 8575: if (@targetdiffs > 0) {
1.171 raeburn 8576: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8577: }
1.171 raeburn 8578: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8579: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8580: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 8581: }
8582: }
8583: }
8584: } else {
1.171 raeburn 8585: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
1.210 raeburn 8586: foreach my $sparetype (@sparestypes) {
1.171 raeburn 8587: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8588: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8589: $changes{'curr'}{$balancer}{'targets'} = 1;
8590: }
1.150 raeburn 8591: }
8592: }
1.210 raeburn 8593: }
1.150 raeburn 8594: }
8595: my $ishomedom;
1.171 raeburn 8596: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
8597: $ishomedom = 1;
1.150 raeburn 8598: }
8599: if (ref($alltypes) eq 'ARRAY') {
8600: foreach my $type (@{$alltypes}) {
8601: my $rule;
1.210 raeburn 8602: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 8603: (!$ishomedom)) {
1.171 raeburn 8604: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
8605: }
8606: if ($rule eq 'specific') {
8607: $rule = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
1.150 raeburn 8608: }
1.171 raeburn 8609: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
8610: if (ref($currrules{$balancer}) eq 'HASH') {
8611: if ($rule ne $currrules{$balancer}{$type}) {
8612: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8613: }
8614: } elsif ($rule ne '') {
1.171 raeburn 8615: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 8616: }
8617: }
8618: }
1.171 raeburn 8619: }
8620: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
8621: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
8622: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
8623: $defaultshash{'loadbalancing'} = {};
8624: }
8625: my $putresult = &Apache::lonnet::put_dom('configuration',
8626: \%defaultshash,$dom);
8627: if ($putresult eq 'ok') {
8628: if (keys(%changes) > 0) {
8629: if (ref($changes{'delete'}) eq 'ARRAY') {
8630: foreach my $balancer (sort(@{$changes{'delete'}})) {
8631: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.211 raeburn 8632: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
8633: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 8634: }
1.171 raeburn 8635: }
8636: if (ref($changes{'add'}) eq 'ARRAY') {
1.210 raeburn 8637: foreach my $balancer (sort(@{$changes{'add'}})) {
1.171 raeburn 8638: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
8639: }
8640: }
8641: if (ref($changes{'curr'}) eq 'HASH') {
8642: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
8643: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
8644: if ($changes{'curr'}{$balancer}{'targets'}) {
8645: my %offloadstr;
8646: foreach my $sparetype (@sparestypes) {
8647: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
8648: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
8649: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
8650: }
8651: }
1.150 raeburn 8652: }
1.171 raeburn 8653: if (keys(%offloadstr) == 0) {
8654: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 8655: } else {
1.171 raeburn 8656: my $showoffload;
8657: foreach my $sparetype (@sparestypes) {
8658: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
8659: if (defined($offloadstr{$sparetype})) {
8660: $showoffload .= $offloadstr{$sparetype};
8661: } else {
8662: $showoffload .= &mt('None');
8663: }
8664: $showoffload .= (' 'x3);
8665: }
8666: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 8667: }
8668: }
8669: }
1.171 raeburn 8670: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
8671: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8672: foreach my $type (@{$alltypes}) {
8673: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
8674: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
8675: my $balancetext;
8676: if ($rule eq '') {
8677: $balancetext = $ruletitles{'default'};
1.209 raeburn 8678: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
8679: ($rule eq 'balancer') || ($rule eq 'offloadedto')) {
1.171 raeburn 8680: $balancetext = $ruletitles{$rule};
8681: } else {
8682: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
8683: }
1.210 raeburn 8684: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 8685: }
8686: }
8687: }
8688: }
1.211 raeburn 8689: my $cachekey = &scape('loadbalancing').':'.&escape($dom);
8690: &Apache::lonnet::remote_devalidate_cache($balancer,[$cachekey]);
1.150 raeburn 8691: }
1.171 raeburn 8692: }
8693: if ($resulttext ne '') {
8694: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 8695: } else {
8696: $resulttext = $nochgmsg;
8697: }
8698: } else {
1.171 raeburn 8699: $resulttext = $nochgmsg;
1.150 raeburn 8700: }
8701: } else {
1.171 raeburn 8702: $resulttext = '<span class="LC_error">'.
8703: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 8704: }
8705: } else {
1.171 raeburn 8706: $resulttext = $nochgmsg;
1.150 raeburn 8707: }
8708: return $resulttext;
8709: }
8710:
1.48 raeburn 8711: sub recurse_check {
8712: my ($chkcats,$categories,$depth,$name) = @_;
8713: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
8714: my $chg = 0;
8715: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
8716: my $category = $chkcats->[$depth]{$name}[$j];
8717: my $item;
8718: if ($category eq '') {
8719: $chg ++;
8720: } else {
8721: my $deeper = $depth + 1;
8722: $item = &escape($category).':'.&escape($name).':'.$depth;
8723: if ($chg) {
8724: $categories->{$item} -= $chg;
8725: }
8726: &recurse_check($chkcats,$categories,$deeper,$category);
8727: $deeper --;
8728: }
8729: }
8730: }
8731: return;
8732: }
8733:
8734: sub recurse_cat_deletes {
8735: my ($item,$coursecategories,$deletions) = @_;
8736: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
8737: my $subdepth = $depth + 1;
8738: if (ref($coursecategories) eq 'HASH') {
8739: foreach my $subitem (keys(%{$coursecategories})) {
8740: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
8741: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
8742: delete($coursecategories->{$subitem});
8743: $deletions->{$subitem} = 1;
8744: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.168 raeburn 8745: }
1.48 raeburn 8746: }
8747: }
8748: return;
8749: }
8750:
1.125 raeburn 8751: sub get_active_dcs {
8752: my ($dom) = @_;
1.191 raeburn 8753: my $now = time;
8754: my %dompersonnel = &Apache::lonnet::get_domain_roles($dom,['dc'],$now,$now);
1.125 raeburn 8755: my %domcoords;
8756: my $numdcs = 0;
8757: foreach my $server (keys(%dompersonnel)) {
8758: foreach my $user (sort(keys(%{$dompersonnel{$server}}))) {
8759: my ($trole,$uname,$udom,$runame,$rudom,$rsec) = split(/:/,$user);
1.191 raeburn 8760: $domcoords{$uname.':'.$udom} = $dompersonnel{$server}{$user};
1.125 raeburn 8761: }
8762: }
8763: return %domcoords;
8764: }
8765:
8766: sub active_dc_picker {
1.191 raeburn 8767: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.125 raeburn 8768: my %domcoords = &get_active_dcs($dom);
1.191 raeburn 8769: my @domcoord = keys(%domcoords);
8770: if (keys(%currhash)) {
8771: foreach my $dc (keys(%currhash)) {
8772: unless (exists($domcoords{$dc})) {
8773: push(@domcoord,$dc);
8774: }
8775: }
8776: }
8777: @domcoord = sort(@domcoord);
1.210 raeburn 8778: my $numdcs = scalar(@domcoord);
1.191 raeburn 8779: my $rows = 0;
8780: my $table;
1.125 raeburn 8781: if ($numdcs > 1) {
1.191 raeburn 8782: $table = '<table>';
8783: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 8784: my $rem = $i%($numinrow);
8785: if ($rem == 0) {
8786: if ($i > 0) {
1.191 raeburn 8787: $table .= '</tr>';
1.125 raeburn 8788: }
1.191 raeburn 8789: $table .= '<tr>';
8790: $rows ++;
1.125 raeburn 8791: }
1.191 raeburn 8792: my $check = '';
8793: if ($inputtype eq 'radio') {
8794: if (keys(%currhash) == 0) {
8795: if (!$i) {
8796: $check = ' checked="checked"';
8797: }
8798: } elsif (exists($currhash{$domcoord[$i]})) {
8799: $check = ' checked="checked"';
8800: }
8801: } else {
8802: if (exists($currhash{$domcoord[$i]})) {
8803: $check = ' checked="checked"';
1.125 raeburn 8804: }
8805: }
1.191 raeburn 8806: if ($i == @domcoord - 1) {
1.125 raeburn 8807: my $colsleft = $numinrow - $rem;
8808: if ($colsleft > 1) {
1.191 raeburn 8809: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 8810: } else {
1.191 raeburn 8811: $table .= '<td class="LC_left_item">';
1.125 raeburn 8812: }
8813: } else {
1.191 raeburn 8814: $table .= '<td class="LC_left_item">';
8815: }
8816: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
8817: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
8818: $table .= '<span class="LC_nobreak"><label>'.
8819: '<input type="'.$inputtype.'" name="'.$name.'"'.
8820: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
8821: if ($user ne $dcname.':'.$dcdom) {
8822: $table .= ' ('.$dcname.':'.$dcdom.')'.
8823: '</label></span></td>';
8824: }
8825: }
8826: $table .= '</tr></table>';
8827: } elsif ($numdcs == 1) {
8828: if ($inputtype eq 'radio') {
8829: $table .= '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />';
8830: } else {
8831: my $check;
8832: if (exists($currhash{$domcoord[0]})) {
8833: $check = ' checked="checked"';
1.125 raeburn 8834: }
1.191 raeburn 8835: $table .= '<input type="checkbox" name="'.$name.'" '.
8836: 'value="'.$domcoord[0].'"'.$check.' />';
8837: $rows ++;
1.125 raeburn 8838: }
8839: }
1.191 raeburn 8840: return ($numdcs,$table,$rows);
1.125 raeburn 8841: }
8842:
1.137 raeburn 8843: sub usersession_titles {
8844: return &Apache::lonlocal::texthash(
8845: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
8846: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 8847: spares => 'Servers offloaded to, when busy',
1.137 raeburn 8848: version => 'LON-CAPA version requirement',
1.138 raeburn 8849: excludedomain => 'Allow all, but exclude specific domains',
8850: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 8851: primary => 'Primary (checked first)',
1.154 raeburn 8852: default => 'Default',
1.137 raeburn 8853: );
8854: }
8855:
1.152 raeburn 8856: sub id_for_thisdom {
8857: my (%servers) = @_;
8858: my %altids;
8859: foreach my $server (keys(%servers)) {
8860: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
8861: if ($serverhome ne $server) {
8862: $altids{$serverhome} = $server;
8863: }
8864: }
8865: return %altids;
8866: }
8867:
1.150 raeburn 8868: sub count_servers {
8869: my ($currbalancer,%servers) = @_;
8870: my (@spares,$numspares);
8871: foreach my $lonhost (sort(keys(%servers))) {
8872: next if ($currbalancer eq $lonhost);
8873: push(@spares,$lonhost);
8874: }
8875: if ($currbalancer) {
8876: $numspares = scalar(@spares);
8877: } else {
8878: $numspares = scalar(@spares) - 1;
8879: }
8880: return ($numspares,@spares);
8881: }
8882:
8883: sub lonbalance_targets_js {
1.171 raeburn 8884: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 8885: my $select = &mt('Select');
8886: my ($alltargets,$allishome,$allinsttypes,@alltypes);
8887: if (ref($servers) eq 'HASH') {
8888: $alltargets = join("','",sort(keys(%{$servers})));
8889: my @homedoms;
8890: foreach my $server (sort(keys(%{$servers}))) {
8891: if (&Apache::lonnet::host_domain($server) eq $dom) {
8892: push(@homedoms,'1');
8893: } else {
8894: push(@homedoms,'0');
8895: }
8896: }
8897: $allishome = join("','",@homedoms);
8898: }
8899: if (ref($types) eq 'ARRAY') {
8900: if (@{$types} > 0) {
8901: @alltypes = @{$types};
8902: }
8903: }
8904: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
8905: $allinsttypes = join("','",@alltypes);
1.171 raeburn 8906: my (%currbalancer,%currtargets,%currrules,%existing);
8907: if (ref($settings) eq 'HASH') {
8908: %existing = %{$settings};
8909: }
8910: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
8911: \%currtargets,\%currrules);
1.210 raeburn 8912: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 8913: return <<"END";
8914:
8915: <script type="text/javascript">
8916: // <![CDATA[
8917:
1.171 raeburn 8918: currBalancers = new Array('$balancers');
8919:
8920: function toggleTargets(balnum) {
8921: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
8922: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
8923: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
8924: var prevbalancer = prevhostitem.value;
8925: var baltotal = document.getElementById('loadbalancing_total').value;
8926: prevhostitem.value = balancer;
8927: if (prevbalancer != '') {
8928: var prevIdx = currBalancers.indexOf(prevbalancer);
8929: if (prevIdx != -1) {
8930: currBalancers.splice(prevIdx,1);
8931: }
8932: }
1.150 raeburn 8933: if (balancer == '') {
1.171 raeburn 8934: hideSpares(balnum);
1.150 raeburn 8935: } else {
1.171 raeburn 8936: var currIdx = currBalancers.indexOf(balancer);
8937: if (currIdx == -1) {
8938: currBalancers.push(balancer);
8939: }
1.150 raeburn 8940: var homedoms = new Array('$allishome');
1.171 raeburn 8941: var ishomedom = homedoms[lonhostitem.selectedIndex];
8942: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 8943: }
1.171 raeburn 8944: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 8945: return;
8946: }
8947:
1.171 raeburn 8948: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 8949: var alltargets = new Array('$alltargets');
8950: var insttypes = new Array('$allinsttypes');
1.151 raeburn 8951: var offloadtypes = new Array('primary','default');
8952:
1.171 raeburn 8953: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
8954: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 8955:
1.151 raeburn 8956: for (var i=0; i<offloadtypes.length; i++) {
8957: var count = 0;
8958: for (var j=0; j<alltargets.length; j++) {
8959: if (alltargets[j] != balancer) {
1.171 raeburn 8960: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
8961: item.value = alltargets[j];
8962: item.style.textAlign='left';
8963: item.style.textFace='normal';
8964: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
8965: if (currBalancers.indexOf(alltargets[j]) == -1) {
8966: item.disabled = '';
8967: } else {
8968: item.disabled = 'disabled';
8969: item.checked = false;
8970: }
1.151 raeburn 8971: count ++;
8972: }
1.150 raeburn 8973: }
8974: }
1.151 raeburn 8975: for (var k=0; k<insttypes.length; k++) {
8976: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 8977: if (ishomedom == 1) {
1.171 raeburn 8978: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8979: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8980: } else {
1.171 raeburn 8981: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
8982: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 8983: }
8984: } else {
1.171 raeburn 8985: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
8986: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 8987: }
1.151 raeburn 8988: if ((insttypes[k] != '_LC_external') &&
8989: ((insttypes[k] != '_LC_internetdom') ||
8990: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.171 raeburn 8991: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
8992: item.options.length = 0;
8993: item.options[0] = new Option("","",true,true);
1.210 raeburn 8994: var idx = 0;
1.151 raeburn 8995: for (var m=0; m<alltargets.length; m++) {
1.171 raeburn 8996: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
8997: idx ++;
8998: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 8999: }
9000: }
9001: }
9002: }
9003: return;
9004: }
9005:
1.171 raeburn 9006: function hideSpares(balnum) {
1.150 raeburn 9007: var alltargets = new Array('$alltargets');
9008: var insttypes = new Array('$allinsttypes');
9009: var offloadtypes = new Array('primary','default');
9010:
1.171 raeburn 9011: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
9012: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 9013:
9014: var total = alltargets.length - 1;
9015: for (var i=0; i<offloadtypes; i++) {
9016: for (var j=0; j<total; j++) {
1.171 raeburn 9017: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
9018: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
9019: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 9020: }
1.150 raeburn 9021: }
9022: for (var k=0; k<insttypes.length; k++) {
1.171 raeburn 9023: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
9024: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 9025: if (insttypes[k] != '_LC_external') {
1.171 raeburn 9026: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
9027: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 9028: }
9029: }
9030: return;
9031: }
9032:
1.171 raeburn 9033: function checkOffloads(item,balnum,type) {
1.150 raeburn 9034: var alltargets = new Array('$alltargets');
9035: var offloadtypes = new Array('primary','default');
9036: if (item.checked) {
9037: var total = alltargets.length - 1;
9038: var other;
9039: if (type == offloadtypes[0]) {
1.151 raeburn 9040: other = offloadtypes[1];
1.150 raeburn 9041: } else {
1.151 raeburn 9042: other = offloadtypes[0];
1.150 raeburn 9043: }
9044: for (var i=0; i<total; i++) {
1.171 raeburn 9045: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 9046: if (server == item.value) {
1.171 raeburn 9047: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
9048: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 9049: }
9050: }
9051: }
9052: }
9053: return;
9054: }
9055:
1.171 raeburn 9056: function singleServerToggle(balnum,type) {
9057: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 9058: if (offloadtoSelIdx == 0) {
1.171 raeburn 9059: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
9060: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9061:
9062: } else {
1.171 raeburn 9063: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
9064: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 9065: }
9066: return;
9067: }
9068:
1.171 raeburn 9069: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 9070: if (type == '_LC_external') {
1.171 raeburn 9071: return;
1.150 raeburn 9072: }
1.171 raeburn 9073: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 9074: for (var i=0; i<typesRules.length; i++) {
9075: if (formname.elements[typesRules[i]].checked) {
9076: if (formname.elements[typesRules[i]].value != 'specific') {
1.171 raeburn 9077: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
9078: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 9079: } else {
1.171 raeburn 9080: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
9081: }
9082: }
9083: }
9084: return;
9085: }
9086:
9087: function balancerDeleteChange(balnum) {
9088: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
9089: var baltotal = document.getElementById('loadbalancing_total').value;
9090: var addtarget;
9091: var removetarget;
9092: var action = 'delete';
9093: if (document.getElementById('loadbalancing_delete_'+balnum)) {
9094: var lonhost = hostitem.value;
9095: var currIdx = currBalancers.indexOf(lonhost);
9096: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
9097: if (currIdx != -1) {
9098: currBalancers.splice(currIdx,1);
9099: }
9100: addtarget = lonhost;
9101: } else {
9102: if (currIdx == -1) {
9103: currBalancers.push(lonhost);
9104: }
9105: removetarget = lonhost;
9106: action = 'undelete';
9107: }
9108: balancerChange(balnum,baltotal,action,addtarget,removetarget);
9109: }
9110: return;
9111: }
9112:
9113: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
9114: if (baltotal > 1) {
9115: var offloadtypes = new Array('primary','default');
9116: var alltargets = new Array('$alltargets');
9117: var insttypes = new Array('$allinsttypes');
9118: for (var i=0; i<baltotal; i++) {
9119: if (i != balnum) {
9120: for (var j=0; j<offloadtypes.length; j++) {
9121: var total = alltargets.length - 1;
9122: for (var k=0; k<total; k++) {
9123: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
9124: var server = serveritem.value;
9125: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9126: if (server == addtarget) {
9127: serveritem.disabled = '';
9128: }
9129: }
9130: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9131: if (server == removetarget) {
9132: serveritem.disabled = 'disabled';
9133: serveritem.checked = false;
9134: }
9135: }
9136: }
9137: }
9138: for (var j=0; j<insttypes.length; j++) {
9139: if (insttypes[j] != '_LC_external') {
9140: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
9141: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
9142: var currSel = singleserver.selectedIndex;
9143: var currVal = singleserver.options[currSel].value;
9144: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
9145: var numoptions = singleserver.options.length;
9146: var needsnew = 1;
9147: for (var k=0; k<numoptions; k++) {
9148: if (singleserver.options[k] == addtarget) {
9149: needsnew = 0;
9150: break;
9151: }
9152: }
9153: if (needsnew == 1) {
9154: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
9155: }
9156: }
9157: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
9158: singleserver.options.length = 0;
9159: if ((currVal) && (currVal != removetarget)) {
9160: singleserver.options[0] = new Option("","",false,false);
9161: } else {
9162: singleserver.options[0] = new Option("","",true,true);
9163: }
9164: var idx = 0;
9165: for (var m=0; m<alltargets.length; m++) {
9166: if (currBalancers.indexOf(alltargets[m]) == -1) {
9167: idx ++;
9168: if (currVal == alltargets[m]) {
9169: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
9170: } else {
9171: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
9172: }
9173: }
9174: }
9175: }
9176: }
9177: }
9178: }
1.150 raeburn 9179: }
9180: }
9181: }
9182: return;
9183: }
9184:
1.152 raeburn 9185: // ]]>
9186: </script>
9187:
9188: END
9189: }
9190:
9191: sub new_spares_js {
9192: my @sparestypes = ('primary','default');
9193: my $types = join("','",@sparestypes);
9194: my $select = &mt('Select');
9195: return <<"END";
9196:
9197: <script type="text/javascript">
9198: // <![CDATA[
9199:
9200: function updateNewSpares(formname,lonhost) {
9201: var types = new Array('$types');
9202: var include = new Array();
9203: var exclude = new Array();
9204: for (var i=0; i<types.length; i++) {
9205: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
9206: for (var j=0; j<spareboxes.length; j++) {
9207: if (formname.elements[spareboxes[j]].checked) {
9208: exclude.push(formname.elements[spareboxes[j]].value);
9209: } else {
9210: include.push(formname.elements[spareboxes[j]].value);
9211: }
9212: }
9213: }
9214: for (var i=0; i<types.length; i++) {
9215: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
9216: var selIdx = newSpare.selectedIndex;
9217: var currnew = newSpare.options[selIdx].value;
9218: var okSpares = new Array();
9219: for (var j=0; j<newSpare.options.length; j++) {
9220: var possible = newSpare.options[j].value;
9221: if (possible != '') {
9222: if (exclude.indexOf(possible) == -1) {
9223: okSpares.push(possible);
9224: } else {
9225: if (currnew == possible) {
9226: selIdx = 0;
9227: }
9228: }
9229: }
9230: }
9231: for (var k=0; k<include.length; k++) {
9232: if (okSpares.indexOf(include[k]) == -1) {
9233: okSpares.push(include[k]);
9234: }
9235: }
9236: okSpares.sort();
9237: newSpare.options.length = 0;
9238: if (selIdx == 0) {
9239: newSpare.options[0] = new Option("$select","",true,true);
9240: } else {
9241: newSpare.options[0] = new Option("$select","",false,false);
9242: }
9243: for (var m=0; m<okSpares.length; m++) {
9244: var idx = m+1;
9245: var selThis = 0;
9246: if (selIdx != 0) {
9247: if (okSpares[m] == currnew) {
9248: selThis = 1;
9249: }
9250: }
9251: if (selThis == 1) {
9252: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
9253: } else {
9254: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
9255: }
9256: }
9257: }
9258: return;
9259: }
9260:
9261: function checkNewSpares(lonhost,type) {
9262: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
9263: var chosen = newSpare.options[newSpare.selectedIndex].value;
9264: if (chosen != '') {
9265: var othertype;
9266: var othernewSpare;
9267: if (type == 'primary') {
9268: othernewSpare = document.getElementById('newspare_default_'+lonhost);
9269: }
9270: if (type == 'default') {
9271: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
9272: }
9273: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
9274: othernewSpare.selectedIndex = 0;
9275: }
9276: }
9277: return;
9278: }
9279:
9280: // ]]>
9281: </script>
9282:
9283: END
9284:
9285: }
9286:
9287: sub common_domprefs_js {
9288: return <<"END";
9289:
9290: <script type="text/javascript">
9291: // <![CDATA[
9292:
1.150 raeburn 9293: function getIndicesByName(formname,item) {
1.152 raeburn 9294: var group = new Array();
1.150 raeburn 9295: for (var i=0;i<formname.elements.length;i++) {
9296: if (formname.elements[i].name == item) {
1.152 raeburn 9297: group.push(formname.elements[i].id);
1.150 raeburn 9298: }
9299: }
1.152 raeburn 9300: return group;
1.150 raeburn 9301: }
9302:
9303: // ]]>
9304: </script>
9305:
9306: END
1.152 raeburn 9307:
1.150 raeburn 9308: }
9309:
1.165 raeburn 9310: sub recaptcha_js {
9311: my %lt = &captcha_phrases();
9312: return <<"END";
9313:
9314: <script type="text/javascript">
9315: // <![CDATA[
9316:
9317: function updateCaptcha(caller,context) {
9318: var privitem;
9319: var pubitem;
9320: var privtext;
9321: var pubtext;
9322: if (document.getElementById(context+'_recaptchapub')) {
9323: pubitem = document.getElementById(context+'_recaptchapub');
9324: } else {
9325: return;
9326: }
9327: if (document.getElementById(context+'_recaptchapriv')) {
9328: privitem = document.getElementById(context+'_recaptchapriv');
9329: } else {
9330: return;
9331: }
9332: if (document.getElementById(context+'_recaptchapubtxt')) {
9333: pubtext = document.getElementById(context+'_recaptchapubtxt');
9334: } else {
9335: return;
9336: }
9337: if (document.getElementById(context+'_recaptchaprivtxt')) {
9338: privtext = document.getElementById(context+'_recaptchaprivtxt');
9339: } else {
9340: return;
9341: }
9342: if (caller.checked) {
9343: if (caller.value == 'recaptcha') {
9344: pubitem.type = 'text';
9345: privitem.type = 'text';
9346: pubitem.size = '40';
9347: privitem.size = '40';
9348: pubtext.innerHTML = "$lt{'pub'}";
9349: privtext.innerHTML = "$lt{'priv'}";
9350: } else {
9351: pubitem.type = 'hidden';
9352: privitem.type = 'hidden';
9353: pubtext.innerHTML = '';
9354: privtext.innerHTML = '';
9355: }
9356: }
9357: return;
9358: }
9359:
9360: // ]]>
9361: </script>
9362:
9363: END
9364:
9365: }
9366:
1.192 raeburn 9367: sub credits_js {
9368: return <<"END";
9369:
9370: <script type="text/javascript">
9371: // <![CDATA[
9372:
9373: function toggleCredits(domForm) {
9374: if (document.getElementById('credits')) {
9375: creditsitem = document.getElementById('credits');
9376: var creditsLength = domForm.coursecredits.length;
9377: if (creditsLength) {
9378: var currval;
9379: for (var i=0; i<creditsLength; i++) {
9380: if (domForm.coursecredits[i].checked) {
9381: currval = domForm.coursecredits[i].value;
9382: }
9383: }
9384: if (currval == 1) {
9385: creditsitem.style.display = 'block';
9386: } else {
9387: creditsitem.style.display = 'none';
9388: }
9389: }
9390: }
9391: return;
9392: }
9393:
9394: // ]]>
9395: </script>
9396:
9397: END
9398:
9399: }
9400:
1.165 raeburn 9401: sub captcha_phrases {
9402: return &Apache::lonlocal::texthash (
9403: priv => 'Private key',
9404: pub => 'Public key',
9405: original => 'original (CAPTCHA)',
9406: recaptcha => 'successor (ReCAPTCHA)',
9407: notused => 'unused',
9408: );
9409: }
9410:
1.205 raeburn 9411: sub devalidate_remote_domconfs {
1.212 ! raeburn 9412: my ($dom,$cachekeys) = @_;
! 9413: return unless (ref($cachekeys) eq 'HASH');
1.205 raeburn 9414: my %servers = &Apache::lonnet::internet_dom_servers($dom);
9415: my %thismachine;
9416: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.212 ! raeburn 9417: my @posscached = ('domainconfig','domdefaults');
1.205 raeburn 9418: if (keys(%servers) > 1) {
9419: foreach my $server (keys(%servers)) {
9420: next if ($thismachine{$server});
1.212 ! raeburn 9421: my @cached;
! 9422: foreach my $name (@posscached) {
! 9423: if ($cachekeys->{$name}) {
! 9424: push(@cached,&escape($name).':'.&escape($dom));
! 9425: }
! 9426: }
! 9427: if (@cached) {
! 9428: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
! 9429: }
1.205 raeburn 9430: }
9431: }
9432: return;
9433: }
9434:
1.3 raeburn 9435: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>