Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.17
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 17(raebu 4:24): # $Id: domainprefs.pm,v 1.160.6.118.2.16 2024/01/02 02:25:19 raeburn Exp $
1.160.6.40 raeburn 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
1.160.6.78 raeburn 22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
1.1 raeburn 24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: #
29: ###############################################################
1.160.6.118.2 14(raebu 30:23): ###############################################################
1.1 raeburn 31:
1.101 raeburn 32: =pod
33:
34: =head1 NAME
35:
36: Apache::domainprefs.pm
37:
38: =head1 SYNOPSIS
39:
40: Handles configuration of a LON-CAPA domain.
41:
42: This is part of the LearningOnline Network with CAPA project
43: described at http://www.lon-capa.org.
44:
45:
46: =head1 OVERVIEW
47:
48: Each institution using LON-CAPA will typically have a single domain designated
1.160.6.13 raeburn 49: for use by individuals affiliated with the institution. Accordingly, each domain
1.101 raeburn 50: may define a default set of logos and a color scheme which can be used to "brand"
51: the LON-CAPA instance. In addition, an institution will typically have a language
52: and timezone which are used for the majority of courses.
53:
54: LON-CAPA provides a mechanism to display and modify these defaults, as well as a
55: host of other domain-wide settings which determine the types of functionality
56: available to users and courses in the domain.
57:
58: There is also a mechanism to configure cataloging of courses in the domain, and
59: controls on the operation of automated processes which govern such things as
60: roster updates, user directory updates and processing of course requests.
61:
62: The domain coordination manual which is built dynamically on install/update of
63: LON-CAPA from the relevant help items provides more information about domain
64: configuration.
65:
66: Most of the domain settings are stored in the configuration.db GDBM file which is
67: housed on the primary library server for the domain in /home/httpd/lonUsers/$dom,
68: where $dom is the domain. The configuration.db stores settings in a number of
69: frozen hashes of hashes. In a few cases, domain information must be uploaded to
70: the domain as files (e.g., image files for logos etc., or plain text files for
71: bubblesheet formats). In this case the domainprefs.pm must be running in a user
72: session hosted on the primary library server in the domain, as these files are
73: stored in author space belonging to a special $dom-domainconfig user.
74:
75: domainprefs.pm in combination with lonconfigsettings.pm will retrieve and display
76: the current settings, and provides an interface to make modifications.
77:
78: =head1 SUBROUTINES
79:
80: =over
81:
82: =item print_quotas()
83:
84: Inputs: 4
85:
86: $dom,$settings,$rowtotal,$action.
87:
88: $dom is the domain, $settings is a reference to a hash of current settings for
89: the current context, $rowtotal is a reference to the scalar used to record the
1.160.6.27 raeburn 90: number of rows displayed on the page, and $action is the context (quotas,
1.160.6.5 raeburn 91: requestcourses or requestauthor).
1.101 raeburn 92:
93: The print_quotas routine was orginally created to display/store information
94: about default quota sizes for portfolio spaces for the different types of
95: institutional affiliation in the domain (e.g., Faculty, Staff, Student etc.),
96: but is now also used to manage availability of user tools:
97: i.e., blogs, aboutme page, and portfolios, and the course request tool,
1.160.6.20 raeburn 98: used by course owners to request creation of a course, and to display/store
1.160.6.34 raeburn 99: default quota sizes for Authoring Spaces.
1.160.6.20 raeburn 100:
1.101 raeburn 101: Outputs: 1
102:
103: $datatable - HTML containing form elements which allow settings to be changed.
104:
105: In the case of course requests, radio buttons are displayed for each institutional
106: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.118.2 14(raebu 107:23): (official, unofficial, community, textbook, and lti).
108:23): In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 109:
1.104 raeburn 110: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 111: which have the following effects:
112:
113: 0
114:
115: =over
116:
117: - course requests are not allowed for this course types/affiliation
118:
119: =back
120:
1.104 raeburn 121: approval
1.101 raeburn 122:
123: =over
124:
125: - course requests must be approved by a Doman Coordinator in the
126: course's domain
127:
128: =back
129:
130: validate
131:
132: =over
133:
134: - an institutional validation (e.g., check requestor is instructor
135: of record) needs to be passed before the course will be created. The required
136: validation is in localenroll.pm on the primary library server for the course
137: domain.
138:
139: =back
140:
141: autolimit
142:
143: =over
144:
1.143 raeburn 145: - course requests will be processed automatically up to a limit of
1.101 raeburn 146: N requests for the course type for the particular requestor.
147: If N is undefined, there is no limit to the number of course requests
148: which a course owner may submit and have processed automatically.
149:
150: =back
151:
152: =item modify_quotas()
153:
154: =back
155:
156: =cut
157:
1.1 raeburn 158: package Apache::domainprefs;
159:
160: use strict;
161: use Apache::Constants qw(:common :http);
162: use Apache::lonnet;
163: use Apache::loncommon();
164: use Apache::lonhtmlcommon();
165: use Apache::lonlocal;
1.43 raeburn 166: use Apache::lonmsg();
1.91 raeburn 167: use Apache::lonconfigsettings;
1.160.6.37 raeburn 168: use Apache::lonuserutils();
1.160.6.39 raeburn 169: use Apache::loncoursequeueadmin();
1.160.6.118.2 14(raebu 170:23): use Apache::courseprefs();
1.69 raeburn 171: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 172: use LONCAPA::Enrollment;
1.81 raeburn 173: use LONCAPA::lonauthcgi();
1.9 raeburn 174: use File::Copy;
1.43 raeburn 175: use Locale::Language;
1.62 raeburn 176: use DateTime::TimeZone;
1.68 raeburn 177: use DateTime::Locale;
1.160.6.118.2 14(raebu 178:23): use Time::HiRes qw( sleep );
1.160.6.113 raeburn 179: use Net::CIDR;
1.160.6.118.2 14(raebu 180:23): use Crypt::CBC;
1.1 raeburn 181:
1.155 raeburn 182: my $registered_cleanup;
183: my $modified_urls;
184:
1.1 raeburn 185: sub handler {
186: my $r=shift;
187: if ($r->header_only) {
188: &Apache::loncommon::content_type($r,'text/html');
189: $r->send_http_header;
190: return OK;
191: }
192:
1.91 raeburn 193: my $context = 'domain';
1.1 raeburn 194: my $dom = $env{'request.role.domain'};
1.5 albertel 195: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 196: if (&Apache::lonnet::allowed('mau',$dom)) {
197: &Apache::loncommon::content_type($r,'text/html');
198: $r->send_http_header;
199: } else {
200: $env{'user.error.msg'}=
201: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
202: return HTTP_NOT_ACCEPTABLE;
203: }
1.155 raeburn 204:
205: $registered_cleanup=0;
206: @{$modified_urls}=();
207:
1.1 raeburn 208: &Apache::lonhtmlcommon::clear_breadcrumbs();
209: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 210: ['phase','actions']);
1.30 raeburn 211: my $phase = 'pickactions';
1.3 raeburn 212: if ( exists($env{'form.phase'}) ) {
213: $phase = $env{'form.phase'};
214: }
1.150 raeburn 215: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 216: my %domconfig =
1.6 raeburn 217: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 218: 'quotas','autoenroll','autoupdate','autocreate',
219: 'directorysrch','usercreation','usermodification',
220: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 221: 'serverstatuses','requestcourses','helpsettings',
222: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113 raeburn 223: 'requestauthor','selfenrollment','inststatus',
1.160.6.118.2 14(raebu 224:23): 'passwords','ltitools','toolsec','lti','ltisec',
225:23): 'wafproxy','ipaccess'],$dom);
6(raebur 226:2): my %encconfig =
14(raebu 227:23): &Apache::lonnet::get_dom('encconfig',['ltitools','lti','linkprot'],$dom,undef,1);
228:23): my ($checked_is_home,$is_home);
1(raebur 229:1): if (ref($domconfig{'ltitools'}) eq 'HASH') {
230:1): if (ref($encconfig{'ltitools'}) eq 'HASH') {
14(raebu 231:23): my $home = &Apache::lonnet::domain($dom,'primary');
232:23): unless (($home eq 'no_host') || ($home eq '')) {
233:23): my @ids=&Apache::lonnet::current_machine_ids();
234:23): if (grep(/^\Q$home\E$/,@ids)) {
235:23): $is_home = 1;
236:23): }
237:23): }
238:23): $checked_is_home = 1;
1(raebur 239:1): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
14(raebu 240:23): if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
241:23): (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
242:23): $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
243:23): if (($is_home) && ($phase eq 'process')) {
244:23): $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
245:23): }
246:23): }
247:23): }
248:23): }
249:23): }
250:23): if (ref($domconfig{'lti'}) eq 'HASH') {
251:23): if (ref($encconfig{'lti'}) eq 'HASH') {
252:23): unless ($checked_is_home) {
253:23): my $home = &Apache::lonnet::domain($dom,'primary');
254:23): unless (($home eq 'no_host') || ($home eq '')) {
255:23): my @ids=&Apache::lonnet::current_machine_ids();
256:23): if (grep(/^\Q$home\E$/,@ids)) {
257:23): $is_home = 1;
258:23): }
259:23): }
260:23): $checked_is_home = 1;
261:23): }
262:23): foreach my $id (keys(%{$domconfig{'lti'}})) {
263:23): if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
264:23): (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
265:23): $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
266:23): if (($is_home) && ($phase eq 'process')) {
267:23): $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1(raebur 268:1): }
269:1): }
270:1): }
271:1): }
272:1): }
5(raebur 273:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
274:2): if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
275:2): if (ref($encconfig{'linkprot'}) eq 'HASH') {
276:2): foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
277:2): unless ($id =~ /^\d+$/) {
278:2): delete($domconfig{'ltisec'}{'linkprot'}{$id});
279:2): }
280:2): if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
281:2): (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
282:2): foreach my $item ('key','secret') {
283:2): $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
284:2): }
285:2): }
286:2): }
287:2): }
288:2): }
289:2): }
1.160.6.113 raeburn 290: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
291: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
292: 'contacts','usercreation','selfcreation','usermodification',
293: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 294: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.118.2 5(raebur 295:2): 'ltitools','selfenrollment','usersessions','lti');
1.160.6.7 raeburn 296: my %existing;
297: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
298: %existing = %{$domconfig{'loadbalancing'}};
299: }
300: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 301: push(@prefs_order,'loadbalancing');
302: }
1.30 raeburn 303: my %prefs = (
304: 'rolecolors' =>
305: { text => 'Default color schemes',
1.67 raeburn 306: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 307: header => [{col1 => 'Student Settings',
308: col2 => '',},
309: {col1 => 'Coordinator Settings',
310: col2 => '',},
311: {col1 => 'Author Settings',
312: col2 => '',},
313: {col1 => 'Administrator Settings',
314: col2 => '',}],
1.160.6.37 raeburn 315: print => \&print_rolecolors,
316: modify => \&modify_rolecolors,
1.30 raeburn 317: },
1.110 raeburn 318: 'login' =>
1.30 raeburn 319: { text => 'Log-in page options',
1.67 raeburn 320: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 321: header => [{col1 => 'Log-in Page Items',
322: col2 => '',},
323: {col1 => 'Log-in Help',
1.160.6.56 raeburn 324: col2 => 'Value'},
325: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 326: col2 => 'Value'},
327: {col1 => 'SSO',
328: col2 => 'Dual login: SSO and non-SSO options'},
329: ],
1.160.6.37 raeburn 330: print => \&print_login,
331: modify => \&modify_login,
1.30 raeburn 332: },
1.43 raeburn 333: 'defaults' =>
1.160.6.40 raeburn 334: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 335: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 336: header => [{col1 => 'Setting',
1.160.6.40 raeburn 337: col2 => 'Value'},
338: {col1 => 'Institutional user types',
1.160.6.118.2 8(raebur 339:2): col2 => 'Name displayed'},
340:2): {col1 => 'Mapping for missing usernames via standard log-in',
341:2): col2 => 'Rules in use'}],
1.160.6.37 raeburn 342: print => \&print_defaults,
343: modify => \&modify_defaults,
1.43 raeburn 344: },
1.160.6.113 raeburn 345: 'wafproxy' =>
346: { text => 'Web Application Firewall/Reverse Proxy',
347: help => 'Domain_Configuration_WAF_Proxy',
348: header => [{col1 => 'Domain(s)',
349: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
350: },
351: {col1 => 'Domain(s)',
352: col2 => 'WAF Configuration',}],
353: print => \&print_wafproxy,
354: modify => \&modify_wafproxy,
355: },
1.160.6.98 raeburn 356: 'passwords' =>
357: { text => 'Passwords (Internal authentication)',
358: help => 'Domain_Configuration_Passwords',
359: header => [{col1 => 'Resetting Forgotten Password',
360: col2 => 'Settings'},
361: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
362: col2 => 'Settings'},
363: {col1 => 'Rules for LON-CAPA Passwords',
364: col2 => 'Settings'},
365: {col1 => 'Course Owner Changing Student Passwords',
366: col2 => 'Settings'}],
367: print => \&print_passwords,
368: modify => \&modify_passwords,
369: },
1.30 raeburn 370: 'quotas' =>
1.160.6.118.2 10(raebu 371:22): { text => 'Blogs, personal pages/timezones, webDAV/quotas, portfolio',
1.67 raeburn 372: help => 'Domain_Configuration_Quotas',
1.77 raeburn 373: header => [{col1 => 'User affiliation',
1.72 raeburn 374: col2 => 'Available tools',
1.160.6.28 raeburn 375: col3 => 'Quotas, MB; (Authoring requires role)',}],
1.160.6.37 raeburn 376: print => \&print_quotas,
377: modify => \&modify_quotas,
1.30 raeburn 378: },
379: 'autoenroll' =>
380: { text => 'Auto-enrollment settings',
1.67 raeburn 381: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 382: header => [{col1 => 'Configuration setting',
383: col2 => 'Value(s)'}],
1.160.6.37 raeburn 384: print => \&print_autoenroll,
385: modify => \&modify_autoenroll,
1.30 raeburn 386: },
387: 'autoupdate' =>
388: { text => 'Auto-update settings',
1.67 raeburn 389: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 390: header => [{col1 => 'Setting',
391: col2 => 'Value',},
1.131 raeburn 392: {col1 => 'Setting',
393: col2 => 'Affiliation'},
1.43 raeburn 394: {col1 => 'User population',
1.160.6.35 raeburn 395: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 396: print => \&print_autoupdate,
397: modify => \&modify_autoupdate,
1.30 raeburn 398: },
1.125 raeburn 399: 'autocreate' =>
400: { text => 'Auto-course creation settings',
401: help => 'Domain_Configuration_Auto_Creation',
402: header => [{col1 => 'Configuration Setting',
403: col2 => 'Value',}],
1.160.6.37 raeburn 404: print => \&print_autocreate,
405: modify => \&modify_autocreate,
1.125 raeburn 406: },
1.30 raeburn 407: 'directorysrch' =>
1.160.6.72 raeburn 408: { text => 'Directory searches',
1.67 raeburn 409: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 410: header => [{col1 => 'Institutional Directory Setting',
411: col2 => 'Value',},
412: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 413: col2 => 'Value',}],
1.160.6.37 raeburn 414: print => \&print_directorysrch,
415: modify => \&modify_directorysrch,
1.30 raeburn 416: },
417: 'contacts' =>
1.160.6.78 raeburn 418: { text => 'E-mail addresses and helpform',
1.67 raeburn 419: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 420: header => [{col1 => 'Default e-mail addresses',
421: col2 => 'Value',},
422: {col1 => 'Recipient(s) for notifications',
423: col2 => 'Value',},
1.160.6.107 raeburn 424: {col1 => 'Nightly status check e-mail',
425: col2 => 'Settings',},
1.160.6.78 raeburn 426: {col1 => 'Ask helpdesk form settings',
427: col2 => 'Value',},],
1.160.6.37 raeburn 428: print => \&print_contacts,
429: modify => \&modify_contacts,
1.30 raeburn 430: },
431: 'usercreation' =>
432: { text => 'User creation',
1.67 raeburn 433: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 434: header => [{col1 => 'Format rule type',
435: col2 => 'Format rules in force'},
1.34 raeburn 436: {col1 => 'User account creation',
437: col2 => 'Usernames which may be created',},
1.30 raeburn 438: {col1 => 'Context',
1.43 raeburn 439: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 440: print => \&print_usercreation,
441: modify => \&modify_usercreation,
1.30 raeburn 442: },
1.160.6.34 raeburn 443: 'selfcreation' =>
444: { text => 'Users self-creating accounts',
445: help => 'Domain_Configuration_Self_Creation',
446: header => [{col1 => 'Self-creation with institutional username',
447: col2 => 'Enabled?'},
448: {col1 => 'Institutional user type (login/SSO self-creation)',
449: col2 => 'Information user can enter'},
1.160.6.93 raeburn 450: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 451: col2 => 'Settings'}],
1.160.6.37 raeburn 452: print => \&print_selfcreation,
453: modify => \&modify_selfcreation,
1.160.6.34 raeburn 454: },
1.69 raeburn 455: 'usermodification' =>
1.33 raeburn 456: { text => 'User modification',
1.67 raeburn 457: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 458: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 459: col2 => 'User information updatable in author context'},
1.33 raeburn 460: {col1 => 'Target user has role',
1.160.6.35 raeburn 461: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 462: print => \&print_usermodification,
463: modify => \&modify_usermodification,
1.33 raeburn 464: },
1.69 raeburn 465: 'scantron' =>
1.160.6.97 raeburn 466: { text => 'Bubblesheet format',
1.67 raeburn 467: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 468: header => [ {col1 => 'Bubblesheet format file',
469: col2 => ''},
470: {col1 => 'Bubblesheet data upload formats',
471: col2 => 'Settings'}],
1.160.6.37 raeburn 472: print => \&print_scantron,
473: modify => \&modify_scantron,
1.46 raeburn 474: },
1.86 raeburn 475: 'requestcourses' =>
476: {text => 'Request creation of courses',
477: help => 'Domain_Configuration_Request_Courses',
478: header => [{col1 => 'User affiliation',
1.102 raeburn 479: col2 => 'Availability/Processing of requests',},
480: {col1 => 'Setting',
1.160.6.30 raeburn 481: col2 => 'Value'},
482: {col1 => 'Available textbooks',
1.160.6.39 raeburn 483: col2 => ''},
1.160.6.46 raeburn 484: {col1 => 'Available templates',
485: col2 => ''},
1.160.6.39 raeburn 486: {col1 => 'Validation (not official courses)',
487: col2 => 'Value'},],
1.160.6.37 raeburn 488: print => \&print_quotas,
489: modify => \&modify_quotas,
1.86 raeburn 490: },
1.160.6.5 raeburn 491: 'requestauthor' =>
1.160.6.34 raeburn 492: {text => 'Request Authoring Space',
1.160.6.5 raeburn 493: help => 'Domain_Configuration_Request_Author',
494: header => [{col1 => 'User affiliation',
495: col2 => 'Availability/Processing of requests',},
496: {col1 => 'Setting',
497: col2 => 'Value'}],
1.160.6.37 raeburn 498: print => \&print_quotas,
499: modify => \&modify_quotas,
1.160.6.5 raeburn 500: },
1.69 raeburn 501: 'coursecategories' =>
1.120 raeburn 502: { text => 'Cataloging of courses/communities',
1.67 raeburn 503: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 504: header => [{col1 => 'Catalog type/availability',
505: col2 => '',},
506: {col1 => 'Category settings for standard catalog',
1.57 raeburn 507: col2 => '',},
508: {col1 => 'Categories',
509: col2 => '',
510: }],
1.160.6.37 raeburn 511: print => \&print_coursecategories,
512: modify => \&modify_coursecategories,
1.69 raeburn 513: },
514: 'serverstatuses' =>
1.77 raeburn 515: {text => 'Access to server status pages',
1.69 raeburn 516: help => 'Domain_Configuration_Server_Status',
517: header => [{col1 => 'Status Page',
518: col2 => 'Other named users',
519: col3 => 'Specific IPs',
520: }],
1.160.6.37 raeburn 521: print => \&print_serverstatuses,
522: modify => \&modify_serverstatuses,
1.69 raeburn 523: },
1.160.6.73 raeburn 524: 'helpsettings' =>
525: {text => 'Support settings',
526: help => 'Domain_Configuration_Help_Settings',
527: header => [{col1 => 'Help Page Settings (logged-in users)',
528: col2 => 'Value'},
529: {col1 => 'Helpdesk Roles',
530: col2 => 'Settings'},],
531: print => \&print_helpsettings,
532: modify => \&modify_helpsettings,
533: },
1.160.6.39 raeburn 534: 'coursedefaults' =>
1.160.6.16 raeburn 535: {text => 'Course/Community defaults',
536: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 537: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
538: col2 => 'Value',},
539: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 540: col2 => 'Value',},],
1.160.6.37 raeburn 541: print => \&print_coursedefaults,
542: modify => \&modify_coursedefaults,
543: },
1.160.6.39 raeburn 544: 'selfenrollment' =>
1.160.6.37 raeburn 545: {text => 'Self-enrollment in Course/Community',
546: help => 'Domain_Configuration_Selfenrollment',
547: header => [{col1 => 'Configuration Rights',
548: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
549: {col1 => 'Defaults',
550: col2 => 'Value'},
551: {col1 => 'Self-enrollment validation (optional)',
552: col2 => 'Value'},],
553: print => \&print_selfenrollment,
554: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 555: },
1.141 raeburn 556: 'usersessions' =>
1.145 raeburn 557: {text => 'User session hosting/offloading',
1.137 raeburn 558: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 559: header => [{col1 => 'Domain server',
560: col2 => 'Servers to offload sessions to when busy'},
561: {col1 => 'Hosting of users from other domains',
1.137 raeburn 562: col2 => 'Rules'},
563: {col1 => "Hosting domain's own users elsewhere",
564: col2 => 'Rules'}],
1.160.6.37 raeburn 565: print => \&print_usersessions,
566: modify => \&modify_usersessions,
1.137 raeburn 567: },
1.160.6.78 raeburn 568: 'loadbalancing' =>
1.160.6.7 raeburn 569: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 570: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 571: header => [{col1 => 'Balancers',
1.150 raeburn 572: col2 => 'Default destinations',
1.160.6.13 raeburn 573: col3 => 'User affiliation',
1.150 raeburn 574: col4 => 'Overrides'},
575: ],
1.160.6.37 raeburn 576: print => \&print_loadbalancing,
577: modify => \&modify_loadbalancing,
1.150 raeburn 578: },
1.160.6.118.2 1(raebur 579:1): 'ltitools' =>
580:1): {text => 'External Tools (LTI)',
581:1): help => 'Domain_Configuration_LTI_Tools',
14(raebu 582:23): header => [{col1 => 'Encryption of shared secrets',
583:23): col2 => 'Settings'},
584:23): {col1 => 'Rules for shared secrets',
585:23): col2 => 'Settings'},
586:23): {col1 => 'Providers',
587:23): col2 => 'Settings',}],
1(raebur 588:1): print => \&print_ltitools,
589:1): modify => \&modify_ltitools,
590:1): },
14(raebu 591:23): 'lti' =>
5(raebur 592:2): {text => 'LTI Link Protection and LTI Consumers',
593:2): help => 'Domain_Configuration_LTI_Provider',
594:2): header => [{col1 => 'Encryption of shared secrets',
595:2): col2 => 'Settings'},
596:2): {col1 => 'Rules for shared secrets',
597:2): col2 => 'Settings'},
598:2): {col1 => 'Link Protectors',
14(raebu 599:23): col2 => 'Settings'},
600:23): {col1 => 'Consumers',
5(raebur 601:2): col2 => 'Settings'},],
602:2): print => \&print_lti,
603:2): modify => \&modify_lti,
604:2): },
14(raebu 605:23): 'ipaccess' =>
1.160.6.113 raeburn 606: {text => 'IP-based access control',
607: help => 'Domain_Configuration_IP_Access',
608: header => [{col1 => 'Setting',
609: col2 => 'Value'},],
610: print => \&print_ipaccess,
611: modify => \&modify_ipaccess,
612: },
1.3 raeburn 613: );
1.110 raeburn 614: if (keys(%servers) > 1) {
615: $prefs{'login'} = { text => 'Log-in page options',
616: help => 'Domain_Configuration_Login_Page',
617: header => [{col1 => 'Log-in Service',
618: col2 => 'Server Setting',},
619: {col1 => 'Log-in Page Items',
1.160.6.118.2 5(raebur 620:2): col2 => 'Settings'},
1.160.6.5 raeburn 621: {col1 => 'Log-in Help',
1.160.6.56 raeburn 622: col2 => 'Value'},
623: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 624: col2 => 'Value'},
625: {col1 => 'SSO',
626: col2 => 'Dual login: SSO and non-SSO options'},
627: ],
1.160.6.37 raeburn 628: print => \&print_login,
629: modify => \&modify_login,
1.110 raeburn 630: };
631: }
1.160.6.13 raeburn 632:
1.6 raeburn 633: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 634: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 635: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 636: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 637: text=>"Settings to display/modify"});
1.9 raeburn 638: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 639:
1.3 raeburn 640: if ($phase eq 'process') {
1.160.6.27 raeburn 641: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
642: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 643: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 644: $r->rflush();
1.160.6.27 raeburn 645: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 646: }
1.30 raeburn 647: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 648: my $js = &recaptcha_js().
1.160.6.40 raeburn 649: &toggle_display_js();
1.160.6.7 raeburn 650: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 651: my ($othertitle,$usertypes,$types) =
652: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 653: $js .= &lonbalance_targets_js($dom,$types,\%servers,
654: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 655: &new_spares_js().
656: &common_domprefs_js().
657: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 658: }
1.160.6.30 raeburn 659: if (grep(/^requestcourses$/,@actions)) {
660: my $javascript_validations;
661: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
662: $js .= <<END;
663: <script type="text/javascript">
664: $javascript_validations
665: </script>
666: $coursebrowserjs
667: END
1.160.6.113 raeburn 668: } elsif (grep(/^ipaccess$/,@actions)) {
669: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 670: }
1.160.6.93 raeburn 671: if (grep(/^selfcreation$/,@actions)) {
672: $js .= &selfcreate_javascript();
673: }
1.160.6.78 raeburn 674: if (grep(/^contacts$/,@actions)) {
675: $js .= &contacts_javascript();
676: }
1.160.6.97 raeburn 677: if (grep(/^scantron$/,@actions)) {
678: $js .= &scantron_javascript();
679: }
1.150 raeburn 680: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 681: } else {
1.160.6.11 raeburn 682: # check if domconfig user exists for the domain.
683: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 684: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 685: &config_check($dom,$confname,$servadm);
686: unless ($configuserok eq 'ok') {
687: &Apache::lonconfigsettings::print_header($r,$phase,$context);
688: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
689: $confname).
690: '<br />'
691: );
692: if ($switchserver) {
693: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
694: '<br />'.
695: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
696: '<br />'.
697: &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).
698: '<br />'.
699: &mt('To do that now, use the following link: [_1]',$switchserver)
700: );
701: } else {
702: $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.').
703: '<br />'.
704: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
705: );
706: }
707: $r->print(&Apache::loncommon::end_page());
708: return OK;
709: }
1.21 raeburn 710: if (keys(%domconfig) == 0) {
711: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 712: my @ids=&Apache::lonnet::current_machine_ids();
713: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 714: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 715: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 716: my $custom_img_count = 0;
717: foreach my $img (@loginimages) {
718: if ($designhash{$dom.'.login.'.$img} ne '') {
719: $custom_img_count ++;
720: }
721: }
722: foreach my $role (@roles) {
723: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
724: $custom_img_count ++;
725: }
726: }
727: if ($custom_img_count > 0) {
1.94 raeburn 728: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 729: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 730: $r->print(
731: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
732: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
733: &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 />'.
734: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
735: if ($switch_server) {
1.30 raeburn 736: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 737: }
1.91 raeburn 738: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 739: return OK;
740: }
741: }
742: }
1.91 raeburn 743: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 744: }
745: return OK;
746: }
747:
748: sub process_changes {
1.160.6.24 raeburn 749: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 750: my %domconfig;
751: if (ref($values) eq 'HASH') {
752: %domconfig = %{$values};
753: }
1.3 raeburn 754: my $output;
755: if ($action eq 'login') {
1.160.6.24 raeburn 756: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 757: } elsif ($action eq 'rolecolors') {
1.9 raeburn 758: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 759: $lastactref,%domconfig);
1.3 raeburn 760: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 761: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 762: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 763: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 764: } elsif ($action eq 'autoupdate') {
765: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 766: } elsif ($action eq 'autocreate') {
767: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 768: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 769: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 770: } elsif ($action eq 'usercreation') {
1.28 raeburn 771: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 772: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 773: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 774: } elsif ($action eq 'usermodification') {
775: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 776: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 777: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 778: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 779: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 780: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 781: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 782: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 783: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 784: } elsif ($action eq 'serverstatuses') {
785: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 786: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 787: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 788: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 789: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 790: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 791: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 792: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 793: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 794: } elsif ($action eq 'selfenrollment') {
795: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 796: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 797: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 798: } elsif ($action eq 'loadbalancing') {
799: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2 14(raebu 800:23): } elsif ($action eq 'ltitools') {
801:23): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
5(raebur 802:2): } elsif ($action eq 'lti') {
803:2): $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98 raeburn 804: } elsif ($action eq 'passwords') {
805: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 806: } elsif ($action eq 'wafproxy') {
807: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
808: } elsif ($action eq 'ipaccess') {
809: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 810: }
811: return $output;
812: }
813:
814: sub print_config_box {
1.9 raeburn 815: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 816: my $rowtotal = 0;
1.49 raeburn 817: my $output;
818: if ($action eq 'coursecategories') {
819: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 820: } elsif ($action eq 'defaults') {
821: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 822: } elsif ($action eq 'passwords') {
1.160.6.118.2 5(raebur 823:2): $output = &passwords_javascript($action);
1.160.6.73 raeburn 824: } elsif ($action eq 'helpsettings') {
825: my (%privs,%levelscurrent);
826: my %full=();
827: my %levels=(
828: course => {},
829: domain => {},
830: system => {},
831: );
832: my $context = 'domain';
833: my $crstype = 'Course';
834: my $formname = 'display';
835: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
836: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
837: $output =
838: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
839: \@templateroles);
1.160.6.118.2 1(raebur 840:1): } elsif ($action eq 'ltitools') {
14(raebu 841:23): $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
5(raebur 842:2): } elsif ($action eq 'lti') {
14(raebu 843:23): $output .= &passwords_javascript('ltisecrets')."\n".
5(raebur 844:2): <i_javascript($dom,$settings);
1.160.6.113 raeburn 845: } elsif ($action eq 'wafproxy') {
846: $output .= &wafproxy_javascript($dom);
847: } elsif ($action eq 'autoupdate') {
848: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 849: } elsif ($action eq 'autoenroll') {
850: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 851: } elsif ($action eq 'login') {
852: $output .= &saml_javascript();
853: } elsif ($action eq 'ipaccess') {
854: $output .= &ipaccess_javascript($settings);
1.91 raeburn 855: }
1.160.6.40 raeburn 856: $output .=
1.30 raeburn 857: '<table class="LC_nested_outer">
1.3 raeburn 858: <tr>
1.160.6.113 raeburn 859: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 860: &mt($item->{text}).' '.
861: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
862: '</tr>';
1.30 raeburn 863: $rowtotal ++;
1.110 raeburn 864: my $numheaders = 1;
865: if (ref($item->{'header'}) eq 'ARRAY') {
866: $numheaders = scalar(@{$item->{'header'}});
867: }
868: if ($numheaders > 1) {
1.64 raeburn 869: my $colspan = '';
1.145 raeburn 870: my $rightcolspan = '';
1.160.6.118.2 14(raebu 871:23): my $leftnobr = '';
1.160.6.42 raeburn 872: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 873: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 874: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 875: $colspan = ' colspan="2"';
876: }
1.145 raeburn 877: if ($action eq 'usersessions') {
878: $rightcolspan = ' colspan="3"';
879: }
1.160.6.104 raeburn 880: if ($action eq 'passwords') {
881: $leftnobr = ' LC_nobreak';
882: }
1.30 raeburn 883: $output .= '
1.3 raeburn 884: <tr>
885: <td>
886: <table class="LC_nested">
887: <tr class="LC_info_row">
1.160.6.104 raeburn 888: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 889: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 890: </tr>';
1.69 raeburn 891: $rowtotal ++;
1.160.6.37 raeburn 892: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 893: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 894: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2 14(raebu 895:23): ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') ||
896:23): ($action eq 'lti') || ($action eq 'ltitools')) {
1.160.6.37 raeburn 897: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 898: } elsif ($action eq 'passwords') {
899: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 900: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 901: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 902: } elsif ($action eq 'scantron') {
903: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 904: } elsif ($action eq 'login') {
1.160.6.113 raeburn 905: if ($numheaders == 5) {
1.160.6.5 raeburn 906: $colspan = ' colspan="2"';
907: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
908: } else {
909: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
910: }
1.160.6.37 raeburn 911: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 912: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 913: } elsif ($action eq 'rolecolors') {
1.30 raeburn 914: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 915: }
1.30 raeburn 916: $output .= '
1.6 raeburn 917: </table>
918: </td>
919: </tr>
920: <tr>
921: <td>
922: <table class="LC_nested">
923: <tr class="LC_info_row">
1.160.6.37 raeburn 924: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 925: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 926: </tr>';
927: $rowtotal ++;
1.160.6.37 raeburn 928: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
929: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 930: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2 8(raebur 931:2): ($action eq 'contacts') || ($action eq 'passwords') ||
14(raebu 932:23): ($action eq 'defaults') || ($action eq 'lti') ||
933:23): ($action eq 'ltitools')) {
1.160.6.42 raeburn 934: if ($action eq 'coursecategories') {
935: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
936: $colspan = ' colspan="2"';
1.160.6.98 raeburn 937: } elsif ($action eq 'passwords') {
938: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.42 raeburn 939: } else {
940: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
941: }
942: $output .= '
1.63 raeburn 943: </table>
944: </td>
945: </tr>
946: <tr>
947: <td>
948: <table class="LC_nested">
949: <tr class="LC_info_row">
1.160.6.113 raeburn 950: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.34 raeburn 951: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1.160.6.42 raeburn 952: </tr>'."\n";
953: if ($action eq 'coursecategories') {
954: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 955: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 956: if ($action eq 'passwords') {
957: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
958: } else {
959: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
960: }
961: $output .= '
1.160.6.98 raeburn 962: </tr>
963: </table>
964: </td>
965: </tr>
966: <tr>
967: <td>
968: <table class="LC_nested">
969: <tr class="LC_info_row">
1.160.6.113 raeburn 970: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1.160.6.107 raeburn 971: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 972: if ($action eq 'passwords') {
973: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
974: } else {
975: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
976: }
977: $output .= '
1.160.6.98 raeburn 978: </table>
979: </td>
980: </tr>
981: <tr>';
1.160.6.42 raeburn 982: } else {
983: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
984: }
1.63 raeburn 985: $rowtotal ++;
1.160.6.57 raeburn 986: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.118.2 8(raebur 987:2): ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
988:2): ($action eq 'wafproxy')) {
1.160.6.37 raeburn 989: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 990: } elsif ($action eq 'scantron') {
991: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 992: } elsif ($action eq 'login') {
1.160.6.113 raeburn 993: if ($numheaders == 5) {
1.160.6.5 raeburn 994: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
995: </table>
996: </td>
997: </tr>
998: <tr>
999: <td>
1000: <table class="LC_nested">
1001: <tr class="LC_info_row">
1002: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 1003: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 1004: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1005: $rowtotal ++;
1006: } else {
1007: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1008: }
1.160.6.56 raeburn 1009: $output .= '
1010: </table>
1011: </td>
1012: </tr>
1013: <tr>
1014: <td>
1015: <table class="LC_nested">
1016: <tr class="LC_info_row">';
1.160.6.113 raeburn 1017: if ($numheaders == 5) {
1.160.6.56 raeburn 1018: $output .= '
1019: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1020: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1021: </tr>';
1022: } else {
1023: $output .= '
1024: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1025: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1026: </tr>';
1027: }
1028: $rowtotal ++;
1.160.6.113 raeburn 1029: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">';
1037: if ($numheaders == 5) {
1038: $output .= '
1039: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1040: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1041: </tr>';
1042: } else {
1043: $output .= '
1044: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1045: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1046: </tr>';
1047: }
1048: $rowtotal ++;
1049: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1050: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 1051: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1052: $rowtotal ++;
1053: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 1054: </table>
1055: </td>
1056: </tr>
1057: <tr>
1058: <td>
1059: <table class="LC_nested">
1060: <tr class="LC_info_row">
1061: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1062: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 1063: &textbookcourses_javascript($settings).
1064: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1065: </table>
1066: </td>
1067: </tr>
1068: <tr>
1069: <td>
1070: <table class="LC_nested">
1071: <tr class="LC_info_row">
1072: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1073: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1074: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 1075: </table>
1076: </td>
1077: </tr>
1078: <tr>
1079: <td>
1080: <table class="LC_nested">
1081: <tr class="LC_info_row">
1.160.6.46 raeburn 1082: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1083: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1084: </tr>'.
1085: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1086: } elsif ($action eq 'requestauthor') {
1087: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1088: $rowtotal ++;
1.122 jms 1089: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1090: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1091: </table>
1092: </td>
1093: </tr>
1094: <tr>
1095: <td>
1096: <table class="LC_nested">
1097: <tr class="LC_info_row">
1.69 raeburn 1098: <td class="LC_left_item"'.$colspan.' valign="top">'.
1099: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1100: <td class="LC_right_item" valign="top">'.
1101: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1102: </tr>'.
1.30 raeburn 1103: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1104: </table>
1105: </td>
1106: </tr>
1107: <tr>
1108: <td>
1109: <table class="LC_nested">
1110: <tr class="LC_info_row">
1.59 bisitz 1111: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1112: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1113: </tr>'.
1.30 raeburn 1114: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1115: $rowtotal += 2;
1.6 raeburn 1116: }
1.3 raeburn 1117: } else {
1.30 raeburn 1118: $output .= '
1.3 raeburn 1119: <tr>
1120: <td>
1121: <table class="LC_nested">
1.30 raeburn 1122: <tr class="LC_info_row">';
1.160.6.72 raeburn 1123: if ($action eq 'login') {
1.30 raeburn 1124: $output .= '
1.59 bisitz 1125: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1126: } elsif ($action eq 'serverstatuses') {
1127: $output .= '
1128: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1129: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1130:
1.6 raeburn 1131: } else {
1.30 raeburn 1132: $output .= '
1.69 raeburn 1133: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1134: }
1.72 raeburn 1135: if (defined($item->{'header'}->[0]->{'col3'})) {
1136: $output .= '<td class="LC_left_item" valign="top">'.
1137: &mt($item->{'header'}->[0]->{'col2'});
1138: if ($action eq 'serverstatuses') {
1139: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1140: }
1.69 raeburn 1141: } else {
1142: $output .= '<td class="LC_right_item" valign="top">'.
1143: &mt($item->{'header'}->[0]->{'col2'});
1144: }
1145: $output .= '</td>';
1146: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1147: if (defined($item->{'header'}->[0]->{'col4'})) {
1148: $output .= '<td class="LC_left_item" valign="top">'.
1149: &mt($item->{'header'}->[0]->{'col3'});
1150: } else {
1151: $output .= '<td class="LC_right_item" valign="top">'.
1152: &mt($item->{'header'}->[0]->{'col3'});
1153: }
1.69 raeburn 1154: if ($action eq 'serverstatuses') {
1155: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1156: }
1157: $output .= '</td>';
1.6 raeburn 1158: }
1.150 raeburn 1159: if ($item->{'header'}->[0]->{'col4'}) {
1160: $output .= '<td class="LC_right_item" valign="top">'.
1161: &mt($item->{'header'}->[0]->{'col4'});
1162: }
1.69 raeburn 1163: $output .= '</tr>';
1.48 raeburn 1164: $rowtotal ++;
1.160.6.5 raeburn 1165: if ($action eq 'quotas') {
1.86 raeburn 1166: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1167: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1168: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 14(raebu 1169:23): ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1170: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1171: }
1.3 raeburn 1172: }
1.30 raeburn 1173: $output .= '
1.3 raeburn 1174: </table>
1175: </td>
1176: </tr>
1.30 raeburn 1177: </table><br />';
1178: return ($output,$rowtotal);
1.1 raeburn 1179: }
1180:
1.3 raeburn 1181: sub print_login {
1.160.6.5 raeburn 1182: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1183: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1184: my %choices = &login_choices();
1.160.6.113 raeburn 1185: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1186: %lt = &login_file_options();
1187: $switchserver = &check_switchserver($dom,$confname);
1188: }
1.160.6.5 raeburn 1189: if ($caller eq 'service') {
1.149 raeburn 1190: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1191: my $choice = $choices{'disallowlogin'};
1192: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1193: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1194: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1195: '<th>'.$choices{'server'}.'</th>'.
1196: '<th>'.$choices{'serverpath'}.'</th>'.
1197: '<th>'.$choices{'custompath'}.'</th>'.
1198: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1199: my %disallowed;
1200: if (ref($settings) eq 'HASH') {
1201: if (ref($settings->{'loginvia'}) eq 'HASH') {
1202: %disallowed = %{$settings->{'loginvia'}};
1203: }
1204: }
1205: foreach my $lonhost (sort(keys(%servers))) {
1206: my $direct = 'selected="selected"';
1.128 raeburn 1207: if (ref($disallowed{$lonhost}) eq 'HASH') {
1208: if ($disallowed{$lonhost}{'server'} ne '') {
1209: $direct = '';
1210: }
1.110 raeburn 1211: }
1.115 raeburn 1212: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1213: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1214: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1215: '</option>';
1.160.6.13 raeburn 1216: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1217: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1218: my $selected = '';
1.128 raeburn 1219: if (ref($disallowed{$lonhost}) eq 'HASH') {
1220: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1221: $selected = 'selected="selected"';
1222: }
1.110 raeburn 1223: }
1224: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1225: $servers{$hostid}.'</option>';
1226: }
1.128 raeburn 1227: $datatable .= '</select></td>'.
1228: '<td><select name="'.$lonhost.'_serverpath">';
1229: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1230: my $pathname = $path;
1231: if ($path eq 'custom') {
1232: $pathname = &mt('Custom Path').' ->';
1233: }
1234: my $selected = '';
1235: if (ref($disallowed{$lonhost}) eq 'HASH') {
1236: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1237: $selected = 'selected="selected"';
1238: }
1239: } elsif ($path eq '') {
1240: $selected = 'selected="selected"';
1241: }
1242: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1243: }
1244: $datatable .= '</select></td>';
1245: my ($custom,$exempt);
1246: if (ref($disallowed{$lonhost}) eq 'HASH') {
1247: $custom = $disallowed{$lonhost}{'custompath'};
1248: $exempt = $disallowed{$lonhost}{'exempt'};
1249: }
1250: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1251: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1252: '</tr>';
1.110 raeburn 1253: }
1254: $datatable .= '</table></td></tr>';
1255: return $datatable;
1.160.6.5 raeburn 1256: } elsif ($caller eq 'page') {
1257: my %defaultchecked = (
1258: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1259: 'helpdesk' => 'on',
1.160.6.5 raeburn 1260: 'adminmail' => 'off',
1261: 'newuser' => 'off',
1262: );
1.160.6.14 raeburn 1263: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1264: my (%checkedon,%checkedoff);
1.42 raeburn 1265: foreach my $item (@toggles) {
1.160.6.5 raeburn 1266: if ($defaultchecked{$item} eq 'on') {
1267: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1268: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1269: } elsif ($defaultchecked{$item} eq 'off') {
1270: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1271: $checkedon{$item} = ' ';
1272: }
1.1 raeburn 1273: }
1.160.6.5 raeburn 1274: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1275:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1276: my @logintext = ('textcol','bgcol');
1277: my @bgs = ('pgbg','mainbg','sidebg');
1278: my @links = ('link','alink','vlink');
1279: my %designhash = &Apache::loncommon::get_domainconf($dom);
1280: my %defaultdesign = %Apache::loncommon::defaultdesign;
1281: my (%is_custom,%designs);
1282: my %defaults = (
1283: font => $defaultdesign{'login.font'},
1284: );
1.6 raeburn 1285: foreach my $item (@images) {
1.160.6.5 raeburn 1286: $defaults{$item} = $defaultdesign{'login.'.$item};
1287: $defaults{'showlogo'}{$item} = 1;
1288: }
1289: foreach my $item (@bgs) {
1290: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1291: }
1.41 raeburn 1292: foreach my $item (@logintext) {
1.160.6.5 raeburn 1293: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1294: }
1.160.6.5 raeburn 1295: foreach my $item (@links) {
1296: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1297: }
1.160.6.5 raeburn 1298: if (ref($settings) eq 'HASH') {
1299: foreach my $item (@toggles) {
1300: if ($settings->{$item} eq '1') {
1301: $checkedon{$item} = ' checked="checked" ';
1302: $checkedoff{$item} = ' ';
1303: } elsif ($settings->{$item} eq '0') {
1304: $checkedoff{$item} = ' checked="checked" ';
1305: $checkedon{$item} = ' ';
1306: }
1.6 raeburn 1307: }
1.160.6.5 raeburn 1308: foreach my $item (@images) {
1309: if (defined($settings->{$item})) {
1310: $designs{$item} = $settings->{$item};
1311: $is_custom{$item} = 1;
1312: }
1313: if (defined($settings->{'showlogo'}{$item})) {
1314: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1315: }
1316: }
1.160.6.118.2 2(raebur 1317:2): foreach my $item (@alttext) {
1318:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1319:2): if ($settings->{'alttext'}->{$item} ne '') {
1320:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1321:2): }
1322:2): }
1323:2): }
1.160.6.5 raeburn 1324: foreach my $item (@logintext) {
1325: if ($settings->{$item} ne '') {
1326: $designs{'logintext'}{$item} = $settings->{$item};
1327: $is_custom{$item} = 1;
1328: }
1329: }
1330: if ($settings->{'font'} ne '') {
1331: $designs{'font'} = $settings->{'font'};
1332: $is_custom{'font'} = 1;
1333: }
1334: foreach my $item (@bgs) {
1335: if ($settings->{$item} ne '') {
1336: $designs{'bgs'}{$item} = $settings->{$item};
1337: $is_custom{$item} = 1;
1338: }
1339: }
1340: foreach my $item (@links) {
1341: if ($settings->{$item} ne '') {
1342: $designs{'links'}{$item} = $settings->{$item};
1343: $is_custom{$item} = 1;
1344: }
1345: }
1346: } else {
1347: if ($designhash{$dom.'.login.font'} ne '') {
1348: $designs{'font'} = $designhash{$dom.'.login.font'};
1349: $is_custom{'font'} = 1;
1350: }
1351: foreach my $item (@images) {
1352: if ($designhash{$dom.'.login.'.$item} ne '') {
1353: $designs{$item} = $designhash{$dom.'.login.'.$item};
1354: $is_custom{$item} = 1;
1355: }
1356: }
1357: foreach my $item (@bgs) {
1358: if ($designhash{$dom.'.login.'.$item} ne '') {
1359: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1360: $is_custom{$item} = 1;
1361: }
1362: }
1363: foreach my $item (@links) {
1364: if ($designhash{$dom.'.login.'.$item} ne '') {
1365: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1366: $is_custom{$item} = 1;
1367: }
1.6 raeburn 1368: }
1369: }
1.160.6.5 raeburn 1370: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1371: logo => 'Institution Logo',
1372: domlogo => 'Domain Logo',
1373: login => 'Login box');
1374: my $itemcount = 1;
1375: foreach my $item (@toggles) {
1376: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1377: $datatable .=
1378: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1379: '</td><td>'.
1380: '<span class="LC_nobreak"><label><input type="radio" name="'.
1381: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1382: '</label> <label><input type="radio" name="'.$item.'"'.
1383: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1384: '</tr>';
1385: $itemcount ++;
1.6 raeburn 1386: }
1.160.6.5 raeburn 1387: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1388: $datatable .= '</tr></table></td></tr>';
1389: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1390: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1391: my $itemcount = 1;
1392: $defaulturl = '/adm/loginproblems.html';
1393: $defaulttype = 'default';
1394: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1395: my @currlangs;
1396: if (ref($settings) eq 'HASH') {
1397: if (ref($settings->{'helpurl'}) eq 'HASH') {
1398: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1399: next if ($settings->{'helpurl'}{$key} eq '');
1400: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1401: $type{$key} = 'custom';
1402: unless ($key eq 'nolang') {
1403: push(@currlangs,$key);
1404: }
1405: }
1406: } elsif ($settings->{'helpurl'} ne '') {
1407: $type{'nolang'} = 'custom';
1408: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1409: }
1410: }
1.160.6.5 raeburn 1411: foreach my $lang ('nolang',sort(@currlangs)) {
1412: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1413: $datatable .= '<tr'.$css_class.'>';
1414: if ($url{$lang} eq '') {
1415: $url{$lang} = $defaulturl;
1416: }
1417: if ($type{$lang} eq '') {
1418: $type{$lang} = $defaulttype;
1419: }
1420: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1421: if ($lang eq 'nolang') {
1422: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1423: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1424: } else {
1425: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1426: $langchoices{$lang},
1427: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1428: }
1429: $datatable .= '</span></td>'."\n".
1430: '<td class="LC_left_item">';
1431: if ($type{$lang} eq 'custom') {
1432: $datatable .= '<span class="LC_nobreak"><label>'.
1433: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1434: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1435: } else {
1436: $datatable .= $lt{'upl'};
1437: }
1438: $datatable .='<br />';
1439: if ($switchserver) {
1440: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1441: } else {
1442: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1443: }
1.160.6.5 raeburn 1444: $datatable .= '</td></tr>';
1445: $itemcount ++;
1.6 raeburn 1446: }
1.160.6.5 raeburn 1447: my @addlangs;
1448: foreach my $lang (sort(keys(%langchoices))) {
1449: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1450: push(@addlangs,$lang);
1451: }
1452: if (@addlangs > 0) {
1453: my %toadd;
1454: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1455: $toadd{''} = &mt('Select');
1456: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1457: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1458: &mt('Add log-in help page for a specific language:').' '.
1459: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1460: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1461: if ($switchserver) {
1462: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1463: } else {
1464: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1465: }
1.160.6.5 raeburn 1466: $datatable .= '</td></tr>';
1467: $itemcount ++;
1.6 raeburn 1468: }
1.160.6.5 raeburn 1469: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1470: } elsif ($caller eq 'headtag') {
1471: my %domservers = &Apache::lonnet::get_servers($dom);
1472: my $choice = $choices{'headtag'};
1473: $css_class = ' class="LC_odd_row"';
1474: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1475: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1476: '<th>'.$choices{'current'}.'</th>'.
1477: '<th>'.$choices{'action'}.'</th>'.
1478: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1479: my (%currurls,%currexempt);
1480: if (ref($settings) eq 'HASH') {
1481: if (ref($settings->{'headtag'}) eq 'HASH') {
1482: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1483: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1484: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1485: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1486: }
1487: }
1488: }
1489: }
1490: foreach my $lonhost (sort(keys(%domservers))) {
1491: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1492: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1493: if ($currurls{$lonhost}) {
1494: $datatable .= '<td class="LC_right_item"><a href="'.
1495: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1496: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1497: '">'.$lt{'curr'}.'</a></td>'.
1498: '<td><span class="LC_nobreak"><label>'.
1499: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1500: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1501: } else {
1502: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1503: }
1504: $datatable .='<br />';
1505: if ($switchserver) {
1506: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1507: } else {
1508: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1509: }
1.160.6.87 raeburn 1510: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1511: }
1512: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1513: } elsif ($caller eq 'saml') {
1514: my %domservers = &Apache::lonnet::get_servers($dom);
1515: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1516: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1517: '<th>'.$choices{'samllanding'}.'</th>'.
1518: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.160.6.118.2 9(raebur 1519:2): my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.160.6.113 raeburn 1520: foreach my $lonhost (keys(%domservers)) {
1521: $samlurl{$lonhost} = '/adm/sso';
1522: $styleon{$lonhost} = 'display:none';
1523: $styleoff{$lonhost} = '';
1524: }
1.160.6.118.2 11(raebu 1525:23): if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.160.6.113 raeburn 1526: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1527: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1528: $saml{$lonhost} = 1;
1529: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1530: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1531: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1532: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1533: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 1534:2): $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 1535: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1536: $styleon{$lonhost} = '';
1537: $styleoff{$lonhost} = 'display:none';
1538: } else {
1539: $styleon{$lonhost} = 'display:none';
1540: $styleoff{$lonhost} = '';
1541: }
1542: }
1543: }
1544: my $itemcount = 1;
1545: foreach my $lonhost (sort(keys(%domservers))) {
1546: my $samlon = ' ';
1547: my $samloff = ' checked="checked" ';
1548: if ($saml{$lonhost}) {
1549: $samlon = $samloff;
1550: $samloff = ' ';
1551: }
1.160.6.118.2 9(raebur 1552:2): my $samlwinon = '';
1553:2): my $samlwinoff = ' checked="checked"';
1554:2): if ($samlwindow{$lonhost}) {
1555:2): $samlwinon = $samlwinoff;
1556:2): $samlwinoff = '';
1557:2): }
1.160.6.113 raeburn 1558: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1559: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1560: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1561: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1562: &mt('No').'</label>'.(' 'x2).
1563: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1564: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1565: &mt('Yes').'</label></span></td>'.
1566: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.160.6.118.2 9(raebur 1567:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.160.6.113 raeburn 1568: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.160.6.118.2 9(raebur 1569:2): '<th>'.&mt('Alt Text').'</th></tr>'.
1570:2): '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.160.6.113 raeburn 1571: $samltext{$lonhost}.'" /></td><td>';
1572: if ($samlimg{$lonhost}) {
1573: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1574: '<span class="LC_nobreak"><label>'.
1575: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1576: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1577: } else {
1578: $datatable .= $lt{'upl'};
1579: }
1580: $datatable .='<br />';
1581: if ($switchserver) {
1582: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1583: } else {
1584: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1585: }
1586: $datatable .= '</td>'.
1.160.6.118.2 9(raebur 1587:2): '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1588:2): 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1589:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1590:2): '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1591:2): '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1592:2): '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1593:2): '<tr'.$css_class.'>'.
1594:2): '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.160.6.113 raeburn 1595: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.160.6.118.2 9(raebur 1596:2): '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.160.6.113 raeburn 1597: $samltitle{$lonhost}.'</textarea></td>'.
1.160.6.118.2 9(raebur 1598:2): '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1599:2): &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1600:2): 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1601:2): '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.160.6.113 raeburn 1602: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1603: '</table></td>'.
1604: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1605: $itemcount ++;
1606: }
1607: $datatable .= '</table></td></tr>';
1.1 raeburn 1608: }
1.6 raeburn 1609: return $datatable;
1610: }
1611:
1612: sub login_choices {
1613: my %choices =
1614: &Apache::lonlocal::texthash (
1.116 bisitz 1615: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1616: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1617: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1618: disallowlogin => "Login page requests redirected",
1619: hostid => "Server",
1.128 raeburn 1620: server => "Redirect to:",
1621: serverpath => "Path",
1622: custompath => "Custom",
1623: exempt => "Exempt IP(s)",
1.110 raeburn 1624: directlogin => "No redirect",
1625: newuser => "Link to create a user account",
1626: img => "Header",
1627: logo => "Main Logo",
1628: domlogo => "Domain Logo",
1629: login => "Log-in Header",
1630: textcol => "Text color",
1631: bgcol => "Box color",
1632: bgs => "Background colors",
1633: links => "Link colors",
1634: font => "Font color",
1635: pgbg => "Header",
1636: mainbg => "Page",
1637: sidebg => "Login box",
1638: link => "Link",
1639: alink => "Active link",
1640: vlink => "Visited link",
1.160.6.56 raeburn 1641: headtag => "Custom markup",
1642: action => "Action",
1643: current => "Current",
1.160.6.113 raeburn 1644: samllanding => "Dual login?",
1645: samloptions => "Options",
1.160.6.118.2 2(raebur 1646:2): alttext => "Alt text",
1.6 raeburn 1647: );
1648: return %choices;
1649: }
1650:
1.160.6.113 raeburn 1651: sub login_file_options {
1652: return &Apache::lonlocal::texthash(
1653: del => 'Delete?',
1654: rep => 'Replace:',
1655: upl => 'Upload:',
1656: curr => 'View contents',
1657: default => 'Default',
1658: custom => 'Custom',
1659: none => 'None',
1660: );
1661: }
1662:
1663: sub print_ipaccess {
1664: my ($dom,$settings,$rowtotal) = @_;
1665: my $css_class;
1666: my $itemcount = 0;
1667: my $datatable;
1668: my %ordered;
1669: if (ref($settings) eq 'HASH') {
1670: foreach my $item (keys(%{$settings})) {
1671: if (ref($settings->{$item}) eq 'HASH') {
1672: my $num = $settings->{$item}{'order'};
1673: if ($num eq '') {
1674: $num = scalar(keys(%{$settings}));
1675: }
1676: $ordered{$num} = $item;
1677: }
1678: }
1679: }
1680: my $maxnum = scalar(keys(%ordered));
1681: if (keys(%ordered)) {
1682: my @items = sort { $a <=> $b } keys(%ordered);
1683: for (my $i=0; $i<@items; $i++) {
1684: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1685: my $item = $ordered{$items[$i]};
1686: my ($name,$ipranges,%commblocks,%courses);
1687: if (ref($settings->{$item}) eq 'HASH') {
1688: $name = $settings->{$item}->{'name'};
1689: $ipranges = $settings->{$item}->{'ip'};
1690: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1691: %commblocks = %{$settings->{$item}->{'commblocks'}};
1692: }
1693: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1694: %courses = %{$settings->{$item}->{'courses'}};
1695: }
1696: }
1697: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1698: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1699: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1700: for (my $k=0; $k<=$maxnum; $k++) {
1701: my $vpos = $k+1;
1702: my $selstr;
1703: if ($k == $i) {
1704: $selstr = ' selected="selected" ';
1705: }
1706: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1707: }
1708: $datatable .= '</select>'.(' 'x2).
1709: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1710: &mt('Delete?').'</label></span></td>'.
1711: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1712: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1713: '</td></tr>';
1714: $itemcount ++;
1715: }
1716: }
1717: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1718: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1719: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1720: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1721: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1722: for (my $k=0; $k<$maxnum+1; $k++) {
1723: my $vpos = $k+1;
1724: my $selstr;
1725: if ($k == $maxnum) {
1726: $selstr = ' selected="selected" ';
1727: }
1728: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1729: }
1730: $datatable .= '</select> '."\n".
1731: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1732: '<td colspan="2">'.
1733: &ipaccess_options('add',$itemcount,$dom).
1734: '</td>'."\n".
1735: '</tr>'."\n";
1736: $$rowtotal ++;
1737: return $datatable;
1738: }
1739:
1740: sub ipaccess_options {
1741: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1742: my (%currblocks,%currcourses,$output);
1743: if (ref($blocksref) eq 'HASH') {
1744: %currblocks = %{$blocksref};
1745: }
1746: if (ref($coursesref) eq 'HASH') {
1747: %currcourses = %{$coursesref};
1748: }
1749: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1750: '<span class="LC_nobreak">'.&mt('Name').': '.
1751: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1752: '</span></fieldset>'.
1753: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1754: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1755: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1756: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1757: $ipranges.'</textarea></fieldset>'.
1758: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1759: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1760: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1761: '<table>';
1762: foreach my $cid (sort(keys(%currcourses))) {
1763: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1764: $output .= '<tr><td><span class="LC_nobreak">'.
1765: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1766: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1767: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1768: }
1769: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1770: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1771: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1772: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1773: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1774: '</span></td></tr></table>'."\n".
1775: '</fieldset>';
1776: return $output;
1777: }
1778:
1779: sub blocker_checkboxes {
1780: my ($num,$blocks) = @_;
1781: my ($typeorder,$types) = &commblocktype_text();
1782: my $numinrow = 6;
1783: my $output = '<table>';
1784: for (my $i=0; $i<@{$typeorder}; $i++) {
1785: my $block = $typeorder->[$i];
1786: my $blockstatus;
1787: if (ref($blocks) eq 'HASH') {
1788: if ($blocks->{$block} eq 'on') {
1789: $blockstatus = 'checked="checked"';
1790: }
1791: }
1792: my $rem = $i%($numinrow);
1793: if ($rem == 0) {
1794: if ($i > 0) {
1795: $output .= '</tr>';
1796: }
1797: $output .= '<tr>';
1798: }
1799: if ($i == scalar(@{$typeorder})-1) {
1800: my $colsleft = $numinrow-$rem;
1801: if ($colsleft > 1) {
1802: $output .= '<td colspan="'.$colsleft.'">';
1803: } else {
1804: $output .= '<td>';
1805: }
1806: } else {
1807: $output .= '<td>';
1808: }
1809: my $item = 'ipaccess_block_'.$num;
1810: if ($blockstatus) {
1811: $blockstatus = ' '.$blockstatus;
1812: }
1813: $output .= '<span class="LC_nobreak"><label>'."\n".
1814: '<input type="checkbox" name="'.$item.'"'.
1815: $blockstatus.' value="'.$block.'"'.' />'.
1816: $types->{$block}.'</label></span>'."\n".
1817: '<br /></td>';
1818: }
1819: $output .= '</tr></table>';
1820: return $output;
1821: }
1822:
1823: sub commblocktype_text {
1824: my %types = &Apache::lonlocal::texthash(
1825: 'com' => 'Messaging',
1826: 'chat' => 'Chat Room',
1827: 'boards' => 'Discussion',
1828: 'port' => 'Portfolio',
1829: 'groups' => 'Groups',
1830: 'blogs' => 'Blogs',
1831: 'about' => 'User Information',
1832: 'printout' => 'Printouts',
1833: 'passwd' => 'Change Password',
1834: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1835: 'search' => 'Course search',
1836: 'wishlist' => 'Stored links',
1837: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1838: );
1.160.6.115 raeburn 1839: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1840: return ($typeorder,\%types);
1841: }
1842:
1.6 raeburn 1843: sub print_rolecolors {
1.30 raeburn 1844: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1845: my %choices = &color_font_choices();
1846: my @bgs = ('pgbg','tabbg','sidebg');
1847: my @links = ('link','alink','vlink');
1848: my @images = ('img');
1849: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1850: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1851: my %defaultdesign = %Apache::loncommon::defaultdesign;
1852: my (%is_custom,%designs);
1.160.6.22 raeburn 1853: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1854: if (ref($settings) eq 'HASH') {
1855: if (ref($settings->{$role}) eq 'HASH') {
1856: if ($settings->{$role}->{'img'} ne '') {
1857: $designs{'img'} = $settings->{$role}->{'img'};
1858: $is_custom{'img'} = 1;
1859: }
1860: if ($settings->{$role}->{'font'} ne '') {
1861: $designs{'font'} = $settings->{$role}->{'font'};
1862: $is_custom{'font'} = 1;
1863: }
1.97 tempelho 1864: if ($settings->{$role}->{'fontmenu'} ne '') {
1865: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1866: $is_custom{'fontmenu'} = 1;
1867: }
1.6 raeburn 1868: foreach my $item (@bgs) {
1869: if ($settings->{$role}->{$item} ne '') {
1870: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1871: $is_custom{$item} = 1;
1872: }
1873: }
1874: foreach my $item (@links) {
1875: if ($settings->{$role}->{$item} ne '') {
1876: $designs{'links'}{$item} = $settings->{$role}->{$item};
1877: $is_custom{$item} = 1;
1878: }
1879: }
1880: }
1881: } else {
1882: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1883: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1884: $is_custom{'img'} = 1;
1885: }
1.97 tempelho 1886: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1887: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1888: $is_custom{'fontmenu'} = 1;
1889: }
1.6 raeburn 1890: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1891: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1892: $is_custom{'font'} = 1;
1893: }
1894: foreach my $item (@bgs) {
1895: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1896: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1897: $is_custom{$item} = 1;
1898:
1899: }
1900: }
1901: foreach my $item (@links) {
1902: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1903: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1904: $is_custom{$item} = 1;
1905: }
1906: }
1907: }
1908: my $itemcount = 1;
1.30 raeburn 1909: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1910: $datatable .= '</tr></table></td></tr>';
1911: return $datatable;
1912: }
1913:
1.160.6.22 raeburn 1914: sub role_defaults {
1915: my ($role,$bgs,$links,$images,$logintext) = @_;
1916: my %defaults;
1917: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1918: return %defaults;
1919: }
1920: my %defaultdesign = %Apache::loncommon::defaultdesign;
1921: if ($role eq 'login') {
1922: %defaults = (
1923: font => $defaultdesign{$role.'.font'},
1924: );
1925: if (ref($logintext) eq 'ARRAY') {
1926: foreach my $item (@{$logintext}) {
1927: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1928: }
1929: }
1930: foreach my $item (@{$images}) {
1931: $defaults{'showlogo'}{$item} = 1;
1932: }
1933: } else {
1934: %defaults = (
1935: img => $defaultdesign{$role.'.img'},
1936: font => $defaultdesign{$role.'.font'},
1937: fontmenu => $defaultdesign{$role.'.fontmenu'},
1938: );
1939: }
1940: foreach my $item (@{$bgs}) {
1941: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1942: }
1943: foreach my $item (@{$links}) {
1944: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1945: }
1946: foreach my $item (@{$images}) {
1947: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1948: }
1949: return %defaults;
1950: }
1951:
1.6 raeburn 1952: sub display_color_options {
1.9 raeburn 1953: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1954: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1955: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1956: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1957: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1958: '<td>'.$choices->{'font'}.'</td>';
1959: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1960: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1961: } else {
1962: $datatable .= '<td> </td>';
1963: }
1.160.6.9 raeburn 1964: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1965:
1.8 raeburn 1966: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1967: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1968: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1969: ' </span></td></tr>';
1.107 raeburn 1970: unless ($role eq 'login') {
1971: $datatable .= '<tr'.$css_class.'>'.
1972: '<td>'.$choices->{'fontmenu'}.'</td>';
1973: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1974: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1975: } else {
1976: $datatable .= '<td> </td>';
1977: }
1.160.6.22 raeburn 1978: $current_color = $designs->{'fontmenu'} ?
1979: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 1980: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1981: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 1982: .$role.'_fontmenu"'.
1.160.6.9 raeburn 1983: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1984: ' </span></td></tr>';
1.97 tempelho 1985: }
1.9 raeburn 1986: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 1987: foreach my $img (@{$images}) {
1.18 albertel 1988: $itemcount ++;
1.6 raeburn 1989: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 1990: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 1991: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 1992:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 1993: if ($role eq 'login') {
1994: if ($img eq 'login') {
1995: $login_hdr_pick =
1.135 bisitz 1996: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 1997: $logincolors =
1998: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 1999: $designs,$defaults);
1.160.6.118.2 2(raebur 2000:2): } else {
2001:2): if ($img ne 'domlogo') {
2002:2): $datatable.= &logo_display_options($img,$defaults,$designs);
2003:2): }
2004:2): if (ref($designs->{'alttext'}) eq 'HASH') {
2005:2): $alttext = $designs->{'alttext'}{$img};
2006:2): }
1.70 raeburn 2007: }
2008: }
2009: $datatable .= '</td>';
1.6 raeburn 2010: if ($designs->{$img} ne '') {
2011: $imgfile = $designs->{$img};
1.18 albertel 2012: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2013: } else {
2014: $imgfile = $defaults->{$img};
2015: }
2016: if ($imgfile) {
1.9 raeburn 2017: my ($showfile,$fullsize);
2018: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2019: my $urldir = $1;
2020: my $filename = $2;
2021: my @info = &Apache::lonnet::stat_file($designs->{$img});
2022: if (@info) {
2023: my $thumbfile = 'tn-'.$filename;
2024: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2025: if (@thumb) {
2026: $showfile = $urldir.'/'.$thumbfile;
2027: } else {
2028: $showfile = $imgfile;
2029: }
2030: } else {
2031: $showfile = '';
2032: }
2033: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2034: $showfile = $imgfile;
1.6 raeburn 2035: my $imgdir = $1;
2036: my $filename = $2;
1.159 raeburn 2037: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2038: $showfile = "/$imgdir/tn-".$filename;
2039: } else {
1.159 raeburn 2040: my $input = $londocroot.$imgfile;
2041: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2042: if (!-e $output) {
1.9 raeburn 2043: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2044: my ($fullwidth,$fullheight) = &check_dimensions($input);
2045: if ($fullwidth ne '' && $fullheight ne '') {
2046: if ($fullwidth > $width && $fullheight > $height) {
2047: my $size = $width.'x'.$height;
1.160.6.88 raeburn 2048: my @args = ('convert','-sample',$size,$input,$output);
2049: system({$args[0]} @args);
1.159 raeburn 2050: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2051: }
2052: }
1.6 raeburn 2053: }
2054: }
1.16 raeburn 2055: }
1.6 raeburn 2056: if ($showfile) {
1.40 raeburn 2057: if ($showfile =~ m{^/(adm|res)/}) {
2058: if ($showfile =~ m{^/res/}) {
2059: my $local_showfile =
2060: &Apache::lonnet::filelocation('',$showfile);
2061: &Apache::lonnet::repcopy($local_showfile);
2062: }
2063: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2064: }
2065: if ($imgfile) {
2066: if ($imgfile =~ m{^/(adm|res)/}) {
2067: if ($imgfile =~ m{^/res/}) {
2068: my $local_imgfile =
2069: &Apache::lonnet::filelocation('',$imgfile);
2070: &Apache::lonnet::repcopy($local_imgfile);
2071: }
2072: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2073: } else {
2074: $fullsize = $imgfile;
2075: }
2076: }
1.41 raeburn 2077: $datatable .= '<td>';
2078: if ($img eq 'login') {
1.135 bisitz 2079: $datatable .= $login_hdr_pick;
2080: }
1.41 raeburn 2081: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2082: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2083: } else {
1.160.6.22 raeburn 2084: $datatable .= '<td> </td><td class="LC_left_item">'.
2085: &mt('Upload:').'<br />';
1.6 raeburn 2086: }
2087: } else {
1.160.6.22 raeburn 2088: $datatable .= '<td> </td><td class="LC_left_item">'.
2089: &mt('Upload:').'<br />';
1.6 raeburn 2090: }
1.9 raeburn 2091: if ($switchserver) {
2092: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2093: } else {
1.135 bisitz 2094: if ($img ne 'login') { # suppress file selection for Log-in header
2095: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2096: }
1.9 raeburn 2097: }
1.160.6.118.2 2(raebur 2098:2): if (($role eq 'login') && ($img ne 'login')) {
2099:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2100:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2101:2): '</label></span>';
2102:2): }
1.9 raeburn 2103: $datatable .= '</td></tr>';
1.6 raeburn 2104: }
2105: $itemcount ++;
2106: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2107: $datatable .= '<tr'.$css_class.'>'.
2108: '<td>'.$choices->{'bgs'}.'</td>';
2109: my $bgs_def;
2110: foreach my $item (@{$bgs}) {
2111: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2112: $bgs_def .= '<td><span class="LC_nobreak">'.$choices->{$item}.'</span> <span class="css_default_'.$role.'_'.$item.'" style="background-color: '.$defaults->{'bgs'}{$item}.';"> </span><br />'.$defaults->{'bgs'}{$item}.'</td>';
1.6 raeburn 2113: }
2114: }
2115: if ($bgs_def) {
1.8 raeburn 2116: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2117: } else {
2118: $datatable .= '<td> </td>';
2119: }
2120: $datatable .= '<td class="LC_right_item">'.
2121: '<table border="0"><tr>';
1.160.6.13 raeburn 2122:
1.6 raeburn 2123: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2124: $datatable .= '<td align="center">'.$choices->{$item};
2125: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2126: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2127: $datatable .= ' ';
1.6 raeburn 2128: }
1.160.6.9 raeburn 2129: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2130: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2131: }
2132: $datatable .= '</tr></table></td></tr>';
2133: $itemcount ++;
2134: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2135: $datatable .= '<tr'.$css_class.'>'.
2136: '<td>'.$choices->{'links'}.'</td>';
2137: my $links_def;
2138: foreach my $item (@{$links}) {
2139: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2140: $links_def .= '<td>'.$choices->{$item}.'<br /><span class="css_default_'.$role.'_'.$item.'" style="color: '.$defaults->{'links'}{$item}.';">'.$defaults->{'links'}{$item}.'</span></td>';
1.6 raeburn 2141: }
2142: }
2143: if ($links_def) {
1.8 raeburn 2144: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2145: } else {
2146: $datatable .= '<td> </td>';
2147: }
2148: $datatable .= '<td class="LC_right_item">'.
2149: '<table border="0"><tr>';
2150: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2151: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2152: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2153: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2154: $datatable.=' ';
1.6 raeburn 2155: }
1.160.6.9 raeburn 2156: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2157: '" /></td>';
2158: }
1.30 raeburn 2159: $$rowtotal += $itemcount;
1.3 raeburn 2160: return $datatable;
2161: }
2162:
1.70 raeburn 2163: sub logo_display_options {
2164: my ($img,$defaults,$designs) = @_;
2165: my $checkedon;
2166: if (ref($defaults) eq 'HASH') {
2167: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2168: if ($defaults->{'showlogo'}{$img}) {
2169: $checkedon = 'checked="checked" ';
2170: }
2171: }
2172: }
2173: if (ref($designs) eq 'HASH') {
2174: if (ref($designs->{'showlogo'}) eq 'HASH') {
2175: if (defined($designs->{'showlogo'}{$img})) {
2176: if ($designs->{'showlogo'}{$img} == 0) {
2177: $checkedon = '';
2178: } elsif ($designs->{'showlogo'}{$img} == 1) {
2179: $checkedon = 'checked="checked" ';
2180: }
2181: }
2182: }
2183: }
2184: return '<br /><label> <input type="checkbox" name="'.
2185: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2186: &mt('show').'</label>'."\n";
2187: }
2188:
1.41 raeburn 2189: sub login_header_options {
1.135 bisitz 2190: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2191: my $output = '';
1.41 raeburn 2192: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2193: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2194: if (!$is_custom->{'textcol'}) {
2195: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2196: ' ';
2197: }
2198: if (!$is_custom->{'bgcol'}) {
2199: $output .= $choices->{'bgcol'}.': '.
2200: '<span id="css_'.$role.'_font" style="background-color: '.
2201: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2202: }
2203: $output .= '<br />';
2204: }
2205: $output .='<br />';
2206: return $output;
2207: }
2208:
2209: sub login_text_colors {
1.160.6.22 raeburn 2210: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2211: my $color_menu = '<table border="0"><tr>';
2212: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2213: $color_menu .= '<td align="center">'.$choices->{$item};
2214: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2215: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2216: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2217: }
2218: $color_menu .= '</tr></table><br />';
2219: return $color_menu;
2220: }
2221:
2222: sub image_changes {
2223: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2224: my $output;
1.135 bisitz 2225: if ($img eq 'login') {
1.160.6.87 raeburn 2226: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2227: } elsif (!$is_custom) {
1.70 raeburn 2228: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2229: $output = &mt('Default image:').'<br />';
1.41 raeburn 2230: } else {
1.160.6.87 raeburn 2231: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2232: }
2233: }
1.160.6.87 raeburn 2234: if ($img ne 'login') {
1.135 bisitz 2235: if ($img_import) {
2236: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2237: }
2238: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2239: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2240: if ($is_custom) {
2241: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2242: '<input type="checkbox" name="'.
2243: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2244: '</label> '.&mt('Replace:').'</span><br />';
2245: } else {
1.160.6.22 raeburn 2246: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2247: }
1.41 raeburn 2248: }
2249: return $output;
2250: }
2251:
1.3 raeburn 2252: sub print_quotas {
1.86 raeburn 2253: my ($dom,$settings,$rowtotal,$action) = @_;
2254: my $context;
2255: if ($action eq 'quotas') {
2256: $context = 'tools';
2257: } else {
2258: $context = $action;
2259: }
1.160.6.20 raeburn 2260: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2261: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2262: my $typecount = 0;
1.101 raeburn 2263: my ($css_class,%titles);
1.86 raeburn 2264: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 2265:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 2266: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2267: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2268: %titles = &courserequest_titles();
1.160.6.5 raeburn 2269: } elsif ($context eq 'requestauthor') {
2270: @usertools = ('author');
2271: @options = ('norequest','approval','automatic');
2272: %titles = &authorrequest_titles();
1.86 raeburn 2273: } else {
1.160.6.118.2 10(raebu 2274:22): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2275: %titles = &tool_titles();
1.86 raeburn 2276: }
1.26 raeburn 2277: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2278: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2279: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2280: unless (($context eq 'requestcourses') ||
2281: ($context eq 'requestauthor')) {
1.86 raeburn 2282: if (ref($settings) eq 'HASH') {
2283: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2284: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2285: } else {
2286: $currdefquota = $settings->{$type};
2287: }
1.160.6.20 raeburn 2288: if (ref($settings->{authorquota}) eq 'HASH') {
2289: $currauthorquota = $settings->{authorquota}->{$type};
2290: }
1.78 raeburn 2291: }
1.72 raeburn 2292: }
1.3 raeburn 2293: if (defined($usertypes->{$type})) {
2294: $typecount ++;
2295: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2296: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2297: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2298: '<td class="LC_left_item">';
1.101 raeburn 2299: if ($context eq 'requestcourses') {
2300: $datatable .= '<table><tr>';
2301: }
2302: my %cell;
1.72 raeburn 2303: foreach my $item (@usertools) {
1.101 raeburn 2304: if ($context eq 'requestcourses') {
2305: my ($curroption,$currlimit);
2306: if (ref($settings) eq 'HASH') {
2307: if (ref($settings->{$item}) eq 'HASH') {
2308: $curroption = $settings->{$item}->{$type};
2309: if ($curroption =~ /^autolimit=(\d*)$/) {
2310: $currlimit = $1;
2311: }
2312: }
2313: }
2314: if (!$curroption) {
2315: $curroption = 'norequest';
2316: }
2317: $datatable .= '<th>'.$titles{$item}.'</th>';
2318: foreach my $option (@options) {
2319: my $val = $option;
2320: if ($option eq 'norequest') {
2321: $val = 0;
2322: }
2323: if ($option eq 'validate') {
2324: my $canvalidate = 0;
2325: if (ref($validations{$item}) eq 'HASH') {
2326: if ($validations{$item}{$type}) {
2327: $canvalidate = 1;
2328: }
2329: }
2330: next if (!$canvalidate);
2331: }
2332: my $checked = '';
2333: if ($option eq $curroption) {
2334: $checked = ' checked="checked"';
2335: } elsif ($option eq 'autolimit') {
2336: if ($curroption =~ /^autolimit/) {
2337: $checked = ' checked="checked"';
2338: }
2339: }
2340: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2341: '<input type="radio" name="crsreq_'.$item.
2342: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2343: $titles{$option}.'</label>';
1.101 raeburn 2344: if ($option eq 'autolimit') {
1.127 raeburn 2345: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2346: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2347: 'value="'.$currlimit.'" />';
1.101 raeburn 2348: }
1.127 raeburn 2349: $cell{$item} .= '</span> ';
1.103 raeburn 2350: if ($option eq 'autolimit') {
1.127 raeburn 2351: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2352: }
1.101 raeburn 2353: }
1.160.6.5 raeburn 2354: } elsif ($context eq 'requestauthor') {
2355: my $curroption;
2356: if (ref($settings) eq 'HASH') {
2357: $curroption = $settings->{$type};
2358: }
2359: if (!$curroption) {
2360: $curroption = 'norequest';
2361: }
2362: foreach my $option (@options) {
2363: my $val = $option;
2364: if ($option eq 'norequest') {
2365: $val = 0;
2366: }
2367: my $checked = '';
2368: if ($option eq $curroption) {
2369: $checked = ' checked="checked"';
2370: }
2371: $datatable .= '<span class="LC_nobreak"><label>'.
2372: '<input type="radio" name="authorreq_'.$type.
2373: '" value="'.$val.'"'.$checked.' />'.
2374: $titles{$option}.'</label></span> ';
2375: }
1.101 raeburn 2376: } else {
2377: my $checked = 'checked="checked" ';
1.160.6.118.2 10(raebu 2378:22): if ($item eq 'timezone') {
2379:22): $checked = '';
2380:22): }
1.101 raeburn 2381: if (ref($settings) eq 'HASH') {
2382: if (ref($settings->{$item}) eq 'HASH') {
1.160.6.118.2 10(raebu 2383:22): if (!$settings->{$item}->{$type}) {
1.101 raeburn 2384: $checked = '';
2385: } elsif ($settings->{$item}->{$type} == 1) {
2386: $checked = 'checked="checked" ';
2387: }
1.78 raeburn 2388: }
1.72 raeburn 2389: }
1.101 raeburn 2390: $datatable .= '<span class="LC_nobreak"><label>'.
2391: '<input type="checkbox" name="'.$context.'_'.$item.
2392: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2393: '</label></span> ';
1.72 raeburn 2394: }
1.101 raeburn 2395: }
2396: if ($context eq 'requestcourses') {
2397: $datatable .= '</tr><tr>';
2398: foreach my $item (@usertools) {
1.106 raeburn 2399: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2400: }
2401: $datatable .= '</tr></table>';
1.72 raeburn 2402: }
1.86 raeburn 2403: $datatable .= '</td>';
1.160.6.5 raeburn 2404: unless (($context eq 'requestcourses') ||
2405: ($context eq 'requestauthor')) {
1.86 raeburn 2406: $datatable .=
1.160.6.20 raeburn 2407: '<td class="LC_right_item">'.
2408: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2409: '<input type="text" name="quota_'.$type.
1.72 raeburn 2410: '" value="'.$currdefquota.
1.160.6.20 raeburn 2411: '" size="5" /></span>'.(' ' x 2).
2412: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2413: '<input type="text" name="authorquota_'.$type.
2414: '" value="'.$currauthorquota.
2415: '" size="5" /></span></td>';
1.86 raeburn 2416: }
2417: $datatable .= '</tr>';
1.3 raeburn 2418: }
2419: }
2420: }
1.160.6.5 raeburn 2421: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2422: $defaultquota = '20';
1.160.6.20 raeburn 2423: $authorquota = '500';
1.86 raeburn 2424: if (ref($settings) eq 'HASH') {
2425: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2426: $defaultquota = $settings->{'defaultquota'}->{'default'};
2427: } elsif (defined($settings->{'default'})) {
2428: $defaultquota = $settings->{'default'};
2429: }
1.160.6.20 raeburn 2430: if (ref($settings->{'authorquota'}) eq 'HASH') {
2431: $authorquota = $settings->{'authorquota'}->{'default'};
2432: }
1.3 raeburn 2433: }
2434: }
2435: $typecount ++;
2436: $css_class = $typecount%2?' class="LC_odd_row"':'';
2437: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2438: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2439: '<td class="LC_left_item">';
1.101 raeburn 2440: if ($context eq 'requestcourses') {
2441: $datatable .= '<table><tr>';
2442: }
2443: my %defcell;
1.72 raeburn 2444: foreach my $item (@usertools) {
1.101 raeburn 2445: if ($context eq 'requestcourses') {
2446: my ($curroption,$currlimit);
2447: if (ref($settings) eq 'HASH') {
2448: if (ref($settings->{$item}) eq 'HASH') {
2449: $curroption = $settings->{$item}->{'default'};
2450: if ($curroption =~ /^autolimit=(\d*)$/) {
2451: $currlimit = $1;
2452: }
2453: }
2454: }
2455: if (!$curroption) {
2456: $curroption = 'norequest';
2457: }
2458: $datatable .= '<th>'.$titles{$item}.'</th>';
2459: foreach my $option (@options) {
2460: my $val = $option;
2461: if ($option eq 'norequest') {
2462: $val = 0;
2463: }
2464: if ($option eq 'validate') {
2465: my $canvalidate = 0;
2466: if (ref($validations{$item}) eq 'HASH') {
2467: if ($validations{$item}{'default'}) {
2468: $canvalidate = 1;
2469: }
2470: }
2471: next if (!$canvalidate);
2472: }
2473: my $checked = '';
2474: if ($option eq $curroption) {
2475: $checked = ' checked="checked"';
2476: } elsif ($option eq 'autolimit') {
2477: if ($curroption =~ /^autolimit/) {
2478: $checked = ' checked="checked"';
2479: }
2480: }
2481: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2482: '<input type="radio" name="crsreq_'.$item.
2483: '_default" value="'.$val.'"'.$checked.' />'.
2484: $titles{$option}.'</label>';
2485: if ($option eq 'autolimit') {
1.127 raeburn 2486: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2487: $item.'_limit_default" size="1" '.
2488: 'value="'.$currlimit.'" />';
2489: }
1.127 raeburn 2490: $defcell{$item} .= '</span> ';
1.104 raeburn 2491: if ($option eq 'autolimit') {
1.127 raeburn 2492: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2493: }
1.101 raeburn 2494: }
1.160.6.5 raeburn 2495: } elsif ($context eq 'requestauthor') {
2496: my $curroption;
2497: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2498: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2499: }
2500: if (!$curroption) {
2501: $curroption = 'norequest';
2502: }
2503: foreach my $option (@options) {
2504: my $val = $option;
2505: if ($option eq 'norequest') {
2506: $val = 0;
2507: }
2508: my $checked = '';
2509: if ($option eq $curroption) {
2510: $checked = ' checked="checked"';
2511: }
2512: $datatable .= '<span class="LC_nobreak"><label>'.
2513: '<input type="radio" name="authorreq_default"'.
2514: ' value="'.$val.'"'.$checked.' />'.
2515: $titles{$option}.'</label></span> ';
2516: }
1.101 raeburn 2517: } else {
2518: my $checked = 'checked="checked" ';
2519: if (ref($settings) eq 'HASH') {
2520: if (ref($settings->{$item}) eq 'HASH') {
2521: if ($settings->{$item}->{'default'} == 0) {
2522: $checked = '';
2523: } elsif ($settings->{$item}->{'default'} == 1) {
2524: $checked = 'checked="checked" ';
2525: }
1.78 raeburn 2526: }
1.72 raeburn 2527: }
1.101 raeburn 2528: $datatable .= '<span class="LC_nobreak"><label>'.
2529: '<input type="checkbox" name="'.$context.'_'.$item.
2530: '" value="default" '.$checked.'/>'.$titles{$item}.
2531: '</label></span> ';
2532: }
2533: }
2534: if ($context eq 'requestcourses') {
2535: $datatable .= '</tr><tr>';
2536: foreach my $item (@usertools) {
1.106 raeburn 2537: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2538: }
1.101 raeburn 2539: $datatable .= '</tr></table>';
1.72 raeburn 2540: }
1.86 raeburn 2541: $datatable .= '</td>';
1.160.6.5 raeburn 2542: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2543: $datatable .= '<td class="LC_right_item">'.
2544: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2545: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2546: $defaultquota.'" size="5" /></span>'.(' ' x2).
2547: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2548: '<input type="text" name="authorquota" value="'.
2549: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2550: }
2551: $datatable .= '</tr>';
1.72 raeburn 2552: $typecount ++;
2553: $css_class = $typecount%2?' class="LC_odd_row"':'';
2554: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2555: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2556: if ($context eq 'requestcourses') {
1.109 raeburn 2557: $datatable .= &mt('(overrides affiliation, if set)').
2558: '</td>'.
2559: '<td class="LC_left_item">'.
2560: '<table><tr>';
1.101 raeburn 2561: } else {
1.109 raeburn 2562: $datatable .= &mt('(overrides affiliation, if checked)').
2563: '</td>'.
2564: '<td class="LC_left_item" colspan="2">'.
2565: '<br />';
1.101 raeburn 2566: }
2567: my %advcell;
1.72 raeburn 2568: foreach my $item (@usertools) {
1.101 raeburn 2569: if ($context eq 'requestcourses') {
2570: my ($curroption,$currlimit);
2571: if (ref($settings) eq 'HASH') {
2572: if (ref($settings->{$item}) eq 'HASH') {
2573: $curroption = $settings->{$item}->{'_LC_adv'};
2574: if ($curroption =~ /^autolimit=(\d*)$/) {
2575: $currlimit = $1;
2576: }
2577: }
2578: }
2579: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2580: my $checked = '';
2581: if ($curroption eq '') {
2582: $checked = ' checked="checked"';
2583: }
2584: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2585: '<input type="radio" name="crsreq_'.$item.
2586: '__LC_adv" value=""'.$checked.' />'.
2587: &mt('No override set').'</label></span> ';
1.101 raeburn 2588: foreach my $option (@options) {
2589: my $val = $option;
2590: if ($option eq 'norequest') {
2591: $val = 0;
2592: }
2593: if ($option eq 'validate') {
2594: my $canvalidate = 0;
2595: if (ref($validations{$item}) eq 'HASH') {
2596: if ($validations{$item}{'_LC_adv'}) {
2597: $canvalidate = 1;
2598: }
2599: }
2600: next if (!$canvalidate);
2601: }
2602: my $checked = '';
1.104 raeburn 2603: if ($val eq $curroption) {
1.101 raeburn 2604: $checked = ' checked="checked"';
2605: } elsif ($option eq 'autolimit') {
2606: if ($curroption =~ /^autolimit/) {
2607: $checked = ' checked="checked"';
2608: }
2609: }
2610: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2611: '<input type="radio" name="crsreq_'.$item.
2612: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2613: $titles{$option}.'</label>';
2614: if ($option eq 'autolimit') {
1.127 raeburn 2615: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2616: $item.'_limit__LC_adv" size="1" '.
2617: 'value="'.$currlimit.'" />';
2618: }
1.127 raeburn 2619: $advcell{$item} .= '</span> ';
1.104 raeburn 2620: if ($option eq 'autolimit') {
1.127 raeburn 2621: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2622: }
1.101 raeburn 2623: }
1.160.6.5 raeburn 2624: } elsif ($context eq 'requestauthor') {
2625: my $curroption;
2626: if (ref($settings) eq 'HASH') {
2627: $curroption = $settings->{'_LC_adv'};
2628: }
2629: my $checked = '';
2630: if ($curroption eq '') {
2631: $checked = ' checked="checked"';
2632: }
2633: $datatable .= '<span class="LC_nobreak"><label>'.
2634: '<input type="radio" name="authorreq__LC_adv"'.
2635: ' value=""'.$checked.' />'.
2636: &mt('No override set').'</label></span> ';
2637: foreach my $option (@options) {
2638: my $val = $option;
2639: if ($option eq 'norequest') {
2640: $val = 0;
2641: }
2642: my $checked = '';
2643: if ($val eq $curroption) {
2644: $checked = ' checked="checked"';
2645: }
2646: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2647: '<input type="radio" name="authorreq__LC_adv"'.
2648: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2649: $titles{$option}.'</label></span> ';
2650: }
1.101 raeburn 2651: } else {
2652: my $checked = 'checked="checked" ';
2653: if (ref($settings) eq 'HASH') {
2654: if (ref($settings->{$item}) eq 'HASH') {
2655: if ($settings->{$item}->{'_LC_adv'} == 0) {
2656: $checked = '';
2657: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2658: $checked = 'checked="checked" ';
2659: }
1.79 raeburn 2660: }
1.72 raeburn 2661: }
1.101 raeburn 2662: $datatable .= '<span class="LC_nobreak"><label>'.
2663: '<input type="checkbox" name="'.$context.'_'.$item.
2664: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2665: '</label></span> ';
2666: }
2667: }
2668: if ($context eq 'requestcourses') {
2669: $datatable .= '</tr><tr>';
2670: foreach my $item (@usertools) {
1.106 raeburn 2671: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2672: }
1.101 raeburn 2673: $datatable .= '</tr></table>';
1.72 raeburn 2674: }
1.98 raeburn 2675: $datatable .= '</td></tr>';
1.30 raeburn 2676: $$rowtotal += $typecount;
1.3 raeburn 2677: return $datatable;
2678: }
2679:
1.160.6.5 raeburn 2680: sub print_requestmail {
1.160.6.93 raeburn 2681: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2682: my ($now,$datatable,%currapp);
1.102 raeburn 2683: $now = time;
2684: if (ref($settings) eq 'HASH') {
2685: if (ref($settings->{'notify'}) eq 'HASH') {
2686: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2687: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2688: }
2689: }
2690: }
1.160.6.16 raeburn 2691: my $numinrow = 2;
1.160.6.34 raeburn 2692: my $css_class;
1.160.6.93 raeburn 2693: if ($$rowtotal%2) {
2694: $css_class = 'LC_odd_row';
2695: }
2696: if ($customcss) {
2697: $css_class .= " $customcss";
2698: }
2699: $css_class =~ s/^\s+//;
2700: if ($css_class) {
2701: $css_class = ' class="'.$css_class.'"';
2702: }
2703: if ($rowstyle) {
2704: $css_class .= ' style="'.$rowstyle.'"';
2705: }
1.160.6.5 raeburn 2706: my $text;
2707: if ($action eq 'requestcourses') {
2708: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2709: } elsif ($action eq 'requestauthor') {
2710: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2711: } else {
1.160.6.34 raeburn 2712: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2713: }
1.160.6.34 raeburn 2714: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2715: ' <td>'.$text.'</td>'.
1.102 raeburn 2716: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2717: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2718: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2719: if ($numdc > 0) {
2720: $datatable .= $table;
1.102 raeburn 2721: } else {
2722: $datatable .= &mt('There are no active Domain Coordinators');
2723: }
2724: $datatable .='</td></tr>';
2725: return $datatable;
2726: }
2727:
1.160.6.30 raeburn 2728: sub print_studentcode {
2729: my ($settings,$rowtotal) = @_;
2730: my $rownum = 0;
2731: my ($output,%current);
1.160.6.118.2 14(raebu 2732:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.51 raeburn 2733: if (ref($settings) eq 'HASH') {
2734: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2735: foreach my $type (@crstypes) {
2736: $current{$type} = $settings->{'uniquecode'}{$type};
2737: }
1.160.6.30 raeburn 2738: }
2739: }
2740: $output .= '<tr>'.
2741: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2742: '<td class="LC_left_item">';
2743: foreach my $type (@crstypes) {
2744: my $check = ' ';
2745: if ($current{$type}) {
2746: $check = ' checked="checked" ';
2747: }
2748: $output .= '<span class="LC_nobreak"><label>'.
2749: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2750: &mt($type).'</label></span>'.(' 'x2).' ';
2751: }
2752: $output .= '</td></tr>';
2753: $$rowtotal ++;
2754: return $output;
2755: }
2756:
2757: sub print_textbookcourses {
1.160.6.46 raeburn 2758: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2759: my $rownum = 0;
2760: my $css_class;
2761: my $itemcount = 1;
2762: my $maxnum = 0;
2763: my $bookshash;
2764: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2765: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2766: }
2767: my %ordered;
2768: if (ref($bookshash) eq 'HASH') {
2769: foreach my $item (keys(%{$bookshash})) {
2770: if (ref($bookshash->{$item}) eq 'HASH') {
2771: my $num = $bookshash->{$item}{'order'};
2772: $ordered{$num} = $item;
2773: }
2774: }
2775: }
2776: my $confname = $dom.'-domainconfig';
2777: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2778: my $maxnum = scalar(keys(%ordered));
2779: my $datatable;
1.160.6.30 raeburn 2780: if (keys(%ordered)) {
2781: my @items = sort { $a <=> $b } keys(%ordered);
2782: for (my $i=0; $i<@items; $i++) {
2783: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2784: my $key = $ordered{$items[$i]};
2785: my %coursehash=&Apache::lonnet::coursedescription($key);
2786: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2787: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2788: if (ref($bookshash->{$key}) eq 'HASH') {
2789: $subject = $bookshash->{$key}->{'subject'};
2790: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2791: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2792: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2793: $author = $bookshash->{$key}->{'author'};
2794: $image = $bookshash->{$key}->{'image'};
2795: if ($image ne '') {
2796: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2797: my $imagethumb = "$path/tn-".$imagefile;
2798: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2799: }
1.160.6.30 raeburn 2800: }
2801: }
1.160.6.46 raeburn 2802: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2803: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2804: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2805: for (my $k=0; $k<=$maxnum; $k++) {
2806: my $vpos = $k+1;
2807: my $selstr;
2808: if ($k == $i) {
2809: $selstr = ' selected="selected" ';
2810: }
2811: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2812: }
2813: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2814: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2815: &mt('Delete?').'</label></span></td>'.
2816: '<td colspan="2">'.
1.160.6.46 raeburn 2817: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2818: (' 'x2).
1.160.6.46 raeburn 2819: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2820: if ($type eq 'textbooks') {
2821: $datatable .= (' 'x2).
1.160.6.47 raeburn 2822: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2823: (' 'x2).
1.160.6.46 raeburn 2824: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2825: (' 'x2).
2826: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2827: if ($image) {
1.160.6.114 raeburn 2828: $datatable .= $imgsrc.
1.160.6.46 raeburn 2829: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2830: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2831: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2832: }
2833: if ($switchserver) {
2834: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2835: } else {
2836: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2837: }
1.160.6.30 raeburn 2838: }
1.160.6.46 raeburn 2839: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2840: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2841: $coursetitle.'</span></td></tr>'."\n";
2842: $itemcount ++;
2843: }
2844: }
2845: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2846: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2847: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2848: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2849: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2850: for (my $k=0; $k<$maxnum+1; $k++) {
2851: my $vpos = $k+1;
2852: my $selstr;
2853: if ($k == $maxnum) {
2854: $selstr = ' selected="selected" ';
2855: }
2856: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2857: }
2858: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2859: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2860: '<td colspan="2">'.
1.160.6.46 raeburn 2861: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2862: (' 'x2).
1.160.6.46 raeburn 2863: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2864: (' 'x2);
2865: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2866: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2867: (' 'x2).
2868: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2869: (' 'x2).
2870: '<span class="LC_nobreak">'.&mt('Image:').' ';
2871: if ($switchserver) {
2872: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2873: } else {
2874: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2875: }
1.160.6.87 raeburn 2876: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2877: }
1.160.6.87 raeburn 2878: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2879: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2880: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2881: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2882: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2883: '</span></td>'."\n".
2884: '</tr>'."\n";
2885: $itemcount ++;
2886: return $datatable;
2887: }
2888:
2889: sub textbookcourses_javascript {
1.160.6.46 raeburn 2890: my ($settings) = @_;
2891: return unless(ref($settings) eq 'HASH');
2892: my (%ordered,%total,%jstext);
2893: foreach my $type ('textbooks','templates') {
2894: $total{$type} = 0;
2895: if (ref($settings->{$type}) eq 'HASH') {
2896: foreach my $item (keys(%{$settings->{$type}})) {
2897: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2898: my $num = $settings->{$type}->{$item}{'order'};
2899: $ordered{$type}{$num} = $item;
2900: }
2901: }
2902: $total{$type} = scalar(keys(%{$settings->{$type}}));
2903: }
2904: my @jsarray = ();
2905: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2906: push(@jsarray,$ordered{$type}{$item});
2907: }
2908: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2909: }
2910: return <<"ENDSCRIPT";
2911: <script type="text/javascript">
2912: // <![CDATA[
1.160.6.46 raeburn 2913: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2914: var changedVal;
1.160.6.46 raeburn 2915: $jstext{'textbooks'};
2916: $jstext{'templates'};
2917: var newpos;
2918: var maxh;
2919: if (caller == 'textbooks') {
2920: newpos = 'textbooks_addbook_pos';
2921: maxh = 1 + $total{'textbooks'};
2922: } else {
2923: newpos = 'templates_addbook_pos';
2924: maxh = 1 + $total{'templates'};
2925: }
1.160.6.30 raeburn 2926: var current = new Array;
2927: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2928: if (item == newpos) {
2929: changedVal = newitemVal;
2930: } else {
2931: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2932: current[newitemVal] = newpos;
2933: }
1.160.6.46 raeburn 2934: if (caller == 'textbooks') {
2935: for (var i=0; i<textbooks.length; i++) {
2936: var elementName = 'textbooks_'+textbooks[i];
2937: if (elementName != item) {
2938: if (form.elements[elementName]) {
2939: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2940: current[currVal] = elementName;
2941: }
2942: }
2943: }
2944: }
2945: if (caller == 'templates') {
2946: for (var i=0; i<templates.length; i++) {
2947: var elementName = 'templates_'+templates[i];
2948: if (elementName != item) {
2949: if (form.elements[elementName]) {
2950: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2951: current[currVal] = elementName;
2952: }
1.160.6.30 raeburn 2953: }
2954: }
2955: }
2956: var oldVal;
2957: for (var j=0; j<maxh; j++) {
2958: if (current[j] == undefined) {
2959: oldVal = j;
2960: }
2961: }
2962: if (oldVal < changedVal) {
2963: for (var k=oldVal+1; k<=changedVal ; k++) {
2964: var elementName = current[k];
2965: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2966: }
2967: } else {
2968: for (var k=changedVal; k<oldVal; k++) {
2969: var elementName = current[k];
2970: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2971: }
2972: }
2973: return;
2974: }
2975:
2976: // ]]>
2977: </script>
2978:
2979: ENDSCRIPT
2980: }
2981:
1.160.6.118.2 1(raebur 2982:1): sub ltitools_javascript {
2983:1): my ($settings) = @_;
2984:1): my $togglejs = <itools_toggle_js();
2985:1): unless (ref($settings) eq 'HASH') {
2986:1): return $togglejs;
2987:1): }
2988:1): my (%ordered,$total,%jstext);
2989:1): $total = 0;
2990:1): foreach my $item (keys(%{$settings})) {
2991:1): if (ref($settings->{$item}) eq 'HASH') {
2992:1): my $num = $settings->{$item}{'order'};
2993:1): $ordered{$num} = $item;
2994:1): }
2995:1): }
2996:1): $total = scalar(keys(%{$settings}));
2997:1): my @jsarray = ();
2998:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
2999:1): push(@jsarray,$ordered{$item});
3000:1): }
3001:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3002:1): return <<"ENDSCRIPT";
3003:1): <script type="text/javascript">
3004:1): // <![CDATA[
3005:1): function reorderLTITools(form,item) {
3006:1): var changedVal;
3007:1): $jstext
3008:1): var newpos = 'ltitools_add_pos';
3009:1): var maxh = 1 + $total;
3010:1): var current = new Array;
3011:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3012:1): if (item == newpos) {
3013:1): changedVal = newitemVal;
3014:1): } else {
3015:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3016:1): current[newitemVal] = newpos;
3017:1): }
3018:1): for (var i=0; i<ltitools.length; i++) {
3019:1): var elementName = 'ltitools_'+ltitools[i];
3020:1): if (elementName != item) {
3021:1): if (form.elements[elementName]) {
3022:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3023:1): current[currVal] = elementName;
3024:1): }
3025:1): }
3026:1): }
3027:1): var oldVal;
3028:1): for (var j=0; j<maxh; j++) {
3029:1): if (current[j] == undefined) {
3030:1): oldVal = j;
3031:1): }
3032:1): }
3033:1): if (oldVal < changedVal) {
3034:1): for (var k=oldVal+1; k<=changedVal ; k++) {
3035:1): var elementName = current[k];
3036:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3037:1): }
3038:1): } else {
3039:1): for (var k=changedVal; k<oldVal; k++) {
3040:1): var elementName = current[k];
3041:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3042:1): }
3043:1): }
3044:1): return;
3045:1): }
3046:1):
3047:1): // ]]>
3048:1): </script>
3049:1):
3050:1): $togglejs
3051:1):
3052:1): ENDSCRIPT
3053:1): }
3054:1):
3055:1): sub ltitools_toggle_js {
3056:1): return <<"ENDSCRIPT";
3057:1): <script type="text/javascript">
3058:1): // <![CDATA[
3059:1):
3060:1): function toggleLTITools(form,setting,item) {
3061:1): var radioname = '';
3062:1): var divid = '';
14(raebu 3063:23): if ((setting == 'passback') || (setting == 'roster')) {
3064:23): radioname = 'ltitools_'+setting+'_'+item;
3065:23): divid = 'ltitools_'+setting+'time_'+item;
3066:23): var num = form.elements[radioname].length;
3067:23): if (num) {
3068:23): var setvis = '';
3069:23): for (var i=0; i<num; i++) {
3070:23): if (form.elements[radioname][i].checked) {
3071:23): if (form.elements[radioname][i].value == '1') {
3072:23): if (document.getElementById(divid)) {
3073:23): document.getElementById(divid).style.display = 'inline-block';
3074:23): }
3075:23): setvis = 1;
3076:23): }
3077:23): break;
3078:23): }
3079:23): }
3080:23): }
3081:23): if (!setvis) {
3082:23): if (document.getElementById(divid)) {
3083:23): document.getElementById(divid).style.display = 'none';
3084:23): }
3085:23): }
3086:23): }
1(raebur 3087:1): if (setting == 'user') {
3088:1): divid = 'ltitools_'+setting+'_div_'+item;
3089:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3090:1): if (document.getElementById(divid)) {
3091:1): if (document.getElementById(checkid)) {
3092:1): if (document.getElementById(checkid).checked) {
3093:1): document.getElementById(divid).style.display = 'inline-block';
3094:1): } else {
3095:1): document.getElementById(divid).style.display = 'none';
3096:1): }
3097:1): }
3098:1): }
3099:1): }
3100:1): return;
3101:1): }
3102:1): // ]]>
3103:1): </script>
3104:1):
3105:1): ENDSCRIPT
3106:1): }
3107:1):
1.160.6.113 raeburn 3108: sub wafproxy_javascript {
3109: my ($dom) = @_;
3110: return <<"ENDSCRIPT";
3111: <script type="text/javascript">
3112: // <![CDATA[
3113: function updateWAF() {
3114: if (document.getElementById('wafproxy_remoteip')) {
3115: var wafremote = 0;
3116: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3117: wafremote = 1;
3118: }
3119: var fields = new Array('header','trust');
3120: for (var i=0; i<fields.length; i++) {
3121: if (document.getElementById('wafproxy_'+fields[i])) {
3122: if (wafremote == 1) {
3123: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3124: }
3125: else {
3126: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3127: }
3128: }
3129: }
3130: if (document.getElementById('wafproxyranges_$dom')) {
3131: if (wafremote == 1) {
3132: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3133: } else {
3134: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3135: if (document.display.wafproxy_vpnaccess[i].checked) {
3136: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3137: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3138: }
3139: }
3140: }
3141: }
3142: }
3143: }
3144: return;
3145: }
3146:
3147: function checkWAF() {
3148: if (document.getElementById('wafproxy_remoteip')) {
3149: var wafvpn = 0;
3150: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3151: if (document.display.wafproxy_vpnaccess[i].checked) {
3152: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3153: wafvpn = 1;
3154: }
3155: break;
3156: }
3157: }
3158: var vpn = new Array('vpnint','vpnext');
3159: for (var i=0; i<vpn.length; i++) {
3160: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3161: if (wafvpn == 1) {
3162: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3163: }
3164: else {
3165: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3166: }
3167: }
3168: }
3169: if (document.getElementById('wafproxyranges_$dom')) {
3170: if (wafvpn == 1) {
3171: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3172: }
3173: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3174: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3175: }
3176: }
3177: }
3178: return;
3179: }
3180:
3181: function toggleWAF() {
3182: if (document.getElementById('wafproxy_table')) {
3183: var wafproxy = 0;
3184: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3185: if (document.display.wafproxy_${dom}[i].checked) {
3186: if (document.display.wafproxy_${dom}[i].value == 1) {
3187: wafproxy = 1;
3188: break;
3189: }
3190: }
3191: }
3192: if (wafproxy == 1) {
3193: document.getElementById('wafproxy_table').style.display='inline';
3194: }
3195: else {
3196: document.getElementById('wafproxy_table').style.display='none';
3197: }
3198: if (document.getElementById('wafproxyrow_${dom}')) {
3199: if (wafproxy == 1) {
3200: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3201: }
3202: else {
3203: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3204: }
3205: }
3206: if (document.getElementById('nowafproxyrow_$dom')) {
3207: if (wafproxy == 1) {
3208: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3209: }
3210: else {
3211: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3212: }
3213: }
3214: }
3215: return;
3216: }
3217: // ]]>
3218: </script>
3219:
3220: ENDSCRIPT
3221: }
3222:
1.160.6.118.2 5(raebur 3223:2): sub lti_javascript {
3224:2): my ($dom,$settings) = @_;
3225:2): my $togglejs = <i_toggle_js($dom);
3226:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
14(raebu 3227:23): unless (ref($settings) eq 'HASH') {
3228:23): return $togglejs.'
3229:23): <script type="text/javascript">
3230:23): // <![CDATA[
3231:23):
3232:23): '.$linkprot_js.'
3233:23):
3234:23): // ]]>
3235:23): </script>
3236:23): ';
3237:23): }
3238:23): my (%ordered,$total,%jstext);
3239:23): $total = scalar(keys(%{$settings}));
3240:23): foreach my $item (keys(%{$settings})) {
3241:23): if (ref($settings->{$item}) eq 'HASH') {
3242:23): my $num = $settings->{$item}{'order'};
3243:23): if ($num eq '') {
3244:23): $num = $total - 1;
3245:23): }
3246:23): $ordered{$num} = $item;
3247:23): }
3248:23): }
3249:23): my @jsarray = ();
3250:23): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3251:23): push(@jsarray,$ordered{$item});
3252:23): }
3253:23): my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
5(raebur 3254:2): return <<"ENDSCRIPT";
3255:2): <script type="text/javascript">
3256:2): // <![CDATA[
14(raebu 3257:23): function reorderLTI(form,item) {
3258:23): var changedVal;
3259:23): $jstext
3260:23): var newpos = 'lti_pos_add';
3261:23): var maxh = 1 + $total;
3262:23): var current = new Array;
3263:23): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3264:23): if (item == newpos) {
3265:23): changedVal = newitemVal;
3266:23): } else {
3267:23): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3268:23): current[newitemVal] = newpos;
3269:23): }
3270:23): for (var i=0; i<lti.length; i++) {
3271:23): var elementName = 'lti_pos_'+lti[i];
3272:23): if (elementName != item) {
3273:23): if (form.elements[elementName]) {
3274:23): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3275:23): current[currVal] = elementName;
3276:23): }
3277:23): }
3278:23): }
3279:23): var oldVal;
3280:23): for (var j=0; j<maxh; j++) {
3281:23): if (current[j] == undefined) {
3282:23): oldVal = j;
3283:23): }
3284:23): }
3285:23): if (oldVal < changedVal) {
3286:23): for (var k=oldVal+1; k<=changedVal ; k++) {
3287:23): var elementName = current[k];
3288:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3289:23): }
3290:23): } else {
3291:23): for (var k=changedVal; k<oldVal; k++) {
3292:23): var elementName = current[k];
3293:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3294:23): }
3295:23): }
3296:23): return;
3297:23): }
5(raebur 3298:2):
3299:2): $linkprot_js
3300:2):
3301:2): // ]]>
3302:2): </script>
3303:2):
3304:2): $togglejs
3305:2):
3306:2): ENDSCRIPT
3307:2): }
3308:2):
3309:2): sub lti_toggle_js {
3310:2): my ($dom) = @_;
14(raebu 3311:23): my %lcauthparmtext = &Apache::lonlocal::texthash (
3312:23): localauth => 'Local auth argument',
3313:23): krb => 'Kerberos domain',
3314:23): );
3315:23): my $crsincalert = &mt('"User\'s identity sent" needs to be set to "Yes" first,[_1] before setting "Course\'s identity sent" to "Yes"',"\n");
3316:23): &js_escape(\$crsincalert);
5(raebur 3317:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3318:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3319:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3320:2): return <<"ENDSCRIPT";
3321:2): <script type="text/javascript">
3322:2): // <![CDATA[
14(raebu 3323:23):
3324:23): function toggleLTI(form,setting,item) {
3325:23): if ((setting == 'requser') || (setting == 'crsinc')) {
3326:23): var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3327:23): var setvis = '';
3328:23): var radioname = 'lti_requser_'+item;
3329:23): var num = form.elements[radioname].length;
3330:23): if (num) {
3331:23): for (var i=0; i<num; i++) {
3332:23): if (form.elements[radioname][i].checked) {
3333:23): if (form.elements[radioname][i].value == '1') {
3334:23): setvis = 1;
3335:23): break;
5(raebur 3336:2): }
14(raebu 3337:23): }
3338:23): }
3339:23): }
3340:23): if (usrfieldsets.length) {
3341:23): for (var j=0; j<usrfieldsets.length; j++) {
3342:23): if (setvis) {
3343:23): usrfieldsets[j].style.display = 'block';
3344:23): } else {
3345:23): usrfieldsets[j].style.display = 'none';
3346:23): }
3347:23): }
3348:23): }
3349:23): var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3350:23): if (crsfieldsets.length) {
3351:23): radioname = 'lti_crsinc_'+item;
3352:23): var num = form.elements[radioname].length;
3353:23): if (num) {
3354:23): var crsvis = '';
3355:23): for (var i=0; i<num; i++) {
3356:23): if (form.elements[radioname][i].checked) {
3357:23): if (form.elements[radioname][i].value == '1') {
3358:23): if (setvis == '') {
3359:23): if (setting == 'crsinc'){
3360:23): alert("$crsincalert");
3361:23): form.elements[radioname][0].checked = true;
3362:23): }
3363:23): } else {
3364:23): crsvis = 1;
5(raebur 3365:2): }
14(raebu 3366:23): break;
5(raebur 3367:2): }
3368:2): }
3369:2): }
14(raebu 3370:23): setvis = crsvis;
5(raebur 3371:2): }
14(raebu 3372:23): for (var j=0; j<crsfieldsets.length; j++) {
3373:23): if (setvis) {
3374:23): crsfieldsets[j].style.display = 'block';
3375:23): } else {
3376:23): crsfieldsets[j].style.display = 'none';
5(raebur 3377:2): }
3378:2): }
3379:2): }
14(raebu 3380:23): } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
3381:23): var radioname = '';
3382:23): var divid = '';
3383:23): if (setting == 'user') {
3384:23): radioname = 'lti_mapuser_'+item;
3385:23): divid = 'lti_userfield_'+item;
3386:23): } else if (setting == 'crs') {
3387:23): radioname = 'lti_mapcrs_'+item;
3388:23): divid = 'lti_crsfield_'+item;
3389:23): } else if (setting == 'callback') {
3390:23): radioname = 'lti_callback_'+item;
3391:23): divid = 'lti_callbackfield_'+item;
3392:23): } else {
3393:23): radioname = 'lti_passback_'+item;
3394:23): divid = 'lti_passback_'+item;
3395:23): }
3396:23): var num = form.elements[radioname].length;
3397:23): if (num) {
3398:23): var setvis = '';
3399:23): for (var i=0; i<num; i++) {
3400:23): if (form.elements[radioname][i].checked) {
3401:23): if ((setting == 'passback') || (setting == 'callback')) {
3402:23): if (form.elements[radioname][i].value == '1') {
3403:23): if (document.getElementById(divid)) {
3404:23): document.getElementById(divid).style.display = 'inline-block';
3405:23): }
3406:23): setvis = 1;
3407:23): break;
3408:23): }
3409:23): } else {
3410:23): if (form.elements[radioname][i].value == 'other') {
3411:23): if (document.getElementById(divid)) {
3412:23): document.getElementById(divid).style.display = 'inline-block';
3413:23): }
3414:23): setvis = 1;
3415:23): break;
3416:23): }
3417:23): }
3418:23): }
3419:23): }
3420:23): if (!setvis) {
3421:23): if (document.getElementById(divid)) {
3422:23): document.getElementById(divid).style.display = 'none';
3423:23): }
5(raebur 3424:2): }
3425:2): }
14(raebu 3426:23): } else if ((setting == 'sec') || (setting == 'secsrc')) {
3427:23): var numsec = form.elements['lti_crssec_'+item].length;
3428:23): if (numsec) {
3429:23): var setvis = '';
3430:23): for (var i=0; i<numsec; i++) {
3431:23): if (form.elements['lti_crssec_'+item][i].checked) {
3432:23): if (form.elements['lti_crssec_'+item][i].value == '1') {
3433:23): if (document.getElementById('lti_crssecfield_'+item)) {
3434:23): document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3435:23): setvis = 1;
3436:23): var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3437:23): if (numsrcsec) {
3438:23): var setsrcvis = '';
3439:23): for (var j=0; j<numsrcsec; j++) {
3440:23): if (form.elements['lti_crssecsrc_'+item][j].checked) {
3441:23): if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3442:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3443:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3444:23): setsrcvis = 1;
3445:23): }
3446:23): }
3447:23): }
3448:23): }
3449:23): if (!setsrcvis) {
3450:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3451:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3452:23): }
3453:23): }
3454:23): }
3455:23): }
3456:23): }
3457:23): }
3458:23): }
3459:23): if (!setvis) {
3460:23): if (document.getElementById('lti_crssecfield_'+item)) {
3461:23): document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3462:23): }
3463:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3464:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3465:23): }
3466:23): }
5(raebur 3467:2): }
14(raebu 3468:23): } else if (setting == 'lcauth') {
3469:23): var numauth = form.elements['lti_lcauth_'+item].length;
3470:23): if (numauth) {
3471:23): for (var i=0; i<numauth; i++) {
3472:23): if (form.elements['lti_lcauth_'+item][i].checked) {
3473:23): if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3474:23): if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3475:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3476:23): } else {
3477:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3478:23): if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3479:23): if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3480:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3481:23): } else {
3482:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3483:23): }
3484:23): }
3485:23): }
3486:23): }
5(raebur 3487:2): }
3488:2): }
3489:2): }
14(raebu 3490:23): } else if (setting == 'lcmenu') {
3491:23): var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3492:23): var divid = 'lti_menufield_'+item;
3493:23): var setvis = '';
3494:23): for (var i=0; i<menus.length; i++) {
3495:23): var radioname = menus[i];
3496:23): var num = form.elements[radioname].length;
3497:23): if (num) {
3498:23): for (var j=0; j<num; j++) {
3499:23): if (form.elements[radioname][j].checked) {
3500:23): if (form.elements[radioname][j].value == '1') {
3501:23): if (document.getElementById(divid)) {
3502:23): document.getElementById(divid).style.display = 'inline-block';
3503:23): }
5(raebur 3504:2): setvis = 1;
14(raebu 3505:23): break;
5(raebur 3506:2): }
3507:2): }
3508:2): }
14(raebu 3509:23): }
3510:23): if (setvis == 1) {
3511:23): break;
3512:23): }
3513:23): }
3514:23): if (!setvis) {
3515:23): if (document.getElementById(divid)) {
3516:23): document.getElementById(divid).style.display = 'none';
5(raebur 3517:2): }
3518:2): }
3519:2): }
14(raebu 3520:23): return;
5(raebur 3521:2): }
3522:2):
3523:2): // ]]>
3524:2): </script>
3525:2):
3526:2): ENDSCRIPT
3527:2): }
3528:2):
1.160.6.113 raeburn 3529: sub autoupdate_javascript {
3530: return <<"ENDSCRIPT";
3531: <script type="text/javascript">
3532: // <![CDATA[
3533: function toggleLastActiveDays(form) {
3534: var radioname = 'lastactive';
3535: var divid = 'lastactive_div';
3536: var num = form.elements[radioname].length;
3537: if (num) {
3538: var setvis = '';
3539: for (var i=0; i<num; i++) {
3540: if (form.elements[radioname][i].checked) {
3541: if (form.elements[radioname][i].value == '1') {
3542: if (document.getElementById(divid)) {
3543: document.getElementById(divid).style.display = 'inline-block';
3544: }
3545: setvis = 1;
3546: }
3547: break;
3548: }
3549: }
3550: if (!setvis) {
3551: if (document.getElementById(divid)) {
3552: document.getElementById(divid).style.display = 'none';
3553: }
3554: }
3555: }
3556: return;
3557: }
3558: // ]]>
3559: </script>
3560:
3561: ENDSCRIPT
3562: }
3563:
1.160.6.116 raeburn 3564: sub autoenroll_javascript {
3565: return <<"ENDSCRIPT";
3566: <script type="text/javascript">
3567: // <![CDATA[
3568: function toggleFailsafe(form) {
3569: var radioname = 'autoenroll_failsafe';
3570: var divid = 'autoenroll_failsafe_div';
3571: var num = form.elements[radioname].length;
3572: if (num) {
3573: var setvis = '';
3574: for (var i=0; i<num; i++) {
3575: if (form.elements[radioname][i].checked) {
3576: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3577: if (document.getElementById(divid)) {
3578: document.getElementById(divid).style.display = 'inline-block';
3579: }
3580: setvis = 1;
3581: }
3582: break;
3583: }
3584: }
3585: if (!setvis) {
3586: if (document.getElementById(divid)) {
3587: document.getElementById(divid).style.display = 'none';
3588: }
3589: }
3590: }
3591: return;
3592: }
3593: // ]]>
3594: </script>
3595:
3596: ENDSCRIPT
3597: }
3598:
1.160.6.113 raeburn 3599: sub saml_javascript {
3600: return <<"ENDSCRIPT";
3601: <script type="text/javascript">
3602: // <![CDATA[
3603: function toggleSamlOptions(form,hostid) {
3604: var radioname = 'saml_'+hostid;
3605: var tablecellon = 'samloptionson_'+hostid;
3606: var tablecelloff = 'samloptionsoff_'+hostid;
3607: var num = form.elements[radioname].length;
3608: if (num) {
3609: var setvis = '';
3610: for (var i=0; i<num; i++) {
3611: if (form.elements[radioname][i].checked) {
3612: if (form.elements[radioname][i].value == '1') {
3613: if (document.getElementById(tablecellon)) {
3614: document.getElementById(tablecellon).style.display='';
3615: }
3616: if (document.getElementById(tablecelloff)) {
3617: document.getElementById(tablecelloff).style.display='none';
3618: }
3619: setvis = 1;
3620: }
3621: break;
3622: }
3623: }
3624: if (!setvis) {
3625: if (document.getElementById(tablecellon)) {
3626: document.getElementById(tablecellon).style.display='none';
3627: }
3628: if (document.getElementById(tablecelloff)) {
3629: document.getElementById(tablecelloff).style.display='';
3630: }
3631: }
3632: }
3633: return;
3634: }
3635: // ]]>
3636: </script>
3637:
3638: ENDSCRIPT
3639: }
3640:
3641: sub ipaccess_javascript {
3642: my ($settings) = @_;
3643: my (%ordered,$total,%jstext);
3644: $total = 0;
3645: if (ref($settings) eq 'HASH') {
3646: foreach my $item (keys(%{$settings})) {
3647: if (ref($settings->{$item}) eq 'HASH') {
3648: my $num = $settings->{$item}{'order'};
3649: $ordered{$num} = $item;
3650: }
3651: }
3652: $total = scalar(keys(%{$settings}));
3653: }
3654: my @jsarray = ();
3655: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3656: push(@jsarray,$ordered{$item});
3657: }
3658: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3659: return <<"ENDSCRIPT";
3660: <script type="text/javascript">
3661: // <![CDATA[
3662: function reorderIPaccess(form,item) {
3663: var changedVal;
3664: $jstext
3665: var newpos = 'ipaccess_pos_add';
3666: var maxh = 1 + $total;
3667: var current = new Array;
3668: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3669: if (item == newpos) {
3670: changedVal = newitemVal;
3671: } else {
3672: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3673: current[newitemVal] = newpos;
3674: }
3675: for (var i=0; i<ipaccess.length; i++) {
3676: var elementName = 'ipaccess_pos_'+ipaccess[i];
3677: if (elementName != item) {
3678: if (form.elements[elementName]) {
3679: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3680: current[currVal] = elementName;
3681: }
3682: }
3683: }
3684: var oldVal;
3685: for (var j=0; j<maxh; j++) {
3686: if (current[j] == undefined) {
3687: oldVal = j;
3688: }
3689: }
3690: if (oldVal < changedVal) {
3691: for (var k=oldVal+1; k<=changedVal ; k++) {
3692: var elementName = current[k];
3693: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3694: }
3695: } else {
3696: for (var k=changedVal; k<oldVal; k++) {
3697: var elementName = current[k];
3698: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3699: }
3700: }
3701: return;
3702: }
3703: // ]]>
3704: </script>
3705:
3706: ENDSCRIPT
3707: }
3708:
1.3 raeburn 3709: sub print_autoenroll {
1.30 raeburn 3710: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3711: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3712: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3713: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3714: $failsafesty = 'none';
3715: %failsafechecked = (
3716: off => ' checked="checked"',
3717: );
1.3 raeburn 3718: if (ref($settings) eq 'HASH') {
3719: if (exists($settings->{'run'})) {
3720: if ($settings->{'run'} eq '0') {
3721: $runoff = ' checked="checked" ';
3722: $runon = ' ';
3723: } else {
3724: $runon = ' checked="checked" ';
3725: $runoff = ' ';
3726: }
3727: } else {
3728: if ($autorun) {
3729: $runon = ' checked="checked" ';
3730: $runoff = ' ';
3731: } else {
3732: $runoff = ' checked="checked" ';
3733: $runon = ' ';
3734: }
3735: }
1.129 raeburn 3736: if (exists($settings->{'co-owners'})) {
3737: if ($settings->{'co-owners'} eq '0') {
3738: $coownersoff = ' checked="checked" ';
3739: $coownerson = ' ';
3740: } else {
3741: $coownerson = ' checked="checked" ';
3742: $coownersoff = ' ';
3743: }
3744: } else {
3745: $coownersoff = ' checked="checked" ';
3746: $coownerson = ' ';
3747: }
1.3 raeburn 3748: if (exists($settings->{'sender_domain'})) {
3749: $defdom = $settings->{'sender_domain'};
3750: }
1.160.6.116 raeburn 3751: if (exists($settings->{'failsafe'})) {
3752: $failsafe = $settings->{'failsafe'};
3753: if ($failsafe eq 'zero') {
3754: $failsafechecked{'zero'} = ' checked="checked"';
3755: $failsafechecked{'off'} = '';
3756: $failsafesty = 'inline-block';
3757: } elsif ($failsafe eq 'any') {
3758: $failsafechecked{'any'} = ' checked="checked"';
3759: $failsafechecked{'off'} = '';
3760: }
3761: $autofailsafe = $settings->{'autofailsafe'};
3762: } elsif (exists($settings->{'autofailsafe'})) {
3763: $autofailsafe = $settings->{'autofailsafe'};
3764: if ($autofailsafe ne '') {
3765: $failsafechecked{'zero'} = ' checked="checked"';
3766: $failsafe = 'zero';
3767: $failsafechecked{'off'} = '';
3768: }
1.160.6.68 raeburn 3769: }
1.14 raeburn 3770: } else {
3771: if ($autorun) {
3772: $runon = ' checked="checked" ';
3773: $runoff = ' ';
3774: } else {
3775: $runoff = ' checked="checked" ';
3776: $runon = ' ';
3777: }
1.3 raeburn 3778: }
3779: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3780: my $notif_sender;
3781: if (ref($settings) eq 'HASH') {
3782: $notif_sender = $settings->{'sender_uname'};
3783: }
1.3 raeburn 3784: my $datatable='<tr class="LC_odd_row">'.
3785: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3786: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3787: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3788: $runon.' value="1" />'.&mt('Yes').'</label> '.
3789: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3790: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3791: '</tr><tr>'.
3792: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3793: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3794: &mt('username').': '.
3795: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3796: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3797: ': '.$domform.'</span></td></tr>'.
3798: '<tr class="LC_odd_row">'.
3799: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3800: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3801: '<input type="radio" name="autoassign_coowners"'.
3802: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3803: '<label><input type="radio" name="autoassign_coowners"'.
3804: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3805: '</tr><tr>'.
3806: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3807: '<td class="LC_left_item"><span class="LC_nobreak">'.
3808: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="off" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'off'}.' />'.&mt('Not in use').'</label></span> '.
3809: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="zero" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'zero'}.' />'.&mt('Retrieved section enrollment is zero').'</label></span><br />'.
3810: '<span class="LC_nobreak"><label><input type="radio" name="autoenroll_failsafe" value="any" onclick="toggleFailsafe(this.form)"'.$failsafechecked{'any'}.' />'.&mt('Retrieved section enrollment is zero or greater').'</label></span>'.
3811: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3812: '<span class="LC_nobreak">'.
3813: &mt('Threshold for number of students in section to drop: [_1]',
3814: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3815: '</span></div></td></tr>';
1.160.6.68 raeburn 3816: $$rowtotal += 4;
1.3 raeburn 3817: return $datatable;
3818: }
3819:
3820: sub print_autoupdate {
1.30 raeburn 3821: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3822: my ($enable,$datatable);
1.3 raeburn 3823: if ($position eq 'top') {
1.160.6.113 raeburn 3824: my %choices = &Apache::lonlocal::texthash (
3825: run => 'Auto-update active?',
3826: classlists => 'Update information in classlists?',
3827: unexpired => 'Skip updates for users without active or future roles?',
3828: lastactive => 'Skip updates for inactive users?',
3829: );
3830: my $itemcount = 0;
1.3 raeburn 3831: my $updateon = ' ';
3832: my $updateoff = ' checked="checked" ';
3833: if (ref($settings) eq 'HASH') {
3834: if ($settings->{'run'} eq '1') {
3835: $updateon = $updateoff;
3836: $updateoff = ' ';
3837: }
3838: }
1.160.6.118.2 14(raebu 3839:23): $enable = '<tr class="LC_odd_row">'.
3840:23): '<td>'.$choices{'run'}.'</td>'.
1.160.6.113 raeburn 3841: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3842: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3843: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3844: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3845: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3846: '</tr>';
1.160.6.113 raeburn 3847: my @toggles = ('classlists','unexpired');
3848: my %defaultchecked = ('classlists' => 'off',
3849: 'unexpired' => 'off'
3850: );
3851: $$rowtotal ++;
3852: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3853: \%choices,$itemcount,'','','left','no');
3854: $datatable = $enable.$datatable;
3855: $$rowtotal += $itemcount;
3856: my $lastactiveon = ' ';
3857: my $lastactiveoff = ' checked="checked" ';
3858: my $lastactivestyle = 'none';
3859: my $lastactivedays;
3860: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3861: if (ref($settings) eq 'HASH') {
3862: if ($settings->{'lastactive'} =~ /^\d+$/) {
3863: $lastactiveon = $lastactiveoff;
3864: $lastactiveoff = ' ';
3865: $lastactivestyle = 'inline-block';
3866: $lastactivedays = $settings->{'lastactive'};
3867: }
3868: }
3869: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3870: $datatable .= '<tr'.$css_class.'>'.
3871: '<td>'.$choices{'lastactive'}.'</td>'.
3872: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3873: '<input type="radio" name="lastactive"'.
3874: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3875: ' <label>'.
3876: '<input type="radio" name="lastactive"'.
3877: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3878: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3879: ': '.&mt('inactive = no activity in last [_1] days',
3880: '<input type="text" size="5" name="lastactivedays" value="'.
3881: $lastactivedays.'" />').
3882: '</span></td>'.
3883: '</tr>';
3884: $$rowtotal ++;
1.131 raeburn 3885: } elsif ($position eq 'middle') {
3886: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3887: my $numinrow = 3;
3888: my $locknamesettings;
3889: $datatable .= &insttypes_row($settings,$types,$usertypes,
3890: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3891: 'lockablenames',$rowtotal);
1.131 raeburn 3892: $$rowtotal ++;
1.3 raeburn 3893: } else {
1.44 raeburn 3894: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3895: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3896: 'permanentemail','id');
1.33 raeburn 3897: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3898: my $numrows = 0;
1.26 raeburn 3899: if (ref($types) eq 'ARRAY') {
3900: if (@{$types} > 0) {
3901: $datatable =
3902: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3903: \@fields,$types,\$numrows);
1.30 raeburn 3904: $$rowtotal += @{$types};
1.26 raeburn 3905: }
1.3 raeburn 3906: }
3907: $datatable .=
3908: &usertype_update_row($settings,{'default' => $othertitle},
3909: \%fieldtitles,\@fields,['default'],
3910: \$numrows);
1.30 raeburn 3911: $$rowtotal ++;
1.3 raeburn 3912: }
3913: return $datatable;
3914: }
3915:
1.125 raeburn 3916: sub print_autocreate {
3917: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3918: my (%createon,%createoff,%currhash);
1.125 raeburn 3919: my @types = ('xml','req');
3920: if (ref($settings) eq 'HASH') {
3921: foreach my $item (@types) {
3922: $createoff{$item} = ' checked="checked" ';
3923: $createon{$item} = ' ';
3924: if (exists($settings->{$item})) {
3925: if ($settings->{$item}) {
3926: $createon{$item} = ' checked="checked" ';
3927: $createoff{$item} = ' ';
3928: }
3929: }
3930: }
1.160.6.16 raeburn 3931: if ($settings->{'xmldc'} ne '') {
3932: $currhash{$settings->{'xmldc'}} = 1;
3933: }
1.125 raeburn 3934: } else {
3935: foreach my $item (@types) {
3936: $createoff{$item} = ' checked="checked" ';
3937: $createon{$item} = ' ';
3938: }
3939: }
3940: $$rowtotal += 2;
1.160.6.16 raeburn 3941: my $numinrow = 2;
1.125 raeburn 3942: my $datatable='<tr class="LC_odd_row">'.
3943: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3944: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3945: '<input type="radio" name="autocreate_xml"'.
3946: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3947: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3948: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3949: '</td></tr><tr>'.
3950: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3951: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3952: '<input type="radio" name="autocreate_req"'.
3953: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3954: '<label><input type="radio" name="autocreate_req"'.
3955: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3956: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3957: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3958: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3959: if ($numdc > 1) {
1.160.6.50 raeburn 3960: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3961: '</td><td class="LC_left_item">';
1.125 raeburn 3962: } else {
1.160.6.50 raeburn 3963: $datatable .= &mt('Course creation processed as:').
3964: '</td><td class="LC_right_item">';
1.125 raeburn 3965: }
1.160.6.50 raeburn 3966: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3967: $$rowtotal += $rows;
1.125 raeburn 3968: return $datatable;
3969: }
3970:
1.23 raeburn 3971: sub print_directorysrch {
1.160.6.72 raeburn 3972: my ($position,$dom,$settings,$rowtotal) = @_;
3973: my $datatable;
3974: if ($position eq 'top') {
3975: my $instsrchon = ' ';
3976: my $instsrchoff = ' checked="checked" ';
3977: my ($exacton,$containson,$beginson);
3978: my $instlocalon = ' ';
3979: my $instlocaloff = ' checked="checked" ';
3980: if (ref($settings) eq 'HASH') {
3981: if ($settings->{'available'} eq '1') {
3982: $instsrchon = $instsrchoff;
3983: $instsrchoff = ' ';
3984: }
3985: if ($settings->{'localonly'} eq '1') {
3986: $instlocalon = $instlocaloff;
3987: $instlocaloff = ' ';
3988: }
3989: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
3990: foreach my $type (@{$settings->{'searchtypes'}}) {
3991: if ($type eq 'exact') {
3992: $exacton = ' checked="checked" ';
3993: } elsif ($type eq 'contains') {
3994: $containson = ' checked="checked" ';
3995: } elsif ($type eq 'begins') {
3996: $beginson = ' checked="checked" ';
3997: }
3998: }
3999: } else {
4000: if ($settings->{'searchtypes'} eq 'exact') {
4001: $exacton = ' checked="checked" ';
4002: } elsif ($settings->{'searchtypes'} eq 'contains') {
4003: $containson = ' checked="checked" ';
4004: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4005: $exacton = ' checked="checked" ';
4006: $containson = ' checked="checked" ';
4007: }
4008: }
1.23 raeburn 4009: }
1.160.6.72 raeburn 4010: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4011: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 4012:
1.160.6.72 raeburn 4013: my $numinrow = 4;
4014: my $cansrchrow = 0;
4015: $datatable='<tr class="LC_odd_row">'.
4016: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4017: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4018: '<input type="radio" name="dirsrch_available"'.
4019: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4020: '<label><input type="radio" name="dirsrch_available"'.
4021: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4022: '</tr><tr>'.
4023: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4024: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4025: '<input type="radio" name="dirsrch_instlocalonly"'.
4026: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4027: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4028: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4029: '</tr>';
4030: $$rowtotal += 2;
4031: if (ref($usertypes) eq 'HASH') {
4032: if (keys(%{$usertypes}) > 0) {
4033: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 4034: $numinrow,$othertitle,'cansearch',
4035: $rowtotal);
1.160.6.72 raeburn 4036: $cansrchrow = 1;
4037: }
1.26 raeburn 4038: }
1.160.6.72 raeburn 4039: if ($cansrchrow) {
4040: $$rowtotal ++;
4041: $datatable .= '<tr>';
4042: } else {
4043: $datatable .= '<tr class="LC_odd_row">';
4044: }
4045: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4046: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4047: foreach my $title (@{$titleorder}) {
4048: if (defined($searchtitles->{$title})) {
4049: my $check = ' ';
4050: if (ref($settings) eq 'HASH') {
4051: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4052: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4053: $check = ' checked="checked" ';
4054: }
1.39 raeburn 4055: }
1.25 raeburn 4056: }
1.160.6.72 raeburn 4057: $datatable .= '<td class="LC_left_item">'.
4058: '<span class="LC_nobreak"><label>'.
4059: '<input type="checkbox" name="searchby" '.
4060: 'value="'.$title.'"'.$check.'/>'.
4061: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4062: }
4063: }
1.160.6.72 raeburn 4064: $datatable .= '</tr></table></td></tr>';
4065: $$rowtotal ++;
4066: if ($cansrchrow) {
4067: $datatable .= '<tr class="LC_odd_row">';
4068: } else {
4069: $datatable .= '<tr>';
4070: }
4071: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4072: '<td class="LC_left_item" colspan="2">'.
4073: '<span class="LC_nobreak"><label>'.
4074: '<input type="checkbox" name="searchtypes" '.
4075: $exacton.' value="exact" />'.&mt('Exact match').
4076: '</label> '.
4077: '<label><input type="checkbox" name="searchtypes" '.
4078: $beginson.' value="begins" />'.&mt('Begins with').
4079: '</label> '.
4080: '<label><input type="checkbox" name="searchtypes" '.
4081: $containson.' value="contains" />'.&mt('Contains').
4082: '</label></span></td></tr>';
4083: $$rowtotal ++;
1.26 raeburn 4084: } else {
1.160.6.72 raeburn 4085: my $domsrchon = ' checked="checked" ';
4086: my $domsrchoff = ' ';
4087: my $domlocalon = ' ';
4088: my $domlocaloff = ' checked="checked" ';
4089: if (ref($settings) eq 'HASH') {
4090: if ($settings->{'lclocalonly'} eq '1') {
4091: $domlocalon = $domlocaloff;
4092: $domlocaloff = ' ';
4093: }
4094: if ($settings->{'lcavailable'} eq '0') {
4095: $domsrchoff = $domsrchon;
4096: $domsrchon = ' ';
4097: }
4098: }
4099: $datatable='<tr class="LC_odd_row">'.
4100: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4101: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4102: '<input type="radio" name="dirsrch_domavailable"'.
4103: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4104: '<label><input type="radio" name="dirsrch_domavailable"'.
4105: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4106: '</tr><tr>'.
4107: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4108: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4109: '<input type="radio" name="dirsrch_domlocalonly"'.
4110: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4111: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4112: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4113: '</tr>';
4114: $$rowtotal += 2;
1.26 raeburn 4115: }
1.25 raeburn 4116: return $datatable;
4117: }
4118:
1.28 raeburn 4119: sub print_contacts {
1.160.6.78 raeburn 4120: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4121: my $datatable;
4122: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 4123: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 4124: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 4125: if ($position eq 'top') {
4126: if (ref($settings) eq 'HASH') {
4127: foreach my $item (@contacts) {
4128: if (exists($settings->{$item})) {
4129: $to{$item} = $settings->{$item};
4130: }
1.28 raeburn 4131: }
4132: }
1.160.6.78 raeburn 4133: } elsif ($position eq 'middle') {
4134: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 4135: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 4136: foreach my $type (@mailings) {
1.160.6.78 raeburn 4137: $otheremails{$type} = '';
4138: }
1.160.6.107 raeburn 4139: } elsif ($position eq 'lower') {
4140: if (ref($settings) eq 'HASH') {
4141: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4142: %lonstatus = %{$settings->{'lonstatus'}};
4143: }
4144: }
1.160.6.78 raeburn 4145: } else {
4146: @mailings = ('helpdeskmail','otherdomsmail');
4147: foreach my $type (@mailings) {
4148: $otheremails{$type} = '';
4149: }
4150: $bccemails{'helpdeskmail'} = '';
4151: $bccemails{'otherdomsmail'} = '';
4152: $includestr{'helpdeskmail'} = '';
4153: $includestr{'otherdomsmail'} = '';
4154: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4155: }
4156: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 4157: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4158: foreach my $type (@mailings) {
4159: if (exists($settings->{$type})) {
4160: if (ref($settings->{$type}) eq 'HASH') {
4161: foreach my $item (@contacts) {
4162: if ($settings->{$type}{$item}) {
4163: $checked{$type}{$item} = ' checked="checked" ';
4164: }
1.28 raeburn 4165: }
1.160.6.78 raeburn 4166: $otheremails{$type} = $settings->{$type}{'others'};
4167: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4168: $bccemails{$type} = $settings->{$type}{'bcc'};
4169: if ($settings->{$type}{'include'} ne '') {
4170: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4171: $includestr{$type} = &unescape($includestr{$type});
4172: }
4173: }
4174: }
4175: } elsif ($type eq 'lonstatusmail') {
4176: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4177: }
4178: }
4179: }
4180: if ($position eq 'bottom') {
4181: foreach my $type (@mailings) {
4182: $bccemails{$type} = $settings->{$type}{'bcc'};
4183: if ($settings->{$type}{'include'} ne '') {
4184: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4185: $includestr{$type} = &unescape($includestr{$type});
4186: }
4187: }
4188: if (ref($settings->{'helpform'}) eq 'HASH') {
4189: if (ref($fields) eq 'ARRAY') {
4190: foreach my $field (@{$fields}) {
4191: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4192: }
1.160.6.78 raeburn 4193: }
4194: if (exists($settings->{'helpform'}{'maxsize'})) {
4195: $maxsize = $settings->{'helpform'}{'maxsize'};
4196: } else {
4197: $maxsize = '1.0';
4198: }
4199: } else {
4200: if (ref($fields) eq 'ARRAY') {
4201: foreach my $field (@{$fields}) {
4202: $currfield{$field} = 'yes';
1.134 raeburn 4203: }
1.28 raeburn 4204: }
1.160.6.78 raeburn 4205: $maxsize = '1.0';
1.28 raeburn 4206: }
4207: }
4208: } else {
1.160.6.78 raeburn 4209: if ($position eq 'top') {
4210: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4211: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4212: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4213: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
4214: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4215: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4216: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4217: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 4218: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 4219: } elsif ($position eq 'bottom') {
4220: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4221: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4222: if (ref($fields) eq 'ARRAY') {
4223: foreach my $field (@{$fields}) {
4224: $currfield{$field} = 'yes';
4225: }
4226: }
4227: $maxsize = '1.0';
4228: }
1.28 raeburn 4229: }
4230: my ($titles,$short_titles) = &contact_titles();
4231: my $rownum = 0;
4232: my $css_class;
1.160.6.78 raeburn 4233: if ($position eq 'top') {
4234: foreach my $item (@contacts) {
4235: $css_class = $rownum%2?' class="LC_odd_row"':'';
4236: $datatable .= '<tr'.$css_class.'>'.
4237: '<td><span class="LC_nobreak">'.$titles->{$item}.
4238: '</span></td><td class="LC_right_item">'.
4239: '<input type="text" name="'.$item.'" value="'.
4240: $to{$item}.'" /></td></tr>';
4241: $rownum ++;
4242: }
1.160.6.101 raeburn 4243: } elsif ($position eq 'bottom') {
4244: $css_class = $rownum%2?' class="LC_odd_row"':'';
4245: $datatable .= '<tr'.$css_class.'>'.
4246: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4247: &mt('(e-mail, subject, and description always shown)').
4248: '</td><td class="LC_left_item">';
4249: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4250: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4251: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4252: foreach my $field (@{$fields}) {
4253: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4254: if (($field eq 'screenshot') || ($field eq 'cc')) {
4255: $datatable .= ' '.&mt('(logged-in users)');
4256: }
4257: $datatable .='</td><td>';
4258: my $clickaction;
4259: if ($field eq 'screenshot') {
4260: $clickaction = ' onclick="screenshotSize(this);"';
4261: }
4262: if (ref($possoptions->{$field}) eq 'ARRAY') {
4263: foreach my $option (@{$possoptions->{$field}}) {
4264: my $checked;
4265: if ($currfield{$field} eq $option) {
4266: $checked = ' checked="checked"';
4267: }
4268: $datatable .= '<span class="LC_nobreak"><label>'.
4269: '<input type="radio" name="helpform_'.$field.'" '.
4270: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4271: '</label></span>'.(' 'x2);
4272: }
4273: }
4274: if ($field eq 'screenshot') {
4275: my $display;
4276: if ($currfield{$field} eq 'no') {
4277: $display = ' style="display:none"';
4278: }
4279: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4280: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4281: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4282: }
4283: $datatable .= '</td></tr>';
4284: }
4285: $datatable .= '</table>';
4286: }
4287: $datatable .= '</td></tr>'."\n";
4288: $rownum ++;
4289: }
1.160.6.107 raeburn 4290: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4291: foreach my $type (@mailings) {
4292: $css_class = $rownum%2?' class="LC_odd_row"':'';
4293: $datatable .= '<tr'.$css_class.'>'.
4294: '<td><span class="LC_nobreak">'.
4295: $titles->{$type}.': </span></td>'.
4296: '<td class="LC_left_item">';
4297: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4298: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4299: }
4300: $datatable .= '<span class="LC_nobreak">';
4301: foreach my $item (@contacts) {
4302: $datatable .= '<label>'.
4303: '<input type="checkbox" name="'.$type.'"'.
4304: $checked{$type}{$item}.
4305: ' value="'.$item.'" />'.$short_titles->{$item}.
4306: '</label> ';
4307: }
4308: $datatable .= '</span><br />'.&mt('Others').': '.
4309: '<input type="text" name="'.$type.'_others" '.
4310: 'value="'.$otheremails{$type}.'" />';
4311: my %locchecked;
4312: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4313: foreach my $loc ('s','b') {
4314: if ($includeloc{$type} eq $loc) {
4315: $locchecked{$loc} = ' checked="checked"';
4316: last;
4317: }
4318: }
4319: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4320: '<input type="text" name="'.$type.'_bcc" '.
4321: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4322: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4323: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4324: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4325: '<span class="LC_nobreak">'.&mt('Location:').' '.
4326: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4327: (' 'x2).
4328: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4329: '</span></fieldset>';
4330: }
4331: $datatable .= '</td></tr>'."\n";
4332: $rownum ++;
4333: }
1.28 raeburn 4334: }
1.160.6.78 raeburn 4335: if ($position eq 'middle') {
4336: my %choices;
1.160.6.107 raeburn 4337: my $corelink = &core_link_msu();
4338: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4339: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4340: $corelink);
4341: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4342: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4343: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4344: 'reportupdates' => 'on',
4345: 'reportstatus' => 'on');
1.160.6.78 raeburn 4346: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4347: \%choices,$rownum);
4348: $datatable .= $reports;
1.160.6.107 raeburn 4349: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4350: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4351: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4352: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4353: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4354: } else {
1.160.6.109 raeburn 4355: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4356: }
4357: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4358: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4359: } else {
1.160.6.109 raeburn 4360: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4361: }
4362: if (ref($lonstatus{'weights'}) eq 'HASH') {
4363: foreach my $type ('E','W','N','U') {
4364: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4365: $weights{$type} = $lonstatus{'weights'}{$type};
4366: } else {
4367: $weights{$type} = $defaults->{$type};
4368: }
4369: }
4370: } else {
4371: foreach my $type ('E','W','N','U') {
4372: $weights{$type} = $defaults->{$type};
4373: }
4374: }
4375: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4376: if (@{$lonstatus{'excluded'}} > 0) {
4377: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4378: }
4379: }
1.160.6.109 raeburn 4380: foreach my $item ('errorthreshold','errorsysmail') {
4381: $css_class = $rownum%2?' class="LC_odd_row"':'';
4382: $datatable .= '<tr'.$css_class.'>'.
4383: '<td class="LC_left_item"><span class="LC_nobreak">'.
4384: $titles->{$item}.
4385: '</span></td><td class="LC_left_item">'.
4386: '<input type="text" name="'.$item.'" value="'.
4387: $current{$item}.'" size="5" /></td></tr>';
4388: $rownum ++;
4389: }
1.160.6.107 raeburn 4390: $css_class = $rownum%2?' class="LC_odd_row"':'';
4391: $datatable .= '<tr'.$css_class.'>'.
4392: '<td class="LC_left_item">'.
4393: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4394: '</span></td><td class="LC_left_item"><table><tr>';
4395: foreach my $type ('E','W','N','U') {
4396: $datatable .= '<td>'.$names->{$type}.'<br />'.
4397: '<input type="text" name="errorweights_'.$type.'" value="'.
4398: $weights{$type}.'" size="5" /></td>';
4399: }
4400: $datatable .= '</tr></table></tr>';
4401: $rownum ++;
4402: $css_class = $rownum%2?' class="LC_odd_row"':'';
4403: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4404: $titles->{'errorexcluded'}.'</td>'.
4405: '<td class="LC_left_item"><table>';
4406: my $numinrow = 4;
4407: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4408: for (my $i=0; $i<@ids; $i++) {
4409: my $rem = $i%($numinrow);
4410: if ($rem == 0) {
4411: if ($i > 0) {
4412: $datatable .= '</tr>';
4413: }
4414: $datatable .= '<tr>';
4415: }
4416: my $check;
4417: if ($excluded{$ids[$i]}) {
4418: $check = ' checked="checked" ';
4419: }
4420: $datatable .= '<td class="LC_left_item">'.
4421: '<span class="LC_nobreak"><label>'.
4422: '<input type="checkbox" name="errorexcluded" '.
4423: 'value="'.$ids[$i].'"'.$check.' />'.
4424: $ids[$i].'</label></span></td>';
4425: }
4426: my $colsleft = $numinrow - @ids%($numinrow);
4427: if ($colsleft > 1 ) {
4428: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4429: ' </td>';
4430: } elsif ($colsleft == 1) {
4431: $datatable .= '<td class="LC_left_item"> </td>';
4432: }
4433: $datatable .= '</tr></table></td></tr>';
4434: $rownum ++;
1.160.6.78 raeburn 4435: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4436: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4437: my (@posstypes,%usertypeshash);
4438: if (ref($types) eq 'ARRAY') {
4439: @posstypes = @{$types};
4440: }
4441: if (@posstypes) {
4442: if (ref($usertypes) eq 'HASH') {
4443: %usertypeshash = %{$usertypes};
4444: }
4445: my @overridden;
4446: my $numinrow = 4;
4447: if (ref($settings) eq 'HASH') {
4448: if (ref($settings->{'overrides'}) eq 'HASH') {
4449: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4450: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4451: push(@overridden,$key);
4452: foreach my $item (@contacts) {
4453: if ($settings->{'overrides'}{$key}{$item}) {
4454: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4455: }
4456: }
4457: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4458: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4459: $includeloc{'override_'.$key} = '';
4460: $includestr{'override_'.$key} = '';
4461: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4462: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4463: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4464: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4465: }
1.160.6.78 raeburn 4466: }
4467: }
4468: }
1.160.6.101 raeburn 4469: }
4470: my $customclass = 'LC_helpdesk_override';
4471: my $optionsprefix = 'LC_options_helpdesk_';
4472:
4473: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4474: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4475: $numinrow,$othertitle,'overrides',
4476: \$rownum,$onclicktypes,$customclass);
4477: $rownum ++;
4478: $usertypeshash{'default'} = $othertitle;
4479: foreach my $status (@posstypes) {
4480: my $css_class;
4481: if ($rownum%2) {
4482: $css_class = 'LC_odd_row ';
4483: }
4484: $css_class .= $customclass;
4485: my $rowid = $optionsprefix.$status;
4486: my $hidden = 1;
4487: my $currstyle = 'display:none';
4488: if (grep(/^\Q$status\E$/,@overridden)) {
4489: $currstyle = 'display:table-row';
4490: $hidden = 0;
4491: }
4492: my $key = 'override_'.$status;
4493: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4494: $includeloc{$key},$includestr{$key},$status,$rowid,
4495: $usertypeshash{$status},$css_class,$currstyle,
4496: \@contacts,$short_titles);
4497: unless ($hidden) {
4498: $rownum ++;
1.160.6.78 raeburn 4499: }
4500: }
1.134 raeburn 4501: }
1.28 raeburn 4502: }
1.30 raeburn 4503: $$rowtotal += $rownum;
1.28 raeburn 4504: return $datatable;
4505: }
4506:
1.160.6.107 raeburn 4507: sub core_link_msu {
4508: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4509: &mt('LON-CAPA core group - MSU'),600,500);
4510: }
4511:
1.160.6.101 raeburn 4512: sub overridden_helpdesk {
4513: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4514: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4515: my $class = 'LC_left_item';
4516: if ($css_class) {
4517: $css_class = ' class="'.$css_class.'"';
4518: }
4519: if ($rowid) {
4520: $rowid = ' id="'.$rowid.'"';
4521: }
4522: if ($rowstyle) {
4523: $rowstyle = ' style="'.$rowstyle.'"';
4524: }
4525: my ($output,$description);
4526: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4527: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4528: "<td>$description</td>\n".
4529: '<td class="'.$class.'" colspan="2">'.
4530: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4531: '<span class="LC_nobreak">';
4532: if (ref($contacts) eq 'ARRAY') {
4533: foreach my $item (@{$contacts}) {
4534: my $check;
4535: if (ref($checked) eq 'HASH') {
4536: $check = $checked->{$item};
4537: }
4538: my $title;
4539: if (ref($short_titles) eq 'HASH') {
4540: $title = $short_titles->{$item};
4541: }
4542: $output .= '<label>'.
4543: '<input type="checkbox" name="override_'.$type.'"'.$check.
4544: ' value="'.$item.'" />'.$title.'</label> ';
4545: }
4546: }
4547: $output .= '</span><br />'.&mt('Others').': '.
4548: '<input type="text" name="override_'.$type.'_others" '.
4549: 'value="'.$otheremails.'" />';
4550: my %locchecked;
4551: foreach my $loc ('s','b') {
4552: if ($includeloc eq $loc) {
4553: $locchecked{$loc} = ' checked="checked"';
4554: last;
4555: }
4556: }
4557: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4558: '<input type="text" name="override_'.$type.'_bcc" '.
4559: 'value="'.$bccemails.'" /></fieldset>'.
4560: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4561: &mt('Text automatically added to e-mail:').' '.
4562: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4563: '<span class="LC_nobreak">'.&mt('Location:').' '.
4564: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4565: (' 'x2).
4566: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4567: '</span></fieldset>'.
4568: '</td></tr>'."\n";
4569: return $output;
4570: }
4571:
1.160.6.78 raeburn 4572: sub contacts_javascript {
4573: return <<"ENDSCRIPT";
4574:
4575: <script type="text/javascript">
4576: // <![CDATA[
4577:
4578: function screenshotSize(field) {
4579: if (document.getElementById('help_screenshotsize')) {
4580: if (field.value == 'no') {
4581: document.getElementById('help_screenshotsize').style.display="none";
4582: } else {
4583: document.getElementById('help_screenshotsize').style.display="";
4584: }
4585: }
4586: return;
4587: }
4588:
1.160.6.101 raeburn 4589: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4590: if (form.elements[checkbox].length != undefined) {
4591: var count = 0;
4592: if (docount) {
4593: for (var i=0; i<form.elements[checkbox].length; i++) {
4594: if (form.elements[checkbox][i].checked) {
4595: count ++;
4596: }
4597: }
4598: }
4599: for (var i=0; i<form.elements[checkbox].length; i++) {
4600: var type = form.elements[checkbox][i].value;
4601: if (document.getElementById(prefix+type)) {
4602: if (form.elements[checkbox][i].checked) {
4603: document.getElementById(prefix+type).style.display = 'table-row';
4604: if (count % 2 == 1) {
4605: document.getElementById(prefix+type).className = target+' LC_odd_row';
4606: } else {
4607: document.getElementById(prefix+type).className = target;
4608: }
4609: count ++;
4610: } else {
4611: document.getElementById(prefix+type).style.display = 'none';
4612: }
4613: }
4614: }
4615: }
4616: return;
4617: }
4618:
1.160.6.78 raeburn 4619: // ]]>
4620: </script>
4621:
4622: ENDSCRIPT
4623: }
4624:
1.118 jms 4625: sub print_helpsettings {
1.160.6.73 raeburn 4626: my ($position,$dom,$settings,$rowtotal) = @_;
4627: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4628: my $formname = 'display';
1.160.6.5 raeburn 4629: my ($datatable,$itemcount);
1.160.6.73 raeburn 4630: if ($position eq 'top') {
4631: $itemcount = 1;
4632: my (%choices,%defaultchecked,@toggles);
4633: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4634: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4635: &mt('LON-CAPA bug tracker'),600,500));
4636: %defaultchecked = ('submitbugs' => 'on');
4637: @toggles = ('submitbugs');
4638: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4639: \%choices,$itemcount);
4640: $$rowtotal ++;
4641: } else {
4642: my $css_class;
4643: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4644: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4645: if (ref($settings) eq 'HASH') {
4646: if (ref($settings->{'adhoc'}) eq 'HASH') {
4647: %current = %{$settings->{'adhoc'}};
4648: }
1.160.6.77 raeburn 4649: }
4650: my $count = 0;
4651: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4652: if ($key=~/^rolesdef\_(\w+)$/) {
4653: my $rolename = $1;
1.160.6.77 raeburn 4654: my (%privs,$order);
1.160.6.73 raeburn 4655: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4656: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4657: if (ref($current{$rolename}) eq 'HASH') {
4658: $order = $current{$rolename}{'order'};
4659: }
4660: if ($order eq '') {
4661: $order = $count;
4662: }
4663: $ordered{$order} = $rolename;
4664: $count++;
1.160.6.73 raeburn 4665: }
4666: }
1.160.6.77 raeburn 4667: my $maxnum = scalar(keys(%ordered));
4668: my @roles_by_num = ();
4669: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4670: push(@roles_by_num,$item);
4671: }
4672: my $context = 'domprefs';
4673: my $crstype = 'Course';
4674: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4675: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4676: my ($numstatustypes,@jsarray);
4677: if (ref($types) eq 'ARRAY') {
4678: if (@{$types} > 0) {
4679: $numstatustypes = scalar(@{$types});
4680: push(@accesstypes,'status');
4681: @jsarray = ('bystatus');
4682: }
4683: }
1.160.6.86 raeburn 4684: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4685: if (keys(%domhelpdesk)) {
4686: push(@accesstypes,('inc','exc'));
4687: push(@jsarray,('notinc','notexc'));
4688: }
4689: my $hiddenstr = join("','",@jsarray);
1.160.6.73 raeburn 4690: my $context = 'domprefs';
4691: my $crstype = 'Course';
1.160.6.77 raeburn 4692: my $prefix = 'helproles_';
4693: my $add_class = 'LC_hidden';
4694: foreach my $num (@roles_by_num) {
4695: my $role = $ordered{$num};
4696: my ($desc,$access,@statuses);
4697: if (ref($current{$role}) eq 'HASH') {
4698: $desc = $current{$role}{'desc'};
4699: $access = $current{$role}{'access'};
4700: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4701: @statuses = @{$current{$role}{'insttypes'}};
4702: }
4703: }
4704: if ($desc eq '') {
4705: $desc = $role;
4706: }
4707: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4708: my %full=();
4709: my %levels= (
4710: course => {},
4711: domain => {},
4712: system => {},
4713: );
4714: my %levelscurrent=(
4715: course => {},
4716: domain => {},
4717: system => {},
4718: );
4719: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4720: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4721: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4722: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4723: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4724: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4725: for (my $k=0; $k<=$maxnum; $k++) {
4726: my $vpos = $k+1;
4727: my $selstr;
4728: if ($k == $num) {
4729: $selstr = ' selected="selected" ';
4730: }
4731: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4732: }
4733: $datatable .= '</select>'.(' 'x2).
4734: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4735: '</td>'.
4736: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4737: &mt('Name shown to users:').
4738: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4739: '</fieldset>'.
4740: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4741: $othertitle,$usertypes,$types,\%domhelpdesk).
4742: '<fieldset>'.
4743: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4744: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4745: \%levelscurrent,$identifier,
4746: 'LC_hidden',$prefix.$num.'_privs').
4747: '</fieldset></td>';
1.160.6.73 raeburn 4748: $itemcount ++;
4749: }
4750: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4751: my $newcust = 'custhelp'.$count;
4752: my (%privs,%levelscurrent);
4753: my %full=();
4754: my %levels= (
4755: course => {},
4756: domain => {},
4757: system => {},
4758: );
4759: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4760: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4761: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4762: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4763: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4764: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4765: for (my $k=0; $k<$maxnum+1; $k++) {
4766: my $vpos = $k+1;
4767: my $selstr;
4768: if ($k == $maxnum) {
4769: $selstr = ' selected="selected" ';
4770: }
4771: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4772: }
4773: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4774: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4775: '</label></span></td>'.
1.160.6.77 raeburn 4776: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4777: '<span class="LC_nobreak">'.
4778: &mt('Internal name:').
4779: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4780: '</span>'.(' 'x4).
4781: '<span class="LC_nobreak">'.
4782: &mt('Name shown to users:').
4783: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4784: '</span></fieldset>'.
4785: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4786: $usertypes,$types,\%domhelpdesk).
4787: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4788: &Apache::lonuserutils::custom_role_header($context,$crstype,
4789: \@templateroles,$newcust).
4790: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4791: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4792: '</fieldset>'.
4793: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4794: '</td></tr>';
1.160.6.73 raeburn 4795: $count ++;
4796: $$rowtotal += $count;
4797: }
1.160.6.5 raeburn 4798: return $datatable;
1.121 raeburn 4799: }
4800:
1.160.6.77 raeburn 4801: sub adhocbutton {
4802: my ($prefix,$num,$field,$visibility) = @_;
4803: my %lt = &Apache::lonlocal::texthash(
4804: show => 'Show details',
4805: hide => 'Hide details',
4806: );
4807: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4808: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4809: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4810: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4811: }
4812:
4813: sub helpsettings_javascript {
4814: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4815: return unless(ref($roles_by_num) eq 'ARRAY');
4816: my %html_js_lt = &Apache::lonlocal::texthash(
4817: show => 'Show details',
4818: hide => 'Hide details',
4819: );
4820: &html_escape(\%html_js_lt);
4821: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4822: return <<"ENDSCRIPT";
4823: <script type="text/javascript">
4824: // <![CDATA[
4825:
4826: function reorderHelpRoles(form,item) {
4827: var changedVal;
4828: $jstext
4829: var newpos = 'helproles_${total}_pos';
4830: var maxh = 1 + $total;
4831: var current = new Array();
4832: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4833: if (item == newpos) {
4834: changedVal = newitemVal;
4835: } else {
4836: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4837: current[newitemVal] = newpos;
4838: }
4839: for (var i=0; i<helproles.length; i++) {
4840: var elementName = 'helproles_'+helproles[i]+'_pos';
4841: if (elementName != item) {
4842: if (form.elements[elementName]) {
4843: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4844: current[currVal] = elementName;
4845: }
4846: }
4847: }
4848: var oldVal;
4849: for (var j=0; j<maxh; j++) {
4850: if (current[j] == undefined) {
4851: oldVal = j;
4852: }
4853: }
4854: if (oldVal < changedVal) {
4855: for (var k=oldVal+1; k<=changedVal ; k++) {
4856: var elementName = current[k];
4857: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4858: }
4859: } else {
4860: for (var k=changedVal; k<oldVal; k++) {
4861: var elementName = current[k];
4862: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4863: }
4864: }
4865: return;
4866: }
4867:
4868: function helpdeskAccess(num) {
4869: var curraccess = null;
4870: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4871: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4872: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4873: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4874: }
4875: }
4876: }
4877: var shown = Array();
4878: var hidden = Array();
4879: if (curraccess == 'none') {
4880: hidden = Array('$hiddenstr');
4881: } else {
4882: if (curraccess == 'status') {
4883: shown = Array('bystatus');
4884: hidden = Array('notinc','notexc');
4885: } else {
4886: if (curraccess == 'exc') {
4887: shown = Array('notexc');
4888: hidden = Array('notinc','bystatus');
4889: }
4890: if (curraccess == 'inc') {
4891: shown = Array('notinc');
4892: hidden = Array('notexc','bystatus');
4893: }
1.160.6.79 raeburn 4894: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4895: hidden = Array('notinc','notexc','bystatus');
4896: }
4897: }
4898: }
4899: if (hidden.length > 0) {
4900: for (var i=0; i<hidden.length; i++) {
4901: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4902: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4903: }
4904: }
4905: }
4906: if (shown.length > 0) {
4907: for (var i=0; i<shown.length; i++) {
4908: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4909: if (shown[i] == 'privs') {
4910: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4911: } else {
4912: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4913: }
4914: }
4915: }
4916: }
4917: return;
4918: }
4919:
4920: function toggleHelpdeskItem(num,field) {
4921: if (document.getElementById('helproles_'+num+'_'+field)) {
4922: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4923: document.getElementById('helproles_'+num+'_'+field).className =
4924: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4925: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4926: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4927: }
4928: } else {
4929: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4930: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4931: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4932: }
4933: }
4934: }
4935: return;
4936: }
4937:
4938: // ]]>
4939: </script>
4940:
4941: ENDSCRIPT
4942: }
4943:
4944: sub helpdeskroles_access {
4945: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4946: $usertypes,$types,$domhelpdesk) = @_;
4947: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4948: my %lt = &Apache::lonlocal::texthash(
4949: 'rou' => 'Role usage',
4950: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4951: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4952: 'dh' => 'All with domain helpdesk role',
4953: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4954: 'none' => 'None',
4955: 'status' => 'Determined based on institutional status',
4956: 'inc' => 'Include all, but exclude specific personnel',
4957: 'exc' => 'Exclude all, but include specific personnel',
4958: );
4959: my %usecheck = (
4960: all => ' checked="checked"',
4961: );
4962: my %displaydiv = (
4963: status => 'none',
4964: inc => 'none',
4965: exc => 'none',
4966: priv => 'block',
4967: );
4968: my $output;
4969: if (ref($current) eq 'HASH') {
4970: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4971: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4972: $usecheck{$current->{access}} = $usecheck{'all'};
4973: delete($usecheck{'all'});
4974: if ($current->{access} =~ /^(status|inc|exc)$/) {
4975: my $access = $1;
4976: $displaydiv{$access} = 'inline';
4977: } elsif ($current->{access} eq 'none') {
4978: $displaydiv{'priv'} = 'none';
4979: }
4980: }
4981: }
4982: }
4983: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
4984: '<p>'.$lt{'whi'}.'</p>';
4985: foreach my $access (@{$accesstypes}) {
4986: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
4987: ' onclick="helpdeskAccess('."'$num'".');" />'.
4988: $lt{$access}.'</label>';
4989: if ($access eq 'status') {
4990: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
4991: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
4992: $othertitle,$usertypes,$types).
4993: '</div>';
4994: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
4995: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
4996: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
4997: '</div>';
4998: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
4999: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5000: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5001: '</div>';
5002: }
5003: $output .= '</p>';
5004: }
5005: $output .= '</fieldset>';
5006: return $output;
5007: }
5008:
1.121 raeburn 5009: sub radiobutton_prefs {
1.160.6.16 raeburn 5010: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 5011: $additional,$align,$firstval) = @_;
1.121 raeburn 5012: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5013: (ref($choices) eq 'HASH'));
5014:
5015: my (%checkedon,%checkedoff,$datatable,$css_class);
5016:
5017: foreach my $item (@{$toggles}) {
5018: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5019: $checkedon{$item} = ' checked="checked" ';
5020: $checkedoff{$item} = ' ';
1.121 raeburn 5021: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5022: $checkedoff{$item} = ' checked="checked" ';
5023: $checkedon{$item} = ' ';
5024: }
5025: }
5026: if (ref($settings) eq 'HASH') {
1.121 raeburn 5027: foreach my $item (@{$toggles}) {
1.118 jms 5028: if ($settings->{$item} eq '1') {
5029: $checkedon{$item} = ' checked="checked" ';
5030: $checkedoff{$item} = ' ';
5031: } elsif ($settings->{$item} eq '0') {
5032: $checkedoff{$item} = ' checked="checked" ';
5033: $checkedon{$item} = ' ';
5034: }
5035: }
1.121 raeburn 5036: }
1.160.6.16 raeburn 5037: if ($onclick) {
5038: $onclick = ' onclick="'.$onclick.'"';
5039: }
1.121 raeburn 5040: foreach my $item (@{$toggles}) {
1.118 jms 5041: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5042: $datatable .=
1.160.6.16 raeburn 5043: '<tr'.$css_class.'><td valign="top">'.
5044: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 5045: '</span></td>';
5046: if ($align eq 'left') {
5047: $datatable .= '<td class="LC_left_item">';
5048: } else {
5049: $datatable .= '<td class="LC_right_item">';
5050: }
1.160.6.113 raeburn 5051: $datatable .= '<span class="LC_nobreak">';
5052: if ($firstval eq 'no') {
5053: $datatable .=
5054: '<label><input type="radio" name="'.
5055: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5056: '</label> <label><input type="radio" name="'.$item.'" '.
5057: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5058: } else {
5059: $datatable .=
1.160.6.118.2 14(raebu 5060:23): '<label><input type="radio" name="'.
5061:23): $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5062:23): '</label> <label><input type="radio" name="'.$item.'" '.
5063:23): $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
1.160.6.113 raeburn 5064: }
5065: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5066: $itemcount ++;
1.121 raeburn 5067: }
5068: return ($datatable,$itemcount);
5069: }
5070:
1.160.6.118.2 1(raebur 5071:1): sub print_ltitools {
14(raebu 5072:23): my ($position,$dom,$settings,$rowtotal) = @_;
5073:23): my (%rules,%encrypt,%privkeys,%linkprot);
1(raebur 5074:1): if (ref($settings) eq 'HASH') {
14(raebu 5075:23): if ($position eq 'top') {
5076:23): if (exists($settings->{'encrypt'})) {
5077:23): if (ref($settings->{'encrypt'}) eq 'HASH') {
5078:23): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5079:23): $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1(raebur 5080:1): }
5081:1): }
5082:1): }
14(raebu 5083:23): if (exists($settings->{'private'})) {
5084:23): if (ref($settings->{'private'}) eq 'HASH') {
5085:23): if (ref($settings->{'private'}) eq 'HASH') {
5086:23): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5087:23): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1(raebur 5088:1): }
5089:1): }
5090:1): }
5091:1): }
14(raebu 5092:23): } elsif ($position eq 'middle') {
5093:23): if (exists($settings->{'rules'})) {
5094:23): if (ref($settings->{'rules'}) eq 'HASH') {
5095:23): %rules = %{$settings->{'rules'}};
1(raebur 5096:1): }
5097:1): }
14(raebu 5098:23): } else {
5099:23): foreach my $key ('encrypt','private','rules') {
5100:23): if (exists($settings->{$key})) {
5101:23): delete($settings->{$key});
1(raebur 5102:1): }
5103:1): }
5104:1): }
5105:1): }
14(raebu 5106:23): my $datatable;
5107:23): my $itemcount = 1;
5108:23): if ($position eq 'top') {
5109:23): $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5110:23): } elsif ($position eq 'middle') {
5111:23): $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5112:23): $$rowtotal += $itemcount;
5113:23): } else {
5114:23): $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1(raebur 5115:1): }
5116:1): return $datatable;
5117:1): }
5118:1):
5119:1): sub ltitools_names {
5120:1): my %lt = &Apache::lonlocal::texthash(
5121:1): 'title' => 'Title',
5122:1): 'version' => 'Version',
5123:1): 'msgtype' => 'Message Type',
5124:1): 'sigmethod' => 'Signature Method',
5125:1): 'url' => 'URL',
5126:1): 'key' => 'Key',
5127:1): 'lifetime' => 'Nonce lifetime (s)',
5128:1): 'secret' => 'Secret',
5129:1): 'icon' => 'Icon',
5130:1): 'user' => 'User',
5131:1): 'fullname' => 'Full Name',
5132:1): 'firstname' => 'First Name',
5133:1): 'lastname' => 'Last Name',
5134:1): 'email' => 'E-mail',
5135:1): 'roles' => 'Role',
5136:1): 'window' => 'Window',
5137:1): 'tab' => 'Tab',
5138:1): 'iframe' => 'iFrame',
5139:1): 'height' => 'Height',
5140:1): 'width' => 'Width',
5141:1): 'linktext' => 'Default Link Text',
5142:1): 'explanation' => 'Default Explanation',
14(raebu 5143:23): 'passback' => 'Tool can return grades:',
5144:23): 'roster' => 'Tool can retrieve roster:',
1(raebur 5145:1): 'crstarget' => 'Display target',
5146:1): 'crslabel' => 'Course label',
5147:1): 'crstitle' => 'Course title',
5148:1): 'crslinktext' => 'Link Text',
5149:1): 'crsexplanation' => 'Explanation',
5150:1): 'crsappend' => 'Provider URL',
5151:1): );
5152:1): return %lt;
5153:1): }
5154:1):
14(raebu 5155:23): sub secrets_form {
5156:23): my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5157:23): my @ids=&Apache::lonnet::current_machine_ids();
5158:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
5159:23): my $primary = &Apache::lonnet::domain($dom,'primary');
5160:23): my ($css_class,$extra,$numshown,$itemcount,$output);
5161:23): $itemcount = 0;
5162:23): foreach my $hostid (sort(keys(%servers))) {
5163:23): my ($showextra,$divsty,$switch);
5164:23): if ($hostid eq $primary) {
5165:23): if ($context eq 'ltisec') {
5166:23): if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5167:23): $showextra = 1;
5168:23): }
5169:23): if ($encrypt->{'ltisec_crslinkprot'}) {
5170:23): $showextra = 1;
5171:23): }
5172:23): } else {
5173:23): if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5174:23): $showextra = 1;
5175:23): }
5176:23): }
5177:23): unless (grep(/^\Q$hostid\E$/,@ids)) {
5178:23): $switch = 1;
5179:23): }
5180:23): if ($showextra) {
5181:23): $numshown ++;
5182:23): $divsty = 'display:inline-block';
5183:23): } else {
5184:23): $divsty = 'display:none';
5185:23): }
5186:23): $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5187:23): '<legend>'.$hostid.'</legend>';
5188:23): if ($switch) {
5189:23): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5190:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5191:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5192:23): if (exists($privkeys->{$hostid})) {
5193:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5194:23): '<span class="LC_nobreak">'.
5195:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5196:23): '<span class="LC_nobreak">'.&mt('Change?').
5197:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5198:23): (' 'x2).
5199:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5200:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5201:23): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5202:23): '</span></div>';
5203:23): } else {
5204:23): $extra .= '<span class="LC_nobreak">'.
5205:23): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5206:23): '</span>'."\n";
5207:23): }
5208:23): } elsif (exists($privkeys->{$hostid})) {
5209:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5210:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5211:23): '<span class="LC_nobreak">'.&mt('Change?').
5212:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5213:23): (' 'x2).
5214:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5215:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5216:23): '<span class="LC_nobreak">'.&mt('New Key').':'.
5217:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5218:23): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>'.
5219:23): '</span></div>';
5220:23): } else {
5221:23): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5222:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5223:23): '<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.'.$context.'_privkey_'.$hostid.'.type='."'text'".' } else { this.form.'.$context.'_privkey_'.$hostid.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5224:23): }
5225:23): $extra .= '</fieldset>';
5226:23): }
5227:23): }
5228:23): my (%choices,@toggles,%defaultchecked);
5229:23): if ($context eq 'ltisec') {
5230:23): %choices = &Apache::lonlocal::texthash (
5231:23): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5232:23): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5233:23): ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5234:23): );
5235:23): @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5236:23): %defaultchecked = (
5237:23): 'ltisec_crslinkprot' => 'off',
5238:23): 'ltisec_domlinkprot' => 'off',
5239:23): 'ltisec_consumers' => 'off',
5240:23): );
5241:23): } else {
5242:23): %choices = &Apache::lonlocal::texthash (
5243:23): toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5244:23): toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5245:23): );
5246:23): @toggles = qw(toolsec_crs toolsec_dom);
5247:23): %defaultchecked = (
5248:23): 'toolsec_crs' => 'off',
5249:23): 'toolsec_dom' => 'off',
5250:23): );
5251:23): }
5252:23): my ($onclick,$itemcount);
5253:23): $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5254:23): ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5255:23): \%choices,$itemcount,$onclick,'','left','no');
5256:23):
5257:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5258:23): my $noprivkeysty = 'display:inline-block';
5259:23): if ($numshown) {
5260:23): $noprivkeysty = 'display:none';
5261:23): }
5262:23): $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5263:23): '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5264:23): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5265:23): $extra.
5266:23): '</td></tr>';
5267:23): $itemcount ++;
5268:23): $$rowtotal += $itemcount;
5269:23): return $output;
5270:23): }
5271:23):
5(raebur 5272:2): sub print_lti {
5273:2): my ($position,$dom,$settings,$rowtotal) = @_;
5274:2): my $itemcount = 1;
5275:2): my ($datatable,$css_class);
5276:2): my (%rules,%encrypt,%privkeys,%linkprot);
5277:2): if (ref($settings) eq 'HASH') {
5278:2): if ($position eq 'top') {
5279:2): if (exists($settings->{'encrypt'})) {
5280:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5281:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
14(raebu 5282:23): if ($key eq 'consumers') {
5283:23): $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5284:23): } else {
5285:23): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5286:23): }
5(raebur 5287:2): }
5288:2): }
5289:2): }
5290:2): if (exists($settings->{'private'})) {
5291:2): if (ref($settings->{'private'}) eq 'HASH') {
5292:2): if (ref($settings->{'private'}) eq 'HASH') {
5293:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5294:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5295:2): }
5296:2): }
5297:2): }
5298:2): }
5299:2): } elsif ($position eq 'middle') {
5300:2): if (exists($settings->{'rules'})) {
5301:2): if (ref($settings->{'rules'}) eq 'HASH') {
5302:2): %rules = %{$settings->{'rules'}};
5303:2): }
5304:2): }
14(raebu 5305:23): } elsif ($position eq 'lower') {
5(raebur 5306:2): if (exists($settings->{'linkprot'})) {
5307:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5308:2): %linkprot = %{$settings->{'linkprot'}};
5309:2): if ($linkprot{'lock'}) {
5310:2): delete($linkprot{'lock'});
5311:2): }
5312:2): }
5313:2): }
14(raebu 5314:23): } else {
5315:23): foreach my $key ('encrypt','private','rules','linkprot') {
5316:23): if (exists($settings->{$key})) {
5317:23): delete($settings->{$key});
5318:23): }
5319:23): }
5(raebur 5320:2): }
5321:2): }
5322:2): if ($position eq 'top') {
14(raebu 5323:23): $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
5324:23): } elsif ($position eq 'middle') {
5325:23): $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5326:23): $$rowtotal += $itemcount;
5327:23): } elsif ($position eq 'lower') {
5328:23): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
5329:23): } else {
5330:23): my ($switchserver,$switchmessage);
5331:23): $switchserver = &check_switchserver($dom);
5332:23): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5333:23): my $maxnum = 0;
5334:23): my %ordered;
5335:23): if (ref($settings) eq 'HASH') {
5336:23): foreach my $item (keys(%{$settings})) {
5337:23): if (ref($settings->{$item}) eq 'HASH') {
5338:23): my $num = $settings->{$item}{'order'};
5339:23): if ($num eq '') {
5340:23): $num = scalar(keys(%{$settings}));
5341:23): }
5342:23): $ordered{$num} = $item;
5(raebur 5343:2): }
5344:2): }
14(raebu 5345:23): }
5346:23): $maxnum = scalar(keys(%ordered));
5347:23): my %lt = <i_names();
5348:23): if (keys(%ordered)) {
5349:23): my @items = sort { $a <=> $b } keys(%ordered);
5350:23): for (my $i=0; $i<@items; $i++) {
5351:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5352:23): my $item = $ordered{$items[$i]};
5353:23): my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5354:23): if (ref($settings->{$item}) eq 'HASH') {
5355:23): $key = $settings->{$item}->{'key'};
5356:23): $usable = $settings->{$item}->{'usable'};
5357:23): $lifetime = $settings->{$item}->{'lifetime'};
5358:23): $consumer = $settings->{$item}->{'consumer'};
5359:23): $requser = $settings->{$item}->{'requser'};
5360:23): $crsinc = $settings->{$item}->{'crsinc'};
5361:23): $current = $settings->{$item};
5362:23): }
5363:23): my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5364:23): my %checkedrequser = (
5365:23): yes => ' checked="checked"',
5366:23): no => '',
5367:23): );
5368:23): if (!$requser) {
5369:23): $checkedrequser{'no'} = $checkedrequser{'yes'};
5370:23): $checkedrequser{'yes'} = '';
5371:23): }
5372:23): my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5373:23): my %checkedcrsinc = (
5374:23): yes => ' checked="checked"',
5375:23): no => '',
5376:23): );
5377:23): if (!$crsinc) {
5378:23): $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5379:23): $checkedcrsinc{'yes'} = '';
5380:23): }
5381:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5382:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5383:23): .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5384:23): for (my $k=0; $k<=$maxnum; $k++) {
5385:23): my $vpos = $k+1;
5386:23): my $selstr;
5387:23): if ($k == $i) {
5388:23): $selstr = ' selected="selected" ';
5389:23): }
5390:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5391:23): }
5392:23): $datatable .= '</select>'.(' 'x2).
5393:23): '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5394:23): &mt('Delete?').'</label></span></td>'.
5395:23): '<td colspan="2">'.
5396:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5397:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5398:23): ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5399:23): (' 'x2).
5400:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5401:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5402:23): (' 'x2).
5403:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5404:23): 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5405:23): if ($key ne '') {
5406:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5407:23): if ($switchserver) {
5408:23): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5409:23): } else {
5410:23): $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5411:23): }
5412:23): $datatable .= '</span> '.(' 'x2);
5413:23): } elsif (!$switchserver) {
5414:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5415:23): '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5416:23): '</span> '.(' 'x2);
5417:23): }
5418:23): if ($switchserver) {
5419:23): if ($usable ne '') {
5420:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5421:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5422:23): '<span class="LC_nobreak">'.&mt('Change secret?').
5423:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5424:23): (' 'x2).
5425:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5426:23): '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5427:23): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5428:23): '</div>';
5429:23): } elsif ($key eq '') {
5430:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5431:23): } else {
5432:23): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5433:23): }
5434:23): } else {
5435:23): if ($usable ne '') {
5436:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5437:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5438:23): '<span class="LC_nobreak">'.&mt('Change?').
5439:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5440:23): (' 'x2).
5441:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5442:23): '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5443:23): '<span class="LC_nobreak">'.&mt('New Secret').':'.
5444:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5445:23): '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label></span></div>';
5446:23): } else {
5447:23): $datatable .=
5448:23): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5449:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5450:23): '<label><input type="checkbox" name="lti_visible_'.$i.'" id="lti_visible_'.$i.'" onclick="if (this.checked) { this.form.lti_secret_'.$i.'.type='."'text'".' } else { this.form.lti_secret_'.$i.'.type='."'password'".' }" />'.&mt('Visible input').'</label>';
5451:23): }
5452:23): }
5453:23): $datatable .= '<br /><br />'.
5454:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5455:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5456:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5457:23): '<br /><br />'.
5458:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5459:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5460:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5461:23): (' 'x4).
5462:23): '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5463:23): '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5464:23): $itemcount ++;
5(raebur 5465:2): }
14(raebu 5466:23): }
5467:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5468:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5469:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5470:23): '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5471:23): '<select name="lti_pos_add"'.$chgstr.'>';
5472:23): for (my $k=0; $k<$maxnum+1; $k++) {
5473:23): my $vpos = $k+1;
5474:23): my $selstr;
5475:23): if ($k == $maxnum) {
5476:23): $selstr = ' selected="selected" ';
5(raebur 5477:2): }
14(raebu 5478:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5479:23): }
5480:23): $datatable .= '</select> '."\n".
5481:23): '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5482:23): '<td colspan="2">'.
5483:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5484:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5485:23): ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5486:23): (' 'x2).
5487:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5488:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5489:23): (' 'x2).
5490:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5491:23): if ($switchserver) {
5492:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5493:23): } else {
5494:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5495:23): (' 'x2).
5496:23): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5497:23): '<label><input type="checkbox" name="lti_add_visible" id="lti_add_visible" onclick="if (this.checked) { this.form.lti_secret_add.type='."'text'".' } else { this.form.lti_secret_add.type='."'password'".' }" />'.&mt('Visible input').'</label></span> '."\n";
5498:23): }
5499:23): $datatable .= '<br /><br />'.
5500:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5501:23): '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5502:23): '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5503:23): '<br /><br />'.
5504:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5505:23): '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5506:23): '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5507:23): '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5508:23): '</td>'."\n".
5509:23): '</tr>'."\n";
5510:23): $itemcount ++;
5511:23): }
5512:23): $$rowtotal += $itemcount;
5513:23): return $datatable;
5514:23): }
5515:23):
5516:23): sub lti_names {
5517:23): my %lt = &Apache::lonlocal::texthash(
5518:23): 'version' => 'LTI Version',
5519:23): 'url' => 'URL',
5520:23): 'key' => 'Key',
5521:23): 'lifetime' => 'Nonce lifetime (s)',
5522:23): 'consumer' => 'Consumer',
5523:23): 'secret' => 'Secret',
5524:23): 'requser' => "User's identity sent",
5525:23): 'crsinc' => "Course's identity sent",
5526:23): 'email' => 'Email address',
5527:23): 'sourcedid' => 'User ID',
5528:23): 'other' => 'Other',
5529:23): 'passback' => 'Can return grades to Consumer:',
5530:23): 'roster' => 'Can retrieve roster from Consumer:',
5531:23): 'topmenu' => 'Display LON-CAPA page header',
5532:23): 'inlinemenu'=> 'Display LON-CAPA inline menu',
5533:23): );
5534:23): return %lt;
5535:23): }
5536:23):
5537:23): sub lti_options {
5538:23): my ($num,$current,$itemcount,%lt) = @_;
5539:23): my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5540:23): $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5541:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5542:23): $checked{'storecrs'}{'Y'} = ' checked="checked"';
5543:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5544:23): $checked{'mapcrstype'} = {};
5545:23): $checked{'makeuser'} = {};
5546:23): $checked{'selfenroll'} = {};
5547:23): $checked{'crssec'} = {};
5548:23): $checked{'crssecsrc'} = {};
5549:23): $checked{'lcauth'} = {};
5550:23): $checked{'menuitem'} = {};
5551:23): if ($num eq 'add') {
5552:23): $checked{'lcauth'}{'lti'} = ' checked="checked"';
5553:23): }
5554:23): my $userfieldsty = 'none';
5555:23): my $crsfieldsty = 'none';
5556:23): my $crssecfieldsty = 'none';
5557:23): my $secsrcfieldsty = 'none';
5558:23): my $callbacksty = 'none';
5559:23): my $passbacksty = 'none';
5560:23): my $optionsty = 'block';
5561:23): my $crssty = 'block';
5562:23): my $lcauthparm;
5563:23): my $lcauthparmstyle = 'display:none';
5564:23): my $lcauthparmtext;
5565:23): my $menusty;
5566:23): my $numinrow = 4;
5567:23): my %menutitles = <imenu_titles();
5568:23):
5569:23): if (ref($current) eq 'HASH') {
5570:23): if (!$current->{'requser'}) {
5571:23): $optionsty = 'none';
5572:23): $crssty = 'none';
5573:23): } elsif (!$current->{'crsinc'}) {
5574:23): $crssty = 'none';
5575:23): }
5576:23): if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5577:23): $checked{'mapuser'}{'sourcedid'} = '';
5578:23): if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5579:23): $checked{'mapuser'}{'email'} = ' checked="checked"';
5(raebur 5580:2): } else {
14(raebu 5581:23): $checked{'mapuser'}{'other'} = ' checked="checked"';
5582:23): $userfield = $current->{'mapuser'};
5583:23): $userfieldsty = 'inline-block';
5(raebur 5584:2): }
14(raebu 5585:23): }
5586:23): if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5587:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5588:23): if ($current->{'mapcrs'} eq 'context_id') {
5589:23): $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5590:23): } else {
5591:23): $checked{'mapcrs'}{'other'} = ' checked="checked"';
5592:23): $cidfield = $current->{'mapcrs'};
5593:23): $crsfieldsty = 'inline-block';
5594:23): }
5595:23): }
5596:23): if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5597:23): foreach my $type (@{$current->{'mapcrstype'}}) {
5598:23): $checked{'mapcrstype'}{$type} = ' checked="checked"';
5599:23): }
5600:23): }
5601:23): if (!$current->{'storecrs'}) {
5602:23): $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5603:23): $checked{'storecrs'}{'Y'} = '';
5604:23): }
5605:23): if ($current->{'makecrs'}) {
5606:23): $checked{'makecrs'}{'Y'} = ' checked="checked"';
5607:23): }
5608:23): if (ref($current->{'makeuser'}) eq 'ARRAY') {
5609:23): foreach my $role (@{$current->{'makeuser'}}) {
5610:23): $checked{'makeuser'}{$role} = ' checked="checked"';
5611:23): }
5612:23): }
5613:23): if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5614:23): $checked{'lcauth'}{$1} = ' checked="checked"';
5615:23): unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5616:23): $lcauthparm = $current->{'lcauthparm'};
5617:23): $lcauthparmstyle = 'display:table-row';
5618:23): if ($current->{'lcauth'} eq 'localauth') {
5619:23): $lcauthparmtext = &mt('Local auth argument');
5(raebur 5620:2): } else {
14(raebu 5621:23): $lcauthparmtext = &mt('Kerberos domain');
5(raebur 5622:2): }
14(raebu 5623:23): }
5624:23): }
5625:23): if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5626:23): foreach my $role (@{$current->{'selfenroll'}}) {
5627:23): $checked{'selfenroll'}{$role} = ' checked="checked"';
5628:23): }
5629:23): }
5630:23): if (ref($current->{'maproles'}) eq 'HASH') {
5631:23): %rolemaps = %{$current->{'maproles'}};
5632:23): }
5633:23): if ($current->{'section'} ne '') {
5634:23): $checked{'crssec'}{'Y'} = ' checked="checked"';
5635:23): $crssecfieldsty = 'inline-block';
5636:23): if ($current->{'section'} eq 'course_section_sourcedid') {
5637:23): $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5(raebur 5638:2): } else {
14(raebu 5639:23): $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5640:23): $crssecsrc = $current->{'section'};
5641:23): $secsrcfieldsty = 'inline-block';
5(raebur 5642:2): }
14(raebu 5643:23): } else {
5644:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5(raebur 5645:2): }
14(raebu 5646:23): if ($current->{'callback'} ne '') {
5647:23): $callback = $current->{'callback'};
5648:23): $checked{'callback'}{'Y'} = ' checked="checked"';
5649:23): $callbacksty = 'inline-block';
5650:23): } else {
5651:23): $checked{'callback'}{'N'} = ' checked="checked"';
5652:23): }
5653:23): if ($current->{'topmenu'}) {
5654:23): $checked{'topmenu'}{'Y'} = ' checked="checked"';
5655:23): } else {
5656:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5657:23): }
5658:23): if ($current->{'inlinemenu'}) {
5659:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5660:23): } else {
5661:23): $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5662:23): }
5663:23): if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5664:23): $menusty = 'inline-block';
5665:23): if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5666:23): foreach my $item (@{$current->{'lcmenu'}}) {
5667:23): if (exists($menutitles{$item})) {
5668:23): $checked{'menuitem'}{$item} = ' checked="checked"';
5669:23): }
5670:23): }
5671:23): }
5672:23): } else {
5673:23): $menusty = 'none';
5674:23): }
5675:23): } else {
5676:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5677:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5678:23): $checked{'callback'}{'N'} = ' checked="checked"';
5679:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5680:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5681:23): $checked{'menuitem'}{'grades'} = ' checked="checked"';
5682:23): $menusty = 'inline-block';
5(raebur 5683:2): }
14(raebu 5684:23): my @coursetypes = ('official','unofficial','community','textbook','lti');
5685:23): my %coursetypetitles = &Apache::lonlocal::texthash (
5686:23): official => 'Official',
5687:23): unofficial => 'Unofficial',
5688:23): community => 'Community',
5689:23): textbook => 'Textbook',
5690:23): lti => 'LTI Provider',
5691:23): );
5692:23): my @authtypes = ('internal','krb4','krb5','localauth');
5693:23): my %shortauth = (
5694:23): internal => 'int',
5695:23): krb4 => 'krb4',
5696:23): krb5 => 'krb5',
5697:23): localauth => 'loc'
5698:23): );
5699:23): my %authnames = &authtype_names();
5700:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5701:23): my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5702:23): my @courseroles = ('cc','in','ta','ep','st');
5703:23): my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5704:23): my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5705:23): my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5706:23): my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5707:23): my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5708:23): my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5709:23): my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5710:23): my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5711:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5712:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5713:23): $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5714:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5715:23): $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5716:23): '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5717:23): '<span class="LC_nobreak">'.&mt('Parameter').': '.
5718:23): '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5719:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5720:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5721:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5722:23): foreach my $option ('sourcedid','email','other') {
5723:23): $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5724:23): $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5725:23): ($option eq 'other' ? '' : (' 'x2) );
5726:23): }
5727:23): $output .= '</span></div>'.
5728:23): '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5729:23): '<input type="text" name="lti_customuser_'.$num.'" '.
5730:23): 'value="'.$userfield.'" /></div></fieldset>'.
5731:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5732:23): foreach my $ltirole (@ltiroles) {
5733:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5734:23): $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5735:23): }
5736:23): $output .= '</fieldset>'.
5737:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5738:23): '<table>'.
5739:23): &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5740:23): '</table>'.
5741:23): '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5742:23): '<td class="LC_left_item">';
5743:23): foreach my $auth ('lti',@authtypes) {
5744:23): my $authtext;
5745:23): if ($auth eq 'lti') {
5746:23): $authtext = &mt('None');
5747:23): } else {
5748:23): $authtext = $authnames{$shortauth{$auth}};
5749:23): }
5750:23): $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5751:23): '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5752:23): $authtext.'</label></span> ';
5753:23): }
5754:23): $output .= '</td></tr>'.
5755:23): '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5756:23): '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5757:23): '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5758:23): '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5759:23): '</table></fieldset>'.
5760:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5761:23): &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5762:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5763:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5764:23): $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5765:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5766:23): $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5767:23): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5768:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5769:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5770:23): $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5771:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5772:23): $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5773:23): $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5774:23): '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5775:23): '<span class="LC_nobreak">'.&mt('Menu items').': ';
5776:23): foreach my $type ('fullname','coursetitle','role','logout','grades') {
5777:23): $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5778:23): $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5779:23): (' 'x2);
5780:23): }
5781:23): $output .= '</span></div></fieldset>'.
5782:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5783:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.
5784:23): &mt('Unique course identifier').': ';
5785:23): foreach my $option ('course_offering_sourcedid','context_id','other') {
5786:23): $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5787:23): $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5788:23): ($option eq 'other' ? '' : (' 'x2) );
5789:23): }
5790:23): $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5791:23): '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5792:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5793:23): '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5794:23): foreach my $type (@coursetypes) {
5795:23): $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5796:23): $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5797:23): (' 'x2);
5798:23): }
5799:23): $output .= '</span><br /><br />'.
5800:23): '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5801:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5802:23): $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5803:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5804:23): $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5805:23): '</fieldset>'.
5806:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5807:23): foreach my $ltirole (@lticourseroles) {
5808:23): my ($selected,$selectnone);
5809:23): if ($rolemaps{$ltirole} eq '') {
5810:23): $selectnone = ' selected="selected"';
5811:23): }
5812:23): $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5813:23): '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5814:23): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5815:23): foreach my $role (@courseroles) {
5816:23): unless ($selectnone) {
5817:23): if ($rolemaps{$ltirole} eq $role) {
5818:23): $selected = ' selected="selected"';
5819:23): } else {
5820:23): $selected = '';
5821:23): }
5822:23): }
5823:23): $output .= '<option value="'.$role.'"'.$selected.'>'.
5824:23): &Apache::lonnet::plaintext($role,'Course').
5825:23): '</option>';
5826:23): }
5827:23): $output .= '</select></td>';
5828:23): }
5829:23): $output .= '</tr></table></fieldset>'.
5830:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5831:23): '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5832:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5833:23): $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5834:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5835:23): $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5836:23): '</fieldset>'.
5837:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5838:23): foreach my $lticrsrole (@lticourseroles) {
5839:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5840:23): $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5841:23): }
5842:23): $output .= '</fieldset>'.
5843:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5844:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5845:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5846:23): $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5847:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5848:23): $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5849:23): '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5850:23): '<span class="LC_nobreak">'.&mt('From').':<label>'.
5851:23): '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5852:23): $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5853:23): &mt('Standard field').'</label>'.(' 'x2).
5854:23): '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5855:23): $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5856:23): '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5857:23): '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5858:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5859:23): my ($pb1p1chk,$pb1p0chk,$onclickpb);
5860:23): foreach my $extra ('roster','passback') {
5861:23): my $checkedon = '';
5862:23): my $checkedoff = ' checked="checked"';
5863:23): if ($extra eq 'passback') {
5864:23): $pb1p1chk = ' checked="checked"';
5865:23): $pb1p0chk = '';
5866:23): $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5867:23): } else {
5868:23): $onclickpb = '';
5869:23): }
5870:23): if (ref($current) eq 'HASH') {
5871:23): if (($current->{$extra})) {
5872:23): $checkedon = $checkedoff;
5873:23): $checkedoff = '';
5874:23): if ($extra eq 'passback') {
5875:23): $passbacksty = 'inline-block';
5876:23): }
5877:23): if ($current->{'passbackformat'} eq '1.0') {
5878:23): $pb1p0chk = ' checked="checked"';
5879:23): $pb1p1chk = '';
5880:23): }
5881:23): }
5882:23): }
5883:23): $output .= $lt{$extra}.' '.
5884:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5885:23): &mt('No').'</label>'.(' 'x2).
5886:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5887:23): &mt('Yes').'</label><br />';
5888:23): }
5889:23): $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5890:23): '<span class="LC_nobreak">'.&mt('Grade format').
5891:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5892:23): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5893:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5894:23): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5895:23): '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5896:23): $output .= '</span></div></fieldset>';
5897:23): # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5898:23): #
5899:23): # $output .= '</fieldset>'.
5900:23): # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5901:23): return $output;
5902:23): }
5903:23):
5904:23): sub ltimenu_titles {
5905:23): return &Apache::lonlocal::texthash(
5906:23): fullname => 'Full name',
5907:23): coursetitle => 'Course title',
5908:23): role => 'Role',
5909:23): logout => 'Logout',
5910:23): grades => 'Grades',
5911:23): );
5(raebur 5912:2): }
5913:2):
14(raebu 5914:23):
5915:23):
1.121 raeburn 5916: sub print_coursedefaults {
1.139 raeburn 5917: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5918: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5919: my $itemcount = 1;
1.160.6.16 raeburn 5920: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 5921: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.118.2 15(raebu 5922:23): coursequota => 'Default cumulative quota for all group portfolio spaces in course',
1.160.6.16 raeburn 5923: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5924: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 5925: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5926: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 5927: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 5928: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 5929: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 5930: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 5931: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 5932:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
14(raebu 5933:23): domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
5934:23): exttool => 'External Tools can be defined and configured in courses/communities (by type)',
7(raebur 5935:2): );
1.160.6.21 raeburn 5936: my %staticdefaults = (
5937: anonsurvey_threshold => 10,
5938: uploadquota => 500,
1.160.6.118.2 15(raebu 5939:23): coursequota => 20,
1.160.6.57 raeburn 5940: postsubmit => 60,
1.160.6.70 raeburn 5941: mysqltables => 172800,
1.160.6.118.2 14(raebu 5942:23): domexttool => 1,
5943:23): exttool => 0,
1.160.6.21 raeburn 5944: );
1.139 raeburn 5945: if ($position eq 'top') {
1.160.6.57 raeburn 5946: %defaultchecked = (
5947: 'uselcmath' => 'on',
5948: 'usejsme' => 'on',
1.160.6.115 raeburn 5949: 'inline_chem' => 'on',
1.160.6.64 raeburn 5950: 'canclone' => 'none',
1.160.6.57 raeburn 5951: );
1.160.6.115 raeburn 5952: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 5953: my $deftex = $Apache::lonnet::deftex;
5954: if (ref($settings) eq 'HASH') {
5955: if ($settings->{'texengine'}) {
5956: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
5957: $deftex = $settings->{'texengine'};
5958: }
5959: }
5960: }
5961: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5962: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
5963: '<span class="LC_nobreak">'.$choices{'texengine'}.
5964: '</span></td><td class="LC_right_item">'.
5965: '<select name="texengine">'."\n";
5966: my %texoptions = (
5967: MathJax => 'MathJax',
5968: mimetex => &mt('Convert to Images'),
5969: tth => &mt('TeX to HTML'),
5970: );
5971: foreach my $renderer ('MathJax','mimetex','tth') {
5972: my $selected = '';
5973: if ($renderer eq $deftex) {
5974: $selected = ' selected="selected"';
5975: }
5976: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
5977: }
5978: $mathdisp .= '</select></td></tr>'."\n";
5979: $itemcount ++;
1.139 raeburn 5980: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 5981: \%choices,$itemcount);
1.160.6.90 raeburn 5982: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 5983: $css_class = $itemcount%2?' class="LC_odd_row"':'';
5984: $datatable .=
5985: '<tr'.$css_class.'><td valign="top">'.
5986: '<span class="LC_nobreak">'.$choices{'canclone'}.
5987: '</span></td><td class="LC_left_item">';
5988: my $currcanclone = 'none';
5989: my $onclick;
5990: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 5991: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 5992: none => 'No additional course requesters',
5993: domain => "Any course requester in course's domain",
5994: instcode => 'Course requests for official courses ...',
5995: );
5996: my (%codedefaults,@code_order,@posscodes);
5997: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
5998: \@code_order) eq 'ok') {
5999: if (@code_order > 0) {
6000: push(@cloneoptions,'instcode');
6001: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6002: }
6003: }
6004: if (ref($settings) eq 'HASH') {
6005: if ($settings->{'canclone'}) {
6006: if (ref($settings->{'canclone'}) eq 'HASH') {
6007: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6008: if (@code_order > 0) {
6009: $currcanclone = 'instcode';
6010: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6011: }
6012: }
6013: } elsif ($settings->{'canclone'} eq 'domain') {
6014: $currcanclone = $settings->{'canclone'};
6015: }
6016: }
6017: }
6018: foreach my $option (@cloneoptions) {
6019: my ($checked,$additional);
6020: if ($currcanclone eq $option) {
6021: $checked = ' checked="checked"';
6022: }
6023: if ($option eq 'instcode') {
6024: if (@code_order) {
6025: my $show = 'none';
6026: if ($checked) {
6027: $show = 'block';
6028: }
1.160.6.118.2 14(raebu 6029:23): $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.160.6.64 raeburn 6030: &mt('Institutional codes for new and cloned course have identical:').
6031: '<br />';
6032: foreach my $item (@code_order) {
6033: my $codechk;
6034: if ($checked) {
6035: if (grep(/^\Q$item\E$/,@posscodes)) {
6036: $codechk = ' checked="checked"';
6037: }
6038: }
6039: $additional .= '<label>'.
6040: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6041: $item.'</label>';
6042: }
6043: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6044: }
6045: }
6046: $datatable .=
6047: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6048: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6049: '</label> '.$additional.'</span><br />';
6050: }
6051: $datatable .= '</td>'.
6052: '</tr>';
6053: $itemcount ++;
1.139 raeburn 6054: } else {
6055: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.118.2 15(raebu 6056:23): my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6057:23): %deftimeout,%currmysql);
1.160.6.16 raeburn 6058: my $currusecredits = 0;
1.160.6.57 raeburn 6059: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 6060:2): my $ltiauth = 0;
14(raebu 6061:23): my %domexttool;
6062:23): my %exttool;
1.160.6.30 raeburn 6063: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 6064: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 6065:2): if ($settings->{'ltiauth'}) {
6066:2): $ltiauth = 1;
6067:2): }
14(raebu 6068:23): if (ref($settings->{'domexttool'}) eq 'HASH') {
6069:23): foreach my $type (@types) {
6070:23): if ($settings->{'domexttool'}->{$type}) {
6071:23): $domexttool{$type} = ' checked="checked"';
6072:23): }
6073:23): }
6074:23): } else {
6075:23): foreach my $type (@types) {
6076:23): if ($staticdefaults{'domexttool'}) {
6077:23): $domexttool{$type} = ' checked="checked"';
6078:23): }
6079:23): }
6080:23): }
6081:23): if (ref($settings->{'exttool'}) eq 'HASH') {
6082:23): foreach my $type (@types) {
6083:23): if ($settings->{'exttool'}->{$type}) {
6084:23): $exttool{$type} = ' checked="checked"';
6085:23): }
6086:23): }
6087:23): }
1.139 raeburn 6088: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 6089: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6090: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6091: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6092: }
6093: }
1.160.6.118.2 15(raebu 6094:23): if (ref($settings->{'coursequota'}) eq 'HASH') {
6095:23): foreach my $type (keys(%{$settings->{'coursequota'}})) {
6096:23): $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6097:23): }
6098:23): }
1.160.6.16 raeburn 6099: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 6100: foreach my $type (@types) {
6101: next if ($type eq 'community');
6102: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6103: if ($defcredits{$type} ne '') {
6104: $currusecredits = 1;
6105: }
6106: }
6107: }
6108: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6109: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6110: $postsubmitclient = 0;
6111: foreach my $type (@types) {
6112: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6113: }
6114: } else {
6115: foreach my $type (@types) {
6116: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6117: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6118: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6119: } else {
6120: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6121: }
6122: } else {
6123: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6124: }
6125: }
6126: }
6127: } else {
6128: foreach my $type (@types) {
6129: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 6130: }
6131: }
1.160.6.70 raeburn 6132: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6133: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6134: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6135: }
6136: } else {
6137: foreach my $type (@types) {
6138: $currmysql{$type} = $staticdefaults{'mysqltables'};
6139: }
6140: }
1.160.6.58 raeburn 6141: } else {
6142: foreach my $type (@types) {
6143: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.118.2 14(raebu 6144:23): if ($staticdefaults{'domexttool'}) {
6145:23): $domexttool{$type} = ' checked="checked"';
6146:23): }
1.160.6.58 raeburn 6147: }
1.139 raeburn 6148: }
6149: if (!$currdefresponder) {
1.160.6.21 raeburn 6150: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6151: } elsif ($currdefresponder < 1) {
6152: $currdefresponder = 1;
6153: }
1.160.6.21 raeburn 6154: foreach my $type (@types) {
6155: if ($curruploadquota{$type} eq '') {
6156: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6157: }
1.160.6.118.2 15(raebu 6158:23): if ($currcoursequota{$type} eq '') {
6159:23): $currcoursequota{$type} = $staticdefaults{'coursequota'};
6160:23): }
1.160.6.21 raeburn 6161: }
1.139 raeburn 6162: $datatable .=
1.160.6.16 raeburn 6163: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6164: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6165: '</span></td>'.
6166: '<td class="LC_right_item"><span class="LC_nobreak">'.
6167: '<input type="text" name="anonsurvey_threshold"'.
6168: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 6169: '</td></tr>'."\n";
6170: $itemcount ++;
6171: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6172: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6173: $choices{'uploadquota'}.
6174: '</span></td>'.
6175: '<td align="right" class="LC_right_item">'.
6176: '<table><tr>';
1.160.6.21 raeburn 6177: foreach my $type (@types) {
6178: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6179: '<input type="text" name="uploadquota_'.$type.'"'.
6180: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6181: }
6182: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 6183: $itemcount ++;
1.160.6.118.2 15(raebu 6184:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6185:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6186:23): $choices{'coursequota'}.
6187:23): '</span></td>'.
6188:23): '<td style="text-align: right" class="LC_right_item">'.
6189:23): '<table><tr>';
6190:23): foreach my $type (@types) {
6191:23): $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6192:23): '<input type="text" name="coursequota_'.$type.'"'.
6193:23): ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6194:23): }
6195:23): $datatable .= '</tr></table></td></tr>'."\n";
6196:23): $itemcount ++;
1.160.6.40 raeburn 6197: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 6198: my $display = 'none';
6199: if ($currusecredits) {
6200: $display = 'block';
6201: }
6202: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 6203: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6204: foreach my $type (@types) {
6205: next if ($type eq 'community');
6206: $additional .= '<td align="center">'.&mt($type).'<br />'.
6207: '<input type="text" name="'.$type.'_credits"'.
6208: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6209: }
6210: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 6211: %defaultchecked = ('coursecredits' => 'off');
6212: @toggles = ('coursecredits');
6213: my $current = {
6214: 'coursecredits' => $currusecredits,
6215: };
6216: (my $table,$itemcount) =
6217: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6218: \%choices,$itemcount,$onclick,$additional,'left');
6219: $datatable .= $table;
6220: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6221: my $display = 'none';
6222: if ($postsubmitclient) {
6223: $display = 'block';
6224: }
6225: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 6226: &mt('Number of seconds submit is disabled').'<br />'.
6227: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6228: '<table><tr>';
1.160.6.57 raeburn 6229: foreach my $type (@types) {
6230: $additional .= '<td align="center">'.&mt($type).'<br />'.
6231: '<input type="text" name="'.$type.'_timeout" value="'.
6232: $deftimeout{$type}.'" size="5" /></td>';
6233: }
6234: $additional .= '</tr></table></div>'."\n";
6235: %defaultchecked = ('postsubmit' => 'on');
6236: @toggles = ('postsubmit');
1.160.6.70 raeburn 6237: $current = {
6238: 'postsubmit' => $postsubmitclient,
6239: };
1.160.6.57 raeburn 6240: ($table,$itemcount) =
6241: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6242: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 6243: $datatable .= $table;
1.160.6.70 raeburn 6244: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6245: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6246: $choices{'mysqltables'}.
6247: '</span></td>'.
6248: '<td align="right" class="LC_right_item">'.
6249: '<table><tr>';
6250: foreach my $type (@types) {
6251: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6252: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 6253: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 6254: }
6255: $datatable .= '</tr></table></td></tr>'."\n";
6256: $itemcount ++;
1.160.6.118.2 4(raebur 6257:2): %defaultchecked = ('ltiauth' => 'off');
6258:2): @toggles = ('ltiauth');
6259:2): $current = {
6260:2): 'ltiauth' => $ltiauth,
6261:2): };
6262:2): ($table,$itemcount) =
6263:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6264:2): \%choices,$itemcount,undef,undef,'left');
6265:2): $datatable .= $table;
14(raebu 6266:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6267:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6268:23): $choices{'domexttool'}.
6269:23): '</span></td>'.
6270:23): '<td style="text-align: right" class="LC_right_item">'.
6271:23): '<table><tr>';
6272:23): foreach my $type (@types) {
6273:23): $datatable .= '<td style="text-align: left">'.
6274:23): '<span class="LC_nobreak">'.
6275:23): '<input type="checkbox" name="domexttool"'.
6276:23): ' value="'.$type.'"'.$domexttool{$type}.' />'.
6277:23): &mt($type).'</span></td>'."\n";
6278:23): }
6279:23): $datatable .= '</tr></table></td></tr>'."\n";
4(raebur 6280:2): $itemcount ++;
14(raebu 6281:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6282:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6283:23): $choices{'exttool'}.
6284:23): '</span></td>'.
6285:23): '<td style="text-align: right" class="LC_right_item">'.
6286:23): '<table><tr>';
6287:23): foreach my $type (@types) {
6288:23): $datatable .= '<td style="text-align: left">'.
6289:23): '<span class="LC_nobreak">'.
6290:23): '<input type="checkbox" name="exttool"'.
6291:23): ' value="'.$type.'"'.$exttool{$type}.' />'.
6292:23): &mt($type).'</span></td>'."\n";
6293:23): }
6294:23): $datatable .= '</tr></table></td></tr>'."\n";
6295:23): }
6296:23): $$rowtotal += $itemcount;
6297:23): return $datatable;
6298:23): }
6299:23):
6300:23): sub print_selfenrollment {
1.160.6.37 raeburn 6301: my ($position,$dom,$settings,$rowtotal) = @_;
6302: my ($css_class,$datatable);
6303: my $itemcount = 1;
6304: my @types = ('official','unofficial','community','textbook');
6305: if (($position eq 'top') || ($position eq 'middle')) {
6306: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6307: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6308: my @rows;
6309: my $key;
6310: if ($position eq 'top') {
6311: $key = 'admin';
6312: if (ref($rowsref) eq 'ARRAY') {
6313: @rows = @{$rowsref};
6314: }
6315: } elsif ($position eq 'middle') {
6316: $key = 'default';
6317: @rows = ('types','registered','approval','limit');
6318: }
6319: foreach my $row (@rows) {
6320: if (defined($titlesref->{$row})) {
6321: $itemcount ++;
6322: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6323: $datatable .= '<tr'.$css_class.'>'.
6324: '<td>'.$titlesref->{$row}.'</td>'.
6325: '<td class="LC_left_item">'.
6326: '<table><tr>';
6327: my (%current,%currentcap);
6328: if (ref($settings) eq 'HASH') {
6329: if (ref($settings->{$key}) eq 'HASH') {
6330: foreach my $type (@types) {
6331: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6332: $current{$type} = $settings->{$key}->{$type}->{$row};
6333: }
6334: if (($row eq 'limit') && ($key eq 'default')) {
6335: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6336: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6337: }
6338: }
6339: }
6340: }
6341: }
6342: my %roles = (
6343: '0' => &Apache::lonnet::plaintext('dc'),
6344: );
6345:
6346: foreach my $type (@types) {
6347: unless (($row eq 'registered') && ($key eq 'default')) {
6348: $datatable .= '<th>'.&mt($type).'</th>';
6349: }
6350: }
6351: unless (($row eq 'registered') && ($key eq 'default')) {
6352: $datatable .= '</tr><tr>';
6353: }
6354: foreach my $type (@types) {
6355: if ($type eq 'community') {
6356: $roles{'1'} = &mt('Community personnel');
6357: } else {
6358: $roles{'1'} = &mt('Course personnel');
6359: }
6360: $datatable .= '<td style="vertical-align: top">';
6361: if ($position eq 'top') {
6362: my %checked;
6363: if ($current{$type} eq '0') {
6364: $checked{'0'} = ' checked="checked"';
6365: } else {
6366: $checked{'1'} = ' checked="checked"';
6367: }
6368: foreach my $role ('1','0') {
6369: $datatable .= '<span class="LC_nobreak"><label>'.
6370: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6371: 'value="'.$role.'"'.$checked{$role}.' />'.
6372: $roles{$role}.'</label></span> ';
6373: }
6374: } else {
6375: if ($row eq 'types') {
6376: my %checked;
6377: if ($current{$type} =~ /^(all|dom)$/) {
6378: $checked{$1} = ' checked="checked"';
6379: } else {
6380: $checked{''} = ' checked="checked"';
6381: }
6382: foreach my $val ('','dom','all') {
6383: $datatable .= '<span class="LC_nobreak"><label>'.
6384: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6385: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6386: }
6387: } elsif ($row eq 'registered') {
6388: my %checked;
6389: if ($current{$type} eq '1') {
6390: $checked{'1'} = ' checked="checked"';
6391: } else {
6392: $checked{'0'} = ' checked="checked"';
6393: }
6394: foreach my $val ('0','1') {
6395: $datatable .= '<span class="LC_nobreak"><label>'.
6396: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6397: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6398: }
6399: } elsif ($row eq 'approval') {
6400: my %checked;
6401: if ($current{$type} =~ /^([12])$/) {
6402: $checked{$1} = ' checked="checked"';
6403: } else {
6404: $checked{'0'} = ' checked="checked"';
6405: }
6406: for my $val (0..2) {
6407: $datatable .= '<span class="LC_nobreak"><label>'.
6408: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6409: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6410: }
6411: } elsif ($row eq 'limit') {
6412: my %checked;
6413: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6414: $checked{$1} = ' checked="checked"';
6415: } else {
6416: $checked{'none'} = ' checked="checked"';
6417: }
6418: my $cap;
6419: if ($currentcap{$type} =~ /^\d+$/) {
6420: $cap = $currentcap{$type};
6421: }
6422: foreach my $val ('none','allstudents','selfenrolled') {
6423: $datatable .= '<span class="LC_nobreak"><label>'.
6424: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6425: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6426: }
6427: $datatable .= '<br />'.
6428: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6429: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6430: '</span>';
6431: }
6432: }
6433: $datatable .= '</td>';
6434: }
6435: $datatable .= '</tr>';
6436: }
6437: $datatable .= '</table></td></tr>';
6438: }
6439: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 6440: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6441: }
6442: $$rowtotal += $itemcount;
6443: return $datatable;
6444: }
6445:
6446: sub print_validation_rows {
6447: my ($caller,$dom,$settings,$rowtotal) = @_;
6448: my ($itemsref,$namesref,$fieldsref);
6449: if ($caller eq 'selfenroll') {
6450: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6451: } elsif ($caller eq 'requestcourses') {
6452: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6453: }
6454: my %currvalidation;
6455: if (ref($settings) eq 'HASH') {
6456: if (ref($settings->{'validation'}) eq 'HASH') {
6457: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 6458: }
1.160.6.39 raeburn 6459: }
6460: my $datatable;
6461: my $itemcount = 0;
6462: foreach my $item (@{$itemsref}) {
6463: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6464: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6465: $namesref->{$item}.
6466: '</span></td>'.
6467: '<td class="LC_left_item">';
6468: if (($item eq 'url') || ($item eq 'button')) {
6469: $datatable .= '<span class="LC_nobreak">'.
6470: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6471: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6472: } elsif ($item eq 'fields') {
6473: my @currfields;
6474: if (ref($currvalidation{$item}) eq 'ARRAY') {
6475: @currfields = @{$currvalidation{$item}};
6476: }
6477: foreach my $field (@{$fieldsref}) {
6478: my $check = '';
6479: if (grep(/^\Q$field\E$/,@currfields)) {
6480: $check = ' checked="checked"';
6481: }
6482: $datatable .= '<span class="LC_nobreak"><label>'.
6483: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6484: ' value="'.$field.'"'.$check.' />'.$field.
6485: '</label></span> ';
6486: }
6487: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 6488: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 6489: $currvalidation{$item}.
1.160.6.37 raeburn 6490: '</textarea>';
1.160.6.39 raeburn 6491: }
6492: $datatable .= '</td></tr>'."\n";
6493: if (ref($rowtotal)) {
1.160.6.37 raeburn 6494: $itemcount ++;
6495: }
1.139 raeburn 6496: }
1.160.6.39 raeburn 6497: if ($caller eq 'requestcourses') {
6498: my %currhash;
1.160.6.51 raeburn 6499: if (ref($settings) eq 'HASH') {
6500: if (ref($settings->{'validation'}) eq 'HASH') {
6501: if ($settings->{'validation'}{'dc'} ne '') {
6502: $currhash{$settings->{'validation'}{'dc'}} = 1;
6503: }
1.160.6.39 raeburn 6504: }
6505: }
6506: my $numinrow = 2;
6507: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6508: 'validationdc',%currhash);
1.160.6.50 raeburn 6509: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 6510: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 6511: if ($numdc > 1) {
1.160.6.50 raeburn 6512: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 6513: } else {
1.160.6.50 raeburn 6514: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 6515: }
1.160.6.50 raeburn 6516: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 6517: $itemcount ++;
6518: }
6519: if (ref($rowtotal)) {
6520: $$rowtotal += $itemcount;
6521: }
1.121 raeburn 6522: return $datatable;
1.118 jms 6523: }
6524:
1.160.6.98 raeburn 6525: sub print_passwords {
6526: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6527: my ($datatable,$css_class);
6528: my $itemcount = 0;
6529: my %titles = &Apache::lonlocal::texthash (
6530: captcha => '"Forgot Password" CAPTCHA validation',
6531: link => 'Reset link expiration (hours)',
6532: case => 'Case-sensitive usernames/e-mail',
6533: prelink => 'Information required (form 1)',
6534: postlink => 'Information required (form 2)',
6535: emailsrc => 'LON-CAPA e-mail address type(s)',
6536: customtext => 'Domain specific text (HTML)',
6537: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6538: intauth_check => 'Check bcrypt cost if authenticated',
6539: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6540: permanent => 'Permanent e-mail address',
6541: critical => 'Critical notification address',
6542: notify => 'Notification address',
6543: min => 'Minimum password length',
6544: max => 'Maximum password length',
6545: chars => 'Required characters',
6546: numsaved => 'Number of previous passwords to save and disallow reuse',
6547: );
6548: if ($position eq 'top') {
6549: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6550: my $shownlinklife = 2;
6551: my $prelink = 'both';
6552: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6553: if (ref($settings) eq 'HASH') {
6554: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6555: $shownlinklife = $settings->{resetlink};
6556: }
6557: if (ref($settings->{resetcase}) eq 'ARRAY') {
6558: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6559: }
6560: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6561: $prelink = $settings->{resetprelink};
6562: }
6563: if (ref($settings->{resetpostlink}) eq 'HASH') {
6564: %postlink = %{$settings->{resetpostlink}};
6565: }
6566: if (ref($settings->{resetemail}) eq 'ARRAY') {
6567: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6568: }
6569: if ($settings->{resetremove}) {
6570: $nostdtext = 1;
6571: }
6572: if ($settings->{resetcustom}) {
6573: $customurl = $settings->{resetcustom};
6574: }
6575: } else {
6576: if (ref($types) eq 'ARRAY') {
6577: foreach my $item (@{$types}) {
6578: $casesens{$item} = 1;
6579: $postlink{$item} = ['username','email'];
6580: }
6581: }
6582: $casesens{'default'} = 1;
6583: $postlink{'default'} = ['username','email'];
6584: $prelink = 'both';
6585: %emailsrc = (
6586: permanent => 1,
6587: critical => 1,
6588: notify => 1,
6589: );
6590: }
6591: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6592: $itemcount ++;
6593: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6594: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6595: '<td class="LC_left_item">'.
6596: '<input type="textbox" value="'.$shownlinklife.'" '.
6597: 'name="passwords_link" size="3" /></td></tr>';
6598: $itemcount ++;
6599: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6600: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6601: '<td class="LC_left_item">';
6602: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6603: foreach my $item (@{$types}) {
6604: my $checkedcase;
6605: if ($casesens{$item}) {
6606: $checkedcase = ' checked="checked"';
6607: }
6608: $datatable .= '<span class="LC_nobreak"><label>'.
6609: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6610: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 6611: '</span> ';
1.160.6.98 raeburn 6612: }
6613: }
6614: my $checkedcase;
6615: if ($casesens{'default'}) {
6616: $checkedcase = ' checked="checked"';
6617: }
6618: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6619: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6620: $othertitle.'</label></span></td>';
6621: $itemcount ++;
6622: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6623: my %checkedpre = (
6624: both => ' checked="checked"',
6625: either => '',
6626: );
6627: if ($prelink eq 'either') {
6628: $checkedpre{either} = ' checked="checked"';
6629: $checkedpre{both} = '';
6630: }
6631: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6632: '<td class="LC_left_item"><span class="LC_nobreak">'.
6633: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6634: &mt('Both username and e-mail address').'</label></span> '.
6635: '<span class="LC_nobreak"><label>'.
6636: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6637: &mt('Either username or e-mail address').'</label></span></td></tr>';
6638: $itemcount ++;
6639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6640: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6641: '<td class="LC_left_item">';
6642: my %postlinked;
6643: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6644: foreach my $item (@{$types}) {
6645: undef(%postlinked);
6646: $datatable .= '<fieldset style="display: inline-block;">'.
6647: '<legend>'.$usertypes->{$item}.'</legend>';
6648: if (ref($postlink{$item}) eq 'ARRAY') {
6649: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6650: }
6651: foreach my $field ('email','username') {
6652: my $checked;
6653: if ($postlinked{$field}) {
6654: $checked = ' checked="checked"';
6655: }
6656: $datatable .= '<span class="LC_nobreak"><label>'.
6657: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6658: $field.'"'.$checked.' />'.$field.'</label>'.
6659: '<span> ';
6660: }
6661: $datatable .= '</fieldset>';
6662: }
6663: }
6664: if (ref($postlink{'default'}) eq 'ARRAY') {
6665: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6666: }
6667: $datatable .= '<fieldset style="display: inline-block;">'.
6668: '<legend>'.$othertitle.'</legend>';
6669: foreach my $field ('email','username') {
6670: my $checked;
6671: if ($postlinked{$field}) {
6672: $checked = ' checked="checked"';
6673: }
6674: $datatable .= '<span class="LC_nobreak"><label>'.
6675: '<input type="checkbox" name="passwords_postlink_default" value="'.
6676: $field.'"'.$checked.' />'.$field.'</label>'.
6677: '<span> ';
6678: }
6679: $datatable .= '</fieldset></td></tr>';
6680: $itemcount ++;
6681: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6682: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6683: '<td class="LC_left_item">';
6684: foreach my $type ('permanent','critical','notify') {
6685: my $checkedemail;
6686: if ($emailsrc{$type}) {
6687: $checkedemail = ' checked="checked"';
6688: }
6689: $datatable .= '<span class="LC_nobreak"><label>'.
6690: '<input type="checkbox" name="passwords_emailsrc" value="'.
6691: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6692: '<span> ';
6693: }
6694: $datatable .= '</td></tr>';
6695: $itemcount ++;
6696: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6697: my $switchserver = &check_switchserver($dom,$confname);
6698: my ($showstd,$noshowstd);
6699: if ($nostdtext) {
6700: $noshowstd = ' checked="checked"';
6701: } else {
6702: $showstd = ' checked="checked"';
6703: }
6704: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6705: '<td class="LC_left_item"><span class="LC_nobreak">'.
6706: &mt('Retain standard text:').
6707: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6708: &mt('Yes').'</label>'.' '.
6709: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6710: &mt('No').'</label></span><br />'.
6711: '<span class="LC_fontsize_small">'.
6712: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6713: &mt('Include custom text:');
6714: if ($customurl) {
1.160.6.104 raeburn 6715: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 6716: undef,undef,undef,undef,'background-color:#ffffff');
6717: $datatable .= '<span class="LC_nobreak"> '.$link.
6718: '<label><input type="checkbox" name="passwords_custom_del"'.
6719: ' value="1" />'.&mt('Delete?').'</label></span>'.
6720: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6721: }
6722: if ($switchserver) {
6723: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6724: } else {
6725: $datatable .='<span class="LC_nobreak"> '.
6726: '<input type="file" name="passwords_customfile" /></span>';
6727: }
6728: $datatable .= '</td></tr>';
6729: } elsif ($position eq 'middle') {
6730: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6731: my @items = ('intauth_cost','intauth_check','intauth_switch');
6732: my %defaults;
6733: if (ref($domconf{'defaults'}) eq 'HASH') {
6734: %defaults = %{$domconf{'defaults'}};
6735: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6736: $defaults{'intauth_cost'} = 10;
6737: }
6738: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6739: $defaults{'intauth_check'} = 0;
6740: }
6741: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6742: $defaults{'intauth_switch'} = 0;
6743: }
6744: } else {
6745: %defaults = (
6746: 'intauth_cost' => 10,
6747: 'intauth_check' => 0,
6748: 'intauth_switch' => 0,
6749: );
6750: }
6751: foreach my $item (@items) {
6752: if ($itemcount%2) {
6753: $css_class = '';
6754: } else {
6755: $css_class = ' class="LC_odd_row" ';
6756: }
6757: $datatable .= '<tr'.$css_class.'>'.
6758: '<td><span class="LC_nobreak">'.$titles{$item}.
6759: '</span></td><td class="LC_left_item" colspan="3">';
6760: if ($item eq 'intauth_switch') {
6761: my @options = (0,1,2);
6762: my %optiondesc = &Apache::lonlocal::texthash (
6763: 0 => 'No',
6764: 1 => 'Yes',
6765: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6766: );
6767: $datatable .= '<table width="100%">';
6768: foreach my $option (@options) {
6769: my $checked = ' ';
6770: if ($defaults{$item} eq $option) {
6771: $checked = ' checked="checked"';
6772: }
6773: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6774: '<label><input type="radio" name="'.$item.
6775: '" value="'.$option.'"'.$checked.' />'.
6776: $optiondesc{$option}.'</label></span></td></tr>';
6777: }
6778: $datatable .= '</table>';
6779: } elsif ($item eq 'intauth_check') {
6780: my @options = (0,1,2);
6781: my %optiondesc = &Apache::lonlocal::texthash (
6782: 0 => 'No',
6783: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6784: 2 => 'Yes, disallow login if stored cost is less than domain default',
6785: );
6786: $datatable .= '<table width="100%">';
6787: foreach my $option (@options) {
6788: my $checked = ' ';
6789: my $onclick;
6790: if ($defaults{$item} eq $option) {
6791: $checked = ' checked="checked"';
6792: }
6793: if ($option == 2) {
6794: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6795: }
6796: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6797: '<label><input type="radio" name="'.$item.
6798: '" value="'.$option.'"'.$checked.$onclick.' />'.
6799: $optiondesc{$option}.'</label></span></td></tr>';
6800: }
6801: $datatable .= '</table>';
6802: } else {
6803: $datatable .= '<input type="text" name="'.$item.'" value="'.
6804: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6805: }
6806: $datatable .= '</td></tr>';
6807: $itemcount ++;
6808: }
6809: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 6810:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 6811: } else {
6812: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6813: my %ownerchg = (
6814: by => {},
6815: for => {},
6816: );
6817: my %ownertitles = &Apache::lonlocal::texthash (
6818: by => 'Course owner status(es) allowed',
6819: for => 'Student status(es) allowed',
6820: );
6821: if (ref($settings) eq 'HASH') {
6822: if (ref($settings->{crsownerchg}) eq 'HASH') {
6823: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6824: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6825: }
6826: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6827: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6828: }
6829: }
6830: }
6831: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6832: $datatable .= '<tr '.$css_class.'>'.
6833: '<td>'.
6834: &mt('Requirements').'<ul>'.
6835: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6836: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6837: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6838: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6839: '</ul>'.
6840: '</td>'.
6841: '<td class="LC_left_item">';
6842: foreach my $item ('by','for') {
6843: $datatable .= '<fieldset style="display: inline-block;">'.
6844: '<legend>'.$ownertitles{$item}.'</legend>';
6845: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6846: foreach my $type (@{$types}) {
6847: my $checked;
6848: if ($ownerchg{$item}{$type}) {
6849: $checked = ' checked="checked"';
6850: }
6851: $datatable .= '<span class="LC_nobreak"><label>'.
6852: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6853: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 6854: '</span> ';
1.160.6.98 raeburn 6855: }
6856: }
6857: my $checked;
6858: if ($ownerchg{$item}{'default'}) {
6859: $checked = ' checked="checked"';
6860: }
6861: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6862: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6863: $othertitle.'</label></span></fieldset>';
6864: }
6865: $datatable .= '</td></tr>';
6866: }
6867: return $datatable;
6868: }
6869:
1.160.6.118.2 5(raebur 6870:2): sub password_rules {
6871:2): my ($prefix,$itemcountref,$settings) = @_;
6872:2): my ($min,$max,%chars,$numsaved,$numinrow);
6873:2): my %titles;
6874:2): if ($prefix eq 'passwords') {
6875:2): %titles = &Apache::lonlocal::texthash (
6876:2): min => 'Minimum password length',
6877:2): max => 'Maximum password length',
6878:2): chars => 'Required characters',
6879:2): );
14(raebu 6880:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 6881:2): %titles = &Apache::lonlocal::texthash (
6882:2): min => 'Minimum secret length',
6883:2): max => 'Maximum secret length',
6884:2): chars => 'Required characters',
6885:2): );
6886:2): }
6887:2): $min = $Apache::lonnet::passwdmin;
6888:2): my $datatable;
6889:2): my $itemcount;
6890:2): if (ref($itemcountref)) {
6891:2): $itemcount = $$itemcountref;
6892:2): }
6893:2): if (ref($settings) eq 'HASH') {
6894:2): if ($settings->{min}) {
6895:2): $min = $settings->{min};
6896:2): }
6897:2): if ($settings->{max}) {
6898:2): $max = $settings->{max};
6899:2): }
6900:2): if (ref($settings->{chars}) eq 'ARRAY') {
6901:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
6902:2): }
6903:2): if ($prefix eq 'passwords') {
6904:2): if ($settings->{numsaved}) {
6905:2): $numsaved = $settings->{numsaved};
6906:2): }
6907:2): }
6908:2): }
6909:2): my %rulenames = &Apache::lonlocal::texthash(
6910:2): uc => 'At least one upper case letter',
6911:2): lc => 'At least one lower case letter',
6912:2): num => 'At least one number',
6913:2): spec => 'At least one non-alphanumeric',
6914:2): );
6915:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6916:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6917:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6918:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6919:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6920:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
6921:2): '</span></td></tr>';
6922:2): $itemcount ++;
6923:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6924:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
6925:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6926:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
6927:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6928:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
6929:2): '</span></td></tr>';
6930:2): $itemcount ++;
6931:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6932:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
6933:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
6934:2): '</span></td>';
6935:2): my $numinrow = 2;
6936:2): my @possrules = ('uc','lc','num','spec');
6937:2): $datatable .= '<td class="LC_left_item"><table>';
6938:2): for (my $i=0; $i<@possrules; $i++) {
6939:2): my ($rem,$checked);
6940:2): if ($chars{$possrules[$i]}) {
6941:2): $checked = ' checked="checked"';
6942:2): }
6943:2): $rem = $i%($numinrow);
6944:2): if ($rem == 0) {
6945:2): if ($i > 0) {
6946:2): $datatable .= '</tr>';
6947:2): }
6948:2): $datatable .= '<tr>';
6949:2): }
6950:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
6951:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
6952:2): $rulenames{$possrules[$i]}.'</label></span></td>';
6953:2): }
6954:2): my $rem = @possrules%($numinrow);
6955:2): my $colsleft = $numinrow - $rem;
6956:2): if ($colsleft > 1 ) {
6957:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
6958:2): ' </td>';
6959:2): } elsif ($colsleft == 1) {
6960:2): $datatable .= '<td class="LC_left_item"> </td>';
6961:2): }
6962:2): $datatable .='</table></td></tr>';
6963:2): $itemcount ++;
6964:2): if ($prefix eq 'passwords') {
6965:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
6966:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6967:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
6968:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6969:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
6970:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6971:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
6972:2): '</span></td></tr>';
6973:2): $itemcount ++;
6974:2): }
6975:2): if (ref($itemcountref)) {
6976:2): $$itemcountref += $itemcount;
6977:2): }
6978:2): return $datatable;
6979:2): }
6980:2):
1.160.6.113 raeburn 6981: sub print_wafproxy {
6982: my ($position,$dom,$settings,$rowtotal) = @_;
6983: my $css_class;
6984: my $itemcount = 0;
6985: my $datatable;
6986: my %servers = &Apache::lonnet::internet_dom_servers($dom);
6987: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
6988: my %lt = &wafproxy_titles();
6989: foreach my $server (sort(keys(%servers))) {
6990: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
6991: next if ($serverhome eq '');
6992: my $serverdom;
6993: if ($serverhome ne $server) {
6994: $serverdom = &Apache::lonnet::host_domain($serverhome);
6995: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
6996: $othercontrol{$server} = $serverdom;
6997: }
6998: } else {
6999: $serverdom = &Apache::lonnet::host_domain($server);
7000: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7001: if ($serverdom ne $dom) {
7002: $othercontrol{$server} = $serverdom;
7003: } else {
7004: $setdom = 1;
7005: if (ref($settings) eq 'HASH') {
7006: if (ref($settings->{'alias'}) eq 'HASH') {
7007: $aliases{$dom} = $settings->{'alias'};
7008: if ($aliases{$dom} ne '') {
7009: $showdom = 1;
7010: }
7011: }
7012: if (ref($settings->{'saml'}) eq 'HASH') {
7013: $saml{$dom} = $settings->{'saml'};
7014: }
7015: }
7016: }
7017: }
7018: }
7019: if ($setdom) {
7020: %{$values{$dom}} = ();
7021: if (ref($settings) eq 'HASH') {
7022: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7023: $values{$dom}{$item} = $settings->{$item};
7024: }
7025: }
7026: }
7027: if (keys(%othercontrol)) {
7028: %otherdoms = reverse(%othercontrol);
7029: foreach my $domain (keys(%otherdoms)) {
7030: %{$values{$domain}} = ();
7031: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7032: if (ref($config{'wafproxy'}) eq 'HASH') {
7033: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7034: if (exists($config{'wafproxy'}{'saml'})) {
7035: $saml{$domain} = $config{'wafproxy'}{'saml'};
7036: }
7037: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7038: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7039: }
7040: }
7041: }
7042: }
7043: if ($position eq 'top') {
7044: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7045: my %aliasinfo;
7046: foreach my $server (sort(keys(%servers))) {
7047: $itemcount ++;
7048: my $dom_in_effect;
7049: my $aliasrows = '<tr>'.
7050: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.118.2 17(raebu 7051:24): &mt('Hostname').': '.
16(raebu 7052:24): '<span class="LC_nobreak LC_cusr_emph">'.
7053:24): &Apache::lonnet::hostname($server).'</span></td><td> </td>';
1.160.6.113 raeburn 7054: if ($othercontrol{$server}) {
7055: $dom_in_effect = $othercontrol{$server};
7056: my ($current,$forsaml);
7057: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7058: $current = $aliases{$dom_in_effect}{$server};
7059: }
7060: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7061: if ($saml{$dom_in_effect}{$server}) {
7062: $forsaml = 1;
7063: }
7064: }
7065: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7066: &mt('Alias').': ';
7067: if ($current) {
7068: $aliasrows .= $current;
7069: if ($forsaml) {
7070: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7071: }
7072: } else {
7073: $aliasrows .= &mt('None');
7074: }
7075: $aliasrows .= ' <span class="LC_small">('.
7076: &mt('controlled by domain: [_1]',
7077: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7078: } else {
7079: $dom_in_effect = $dom;
7080: my ($current,$samlon,$samloff);
7081: $samloff = ' checked="checked"';
7082: if (ref($aliases{$dom}) eq 'HASH') {
7083: if ($aliases{$dom}{$server}) {
7084: $current = $aliases{$dom}{$server};
7085: }
7086: }
7087: if (ref($saml{$dom}) eq 'HASH') {
7088: if ($saml{$dom}{$server}) {
7089: $samlon = $samloff;
7090: undef($samloff);
7091: }
7092: }
7093: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7094: &mt('Alias').': '.
7095: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7096: 'value="'.$current.'" size="30" />'.
7097: (' 'x2).'<span class="LC_nobreak">'.
7098: &mt('Alias used for SSO Auth').': <label>'.
7099: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7100: &mt('No').'</label> <label>'.
7101: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7102: &mt('Yes').'</label></span>'.
7103: '</td>';
7104: }
7105: $aliasrows .= '</tr>';
7106: $aliasinfo{$dom_in_effect} .= $aliasrows;
7107: }
7108: if ($aliasinfo{$dom}) {
7109: my ($onclick,$wafon,$wafoff,$showtable);
7110: $onclick = ' onclick="javascript:toggleWAF();"';
7111: $wafoff = ' checked="checked"';
7112: $showtable = ' style="display:none";';
7113: if ($showdom) {
7114: $wafon = $wafoff;
7115: $wafoff = '';
7116: $showtable = ' style="display:inline;"';
7117: }
7118: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7119: $datatable = '<tr'.$css_class.'>'.
7120: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7121: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7122: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7123: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7124: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7125: &mt('No').'</label></span></td>'.
7126: '<td class="LC_left_item">'.
7127: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7128: '</table></td></tr>';
7129: $itemcount++;
7130: }
7131: if (keys(%otherdoms)) {
7132: foreach my $key (sort(keys(%otherdoms))) {
7133: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7134: $datatable .= '<tr'.$css_class.'>'.
7135: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7136: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7137: '</table></td></tr>';
7138: $itemcount++;
7139: }
7140: }
7141: } else {
7142: my %ip_methods = &remoteip_methods();
7143: if ($setdom) {
7144: $itemcount ++;
7145: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7146: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7147: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7148: $wafstyle = ' style="display:none;"';
7149: $nowafstyle = ' style="display:table-row;"';
7150: $currwafdisplay = ' style="display: none"';
7151: $wafrangestyle = ' style="display: none"';
7152: $curr_remotip = 'n';
7153: $ssltossl = ' checked="checked"';
7154: if ($showdom) {
7155: $wafstyle = ' style="display:table-row;"';
7156: $nowafstyle = ' style="display:none;"';
7157: if (keys(%{$values{$dom}})) {
7158: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7159: $curr_remotip = $values{$dom}{remoteip};
7160: }
7161: if ($curr_remotip eq 'h') {
7162: $currwafdisplay = ' style="display:table-row"';
7163: $wafrangestyle = ' style="display:inline-block;"';
7164: }
7165: if ($values{$dom}{'sslopt'}) {
7166: $alltossl = ' checked="checked"';
7167: $ssltossl = '';
7168: }
7169: }
7170: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7171: $vpndircheck = ' checked="checked"';
7172: $currwafvpn = ' style="display:table-row;"';
7173: $wafrangestyle = ' style="display:inline-block;"';
7174: } else {
7175: $vpnaliascheck = ' checked="checked"';
7176: $currwafvpn = ' style="display:none;"';
7177: }
7178: }
7179: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7180: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7181: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7182: '</tr>'.
7183: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7184: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7185: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7186: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7187: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7188: '<td class="LC_left_item"><table>'.
7189: '<tr>'.
7190: '<td valign="top">'.$lt{'remoteip'}.': '.
7191: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7192: foreach my $option ('m','h','n') {
7193: my $sel;
1.160.6.114 raeburn 7194: if ($option eq $curr_remotip) {
7195: $sel = ' selected="selected"';
7196: }
7197: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7198: $ip_methods{$option}.'</option>';
7199: }
7200: $datatable .= '</select></td></tr>'."\n".
7201: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7202: $lt{'ipheader'}.': '.
7203: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7204: 'name="wafproxy_ipheader" />'.
7205: '</td></tr>'."\n".
7206: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7207: $lt{'trusted'}.':<br />'.
7208: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7209: $values{$dom}{'trusted'}.'</textarea>'.
7210: '</td></tr>'."\n".
7211: '<tr><td><hr /></td></tr>'."\n".
7212: '<tr>'.
1.160.6.113 raeburn 7213: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7214: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7215: $lt{'vpndirect'}.'</label>'.(' 'x2).
7216: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7217: $lt{'vpnaliased'}.'</label></span></td></tr>';
7218: foreach my $item ('vpnint','vpnext') {
7219: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7220: '<td valign="top">'.$lt{$item}.':<br />'.
7221: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7222: $values{$dom}{$item}.'</textarea>'.
7223: '</td></tr>'."\n";
7224: }
7225: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7226: '<tr>'.
7227: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7228: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7229: $lt{'alltossl'}.'</label>'.(' 'x2).
7230: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7231: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7232: '</table></td></tr>';
7233: }
7234: if (keys(%otherdoms)) {
7235: foreach my $domain (sort(keys(%otherdoms))) {
7236: $itemcount ++;
7237: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7238: $datatable .= '<tr'.$css_class.'>'.
7239: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7240: '<td class="LC_left_item"><table>';
7241: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7242: my $showval = &mt('None');
7243: if ($item eq 'ssl') {
7244: $showval = $lt{'ssltossl'};
7245: }
7246: if ($values{$domain}{$item}) {
7247: $showval = $values{$domain}{$item};
7248: if ($item eq 'ssl') {
7249: $showval = $lt{'alltossl'};
7250: } elsif ($item eq 'remoteip') {
7251: $showval = $ip_methods{$values{$domain}{$item}};
7252: }
7253: }
7254: $datatable .= '<tr>'.
7255: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7256: }
7257: $datatable .= '</table></td></tr>';
7258: }
7259: }
7260: }
7261: $$rowtotal += $itemcount;
7262: return $datatable;
7263: }
7264:
7265: sub wafproxy_titles {
7266: return &Apache::lonlocal::texthash(
7267: remoteip => "Method for determining user's IP",
7268: ipheader => 'Request header containing remote IP',
7269: trusted => 'Trusted IP range(s)',
7270: vpnaccess => 'Access from institutional VPN',
7271: vpndirect => 'via regular hostname (no WAF)',
7272: vpnaliased => 'via aliased hostname (WAF)',
7273: vpnint => 'Internal IP Range(s) for VPN sessions',
7274: vpnext => 'IP Range(s) for backend WAF connections',
7275: sslopt => 'Forwarding http/https',
7276: alltossl => 'WAF forwards both http and https requests to https',
7277: ssltossl => 'WAF forwards http requests to http and https to https',
7278: );
7279: }
7280:
7281: sub remoteip_methods {
7282: return &Apache::lonlocal::texthash(
7283: m => 'Use Apache mod_remoteip',
7284: h => 'Use headers parsed by LON-CAPA',
7285: n => 'Not in use',
7286: );
7287: }
7288:
1.137 raeburn 7289: sub print_usersessions {
7290: my ($position,$dom,$settings,$rowtotal) = @_;
7291: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 7292: my (%by_ip,%by_location,@intdoms);
7293: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 7294:
7295: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7296: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7297: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7298: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7299: my $itemcount = 1;
7300: if ($position eq 'top') {
1.152 raeburn 7301: if (keys(%serverhomes) > 1) {
1.145 raeburn 7302: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 7303: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 7304: if (ref($settings) eq 'HASH') {
7305: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7306: $curroffloadnow = $settings->{'offloadnow'};
7307: }
1.160.6.105 raeburn 7308: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7309: $curroffloadoth = $settings->{'offloadoth'};
7310: }
1.160.6.61 raeburn 7311: }
1.160.6.105 raeburn 7312: my $other_insts = scalar(keys(%by_location));
7313: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7314: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7315: } else {
1.140 raeburn 7316: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7317:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7318:23): '</td></tr>';
1.140 raeburn 7319: }
1.137 raeburn 7320: } else {
1.145 raeburn 7321: if (keys(%by_location) == 0) {
7322: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7323:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7324:23): '</td></tr>';
1.145 raeburn 7325: } else {
7326: my %lt = &usersession_titles();
7327: my $numinrow = 5;
7328: my $prefix;
7329: my @types;
7330: if ($position eq 'bottom') {
7331: $prefix = 'remote';
7332: @types = ('version','excludedomain','includedomain');
7333: } else {
7334: $prefix = 'hosted';
7335: @types = ('excludedomain','includedomain');
7336: }
7337: my (%current,%checkedon,%checkedoff);
7338: my @lcversions = &Apache::lonnet::all_loncaparevs();
7339: my @locations = sort(keys(%by_location));
7340: foreach my $type (@types) {
7341: $checkedon{$type} = '';
7342: $checkedoff{$type} = ' checked="checked"';
7343: }
7344: if (ref($settings) eq 'HASH') {
7345: if (ref($settings->{$prefix}) eq 'HASH') {
7346: foreach my $key (keys(%{$settings->{$prefix}})) {
7347: $current{$key} = $settings->{$prefix}{$key};
7348: if ($key eq 'version') {
7349: if ($current{$key} ne '') {
7350: $checkedon{$key} = ' checked="checked"';
7351: $checkedoff{$key} = '';
7352: }
7353: } elsif (ref($current{$key}) eq 'ARRAY') {
7354: $checkedon{$key} = ' checked="checked"';
7355: $checkedoff{$key} = '';
7356: }
1.137 raeburn 7357: }
7358: }
7359: }
1.145 raeburn 7360: foreach my $type (@types) {
7361: next if ($type ne 'version' && !@locations);
7362: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7363: $datatable .= '<tr'.$css_class.'>
7364: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7365: <span class="LC_nobreak">
7366: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7367: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7368: if ($type eq 'version') {
7369: my $selector = '<select name="'.$prefix.'_version">';
7370: foreach my $version (@lcversions) {
7371: my $selected = '';
7372: if ($current{'version'} eq $version) {
7373: $selected = ' selected="selected"';
7374: }
7375: $selector .= ' <option value="'.$version.'"'.
7376: $selected.'>'.$version.'</option>';
7377: }
7378: $selector .= '</select> ';
7379: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7380: } else {
7381: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7382: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7383: ' />'.(' 'x2).
7384: '<input type="button" value="'.&mt('uncheck all').'" '.
7385: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7386: "\n".
7387: '</div><div><table>';
7388: my $rem;
7389: for (my $i=0; $i<@locations; $i++) {
7390: my ($showloc,$value,$checkedtype);
7391: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7392: my $ip = $by_location{$locations[$i]}->[0];
7393: if (ref($by_ip{$ip}) eq 'ARRAY') {
7394: $value = join(':',@{$by_ip{$ip}});
7395: $showloc = join(', ',@{$by_ip{$ip}});
7396: if (ref($current{$type}) eq 'ARRAY') {
7397: foreach my $loc (@{$by_ip{$ip}}) {
7398: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7399: $checkedtype = ' checked="checked"';
7400: last;
7401: }
7402: }
1.138 raeburn 7403: }
7404: }
7405: }
1.145 raeburn 7406: $rem = $i%($numinrow);
7407: if ($rem == 0) {
7408: if ($i > 0) {
7409: $datatable .= '</tr>';
7410: }
7411: $datatable .= '<tr>';
7412: }
7413: $datatable .= '<td class="LC_left_item">'.
7414: '<span class="LC_nobreak"><label>'.
7415: '<input type="checkbox" name="'.$prefix.'_'.$type.
7416: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7417: '</label></span></td>';
1.137 raeburn 7418: }
1.145 raeburn 7419: $rem = @locations%($numinrow);
7420: my $colsleft = $numinrow - $rem;
7421: if ($colsleft > 1 ) {
7422: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7423: ' </td>';
7424: } elsif ($colsleft == 1) {
7425: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7426: }
1.145 raeburn 7427: $datatable .= '</tr></table>';
1.137 raeburn 7428: }
1.145 raeburn 7429: $datatable .= '</td></tr>';
7430: $itemcount ++;
1.137 raeburn 7431: }
7432: }
7433: }
7434: $$rowtotal += $itemcount;
7435: return $datatable;
7436: }
7437:
1.138 raeburn 7438: sub build_location_hashes {
7439: my ($intdoms,$by_ip,$by_location) = @_;
7440: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7441: (ref($by_location) eq 'HASH'));
7442: my %iphost = &Apache::lonnet::get_iphost();
7443: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7444: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7445: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7446: foreach my $id (@{$iphost{$primary_ip}}) {
7447: my $intdom = &Apache::lonnet::internet_dom($id);
7448: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7449: push(@{$intdoms},$intdom);
7450: }
7451: }
7452: }
7453: foreach my $ip (keys(%iphost)) {
7454: if (ref($iphost{$ip}) eq 'ARRAY') {
7455: foreach my $id (@{$iphost{$ip}}) {
7456: my $location = &Apache::lonnet::internet_dom($id);
7457: if ($location) {
7458: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7459: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7460: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7461: push(@{$by_ip->{$ip}},$location);
7462: }
7463: } else {
7464: $by_ip->{$ip} = [$location];
7465: }
7466: }
7467: }
7468: }
7469: }
7470: foreach my $ip (sort(keys(%{$by_ip}))) {
7471: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7472: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7473: my $first = $by_ip->{$ip}->[0];
7474: if (ref($by_location->{$first}) eq 'ARRAY') {
7475: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7476: push(@{$by_location->{$first}},$ip);
7477: }
7478: } else {
7479: $by_location->{$first} = [$ip];
7480: }
7481: }
7482: }
7483: return;
7484: }
7485:
1.145 raeburn 7486: sub current_offloads_to {
7487: my ($dom,$settings,$servers) = @_;
7488: my (%spareid,%otherdomconfigs);
1.152 raeburn 7489: if (ref($servers) eq 'HASH') {
1.145 raeburn 7490: foreach my $lonhost (sort(keys(%{$servers}))) {
7491: my $gotspares;
1.152 raeburn 7492: if (ref($settings) eq 'HASH') {
7493: if (ref($settings->{'spares'}) eq 'HASH') {
7494: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7495: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7496: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7497: $gotspares = 1;
7498: }
1.145 raeburn 7499: }
7500: }
7501: unless ($gotspares) {
7502: my $gotspares;
7503: my $serverhomeID =
7504: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7505: my $serverhomedom =
7506: &Apache::lonnet::host_domain($serverhomeID);
7507: if ($serverhomedom ne $dom) {
7508: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7509: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7510: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7511: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7512: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7513: $gotspares = 1;
7514: }
7515: }
7516: } else {
7517: $otherdomconfigs{$serverhomedom} =
7518: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7519: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7520: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7521: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7522: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7523: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7524: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7525: $gotspares = 1;
7526: }
7527: }
7528: }
7529: }
7530: }
7531: }
7532: }
7533: unless ($gotspares) {
7534: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7535: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7536: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7537: } else {
7538: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7539: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7540: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7541: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7542: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7543: } else {
1.150 raeburn 7544: my %what = (
7545: spareid => 1,
7546: );
7547: my ($result,$returnhash) =
7548: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7549: if ($result eq 'ok') {
7550: if (ref($returnhash) eq 'HASH') {
7551: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7552: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7553: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7554: }
7555: }
1.145 raeburn 7556: }
7557: }
7558: }
7559: }
7560: }
7561: }
7562: return %spareid;
7563: }
7564:
7565: sub spares_row {
1.160.6.105 raeburn 7566: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7567: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7568: my $css_class;
7569: my $numinrow = 4;
7570: my $itemcount = 1;
7571: my $datatable;
1.152 raeburn 7572: my %typetitles = &sparestype_titles();
7573: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7574: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7575: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7576: my ($othercontrol,$serverdom);
7577: if ($serverhome ne $server) {
7578: $serverdom = &Apache::lonnet::host_domain($serverhome);
7579: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7580: } else {
7581: $serverdom = &Apache::lonnet::host_domain($server);
7582: if ($serverdom ne $dom) {
7583: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7584: }
7585: }
7586: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 7587: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 7588: if (ref($curroffloadnow) eq 'HASH') {
7589: if ($curroffloadnow->{$server}) {
7590: $checkednow = ' checked="checked"';
7591: }
7592: }
1.160.6.105 raeburn 7593: if (ref($curroffloadoth) eq 'HASH') {
7594: if ($curroffloadoth->{$server}) {
7595: $checkedoth = ' checked="checked"';
7596: }
7597: }
1.145 raeburn 7598: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7599: $datatable .= '<tr'.$css_class.'>
7600: <td rowspan="2">
1.160.6.13 raeburn 7601: <span class="LC_nobreak">'.
7602: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 7603: ,'<b>'.$server.'</b>').'</span><br />'.
7604: '<span class="LC_nobreak">'."\n".
7605: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 7606: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 7607: "\n";
1.160.6.105 raeburn 7608: if ($other_insts) {
7609: $datatable .= '<br />'.
7610: '<span class="LC_nobreak">'."\n".
7611: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7612: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7613: "\n";
7614: }
1.145 raeburn 7615: my (%current,%canselect);
1.152 raeburn 7616: my @choices =
7617: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7618: foreach my $type ('primary','default') {
7619: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7620: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7621: my @spares = @{$spareid->{$server}{$type}};
7622: if (@spares > 0) {
1.152 raeburn 7623: if ($othercontrol) {
7624: $current{$type} = join(', ',@spares);
7625: } else {
7626: $current{$type} .= '<table>';
7627: my $numspares = scalar(@spares);
7628: for (my $i=0; $i<@spares; $i++) {
7629: my $rem = $i%($numinrow);
7630: if ($rem == 0) {
7631: if ($i > 0) {
7632: $current{$type} .= '</tr>';
7633: }
7634: $current{$type} .= '<tr>';
1.145 raeburn 7635: }
1.152 raeburn 7636: $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'".');" /> '.
7637: $spareid->{$server}{$type}[$i].
7638: '</label></td>'."\n";
7639: }
7640: my $rem = @spares%($numinrow);
7641: my $colsleft = $numinrow - $rem;
7642: if ($colsleft > 1 ) {
7643: $current{$type} .= '<td colspan="'.$colsleft.
7644: '" class="LC_left_item">'.
7645: ' </td>';
7646: } elsif ($colsleft == 1) {
7647: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7648: }
1.152 raeburn 7649: $current{$type} .= '</tr></table>';
1.150 raeburn 7650: }
1.145 raeburn 7651: }
7652: }
7653: if ($current{$type} eq '') {
7654: $current{$type} = &mt('None specified');
7655: }
1.152 raeburn 7656: if ($othercontrol) {
7657: if ($type eq 'primary') {
7658: $canselect{$type} = $othercontrol;
7659: }
7660: } else {
7661: $canselect{$type} =
7662: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7663: '<select name="newspare_'.$type.'_'.$server.'" '.
7664: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7665: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7666: if (@choices > 0) {
7667: foreach my $lonhost (@choices) {
7668: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7669: }
7670: }
7671: $canselect{$type} .= '</select>'."\n";
7672: }
7673: } else {
7674: $current{$type} = &mt('Could not be determined');
7675: if ($type eq 'primary') {
7676: $canselect{$type} = $othercontrol;
7677: }
1.145 raeburn 7678: }
1.152 raeburn 7679: if ($type eq 'default') {
7680: $datatable .= '<tr'.$css_class.'>';
7681: }
7682: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7683: '<td>'.$current{$type}.'</td>'."\n".
7684: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7685: }
7686: $itemcount ++;
7687: }
7688: }
7689: $$rowtotal += $itemcount;
7690: return $datatable;
7691: }
7692:
1.152 raeburn 7693: sub possible_newspares {
7694: my ($server,$currspares,$serverhomes,$altids) = @_;
7695: my $serverhostname = &Apache::lonnet::hostname($server);
7696: my %excluded;
7697: if ($serverhostname ne '') {
7698: %excluded = (
7699: $serverhostname => 1,
7700: );
7701: }
7702: if (ref($currspares) eq 'HASH') {
7703: foreach my $type (keys(%{$currspares})) {
7704: if (ref($currspares->{$type}) eq 'ARRAY') {
7705: if (@{$currspares->{$type}} > 0) {
7706: foreach my $curr (@{$currspares->{$type}}) {
7707: my $hostname = &Apache::lonnet::hostname($curr);
7708: $excluded{$hostname} = 1;
7709: }
7710: }
7711: }
7712: }
7713: }
7714: my @choices;
7715: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7716: if (keys(%{$serverhomes}) > 1) {
7717: foreach my $name (sort(keys(%{$serverhomes}))) {
7718: unless ($excluded{$name}) {
7719: if (exists($altids->{$serverhomes->{$name}})) {
7720: push(@choices,$altids->{$serverhomes->{$name}});
7721: } else {
7722: push(@choices,$serverhomes->{$name});
1.145 raeburn 7723: }
7724: }
7725: }
7726: }
7727: }
1.152 raeburn 7728: return sort(@choices);
1.145 raeburn 7729: }
7730:
1.150 raeburn 7731: sub print_loadbalancing {
7732: my ($dom,$settings,$rowtotal) = @_;
7733: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7734: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7735: my $numinrow = 1;
7736: my $datatable;
7737: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 7738: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 7739: if (ref($settings) eq 'HASH') {
7740: %existing = %{$settings};
7741: }
7742: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7743: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 7744: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7745: } else {
7746: return;
7747: }
7748: my ($othertitle,$usertypes,$types) =
7749: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 7750: my $rownum = 8;
1.150 raeburn 7751: if (ref($types) eq 'ARRAY') {
7752: $rownum += scalar(@{$types});
7753: }
1.160.6.7 raeburn 7754: my @css_class = ('LC_odd_row','LC_even_row');
7755: my $balnum = 0;
7756: my $islast;
7757: my (@toshow,$disabledtext);
7758: if (keys(%currbalancer) > 0) {
7759: @toshow = sort(keys(%currbalancer));
7760: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7761: push(@toshow,'');
7762: }
7763: } else {
7764: @toshow = ('');
7765: $disabledtext = &mt('No existing load balancer');
7766: }
7767: foreach my $lonhost (@toshow) {
7768: if ($balnum == scalar(@toshow)-1) {
7769: $islast = 1;
7770: } else {
7771: $islast = 0;
7772: }
7773: my $cssidx = $balnum%2;
7774: my $targets_div_style = 'display: none';
7775: my $disabled_div_style = 'display: block';
7776: my $homedom_div_style = 'display: none';
7777: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7778: '<td rowspan="'.$rownum.'" valign="top">'.
7779: '<p>';
7780: if ($lonhost eq '') {
7781: $datatable .= '<span class="LC_nobreak">';
7782: if (keys(%currbalancer) > 0) {
7783: $datatable .= &mt('Add balancer:');
7784: } else {
7785: $datatable .= &mt('Enable balancer:');
7786: }
7787: $datatable .= ' '.
7788: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7789: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7790: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7791: '<option value="" selected="selected">'.&mt('None').
7792: '</option>'."\n";
7793: foreach my $server (sort(keys(%servers))) {
7794: next if ($currbalancer{$server});
7795: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7796: }
7797: $datatable .=
7798: '</select>'."\n".
7799: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7800: } else {
7801: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7802: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7803: &mt('Stop balancing').'</label>'.
7804: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7805: $targets_div_style = 'display: block';
7806: $disabled_div_style = 'display: none';
7807: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7808: $homedom_div_style = 'display: block';
7809: }
7810: }
7811: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7812: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7813: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7814: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7815: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7816: my @sparestypes = ('primary','default');
7817: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 7818: my %hostherechecked = (
7819: no => ' checked="checked"',
7820: );
1.160.6.94 raeburn 7821: my %balcookiechecked = (
7822: no => ' checked="checked"',
7823: );
1.160.6.7 raeburn 7824: foreach my $sparetype (@sparestypes) {
7825: my $targettable;
7826: for (my $i=0; $i<$numspares; $i++) {
7827: my $checked;
7828: if (ref($currtargets{$lonhost}) eq 'HASH') {
7829: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7830: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7831: $checked = ' checked="checked"';
7832: }
7833: }
7834: }
7835: my ($chkboxval,$disabled);
7836: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7837: $chkboxval = $spares[$i];
7838: }
7839: if (exists($currbalancer{$spares[$i]})) {
7840: $disabled = ' disabled="disabled"';
7841: }
7842: $targettable .=
1.160.6.55 raeburn 7843: '<td><span class="LC_nobreak"><label>'.
7844: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 7845: $checked.$disabled.' value="'.$chkboxval.'" id="loadbalancing_target_'.$balnum.'_'.$sparetype.'_'.$i.'" onclick="checkOffloads('."this,'$balnum','$sparetype'".');" /><span id="loadbalancing_targettxt_'.$balnum.'_'.$sparetype.'_'.$i.'"> '.$chkboxval.
1.160.6.55 raeburn 7846: '</span></label></span></td>';
1.160.6.7 raeburn 7847: my $rem = $i%($numinrow);
7848: if ($rem == 0) {
7849: if (($i > 0) && ($i < $numspares-1)) {
7850: $targettable .= '</tr>';
7851: }
7852: if ($i < $numspares-1) {
7853: $targettable .= '<tr>';
1.150 raeburn 7854: }
7855: }
7856: }
1.160.6.7 raeburn 7857: if ($targettable ne '') {
7858: my $rem = $numspares%($numinrow);
7859: my $colsleft = $numinrow - $rem;
7860: if ($colsleft > 1 ) {
7861: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7862: ' </td>';
7863: } elsif ($colsleft == 1) {
7864: $targettable .= '<td class="LC_left_item"> </td>';
7865: }
7866: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7867: '<table><tr>'.$targettable.'</tr></table><br />';
7868: }
1.160.6.76 raeburn 7869: $hostherechecked{$sparetype} = '';
7870: if (ref($currtargets{$lonhost}) eq 'HASH') {
7871: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7872: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7873: $hostherechecked{$sparetype} = ' checked="checked"';
7874: $hostherechecked{'no'} = '';
7875: }
7876: }
7877: }
7878: }
1.160.6.94 raeburn 7879: if ($currcookies{$lonhost}) {
7880: %balcookiechecked = (
7881: yes => ' checked="checked"',
7882: );
7883: }
1.160.6.76 raeburn 7884: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7885: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7886: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7887: foreach my $sparetype (@sparestypes) {
7888: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7889: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7890: '</i></label><br />';
1.160.6.7 raeburn 7891: }
1.160.6.94 raeburn 7892: $datatable .= &mt('Use balancer cookie').'<br />'.
7893: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7894: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7895: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7896: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7897: '</div></td></tr>'.
1.160.6.7 raeburn 7898: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7899: $othertitle,$usertypes,$types,\%servers,
7900: \%currbalancer,$lonhost,
7901: $targets_div_style,$homedom_div_style,
7902: $css_class[$cssidx],$balnum,$islast);
7903: $$rowtotal += $rownum;
7904: $balnum ++;
7905: }
7906: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7907: return $datatable;
7908: }
7909:
7910: sub get_loadbalancers_config {
1.160.6.94 raeburn 7911: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 7912: return unless ((ref($servers) eq 'HASH') &&
7913: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 7914: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7915: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 7916: if (keys(%{$existing}) > 0) {
7917: my $oldlonhost;
7918: foreach my $key (sort(keys(%{$existing}))) {
7919: if ($key eq 'lonhost') {
7920: $oldlonhost = $existing->{'lonhost'};
7921: $currbalancer->{$oldlonhost} = 1;
7922: } elsif ($key eq 'targets') {
7923: if ($oldlonhost) {
7924: $currtargets->{$oldlonhost} = $existing->{'targets'};
7925: }
7926: } elsif ($key eq 'rules') {
7927: if ($oldlonhost) {
7928: $currrules->{$oldlonhost} = $existing->{'rules'};
7929: }
7930: } elsif (ref($existing->{$key}) eq 'HASH') {
7931: $currbalancer->{$key} = 1;
7932: $currtargets->{$key} = $existing->{$key}{'targets'};
7933: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 7934: if ($existing->{$key}{'cookie'}) {
7935: $currcookies->{$key} = 1;
7936: }
1.150 raeburn 7937: }
7938: }
1.160.6.7 raeburn 7939: } else {
7940: my ($balancerref,$targetsref) =
7941: &Apache::lonnet::get_lonbalancer_config($servers);
7942: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
7943: foreach my $server (sort(keys(%{$balancerref}))) {
7944: $currbalancer->{$server} = 1;
7945: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 7946: }
7947: }
7948: }
1.160.6.7 raeburn 7949: return;
1.150 raeburn 7950: }
7951:
7952: sub loadbalancing_rules {
7953: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 7954: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
7955: $css_class,$balnum,$islast) = @_;
1.150 raeburn 7956: my $output;
1.160.6.7 raeburn 7957: my $num = 0;
7958: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 7959: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
7960: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
7961: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 7962: $num ++;
1.150 raeburn 7963: my $current;
7964: if (ref($currrules) eq 'HASH') {
7965: $current = $currrules->{$type};
7966: }
1.160.6.55 raeburn 7967: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 7968: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 7969: $current = '';
7970: }
7971: }
7972: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 7973: $servers,$currbalancer,$lonhost,$dom,
7974: $targets_div_style,$homedom_div_style,
7975: $css_class,$balnum,$num,$islast);
1.150 raeburn 7976: }
7977: }
7978: return $output;
7979: }
7980:
7981: sub loadbalancing_titles {
7982: my ($dom,$intdom,$usertypes,$types) = @_;
7983: my %othertypes = (
7984: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
7985: '_LC_author' => &mt('Users from [_1] with author role',$dom),
7986: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
7987: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 7988: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
7989: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 7990: );
1.160.6.26 raeburn 7991: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 7992: my @available;
1.150 raeburn 7993: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 7994: @available = @{$types};
1.150 raeburn 7995: }
1.160.6.89 raeburn 7996: unless (grep(/^default$/,@available)) {
7997: push(@available,'default');
7998: }
7999: unshift(@alltypes,@available);
1.150 raeburn 8000: my %titles;
8001: foreach my $type (@alltypes) {
8002: if ($type =~ /^_LC_/) {
8003: $titles{$type} = $othertypes{$type};
8004: } elsif ($type eq 'default') {
8005: $titles{$type} = &mt('All users from [_1]',$dom);
8006: if (ref($types) eq 'ARRAY') {
8007: if (@{$types} > 0) {
8008: $titles{$type} = &mt('Other users from [_1]',$dom);
8009: }
8010: }
8011: } elsif (ref($usertypes) eq 'HASH') {
8012: $titles{$type} = $usertypes->{$type};
8013: }
8014: }
8015: return (\@alltypes,\%othertypes,\%titles);
8016: }
8017:
8018: sub loadbalance_rule_row {
1.160.6.7 raeburn 8019: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8020: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 8021: my @rulenames;
1.150 raeburn 8022: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 8023: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 8024: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8025: } else {
1.160.6.26 raeburn 8026: @rulenames = ('default','homeserver');
8027: if ($type eq '_LC_external') {
8028: push(@rulenames,'externalbalancer');
8029: } else {
8030: push(@rulenames,'specific');
8031: }
8032: push(@rulenames,'none');
1.150 raeburn 8033: }
8034: my $style = $targets_div_style;
1.160.6.55 raeburn 8035: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8036: $style = $homedom_div_style;
8037: }
1.160.6.7 raeburn 8038: my $space;
8039: if ($islast && $num == 1) {
1.160.6.118.2 14(raebu 8040:23): $space = '<div style="display:inline-block;"> </div>';
1.160.6.7 raeburn 8041: }
8042: my $output =
8043: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8044: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8045: '<td valaign="top">'.$space.
8046: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8047: for (my $i=0; $i<@rulenames; $i++) {
8048: my $rule = $rulenames[$i];
8049: my ($checked,$extra);
8050: if ($rulenames[$i] eq 'default') {
8051: $rule = '';
8052: }
8053: if ($rulenames[$i] eq 'specific') {
8054: if (ref($servers) eq 'HASH') {
8055: my $default;
8056: if (($current ne '') && (exists($servers->{$current}))) {
8057: $checked = ' checked="checked"';
8058: }
8059: unless ($checked) {
8060: $default = ' selected="selected"';
8061: }
1.160.6.7 raeburn 8062: $extra =
8063: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8064: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8065: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8066: '<option value=""'.$default.'></option>'."\n";
8067: foreach my $server (sort(keys(%{$servers}))) {
8068: if (ref($currbalancer) eq 'HASH') {
8069: next if (exists($currbalancer->{$server}));
8070: }
1.150 raeburn 8071: my $selected;
1.160.6.7 raeburn 8072: if ($server eq $current) {
1.150 raeburn 8073: $selected = ' selected="selected"';
8074: }
1.160.6.7 raeburn 8075: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8076: }
8077: $extra .= '</select>';
8078: }
8079: } elsif ($rule eq $current) {
8080: $checked = ' checked="checked"';
8081: }
8082: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 8083: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8084: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8085: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 8086: ')"'.$checked.' /> ';
1.160.6.56 raeburn 8087: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 8088: $output .= $ruletitles{'particular'};
8089: } else {
8090: $output .= $ruletitles{$rulenames[$i]};
8091: }
8092: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8093: }
8094: $output .= '</div></td></tr>'."\n";
8095: return $output;
8096: }
8097:
8098: sub offloadtype_text {
8099: my %ruletitles = &Apache::lonlocal::texthash (
8100: 'default' => 'Offloads to default destinations',
8101: 'homeserver' => "Offloads to user's home server",
8102: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8103: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 8104: 'none' => 'No offload',
1.160.6.26 raeburn 8105: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8106: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 8107: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8108: );
8109: return %ruletitles;
8110: }
8111:
8112: sub sparestype_titles {
8113: my %typestitles = &Apache::lonlocal::texthash (
8114: 'primary' => 'primary',
8115: 'default' => 'default',
8116: );
8117: return %typestitles;
8118: }
8119:
1.28 raeburn 8120: sub contact_titles {
8121: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 8122: 'supportemail' => 'Support E-mail address',
8123: 'adminemail' => 'Default Server Admin E-mail address',
8124: 'errormail' => 'Error reports to be e-mailed to',
8125: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 8126: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8127: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 8128: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8129: 'requestsmail' => 'E-mail from course requests requiring approval',
8130: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 8131: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 8132: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 8133: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8134: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 8135: 'errorweights' => 'Weights used to compute error count',
8136: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8137: );
8138: my %short_titles = &Apache::lonlocal::texthash (
8139: adminemail => 'Admin E-mail address',
8140: supportemail => 'Support E-mail',
8141: );
8142: return (\%titles,\%short_titles);
8143: }
8144:
1.160.6.78 raeburn 8145: sub helpform_fields {
8146: my %titles = &Apache::lonlocal::texthash (
8147: 'username' => 'Name',
8148: 'user' => 'Username/domain',
8149: 'phone' => 'Phone',
8150: 'cc' => 'Cc e-mail',
8151: 'course' => 'Course Details',
8152: 'section' => 'Sections',
8153: 'screenshot' => 'File upload',
8154: );
8155: my @fields = ('username','phone','user','course','section','cc','screenshot');
8156: my %possoptions = (
8157: username => ['yes','no','req'],
8158: phone => ['yes','no','req'],
8159: user => ['yes','no'],
8160: cc => ['yes','no'],
8161: course => ['yes','no'],
8162: section => ['yes','no'],
8163: screenshot => ['yes','no'],
8164: );
8165: my %fieldoptions = &Apache::lonlocal::texthash (
8166: 'yes' => 'Optional',
8167: 'req' => 'Required',
8168: 'no' => "Not shown",
8169: );
8170: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8171: }
8172:
1.72 raeburn 8173: sub tool_titles {
8174: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 8175: aboutme => 'Personal web page',
1.86 raeburn 8176: blog => 'Blog',
1.160.6.4 raeburn 8177: webdav => 'WebDAV',
1.86 raeburn 8178: portfolio => 'Portfolio',
1.160.6.118.2 10(raebu 8179:22): timezone => 'Can set time zone',
1.88 bisitz 8180: official => 'Official courses (with institutional codes)',
8181: unofficial => 'Unofficial courses',
1.98 raeburn 8182: community => 'Communities',
1.160.6.30 raeburn 8183: textbook => 'Textbook courses',
1.86 raeburn 8184: );
1.72 raeburn 8185: return %titles;
8186: }
8187:
1.101 raeburn 8188: sub courserequest_titles {
8189: my %titles = &Apache::lonlocal::texthash (
8190: official => 'Official',
8191: unofficial => 'Unofficial',
8192: community => 'Communities',
1.160.6.30 raeburn 8193: textbook => 'Textbook',
1.160.6.118.2 14(raebu 8194:23): lti => 'LTI Provider',
1.101 raeburn 8195: norequest => 'Not allowed',
1.104 raeburn 8196: approval => 'Approval by Dom. Coord.',
1.101 raeburn 8197: validate => 'With validation',
8198: autolimit => 'Numerical limit',
1.103 raeburn 8199: unlimited => '(blank for unlimited)',
1.101 raeburn 8200: );
8201: return %titles;
8202: }
8203:
1.160.6.5 raeburn 8204: sub authorrequest_titles {
8205: my %titles = &Apache::lonlocal::texthash (
8206: norequest => 'Not allowed',
8207: approval => 'Approval by Dom. Coord.',
8208: automatic => 'Automatic approval',
8209: );
8210: return %titles;
8211: }
8212:
1.101 raeburn 8213: sub courserequest_conditions {
8214: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8215: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 8216: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8217: );
8218: return %conditions;
8219: }
8220:
8221:
1.27 raeburn 8222: sub print_usercreation {
1.30 raeburn 8223: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8224: my $numinrow = 4;
1.28 raeburn 8225: my $datatable;
8226: if ($position eq 'top') {
1.30 raeburn 8227: $$rowtotal ++;
1.34 raeburn 8228: my $rowcount = 0;
1.32 raeburn 8229: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8230: if (ref($rules) eq 'HASH') {
8231: if (keys(%{$rules}) > 0) {
1.32 raeburn 8232: $datatable .= &user_formats_row('username',$settings,$rules,
8233: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8234: $$rowtotal ++;
1.32 raeburn 8235: $rowcount ++;
8236: }
8237: }
8238: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8239: if (ref($idrules) eq 'HASH') {
8240: if (keys(%{$idrules}) > 0) {
8241: $datatable .= &user_formats_row('id',$settings,$idrules,
8242: $idruleorder,$numinrow,$rowcount);
8243: $$rowtotal ++;
8244: $rowcount ++;
1.28 raeburn 8245: }
8246: }
1.39 raeburn 8247: if ($rowcount == 0) {
8248: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8249: $$rowtotal ++;
8250: $rowcount ++;
8251: }
1.34 raeburn 8252: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 8253: my @creators = ('author','course','requestcrs');
1.37 raeburn 8254: my ($rules,$ruleorder) =
8255: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8256: my %lt = &usercreation_types();
8257: my %checked;
8258: if (ref($settings) eq 'HASH') {
8259: if (ref($settings->{'cancreate'}) eq 'HASH') {
8260: foreach my $item (@creators) {
8261: $checked{$item} = $settings->{'cancreate'}{$item};
8262: }
8263: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8264: foreach my $item (@creators) {
8265: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8266: $checked{$item} = 'none';
8267: }
8268: }
8269: }
8270: }
8271: my $rownum = 0;
8272: foreach my $item (@creators) {
8273: $rownum ++;
1.160.6.34 raeburn 8274: if ($checked{$item} eq '') {
8275: $checked{$item} = 'any';
1.34 raeburn 8276: }
8277: my $css_class;
8278: if ($rownum%2) {
8279: $css_class = '';
8280: } else {
8281: $css_class = ' class="LC_odd_row" ';
8282: }
8283: $datatable .= '<tr'.$css_class.'>'.
8284: '<td><span class="LC_nobreak">'.$lt{$item}.
8285: '</span></td><td align="right">';
1.160.6.34 raeburn 8286: my @options = ('any');
8287: if (ref($rules) eq 'HASH') {
8288: if (keys(%{$rules}) > 0) {
8289: push(@options,('official','unofficial'));
1.37 raeburn 8290: }
8291: }
1.160.6.34 raeburn 8292: push(@options,'none');
1.37 raeburn 8293: foreach my $option (@options) {
1.50 raeburn 8294: my $type = 'radio';
1.34 raeburn 8295: my $check = ' ';
1.160.6.34 raeburn 8296: if ($checked{$item} eq $option) {
8297: $check = ' checked="checked" ';
1.34 raeburn 8298: }
8299: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8300: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8301: $item.'" value="'.$option.'"'.$check.'/> '.
8302: $lt{$option}.'</label> </span>';
8303: }
8304: $datatable .= '</td></tr>';
8305: }
1.28 raeburn 8306: } else {
8307: my @contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 8308:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8309: my %checked;
8310: if (ref($settings) eq 'HASH') {
8311: if (ref($settings->{'authtypes'}) eq 'HASH') {
8312: foreach my $item (@contexts) {
8313: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8314: foreach my $auth (@authtypes) {
8315: if ($settings->{'authtypes'}{$item}{$auth}) {
8316: $checked{$item}{$auth} = ' checked="checked" ';
8317: }
8318: }
8319: }
8320: }
1.27 raeburn 8321: }
1.35 raeburn 8322: } else {
8323: foreach my $item (@contexts) {
1.36 raeburn 8324: foreach my $auth (@authtypes) {
1.35 raeburn 8325: $checked{$item}{$auth} = ' checked="checked" ';
8326: }
8327: }
1.27 raeburn 8328: }
1.28 raeburn 8329: my %title = &context_names();
8330: my %authname = &authtype_names();
8331: my $rownum = 0;
8332: my $css_class;
8333: foreach my $item (@contexts) {
8334: if ($rownum%2) {
8335: $css_class = '';
8336: } else {
8337: $css_class = ' class="LC_odd_row" ';
8338: }
1.30 raeburn 8339: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8340: '<td>'.$title{$item}.
8341: '</td><td class="LC_left_item">'.
8342: '<span class="LC_nobreak">';
8343: foreach my $auth (@authtypes) {
8344: $datatable .= '<label>'.
8345: '<input type="checkbox" name="'.$item.'_auth" '.
8346: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8347: $authname{$auth}.'</label> ';
8348: }
8349: $datatable .= '</span></td></tr>';
8350: $rownum ++;
1.27 raeburn 8351: }
1.30 raeburn 8352: $$rowtotal += $rownum;
1.27 raeburn 8353: }
8354: return $datatable;
8355: }
8356:
1.160.6.34 raeburn 8357: sub print_selfcreation {
8358: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 8359: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8360: $emaildomain,$datatable);
1.160.6.34 raeburn 8361: if (ref($settings) eq 'HASH') {
8362: if (ref($settings->{'cancreate'}) eq 'HASH') {
8363: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 8364: if (ref($createsettings) eq 'HASH') {
8365: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8366: @selfcreate = @{$createsettings->{'selfcreate'}};
8367: } elsif ($createsettings->{'selfcreate'} ne '') {
8368: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8369: @selfcreate = ('email','login','sso');
8370: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8371: @selfcreate = ($createsettings->{'selfcreate'});
8372: }
8373: }
8374: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8375: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 8376: }
1.160.6.93 raeburn 8377: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8378: $emailoptions = $createsettings->{'emailoptions'};
8379: }
8380: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8381: $emailverified = $createsettings->{'emailverified'};
8382: }
8383: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8384: $emaildomain = $createsettings->{'emaildomain'};
8385: }
1.160.6.34 raeburn 8386: }
8387: }
8388: }
8389: my %radiohash;
8390: my $numinrow = 4;
8391: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 8392: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 8393: if ($position eq 'top') {
8394: my %choices = &Apache::lonlocal::texthash (
8395: cancreate_login => 'Institutional Login',
8396: cancreate_sso => 'Institutional Single Sign On',
8397: );
8398: my @toggles = sort(keys(%choices));
8399: my %defaultchecked = (
8400: 'cancreate_login' => 'off',
8401: 'cancreate_sso' => 'off',
8402: );
1.160.6.35 raeburn 8403: my ($onclick,$itemcount);
1.160.6.34 raeburn 8404: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8405: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 8406: $$rowtotal += $itemcount;
1.160.6.34 raeburn 8407:
8408: if (ref($usertypes) eq 'HASH') {
8409: if (keys(%{$usertypes}) > 0) {
8410: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8411: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 8412: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 8413: $$rowtotal ++;
8414: }
8415: }
1.160.6.44 raeburn 8416: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8417: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8418: $fieldtitles{'inststatus'} = &mt('Institutional status');
8419: my $rem;
8420: my $numperrow = 2;
8421: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8422: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 8423: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 8424: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 8425: '<table>'."\n";
1.160.6.44 raeburn 8426: for (my $i=0; $i<@fields; $i++) {
8427: $rem = $i%($numperrow);
8428: if ($rem == 0) {
8429: if ($i > 0) {
8430: $datatable .= '</tr>';
8431: }
8432: $datatable .= '<tr>';
8433: }
8434: my $currval;
1.160.6.51 raeburn 8435: if (ref($createsettings) eq 'HASH') {
8436: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8437: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8438: }
1.160.6.44 raeburn 8439: }
8440: $datatable .= '<td class="LC_left_item">'.
8441: '<span class="LC_nobreak">'.
8442: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8443: 'value="'.$currval.'" size="10" /> '.
8444: $fieldtitles{$fields[$i]}.'</span></td>';
8445: }
8446: my $colsleft = $numperrow - $rem;
8447: if ($colsleft > 1 ) {
8448: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8449: ' </td>';
8450: } elsif ($colsleft == 1) {
8451: $datatable .= '<td class="LC_left_item"> </td>';
8452: }
8453: $datatable .= '</tr></table></td></tr>';
8454: $$rowtotal ++;
1.160.6.34 raeburn 8455: } elsif ($position eq 'middle') {
8456: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 8457: my @posstypes;
1.160.6.34 raeburn 8458: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8459: @posstypes = @{$types};
8460: }
8461: unless (grep(/^default$/,@posstypes)) {
8462: push(@posstypes,'default');
8463: }
8464: my %usertypeshash;
8465: if (ref($usertypes) eq 'HASH') {
8466: %usertypeshash = %{$usertypes};
8467: }
8468: $usertypeshash{'default'} = $othertitle;
8469: foreach my $status (@posstypes) {
8470: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8471: $numinrow,$$rowtotal,\%usertypeshash);
8472: $$rowtotal ++;
1.160.6.34 raeburn 8473: }
8474: } else {
1.160.6.40 raeburn 8475: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 8476: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 8477: );
8478: my @toggles = sort(keys(%choices));
8479: my %defaultchecked = (
8480: 'cancreate_email' => 'off',
8481: );
1.160.6.93 raeburn 8482: my $customclass = 'LC_selfcreate_email';
8483: my $classprefix = 'LC_canmodify_emailusername_';
8484: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 8485: my $display = 'none';
1.160.6.93 raeburn 8486: my $rowstyle = 'display:none';
1.160.6.40 raeburn 8487: if (grep(/^\Qemail\E$/,@selfcreate)) {
8488: $display = 'block';
1.160.6.93 raeburn 8489: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 8490: }
1.160.6.93 raeburn 8491: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8492: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8493: \%choices,$$rowtotal,$onclick);
8494: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8495: $rowstyle);
8496: $$rowtotal ++;
8497: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8498: $rowstyle);
8499: $$rowtotal ++;
8500: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 8501: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 8502: my ($emailrules,$emailruleorder) =
8503: &Apache::lonnet::inst_userrules($dom,'email');
8504: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8505: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8506: if (ref($types) eq 'ARRAY') {
8507: @posstypes = @{$types};
8508: }
8509: if (@posstypes) {
8510: unless (grep(/^default$/,@posstypes)) {
8511: push(@posstypes,'default');
1.160.6.89 raeburn 8512: }
8513: if (ref($usertypes) eq 'HASH') {
8514: %usertypeshash = %{$usertypes};
8515: }
1.160.6.93 raeburn 8516: my $currassign;
8517: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8518: $currassign = {
8519: selfassign => $domdefaults{'inststatusguest'},
8520: };
8521: @ordered = @{$domdefaults{'inststatusguest'}};
8522: } else {
8523: $currassign = { selfassign => [] };
8524: }
8525: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8526: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8527: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8528: $numinrow,$othertitle,'selfassign',
8529: $rowtotal,$onclicktypes,$customclass,
8530: $rowstyle);
8531: $$rowtotal ++;
1.160.6.89 raeburn 8532: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8533: foreach my $status (@posstypes) {
8534: my $css_class;
8535: if ($$rowtotal%2) {
8536: $css_class = 'LC_odd_row ';
8537: }
8538: $css_class .= $customclass;
8539: my $rowid = $optionsprefix.$status;
8540: my $hidden = 1;
8541: my $currstyle = 'display:none';
8542: if (grep(/^\Q$status\E$/,@ordered)) {
8543: $currstyle = $rowstyle;
8544: $hidden = 0;
8545: }
8546: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8547: $emailrules,$emailruleorder,$settings,$status,$rowid,
8548: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8549: unless ($hidden) {
8550: $$rowtotal ++;
8551: }
1.160.6.89 raeburn 8552: }
8553: } else {
1.160.6.93 raeburn 8554: my $css_class;
8555: if ($$rowtotal%2) {
8556: $css_class = 'LC_odd_row ';
8557: }
8558: $css_class .= $customclass;
1.160.6.89 raeburn 8559: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8560: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8561: $emailrules,$emailruleorder,$settings,'default','',
8562: $othertitle,$css_class,$rowstyle,$intdom);
8563: $$rowtotal ++;
1.160.6.34 raeburn 8564: }
1.160.6.35 raeburn 8565: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8566: $numinrow = 1;
1.160.6.93 raeburn 8567: if (@posstypes) {
8568: foreach my $status (@posstypes) {
8569: my $rowid = $classprefix.$status;
8570: my $datarowstyle = 'display:none';
8571: if (grep(/^\Q$status\E$/,@ordered)) {
8572: $datarowstyle = $rowstyle;
8573: }
8574: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8575: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8576: $infotitles,$rowid,$customclass,$datarowstyle);
8577: unless ($datarowstyle eq 'display:none') {
8578: $$rowtotal ++;
8579: }
1.160.6.34 raeburn 8580: }
1.160.6.93 raeburn 8581: } else {
8582: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8583: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8584: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 8585: }
8586: }
8587: return $datatable;
8588: }
8589:
1.160.6.93 raeburn 8590: sub selfcreate_javascript {
8591: return <<"ENDSCRIPT";
8592:
8593: <script type="text/javascript">
8594: // <![CDATA[
8595:
8596: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8597: var x = document.getElementsByClassName(target);
8598: var insttypes = 0;
8599: var insttypeRegExp = new RegExp(prefix);
8600: if ((x.length != undefined) && (x.length > 0)) {
8601: if (form.elements[radio].length != undefined) {
8602: for (var i=0; i<form.elements[radio].length; i++) {
8603: if (form.elements[radio][i].checked) {
8604: if (form.elements[radio][i].value == 1) {
8605: for (var j=0; j<x.length; j++) {
8606: if (x[j].id == 'undefined') {
8607: x[j].style.display = 'table-row';
8608: } else if (insttypeRegExp.test(x[j].id)) {
8609: insttypes ++;
8610: } else {
8611: x[j].style.display = 'table-row';
8612: }
8613: }
8614: } else {
8615: for (var j=0; j<x.length; j++) {
8616: x[j].style.display = 'none';
8617: }
1.160.6.40 raeburn 8618: }
1.160.6.93 raeburn 8619: break;
8620: }
8621: }
8622: if (insttypes > 0) {
8623: toggleDataRow(form,checkbox,target,altprefix);
8624: toggleDataRow(form,checkbox,target,prefix,1);
8625: }
8626: }
8627: }
8628: return;
8629: }
8630:
8631: function toggleDataRow(form,checkbox,target,prefix,docount) {
8632: if (form.elements[checkbox].length != undefined) {
8633: var count = 0;
8634: if (docount) {
8635: for (var i=0; i<form.elements[checkbox].length; i++) {
8636: if (form.elements[checkbox][i].checked) {
8637: count ++;
8638: }
8639: }
8640: }
8641: for (var i=0; i<form.elements[checkbox].length; i++) {
8642: var type = form.elements[checkbox][i].value;
8643: if (document.getElementById(prefix+type)) {
8644: if (form.elements[checkbox][i].checked) {
8645: document.getElementById(prefix+type).style.display = 'table-row';
8646: if (count % 2 == 1) {
8647: document.getElementById(prefix+type).className = target+' LC_odd_row';
8648: } else {
8649: document.getElementById(prefix+type).className = target;
8650: }
8651: count ++;
1.160.6.40 raeburn 8652: } else {
1.160.6.93 raeburn 8653: document.getElementById(prefix+type).style.display = 'none';
8654: }
8655: }
8656: }
8657: }
8658: return;
8659: }
8660:
8661: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8662: var caller = radio+'_'+status;
8663: if (form.elements[caller].length != undefined) {
8664: for (var i=0; i<form.elements[caller].length; i++) {
8665: if (form.elements[caller][i].checked) {
8666: if (document.getElementById(altprefix+'_inst_'+status)) {
8667: var curr = form.elements[caller][i].value;
8668: if (prefix) {
8669: document.getElementById(prefix+'_'+status).style.display = 'none';
8670: }
8671: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8672: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8673: if (curr == 'custom') {
8674: if (prefix) {
8675: document.getElementById(prefix+'_'+status).style.display = 'inline';
8676: }
8677: } else if (curr == 'inst') {
8678: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8679: } else if (curr == 'noninst') {
8680: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 8681: }
1.160.6.93 raeburn 8682: break;
1.160.6.40 raeburn 8683: }
1.160.6.93 raeburn 8684: }
8685: }
8686: }
8687: }
8688:
8689: // ]]>
8690: </script>
8691:
8692: ENDSCRIPT
8693: }
8694:
8695: sub noninst_users {
8696: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8697: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8698: my $class = 'LC_left_item';
8699: if ($css_class) {
8700: $css_class = ' class="'.$css_class.'"';
8701: }
8702: if ($rowid) {
8703: $rowid = ' id="'.$rowid.'"';
8704: }
8705: if ($rowstyle) {
8706: $rowstyle = ' style="'.$rowstyle.'"';
8707: }
8708: my ($output,$description);
8709: if ($type eq 'default') {
8710: $description = &mt('Requests for: [_1]',$typetitle);
8711: } else {
8712: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8713: }
8714: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8715: "<td>$description</td>\n".
8716: '<td class="'.$class.'" colspan="2">'.
8717: '<table><tr>';
8718: my %headers = &Apache::lonlocal::texthash(
8719: approve => 'Processing',
8720: email => 'E-mail',
8721: username => 'Username',
8722: );
8723: foreach my $item ('approve','email','username') {
8724: $output .= '<th>'.$headers{$item}.'</th>';
8725: }
8726: $output .= '</tr><tr>';
8727: foreach my $item ('approve','email','username') {
8728: $output .= '<td valign="top">';
8729: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8730: if ($item eq 'approve') {
8731: %choices = &Apache::lonlocal::texthash (
8732: automatic => 'Automatically approved',
8733: approval => 'Queued for approval',
8734: );
8735: @options = ('automatic','approval');
8736: $hashref = $processing;
8737: $defoption = 'automatic';
8738: $name = 'cancreate_emailprocess_'.$type;
8739: } elsif ($item eq 'email') {
8740: %choices = &Apache::lonlocal::texthash (
8741: any => 'Any e-mail',
8742: inst => 'Institutional only',
8743: noninst => 'Non-institutional only',
8744: custom => 'Custom restrictions',
8745: );
8746: @options = ('any','inst','noninst');
8747: my $showcustom;
8748: if (ref($emailrules) eq 'HASH') {
8749: if (keys(%{$emailrules}) > 0) {
8750: push(@options,'custom');
8751: $showcustom = 'cancreate_emailrule';
8752: if (ref($settings) eq 'HASH') {
8753: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8754: foreach my $rule (@{$settings->{'email_rule'}}) {
8755: if (exists($emailrules->{$rule})) {
8756: $hascustom ++;
8757: }
8758: }
8759: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8760: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8761: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8762: if (exists($emailrules->{$rule})) {
8763: $hascustom ++;
8764: }
8765: }
8766: }
8767: }
8768: }
8769: }
8770: }
8771: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8772: "'cancreate_emaildomain','$type'".');"';
8773: $hashref = $emailoptions;
8774: $defoption = 'any';
8775: $name = 'cancreate_emailoptions_'.$type;
8776: } elsif ($item eq 'username') {
8777: %choices = &Apache::lonlocal::texthash (
8778: all => 'Same as e-mail',
8779: first => 'Omit @domain',
8780: free => 'Free to choose',
8781: );
8782: @options = ('all','first','free');
8783: $hashref = $emailverified;
8784: $defoption = 'all';
8785: $name = 'cancreate_usernameoptions_'.$type;
8786: }
8787: foreach my $option (@options) {
8788: my $checked;
8789: if (ref($hashref) eq 'HASH') {
8790: if ($type eq '') {
8791: if (!exists($hashref->{'default'})) {
8792: if ($option eq $defoption) {
8793: $checked = ' checked="checked"';
8794: }
8795: } else {
8796: if ($hashref->{'default'} eq $option) {
8797: $checked = ' checked="checked"';
8798: }
1.160.6.40 raeburn 8799: }
8800: } else {
1.160.6.93 raeburn 8801: if (!exists($hashref->{$type})) {
8802: if ($option eq $defoption) {
8803: $checked = ' checked="checked"';
8804: }
8805: } else {
8806: if ($hashref->{$type} eq $option) {
8807: $checked = ' checked="checked"';
8808: }
1.160.6.40 raeburn 8809: }
8810: }
1.160.6.93 raeburn 8811: } elsif (($item eq 'email') && ($hascustom)) {
8812: if ($option eq 'custom') {
8813: $checked = ' checked="checked"';
8814: }
8815: } elsif ($option eq $defoption) {
8816: $checked = ' checked="checked"';
8817: }
8818: $output .= '<span class="LC_nobreak"><label>'.
8819: '<input type="radio" name="'.$name.'"'.
8820: $checked.' value="'.$option.'"'.$onclick.' />'.
8821: $choices{$option}.'</label></span><br />';
8822: if ($item eq 'email') {
8823: if ($option eq 'custom') {
8824: my $id = 'cancreate_emailrule_'.$type;
8825: my $display = 'none';
8826: if ($checked) {
8827: $display = 'inline';
8828: }
8829: my $numinrow = 2;
8830: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8831: '<legend>'.&mt('Disallow').'</legend><table>'.
8832: &user_formats_row('email',$settings,$emailrules,
8833: $emailruleorder,$numinrow,'',$type);
8834: '</table></fieldset>';
8835: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8836: my %text = &Apache::lonlocal::texthash (
8837: inst => 'must end:',
8838: noninst => 'cannot end:',
8839: );
8840: my $value;
8841: if (ref($emaildomain) eq 'HASH') {
8842: if (ref($emaildomain->{$type}) eq 'HASH') {
8843: $value = $emaildomain->{$type}->{$option};
8844: }
8845: }
8846: if ($value eq '') {
8847: $value = '@'.$intdom;
8848: }
8849: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8850: my $display = 'none';
8851: if ($checked) {
8852: $display = 'inline';
8853: }
8854: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8855: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8856: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8857: '</div>';
8858: }
1.160.6.40 raeburn 8859: }
8860: }
1.160.6.93 raeburn 8861: $output .= '</td>'."\n";
1.160.6.40 raeburn 8862: }
1.160.6.93 raeburn 8863: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 8864: return $output;
8865: }
8866:
1.160.6.5 raeburn 8867: sub captcha_choice {
1.160.6.93 raeburn 8868: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 8869: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
1.160.6.118.2 14(raebu 8870:23): $vertext,$currver);
1.160.6.5 raeburn 8871: my %lt = &captcha_phrases();
8872: $keyentry = 'hidden';
1.160.6.98 raeburn 8873: my $colspan=2;
1.160.6.5 raeburn 8874: if ($context eq 'cancreate') {
1.160.6.34 raeburn 8875: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 8876: } elsif ($context eq 'login') {
8877: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 8878: } elsif ($context eq 'passwords') {
8879: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8880: $colspan=1;
1.160.6.5 raeburn 8881: }
8882: if (ref($settings) eq 'HASH') {
8883: if ($settings->{'captcha'}) {
8884: $checked{$settings->{'captcha'}} = ' checked="checked"';
8885: } else {
8886: $checked{'original'} = ' checked="checked"';
8887: }
8888: if ($settings->{'captcha'} eq 'recaptcha') {
8889: $pubtext = $lt{'pub'};
8890: $privtext = $lt{'priv'};
8891: $keyentry = 'text';
1.160.6.69 raeburn 8892: $vertext = $lt{'ver'};
8893: $currver = $settings->{'recaptchaversion'};
8894: if ($currver ne '2') {
8895: $currver = 1;
8896: }
1.160.6.5 raeburn 8897: }
8898: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8899: $currpub = $settings->{'recaptchakeys'}{'public'};
8900: $currpriv = $settings->{'recaptchakeys'}{'private'};
8901: }
8902: } else {
8903: $checked{'original'} = ' checked="checked"';
8904: }
1.160.6.93 raeburn 8905: my $css_class;
8906: if ($itemcount%2) {
8907: $css_class = 'LC_odd_row';
8908: }
8909: if ($customcss) {
8910: $css_class .= " $customcss";
8911: }
8912: $css_class =~ s/^\s+//;
8913: if ($css_class) {
8914: $css_class = ' class="'.$css_class.'"';
8915: }
8916: if ($rowstyle) {
8917: $css_class .= ' style="'.$rowstyle.'"';
8918: }
1.160.6.5 raeburn 8919: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 8920: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 8921: '<table><tr><td>'."\n";
8922: foreach my $option ('original','recaptcha','notused') {
8923: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
8924: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
8925: $lt{$option}.'</label></span>';
8926: unless ($option eq 'notused') {
8927: $output .= (' 'x2)."\n";
8928: }
8929: }
8930: #
8931: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
8932: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
8933: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
8934: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
8935: #
8936: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 8937: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 8938: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
8939: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
8940: $currpub.'" size="40" /></span><br />'."\n".
8941: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
8942: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 8943: $currpriv.'" size="40" /></span><br />'.
8944: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
8945: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
8946: $currver.'" size="3" /></span><br />'.
8947: '</td></tr></table>'."\n".
1.160.6.5 raeburn 8948: '</td></tr>';
8949: return $output;
8950: }
8951:
1.32 raeburn 8952: sub user_formats_row {
1.160.6.93 raeburn 8953: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 8954: my $output;
8955: my %text = (
8956: 'username' => 'new usernames',
8957: 'id' => 'IDs',
8958: );
1.160.6.118.2 8(raebur 8959:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 8960: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
8961: $output = '<tr '.$css_class.'>'.
8962: '<td><span class="LC_nobreak">'.
8963: &mt("Format rules to check for $text{$type}: ").
8964: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 8965: }
1.27 raeburn 8966: my $rem;
8967: if (ref($ruleorder) eq 'ARRAY') {
8968: for (my $i=0; $i<@{$ruleorder}; $i++) {
8969: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
8970: my $rem = $i%($numinrow);
8971: if ($rem == 0) {
8972: if ($i > 0) {
8973: $output .= '</tr>';
8974: }
8975: $output .= '<tr>';
8976: }
8977: my $check = ' ';
1.39 raeburn 8978: if (ref($settings) eq 'HASH') {
8979: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
8980: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
8981: $check = ' checked="checked" ';
8982: }
1.160.6.93 raeburn 8983: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
8984: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
8985: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
8986: $check = ' checked="checked" ';
8987: }
8988: }
1.27 raeburn 8989: }
8990: }
1.160.6.93 raeburn 8991: my $name = $type.'_rule';
8992: if ($type eq 'email') {
8993: $name .= '_'.$status;
8994: }
1.27 raeburn 8995: $output .= '<td class="LC_left_item">'.
8996: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 8997: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 8998: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
8999: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9000: }
9001: }
9002: $rem = @{$ruleorder}%($numinrow);
9003: }
1.160.6.93 raeburn 9004: my $colsleft;
9005: if ($rem) {
9006: $colsleft = $numinrow - $rem;
9007: }
1.27 raeburn 9008: if ($colsleft > 1 ) {
9009: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9010: ' </td>';
9011: } elsif ($colsleft == 1) {
9012: $output .= '<td class="LC_left_item"> </td>';
9013: }
1.160.6.118.2 8(raebur 9014:2): $output .= '</tr>';
9015:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
9016:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 9017: }
1.27 raeburn 9018: return $output;
9019: }
9020:
1.34 raeburn 9021: sub usercreation_types {
9022: my %lt = &Apache::lonlocal::texthash (
9023: author => 'When adding a co-author',
9024: course => 'When adding a user to a course',
1.100 raeburn 9025: requestcrs => 'When requesting a course',
1.34 raeburn 9026: any => 'Any',
9027: official => 'Institutional only ',
9028: unofficial => 'Non-institutional only',
9029: none => 'None',
9030: );
9031: return %lt;
1.48 raeburn 9032: }
1.34 raeburn 9033:
1.160.6.34 raeburn 9034: sub selfcreation_types {
9035: my %lt = &Apache::lonlocal::texthash (
9036: selfcreate => 'User creates own account',
9037: any => 'Any',
9038: official => 'Institutional only ',
9039: unofficial => 'Non-institutional only',
9040: email => 'E-mail address',
9041: login => 'Institutional Login',
9042: sso => 'SSO',
9043: );
9044: }
9045:
1.28 raeburn 9046: sub authtype_names {
9047: my %lt = &Apache::lonlocal::texthash(
9048: int => 'Internal',
9049: krb4 => 'Kerberos 4',
9050: krb5 => 'Kerberos 5',
9051: loc => 'Local',
1.160.6.118.2 14(raebu 9052:23): lti => 'LTI',
1.28 raeburn 9053: );
9054: return %lt;
9055: }
9056:
9057: sub context_names {
9058: my %context_title = &Apache::lonlocal::texthash(
9059: author => 'Creating users when an Author',
9060: course => 'Creating users when in a course',
9061: domain => 'Creating users when a Domain Coordinator',
9062: );
9063: return %context_title;
9064: }
9065:
1.33 raeburn 9066: sub print_usermodification {
9067: my ($position,$dom,$settings,$rowtotal) = @_;
9068: my $numinrow = 4;
9069: my ($context,$datatable,$rowcount);
9070: if ($position eq 'top') {
9071: $rowcount = 0;
9072: $context = 'author';
9073: foreach my $role ('ca','aa') {
9074: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9075: $numinrow,$rowcount);
9076: $$rowtotal ++;
9077: $rowcount ++;
9078: }
1.160.6.37 raeburn 9079: } elsif ($position eq 'bottom') {
1.33 raeburn 9080: $context = 'course';
9081: $rowcount = 0;
9082: foreach my $role ('st','ep','ta','in','cr') {
9083: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9084: $numinrow,$rowcount);
9085: $$rowtotal ++;
9086: $rowcount ++;
9087: }
9088: }
9089: return $datatable;
9090: }
9091:
1.43 raeburn 9092: sub print_defaults {
1.160.6.40 raeburn 9093: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9094: my $rownum = 0;
1.160.6.80 raeburn 9095: my ($datatable,$css_class,$titles);
9096: unless ($position eq 'bottom') {
9097: $titles = &defaults_titles($dom);
9098: }
1.160.6.40 raeburn 9099: if ($position eq 'top') {
9100: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9101: 'datelocale_def','portal_def');
9102: my %defaults;
9103: if (ref($settings) eq 'HASH') {
9104: %defaults = %{$settings};
1.43 raeburn 9105: } else {
1.160.6.40 raeburn 9106: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9107: foreach my $item (@items) {
9108: $defaults{$item} = $domdefaults{$item};
9109: }
1.43 raeburn 9110: }
1.160.6.40 raeburn 9111: foreach my $item (@items) {
9112: if ($rownum%2) {
9113: $css_class = '';
9114: } else {
9115: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 9116: }
1.160.6.40 raeburn 9117: $datatable .= '<tr'.$css_class.'>'.
9118: '<td><span class="LC_nobreak">'.$titles->{$item}.
9119: '</span></td><td class="LC_right_item" colspan="3">';
9120: if ($item eq 'auth_def') {
1.160.6.118.2 14(raebu 9121:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.160.6.40 raeburn 9122: my %shortauth = (
9123: internal => 'int',
9124: krb4 => 'krb4',
9125: krb5 => 'krb5',
1.160.6.118.2 14(raebu 9126:23): localauth => 'loc',
9127:23): lti => 'lti',
1.160.6.40 raeburn 9128: );
9129: my %authnames = &authtype_names();
9130: foreach my $auth (@authtypes) {
9131: my $checked = ' ';
9132: if ($defaults{$item} eq $auth) {
9133: $checked = ' checked="checked" ';
9134: }
9135: $datatable .= '<label><input type="radio" name="'.$item.
9136: '" value="'.$auth.'"'.$checked.'/>'.
9137: $authnames{$shortauth{$auth}}.'</label> ';
9138: }
9139: } elsif ($item eq 'timezone_def') {
9140: my $includeempty = 1;
9141: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9142: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 9143: my $includeempty = 1;
9144: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9145: } elsif ($item eq 'lang_def') {
9146: my $includeempty = 1;
9147: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 9148:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 9149: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 9150:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9151:23): my $portalsty = 'none';
9152:23): if ($defaults{$item}) {
9153:23): $portalsty = 'block';
9154:23): }
9155:23): foreach my $field ('email','web') {
9156:23): my $checkedoff = ' checked="checked"';
9157:23): my $checkedon;
9158:23): if ($defaults{$item.'_'.$field}) {
9159:23): $checkedon = $checkedoff;
9160:23): $checkedoff = '';
9161:23): }
9162:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9163:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
9164:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9165:23): (' 'x2).
9166:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9167:23): '</div>';
9168:23): }
9169:23): } else {
9170:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 9171: }
9172: $datatable .= '</td></tr>';
9173: $rownum ++;
9174: }
1.160.6.118.2 8(raebur 9175:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 9176: my %defaults;
1.160.6.40 raeburn 9177: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 9178: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 9179: my $maxnum = @{$settings->{'inststatusorder'}};
9180: for (my $i=0; $i<$maxnum; $i++) {
9181: $css_class = $rownum%2?' class="LC_odd_row"':'';
9182: my $item = $settings->{'inststatusorder'}->[$i];
9183: my $title = $settings->{'inststatustypes'}->{$item};
9184: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9185: $datatable .= '<tr'.$css_class.'>'.
9186: '<td><span class="LC_nobreak">'.
9187: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9188: for (my $k=0; $k<=$maxnum; $k++) {
9189: my $vpos = $k+1;
9190: my $selstr;
9191: if ($k == $i) {
9192: $selstr = ' selected="selected" ';
9193: }
9194: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9195: }
9196: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9197: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9198: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 9199: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 9200: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 9201: '</span></td></tr>';
1.160.6.40 raeburn 9202: }
9203: $css_class = $rownum%2?' class="LC_odd_row"':'';
9204: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9205: $datatable .= '<tr '.$css_class.'>'.
9206: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9207: for (my $k=0; $k<=$maxnum; $k++) {
9208: my $vpos = $k+1;
9209: my $selstr;
9210: if ($k == $maxnum) {
9211: $selstr = ' selected="selected" ';
9212: }
9213: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9214: }
9215: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 9216: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 9217: ' '.&mt('(new)').
9218: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 9219: &mt('Name displayed').':'.
1.160.6.40 raeburn 9220: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9221: '</tr>'."\n";
9222: $rownum ++;
1.141 raeburn 9223: }
1.43 raeburn 9224: }
1.160.6.118.2 8(raebur 9225:2): } else {
9226:2): my ($unamemaprules,$ruleorder) =
9227:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
9228:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
9229:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9230:2): my $numinrow = 2;
9231:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9232:2): &user_formats_row('unamemap',$settings,$unamemaprules,
9233:2): $ruleorder,$numinrow).
9234:2): '</table></td></tr>';
9235:2): }
9236:2): if ($datatable eq '') {
9237:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9238:2): &mt('No rules set for domain in customized localenroll.pm').
9239:2): '</td></tr>';
9240:2): }
1.43 raeburn 9241: }
9242: $$rowtotal += $rownum;
9243: return $datatable;
9244: }
9245:
1.160.6.5 raeburn 9246: sub get_languages_hash {
9247: my %langchoices;
9248: foreach my $id (&Apache::loncommon::languageids()) {
9249: my $code = &Apache::loncommon::supportedlanguagecode($id);
9250: if ($code ne '') {
9251: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9252: }
9253: }
9254: return %langchoices;
9255: }
9256:
1.43 raeburn 9257: sub defaults_titles {
1.141 raeburn 9258: my ($dom) = @_;
1.43 raeburn 9259: my %titles = &Apache::lonlocal::texthash (
9260: 'auth_def' => 'Default authentication type',
9261: 'auth_arg_def' => 'Default authentication argument',
9262: 'lang_def' => 'Default language',
1.54 raeburn 9263: 'timezone_def' => 'Default timezone',
1.68 raeburn 9264: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9265: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 9266:23): 'email' => 'Email links use portal URL',
9267:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 9268: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9269: 'intauth_check' => 'Check bcrypt cost if authenticated',
9270: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9271: );
1.141 raeburn 9272: if ($dom) {
9273: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9274: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9275: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9276: $protocol = 'http' if ($protocol ne 'https');
9277: if ($uint_dom) {
9278: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9279: $uint_dom);
9280: }
9281: }
1.43 raeburn 9282: return (\%titles);
9283: }
9284:
1.160.6.97 raeburn 9285: sub print_scantron {
9286: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9287: if ($position eq 'top') {
9288: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9289: } else {
9290: return &print_scantronconfig($dom,$settings,\$rowtotal);
9291: }
9292: }
9293:
9294: sub scantron_javascript {
9295: return <<"ENDSCRIPT";
9296:
9297: <script type="text/javascript">
9298: // <![CDATA[
9299:
9300: function toggleScantron(form) {
9301: var csvfieldset = new Array();
9302: if (document.getElementById('scantroncsv_cols')) {
9303: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9304: }
9305: if (document.getElementById('scantroncsv_options')) {
9306: csvfieldset.push(document.getElementById('scantroncsv_options'));
9307: }
9308: if (csvfieldset.length) {
9309: if (document.getElementById('scantronconfcsv')) {
9310: var scantroncsv = document.getElementById('scantronconfcsv');
9311: if (scantroncsv.checked) {
9312: for (var i=0; i<csvfieldset.length; i++) {
9313: csvfieldset[i].style.display = 'block';
9314: }
9315: } else {
9316: for (var i=0; i<csvfieldset.length; i++) {
9317: csvfieldset[i].style.display = 'none';
9318: }
9319: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9320: if (csvselects.length) {
9321: for (var j=0; j<csvselects.length; j++) {
9322: csvselects[j].selectedIndex = 0;
9323: }
9324: }
9325: }
9326: }
9327: }
9328: return;
9329: }
9330: // ]]>
9331: </script>
9332:
9333: ENDSCRIPT
9334:
9335: }
9336:
1.46 raeburn 9337: sub print_scantronformat {
9338: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9339: my $itemcount = 1;
1.60 raeburn 9340: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9341: %confhash);
1.46 raeburn 9342: my $switchserver = &check_switchserver($dom,$confname);
9343: my %lt = &Apache::lonlocal::texthash (
1.95 www 9344: default => 'Default bubblesheet format file error',
9345: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9346: );
9347: my %scantronfiles = (
9348: default => 'default.tab',
9349: custom => 'custom.tab',
9350: );
9351: foreach my $key (keys(%scantronfiles)) {
9352: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9353: .$scantronfiles{$key};
9354: }
9355: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9356: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9357: if (!$switchserver) {
9358: my $servadm = $r->dir_config('lonAdmEMail');
9359: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9360: if ($configuserok eq 'ok') {
9361: if ($author_ok eq 'ok') {
9362: my %legacyfile = (
1.160.6.97 raeburn 9363: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9364: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9365: );
9366: my %md5chk;
9367: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9368: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9369: chomp($md5chk{$type});
1.46 raeburn 9370: }
9371: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9372: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 9373: ($scantronurls{$type},my $error) =
1.46 raeburn 9374: &legacy_scantronformat($r,$dom,$confname,
9375: $type,$legacyfile{$type},
9376: $scantronurls{$type},
9377: $scantronfiles{$type});
1.60 raeburn 9378: if ($error ne '') {
9379: $error{$type} = $error;
9380: }
9381: }
9382: if (keys(%error) == 0) {
9383: $is_custom = 1;
1.160.6.97 raeburn 9384: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9385: $scantronurls{'custom'};
1.160.6.97 raeburn 9386: my $putresult =
1.60 raeburn 9387: &Apache::lonnet::put_dom('configuration',
9388: \%confhash,$dom);
9389: if ($putresult ne 'ok') {
1.160.6.97 raeburn 9390: $error{'custom'} =
1.60 raeburn 9391: '<span class="LC_error">'.
9392: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9393: }
1.46 raeburn 9394: }
9395: } else {
1.60 raeburn 9396: ($scantronurls{'default'},my $error) =
1.46 raeburn 9397: &legacy_scantronformat($r,$dom,$confname,
9398: 'default',$legacyfile{'default'},
9399: $scantronurls{'default'},
9400: $scantronfiles{'default'});
1.60 raeburn 9401: if ($error eq '') {
9402: $confhash{'scantron'}{'scantronformat'} = '';
9403: my $putresult =
9404: &Apache::lonnet::put_dom('configuration',
9405: \%confhash,$dom);
9406: if ($putresult ne 'ok') {
9407: $error{'default'} =
9408: '<span class="LC_error">'.
9409: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9410: }
9411: } else {
9412: $error{'default'} = $error;
9413: }
1.46 raeburn 9414: }
9415: }
9416: }
9417: } else {
1.95 www 9418: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9419: }
9420: }
9421: if (ref($settings) eq 'HASH') {
9422: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9423: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9424: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9425: $scantronurl = '';
9426: } else {
9427: $scantronurl = $settings->{'scantronformat'};
9428: }
9429: $is_custom = 1;
9430: } else {
9431: $scantronurl = $scantronurls{'default'};
9432: }
9433: } else {
1.60 raeburn 9434: if ($is_custom) {
9435: $scantronurl = $scantronurls{'custom'};
9436: } else {
9437: $scantronurl = $scantronurls{'default'};
9438: }
1.46 raeburn 9439: }
9440: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9441: $datatable .= '<tr'.$css_class.'>';
9442: if (!$is_custom) {
1.65 raeburn 9443: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9444: '<span class="LC_nobreak">';
1.46 raeburn 9445: if ($scantronurl) {
1.160.6.21 raeburn 9446: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9447: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9448: } else {
9449: $datatable = &mt('File unavailable for display');
9450: }
1.65 raeburn 9451: $datatable .= '</span></td>';
1.60 raeburn 9452: if (keys(%error) == 0) {
9453: $datatable .= '<td valign="bottom">';
9454: if (!$switchserver) {
9455: $datatable .= &mt('Upload:').'<br />';
9456: }
9457: } else {
9458: my $errorstr;
9459: foreach my $key (sort(keys(%error))) {
9460: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9461: }
9462: $datatable .= '<td>'.$errorstr;
9463: }
1.46 raeburn 9464: } else {
9465: if (keys(%error) > 0) {
9466: my $errorstr;
9467: foreach my $key (sort(keys(%error))) {
9468: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9469: }
1.60 raeburn 9470: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9471: } elsif ($scantronurl) {
1.160.6.26 raeburn 9472: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 9473: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9474: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 9475: $link.
9476: '<label><input type="checkbox" name="scantronformat_del"'.
9477: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9478: '<td><span class="LC_nobreak"> '.
9479: &mt('Replace:').'</span><br />';
1.46 raeburn 9480: }
9481: }
9482: if (keys(%error) == 0) {
9483: if ($switchserver) {
9484: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9485: } else {
1.65 raeburn 9486: $datatable .='<span class="LC_nobreak"> '.
9487: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9488: }
9489: }
9490: $datatable .= '</td></tr>';
9491: $$rowtotal ++;
9492: return $datatable;
9493: }
9494:
9495: sub legacy_scantronformat {
9496: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9497: my ($url,$error);
9498: my @statinfo = &Apache::lonnet::stat_file($newurl);
9499: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.160.6.118.2 14(raebu 9500:23): my $modified = [];
1.46 raeburn 9501: (my $result,$url) =
1.160.6.118.2 14(raebu 9502:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9503:23): 'scantron','','',$newfile,$modified);
9504:23): if ($result eq 'ok') {
9505:23): &update_modify_urls($r,$modified);
9506:23): } else {
1.130 raeburn 9507: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9508: }
9509: }
9510: return ($url,$error);
9511: }
1.43 raeburn 9512:
1.160.6.97 raeburn 9513: sub print_scantronconfig {
9514: my ($dom,$settings,$rowtotal) = @_;
9515: my $itemcount = 2;
9516: my $is_checked = ' checked="checked"';
9517: my %optionson = (
9518: hdr => ' checked="checked"',
9519: pad => ' checked="checked"',
9520: rem => ' checked="checked"',
9521: );
9522: my %optionsoff = (
9523: hdr => '',
9524: pad => '',
9525: rem => '',
9526: );
9527: my $currcsvsty = 'none';
9528: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9529: my @fields = &scantroncsv_fields();
9530: my %titles = &scantronconfig_titles();
9531: if (ref($settings) eq 'HASH') {
9532: if (ref($settings->{config}) eq 'HASH') {
9533: if ($settings->{config}->{dat}) {
9534: $checked{'dat'} = $is_checked;
9535: }
9536: if (ref($settings->{config}->{csv}) eq 'HASH') {
9537: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9538: %csvfields = %{$settings->{config}->{csv}->{fields}};
9539: if (keys(%csvfields) > 0) {
9540: $checked{'csv'} = $is_checked;
9541: $currcsvsty = 'block';
9542: }
9543: }
9544: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9545: %csvoptions = %{$settings->{config}->{csv}->{options}};
9546: foreach my $option (keys(%optionson)) {
9547: unless ($csvoptions{$option}) {
9548: $optionsoff{$option} = $optionson{$option};
9549: $optionson{$option} = '';
9550: }
9551: }
9552: }
9553: }
9554: } else {
9555: $checked{'dat'} = $is_checked;
9556: }
9557: } else {
9558: $checked{'dat'} = $is_checked;
9559: }
9560: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9561: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9562: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9563: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9564: foreach my $item ('dat','csv') {
9565: my $id;
9566: if ($item eq 'csv') {
9567: $id = 'id="scantronconfcsv" ';
9568: }
9569: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9570: $titles{$item}.'</label>'.(' 'x3);
9571: if ($item eq 'csv') {
9572: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9573: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9574: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9575: foreach my $col (@fields) {
9576: my $selnone;
9577: if ($csvfields{$col} eq '') {
9578: $selnone = ' selected="selected"';
9579: }
9580: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9581: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9582: '<option value=""'.$selnone.'></option>';
9583: for (my $i=0; $i<20; $i++) {
9584: my $shown = $i+1;
9585: my $sel;
9586: unless ($selnone) {
9587: if (exists($csvfields{$col})) {
9588: if ($csvfields{$col} == $i) {
9589: $sel = ' selected="selected"';
9590: }
9591: }
9592: }
9593: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9594: }
9595: $datatable .= '</select></td></tr>';
9596: }
9597: $datatable .= '</table></fieldset>'.
9598: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9599: '<legend>'.&mt('CSV Options').'</legend>';
9600: foreach my $option ('hdr','pad','rem') {
9601: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9602: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9603: &mt('Yes').'</label>'.(' 'x2)."\n".
9604: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9605: }
9606: $datatable .= '</fieldset>';
9607: $itemcount ++;
9608: }
9609: }
9610: $datatable .= '</td></tr>';
9611: $$rowtotal ++;
9612: return $datatable;
9613: }
9614:
9615: sub scantronconfig_titles {
9616: return &Apache::lonlocal::texthash(
9617: dat => 'Standard format (.dat)',
9618: csv => 'Comma separated values (.csv)',
9619: hdr => 'Remove first line in file (contains column titles)',
9620: pad => 'Prepend 0s to PaperID',
9621: rem => 'Remove leading spaces (except Question Response columns)',
9622: CODE => 'CODE',
9623: ID => 'Student ID',
9624: PaperID => 'Paper ID',
9625: FirstName => 'First Name',
9626: LastName => 'Last Name',
9627: FirstQuestion => 'First Question Response',
9628: Section => 'Section',
9629: );
9630: }
9631:
9632: sub scantroncsv_fields {
9633: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9634: }
9635:
1.49 raeburn 9636: sub print_coursecategories {
1.57 raeburn 9637: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9638: my $datatable;
9639: if ($position eq 'top') {
1.160.6.42 raeburn 9640: my (%checked);
9641: my @catitems = ('unauth','auth');
9642: my @cattypes = ('std','domonly','codesrch','none');
9643: $checked{'unauth'} = 'std';
9644: $checked{'auth'} = 'std';
9645: if (ref($settings) eq 'HASH') {
9646: foreach my $type (@cattypes) {
9647: if ($type eq $settings->{'unauth'}) {
9648: $checked{'unauth'} = $type;
9649: }
9650: if ($type eq $settings->{'auth'}) {
9651: $checked{'auth'} = $type;
9652: }
9653: }
9654: }
9655: my %lt = &Apache::lonlocal::texthash (
9656: unauth => 'Catalog type for unauthenticated users',
9657: auth => 'Catalog type for authenticated users',
9658: none => 'No catalog',
9659: std => 'Standard catalog',
9660: domonly => 'Domain-only catalog',
9661: codesrch => "Code search form",
9662: );
9663: my $itemcount = 0;
9664: foreach my $item (@catitems) {
9665: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9666: $datatable .= '<tr '.$css_class.'>'.
9667: '<td>'.$lt{$item}.'</td>'.
9668: '<td class="LC_right_item"><span class="LC_nobreak">';
9669: foreach my $type (@cattypes) {
9670: my $ischecked;
9671: if ($checked{$item} eq $type) {
9672: $ischecked=' checked="checked"';
9673: }
9674: $datatable .= '<label>'.
9675: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9676: ' />'.$lt{$type}.'</label> ';
9677: }
1.160.6.87 raeburn 9678: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 9679: $itemcount ++;
9680: }
9681: $$rowtotal += $itemcount;
9682: } elsif ($position eq 'middle') {
1.57 raeburn 9683: my $toggle_cats_crs = ' ';
9684: my $toggle_cats_dom = ' checked="checked" ';
9685: my $can_cat_crs = ' ';
9686: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9687: my $toggle_catscomm_comm = ' ';
9688: my $toggle_catscomm_dom = ' checked="checked" ';
9689: my $can_catcomm_comm = ' ';
9690: my $can_catcomm_dom = ' checked="checked" ';
9691:
1.57 raeburn 9692: if (ref($settings) eq 'HASH') {
9693: if ($settings->{'togglecats'} eq 'crs') {
9694: $toggle_cats_crs = $toggle_cats_dom;
9695: $toggle_cats_dom = ' ';
9696: }
9697: if ($settings->{'categorize'} eq 'crs') {
9698: $can_cat_crs = $can_cat_dom;
9699: $can_cat_dom = ' ';
9700: }
1.120 raeburn 9701: if ($settings->{'togglecatscomm'} eq 'comm') {
9702: $toggle_catscomm_comm = $toggle_catscomm_dom;
9703: $toggle_catscomm_dom = ' ';
9704: }
9705: if ($settings->{'categorizecomm'} eq 'comm') {
9706: $can_catcomm_comm = $can_catcomm_dom;
9707: $can_catcomm_dom = ' ';
9708: }
1.57 raeburn 9709: }
9710: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 9711: togglecats => 'Show/Hide a course in catalog',
9712: togglecatscomm => 'Show/Hide a community in catalog',
9713: categorize => 'Assign a category to a course',
9714: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9715: );
9716: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 9717: dom => 'Set in Domain',
9718: crs => 'Set in Course',
9719: comm => 'Set in Community',
1.57 raeburn 9720: );
9721: $datatable = '<tr class="LC_odd_row">'.
9722: '<td>'.$title{'togglecats'}.'</td>'.
9723: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9724: '<input type="radio" name="togglecats"'.
9725: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9726: '<label><input type="radio" name="togglecats"'.
9727: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9728: '</tr><tr>'.
9729: '<td>'.$title{'categorize'}.'</td>'.
9730: '<td class="LC_right_item"><span class="LC_nobreak">'.
9731: '<label><input type="radio" name="categorize"'.
9732: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9733: '<label><input type="radio" name="categorize"'.
9734: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9735: '</tr><tr class="LC_odd_row">'.
9736: '<td>'.$title{'togglecatscomm'}.'</td>'.
9737: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9738: '<input type="radio" name="togglecatscomm"'.
9739: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9740: '<label><input type="radio" name="togglecatscomm"'.
9741: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9742: '</tr><tr>'.
9743: '<td>'.$title{'categorizecomm'}.'</td>'.
9744: '<td class="LC_right_item"><span class="LC_nobreak">'.
9745: '<label><input type="radio" name="categorizecomm"'.
9746: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9747: '<label><input type="radio" name="categorizecomm"'.
9748: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 9749: '</tr>';
1.120 raeburn 9750: $$rowtotal += 4;
1.57 raeburn 9751: } else {
9752: my $css_class;
9753: my $itemcount = 1;
9754: my $cathash;
9755: if (ref($settings) eq 'HASH') {
9756: $cathash = $settings->{'cats'};
9757: }
9758: if (ref($cathash) eq 'HASH') {
9759: my (@cats,@trails,%allitems,%idx,@jsarray);
9760: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9761: \%allitems,\%idx,\@jsarray);
9762: my $maxdepth = scalar(@cats);
9763: my $colattrib = '';
9764: if ($maxdepth > 2) {
9765: $colattrib = ' colspan="2" ';
9766: }
9767: my @path;
9768: if (@cats > 0) {
9769: if (ref($cats[0]) eq 'ARRAY') {
9770: my $numtop = @{$cats[0]};
9771: my $maxnum = $numtop;
1.120 raeburn 9772: my %default_names = (
9773: instcode => &mt('Official courses'),
9774: communities => &mt('Communities'),
9775: );
9776:
9777: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9778: ($cathash->{'instcode::0'} eq '') ||
9779: (!grep(/^communities$/,@{$cats[0]})) ||
9780: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 9781: $maxnum ++;
9782: }
9783: my $lastidx;
9784: for (my $i=0; $i<$numtop; $i++) {
9785: my $parent = $cats[0][$i];
9786: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9787: my $item = &escape($parent).'::0';
9788: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9789: $lastidx = $idx{$item};
9790: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9791: .'<select name="'.$item.'"'.$chgstr.'>';
9792: for (my $k=0; $k<=$maxnum; $k++) {
9793: my $vpos = $k+1;
9794: my $selstr;
9795: if ($k == $i) {
9796: $selstr = ' selected="selected" ';
9797: }
9798: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9799: }
1.160.6.29 raeburn 9800: $datatable .= '</select></span></td><td>';
1.120 raeburn 9801: if ($parent eq 'instcode' || $parent eq 'communities') {
9802: $datatable .= '<span class="LC_nobreak">'
9803: .$default_names{$parent}.'</span>';
9804: if ($parent eq 'instcode') {
9805: $datatable .= '<br /><span class="LC_nobreak">('
9806: .&mt('with institutional codes')
9807: .')</span></td><td'.$colattrib.'>';
9808: } else {
9809: $datatable .= '<table><tr><td>';
9810: }
9811: $datatable .= '<span class="LC_nobreak">'
9812: .'<label><input type="radio" name="'
9813: .$parent.'" value="1" checked="checked" />'
9814: .&mt('Display').'</label>';
9815: if ($parent eq 'instcode') {
9816: $datatable .= ' ';
9817: } else {
9818: $datatable .= '</span></td></tr><tr><td>'
9819: .'<span class="LC_nobreak">';
9820: }
9821: $datatable .= '<label><input type="radio" name="'
9822: .$parent.'" value="0" />'
9823: .&mt('Do not display').'</label></span>';
9824: if ($parent eq 'communities') {
9825: $datatable .= '</td></tr></table>';
9826: }
9827: $datatable .= '</td>';
1.57 raeburn 9828: } else {
9829: $datatable .= $parent
1.160.6.29 raeburn 9830: .' <span class="LC_nobreak"><label>'
9831: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9832: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9833: }
9834: my $depth = 1;
9835: push(@path,$parent);
9836: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9837: pop(@path);
9838: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9839: $itemcount ++;
9840: }
1.48 raeburn 9841: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9842: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9843: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9844: for (my $k=0; $k<=$maxnum; $k++) {
9845: my $vpos = $k+1;
9846: my $selstr;
1.57 raeburn 9847: if ($k == $numtop) {
1.48 raeburn 9848: $selstr = ' selected="selected" ';
9849: }
9850: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9851: }
1.59 bisitz 9852: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9853: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9854: .'</tr>'."\n";
1.48 raeburn 9855: $itemcount ++;
1.120 raeburn 9856: foreach my $default ('instcode','communities') {
9857: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9858: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9859: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9860: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9861: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9862: for (my $k=0; $k<=$maxnum; $k++) {
9863: my $vpos = $k+1;
9864: my $selstr;
9865: if ($k == $maxnum) {
9866: $selstr = ' selected="selected" ';
9867: }
9868: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9869: }
1.120 raeburn 9870: $datatable .= '</select></span></td>'.
9871: '<td><span class="LC_nobreak">'.
9872: $default_names{$default}.'</span>';
9873: if ($default eq 'instcode') {
9874: $datatable .= '<br /><span class="LC_nobreak">('
9875: .&mt('with institutional codes').')</span>';
9876: }
9877: $datatable .= '</td>'
9878: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9879: .&mt('Display').'</label> '
9880: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9881: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9882: }
9883: }
9884: }
1.57 raeburn 9885: } else {
9886: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9887: }
9888: } else {
1.160.6.87 raeburn 9889: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9890: .&initialize_categories($itemcount);
1.48 raeburn 9891: }
1.57 raeburn 9892: $$rowtotal += $itemcount;
1.48 raeburn 9893: }
9894: return $datatable;
9895: }
9896:
1.69 raeburn 9897: sub print_serverstatuses {
9898: my ($dom,$settings,$rowtotal) = @_;
9899: my $datatable;
9900: my @pages = &serverstatus_pages();
9901: my (%namedaccess,%machineaccess);
9902: foreach my $type (@pages) {
9903: $namedaccess{$type} = '';
9904: $machineaccess{$type}= '';
9905: }
9906: if (ref($settings) eq 'HASH') {
9907: foreach my $type (@pages) {
9908: if (exists($settings->{$type})) {
9909: if (ref($settings->{$type}) eq 'HASH') {
9910: foreach my $key (keys(%{$settings->{$type}})) {
9911: if ($key eq 'namedusers') {
9912: $namedaccess{$type} = $settings->{$type}->{$key};
9913: } elsif ($key eq 'machines') {
9914: $machineaccess{$type} = $settings->{$type}->{$key};
9915: }
9916: }
9917: }
9918: }
9919: }
9920: }
1.81 raeburn 9921: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 9922: my $rownum = 0;
9923: my $css_class;
9924: foreach my $type (@pages) {
9925: $rownum ++;
9926: $css_class = $rownum%2?' class="LC_odd_row"':'';
9927: $datatable .= '<tr'.$css_class.'>'.
9928: '<td><span class="LC_nobreak">'.
9929: $titles->{$type}.'</span></td>'.
9930: '<td class="LC_left_item">'.
9931: '<input type="text" name="'.$type.'_namedusers" '.
9932: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
9933: '<td class="LC_right_item">'.
9934: '<span class="LC_nobreak">'.
9935: '<input type="text" name="'.$type.'_machines" '.
9936: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 9937: '</span></td></tr>'."\n";
1.69 raeburn 9938: }
9939: $$rowtotal += $rownum;
9940: return $datatable;
9941: }
9942:
9943: sub serverstatus_pages {
9944: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 9945: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 9946: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 9947: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 9948: }
9949:
1.160.6.40 raeburn 9950: sub defaults_javascript {
9951: my ($settings) = @_;
1.160.6.98 raeburn 9952: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 9953:23): my $portal_js = <<"ENDPORTAL";
9954:23):
9955:23): function portalExtras(caller) {
9956:23): var x = caller.value;
9957:23): var y = new Array('email','web');
9958:23): for (var i=0; i<y.length; i++) {
9959:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
9960:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
9961:23): if (x.length > 0) {
9962:23): z.style.display = 'block';
9963:23): } else {
9964:23): z.style.display = 'none';
9965:23): }
9966:23): }
9967:23): }
9968:23): }
9969:23): ENDPORTAL
1.160.6.40 raeburn 9970: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
9971: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
9972: if ($maxnum eq '') {
9973: $maxnum = 0;
9974: }
9975: $maxnum ++;
1.160.6.51 raeburn 9976: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 9977: return <<"ENDSCRIPT";
9978: <script type="text/javascript">
9979: // <![CDATA[
9980: function reorderTypes(form,caller) {
9981: var changedVal;
9982: $jstext
9983: var newpos = 'addinststatus_pos';
9984: var current = new Array;
9985: var maxh = $maxnum;
9986: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
9987: var oldVal;
9988: if (caller == newpos) {
9989: changedVal = newitemVal;
9990: } else {
9991: var curritem = 'inststatus_pos_'+caller;
9992: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
9993: current[newitemVal] = newpos;
9994: }
9995: for (var i=0; i<inststatuses.length; i++) {
9996: if (inststatuses[i] != caller) {
9997: var elementName = 'inststatus_pos_'+inststatuses[i];
9998: if (form.elements[elementName]) {
9999: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10000: current[currVal] = elementName;
10001: }
10002: }
10003: }
10004: for (var j=0; j<maxh; j++) {
10005: if (current[j] == undefined) {
10006: oldVal = j;
10007: }
10008: }
10009: if (oldVal < changedVal) {
10010: for (var k=oldVal+1; k<=changedVal ; k++) {
10011: var elementName = current[k];
10012: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10013: }
10014: } else {
10015: for (var k=changedVal; k<oldVal; k++) {
10016: var elementName = current[k];
10017: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10018: }
10019: }
10020: return;
10021: }
10022:
1.160.6.118.2 12(raebu 10023:23): $portal_js
10024:23):
10025:23): // ]]>
10026:23): </script>
10027:23):
10028:23): ENDSCRIPT
10029:23): } else {
10030:23): return <<"ENDSCRIPT";
10031:23): <script type="text/javascript">
10032:23): // <![CDATA[
10033:23): $portal_js
1.160.6.40 raeburn 10034: // ]]>
10035: </script>
10036:
10037: ENDSCRIPT
10038: }
1.160.6.118.2 14(raebu 10039:23): return;
1.160.6.40 raeburn 10040: }
10041:
1.160.6.98 raeburn 10042: sub passwords_javascript {
1.160.6.118.2 5(raebur 10043:2): my ($prefix) = @_;
10044:2): my %intalert;
10045:2): if ($prefix eq 'passwords') {
10046:2): %intalert = &Apache::lonlocal::texthash (
10047:2): authcheck => 'Warning: disallowing login for an authenticated user if the stored cost is less than the default will require a password reset by/for the user.',
10048:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10049:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10050:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10051:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10052:2): );
14(raebu 10053:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 10054:2): %intalert = &Apache::lonlocal::texthash (
10055:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10056:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10057:2): );
10058:2): }
1.160.6.99 raeburn 10059: &js_escape(\%intalert);
10060: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 10061:2): my $intauthjs;
10062:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 10063:
10064: function warnIntAuth(field) {
10065: if (field.name == 'intauth_check') {
10066: if (field.value == '2') {
1.160.6.99 raeburn 10067: alert('$intalert{authcheck}');
1.160.6.98 raeburn 10068: }
10069: }
10070: if (field.name == 'intauth_cost') {
10071: field.value.replace(/\s/g,'');
10072: if (field.value != '') {
10073: var regexdigit=/^\\d+\$/;
10074: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 10075: alert('$intalert{authcost}');
10076: }
10077: }
10078: }
10079: return;
10080: }
10081:
1.160.6.118.2 5(raebur 10082:2): ENDSCRIPT
10083:2):
10084:2): }
10085:2):
10086:2): $intauthjs .= <<"ENDSCRIPT";
10087:2):
10088:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 10089: field.value.replace(/^\s+/,'');
10090: field.value.replace(/\s+\$/,'');
10091: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 10092:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 10093: if (field.value == '') {
10094: alert('$intalert{passmin}');
10095: field.value = '$defmin';
10096: } else {
10097: if (!regexdigit.test(field.value)) {
10098: alert('$intalert{passmin}');
10099: field.value = '$defmin';
10100: }
10101: var minval = parseInt(field.value,10);
10102: if (minval < $defmin) {
10103: alert('$intalert{passmin}');
10104: field.value = '$defmin';
10105: }
10106: }
10107: } else {
10108: if (field.value == '0') {
10109: field.value = '';
10110: }
10111: if (field.value != '') {
1.160.6.118.2 5(raebur 10112:2): if (!regexdigit.test(field.value)) {
10113:2): if (field.name == '${prefix}_max') {
10114:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 10115: } else {
1.160.6.118.2 5(raebur 10116:2): if (field.name == '${prefix}_numsaved') {
10117:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 10118: }
10119: }
1.160.6.118.2 5(raebur 10120:2): field.value = '';
1.160.6.98 raeburn 10121: }
10122: }
10123: }
10124: return;
10125: }
10126:
10127: ENDSCRIPT
10128: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10129: }
10130:
1.49 raeburn 10131: sub coursecategories_javascript {
10132: my ($settings) = @_;
1.57 raeburn 10133: my ($output,$jstext,$cathash);
1.49 raeburn 10134: if (ref($settings) eq 'HASH') {
1.57 raeburn 10135: $cathash = $settings->{'cats'};
10136: }
10137: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10138: my (@cats,@jsarray,%idx);
1.57 raeburn 10139: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10140: if (@jsarray > 0) {
10141: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10142: for (my $i=0; $i<@jsarray; $i++) {
10143: if (ref($jsarray[$i]) eq 'ARRAY') {
10144: my $catstr = join('","',@{$jsarray[$i]});
10145: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10146: }
10147: }
10148: }
10149: } else {
10150: $jstext = ' var categories = Array(1);'."\n".
10151: ' categories[0] = Array("instcode_pos");'."\n";
10152: }
1.160.6.42 raeburn 10153: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10154: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 10155: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10156: &js_escape(\$instcode_reserved);
10157: &js_escape(\$communities_reserved);
10158: &js_escape(\$choose_again);
1.49 raeburn 10159: $output = <<"ENDSCRIPT";
10160: <script type="text/javascript">
1.109 raeburn 10161: // <![CDATA[
1.49 raeburn 10162: function reorderCats(form,parent,item,idx) {
10163: var changedVal;
10164: $jstext
10165: var newpos = 'addcategory_pos';
10166: if (parent == '') {
10167: var has_instcode = 0;
10168: var maxtop = categories[idx].length;
10169: for (var j=0; j<maxtop; j++) {
10170: if (categories[idx][j] == 'instcode::0') {
10171: has_instcode == 1;
10172: }
10173: }
10174: if (has_instcode == 0) {
10175: categories[idx][maxtop] = 'instcode_pos';
10176: }
10177: } else {
10178: newpos += '_'+parent;
10179: }
10180: var maxh = 1 + categories[idx].length;
10181: var current = new Array;
10182: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10183: if (item == newpos) {
10184: changedVal = newitemVal;
10185: } else {
10186: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10187: current[newitemVal] = newpos;
10188: }
10189: for (var i=0; i<categories[idx].length; i++) {
10190: var elementName = categories[idx][i];
10191: if (elementName != item) {
10192: if (form.elements[elementName]) {
10193: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10194: current[currVal] = elementName;
10195: }
10196: }
10197: }
10198: var oldVal;
10199: for (var j=0; j<maxh; j++) {
10200: if (current[j] == undefined) {
10201: oldVal = j;
10202: }
10203: }
10204: if (oldVal < changedVal) {
10205: for (var k=oldVal+1; k<=changedVal ; k++) {
10206: var elementName = current[k];
10207: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10208: }
10209: } else {
10210: for (var k=changedVal; k<oldVal; k++) {
10211: var elementName = current[k];
10212: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10213: }
10214: }
10215: return;
10216: }
1.120 raeburn 10217:
10218: function categoryCheck(form) {
10219: if (form.elements['addcategory_name'].value == 'instcode') {
10220: alert('$instcode_reserved\\n$choose_again');
10221: return false;
10222: }
10223: if (form.elements['addcategory_name'].value == 'communities') {
10224: alert('$communities_reserved\\n$choose_again');
10225: return false;
10226: }
10227: return true;
10228: }
10229:
1.109 raeburn 10230: // ]]>
1.49 raeburn 10231: </script>
10232:
10233: ENDSCRIPT
10234: return $output;
10235: }
10236:
1.48 raeburn 10237: sub initialize_categories {
10238: my ($itemcount) = @_;
1.120 raeburn 10239: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 10240: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10241: instcode => 'Official courses (with institutional codes)',
10242: communities => 'Communities',
10243: );
10244: my $select0 = ' selected="selected"';
10245: my $select1 = '';
10246: foreach my $default ('instcode','communities') {
10247: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 10248: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 10249: if ($default eq 'communities') {
10250: $select1 = $select0;
10251: $select0 = '';
10252: }
10253: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10254: .'<select name="'.$default.'_pos">'
10255: .'<option value="0"'.$select0.'>1</option>'
10256: .'<option value="1"'.$select1.'>2</option>'
10257: .'<option value="2">3</option></select> '
10258: .$default_names{$default}
10259: .'</span></td><td><span class="LC_nobreak">'
10260: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10261: .&mt('Display').'</label> <label>'
10262: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10263: .'</label></span></td></tr>';
1.120 raeburn 10264: $itemcount ++;
10265: }
1.48 raeburn 10266: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10267: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10268: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10269: .'<select name="addcategory_pos"'.$chgstr.'>'
10270: .'<option value="0">1</option>'
10271: .'<option value="1">2</option>'
10272: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 10273: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 10274: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10275: .'</td></tr>';
1.48 raeburn 10276: return $datatable;
10277: }
10278:
10279: sub build_category_rows {
1.49 raeburn 10280: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10281: my ($text,$name,$item,$chgstr);
1.48 raeburn 10282: if (ref($cats) eq 'ARRAY') {
10283: my $maxdepth = scalar(@{$cats});
10284: if (ref($cats->[$depth]) eq 'HASH') {
10285: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10286: my $numchildren = @{$cats->[$depth]{$parent}};
10287: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 10288: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10289: my ($idxnum,$parent_name,$parent_item);
10290: my $higher = $depth - 1;
10291: if ($higher == 0) {
10292: $parent_name = &escape($parent).'::'.$higher;
10293: } else {
10294: if (ref($path) eq 'ARRAY') {
10295: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10296: }
10297: }
10298: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10299: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10300: if ($j < $numchildren) {
1.48 raeburn 10301: $name = $cats->[$depth]{$parent}[$j];
10302: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10303: $idxnum = $idx->{$item};
10304: } else {
10305: $name = $parent_name;
10306: $item = $parent_item;
1.48 raeburn 10307: }
1.49 raeburn 10308: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10309: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10310: for (my $i=0; $i<=$numchildren; $i++) {
10311: my $vpos = $i+1;
10312: my $selstr;
10313: if ($j == $i) {
10314: $selstr = ' selected="selected" ';
10315: }
10316: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10317: }
10318: $text .= '</select> ';
10319: if ($j < $numchildren) {
10320: my $deeper = $depth+1;
10321: $text .= $name.' '
10322: .'<label><input type="checkbox" name="deletecategory" value="'
10323: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10324: if(ref($path) eq 'ARRAY') {
10325: push(@{$path},$name);
1.49 raeburn 10326: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10327: pop(@{$path});
10328: }
10329: } else {
1.160.6.87 raeburn 10330: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10331: if ($j == $numchildren) {
10332: $text .= $name;
10333: } else {
10334: $text .= $item;
10335: }
10336: $text .= '" value="" />';
10337: }
10338: $text .= '</td></tr>';
10339: }
10340: $text .= '</table></td>';
10341: } else {
10342: my $higher = $depth-1;
10343: if ($higher == 0) {
10344: $name = &escape($parent).'::'.$higher;
10345: } else {
10346: if (ref($path) eq 'ARRAY') {
10347: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10348: }
10349: }
10350: my $colspan;
10351: if ($parent ne 'instcode') {
10352: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 10353: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10354: }
10355: }
10356: }
10357: }
10358: return $text;
10359: }
10360:
1.33 raeburn 10361: sub modifiable_userdata_row {
1.160.6.93 raeburn 10362: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.160.6.118.2 14(raebu 10363:23): $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.160.6.35 raeburn 10364: my ($role,$rolename,$statustype);
10365: $role = $item;
1.160.6.34 raeburn 10366: if ($context eq 'cancreate') {
1.160.6.93 raeburn 10367: if ($item =~ /^(emailusername)_(.+)$/) {
10368: $role = $1;
10369: $statustype = $2;
1.160.6.35 raeburn 10370: if (ref($usertypes) eq 'HASH') {
10371: if ($usertypes->{$statustype}) {
10372: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10373: } else {
10374: $rolename = &mt('Data provided by user');
10375: }
10376: }
1.160.6.34 raeburn 10377: }
10378: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10379: if (ref($usertypes) eq 'HASH') {
10380: $rolename = $usertypes->{$role};
10381: } else {
10382: $rolename = $role;
10383: }
1.160.6.118.2 14(raebu 10384:23): } elsif ($context eq 'lti') {
10385:23): $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 10386: } else {
1.63 raeburn 10387: if ($role eq 'cr') {
10388: $rolename = &mt('Custom role');
10389: } else {
10390: $rolename = &Apache::lonnet::plaintext($role);
10391: }
1.33 raeburn 10392: }
1.160.6.34 raeburn 10393: my (@fields,%fieldtitles);
10394: if (ref($fieldsref) eq 'ARRAY') {
10395: @fields = @{$fieldsref};
10396: } else {
10397: @fields = ('lastname','firstname','middlename','generation',
10398: 'permanentemail','id');
10399: }
10400: if ((ref($titlesref) eq 'HASH')) {
10401: %fieldtitles = %{$titlesref};
10402: } else {
10403: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10404: }
1.33 raeburn 10405: my $output;
1.160.6.93 raeburn 10406: my $css_class;
10407: if ($rowcount%2) {
10408: $css_class = 'LC_odd_row';
10409: }
10410: if ($customcss) {
10411: $css_class .= " $customcss";
10412: }
10413: $css_class =~ s/^\s+//;
10414: if ($css_class) {
10415: $css_class = ' class="'.$css_class.'"';
10416: }
10417: if ($rowstyle) {
10418: $css_class .= ' style="'.$rowstyle.'"';
10419: }
10420: if ($rowid) {
10421: $rowid = ' id="'.$rowid.'"';
10422: }
10423: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10424: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10425: '<td class="LC_left_item" colspan="2"><table>';
10426: my $rem;
10427: my %checks;
10428: if (ref($settings) eq 'HASH') {
1.160.6.118.2 14(raebu 10429:23): my $hashref;
10430:23): if ($context eq 'lti') {
10431:23): if (ref($settings) eq 'HASH') {
10432:23): $hashref = $settings->{'instdata'};
10433:23): }
10434:23): } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10435: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.118.2 14(raebu 10436:23): $hashref = $settings->{'lti_instdata'};
10437:23): }
10438:23): if ($role eq 'emailusername') {
10439:23): if ($statustype) {
10440:23): if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10441:23): $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.35 raeburn 10442: }
1.160.6.118.2 14(raebu 10443:23): }
10444:23): }
10445:23): }
10446:23): if (ref($hashref) eq 'HASH') {
10447:23): foreach my $field (@fields) {
10448:23): if ($hashref->{$field}) {
10449:23): if ($role eq 'emailusername') {
10450:23): $checks{$field} = $hashref->{$field};
10451:23): } else {
10452:23): $checks{$field} = ' checked="checked" ';
1.33 raeburn 10453: }
10454: }
10455: }
10456: }
10457: }
1.160.6.93 raeburn 10458: my $total = scalar(@fields);
10459: for (my $i=0; $i<$total; $i++) {
10460: $rem = $i%($numinrow);
1.33 raeburn 10461: if ($rem == 0) {
10462: if ($i > 0) {
10463: $output .= '</tr>';
10464: }
10465: $output .= '<tr>';
10466: }
10467: my $check = ' ';
1.160.6.35 raeburn 10468: unless ($role eq 'emailusername') {
10469: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 10470: $check = $checks{$fields[$i]};
1.160.6.118.2 14(raebu 10471:23): } elsif ($context ne 'lti') {
1.160.6.35 raeburn 10472: if ($role eq 'st') {
10473: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 10474: $check = ' checked="checked" ';
1.160.6.35 raeburn 10475: }
1.33 raeburn 10476: }
10477: }
10478: }
10479: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 10480: '<span class="LC_nobreak">';
1.160.6.118.2 14(raebu 10481:23): my $prefix = 'canmodify';
1.160.6.35 raeburn 10482: if ($role eq 'emailusername') {
10483: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10484: $checks{$fields[$i]} = 'omit';
10485: }
10486: foreach my $option ('required','optional','omit') {
10487: my $checked='';
10488: if ($checks{$fields[$i]} eq $option) {
10489: $checked='checked="checked" ';
10490: }
10491: $output .= '<label>'.
1.160.6.118.2 14(raebu 10492:23): '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.160.6.35 raeburn 10493: &mt($option).'</label>'.(' ' x2);
10494: }
10495: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10496: } else {
1.160.6.118.2 14(raebu 10497:23): if ($context eq 'lti') {
10498:23): $prefix = 'lti';
10499:23): }
1.160.6.35 raeburn 10500: $output .= '<label>'.
1.160.6.118.2 14(raebu 10501:23): '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.160.6.35 raeburn 10502: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10503: '</label>';
10504: }
10505: $output .= '</span></td>';
1.33 raeburn 10506: }
1.160.6.93 raeburn 10507: $rem = $total%$numinrow;
10508: my $colsleft;
10509: if ($rem) {
10510: $colsleft = $numinrow - $rem;
10511: }
10512: if ($colsleft > 1) {
1.33 raeburn 10513: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10514: ' </td>';
10515: } elsif ($colsleft == 1) {
10516: $output .= '<td class="LC_left_item"> </td>';
10517: }
10518: $output .= '</tr></table></td></tr>';
10519: return $output;
10520: }
1.28 raeburn 10521:
1.93 raeburn 10522: sub insttypes_row {
1.160.6.93 raeburn 10523: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10524: $customcss,$rowstyle) = @_;
1.93 raeburn 10525: my %lt = &Apache::lonlocal::texthash (
10526: cansearch => 'Users allowed to search',
10527: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 10528: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 10529: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 10530: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 10531: );
10532: my $showdom;
10533: if ($context eq 'cansearch') {
10534: $showdom = ' ('.$dom.')';
10535: }
1.160.6.5 raeburn 10536: my $class = 'LC_left_item';
10537: if ($context eq 'statustocreate') {
10538: $class = 'LC_right_item';
10539: }
1.160.6.93 raeburn 10540: my $css_class;
10541: if ($$rowtotal%2) {
10542: $css_class = 'LC_odd_row';
10543: }
10544: if ($customcss) {
10545: $css_class .= ' '.$customcss;
10546: }
10547: $css_class =~ s/^\s+//;
10548: if ($css_class) {
10549: $css_class = ' class="'.$css_class.'"';
10550: }
10551: if ($rowstyle) {
10552: $css_class .= ' style="'.$rowstyle.'"';
10553: }
10554: if ($onclick) {
10555: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 10556: }
10557: my $output = '<tr'.$css_class.'>'.
10558: '<td>'.$lt{$context}.$showdom.
10559: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10560: my $rem;
10561: if (ref($types) eq 'ARRAY') {
10562: for (my $i=0; $i<@{$types}; $i++) {
10563: if (defined($usertypes->{$types->[$i]})) {
10564: my $rem = $i%($numinrow);
10565: if ($rem == 0) {
10566: if ($i > 0) {
10567: $output .= '</tr>';
10568: }
10569: $output .= '<tr>';
1.23 raeburn 10570: }
1.26 raeburn 10571: my $check = ' ';
1.99 raeburn 10572: if (ref($settings) eq 'HASH') {
10573: if (ref($settings->{$context}) eq 'ARRAY') {
10574: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10575: $check = ' checked="checked" ';
10576: }
1.160.6.101 raeburn 10577: } elsif (ref($settings->{$context}) eq 'HASH') {
10578: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10579: $check = ' checked="checked" ';
10580: }
1.99 raeburn 10581: } elsif ($context eq 'statustocreate') {
1.26 raeburn 10582: $check = ' checked="checked" ';
10583: }
1.23 raeburn 10584: }
1.26 raeburn 10585: $output .= '<td class="LC_left_item">'.
10586: '<span class="LC_nobreak"><label>'.
1.93 raeburn 10587: '<input type="checkbox" name="'.$context.'" '.
1.160.6.118.2 14(raebu 10588:23): 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 10589: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10590: }
10591: }
1.26 raeburn 10592: $rem = @{$types}%($numinrow);
1.23 raeburn 10593: }
10594: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 10595: if ($context eq 'overrides') {
10596: if ($colsleft > 1) {
10597: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10598: } else {
10599: $output .= '<td class="LC_left_item">';
10600: }
10601: $output .= ' ';
1.23 raeburn 10602: } else {
1.160.6.101 raeburn 10603: if ($rem == 0) {
10604: $output .= '<tr>';
10605: }
10606: if ($colsleft > 1) {
10607: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10608: } else {
10609: $output .= '<td class="LC_left_item">';
10610: }
10611: my $defcheck = ' ';
10612: if (ref($settings) eq 'HASH') {
10613: if (ref($settings->{$context}) eq 'ARRAY') {
10614: if (grep(/^default$/,@{$settings->{$context}})) {
10615: $defcheck = ' checked="checked" ';
10616: }
10617: } elsif ($context eq 'statustocreate') {
1.99 raeburn 10618: $defcheck = ' checked="checked" ';
10619: }
1.26 raeburn 10620: }
1.160.6.101 raeburn 10621: $output .= '<span class="LC_nobreak"><label>'.
10622: '<input type="checkbox" name="'.$context.'" '.
10623: 'value="default"'.$defcheck.$onclick.' />'.
10624: $othertitle.'</label></span>';
1.23 raeburn 10625: }
1.160.6.101 raeburn 10626: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 10627: return $output;
1.23 raeburn 10628: }
10629:
10630: sub sorted_searchtitles {
10631: my %searchtitles = &Apache::lonlocal::texthash(
10632: 'uname' => 'username',
10633: 'lastname' => 'last name',
10634: 'lastfirst' => 'last name, first name',
10635: );
10636: my @titleorder = ('uname','lastname','lastfirst');
10637: return (\%searchtitles,\@titleorder);
10638: }
10639:
1.25 raeburn 10640: sub sorted_searchtypes {
10641: my %srchtypes_desc = (
10642: exact => 'is exact match',
10643: contains => 'contains ..',
10644: begins => 'begins with ..',
10645: );
10646: my @srchtypeorder = ('exact','begins','contains');
10647: return (\%srchtypes_desc,\@srchtypeorder);
10648: }
10649:
1.3 raeburn 10650: sub usertype_update_row {
10651: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10652: my $datatable;
10653: my $numinrow = 4;
10654: foreach my $type (@{$types}) {
10655: if (defined($usertypes->{$type})) {
10656: $$rownums ++;
10657: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10658: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10659: '</td><td class="LC_left_item"><table>';
10660: for (my $i=0; $i<@{$fields}; $i++) {
10661: my $rem = $i%($numinrow);
10662: if ($rem == 0) {
10663: if ($i > 0) {
10664: $datatable .= '</tr>';
10665: }
10666: $datatable .= '<tr>';
10667: }
10668: my $check = ' ';
1.39 raeburn 10669: if (ref($settings) eq 'HASH') {
10670: if (ref($settings->{'fields'}) eq 'HASH') {
10671: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10672: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10673: $check = ' checked="checked" ';
10674: }
1.3 raeburn 10675: }
10676: }
10677: }
10678:
10679: if ($i == @{$fields}-1) {
10680: my $colsleft = $numinrow - $rem;
10681: if ($colsleft > 1) {
10682: $datatable .= '<td colspan="'.$colsleft.'">';
10683: } else {
10684: $datatable .= '<td>';
10685: }
10686: } else {
10687: $datatable .= '<td>';
10688: }
1.8 raeburn 10689: $datatable .= '<span class="LC_nobreak"><label>'.
10690: '<input type="checkbox" name="updateable_'.$type.
10691: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10692: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 10693: }
10694: $datatable .= '</tr></table></td></tr>';
10695: }
10696: }
10697: return $datatable;
1.1 raeburn 10698: }
10699:
10700: sub modify_login {
1.160.6.24 raeburn 10701: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 10702: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 10703: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 10704:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 10705: %title = ( coursecatalog => 'Display course catalog',
10706: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 10707: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 10708: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 10709: loginheader => 'Log-in box header',
10710: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 10711: @offon = ('off','on');
1.112 raeburn 10712: if (ref($domconfig{login}) eq 'HASH') {
10713: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10714: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10715: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10716: }
10717: }
1.160.6.113 raeburn 10718: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10719: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10720: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10721: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10722: $saml{$lonhost} = 1;
10723: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10724: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10725: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10726: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10727: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 10728:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 10729: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10730: }
10731: }
10732: }
1.112 raeburn 10733: }
1.9 raeburn 10734: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10735: \%domconfig,\%loginhash);
1.160.6.14 raeburn 10736: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10737: foreach my $item (@toggles) {
10738: $loginhash{login}{$item} = $env{'form.'.$item};
10739: }
1.41 raeburn 10740: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10741: if (ref($colchanges{'login'}) eq 'HASH') {
10742: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10743: \%loginhash);
10744: }
1.110 raeburn 10745:
1.149 raeburn 10746: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 10747: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10748: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10749: if (keys(%servers) > 1) {
10750: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10751: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10752: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10753: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10754: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10755: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10756: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10757: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10758: $changes{'loginvia'}{$lonhost} = 1;
10759: } else {
10760: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10761: $changes{'loginvia'}{$lonhost} = 1;
10762: }
10763: } else {
10764: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10765: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10766: $changes{'loginvia'}{$lonhost} = 1;
10767: }
10768: }
10769: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10770: foreach my $item (@loginvia_attribs) {
10771: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10772: }
10773: } else {
10774: foreach my $item (@loginvia_attribs) {
10775: my $new = $env{'form.'.$lonhost.'_'.$item};
10776: if (($item eq 'serverpath') && ($new eq 'custom')) {
10777: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10778: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10779: $new = '/';
10780: }
10781: }
10782: if (($item eq 'custompath') &&
10783: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10784: $new = '';
10785: }
10786: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10787: $changes{'loginvia'}{$lonhost} = 1;
10788: }
10789: if ($item eq 'exempt') {
1.160.6.56 raeburn 10790: $new = &check_exempt_addresses($new);
1.128 raeburn 10791: }
10792: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10793: }
10794: }
1.112 raeburn 10795: } else {
1.128 raeburn 10796: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10797: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 10798: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 10799: foreach my $item (@loginvia_attribs) {
10800: my $new = $env{'form.'.$lonhost.'_'.$item};
10801: if (($item eq 'serverpath') && ($new eq 'custom')) {
10802: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10803: $new = '/';
10804: }
10805: }
10806: if (($item eq 'custompath') &&
10807: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10808: $new = '';
10809: }
10810: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10811: }
1.110 raeburn 10812: }
10813: }
10814: }
10815: }
1.119 raeburn 10816:
1.160.6.5 raeburn 10817: my $servadm = $r->dir_config('lonAdmEMail');
10818: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10819: if (ref($domconfig{'login'}) eq 'HASH') {
10820: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10821: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10822: if ($lang eq 'nolang') {
10823: push(@currlangs,$lang);
10824: } elsif (defined($langchoices{$lang})) {
10825: push(@currlangs,$lang);
10826: } else {
10827: next;
10828: }
10829: }
10830: }
10831: }
10832: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10833: if (@currlangs > 0) {
10834: foreach my $lang (@currlangs) {
10835: if (grep(/^\Q$lang\E$/,@delurls)) {
10836: $changes{'helpurl'}{$lang} = 1;
10837: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10838: $changes{'helpurl'}{$lang} = 1;
10839: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10840: push(@newlangs,$lang);
10841: } else {
10842: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10843: }
10844: }
10845: }
10846: unless (grep(/^nolang$/,@currlangs)) {
10847: if ($env{'form.loginhelpurl_nolang.filename'}) {
10848: $changes{'helpurl'}{'nolang'} = 1;
10849: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10850: push(@newlangs,'nolang');
10851: }
10852: }
10853: if ($env{'form.loginhelpurl_add_lang'}) {
10854: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10855: ($env{'form.loginhelpurl_add_file.filename'})) {
10856: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10857: $addedfile = $env{'form.loginhelpurl_add_lang'};
10858: }
10859: }
10860: if ((@newlangs > 0) || ($addedfile)) {
10861: my $error;
10862: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10863: if ($configuserok eq 'ok') {
10864: if ($switchserver) {
10865: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10866: } elsif ($author_ok eq 'ok') {
10867: my @allnew = @newlangs;
10868: if ($addedfile ne '') {
10869: push(@allnew,$addedfile);
10870: }
1.160.6.118.2 14(raebu 10871:23): my $modified = [];
1.160.6.5 raeburn 10872: foreach my $lang (@allnew) {
10873: my $formelem = 'loginhelpurl_'.$lang;
10874: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10875: $formelem = 'loginhelpurl_add_file';
10876: }
1.160.6.118.2 14(raebu 10877:23): (my $result,$newurl{$lang}) =
10878:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
10879:23): "help/$lang",'','',$newfile{$lang},
10880:23): $modified);
1.160.6.5 raeburn 10881: if ($result eq 'ok') {
10882: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10883: $changes{'helpurl'}{$lang} = 1;
10884: } else {
10885: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10886: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10887: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10888: (!grep(/^\Q$lang\E$/,@delurls))) {
10889: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10890: }
10891: }
10892: }
1.160.6.118.2 14(raebu 10893:23): &update_modify_urls($r,$modified);
1.160.6.5 raeburn 10894: } else {
10895: $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);
10896: }
10897: } else {
10898: $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);
10899: }
10900: if ($error) {
10901: &Apache::lonnet::logthis($error);
10902: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10903: }
10904: }
1.160.6.56 raeburn 10905:
10906: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10907: if (ref($domconfig{'login'}) eq 'HASH') {
10908: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10909: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10910: if ($domservers{$lonhost}) {
10911: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10912: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 10913: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 10914: }
10915: }
10916: }
10917: }
10918: }
10919: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10920: foreach my $lonhost (sort(keys(%domservers))) {
10921: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
10922: $changes{'headtag'}{$lonhost} = 1;
10923: } else {
10924: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
10925: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
10926: }
10927: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
10928: push(@newhosts,$lonhost);
10929: } elsif ($currheadtagurls{$lonhost}) {
10930: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
10931: if ($currexempt{$lonhost}) {
10932: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
10933: $changes{'headtag'}{$lonhost} = 1;
10934: }
10935: } elsif ($possexempt{$lonhost}) {
10936: $changes{'headtag'}{$lonhost} = 1;
10937: }
10938: if ($possexempt{$lonhost}) {
10939: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10940: }
10941: }
10942: }
10943: }
10944: if (@newhosts) {
10945: my $error;
10946: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10947: if ($configuserok eq 'ok') {
10948: if ($switchserver) {
10949: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
10950: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 10951:23): my $modified = [];
1.160.6.56 raeburn 10952: foreach my $lonhost (@newhosts) {
10953: my $formelem = 'loginheadtag_'.$lonhost;
1.160.6.118.2 14(raebu 10954:23): (my $result,$newheadtagurls{$lonhost}) =
10955:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
10956:23): "login/headtag/$lonhost",'','',
10957:23): $env{'form.loginheadtag_'.$lonhost.'.filename'},
10958:23): $modified);
1.160.6.56 raeburn 10959: if ($result eq 'ok') {
1.160.6.113 raeburn 10960: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
10961: $changes{'headtag'}{$lonhost} = 1;
10962: if ($possexempt{$lonhost}) {
10963: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
10964: }
10965: } else {
10966: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
10967: $newheadtagurls{$lonhost},$result);
10968: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10969: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
10970: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
10971: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
10972: }
10973: }
10974: }
1.160.6.118.2 14(raebu 10975:23): &update_modify_urls($r,$modified);
1.160.6.113 raeburn 10976: } else {
10977: $error = &mt("Upload of custom markup 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);
10978: }
10979: } else {
10980: $error = &mt("Upload of custom markup file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
10981: }
10982: if ($error) {
10983: &Apache::lonnet::logthis($error);
10984: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10985: }
10986: }
10987: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
10988: my @newsamlimgs;
10989: foreach my $lonhost (keys(%domservers)) {
10990: if ($env{'form.saml_'.$lonhost}) {
10991: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
10992: push(@newsamlimgs,$lonhost);
10993: }
1.160.6.118.2 9(raebur 10994:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 10995: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
10996: }
10997: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 10998:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
10999:2): $env{'form.saml_window_'.$lonhost} = '';
11000:2): }
1.160.6.113 raeburn 11001: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11002: #FIXME Need to obsolete published image
11003: delete($currsaml{$lonhost}{'img'});
11004: $changes{'saml'}{$lonhost} = 1;
11005: }
11006: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11007: $changes{'saml'}{$lonhost} = 1;
11008: }
11009: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11010: $changes{'saml'}{$lonhost} = 1;
11011: }
11012: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11013: $changes{'saml'}{$lonhost} = 1;
11014: }
11015: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11016: $changes{'saml'}{$lonhost} = 1;
11017: }
1.160.6.118.2 9(raebur 11018:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11019:2): $changes{'saml'}{$lonhost} = 1;
11020:2): }
1.160.6.113 raeburn 11021: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11022: $changes{'saml'}{$lonhost} = 1;
11023: }
11024: } else {
11025: $changes{'saml'}{$lonhost} = 1;
11026: }
1.160.6.118.2 9(raebur 11027:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11028: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11029: }
11030: } else {
11031: if ($saml{$lonhost}) {
11032: $changes{'saml'}{$lonhost} = 1;
11033: delete($currsaml{$lonhost});
11034: }
11035: }
11036: }
11037: foreach my $posshost (keys(%currsaml)) {
11038: unless (exists($domservers{$posshost})) {
11039: delete($currsaml{$posshost});
11040: }
11041: }
11042: %{$loginhash{'login'}{'saml'}} = %currsaml;
11043: if (@newsamlimgs) {
11044: my $error;
11045: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11046: if ($configuserok eq 'ok') {
11047: if ($switchserver) {
11048: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11049: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11050:23): my $modified = [];
1.160.6.113 raeburn 11051: foreach my $lonhost (@newsamlimgs) {
11052: my $formelem = 'saml_img_'.$lonhost;
1.160.6.118.2 14(raebu 11053:23): my ($result,$imgurl) =
11054:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11055:23): "login/saml/$lonhost",'','',
11056:23): $env{'form.saml_img_'.$lonhost.'.filename'},
11057:23): $modified);
1.160.6.113 raeburn 11058: if ($result eq 'ok') {
11059: $currsaml{$lonhost}{'img'} = $imgurl;
11060: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11061: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 11062: } else {
1.160.6.113 raeburn 11063: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11064: $lonhost,$result);
1.160.6.56 raeburn 11065: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11066: }
11067: }
1.160.6.118.2 14(raebu 11068:23): &update_modify_urls($r,$modified);
1.160.6.56 raeburn 11069: } else {
1.160.6.113 raeburn 11070: $error = &mt("Upload of SSO button image 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);
1.160.6.56 raeburn 11071: }
11072: } else {
1.160.6.113 raeburn 11073: $error = &mt("Upload of SSO button image file(s) failed because a Domain Configuration user ([_1]) could not be created in domain: [_2]. Error was: [_3].",$confname,$dom,$configuserok);
1.160.6.56 raeburn 11074: }
11075: if ($error) {
11076: &Apache::lonnet::logthis($error);
11077: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11078: }
11079: }
1.160.6.5 raeburn 11080: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11081:
11082: my $defaulthelpfile = '/adm/loginproblems.html';
11083: my $defaulttext = &mt('Default in use');
11084:
1.1 raeburn 11085: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11086: $dom);
11087: if ($putresult eq 'ok') {
1.160.6.14 raeburn 11088: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11089: my %defaultchecked = (
11090: 'coursecatalog' => 'on',
1.160.6.14 raeburn 11091: 'helpdesk' => 'on',
1.42 raeburn 11092: 'adminmail' => 'off',
1.43 raeburn 11093: 'newuser' => 'off',
1.42 raeburn 11094: );
1.55 raeburn 11095: if (ref($domconfig{'login'}) eq 'HASH') {
11096: foreach my $item (@toggles) {
11097: if ($defaultchecked{$item} eq 'on') {
11098: if (($domconfig{'login'}{$item} eq '0') &&
11099: ($env{'form.'.$item} eq '1')) {
11100: $changes{$item} = 1;
11101: } elsif (($domconfig{'login'}{$item} eq '' ||
11102: $domconfig{'login'}{$item} eq '1') &&
11103: ($env{'form.'.$item} eq '0')) {
11104: $changes{$item} = 1;
11105: }
11106: } elsif ($defaultchecked{$item} eq 'off') {
11107: if (($domconfig{'login'}{$item} eq '1') &&
11108: ($env{'form.'.$item} eq '0')) {
11109: $changes{$item} = 1;
11110: } elsif (($domconfig{'login'}{$item} eq '' ||
11111: $domconfig{'login'}{$item} eq '0') &&
11112: ($env{'form.'.$item} eq '1')) {
11113: $changes{$item} = 1;
11114: }
1.42 raeburn 11115: }
11116: }
1.41 raeburn 11117: }
1.6 raeburn 11118: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11119: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 11120: if (exists($changes{'saml'})) {
11121: my $hostid_in_use;
11122: my @hosts = &Apache::lonnet::current_machine_ids();
11123: if (@hosts > 1) {
11124: foreach my $hostid (@hosts) {
11125: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11126: $hostid_in_use = $hostid;
11127: last;
11128: }
11129: }
11130: } else {
11131: $hostid_in_use = $r->dir_config('lonHostID');
11132: }
11133: if (($hostid_in_use) &&
11134: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11135: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11136: }
11137: if (ref($lastactref) eq 'HASH') {
11138: if (ref($changes{'saml'}) eq 'HASH') {
11139: my %updates;
11140: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11141: $lastactref->{'samllanding'} = \%updates;
11142: }
11143: }
11144: }
1.160.6.27 raeburn 11145: if (ref($lastactref) eq 'HASH') {
11146: $lastactref->{'domainconfig'} = 1;
11147: }
1.1 raeburn 11148: $resulttext = &mt('Changes made:').'<ul>';
11149: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11150: if ($item eq 'loginvia') {
1.112 raeburn 11151: if (ref($changes{$item}) eq 'HASH') {
11152: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11153: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11154: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11155: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11156: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11157: $protocol = 'http' if ($protocol ne 'https');
11158: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11159:
11160: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11161: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11162: } else {
11163: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11164: }
11165: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11166: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11167: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11168: }
11169: $resulttext .= '</li>';
11170: } else {
11171: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11172: }
1.112 raeburn 11173: } else {
1.128 raeburn 11174: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11175: }
11176: }
1.128 raeburn 11177: $resulttext .= '</ul></li>';
1.112 raeburn 11178: }
1.160.6.5 raeburn 11179: } elsif ($item eq 'helpurl') {
11180: if (ref($changes{$item}) eq 'HASH') {
11181: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11182: if (grep(/^\Q$lang\E$/,@delurls)) {
11183: my ($chg,$link);
11184: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11185: if ($lang eq 'nolang') {
11186: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11187: } else {
11188: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11189: }
11190: $resulttext .= '<li>'.$chg.'</li>';
11191: } else {
11192: my $chg;
11193: if ($lang eq 'nolang') {
11194: $chg = &mt('custom log-in help file for no preferred language');
11195: } else {
11196: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11197: }
11198: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11199: $loginhash{'login'}{'helpurl'}{$lang}.
11200: '?inhibitmenu=yes',$chg,600,500).
11201: '</li>';
11202: }
11203: }
11204: }
1.160.6.56 raeburn 11205: } elsif ($item eq 'headtag') {
11206: if (ref($changes{$item}) eq 'HASH') {
11207: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11208: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11209: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11210: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11211: $resulttext .= '<li><a href="'.
11212: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11213: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11214: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11215: if ($possexempt{$lonhost}) {
11216: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11217: } else {
11218: $resulttext .= &mt('included for any client IP');
11219: }
11220: $resulttext .= '</li>';
11221: }
11222: }
11223: }
1.160.6.113 raeburn 11224: } elsif ($item eq 'saml') {
11225: if (ref($changes{$item}) eq 'HASH') {
11226: my %notlt = (
11227: text => 'Text for log-in by SSO',
11228: img => 'SSO button image',
11229: alt => 'Alt text for button image',
11230: url => 'SSO URL',
11231: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 11232:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 11233: notsso => 'Text for non-SSO log-in',
11234: );
11235: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11236: if (ref($currsaml{$lonhost}) eq 'HASH') {
11237: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11238: '<ul>';
1.160.6.118.2 9(raebur 11239:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11240: if ($currsaml{$lonhost}{$key} eq '') {
11241: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11242: } else {
11243: my $value = "'$currsaml{$lonhost}{$key}'";
11244: if ($key eq 'img') {
11245: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 11246:2): } elsif ($key eq 'window') {
11247:2): $value = 'On';
1.160.6.113 raeburn 11248: }
11249: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11250: $value).'</li>';
11251: }
11252: }
11253: $resulttext .= '</ul></li>';
11254: } else {
11255: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11256: }
11257: }
11258: }
1.160.6.5 raeburn 11259: } elsif ($item eq 'captcha') {
11260: if (ref($loginhash{'login'}) eq 'HASH') {
11261: my $chgtxt;
11262: if ($loginhash{'login'}{$item} eq 'notused') {
11263: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11264: } else {
11265: my %captchas = &captcha_phrases();
11266: if ($captchas{$loginhash{'login'}{$item}}) {
11267: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11268: } else {
11269: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11270: }
11271: }
11272: $resulttext .= '<li>'.$chgtxt.'</li>';
11273: }
11274: } elsif ($item eq 'recaptchakeys') {
11275: if (ref($loginhash{'login'}) eq 'HASH') {
11276: my ($privkey,$pubkey);
11277: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11278: $pubkey = $loginhash{'login'}{$item}{'public'};
11279: $privkey = $loginhash{'login'}{$item}{'private'};
11280: }
11281: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11282: if (!$pubkey) {
11283: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11284: } else {
11285: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11286: }
11287: if (!$privkey) {
11288: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11289: } else {
1.160.6.53 raeburn 11290: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 11291: }
11292: $chgtxt .= '</ul>';
11293: $resulttext .= '<li>'.$chgtxt.'</li>';
11294: }
1.160.6.69 raeburn 11295: } elsif ($item eq 'recaptchaversion') {
11296: if (ref($loginhash{'login'}) eq 'HASH') {
11297: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11298: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11299: '</li>';
11300: }
11301: }
1.41 raeburn 11302: } else {
11303: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11304: }
1.1 raeburn 11305: }
1.6 raeburn 11306: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11307: } else {
11308: $resulttext = &mt('No changes made to log-in page settings');
11309: }
11310: } else {
1.11 albertel 11311: $resulttext = '<span class="LC_error">'.
11312: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11313: }
1.6 raeburn 11314: if ($errors) {
1.9 raeburn 11315: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11316: $errors.'</ul>';
11317: }
11318: return $resulttext;
11319: }
11320:
1.160.6.56 raeburn 11321: sub check_exempt_addresses {
11322: my ($iplist) = @_;
11323: $iplist =~ s/^\s+//;
11324: $iplist =~ s/\s+$//;
11325: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11326: my (@okips,$new);
11327: foreach my $ip (@poss_ips) {
11328: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11329: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11330: push(@okips,$ip);
11331: }
11332: }
11333: }
11334: if (@okips > 0) {
11335: $new = join(',',@okips);
11336: } else {
11337: $new = '';
11338: }
11339: return $new;
11340: }
11341:
1.6 raeburn 11342: sub color_font_choices {
11343: my %choices =
11344: &Apache::lonlocal::texthash (
11345: img => "Header",
11346: bgs => "Background colors",
11347: links => "Link colors",
1.55 raeburn 11348: images => "Images",
1.6 raeburn 11349: font => "Font color",
1.160.6.22 raeburn 11350: fontmenu => "Font menu",
1.76 raeburn 11351: pgbg => "Page",
1.6 raeburn 11352: tabbg => "Header",
11353: sidebg => "Border",
11354: link => "Link",
11355: alink => "Active link",
11356: vlink => "Visited link",
11357: );
11358: return %choices;
11359: }
11360:
1.160.6.113 raeburn 11361: sub modify_ipaccess {
11362: my ($dom,$lastactref,%domconfig) = @_;
11363: my (@allpos,%changes,%confhash,$errors,$resulttext);
11364: my (@items,%deletions,%itemids,@warnings);
11365: my ($typeorder,$types) = &commblocktype_text();
11366: if ($env{'form.ipaccess_add'}) {
11367: my $name = $env{'form.ipaccess_name_add'};
11368: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11369: if ($newid) {
11370: $itemids{'add'} = $newid;
11371: push(@items,'add');
11372: $changes{$newid} = 1;
11373: } else {
11374: $error = &mt('Failed to acquire unique ID for new IP access control item');
11375: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11376: }
11377: }
11378: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11379: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11380: if (@todelete) {
11381: map { $deletions{$_} = 1; } @todelete;
11382: }
11383: my $maxnum = $env{'form.ipaccess_maxnum'};
11384: for (my $i=0; $i<$maxnum; $i++) {
11385: my $itemid = $env{'form.ipaccess_id_'.$i};
11386: $itemid =~ s/\D+//g;
11387: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11388: if ($deletions{$itemid}) {
11389: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11390: } else {
11391: push(@items,$i);
11392: $itemids{$i} = $itemid;
11393: }
11394: }
11395: }
11396: }
11397: foreach my $idx (@items) {
11398: my $itemid = $itemids{$idx};
11399: next unless ($itemid);
11400: my %current;
11401: unless ($idx eq 'add') {
11402: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11403: %current = %{$domconfig{'ipaccess'}{$itemid}};
11404: }
11405: }
11406: my $position = $env{'form.ipaccess_pos_'.$itemid};
11407: $position =~ s/\D+//g;
11408: if ($position ne '') {
11409: $allpos[$position] = $itemid;
11410: }
11411: my $name = $env{'form.ipaccess_name_'.$idx};
11412: $name =~ s/^\s+|\s+$//g;
11413: $confhash{$itemid}{'name'} = $name;
11414: my $possrange = $env{'form.ipaccess_range_'.$idx};
11415: $possrange =~ s/^\s+|\s+$//g;
11416: unless ($possrange eq '') {
11417: $possrange =~ s/[\r\n]+/\s/g;
11418: $possrange =~ s/\s*-\s*/-/g;
11419: $possrange =~ s/\s+/,/g;
11420: $possrange =~ s/,+/,/g;
11421: if ($possrange ne '') {
11422: my (@ok,$count);
11423: $count = 0;
11424: foreach my $poss (split(/\,/,$possrange)) {
11425: $count ++;
11426: $poss = &validate_ip_pattern($poss);
11427: if ($poss ne '') {
11428: push(@ok,$poss);
11429: }
11430: }
11431: my $diff = $count - scalar(@ok);
11432: if ($diff) {
11433: $errors .= '<li><span class="LC_error">'.
11434: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11435: $diff,$name).
11436: '</span></li>';
11437: }
11438: if (@ok) {
11439: my @cidr_list;
11440: foreach my $item (@ok) {
11441: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11442: }
11443: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11444: }
11445: }
11446: }
11447: foreach my $field ('name','ip') {
11448: unless (($idx eq 'add') || ($changes{$itemid})) {
11449: if ($current{$field} ne $confhash{$itemid}{$field}) {
11450: $changes{$itemid} = 1;
11451: last;
11452: }
11453: }
11454: }
11455: $confhash{$itemid}{'commblocks'} = {};
11456:
11457: my %commblocks;
11458: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11459: foreach my $type (@{$typeorder}) {
11460: if ($commblocks{$type}) {
11461: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11462: }
11463: unless (($idx eq 'add') || ($changes{$itemid})) {
11464: if (ref($current{'commblocks'}) eq 'HASH') {
11465: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11466: $changes{$itemid} = 1;
11467: }
11468: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11469: $changes{$itemid} = 1;
11470: }
11471: }
11472: }
11473: $confhash{$itemid}{'courses'} = {};
11474: my %crsdeletions;
11475: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11476: if (@delcrs) {
11477: map { $crsdeletions{$_} = 1; } @delcrs;
11478: }
11479: if (ref($current{'courses'}) eq 'HASH') {
11480: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11481: if ($crsdeletions{$cid}) {
11482: $changes{$itemid} = 1;
11483: } else {
11484: $confhash{$itemid}{'courses'}{$cid} = 1;
11485: }
11486: }
11487: }
11488: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11489: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11490: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11491: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11492: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11493: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11494: $errors .= '<li><span class="LC_error">'.
11495: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11496: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11497: '</span></li>';
11498: } else {
11499: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11500: $changes{$itemid} = 1;
11501: }
11502: }
11503: }
11504: if (@allpos > 0) {
11505: my $idx = 0;
11506: foreach my $itemid (@allpos) {
11507: if ($itemid ne '') {
11508: $confhash{$itemid}{'order'} = $idx;
11509: unless ($changes{$itemid}) {
11510: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11511: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11512: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11513: $changes{$itemid} = 1;
11514: }
11515: }
11516: }
11517: }
11518: $idx ++;
11519: }
11520: }
11521: }
11522: if (keys(%changes)) {
11523: my %defaultshash = (
11524: ipaccess => \%confhash,
11525: );
11526: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11527: $dom);
11528: if ($putresult eq 'ok') {
11529: my $cachetime = 1800;
11530: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11531: if (ref($lastactref) eq 'HASH') {
11532: $lastactref->{'ipaccess'} = 1;
11533: }
11534: $resulttext = &mt('Changes made:').'<ul>';
11535: my %bynum;
11536: foreach my $itemid (sort(keys(%changes))) {
11537: if (ref($confhash{$itemid}) eq 'HASH') {
11538: my $position = $confhash{$itemid}{'order'};
11539: if ($position =~ /^\d+$/) {
11540: $bynum{$position} = $itemid;
11541: }
11542: }
11543: }
11544: if (keys(%deletions)) {
11545: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11546: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11547: }
11548: }
11549: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11550: my $itemid = $bynum{$pos};
11551: if (ref($confhash{$itemid}) eq 'HASH') {
11552: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11553: my $position = $pos + 1;
11554: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11555: if ($confhash{$itemid}{'ip'} eq '') {
11556: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11557: } else {
11558: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11559: }
11560: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11561: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11562: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11563: '</li>';
11564: } else {
11565: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11566: }
11567: if (keys(%{$confhash{$itemid}{'courses'}})) {
11568: my @courses;
11569: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11570: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11571: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
11572: }
11573: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
11574: join('</li><li>',@courses).'</li></ul>';
11575: } else {
11576: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
11577: }
11578: $resulttext .= '</ul></li>';
11579: }
11580: }
11581: $resulttext .= '</ul>';
11582: } else {
11583: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11584: }
11585: } else {
11586: $resulttext = &mt('No changes made');
11587: }
11588: if ($errors) {
11589: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11590: $errors.'</ul></p>';
11591: }
11592: return $resulttext;
11593: }
11594:
11595: sub get_ipaccess_id {
11596: my ($domain,$location) = @_;
11597: # get lock on ipaccess db
11598: my $lockhash = {
11599: lock => $env{'user.name'}.
11600: ':'.$env{'user.domain'},
11601: };
11602: my $tries = 0;
11603: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11604: my ($id,$error);
11605:
11606: while (($gotlock ne 'ok') && ($tries<10)) {
11607: $tries ++;
11608: sleep (0.1);
11609: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11610: }
11611: if ($gotlock eq 'ok') {
11612: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
11613: if ($currids{'lock'}) {
11614: delete($currids{'lock'});
11615: if (keys(%currids)) {
11616: my @curr = sort { $a <=> $b } keys(%currids);
11617: if ($curr[-1] =~ /^\d+$/) {
11618: $id = 1 + $curr[-1];
11619: }
11620: } else {
11621: $id = 1;
11622: }
11623: if ($id) {
11624: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
11625: $error = 'nostore';
11626: }
11627: } else {
11628: $error = 'nonumber';
11629: }
11630: }
11631: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
11632: } else {
11633: $error = 'nolock';
11634: }
11635: return ($id,$error);
11636: }
11637:
1.6 raeburn 11638: sub modify_rolecolors {
1.160.6.24 raeburn 11639: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 11640: my ($resulttext,%rolehash);
11641: $rolehash{'rolecolors'} = {};
1.55 raeburn 11642: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11643: if ($domconfig{'rolecolors'} eq '') {
11644: $domconfig{'rolecolors'} = {};
11645: }
11646: }
1.9 raeburn 11647: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11648: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11649: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11650: $dom);
11651: if ($putresult eq 'ok') {
11652: if (keys(%changes) > 0) {
1.41 raeburn 11653: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11654: if (ref($lastactref) eq 'HASH') {
11655: $lastactref->{'domainconfig'} = 1;
11656: }
1.6 raeburn 11657: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11658: $rolehash{'rolecolors'});
11659: } else {
11660: $resulttext = &mt('No changes made to default color schemes');
11661: }
11662: } else {
1.11 albertel 11663: $resulttext = '<span class="LC_error">'.
11664: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11665: }
11666: if ($errors) {
11667: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11668: $errors.'</ul>';
11669: }
11670: return $resulttext;
11671: }
11672:
11673: sub modify_colors {
1.9 raeburn 11674: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11675: my (%changes,%choices);
1.51 raeburn 11676: my @bgs;
1.6 raeburn 11677: my @links = ('link','alink','vlink');
1.41 raeburn 11678: my @logintext;
1.6 raeburn 11679: my @images;
11680: my $servadm = $r->dir_config('lonAdmEMail');
11681: my $errors;
1.160.6.22 raeburn 11682: my %defaults;
1.6 raeburn 11683: foreach my $role (@{$roles}) {
11684: if ($role eq 'login') {
1.12 raeburn 11685: %choices = &login_choices();
1.41 raeburn 11686: @logintext = ('textcol','bgcol');
1.12 raeburn 11687: } else {
11688: %choices = &color_font_choices();
11689: }
11690: if ($role eq 'login') {
1.41 raeburn 11691: @images = ('img','logo','domlogo','login');
1.51 raeburn 11692: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11693: } else {
11694: @images = ('img');
1.160.6.22 raeburn 11695: @bgs = ('pgbg','tabbg','sidebg');
11696: }
11697: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11698: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11699: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11700: }
11701: if ($role eq 'login') {
11702: foreach my $item (@logintext) {
1.160.6.39 raeburn 11703: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11704: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11705: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11706: }
11707: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 11708: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11709: }
11710: }
11711: } else {
1.160.6.39 raeburn 11712: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11713: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11714: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11715: }
11716: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 11717: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11718: }
1.6 raeburn 11719: }
1.160.6.22 raeburn 11720: foreach my $item (@bgs) {
1.160.6.39 raeburn 11721: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11722: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11723: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11724: }
11725: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 11726: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11727: }
11728: }
11729: foreach my $item (@links) {
1.160.6.39 raeburn 11730: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11731: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11732: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11733: }
11734: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 11735: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11736: }
1.6 raeburn 11737: }
1.46 raeburn 11738: my ($configuserok,$author_ok,$switchserver) =
11739: &config_check($dom,$confname,$servadm);
1.9 raeburn 11740: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11741: if (ref($domconfig->{$role}) ne 'HASH') {
11742: $domconfig->{$role} = {};
11743: }
1.8 raeburn 11744: foreach my $img (@images) {
1.160.6.118.2 2(raebur 11745:2): if ($role eq 'login') {
11746:2): if (($img eq 'img') || ($img eq 'logo')) {
11747:2): if (defined($env{'form.login_showlogo_'.$img})) {
11748:2): $confhash->{$role}{'showlogo'}{$img} = 1;
11749:2): } else {
11750:2): $confhash->{$role}{'showlogo'}{$img} = 0;
11751:2): }
1.70 raeburn 11752: }
1.160.6.118.2 2(raebur 11753:2): if ($env{'form.login_alt_'.$img} ne '') {
11754:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11755:2): }
11756:2): }
1.18 albertel 11757: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11758: && !defined($domconfig->{$role}{$img})
11759: && !$env{'form.'.$role.'_del_'.$img}
11760: && $env{'form.'.$role.'_import_'.$img}) {
11761: # import the old configured image from the .tab setting
11762: # if they haven't provided a new one
11763: $domconfig->{$role}{$img} =
11764: $env{'form.'.$role.'_import_'.$img};
11765: }
1.6 raeburn 11766: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11767: my $error;
1.6 raeburn 11768: if ($configuserok eq 'ok') {
1.9 raeburn 11769: if ($switchserver) {
1.12 raeburn 11770: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11771: } else {
11772: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11773:23): my $modified = [];
1.9 raeburn 11774: my ($result,$logourl) =
1.160.6.118.2 14(raebu 11775:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
11776:23): $dom,$confname,$img,$width,$height,
11777:23): '',$modified);
1.9 raeburn 11778: if ($result eq 'ok') {
11779: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11780: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 11781:23): &update_modify_urls($r,$modified);
1.9 raeburn 11782: } else {
1.12 raeburn 11783: $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 11784: }
11785: } else {
1.46 raeburn 11786: $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 11787: }
11788: }
11789: } else {
1.46 raeburn 11790: $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 11791: }
11792: if ($error) {
1.8 raeburn 11793: &Apache::lonnet::logthis($error);
1.11 albertel 11794: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11795: }
11796: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11797: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11798: my $error;
11799: if ($configuserok eq 'ok') {
11800: # is confname an author?
11801: if ($switchserver eq '') {
11802: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11803:23): my $modified = [];
1.9 raeburn 11804: my ($result,$logourl) =
1.160.6.118.2 14(raebu 11805:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
11806:23): $dom,$confname,$img,$width,$height,
11807:23): '',$modified);
1.9 raeburn 11808: if ($result eq 'ok') {
11809: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11810: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 11811:23): &update_modify_urls($r,$modified);
1.9 raeburn 11812: }
11813: }
11814: }
11815: }
1.6 raeburn 11816: }
11817: }
11818: }
11819: if (ref($domconfig) eq 'HASH') {
11820: if (ref($domconfig->{$role}) eq 'HASH') {
11821: foreach my $img (@images) {
11822: if ($domconfig->{$role}{$img} ne '') {
11823: if ($env{'form.'.$role.'_del_'.$img}) {
11824: $confhash->{$role}{$img} = '';
1.12 raeburn 11825: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11826: } else {
1.9 raeburn 11827: if ($confhash->{$role}{$img} eq '') {
11828: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11829: }
1.6 raeburn 11830: }
11831: } else {
11832: if ($env{'form.'.$role.'_del_'.$img}) {
11833: $confhash->{$role}{$img} = '';
1.12 raeburn 11834: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11835: }
11836: }
1.160.6.118.2 2(raebur 11837:2): if ($role eq 'login') {
11838:2): if (($img eq 'logo') || ($img eq 'img')) {
11839:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11840:2): if ($confhash->{$role}{'showlogo'}{$img} ne
11841:2): $domconfig->{$role}{'showlogo'}{$img}) {
11842:2): $changes{$role}{'showlogo'}{$img} = 1;
11843:2): }
11844:2): } else {
11845:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11846:2): $changes{$role}{'showlogo'}{$img} = 1;
11847:2): }
1.70 raeburn 11848: }
1.160.6.118.2 2(raebur 11849:2): }
11850:2): if ($img ne 'login') {
11851:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11852:2): if ($confhash->{$role}{'alttext'}{$img} ne
11853:2): $domconfig->{$role}{'alttext'}{$img}) {
11854:2): $changes{$role}{'alttext'}{$img} = 1;
11855:2): }
11856:2): } else {
11857:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11858:2): $changes{$role}{'alttext'}{$img} = 1;
11859:2): }
1.70 raeburn 11860: }
11861: }
11862: }
11863: }
1.6 raeburn 11864: if ($domconfig->{$role}{'font'} ne '') {
11865: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11866: $changes{$role}{'font'} = 1;
11867: }
11868: } else {
11869: if ($confhash->{$role}{'font'}) {
11870: $changes{$role}{'font'} = 1;
11871: }
11872: }
1.107 raeburn 11873: if ($role ne 'login') {
11874: if ($domconfig->{$role}{'fontmenu'} ne '') {
11875: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11876: $changes{$role}{'fontmenu'} = 1;
11877: }
11878: } else {
11879: if ($confhash->{$role}{'fontmenu'}) {
11880: $changes{$role}{'fontmenu'} = 1;
11881: }
1.97 tempelho 11882: }
11883: }
1.6 raeburn 11884: foreach my $item (@bgs) {
11885: if ($domconfig->{$role}{$item} ne '') {
11886: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11887: $changes{$role}{'bgs'}{$item} = 1;
11888: }
11889: } else {
11890: if ($confhash->{$role}{$item}) {
11891: $changes{$role}{'bgs'}{$item} = 1;
11892: }
11893: }
11894: }
11895: foreach my $item (@links) {
11896: if ($domconfig->{$role}{$item} ne '') {
11897: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11898: $changes{$role}{'links'}{$item} = 1;
11899: }
11900: } else {
11901: if ($confhash->{$role}{$item}) {
11902: $changes{$role}{'links'}{$item} = 1;
11903: }
11904: }
11905: }
1.41 raeburn 11906: foreach my $item (@logintext) {
11907: if ($domconfig->{$role}{$item} ne '') {
11908: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11909: $changes{$role}{'logintext'}{$item} = 1;
11910: }
11911: } else {
11912: if ($confhash->{$role}{$item}) {
11913: $changes{$role}{'logintext'}{$item} = 1;
11914: }
11915: }
11916: }
1.6 raeburn 11917: } else {
11918: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11919: \@logintext,$confhash,\%changes);
1.6 raeburn 11920: }
11921: } else {
11922: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11923: \@logintext,$confhash,\%changes);
1.6 raeburn 11924: }
11925: }
11926: return ($errors,%changes);
11927: }
11928:
1.46 raeburn 11929: sub config_check {
11930: my ($dom,$confname,$servadm) = @_;
11931: my ($configuserok,$author_ok,$switchserver,%currroles);
11932: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
11933: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
11934: $confname,$servadm);
11935: if ($configuserok eq 'ok') {
11936: $switchserver = &check_switchserver($dom,$confname);
11937: if ($switchserver eq '') {
11938: $author_ok = &check_authorstatus($dom,$confname,%currroles);
11939: }
11940: }
11941: return ($configuserok,$author_ok,$switchserver);
11942: }
11943:
1.6 raeburn 11944: sub default_change_checker {
1.41 raeburn 11945: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 11946: foreach my $item (@{$links}) {
11947: if ($confhash->{$role}{$item}) {
11948: $changes->{$role}{'links'}{$item} = 1;
11949: }
11950: }
11951: foreach my $item (@{$bgs}) {
11952: if ($confhash->{$role}{$item}) {
11953: $changes->{$role}{'bgs'}{$item} = 1;
11954: }
11955: }
1.41 raeburn 11956: foreach my $item (@{$logintext}) {
11957: if ($confhash->{$role}{$item}) {
11958: $changes->{$role}{'logintext'}{$item} = 1;
11959: }
11960: }
1.6 raeburn 11961: foreach my $img (@{$images}) {
11962: if ($env{'form.'.$role.'_del_'.$img}) {
11963: $confhash->{$role}{$img} = '';
1.12 raeburn 11964: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 11965: }
1.70 raeburn 11966: if ($role eq 'login') {
11967: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11968: $changes->{$role}{'showlogo'}{$img} = 1;
11969: }
1.160.6.118.2 2(raebur 11970:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
11971:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11972:2): $changes->{$role}{'alttext'}{$img} = 1;
11973:2): }
11974:2): }
1.70 raeburn 11975: }
1.6 raeburn 11976: }
11977: if ($confhash->{$role}{'font'}) {
11978: $changes->{$role}{'font'} = 1;
11979: }
1.48 raeburn 11980: }
1.6 raeburn 11981:
11982: sub display_colorchgs {
11983: my ($dom,$changes,$roles,$confhash) = @_;
11984: my (%choices,$resulttext);
11985: if (!grep(/^login$/,@{$roles})) {
11986: $resulttext = &mt('Changes made:').'<br />';
11987: }
11988: foreach my $role (@{$roles}) {
11989: if ($role eq 'login') {
11990: %choices = &login_choices();
11991: } else {
11992: %choices = &color_font_choices();
11993: }
11994: if (ref($changes->{$role}) eq 'HASH') {
11995: if ($role ne 'login') {
11996: $resulttext .= '<h4>'.&mt($role).'</h4>';
11997: }
11998: foreach my $key (sort(keys(%{$changes->{$role}}))) {
11999: if ($role ne 'login') {
12000: $resulttext .= '<ul>';
12001: }
12002: if (ref($changes->{$role}{$key}) eq 'HASH') {
12003: if ($role ne 'login') {
12004: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12005: }
12006: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12007: if (($role eq 'login') && ($key eq 'showlogo')) {
12008: if ($confhash->{$role}{$key}{$item}) {
12009: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12010: } else {
12011: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12012: }
1.160.6.118.2 2(raebur 12013:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
12014:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 12015:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 12016:2): $confhash->{$role}{$key}{$item}).'</li>';
12017:2): } else {
12018:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12019:2): }
1.70 raeburn 12020: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12021: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12022: } else {
1.12 raeburn 12023: my $newitem = $confhash->{$role}{$item};
12024: if ($key eq 'images') {
12025: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12026: }
12027: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12028: }
12029: }
12030: if ($role ne 'login') {
12031: $resulttext .= '</ul></li>';
12032: }
12033: } else {
12034: if ($confhash->{$role}{$key} eq '') {
12035: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12036: } else {
12037: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12038: }
12039: }
12040: if ($role ne 'login') {
12041: $resulttext .= '</ul>';
12042: }
12043: }
12044: }
12045: }
1.3 raeburn 12046: return $resulttext;
1.1 raeburn 12047: }
12048:
1.9 raeburn 12049: sub thumb_dimensions {
12050: return ('200','50');
12051: }
12052:
1.16 raeburn 12053: sub check_dimensions {
12054: my ($inputfile) = @_;
12055: my ($fullwidth,$fullheight);
12056: if ($inputfile =~ m|^[/\w.\-]+$|) {
12057: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12058: my $imageinfo = <PIPE>;
12059: if (!close(PIPE)) {
12060: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12061: }
12062: chomp($imageinfo);
12063: my ($fullsize) =
1.21 raeburn 12064: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12065: if ($fullsize) {
12066: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12067: }
12068: }
12069: }
12070: return ($fullwidth,$fullheight);
12071: }
12072:
1.9 raeburn 12073: sub check_configuser {
12074: my ($uhome,$dom,$confname,$servadm) = @_;
12075: my ($configuserok,%currroles);
12076: if ($uhome eq 'no_host') {
12077: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 12078: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12079: $configuserok =
12080: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12081: $configpass,'','','','','',undef,$servadm);
12082: } else {
12083: $configuserok = 'ok';
12084: %currroles =
12085: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12086: }
12087: return ($configuserok,%currroles);
12088: }
12089:
12090: sub check_authorstatus {
12091: my ($dom,$confname,%currroles) = @_;
12092: my $author_ok;
1.40 raeburn 12093: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12094: my $start = time;
12095: my $end = 0;
12096: $author_ok =
12097: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12098: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12099: } else {
12100: $author_ok = 'ok';
12101: }
12102: return $author_ok;
12103: }
12104:
1.160.6.118.2 14(raebu 12105:23): sub update_modify_urls {
12106:23): my ($r,$modified) = @_;
12107:23): if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12108:23): push(@{$modified_urls},$modified);
12109:23): unless ($registered_cleanup) {
12110:23): my $handlers = $r->get_handlers('PerlCleanupHandler');
12111:23): $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12112:23): $registered_cleanup=1;
1.9 raeburn 12113: }
12114: }
1.155 raeburn 12115: }
12116:
12117: sub notifysubscribed {
12118: foreach my $targetsource (@{$modified_urls}){
12119: next unless (ref($targetsource) eq 'ARRAY');
12120: my ($target,$source)=@{$targetsource};
12121: if ($source ne '') {
1.160.6.88 raeburn 12122: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12123: print $logfh "\nCleanup phase: Notifications\n";
12124: my @subscribed=&subscribed_hosts($target);
12125: foreach my $subhost (@subscribed) {
12126: print $logfh "\nNotifying host ".$subhost.':';
12127: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12128: print $logfh $reply;
12129: }
12130: my @subscribedmeta=&subscribed_hosts("$target.meta");
12131: foreach my $subhost (@subscribedmeta) {
12132: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12133: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12134: $subhost);
12135: print $logfh $reply;
12136: }
12137: print $logfh "\n============ Done ============\n";
1.160 raeburn 12138: close($logfh);
1.155 raeburn 12139: }
12140: }
12141: }
12142: return OK;
12143: }
12144:
12145: sub subscribed_hosts {
12146: my ($target) = @_;
12147: my @subscribed;
1.160.6.88 raeburn 12148: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12149: while (my $subline=<$fh>) {
12150: if ($subline =~ /^($match_lonid):/) {
12151: my $host = $1;
12152: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12153: unless (grep(/^\Q$host\E$/,@subscribed)) {
12154: push(@subscribed,$host);
12155: }
12156: }
12157: }
12158: }
12159: }
12160: return @subscribed;
1.9 raeburn 12161: }
12162:
12163: sub check_switchserver {
12164: my ($dom,$confname) = @_;
1.160.6.118.2 14(raebu 12165:23): my ($allowed,$switchserver,$home);
12166:23): if ($confname eq '') {
1.9 raeburn 12167: $home = &Apache::lonnet::domain($dom,'primary');
1.160.6.118.2 14(raebu 12168:23): } else {
12169:23): $home = &Apache::lonnet::homeserver($confname,$dom);
12170:23): if ($home eq 'no_host') {
12171:23): $home = &Apache::lonnet::domain($dom,'primary');
12172:23): }
1.9 raeburn 12173: }
12174: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12175: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12176: if (!$allowed) {
1.160.6.118.2 14(raebu 12177:23): $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12178:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12179:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12180: }
12181: return $switchserver;
12182: }
12183:
1.1 raeburn 12184: sub modify_quotas {
1.160.6.30 raeburn 12185: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12186: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 12187: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 12188: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12189: $validationfieldsref);
1.86 raeburn 12190: if ($action eq 'quotas') {
12191: $context = 'tools';
1.160.6.26 raeburn 12192: } else {
1.86 raeburn 12193: $context = $action;
12194: }
12195: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 12196:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 12197: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12198: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12199: %titles = &courserequest_titles();
12200: $toolregexp = join('|',@usertools);
12201: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 12202: $confname = $dom.'-domainconfig';
12203: my $servadm = $r->dir_config('lonAdmEMail');
12204: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 12205: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12206: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 12207: } elsif ($context eq 'requestauthor') {
12208: @usertools = ('author');
12209: %titles = &authorrequest_titles();
1.86 raeburn 12210: } else {
1.160.6.118.2 10(raebu 12211:22): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 12212: %titles = &tool_titles();
1.86 raeburn 12213: }
1.160.6.27 raeburn 12214: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12215: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12216: foreach my $key (keys(%env)) {
1.101 raeburn 12217: if ($context eq 'requestcourses') {
12218: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12219: my $item = $1;
12220: my $type = $2;
12221: if ($type =~ /^limit_(.+)/) {
12222: $limithash{$item}{$1} = $env{$key};
12223: } else {
12224: $confhash{$item}{$type} = $env{$key};
12225: }
12226: }
1.160.6.5 raeburn 12227: } elsif ($context eq 'requestauthor') {
12228: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12229: $confhash{$1} = $env{$key};
12230: }
1.101 raeburn 12231: } else {
1.86 raeburn 12232: if ($key =~ /^form\.quota_(.+)$/) {
12233: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 12234: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12235: $confhash{'authorquota'}{$1} = $env{$key};
12236: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12237: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12238: }
1.72 raeburn 12239: }
12240: }
1.160.6.5 raeburn 12241: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 12242: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12243: @approvalnotify = sort(@approvalnotify);
12244: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.118.2 14(raebu 12245:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.30 raeburn 12246: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12247: foreach my $type (@hasuniquecode) {
12248: if (grep(/^\Q$type\E$/,@crstypes)) {
12249: $confhash{'uniquecode'}{$type} = 1;
12250: }
12251: }
1.160.6.46 raeburn 12252: my (%newbook,%allpos);
1.160.6.30 raeburn 12253: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12254: foreach my $type ('textbooks','templates') {
12255: @{$allpos{$type}} = ();
12256: my $invalid;
12257: if ($type eq 'textbooks') {
12258: $invalid = &mt('Invalid LON-CAPA course for textbook');
12259: } else {
12260: $invalid = &mt('Invalid LON-CAPA course for template');
12261: }
12262: if ($env{'form.'.$type.'_addbook'}) {
12263: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12264: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12265: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12266: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12267: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12268: } else {
12269: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12270: my $position = $env{'form.'.$type.'_addbook_pos'};
12271: $position =~ s/\D+//g;
12272: if ($position ne '') {
12273: $allpos{$type}[$position] = $newbook{$type};
12274: }
1.160.6.30 raeburn 12275: }
1.160.6.46 raeburn 12276: } else {
12277: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 12278: }
12279: }
1.160.6.46 raeburn 12280: }
1.160.6.30 raeburn 12281: }
1.102 raeburn 12282: if (ref($domconfig{$action}) eq 'HASH') {
12283: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12284: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12285: $changes{'notify'}{'approval'} = 1;
12286: }
12287: } else {
1.144 raeburn 12288: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12289: $changes{'notify'}{'approval'} = 1;
12290: }
12291: }
1.160.6.30 raeburn 12292: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12293: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12294: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12295: unless ($confhash{'uniquecode'}{$crstype}) {
12296: $changes{'uniquecode'} = 1;
12297: }
12298: }
12299: unless ($changes{'uniquecode'}) {
12300: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12301: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12302: $changes{'uniquecode'} = 1;
12303: }
12304: }
12305: }
12306: } else {
12307: $changes{'uniquecode'} = 1;
12308: }
12309: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12310: $changes{'uniquecode'} = 1;
12311: }
12312: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12313: foreach my $type ('textbooks','templates') {
12314: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12315: my %deletions;
12316: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12317: if (@todelete) {
12318: map { $deletions{$_} = 1; } @todelete;
12319: }
12320: my %imgdeletions;
12321: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12322: if (@todeleteimages) {
12323: map { $imgdeletions{$_} = 1; } @todeleteimages;
12324: }
12325: my $maxnum = $env{'form.'.$type.'_maxnum'};
12326: for (my $i=0; $i<=$maxnum; $i++) {
12327: my $itemid = $env{'form.'.$type.'_id_'.$i};
12328: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12329: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12330: if ($deletions{$key}) {
12331: if ($domconfig{$action}{$type}{$key}{'image'}) {
12332: #FIXME need to obsolete item in RES space
12333: }
12334: next;
12335: } else {
12336: my $newpos = $env{'form.'.$itemid};
12337: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 12338: foreach my $item ('subject','title','publisher','author') {
12339: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12340: ($type eq 'templates'));
1.160.6.46 raeburn 12341: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12342: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12343: $changes{$type}{$key} = 1;
12344: }
12345: }
12346: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 12347: }
1.160.6.46 raeburn 12348: if ($imgdeletions{$key}) {
12349: $changes{$type}{$key} = 1;
12350: #FIXME need to obsolete item in RES space
12351: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12352: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 12353: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12354: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12355: } else {
12356: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12357: $cdom,$cnum,$type,$configuserok,
12358: $switchserver,$author_ok);
12359: if ($imgurl) {
12360: $confhash{$type}{$key}{'image'} = $imgurl;
12361: $changes{$type}{$key} = 1;
12362: }
12363: if ($error) {
12364: &Apache::lonnet::logthis($error);
12365: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12366: }
1.160.6.118.2 14(raebu 12367:23): }
1.160.6.46 raeburn 12368: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12369: $confhash{$type}{$key}{'image'} =
12370: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 12371: }
12372: }
12373: }
12374: }
12375: }
12376: }
1.102 raeburn 12377: } else {
1.144 raeburn 12378: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12379: $changes{'notify'}{'approval'} = 1;
12380: }
1.160.6.30 raeburn 12381: if (ref($confhash{'uniquecode'} eq 'HASH')) {
12382: $changes{'uniquecode'} = 1;
12383: }
12384: }
12385: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12386: foreach my $type ('textbooks','templates') {
12387: if ($newbook{$type}) {
12388: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 12389: foreach my $item ('subject','title','publisher','author') {
12390: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12391: ($type eq 'template'));
1.160.6.46 raeburn 12392: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12393: if ($env{'form.'.$type.'_addbook_'.$item}) {
12394: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12395: }
12396: }
12397: if ($type eq 'textbooks') {
12398: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12399: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 12400: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12401: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12402: } else {
12403: my ($imageurl,$error) =
12404: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12405: $configuserok,$switchserver,$author_ok);
12406: if ($imageurl) {
12407: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12408: }
12409: if ($error) {
12410: &Apache::lonnet::logthis($error);
12411: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12412: }
1.160.6.46 raeburn 12413: }
12414: }
1.160.6.30 raeburn 12415: }
12416: }
1.160.6.46 raeburn 12417: if (@{$allpos{$type}} > 0) {
12418: my $idx = 0;
12419: foreach my $item (@{$allpos{$type}}) {
12420: if ($item ne '') {
12421: $confhash{$type}{$item}{'order'} = $idx;
12422: if (ref($domconfig{$action}) eq 'HASH') {
12423: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12424: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12425: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12426: $changes{$type}{$item} = 1;
12427: }
1.160.6.30 raeburn 12428: }
12429: }
12430: }
1.160.6.46 raeburn 12431: $idx ++;
1.160.6.30 raeburn 12432: }
12433: }
12434: }
12435: }
1.160.6.39 raeburn 12436: if (ref($validationitemsref) eq 'ARRAY') {
12437: foreach my $item (@{$validationitemsref}) {
12438: if ($item eq 'fields') {
12439: my @changed;
12440: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12441: if (@{$confhash{'validation'}{$item}} > 0) {
12442: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12443: }
1.160.6.65 raeburn 12444: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12445: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12446: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12447: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12448: $domconfig{'requestcourses'}{'validation'}{$item});
12449: } else {
12450: @changed = @{$confhash{'validation'}{$item}};
12451: }
1.160.6.39 raeburn 12452: } else {
12453: @changed = @{$confhash{'validation'}{$item}};
12454: }
12455: } else {
12456: @changed = @{$confhash{'validation'}{$item}};
12457: }
12458: if (@changed) {
12459: if ($confhash{'validation'}{$item}) {
12460: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12461: } else {
12462: $changes{'validation'}{$item} = &mt('None');
12463: }
12464: }
12465: } else {
12466: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12467: if ($item eq 'markup') {
12468: if ($env{'form.requestcourses_validation_'.$item}) {
12469: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12470: }
12471: }
1.160.6.65 raeburn 12472: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12473: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12474: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12475: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12476: }
12477: } else {
12478: if ($confhash{'validation'}{$item} ne '') {
12479: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12480: }
1.160.6.39 raeburn 12481: }
12482: } else {
12483: if ($confhash{'validation'}{$item} ne '') {
12484: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12485: }
12486: }
12487: }
12488: }
12489: }
12490: if ($env{'form.validationdc'}) {
12491: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 12492: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 12493: if (exists($domcoords{$newval})) {
12494: $confhash{'validation'}{'dc'} = $newval;
12495: }
12496: }
12497: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 12498: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12499: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12500: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12501: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12502: if ($confhash{'validation'}{'dc'} eq '') {
12503: $changes{'validation'}{'dc'} = &mt('None');
12504: } else {
12505: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12506: }
1.160.6.39 raeburn 12507: }
1.160.6.65 raeburn 12508: } elsif ($confhash{'validation'}{'dc'} ne '') {
12509: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 12510: }
12511: } elsif ($confhash{'validation'}{'dc'} ne '') {
12512: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12513: }
12514: } elsif ($confhash{'validation'}{'dc'} ne '') {
12515: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12516: }
1.160.6.65 raeburn 12517: } else {
12518: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12519: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12520: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12521: $changes{'validation'}{'dc'} = &mt('None');
12522: }
12523: }
1.160.6.39 raeburn 12524: }
12525: }
1.102 raeburn 12526: }
12527: } else {
1.86 raeburn 12528: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 12529: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12530: }
1.72 raeburn 12531: foreach my $item (@usertools) {
12532: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12533: my $unset;
1.101 raeburn 12534: if ($context eq 'requestcourses') {
1.104 raeburn 12535: $unset = '0';
12536: if ($type eq '_LC_adv') {
12537: $unset = '';
12538: }
1.101 raeburn 12539: if ($confhash{$item}{$type} eq 'autolimit') {
12540: $confhash{$item}{$type} .= '=';
12541: unless ($limithash{$item}{$type} =~ /\D/) {
12542: $confhash{$item}{$type} .= $limithash{$item}{$type};
12543: }
12544: }
1.160.6.5 raeburn 12545: } elsif ($context eq 'requestauthor') {
12546: $unset = '0';
12547: if ($type eq '_LC_adv') {
12548: $unset = '';
12549: }
1.72 raeburn 12550: } else {
1.101 raeburn 12551: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12552: $confhash{$item}{$type} = 1;
12553: } else {
12554: $confhash{$item}{$type} = 0;
12555: }
1.72 raeburn 12556: }
1.86 raeburn 12557: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 12558: if ($action eq 'requestauthor') {
12559: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12560: $changes{$type} = 1;
12561: }
12562: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12563: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12564: $changes{$item}{$type} = 1;
12565: }
12566: } else {
12567: if ($context eq 'requestcourses') {
1.104 raeburn 12568: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12569: $changes{$item}{$type} = 1;
12570: }
12571: } else {
12572: if (!$confhash{$item}{$type}) {
12573: $changes{$item}{$type} = 1;
12574: }
12575: }
12576: }
12577: } else {
12578: if ($context eq 'requestcourses') {
1.104 raeburn 12579: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12580: $changes{$item}{$type} = 1;
12581: }
1.160.6.5 raeburn 12582: } elsif ($context eq 'requestauthor') {
12583: if ($confhash{$type} ne $unset) {
12584: $changes{$type} = 1;
12585: }
1.72 raeburn 12586: } else {
12587: if (!$confhash{$item}{$type}) {
12588: $changes{$item}{$type} = 1;
12589: }
12590: }
12591: }
1.1 raeburn 12592: }
12593: }
1.160.6.5 raeburn 12594: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12595: if (ref($domconfig{'quotas'}) eq 'HASH') {
12596: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12597: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12598: if (exists($confhash{'defaultquota'}{$key})) {
12599: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12600: $changes{'defaultquota'}{$key} = 1;
12601: }
12602: } else {
12603: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12604: }
12605: }
1.86 raeburn 12606: } else {
12607: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12608: if (exists($confhash{'defaultquota'}{$key})) {
12609: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12610: $changes{'defaultquota'}{$key} = 1;
12611: }
12612: } else {
12613: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12614: }
1.1 raeburn 12615: }
12616: }
1.160.6.20 raeburn 12617: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12618: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12619: if (exists($confhash{'authorquota'}{$key})) {
12620: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12621: $changes{'authorquota'}{$key} = 1;
12622: }
12623: } else {
12624: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12625: }
12626: }
12627: }
1.1 raeburn 12628: }
1.86 raeburn 12629: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12630: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12631: if (ref($domconfig{'quotas'}) eq 'HASH') {
12632: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12633: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12634: $changes{'defaultquota'}{$key} = 1;
12635: }
12636: } else {
12637: if (!exists($domconfig{'quotas'}{$key})) {
12638: $changes{'defaultquota'}{$key} = 1;
12639: }
1.72 raeburn 12640: }
12641: } else {
1.86 raeburn 12642: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12643: }
1.1 raeburn 12644: }
12645: }
1.160.6.20 raeburn 12646: if (ref($confhash{'authorquota'}) eq 'HASH') {
12647: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12648: if (ref($domconfig{'quotas'}) eq 'HASH') {
12649: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12650: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12651: $changes{'authorquota'}{$key} = 1;
12652: }
12653: } else {
12654: $changes{'authorquota'}{$key} = 1;
12655: }
12656: } else {
12657: $changes{'authorquota'}{$key} = 1;
12658: }
12659: }
12660: }
1.1 raeburn 12661: }
1.72 raeburn 12662:
1.160.6.5 raeburn 12663: if ($context eq 'requestauthor') {
12664: $domdefaults{'requestauthor'} = \%confhash;
12665: } else {
12666: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 12667: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 12668: $domdefaults{$key} = $confhash{$key};
12669: }
1.160.6.5 raeburn 12670: }
1.72 raeburn 12671: }
1.160.6.5 raeburn 12672:
1.1 raeburn 12673: my %quotahash = (
1.86 raeburn 12674: $action => { %confhash }
1.1 raeburn 12675: );
12676: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12677: $dom);
12678: if ($putresult eq 'ok') {
12679: if (keys(%changes) > 0) {
1.72 raeburn 12680: my $cachetime = 24*60*60;
12681: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12682: if (ref($lastactref) eq 'HASH') {
12683: $lastactref->{'domdefaults'} = 1;
12684: }
1.1 raeburn 12685: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 12686: unless (($context eq 'requestcourses') ||
12687: ($context eq 'requestauthor')) {
1.86 raeburn 12688: if (ref($changes{'defaultquota'}) eq 'HASH') {
12689: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12690: foreach my $type (@{$types},'default') {
12691: if (defined($changes{'defaultquota'}{$type})) {
12692: my $typetitle = $usertypes->{$type};
12693: if ($type eq 'default') {
12694: $typetitle = $othertitle;
12695: }
1.160.6.28 raeburn 12696: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12697: }
12698: }
1.86 raeburn 12699: $resulttext .= '</ul></li>';
1.72 raeburn 12700: }
1.160.6.20 raeburn 12701: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 12702: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 12703: foreach my $type (@{$types},'default') {
12704: if (defined($changes{'authorquota'}{$type})) {
12705: my $typetitle = $usertypes->{$type};
12706: if ($type eq 'default') {
12707: $typetitle = $othertitle;
12708: }
1.160.6.28 raeburn 12709: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 12710: }
12711: }
12712: $resulttext .= '</ul></li>';
12713: }
1.72 raeburn 12714: }
1.80 raeburn 12715: my %newenv;
1.72 raeburn 12716: foreach my $item (@usertools) {
1.160.6.5 raeburn 12717: my (%haschgs,%inconf);
12718: if ($context eq 'requestauthor') {
12719: %haschgs = %changes;
12720: %inconf = %confhash;
12721: } else {
12722: if (ref($changes{$item}) eq 'HASH') {
12723: %haschgs = %{$changes{$item}};
12724: }
12725: if (ref($confhash{$item}) eq 'HASH') {
12726: %inconf = %{$confhash{$item}};
12727: }
12728: }
12729: if (keys(%haschgs) > 0) {
1.80 raeburn 12730: my $newacc =
12731: &Apache::lonnet::usertools_access($env{'user.name'},
12732: $env{'user.domain'},
1.86 raeburn 12733: $item,'reload',$context);
1.160.6.5 raeburn 12734: if (($context eq 'requestcourses') ||
12735: ($context eq 'requestauthor')) {
1.108 raeburn 12736: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12737: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12738: }
12739: } else {
12740: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12741: $newenv{'environment.availabletools.'.$item} = $newacc;
12742: }
1.80 raeburn 12743: }
1.160.6.5 raeburn 12744: unless ($context eq 'requestauthor') {
12745: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12746: }
1.72 raeburn 12747: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 12748: if ($haschgs{$type}) {
1.72 raeburn 12749: my $typetitle = $usertypes->{$type};
12750: if ($type eq 'default') {
12751: $typetitle = $othertitle;
12752: } elsif ($type eq '_LC_adv') {
12753: $typetitle = 'LON-CAPA Advanced Users';
12754: }
1.160.6.5 raeburn 12755: if ($inconf{$type}) {
1.101 raeburn 12756: if ($context eq 'requestcourses') {
12757: my $cond;
1.160.6.5 raeburn 12758: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12759: if ($1 eq '') {
12760: $cond = &mt('(Automatic processing of any request).');
12761: } else {
12762: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12763: }
12764: } else {
1.160.6.5 raeburn 12765: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12766: }
12767: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 12768: } elsif ($context eq 'requestauthor') {
12769: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12770: $titles{$inconf{$type}},$typetitle);
12771:
1.101 raeburn 12772: } else {
12773: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12774: }
1.72 raeburn 12775: } else {
1.104 raeburn 12776: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 12777: if ($inconf{$type} eq '0') {
1.104 raeburn 12778: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12779: } else {
12780: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12781: }
12782: } else {
12783: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12784: }
1.72 raeburn 12785: }
12786: }
1.26 raeburn 12787: }
1.160.6.5 raeburn 12788: unless ($context eq 'requestauthor') {
12789: $resulttext .= '</ul></li>';
12790: }
1.26 raeburn 12791: }
1.1 raeburn 12792: }
1.160.6.5 raeburn 12793: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12794: if (ref($changes{'notify'}) eq 'HASH') {
12795: if ($changes{'notify'}{'approval'}) {
12796: if (ref($confhash{'notify'}) eq 'HASH') {
12797: if ($confhash{'notify'}{'approval'}) {
12798: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12799: } else {
1.160.6.5 raeburn 12800: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12801: }
12802: }
12803: }
12804: }
12805: }
1.160.6.30 raeburn 12806: if ($action eq 'requestcourses') {
12807: my @offon = ('off','on');
12808: if ($changes{'uniquecode'}) {
12809: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12810: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12811: $resulttext .= '<li>'.
12812: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12813: '</li>';
12814: } else {
12815: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12816: '</li>';
12817: }
12818: }
1.160.6.46 raeburn 12819: foreach my $type ('textbooks','templates') {
12820: if (ref($changes{$type}) eq 'HASH') {
12821: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12822: foreach my $key (sort(keys(%{$changes{$type}}))) {
12823: my %coursehash = &Apache::lonnet::coursedescription($key);
12824: my $coursetitle = $coursehash{'description'};
12825: my $position = $confhash{$type}{$key}{'order'} + 1;
12826: $resulttext .= '<li>';
1.160.6.47 raeburn 12827: foreach my $item ('subject','title','publisher','author') {
12828: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12829: ($type eq 'templates'));
1.160.6.46 raeburn 12830: my $name = $item.':';
12831: $name =~ s/^(\w)/\U$1/;
12832: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12833: }
12834: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12835: if ($type eq 'textbooks') {
12836: if ($confhash{$type}{$key}{'image'}) {
12837: $resulttext .= ' '.&mt('Image: [_1]',
12838: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12839: ' alt="Textbook cover" />').'<br />';
12840: }
12841: }
12842: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 12843: }
1.160.6.46 raeburn 12844: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 12845: }
12846: }
1.160.6.39 raeburn 12847: if (ref($changes{'validation'}) eq 'HASH') {
12848: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12849: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12850: foreach my $item (@{$validationitemsref}) {
12851: if (exists($changes{'validation'}{$item})) {
12852: if ($item eq 'markup') {
12853: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12854: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12855: } else {
12856: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12857: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12858: }
12859: }
12860: }
12861: if (exists($changes{'validation'}{'dc'})) {
12862: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12863: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12864: }
12865: }
12866: }
1.160.6.30 raeburn 12867: }
1.1 raeburn 12868: $resulttext .= '</ul>';
1.80 raeburn 12869: if (keys(%newenv)) {
12870: &Apache::lonnet::appenv(\%newenv);
12871: }
1.1 raeburn 12872: } else {
1.86 raeburn 12873: if ($context eq 'requestcourses') {
12874: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 12875: } elsif ($context eq 'requestauthor') {
12876: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12877: } else {
1.90 weissno 12878: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12879: }
1.1 raeburn 12880: }
12881: } else {
1.11 albertel 12882: $resulttext = '<span class="LC_error">'.
12883: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12884: }
1.160.6.30 raeburn 12885: if ($errors) {
12886: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12887: '<ul>'.$errors.'</ul></p>';
12888: }
1.3 raeburn 12889: return $resulttext;
1.1 raeburn 12890: }
12891:
1.160.6.30 raeburn 12892: sub process_textbook_image {
1.160.6.46 raeburn 12893: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 12894: my $filename = $env{'form.'.$caller.'.filename'};
12895: my ($error,$url);
12896: my ($width,$height) = (50,50);
12897: if ($configuserok eq 'ok') {
12898: if ($switchserver) {
12899: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12900: $switchserver);
12901: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12902:23): my $modified = [];
1.160.6.30 raeburn 12903: my ($result,$imageurl) =
1.160.6.118.2 14(raebu 12904:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
12905:23): "$type/$cdom/$cnum/cover",$width,$height,
12906:23): '',$modified);
1.160.6.30 raeburn 12907: if ($result eq 'ok') {
12908: $url = $imageurl;
1.160.6.118.2 14(raebu 12909:23): &update_modify_urls($r,$modified);
1.160.6.30 raeburn 12910: } else {
12911: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12912: }
12913: } else {
12914: $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].",$filename,$confname,$dom,$author_ok);
12915: }
12916: } else {
12917: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$filename,$confname,$dom,$configuserok);
12918: }
12919: return ($url,$error);
12920: }
12921:
1.160.6.118.2 1(raebur 12922:1): sub modify_ltitools {
12923:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14(raebu 12924:23): my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
12925:23): &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
12926:23):
1(raebur 12927:1): my $confname = $dom.'-domainconfig';
12928:1): my $servadm = $r->dir_config('lonAdmEMail');
12929:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14(raebu 12930:23):
12931:23): my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
12932:23): my $toolserror =
12933:23): &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
12934:23): $lastactref,$configuserok,$switchserver,$author_ok);
12935:23):
12936:23): my $home = &Apache::lonnet::domain($dom,'primary');
12937:23): unless (($home eq 'no_host') || ($home eq '')) {
12938:23): my @ids=&Apache::lonnet::current_machine_ids();
12939:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
12940:23): }
12941:23):
12942:23): if (keys(%ltitoolschg)) {
12943:23): foreach my $id (keys(%ltitoolschg)) {
12944:23): if (ref($ltitoolschg{$id}) eq 'HASH') {
12945:23): foreach my $inner (keys(%{$ltitoolschg{$id}})) {
12946:23): if (($inner eq 'secret') || ($inner eq 'key')) {
12947:23): if ($is_home) {
12948:23): $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
12949:23): }
12950:23): }
1(raebur 12951:1): }
14(raebu 12952:23): }
12953:23): }
12954:23): $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
12955:23): if (keys(%ltitoolschg)) {
12956:23): %newltitools = %ltitoolschg;
12957:23): }
12958:23): }
12959:23): if (ref($domconfig{'ltitools'}) eq 'HASH') {
12960:23): foreach my $id (%{$domconfig{'ltitools'}}) {
12961:23): next if ($id !~ /^\d+$/);
12962:23): unless (exists($ltitoolschg{$id})) {
12963:23): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
12964:23): foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
12965:23): if (($inner eq 'secret') || ($inner eq 'key')) {
12966:23): if ($is_home) {
12967:23): $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
12968:23): }
12969:23): } else {
12970:23): $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
12971:23): }
1(raebur 12972:1): }
14(raebu 12973:23): } else {
12974:23): $newltitools{$id} = $domconfig{'ltitools'}{$id};
1(raebur 12975:1): }
12976:1): }
14(raebu 12977:23): }
12978:23): }
12979:23): if ($toolserror) {
12980:23): $errors = '<li>'.$toolserror.'</li>';
12981:23): }
12982:23): if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
12983:23): $resulttext = &mt('No changes made.');
12984:23): if ($errors) {
12985:23): $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
12986:23): $errors.'</ul>';
12987:23): }
12988:23): return $resulttext;
12989:23): }
12990:23): my %ltitoolshash = (
12991:23): $action => { %newltitools }
12992:23): );
12993:23): if (keys(%secchanges)) {
12994:23): $ltitoolshash{'toolsec'} = \%newtoolsec;
12995:23): }
12996:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
12997:23): if ($putresult eq 'ok') {
12998:23): my %keystore;
12999:23): if ($is_home) {
13000:23): my %toolsenchash = (
13001:23): $action => { %newtoolsenc }
13002:23): );
13003:23): &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13004:23): my $cachetime = 24*60*60;
13005:23): &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13006:23): &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13007:23): }
13008:23): $resulttext = &mt('Changes made:').'<ul>';
13009:23): if (keys(%secchanges) > 0) {
13010:23): $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13011:23): }
13012:23): if (keys(%ltitoolschg) > 0) {
13013:23): $resulttext .= $ltitoolsoutput;
13014:23): }
13015:23): my $cachetime = 24*60*60;
13016:23): &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13017:23): if (ref($lastactref) eq 'HASH') {
13018:23): $lastactref->{'ltitools'} = 1;
13019:23): }
13020:23): } else {
13021:23): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13022:23): }
13023:23): if ($errors) {
13024:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13025:23): $errors.'</ul></p>';
13026:23): }
13027:23): return $resulttext;
13028:23): }
13029:23):
13030:23): sub fetch_secrets {
13031:23): my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13032:23): my %keyset;
13033:23): %{$currsec} = ();
13034:23): $newsec->{'private'}{'keys'} = [];
13035:23): $newsec->{'encrypt'} = {};
13036:23): $newsec->{'rules'} = {};
13037:23): if ($context eq 'ltisec') {
13038:23): $newsec->{'linkprot'} = {};
13039:23): }
13040:23): if (ref($domconfig->{$context}) eq 'HASH') {
13041:23): %{$currsec} = %{$domconfig->{$context}};
13042:23): if ($context eq 'ltisec') {
13043:23): if (ref($currsec->{'linkprot'}) eq 'HASH') {
13044:23): foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13045:23): unless ($id =~ /^\d+$/) {
13046:23): delete($currsec->{'linkprot'}{$id});
13047:23): }
13048:23): }
1(raebur 13049:1): }
14(raebu 13050:23): }
13051:23): if (ref($currsec->{'private'}) eq 'HASH') {
13052:23): if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13053:23): $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13054:23): map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1(raebur 13055:1): }
14(raebu 13056:23): }
13057:23): }
13058:23): my @items= ('crs','dom');
13059:23): if ($context eq 'ltisec') {
13060:23): push(@items,'consumers');
13061:23): }
13062:23): foreach my $item (@items) {
13063:23): my $formelement;
13064:23): if (($context eq 'toolsec') || ($item eq 'consumers')) {
13065:23): $formelement = 'form.'.$context.'_'.$item;
13066:23): } else {
13067:23): $formelement = 'form.'.$context.'_'.$item.'linkprot';
13068:23): }
13069:23): if ($env{$formelement}) {
13070:23): $newsec->{'encrypt'}{$item} = 1;
13071:23): if (ref($currsec->{'encrypt'}) eq 'HASH') {
13072:23): unless ($currsec->{'encrypt'}{$item}) {
13073:23): $secchanges->{'encrypt'} = 1;
13074:23): }
1(raebur 13075:1): } else {
14(raebu 13076:23): $secchanges->{'encrypt'} = 1;
13077:23): }
13078:23): } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13079:23): if ($currsec->{'encrypt'}{$item}) {
13080:23): $secchanges->{'encrypt'} = 1;
1(raebur 13081:1): }
14(raebu 13082:23): }
13083:23): }
13084:23): my $secrets;
13085:23): if ($context eq 'ltisec') {
13086:23): $secrets = 'ltisecrets';
13087:23): } else {
13088:23): $secrets = 'toolsecrets';
13089:23): }
13090:23): unless (exists($currsec->{'rules'})) {
13091:23): $currsec->{'rules'} = {};
13092:23): }
13093:23): &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13094:23):
13095:23): my @ids=&Apache::lonnet::current_machine_ids();
13096:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
13097:23):
13098:23): foreach my $hostid (keys(%servers)) {
13099:23): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13100:23): my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13101:23): if (exists($env{$keyitem})) {
13102:23): $env{$keyitem} =~ s/(`)/'/g;
13103:23): if ($keyset{$hostid}) {
13104:23): if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13105:23): if ($env{$keyitem} ne '') {
13106:23): $secchanges->{'private'} = 1;
13107:23): $newkeyset->{$hostid} = $env{$keyitem};
13108:23): }
1(raebur 13109:1): }
14(raebu 13110:23): } elsif ($env{$keyitem} ne '') {
13111:23): unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13112:23): push(@{$newsec->{'private'}{'keys'}},$hostid);
1(raebur 13113:1): }
14(raebu 13114:23): $secchanges->{'private'} = 1;
13115:23): $newkeyset->{$hostid} = $env{$keyitem};
1(raebur 13116:1): }
13117:1): }
14(raebu 13118:23): }
13119:23): }
13120:23): }
13121:23):
13122:23): sub store_security {
13123:23): my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13124:23): return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13125:23): (ref($keystore) eq 'HASH'));
13126:23): if (keys(%{$secchanges})) {
13127:23): if ($secchanges->{'private'}) {
13128:23): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13129:23): foreach my $hostid (keys(%{$newkeyset})) {
13130:23): my $storehash = {
13131:23): key => $newkeyset->{$hostid},
13132:23): who => $env{'user.name'}.':'.$env{'user.domain'},
13133:23): };
13134:23): $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13135:23): $dom,$hostid);
13136:23): }
13137:23): }
13138:23): }
13139:23): }
13140:23):
13141:23): sub lti_security_results {
13142:23): my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13143:23): my $output;
13144:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13145:23): my $needs_update;
13146:23): foreach my $item (keys(%{$secchanges})) {
13147:23): if ($item eq 'encrypt') {
13148:23): $needs_update = 1;
13149:23): my %encrypted;
13150:23): if ($context eq 'lti') {
13151:23): %encrypted = (
13152:23): crs => {
13153:23): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13154:23): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13155:23): },
13156:23): dom => {
13157:23): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13158:23): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13159:23): },
13160:23): consumers => {
13161:23): on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13162:23): off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13163:23): },
13164:23): );
1(raebur 13165:1): } else {
14(raebu 13166:23): %encrypted = (
13167:23): crs => {
13168:23): on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13169:23): off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13170:23): },
13171:23): dom => {
13172:23): on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13173:23): off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13174:23): },
13175:23): );
13176:23):
1(raebur 13177:1): }
14(raebu 13178:23): my @types= ('crs','dom');
13179:23): if ($context eq 'lti') {
13180:23): foreach my $type (@types) {
13181:23): undef($domdefaults{'linkprotenc_'.$type});
1(raebur 13182:1): }
14(raebu 13183:23): push(@types,'consumers');
13184:23): undef($domdefaults{'ltienc_consumers'});
13185:23): } elsif ($context eq 'ltitools') {
13186:23): foreach my $type (@types) {
13187:23): undef($domdefaults{'toolenc_'.$type});
1(raebur 13188:1): }
13189:1): }
14(raebu 13190:23): foreach my $type (@types) {
13191:23): my $shown = $encrypted{$type}{'off'};
13192:23): if (ref($newsec->{$item}) eq 'HASH') {
13193:23): if ($newsec->{$item}{$type}) {
13194:23): if ($context eq 'lti') {
13195:23): if ($type eq 'consumers') {
13196:23): $domdefaults{'ltienc_consumers'} = 1;
13197:23): } else {
13198:23): $domdefaults{'linkprotenc_'.$type} = 1;
1(raebur 13199:1): }
14(raebu 13200:23): } elsif ($context eq 'ltitools') {
13201:23): $domdefaults{'toolenc_'.$type} = 1;
1(raebur 13202:1): }
14(raebu 13203:23): $shown = $encrypted{$type}{'on'};
1(raebur 13204:1): }
13205:1): }
14(raebu 13206:23): $output .= '<li>'.$shown.'</li>';
13207:23): }
13208:23): } elsif ($item eq 'rules') {
13209:23): my %titles = &Apache::lonlocal::texthash(
13210:23): min => 'Minimum password length',
13211:23): max => 'Maximum password length',
13212:23): chars => 'Required characters',
13213:23): );
13214:23): foreach my $rule ('min','max') {
13215:23): if ($newsec->{rules}{$rule} eq '') {
13216:23): if ($rule eq 'min') {
13217:23): $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13218:23): ' '.&mt('Default of [_1] will be used',
13219:23): $Apache::lonnet::passwdmin).'</li>';
13220:23): } else {
13221:23): $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13222:23): }
13223:23): } else {
13224:23): $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13225:23): }
13226:23): }
13227:23): if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13228:23): if (@{$newsec->{'rules'}{'chars'}} > 0) {
13229:23): my %rulenames = &Apache::lonlocal::texthash(
13230:23): uc => 'At least one upper case letter',
13231:23): lc => 'At least one lower case letter',
13232:23): num => 'At least one number',
13233:23): spec => 'At least one non-alphanumeric',
13234:23): );
13235:23): my $needed = '<ul><li>'.
13236:23): join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13237:23): '</li></ul>';
13238:23): $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13239:23): } else {
13240:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13241:23): }
13242:23): } else {
13243:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1(raebur 13244:1): }
14(raebu 13245:23): } elsif ($item eq 'private') {
13246:23): $needs_update = 1;
13247:23): if ($context eq 'lti') {
13248:23): undef($domdefaults{'ltiprivhosts'});
13249:23): } elsif ($context eq 'ltitools') {
13250:23): undef($domdefaults{'toolprivhosts'});
13251:23): }
13252:23): if (keys(%{$newkeyset})) {
13253:23): my @privhosts;
13254:23): foreach my $hostid (sort(keys(%{$newkeyset}))) {
13255:23): if ($keystore->{$hostid} eq 'ok') {
13256:23): $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13257:23): unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13258:23): push(@privhosts,$hostid);
13259:23): }
13260:23): }
13261:23): }
13262:23): if (@privhosts) {
13263:23): if ($context eq 'lti') {
13264:23): $domdefaults{'ltiprivhosts'} = \@privhosts;
13265:23): } elsif ($context eq 'ltitools') {
13266:23): $domdefaults{'toolprivhosts'} = \@privhosts;
1(raebur 13267:1): }
13268:1): }
13269:1): }
14(raebu 13270:23): } elsif ($item eq 'linkprot') {
13271:23): next;
13272:23): }
13273:23): }
13274:23): if ($needs_update) {
13275:23): my $cachetime = 24*60*60;
13276:23): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13277:23): }
13278:23): return $output;
13279:23): }
13280:23):
13281:23): sub modify_lti {
13282:23): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13283:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13284:23): my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13285:23): my (%posslti,%posslticrs,%posscrstype);
13286:23): my @courseroles = ('cc','in','ta','ep','st');
13287:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13288:23): my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13289:23): my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13290:23): my %coursetypetitles = &Apache::lonlocal::texthash (
13291:23): official => 'Official',
13292:23): unofficial => 'Unofficial',
13293:23): community => 'Community',
13294:23): textbook => 'Textbook',
13295:23): placement => 'Placement Test',
13296:23): lti => 'LTI Provider',
13297:23): );
13298:23): my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13299:23): my %lt = <i_names();
13300:23): map { $posslti{$_} = 1; } @ltiroles;
13301:23): map { $posslticrs{$_} = 1; } @lticourseroles;
13302:23): map { $posscrstype{$_} = 1; } @coursetypes;
13303:23):
13304:23): my %menutitles = <imenu_titles();
13305:23): my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13306:23):
13307:23): &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13308:23):
13309:23): my (%linkprotchg,$linkprotoutput,$is_home);
13310:23): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13311:23): \%linkprotchg,'domain');
13312:23): my $home = &Apache::lonnet::domain($dom,'primary');
13313:23): unless (($home eq 'no_host') || ($home eq '')) {
13314:23): my @ids=&Apache::lonnet::current_machine_ids();
13315:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13316:23): }
13317:23):
13318:23): if (keys(%linkprotchg)) {
13319:23): $secchanges{'linkprot'} = 1;
13320:23): my %oldlinkprot;
13321:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13322:23): %oldlinkprot = %{$currltisec{'linkprot'}};
13323:23): }
13324:23): foreach my $id (keys(%linkprotchg)) {
13325:23): if (ref($linkprotchg{$id}) eq 'HASH') {
13326:23): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13327:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13328:23): if ($is_home) {
13329:23): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13330:23): }
13331:23): }
13332:23): }
13333:23): } else {
13334:23): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
1(raebur 13335:1): }
14(raebu 13336:23): }
13337:23): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13338:23): if (keys(%linkprotchg)) {
13339:23): %{$newltisec{'linkprot'}} = %linkprotchg;
13340:23): }
13341:23): }
13342:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13343:23): foreach my $id (%{$currltisec{'linkprot'}}) {
13344:23): next if ($id !~ /^\d+$/);
13345:23): unless (exists($linkprotchg{$id})) {
13346:23): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13347:23): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13348:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13349:23): if ($is_home) {
13350:23): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13351:23): }
13352:23): } else {
13353:23): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13354:23): }
13355:23): }
13356:23): } else {
13357:23): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13358:23): }
1(raebur 13359:1): }
14(raebu 13360:23): }
13361:23): }
13362:23): if ($proterror) {
13363:23): $errors .= '<li>'.$proterror.'</li>';
13364:23): }
13365:23): my (@items,%deletions,%itemids);
13366:23): if ($env{'form.lti_add'}) {
13367:23): my $consumer = $env{'form.lti_consumer_add'};
13368:23): $consumer =~ s/(`)/'/g;
13369:23): ($newid,my $error) = &get_lti_id($dom,$consumer);
13370:23): if ($newid) {
13371:23): $itemids{'add'} = $newid;
13372:23): push(@items,'add');
13373:23): $changes{$newid} = 1;
1(raebur 13374:1): } else {
14(raebu 13375:23): my $error = &mt('Failed to acquire unique ID for new LTI configuration');
1(raebur 13376:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13377:1): }
13378:1): }
13379:1): if (ref($domconfig{$action}) eq 'HASH') {
14(raebu 13380:23): my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
1(raebur 13381:1): if (@todelete) {
13382:1): map { $deletions{$_} = 1; } @todelete;
13383:1): }
14(raebu 13384:23): my $maxnum = $env{'form.lti_maxnum'};
13385:23): for (my $i=0; $i<$maxnum; $i++) {
13386:23): my $itemid = $env{'form.lti_id_'.$i};
1(raebur 13387:1): $itemid =~ s/\D+//g;
13388:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13389:1): if ($deletions{$itemid}) {
14(raebu 13390:23): $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
1(raebur 13391:1): } else {
14(raebu 13392:23): push(@items,$i);
13393:23): $itemids{$i} = $itemid;
13394:23): }
13395:23): }
13396:23): }
13397:23): }
13398:23): my (%keystore,$secstored);
13399:23): if ($is_home) {
13400:23): &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
13401:23): }
13402:23):
13403:23): my ($cipher,$privnum);
13404:23): if ((@items > 0) && ($is_home)) {
13405:23): ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
13406:23): $newltisec{'encrypt'},$keystore{$home});
13407:23): }
13408:23): foreach my $idx (@items) {
13409:23): my $itemid = $itemids{$idx};
13410:23): next unless ($itemid);
13411:23): my %currlti;
13412:23): unless ($idx eq 'add') {
13413:23): if (ref($domconfig{$action}) eq 'HASH') {
13414:23): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13415:23): %currlti = %{$domconfig{$action}{$itemid}};
13416:23): }
13417:23): }
13418:23): }
13419:23): my $position = $env{'form.lti_pos_'.$itemid};
13420:23): $position =~ s/\D+//g;
13421:23): if ($position ne '') {
13422:23): $allpos[$position] = $itemid;
13423:23): }
13424:23): foreach my $item ('consumer','lifetime','requser','crsinc') {
13425:23): my $formitem = 'form.lti_'.$item.'_'.$idx;
13426:23): $env{$formitem} =~ s/(`)/'/g;
13427:23): if ($item eq 'lifetime') {
13428:23): $env{$formitem} =~ s/[^\d.]//g;
13429:23): }
13430:23): if ($env{$formitem} ne '') {
13431:23): $confhash{$itemid}{$item} = $env{$formitem};
13432:23): unless (($idx eq 'add') || ($changes{$itemid})) {
13433:23): if ($currlti{$item} ne $confhash{$itemid}{$item}) {
13434:23): $changes{$itemid} = 1;
13435:23): }
13436:23): }
13437:23): }
13438:23): }
13439:23): if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
13440:23): $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
13441:23): }
13442:23): if ($confhash{$itemid}{'requser'}) {
13443:23): if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
13444:23): $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
13445:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
13446:23): $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
13447:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
13448:23): my $mapuser = $env{'form.lti_customuser_'.$idx};
13449:23): $mapuser =~ s/(`)/'/g;
13450:23): $mapuser =~ s/^\s+|\s+$//g;
13451:23): $confhash{$itemid}{'mapuser'} = $mapuser;
13452:23): }
13453:23): my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
13454:23): my @makeuser;
13455:23): foreach my $ltirole (sort(@possmakeuser)) {
13456:23): if ($posslti{$ltirole}) {
13457:23): push(@makeuser,$ltirole);
13458:23): }
13459:23): }
13460:23): $confhash{$itemid}{'makeuser'} = \@makeuser;
13461:23): if (@makeuser) {
13462:23): my $lcauth = $env{'form.lti_lcauth_'.$idx};
13463:23): if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
13464:23): $confhash{$itemid}{'lcauth'} = $lcauth;
13465:23): if ($lcauth ne 'internal') {
13466:23): my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
13467:23): $lcauthparm =~ s/^(\s+|\s+)$//g;
13468:23): $lcauthparm =~ s/`//g;
13469:23): if ($lcauthparm ne '') {
13470:23): $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
1(raebur 13471:1): }
13472:1): }
14(raebu 13473:23): } else {
13474:23): $confhash{$itemid}{'lcauth'} = 'lti';
13475:23): }
13476:23): }
13477:23): my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
13478:23): if (@possinstdata) {
13479:23): foreach my $field (@possinstdata) {
13480:23): if (exists($fieldtitles{$field})) {
13481:23): push(@{$confhash{$itemid}{'instdata'}});
13482:23): }
13483:23): }
13484:23): }
13485:23): if ($env{'form.lti_callback_'.$idx}) {
13486:23): if ($env{'form.lti_callbackparam_'.$idx}) {
13487:23): my $callback = $env{'form.lti_callbackparam_'.$idx};
13488:23): $callback =~ s/^\s+|\s+$//g;
13489:23): $confhash{$itemid}{'callback'} = $callback;
13490:23): }
13491:23): }
13492:23): foreach my $field ('topmenu','inlinemenu') {
13493:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
13494:23): $confhash{$itemid}{$field} = 1;
13495:23): }
13496:23): }
13497:23): if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
13498:23): $confhash{$itemid}{lcmenu} = [];
13499:23): my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
13500:23): foreach my $field (@possmenu) {
13501:23): if (exists($menutitles{$field})) {
13502:23): if ($field eq 'grades') {
13503:23): next unless ($env{'form.lti_inlinemenu_'.$idx});
1(raebur 13504:1): }
14(raebu 13505:23): push(@{$confhash{$itemid}{lcmenu}},$field);
13506:23): }
13507:23): }
13508:23): }
13509:23): if ($confhash{$itemid}{'crsinc'}) {
13510:23): if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
13511:23): ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
13512:23): $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
13513:23): } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
13514:23): my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
13515:23): $mapcrs =~ s/(`)/'/g;
13516:23): $mapcrs =~ s/^\s+|\s+$//g;
13517:23): $confhash{$itemid}{'mapcrs'} = $mapcrs;
13518:23): }
13519:23): my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
13520:23): my @crstypes;
13521:23): foreach my $type (sort(@posstypes)) {
13522:23): if ($posscrstype{$type}) {
13523:23): push(@crstypes,$type);
13524:23): }
13525:23): }
13526:23): $confhash{$itemid}{'mapcrstype'} = \@crstypes;
13527:23): if ($env{'form.lti_storecrs_'.$idx}) {
13528:23): $confhash{$itemid}{'storecrs'} = 1;
13529:23): }
13530:23): if ($env{'form.lti_makecrs_'.$idx}) {
13531:23): $confhash{$itemid}{'makecrs'} = 1;
13532:23): }
13533:23): foreach my $ltirole (@lticourseroles) {
13534:23): my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
13535:23): if (grep(/^\Q$possrole\E$/,@courseroles)) {
13536:23): $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
1(raebur 13537:1): }
14(raebu 13538:23): }
13539:23): my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
13540:23): my @selfenroll;
13541:23): foreach my $type (sort(@possenroll)) {
13542:23): if ($posslticrs{$type}) {
13543:23): push(@selfenroll,$type);
13544:23): }
13545:23): }
13546:23): $confhash{$itemid}{'selfenroll'} = \@selfenroll;
13547:23): if ($env{'form.lti_crssec_'.$idx}) {
13548:23): if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
13549:23): $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
13550:23): } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
13551:23): my $section = $env{'form.lti_customsection_'.$idx};
13552:23): $section =~ s/(`)/'/g;
13553:23): $section =~ s/^\s+|\s+$//g;
13554:23): if ($section ne '') {
13555:23): $confhash{$itemid}{'section'} = $section;
13556:23): }
1(raebur 13557:1): }
14(raebu 13558:23): }
13559:23): foreach my $field ('passback','roster') {
13560:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
13561:23): $confhash{$itemid}{$field} = 1;
1(raebur 13562:1): }
14(raebu 13563:23): }
13564:23): if ($env{'form.lti_passback_'.$idx}) {
13565:23): if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
13566:23): $confhash{$itemid}{'passbackformat'} = '1.0';
1(raebur 13567:1): } else {
14(raebu 13568:23): $confhash{$itemid}{'passbackformat'} = '1.1';
1(raebur 13569:1): }
14(raebu 13570:23): }
13571:23): }
13572:23): unless (($idx eq 'add') || ($changes{$itemid})) {
13573:23): if ($confhash{$itemid}{'crsinc'}) {
13574:23): foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
13575:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1(raebur 13576:1): $changes{$itemid} = 1;
13577:1): }
13578:1): }
14(raebu 13579:23): unless ($changes{$itemid}) {
13580:23): if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
13581:23): if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1(raebur 13582:1): $changes{$itemid} = 1;
13583:1): }
13584:1): }
13585:1): }
14(raebu 13586:23): foreach my $field ('mapcrstype','selfenroll') {
13587:23): unless ($changes{$itemid}) {
13588:23): if (ref($currlti{$field}) eq 'ARRAY') {
13589:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13590:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
13591:23): $confhash{$itemid}{$field});
13592:23): if (@diffs) {
13593:23): $changes{$itemid} = 1;
13594:23): }
13595:23): } elsif (@{$currlti{$field}} > 0) {
1(raebur 13596:1): $changes{$itemid} = 1;
13597:1): }
14(raebu 13598:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13599:23): if (@{$confhash{$itemid}{$field}} > 0) {
1(raebur 13600:1): $changes{$itemid} = 1;
13601:1): }
13602:1): }
13603:1): }
13604:1): }
14(raebu 13605:23): unless ($changes{$itemid}) {
13606:23): if (ref($currlti{'maproles'}) eq 'HASH') {
13607:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13608:23): foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
13609:23): if ($currlti{'maproles'}{$ltirole} ne
13610:23): $confhash{$itemid}{'maproles'}{$ltirole}) {
13611:23): $changes{$itemid} = 1;
13612:23): last;
1(raebur 13613:1): }
14(raebu 13614:23): }
13615:23): unless ($changes{$itemid}) {
13616:23): foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
13617:23): if ($confhash{$itemid}{'maproles'}{$ltirole} ne
13618:23): $currlti{'maproles'}{$ltirole}) {
1(raebur 13619:1): $changes{$itemid} = 1;
14(raebu 13620:23): last;
1(raebur 13621:1): }
13622:1): }
13623:1): }
14(raebu 13624:23): } elsif (keys(%{$currlti{'maproles'}}) > 0) {
13625:23): $changes{$itemid} = 1;
13626:23): }
13627:23): } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13628:23): unless ($changes{$itemid}) {
13629:23): if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
1(raebur 13630:1): $changes{$itemid} = 1;
13631:1): }
13632:1): }
13633:1): }
13634:1): }
14(raebu 13635:23): }
13636:23): unless ($changes{$itemid}) {
13637:23): foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
13638:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
13639:23): $changes{$itemid} = 1;
13640:23): }
13641:23): }
13642:23): unless ($changes{$itemid}) {
13643:23): foreach my $field ('makeuser','lcmenu') {
13644:23): if (ref($currlti{$field}) eq 'ARRAY') {
13645:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13646:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
13647:23): $confhash{$itemid}{$field});
13648:23): if (@diffs) {
13649:23): $changes{$itemid} = 1;
13650:23): }
13651:23): } elsif (@{$currlti{$field}} > 0) {
13652:23): $changes{$itemid} = 1;
13653:23): }
13654:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13655:23): if (@{$confhash{$itemid}{$field}} > 0) {
13656:23): $changes{$itemid} = 1;
13657:23): }
1(raebur 13658:1): }
13659:1): }
13660:1): }
13661:1): }
14(raebu 13662:23): }
13663:23): }
13664:23): if ($is_home) {
13665:23): my $keyitem = 'form.lti_key_'.$idx;
13666:23): $env{$keyitem} =~ s/(`)/'/g;
13667:23): if ($env{$keyitem} ne '') {
13668:23): $ltienc{$itemid}{'key'} = $env{$keyitem};
13669:23): unless ($changes{$itemid}) {
13670:23): if ($currlti{'key'} ne $env{$keyitem}) {
1(raebur 13671:1): $changes{$itemid} = 1;
13672:1): }
14(raebu 13673:23): }
13674:23): }
13675:23): my $secretitem = 'form.lti_secret_'.$idx;
13676:23): $env{$secretitem} =~ s/(`)/'/g;
13677:23): if ($currlti{'usable'}) {
13678:23): if ($env{'form.lti_changesecret_'.$idx}) {
13679:23): if ($env{$secretitem} ne '') {
13680:23): if ($privnum && $cipher) {
13681:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
13682:23): $confhash{$itemid}{'cipher'} = $privnum;
13683:23): } else {
13684:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
13685:23): }
1(raebur 13686:1): $changes{$itemid} = 1;
13687:1): }
14(raebu 13688:23): } else {
13689:23): $ltienc{$itemid}{'secret'} = $currlti{'secret'};
13690:23): $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
1(raebur 13691:1): }
14(raebu 13692:23): if (ref($ltienc{$itemid}) eq 'HASH') {
13693:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
13694:23): $confhash{$itemid}{'usable'} = 1;
13695:23): }
1(raebur 13696:1): }
14(raebu 13697:23): } elsif ($env{$secretitem} ne '') {
13698:23): if ($privnum && $cipher) {
13699:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
13700:23): $confhash{$itemid}{'cipher'} = $privnum;
13701:23): } else {
13702:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
13703:23): }
13704:23): if (ref($ltienc{$itemid}) eq 'HASH') {
13705:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
13706:23): $confhash{$itemid}{'usable'} = 1;
1(raebur 13707:1): }
13708:1): }
14(raebu 13709:23): $changes{$itemid} = 1;
13710:23): }
13711:23): }
13712:23): unless ($changes{$itemid}) {
13713:23): foreach my $key (keys(%currlti)) {
13714:23): if (ref($currlti{$key}) eq 'HASH') {
13715:23): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13716:23): foreach my $innerkey (keys(%{$currlti{$key}})) {
13717:23): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
1(raebur 13718:1): $changes{$itemid} = 1;
14(raebu 13719:23): last;
1(raebur 13720:1): }
13721:1): }
14(raebu 13722:23): } elsif (keys(%{$currlti{$key}}) > 0) {
13723:23): $changes{$itemid} = 1;
1(raebur 13724:1): }
13725:1): }
14(raebu 13726:23): last if ($changes{$itemid});
1(raebur 13727:1): }
13728:1): }
13729:1): }
13730:1): if (@allpos > 0) {
13731:1): my $idx = 0;
13732:1): foreach my $itemid (@allpos) {
13733:1): if ($itemid ne '') {
13734:1): $confhash{$itemid}{'order'} = $idx;
13735:1): if (ref($domconfig{$action}) eq 'HASH') {
13736:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13737:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13738:1): $changes{$itemid} = 1;
13739:1): }
13740:1): }
13741:1): }
13742:1): $idx ++;
13743:1): }
13744:1): }
13745:1): }
14(raebu 13746:23):
13747:23): if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
13748:23): return &mt('No changes made.');
13749:23): }
13750:23):
13751:23): my %ltihash = (
13752:23): $action => { %confhash }
13753:23): );
13754:23): my %ltienchash;
13755:23):
13756:23): if ($is_home) {
13757:23): %ltienchash = (
13758:23): $action => { %ltienc }
13759:23): );
13760:23): }
13761:23): if (keys(%secchanges)) {
13762:23): $ltihash{'ltisec'} = \%newltisec;
13763:23): if ($secchanges{'linkprot'}) {
13764:23): if ($is_home) {
13765:23): $ltienchash{'linkprot'} = \%newltienc;
13766:23): }
13767:23): }
13768:23): }
13769:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1(raebur 13770:1): if ($putresult eq 'ok') {
14(raebu 13771:23): if (keys(%ltienchash)) {
13772:23): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13773:23): }
13774:23): $resulttext = &mt('Changes made:').'<ul>';
13775:23): if (keys(%secchanges) > 0) {
13776:23): $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
13777:23): if (exists($secchanges{'linkprot'})) {
13778:23): $resulttext .= $linkprotoutput;
13779:23): }
13780:23): }
1(raebur 13781:1): if (keys(%changes) > 0) {
13782:1): my $cachetime = 24*60*60;
14(raebu 13783:23): &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1(raebur 13784:1): if (ref($lastactref) eq 'HASH') {
14(raebu 13785:23): $lastactref->{'lti'} = 1;
1(raebur 13786:1): }
13787:1): my %bynum;
13788:1): foreach my $itemid (sort(keys(%changes))) {
14(raebu 13789:23): if (ref($confhash{$itemid}) eq 'HASH') {
13790:23): my $position = $confhash{$itemid}{'order'};
13791:23): $bynum{$position} = $itemid;
13792:23): }
1(raebur 13793:1): }
13794:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13795:1): my $itemid = $bynum{$pos};
14(raebu 13796:23): if (ref($confhash{$itemid}) eq 'HASH') {
13797:23): $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1(raebur 13798:1): my $position = $pos + 1;
13799:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14(raebu 13800:23): foreach my $item ('version','lifetime') {
1(raebur 13801:1): if ($confhash{$itemid}{$item} ne '') {
13802:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13803:1): }
13804:1): }
14(raebu 13805:23): if ($ltienc{$itemid}{'key'} ne '') {
13806:23): $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
13807:23): }
13808:23): if ($ltienc{$itemid}{'secret'} ne '') {
13809:23): $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1(raebur 13810:1): }
14(raebu 13811:23): if ($confhash{$itemid}{'requser'}) {
13812:23): if ($confhash{$itemid}{'callback'}) {
13813:23): $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
13814:23): } else {
13815:23): $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
13816:23): }
13817:23): if ($confhash{$itemid}{'mapuser'}) {
13818:23): my $shownmapuser;
13819:23): if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
13820:23): $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
13821:23): } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
13822:23): $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
13823:23): } else {
13824:23): $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
13825:23): }
13826:23): $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
13827:23): }
13828:23): if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
13829:23): if (@{$confhash{$itemid}{'makeuser'}} > 0) {
13830:23): $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
13831:23): join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
13832:23): if ($confhash{$itemid}{'lcauth'} eq 'lti') {
13833:23): $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
13834:23): } else {
13835:23): $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
13836:23): $confhash{$itemid}{'lcauth'});
13837:23): if ($confhash{$itemid}{'lcauth'} eq 'internal') {
13838:23): $resulttext .= '; '.&mt('a randomly generated password will be created');
13839:23): } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
13840:23): if ($confhash{$itemid}{'lcauthparm'} ne '') {
13841:23): $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
13842:23): }
13843:23): } else {
13844:23): $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
13845:23): }
13846:23): }
13847:23): $resulttext .= '</li>';
13848:23): } else {
13849:23): $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
1(raebur 13850:1): }
13851:1): }
14(raebu 13852:23): if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
13853:23): if (@{$confhash{$itemid}{'instdata'}} > 0) {
13854:23): $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
13855:23): join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
13856:23): } else {
13857:23): $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1(raebur 13858:1): }
13859:1): }
14(raebu 13860:23): foreach my $item ('topmenu','inlinemenu') {
13861:23): $resulttext .= '<li>'.$lt{$item}.': ';
13862:23): if ($confhash{$itemid}{$item}) {
13863:23): $resulttext .= &mt('Yes');
13864:23): } else {
13865:23): $resulttext .= &mt('No');
1(raebur 13866:1): }
14(raebu 13867:23): $resulttext .= '</li>';
1(raebur 13868:1): }
14(raebu 13869:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
13870:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
13871:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
13872:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
13873:23): } else {
13874:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
1(raebur 13875:1): }
13876:1): }
14(raebu 13877:23): if ($confhash{$itemid}{'crsinc'}) {
13878:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13879:23): my $rolemaps;
13880:23): foreach my $role (@ltiroles) {
13881:23): if ($confhash{$itemid}{'maproles'}{$role}) {
13882:23): $rolemaps .= (' 'x2).$role.'='.
13883:23): &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
13884:23): 'Course').',';
13885:23): }
13886:23): }
13887:23): if ($rolemaps) {
13888:23): $rolemaps =~ s/,$//;
13889:23): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
13890:23): }
13891:23): }
13892:23): if ($confhash{$itemid}{'mapcrs'}) {
13893:23): $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
13894:23): }
13895:23): if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
13896:23): if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
13897:23): $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
13898:23): join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
13899:23): '</li>';
1(raebur 13900:1): } else {
14(raebu 13901:23): $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
1(raebur 13902:1): }
13903:1): }
14(raebu 13904:23): if ($confhash{$itemid}{'storecrs'}) {
13905:23): $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
1(raebur 13906:1): }
14(raebu 13907:23): if ($confhash{$itemid}{'makecrs'}) {
13908:23): $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
13909:23): } else {
13910:23): $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
13911:23): }
13912:23): if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
13913:23): if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
13914:23): $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
13915:23): join(', ',@{$confhash{$itemid}{'selfenroll'}})).
13916:23): '</li>';
13917:23): } else {
13918:23): $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
13919:23): }
13920:23): }
13921:23): if ($confhash{$itemid}{'section'}) {
13922:23): if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
13923:23): $resulttext .= '<li>'.&mt('User section from standard field:').
13924:23): ' (course_section_sourcedid)'.'</li>';
13925:23): } else {
13926:23): $resulttext .= '<li>'.&mt('User section from:').' '.
13927:23): $confhash{$itemid}{'section'}.'</li>';
13928:23): }
13929:23): } else {
13930:23): $resulttext .= '<li>'.&mt('No section assignment').'</li>';
13931:23): }
13932:23): foreach my $item ('passback','roster','topmenu','inlinemenu') {
13933:23): $resulttext .= '<li>'.$lt{$item}.': ';
13934:23): if ($confhash{$itemid}{$item}) {
13935:23): $resulttext .= &mt('Yes');
13936:23): if ($item eq 'passback') {
13937:23): if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
13938:23): $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
13939:23): } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
13940:23): $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
13941:23): }
13942:23): }
13943:23): } else {
13944:23): $resulttext .= &mt('No');
13945:23): }
13946:23): $resulttext .= '</li>';
13947:23): }
13948:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
13949:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
13950:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
13951:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
13952:23): } else {
13953:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
13954:23): }
1(raebur 13955:1): }
13956:1): }
13957:1): }
13958:1): $resulttext .= '</ul></li>';
13959:1): }
13960:1): }
14(raebu 13961:23): if (keys(%deletions)) {
13962:23): foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
13963:23): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
13964:23): }
13965:23): }
13966:23): }
13967:23): $resulttext .= '</ul>';
13968:23): if (ref($lastactref) eq 'HASH') {
13969:23): if (($secchanges{'encrypt'}) || ($secchanges{'private'})) {
13970:23): $lastactref->{'domdefaults'} = 1;
13971:23): }
1(raebur 13972:1): }
13973:1): } else {
13974:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13975:1): }
13976:1): if ($errors) {
13977:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
13978:1): $errors.'</ul>';
13979:1): }
13980:1): return $resulttext;
13981:1): }
13982:1):
14(raebu 13983:23): sub get_priv_creds {
13984:23): my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
13985:23): my ($needenc,$cipher,$privnum);
13986:23): my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
13987:23): if (($encchg) && (ref($encrypt) eq 'HASH')) {
13988:23): $needenc = $encrypt->{'consumers'}
13989:23): } else {
13990:23): $needenc = $domdefs{'ltienc_consumers'};
13991:23): }
13992:23): if ($needenc) {
13993:23): if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
13994:23): (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
13995:23): my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
13996:23): my $privkey = $privhash{'key'};
13997:23): $privnum = $privhash{'version'};
13998:23): if (($privnum) && ($privkey ne '')) {
13999:23): $cipher = Crypt::CBC->new({'key' => $privkey,
14000:23): 'cipher' => 'DES'});
1(raebur 14001:1): }
14002:1): }
14003:1): }
14(raebu 14004:23): return ($cipher,$privnum);
1(raebur 14005:1): }
14006:1):
14(raebu 14007:23): sub get_lti_id {
14008:23): my ($domain,$consumer) = @_;
14009:23): # get lock on lti db
1(raebur 14010:1): my $lockhash = {
14011:1): lock => $env{'user.name'}.
14012:1): ':'.$env{'user.domain'},
14013:1): };
14014:1): my $tries = 0;
14(raebu 14015:23): my $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
1(raebur 14016:1): my ($id,$error);
14017:1):
14018:1): while (($gotlock ne 'ok') && ($tries<10)) {
14019:1): $tries ++;
14020:1): sleep (0.1);
14(raebu 14021:23): $gotlock = &Apache::lonnet::newput_dom('lti',$lockhash,$domain);
1(raebur 14022:1): }
14023:1): if ($gotlock eq 'ok') {
14(raebu 14024:23): my %currids = &Apache::lonnet::dump_dom('lti',$domain);
1(raebur 14025:1): if ($currids{'lock'}) {
14026:1): delete($currids{'lock'});
14027:1): if (keys(%currids)) {
14028:1): my @curr = sort { $a <=> $b } keys(%currids);
14029:1): if ($curr[-1] =~ /^\d+$/) {
14030:1): $id = 1 + $curr[-1];
14031:1): }
14032:1): } else {
14033:1): $id = 1;
14034:1): }
14035:1): if ($id) {
14(raebu 14036:23): unless (&Apache::lonnet::newput_dom('lti',{ $id => $consumer },$domain) eq 'ok') {
1(raebur 14037:1): $error = 'nostore';
14038:1): }
14039:1): } else {
14040:1): $error = 'nonumber';
14041:1): }
14042:1): }
14(raebu 14043:23): my $dellockoutcome = &Apache::lonnet::del_dom('lti',['lock'],$domain);
1(raebur 14044:1): } else {
14045:1): $error = 'nolock';
14046:1): }
14047:1): return ($id,$error);
14048:1): }
14049:1):
1.3 raeburn 14050: sub modify_autoenroll {
1.160.6.24 raeburn 14051: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14052: my ($resulttext,%changes);
14053: my %currautoenroll;
14054: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14055: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14056: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14057: }
14058: }
14059: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14060: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14061: sender => 'Sender for notification messages',
1.160.6.68 raeburn 14062: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 14063: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14064: my @offon = ('off','on');
1.17 raeburn 14065: my $sender_uname = $env{'form.sender_uname'};
14066: my $sender_domain = $env{'form.sender_domain'};
14067: if ($sender_domain eq '') {
14068: $sender_uname = '';
14069: } elsif ($sender_uname eq '') {
14070: $sender_domain = '';
14071: }
1.129 raeburn 14072: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 14073: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14074: $autofailsafe =~ s{^\s+|\s+$}{}g;
14075: if ($autofailsafe =~ /\D/) {
14076: undef($autofailsafe);
14077: }
1.160.6.68 raeburn 14078: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 14079: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14080: $failsafe = 'off';
14081: undef($autofailsafe);
1.160.6.68 raeburn 14082: }
1.1 raeburn 14083: my %autoenrollhash = (
1.129 raeburn 14084: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14085: 'sender_uname' => $sender_uname,
14086: 'sender_domain' => $sender_domain,
14087: 'co-owners' => $coowners,
1.160.6.116 raeburn 14088: 'autofailsafe' => $autofailsafe,
14089: 'failsafe' => $failsafe,
1.1 raeburn 14090: }
14091: );
1.4 raeburn 14092: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14093: $dom);
1.1 raeburn 14094: if ($putresult eq 'ok') {
14095: if (exists($currautoenroll{'run'})) {
14096: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14097: $changes{'run'} = 1;
14098: }
14099: } elsif ($autorun) {
14100: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14101: $changes{'run'} = 1;
1.1 raeburn 14102: }
14103: }
1.17 raeburn 14104: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14105: $changes{'sender'} = 1;
14106: }
1.17 raeburn 14107: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14108: $changes{'sender'} = 1;
14109: }
1.129 raeburn 14110: if ($currautoenroll{'co-owners'} ne '') {
14111: if ($currautoenroll{'co-owners'} ne $coowners) {
14112: $changes{'coowners'} = 1;
14113: }
14114: } elsif ($coowners) {
14115: $changes{'coowners'} = 1;
1.160.6.68 raeburn 14116: }
1.160.6.116 raeburn 14117: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 14118: $changes{'autofailsafe'} = 1;
14119: }
1.160.6.116 raeburn 14120: if ($currautoenroll{'failsafe'} ne $failsafe) {
14121: $changes{'failsafe'} = 1;
14122: }
1.1 raeburn 14123: if (keys(%changes) > 0) {
14124: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14125: if ($changes{'run'}) {
1.1 raeburn 14126: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14127: }
14128: if ($changes{'sender'}) {
1.17 raeburn 14129: if ($sender_uname eq '' || $sender_domain eq '') {
14130: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14131: } else {
14132: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14133: }
1.1 raeburn 14134: }
1.129 raeburn 14135: if ($changes{'coowners'}) {
14136: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14137: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14138: if (ref($lastactref) eq 'HASH') {
14139: $lastactref->{'domainconfig'} = 1;
14140: }
1.129 raeburn 14141: }
1.160.6.68 raeburn 14142: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 14143: if ($autofailsafe ne '') {
14144: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 14145: } else {
1.160.6.116 raeburn 14146: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 14147: }
1.160.6.116 raeburn 14148: }
14149: if ($changes{'failsafe'}) {
14150: if ($failsafe eq 'off') {
14151: unless ($changes{'autofailsafe'}) {
14152: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14153: }
14154: } elsif ($failsafe eq 'zero') {
14155: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14156: } else {
14157: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14158: }
14159: }
14160: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 14161: &Apache::lonnet::get_domain_defaults($dom,1);
14162: if (ref($lastactref) eq 'HASH') {
14163: $lastactref->{'domdefaults'} = 1;
14164: }
14165: }
1.1 raeburn 14166: $resulttext .= '</ul>';
14167: } else {
14168: $resulttext = &mt('No changes made to auto-enrollment settings');
14169: }
14170: } else {
1.11 albertel 14171: $resulttext = '<span class="LC_error">'.
14172: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14173: }
1.3 raeburn 14174: return $resulttext;
1.1 raeburn 14175: }
14176:
14177: sub modify_autoupdate {
1.3 raeburn 14178: my ($dom,%domconfig) = @_;
1.1 raeburn 14179: my ($resulttext,%currautoupdate,%fields,%changes);
14180: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14181: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14182: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14183: }
14184: }
14185: my @offon = ('off','on');
14186: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 14187: run => 'Auto-update:',
14188: classlists => 'Updates to user information in classlists?',
14189: unexpired => 'Skip updates for users without active or future roles?',
14190: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 14191: );
1.44 raeburn 14192: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14193: my %fieldtitles = &Apache::lonlocal::texthash (
14194: id => 'Student/Employee ID',
1.20 raeburn 14195: permanentemail => 'E-mail address',
1.1 raeburn 14196: lastname => 'Last Name',
14197: firstname => 'First Name',
14198: middlename => 'Middle Name',
1.132 raeburn 14199: generation => 'Generation',
1.1 raeburn 14200: );
1.142 raeburn 14201: $othertitle = &mt('All users');
1.1 raeburn 14202: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14203: $othertitle = &mt('Other users');
1.1 raeburn 14204: }
14205: foreach my $key (keys(%env)) {
14206: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14207: my ($usertype,$item) = ($1,$2);
14208: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14209: if ($usertype eq 'default') {
14210: push(@{$fields{$1}},$2);
14211: } elsif (ref($types) eq 'ARRAY') {
14212: if (grep(/^\Q$usertype\E$/,@{$types})) {
14213: push(@{$fields{$1}},$2);
14214: }
14215: }
14216: }
1.1 raeburn 14217: }
14218: }
1.131 raeburn 14219: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14220: @lockablenames = sort(@lockablenames);
14221: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14222: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14223: if (@changed) {
14224: $changes{'lockablenames'} = 1;
14225: }
14226: } else {
14227: if (@lockablenames) {
14228: $changes{'lockablenames'} = 1;
14229: }
14230: }
1.1 raeburn 14231: my %updatehash = (
14232: autoupdate => { run => $env{'form.autoupdate_run'},
14233: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 14234: unexpired => $env{'form.unexpired'},
1.1 raeburn 14235: fields => {%fields},
1.131 raeburn 14236: lockablenames => \@lockablenames,
1.1 raeburn 14237: }
14238: );
1.160.6.113 raeburn 14239: my $lastactivedays;
14240: if ($env{'form.lastactive'}) {
14241: $lastactivedays = $env{'form.lastactivedays'};
14242: $lastactivedays =~ s/^\s+|\s+$//g;
14243: unless ($lastactivedays =~ /^\d+$/) {
14244: undef($lastactivedays);
14245: $env{'form.lastactive'} = 0;
14246: }
14247: }
14248: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 14249: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 14250: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 14251: if (exists($updatehash{autoupdate}{$key})) {
14252: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14253: $changes{$key} = 1;
14254: }
14255: }
14256: } elsif ($key eq 'fields') {
14257: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14258: foreach my $item (@{$types},'default') {
1.1 raeburn 14259: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14260: my $change = 0;
14261: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14262: if (!exists($fields{$item})) {
14263: $change = 1;
1.132 raeburn 14264: last;
1.1 raeburn 14265: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14266: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14267: $change = 1;
1.132 raeburn 14268: last;
1.1 raeburn 14269: }
14270: }
14271: }
14272: if ($change) {
14273: push(@{$changes{$key}},$item);
14274: }
1.26 raeburn 14275: }
1.1 raeburn 14276: }
14277: }
1.131 raeburn 14278: } elsif ($key eq 'lockablenames') {
14279: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14280: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14281: if (@changed) {
14282: $changes{'lockablenames'} = 1;
14283: }
14284: } else {
14285: if (@lockablenames) {
14286: $changes{'lockablenames'} = 1;
14287: }
14288: }
14289: }
14290: }
14291: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14292: if (@lockablenames) {
14293: $changes{'lockablenames'} = 1;
1.1 raeburn 14294: }
14295: }
1.160.6.113 raeburn 14296: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
14297: if ($updatehash{'autoupdate'}{'unexpired'}) {
14298: $changes{'unexpired'} = 1;
14299: }
14300: }
14301: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
14302: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
14303: $changes{'lastactive'} = 1;
14304: }
14305: }
1.26 raeburn 14306: foreach my $item (@{$types},'default') {
14307: if (defined($fields{$item})) {
14308: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 14309: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14310: my $change = 0;
14311: if (ref($fields{$item}) eq 'ARRAY') {
14312: foreach my $type (@{$fields{$item}}) {
14313: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14314: $change = 1;
14315: last;
14316: }
14317: }
14318: }
14319: if ($change) {
14320: push(@{$changes{'fields'}},$item);
14321: }
14322: } else {
1.26 raeburn 14323: push(@{$changes{'fields'}},$item);
14324: }
14325: } else {
14326: push(@{$changes{'fields'}},$item);
1.1 raeburn 14327: }
14328: }
14329: }
14330: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
14331: $dom);
14332: if ($putresult eq 'ok') {
14333: if (keys(%changes) > 0) {
14334: $resulttext = &mt('Changes made:').'<ul>';
14335: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 14336: if ($key eq 'lockablenames') {
14337: $resulttext .= '<li>';
14338: if (@lockablenames) {
14339: $usertypes->{'default'} = $othertitle;
14340: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
14341: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
14342: } else {
14343: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
14344: }
14345: $resulttext .= '</li>';
14346: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 14347: foreach my $item (@{$changes{$key}}) {
14348: my @newvalues;
14349: foreach my $type (@{$fields{$item}}) {
14350: push(@newvalues,$fieldtitles{$type});
14351: }
1.3 raeburn 14352: my $newvaluestr;
14353: if (@newvalues > 0) {
14354: $newvaluestr = join(', ',@newvalues);
14355: } else {
14356: $newvaluestr = &mt('none');
1.6 raeburn 14357: }
1.1 raeburn 14358: if ($item eq 'default') {
1.26 raeburn 14359: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 14360: } else {
1.26 raeburn 14361: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 14362: }
14363: }
14364: } else {
14365: my $newvalue;
14366: if ($key eq 'run') {
14367: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 14368: } elsif ($key eq 'lastactive') {
14369: $newvalue = $offon[$env{'form.lastactive'}];
14370: unless ($lastactivedays eq '') {
14371: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
14372: }
1.1 raeburn 14373: } else {
14374: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 14375: }
1.1 raeburn 14376: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
14377: }
14378: }
14379: $resulttext .= '</ul>';
14380: } else {
1.3 raeburn 14381: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 14382: }
14383: } else {
1.11 albertel 14384: $resulttext = '<span class="LC_error">'.
14385: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14386: }
1.3 raeburn 14387: return $resulttext;
1.1 raeburn 14388: }
14389:
1.125 raeburn 14390: sub modify_autocreate {
14391: my ($dom,%domconfig) = @_;
14392: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
14393: if (ref($domconfig{'autocreate'}) eq 'HASH') {
14394: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
14395: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
14396: }
14397: }
14398: my %title= ( xml => 'Auto-creation of courses in XML course description files',
14399: req => 'Auto-creation of validated requests for official courses',
14400: xmldc => 'Identity of course creator of courses from XML files',
14401: );
14402: my @types = ('xml','req');
14403: foreach my $item (@types) {
14404: $newvals{$item} = $env{'form.autocreate_'.$item};
14405: $newvals{$item} =~ s/\D//g;
14406: $newvals{$item} = 0 if ($newvals{$item} eq '');
14407: }
14408: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 14409: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 14410: unless (exists($domcoords{$newvals{'xmldc'}})) {
14411: $newvals{'xmldc'} = '';
14412: }
14413: %autocreatehash = (
14414: autocreate => { xml => $newvals{'xml'},
14415: req => $newvals{'req'},
14416: }
14417: );
14418: if ($newvals{'xmldc'} ne '') {
14419: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
14420: }
14421: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
14422: $dom);
14423: if ($putresult eq 'ok') {
14424: my @items = @types;
14425: if ($newvals{'xml'}) {
14426: push(@items,'xmldc');
14427: }
14428: foreach my $item (@items) {
14429: if (exists($currautocreate{$item})) {
14430: if ($currautocreate{$item} ne $newvals{$item}) {
14431: $changes{$item} = 1;
14432: }
14433: } elsif ($newvals{$item}) {
14434: $changes{$item} = 1;
14435: }
14436: }
14437: if (keys(%changes) > 0) {
14438: my @offon = ('off','on');
14439: $resulttext = &mt('Changes made:').'<ul>';
14440: foreach my $item (@types) {
14441: if ($changes{$item}) {
14442: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 14443: $resulttext .= '<li>'.
14444: &mt("$title{$item} set to [_1]$newtxt [_2]",
14445: '<b>','</b>').
14446: '</li>';
1.125 raeburn 14447: }
14448: }
14449: if ($changes{'xmldc'}) {
14450: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
14451: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 14452: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 14453: }
14454: $resulttext .= '</ul>';
14455: } else {
14456: $resulttext = &mt('No changes made to auto-creation settings');
14457: }
14458: } else {
14459: $resulttext = '<span class="LC_error">'.
14460: &mt('An error occurred: [_1]',$putresult).'</span>';
14461: }
14462: return $resulttext;
14463: }
14464:
1.23 raeburn 14465: sub modify_directorysrch {
1.160.6.81 raeburn 14466: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 14467: my ($resulttext,%changes);
14468: my %currdirsrch;
14469: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
14470: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
14471: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
14472: }
14473: }
1.160.6.72 raeburn 14474: my %title = ( available => 'Institutional directory search available',
14475: localonly => 'Other domains can search institution',
14476: lcavailable => 'LON-CAPA directory search available',
14477: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 14478: searchby => 'Search types',
14479: searchtypes => 'Search latitude');
14480: my @offon = ('off','on');
1.24 raeburn 14481: my @otherdoms = ('Yes','No');
1.23 raeburn 14482:
1.25 raeburn 14483: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 14484: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
14485: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
14486:
1.44 raeburn 14487: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 14488: if (keys(%{$usertypes}) == 0) {
14489: @cansearch = ('default');
14490: } else {
14491: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
14492: foreach my $type (@{$currdirsrch{'cansearch'}}) {
14493: if (!grep(/^\Q$type\E$/,@cansearch)) {
14494: push(@{$changes{'cansearch'}},$type);
14495: }
1.23 raeburn 14496: }
1.26 raeburn 14497: foreach my $type (@cansearch) {
14498: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
14499: push(@{$changes{'cansearch'}},$type);
14500: }
1.23 raeburn 14501: }
1.26 raeburn 14502: } else {
14503: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 14504: }
14505: }
14506:
14507: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
14508: foreach my $by (@{$currdirsrch{'searchby'}}) {
14509: if (!grep(/^\Q$by\E$/,@searchby)) {
14510: push(@{$changes{'searchby'}},$by);
14511: }
14512: }
14513: foreach my $by (@searchby) {
14514: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
14515: push(@{$changes{'searchby'}},$by);
14516: }
14517: }
14518: } else {
14519: push(@{$changes{'searchby'}},@searchby);
14520: }
1.25 raeburn 14521:
14522: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
14523: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
14524: if (!grep(/^\Q$type\E$/,@searchtypes)) {
14525: push(@{$changes{'searchtypes'}},$type);
14526: }
14527: }
14528: foreach my $type (@searchtypes) {
14529: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
14530: push(@{$changes{'searchtypes'}},$type);
14531: }
14532: }
14533: } else {
14534: if (exists($currdirsrch{'searchtypes'})) {
14535: foreach my $type (@searchtypes) {
14536: if ($type ne $currdirsrch{'searchtypes'}) {
14537: push(@{$changes{'searchtypes'}},$type);
14538: }
14539: }
14540: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
14541: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
14542: }
14543: } else {
14544: push(@{$changes{'searchtypes'}},@searchtypes);
14545: }
14546: }
14547:
1.23 raeburn 14548: my %dirsrch_hash = (
14549: directorysrch => { available => $env{'form.dirsrch_available'},
14550: cansearch => \@cansearch,
1.160.6.72 raeburn 14551: localonly => $env{'form.dirsrch_instlocalonly'},
14552: lclocalonly => $env{'form.dirsrch_domlocalonly'},
14553: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 14554: searchby => \@searchby,
1.25 raeburn 14555: searchtypes => \@searchtypes,
1.23 raeburn 14556: }
14557: );
14558: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
14559: $dom);
14560: if ($putresult eq 'ok') {
14561: if (exists($currdirsrch{'available'})) {
14562: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
14563: $changes{'available'} = 1;
14564: }
14565: } else {
14566: if ($env{'form.dirsrch_available'} eq '1') {
14567: $changes{'available'} = 1;
14568: }
14569: }
1.160.6.72 raeburn 14570: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 14571: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
14572: $changes{'lcavailable'} = 1;
14573: }
1.24 raeburn 14574: } else {
1.160.6.72 raeburn 14575: if ($env{'form.dirsrch_lcavailable'} eq '1') {
14576: $changes{'lcavailable'} = 1;
14577: }
14578: }
14579: if (exists($currdirsrch{'localonly'})) {
14580: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 14581: $changes{'localonly'} = 1;
14582: }
1.160.6.72 raeburn 14583: } else {
14584: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
14585: $changes{'localonly'} = 1;
14586: }
14587: }
14588: if (exists($currdirsrch{'lclocalonly'})) {
14589: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
14590: $changes{'lclocalonly'} = 1;
14591: }
14592: } else {
14593: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
14594: $changes{'lclocalonly'} = 1;
14595: }
1.24 raeburn 14596: }
1.23 raeburn 14597: if (keys(%changes) > 0) {
14598: $resulttext = &mt('Changes made:').'<ul>';
14599: if ($changes{'available'}) {
14600: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
14601: }
1.160.6.72 raeburn 14602: if ($changes{'lcavailable'}) {
14603: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
14604: }
1.24 raeburn 14605: if ($changes{'localonly'}) {
1.160.6.72 raeburn 14606: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
14607: }
14608: if ($changes{'lclocalonly'}) {
14609: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 14610: }
1.23 raeburn 14611: if (ref($changes{'cansearch'}) eq 'ARRAY') {
14612: my $chgtext;
1.26 raeburn 14613: if (ref($usertypes) eq 'HASH') {
14614: if (keys(%{$usertypes}) > 0) {
14615: foreach my $type (@{$types}) {
14616: if (grep(/^\Q$type\E$/,@cansearch)) {
14617: $chgtext .= $usertypes->{$type}.'; ';
14618: }
14619: }
14620: if (grep(/^default$/,@cansearch)) {
14621: $chgtext .= $othertitle;
14622: } else {
14623: $chgtext =~ s/\; $//;
14624: }
1.160.6.13 raeburn 14625: $resulttext .=
14626: '<li>'.
14627: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
14628: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
14629: '</li>';
1.23 raeburn 14630: }
14631: }
14632: }
14633: if (ref($changes{'searchby'}) eq 'ARRAY') {
14634: my ($searchtitles,$titleorder) = &sorted_searchtitles();
14635: my $chgtext;
14636: foreach my $type (@{$titleorder}) {
14637: if (grep(/^\Q$type\E$/,@searchby)) {
14638: if (defined($searchtitles->{$type})) {
14639: $chgtext .= $searchtitles->{$type}.'; ';
14640: }
14641: }
14642: }
14643: $chgtext =~ s/\; $//;
14644: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
14645: }
1.25 raeburn 14646: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
14647: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
14648: my $chgtext;
14649: foreach my $type (@{$srchtypeorder}) {
14650: if (grep(/^\Q$type\E$/,@searchtypes)) {
14651: if (defined($srchtypes_desc->{$type})) {
14652: $chgtext .= $srchtypes_desc->{$type}.'; ';
14653: }
14654: }
14655: }
14656: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 14657: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 14658: }
14659: $resulttext .= '</ul>';
1.160.6.81 raeburn 14660: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
14661: if (ref($lastactref) eq 'HASH') {
14662: $lastactref->{'directorysrch'} = 1;
14663: }
1.23 raeburn 14664: } else {
1.160.6.72 raeburn 14665: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 14666: }
14667: } else {
14668: $resulttext = '<span class="LC_error">'.
1.27 raeburn 14669: &mt('An error occurred: [_1]',$putresult).'</span>';
14670: }
14671: return $resulttext;
14672: }
14673:
1.28 raeburn 14674: sub modify_contacts {
1.160.6.24 raeburn 14675: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 14676: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
14677: if (ref($domconfig{'contacts'}) eq 'HASH') {
14678: foreach my $key (keys(%{$domconfig{'contacts'}})) {
14679: $currsetting{$key} = $domconfig{'contacts'}{$key};
14680: }
14681: }
1.160.6.78 raeburn 14682: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 14683: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 14684: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 14685: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 14686: my @toggles = ('reporterrors','reportupdates','reportstatus');
14687: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 14688: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 14689: foreach my $type (@mailings) {
14690: @{$newsetting{$type}} =
14691: &Apache::loncommon::get_env_multiple('form.'.$type);
14692: foreach my $item (@contacts) {
14693: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
14694: $contacts_hash{contacts}{$type}{$item} = 1;
14695: } else {
14696: $contacts_hash{contacts}{$type}{$item} = 0;
14697: }
1.160.6.78 raeburn 14698: }
1.28 raeburn 14699: $others{$type} = $env{'form.'.$type.'_others'};
14700: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 14701: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14702: $bcc{$type} = $env{'form.'.$type.'_bcc'};
14703: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 14704: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
14705: $includestr{$type} = $env{'form.'.$type.'_includestr'};
14706: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
14707: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14708: }
1.134 raeburn 14709: }
1.28 raeburn 14710: }
14711: foreach my $item (@contacts) {
14712: $to{$item} = $env{'form.'.$item};
14713: $contacts_hash{'contacts'}{$item} = $to{$item};
14714: }
1.160.6.23 raeburn 14715: foreach my $item (@toggles) {
14716: if ($env{'form.'.$item} =~ /^(0|1)$/) {
14717: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
14718: }
14719: }
1.160.6.107 raeburn 14720: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
14721: foreach my $item (@lonstatus) {
14722: if ($item eq 'excluded') {
14723: my (%serverhomes,@excluded);
14724: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
14725: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
14726: if (@possexcluded) {
14727: foreach my $id (sort(@possexcluded)) {
14728: if ($serverhomes{$id}) {
14729: push(@excluded,$id);
14730: }
14731: }
14732: }
14733: if (@excluded) {
14734: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
14735: }
14736: } elsif ($item eq 'weights') {
14737: foreach my $type ('E','W','N','U') {
14738: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
14739: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
14740: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
14741: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
14742: $env{'form.error'.$item.'_'.$type};
14743: }
14744: }
14745: }
14746: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
14747: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
14748: if ($env{'form.error'.$item} =~ /^\d+$/) {
14749: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
14750: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
14751: }
14752: }
14753: }
14754: }
1.160.6.78 raeburn 14755: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
14756: foreach my $field (@{$fields}) {
14757: if (ref($possoptions->{$field}) eq 'ARRAY') {
14758: my $value = $env{'form.helpform_'.$field};
14759: $value =~ s/^\s+|\s+$//g;
14760: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 14761: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 14762: if ($field eq 'screenshot') {
14763: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
14764: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 14765: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 14766: }
14767: }
14768: }
14769: }
14770: }
14771: }
1.160.6.101 raeburn 14772: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14773: my (@statuses,%usertypeshash,@overrides);
14774: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
14775: @statuses = @{$types};
14776: if (ref($usertypes) eq 'HASH') {
14777: %usertypeshash = %{$usertypes};
14778: }
14779: }
14780: if (@statuses) {
14781: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
14782: foreach my $type (@possoverrides) {
14783: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
14784: push(@overrides,$type);
14785: }
14786: }
14787: if (@overrides) {
14788: foreach my $type (@overrides) {
14789: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
14790: foreach my $item (@contacts) {
14791: if (grep(/^\Q$item\E$/,@standard)) {
14792: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
14793: $newsetting{'override_'.$type}{$item} = 1;
14794: } else {
14795: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
14796: $newsetting{'override_'.$type}{$item} = 0;
14797: }
14798: }
14799: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
14800: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14801: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
14802: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14803: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
14804: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
14805: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
14806: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14807: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
14808: }
1.160.6.118.2 14(raebu 14809:23): }
1.160.6.101 raeburn 14810: }
14811: }
1.28 raeburn 14812: if (keys(%currsetting) > 0) {
14813: foreach my $item (@contacts) {
14814: if ($to{$item} ne $currsetting{$item}) {
14815: $changes{$item} = 1;
14816: }
14817: }
14818: foreach my $type (@mailings) {
14819: foreach my $item (@contacts) {
14820: if (ref($currsetting{$type}) eq 'HASH') {
14821: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14822: push(@{$changes{$type}},$item);
14823: }
14824: } else {
14825: push(@{$changes{$type}},@{$newsetting{$type}});
14826: }
14827: }
14828: if ($others{$type} ne $currsetting{$type}{'others'}) {
14829: push(@{$changes{$type}},'others');
14830: }
1.160.6.78 raeburn 14831: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14832: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14833: push(@{$changes{$type}},'bcc');
14834: }
1.160.6.78 raeburn 14835: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14836: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14837: push(@{$changes{$type}},'include');
14838: }
14839: }
14840: }
14841: if (ref($fields) eq 'ARRAY') {
14842: if (ref($currsetting{'helpform'}) eq 'HASH') {
14843: foreach my $field (@{$fields}) {
14844: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
14845: push(@{$changes{'helpform'}},$field);
14846: }
14847: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14848: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
14849: push(@{$changes{'helpform'}},'maxsize');
14850: }
14851: }
14852: }
14853: } else {
14854: foreach my $field (@{$fields}) {
14855: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14856: push(@{$changes{'helpform'}},$field);
14857: }
14858: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
14859: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
14860: push(@{$changes{'helpform'}},'maxsize');
14861: }
14862: }
14863: }
1.134 raeburn 14864: }
1.28 raeburn 14865: }
1.160.6.101 raeburn 14866: if (@statuses) {
14867: if (ref($currsetting{'overrides'}) eq 'HASH') {
14868: foreach my $key (keys(%{$currsetting{'overrides'}})) {
14869: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
14870: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
14871: foreach my $item (@contacts,'bcc','others','include') {
14872: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
14873: push(@{$changes{'overrides'}},$key);
14874: last;
14875: }
14876: }
14877: } else {
14878: push(@{$changes{'overrides'}},$key);
14879: }
14880: }
14881: }
14882: foreach my $key (@overrides) {
14883: unless (exists($currsetting{'overrides'}{$key})) {
14884: push(@{$changes{'overrides'}},$key);
14885: }
14886: }
14887: } else {
14888: foreach my $key (@overrides) {
14889: push(@{$changes{'overrides'}},$key);
14890: }
14891: }
14892: }
1.160.6.107 raeburn 14893: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
14894: foreach my $key ('excluded','weights','threshold','sysmail') {
14895: if ($key eq 'excluded') {
14896: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14897: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
14898: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14899: (@{$currsetting{'lonstatus'}{$key}})) {
14900: my @diffs =
14901: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
14902: $currsetting{'lonstatus'}{$key});
14903: if (@diffs) {
14904: push(@{$changes{'lonstatus'}},$key);
14905: }
14906: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
14907: push(@{$changes{'lonstatus'}},$key);
14908: }
14909: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
14910: (@{$currsetting{'lonstatus'}{$key}})) {
14911: push(@{$changes{'lonstatus'}},$key);
14912: }
14913: } elsif ($key eq 'weights') {
14914: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
14915: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
14916: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14917: foreach my $type ('E','W','N','U') {
14918: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
14919: $currsetting{'lonstatus'}{$key}{$type}) {
14920: push(@{$changes{'lonstatus'}},$key);
14921: last;
14922: }
14923: }
14924: } else {
14925: foreach my $type ('E','W','N','U') {
14926: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
14927: push(@{$changes{'lonstatus'}},$key);
14928: last;
14929: }
14930: }
14931: }
14932: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
14933: foreach my $type ('E','W','N','U') {
14934: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
14935: push(@{$changes{'lonstatus'}},$key);
14936: last;
14937: }
14938: }
14939: }
14940: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
14941: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14942: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14943: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
14944: push(@{$changes{'lonstatus'}},$key);
14945: }
14946: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
14947: push(@{$changes{'lonstatus'}},$key);
14948: }
14949: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
14950: push(@{$changes{'lonstatus'}},$key);
14951: }
14952: }
14953: }
14954: } else {
14955: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
14956: foreach my $key ('excluded','weights','threshold','sysmail') {
14957: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
14958: push(@{$changes{'lonstatus'}},$key);
14959: }
14960: }
14961: }
14962: }
1.28 raeburn 14963: } else {
14964: my %default;
14965: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
14966: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
14967: $default{'errormail'} = 'adminemail';
14968: $default{'packagesmail'} = 'adminemail';
14969: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 14970: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 14971: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 14972: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 14973: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 14974: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 14975: foreach my $item (@contacts) {
14976: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 14977: $changes{$item} = 1;
1.160.6.23 raeburn 14978: }
1.28 raeburn 14979: }
14980: foreach my $type (@mailings) {
14981: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
14982: push(@{$changes{$type}},@{$newsetting{$type}});
14983: }
14984: if ($others{$type} ne '') {
14985: push(@{$changes{$type}},'others');
1.134 raeburn 14986: }
1.160.6.78 raeburn 14987: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14988: if ($bcc{$type} ne '') {
14989: push(@{$changes{$type}},'bcc');
14990: }
1.160.6.78 raeburn 14991: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
14992: push(@{$changes{$type}},'include');
14993: }
14994: }
14995: }
14996: if (ref($fields) eq 'ARRAY') {
14997: foreach my $field (@{$fields}) {
14998: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
14999: push(@{$changes{'helpform'}},$field);
15000: }
15001: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15002: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15003: push(@{$changes{'helpform'}},'maxsize');
15004: }
15005: }
1.134 raeburn 15006: }
1.28 raeburn 15007: }
1.160.6.107 raeburn 15008: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15009: foreach my $key ('excluded','weights','threshold','sysmail') {
15010: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15011: push(@{$changes{'lonstatus'}},$key);
15012: }
15013: }
15014: }
1.28 raeburn 15015: }
1.160.6.23 raeburn 15016: foreach my $item (@toggles) {
15017: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15018: $changes{$item} = 1;
15019: } elsif ((!$env{'form.'.$item}) &&
15020: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15021: $changes{$item} = 1;
15022: }
15023: }
1.28 raeburn 15024: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15025: $dom);
15026: if ($putresult eq 'ok') {
15027: if (keys(%changes) > 0) {
1.160.6.24 raeburn 15028: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 15029: if (ref($lastactref) eq 'HASH') {
15030: $lastactref->{'domainconfig'} = 1;
15031: }
1.28 raeburn 15032: my ($titles,$short_titles) = &contact_titles();
15033: $resulttext = &mt('Changes made:').'<ul>';
15034: foreach my $item (@contacts) {
15035: if ($changes{$item}) {
15036: $resulttext .= '<li>'.$titles->{$item}.
15037: &mt(' set to: ').
15038: '<span class="LC_cusr_emph">'.
15039: $to{$item}.'</span></li>';
15040: }
15041: }
15042: foreach my $type (@mailings) {
15043: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 15044: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15045: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15046: } else {
15047: $resulttext .= '<li>'.$titles->{$type}.': ';
15048: }
1.28 raeburn 15049: my @text;
15050: foreach my $item (@{$newsetting{$type}}) {
15051: push(@text,$short_titles->{$item});
15052: }
15053: if ($others{$type} ne '') {
15054: push(@text,$others{$type});
15055: }
1.160.6.78 raeburn 15056: if (@text) {
15057: $resulttext .= '<span class="LC_cusr_emph">'.
15058: join(', ',@text).'</span>';
15059: }
15060: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15061: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 15062: my $bcctext;
15063: if (@text) {
15064: $bcctext = ' '.&mt('with Bcc to');
15065: } else {
15066: $bcctext = '(Bcc)';
15067: }
15068: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15069: } elsif (!@text) {
15070: $resulttext .= &mt('No one');
1.134 raeburn 15071: }
1.160.6.78 raeburn 15072: if ($includestr{$type} ne '') {
15073: if ($includeloc{$type} eq 'b') {
15074: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15075: } elsif ($includeloc{$type} eq 's') {
15076: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15077: }
15078: }
15079: } elsif (!@text) {
15080: $resulttext .= &mt('No recipients');
1.134 raeburn 15081: }
15082: $resulttext .= '</li>';
1.28 raeburn 15083: }
15084: }
1.160.6.101 raeburn 15085: if (ref($changes{'overrides'}) eq 'ARRAY') {
15086: my @deletions;
15087: foreach my $type (@{$changes{'overrides'}}) {
15088: if ($usertypeshash{$type}) {
15089: if (grep(/^\Q$type\E/,@overrides)) {
15090: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15091: $usertypeshash{$type}).'<ul><li>';
15092: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15093: my @text;
15094: foreach my $item (@contacts) {
15095: if ($newsetting{'override_'.$type}{$item}) {
15096: push(@text,$short_titles->{$item});
15097: }
15098: }
15099: if ($newsetting{'override_'.$type}{'others'} ne '') {
15100: push(@text,$newsetting{'override_'.$type}{'others'});
15101: }
15102:
15103: if (@text) {
15104: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15105: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15106: }
15107: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15108: my $bcctext;
15109: if (@text) {
15110: $bcctext = ' '.&mt('with Bcc to');
15111: } else {
15112: $bcctext = '(Bcc)';
15113: }
15114: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15115: } elsif (!@text) {
15116: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15117: }
15118: $resulttext .= '</li>';
15119: if ($newsetting{'override_'.$type}{'include'} ne '') {
15120: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15121: if ($loc eq 'b') {
15122: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15123: } elsif ($loc eq 's') {
15124: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15125: }
15126: }
15127: }
15128: $resulttext .= '</li></ul></li>';
15129: } else {
15130: push(@deletions,$usertypeshash{$type});
15131: }
15132: }
15133: }
15134: if (@deletions) {
15135: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15136: join(', ',@deletions)).'</li>';
15137: }
15138: }
1.160.6.23 raeburn 15139: my @offon = ('off','on');
1.160.6.107 raeburn 15140: my $corelink = &core_link_msu();
1.160.6.23 raeburn 15141: if ($changes{'reporterrors'}) {
15142: $resulttext .= '<li>'.
15143: &mt('E-mail error reports to [_1] set to "'.
15144: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 15145: $corelink).
1.160.6.23 raeburn 15146: '</li>';
15147: }
15148: if ($changes{'reportupdates'}) {
15149: $resulttext .= '<li>'.
15150: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15151: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 15152: $corelink).
1.160.6.23 raeburn 15153: '</li>';
15154: }
1.160.6.107 raeburn 15155: if ($changes{'reportstatus'}) {
15156: $resulttext .= '<li>'.
15157: &mt('E-mail status if errors above threshold to [_1] set to "'.
15158: $offon[$env{'form.reportstatus'}].'".',
15159: $corelink).
15160: '</li>';
15161: }
15162: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15163: $resulttext .= '<li>'.
15164: &mt('Nightly status check e-mail settings').':<ul>';
15165: my (%defval,%use_def,%shown);
15166: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15167: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15168: $defval{'weights'} =
15169: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15170: $defval{'excluded'} = &mt('None');
15171: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15172: foreach my $item ('threshold','sysmail','weights','excluded') {
15173: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15174: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15175: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15176: } elsif ($item eq 'weights') {
15177: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15178: foreach my $type ('E','W','N','U') {
15179: $shown{$item} .= $lonstatus_names->{$type}.'=';
15180: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15181: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15182: } else {
15183: $shown{$item} .= $lonstatus_defs->{$type};
15184: }
15185: $shown{$item} .= ', ';
15186: }
15187: $shown{$item} =~ s/, $//;
15188: } else {
15189: $shown{$item} = $defval{$item};
15190: }
15191: } elsif ($item eq 'excluded') {
15192: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15193: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15194: } else {
15195: $shown{$item} = $defval{$item};
15196: }
15197: }
15198: } else {
15199: $shown{$item} = $defval{$item};
15200: }
15201: }
15202: } else {
15203: foreach my $item ('threshold','weights','excluded','sysmail') {
15204: $shown{$item} = $defval{$item};
15205: }
15206: }
15207: foreach my $item ('threshold','weights','excluded','sysmail') {
15208: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15209: $shown{$item}).'</li>';
15210: }
15211: $resulttext .= '</ul></li>';
15212: }
1.160.6.78 raeburn 15213: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15214: my (@optional,@required,@unused,$maxsizechg);
15215: foreach my $field (@{$changes{'helpform'}}) {
15216: if ($field eq 'maxsize') {
15217: $maxsizechg = 1;
15218: next;
15219: }
15220: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15221: push(@optional,$field);
15222: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15223: push(@unused,$field);
15224: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15225: push(@required,$field);
15226: }
15227: }
15228: if (@optional) {
15229: $resulttext .= '<li>'.
15230: &mt('Help form fields changed to "Optional": [_1].',
15231: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15232: '</li>';
15233: }
15234: if (@required) {
15235: $resulttext .= '<li>'.
15236: &mt('Help form fields changed to "Required": [_1].',
15237: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15238: '</li>';
15239: }
15240: if (@unused) {
15241: $resulttext .= '<li>'.
15242: &mt('Help form fields changed to "Not shown": [_1].',
15243: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15244: '</li>';
15245: }
15246: if ($maxsizechg) {
15247: $resulttext .= '<li>'.
15248: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15249: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15250: '</li>';
15251: }
15252: }
1.28 raeburn 15253: $resulttext .= '</ul>';
15254: } else {
1.160.6.78 raeburn 15255: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15256: }
15257: } else {
15258: $resulttext = '<span class="LC_error">'.
1.160.6.118.2 14(raebu 15259:23): &mt('An error occurred: [_1]',$putresult).'</span>';
1.28 raeburn 15260: }
15261: return $resulttext;
15262: }
15263:
1.160.6.98 raeburn 15264: sub modify_passwords {
15265: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15266: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15267: $updatedefaults,$updateconf);
15268: my $customfn = 'resetpw.html';
15269: if (ref($domconfig{'passwords'}) eq 'HASH') {
15270: %current = %{$domconfig{'passwords'}};
15271: }
15272: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15273: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15274: if (ref($types) eq 'ARRAY') {
15275: @oktypes = @{$types};
15276: }
15277: push(@oktypes,'default');
15278:
15279: my %titles = &Apache::lonlocal::texthash (
15280: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15281: intauth_check => 'Check bcrypt cost if authenticated',
15282: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15283: permanent => 'Permanent e-mail address',
15284: critical => 'Critical notification address',
15285: notify => 'Notification address',
15286: min => 'Minimum password length',
15287: max => 'Maximum password length',
15288: chars => 'Required characters',
15289: numsaved => 'Number of previous passwords to save',
15290: reset => 'Resetting Forgotten Password',
15291: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15292: rules => 'Rules for LON-CAPA Passwords',
15293: crsownerchg => 'Course Owner Changing Student Passwords',
15294: username => 'Username',
15295: email => 'E-mail address',
15296: );
15297:
15298: #
15299: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15300: #
15301: my (%curr_defaults,%save_defaults);
15302: if (ref($domconfig{'defaults'}) eq 'HASH') {
15303: foreach my $key (keys(%{$domconfig{'defaults'}})) {
15304: if ($key =~ /^intauth_(cost|check|switch)$/) {
15305: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
15306: } else {
15307: $save_defaults{$key} = $domconfig{'defaults'}{$key};
15308: }
15309: }
15310: }
15311: my %staticdefaults = (
15312: 'resetlink' => 2,
15313: 'resetcase' => \@oktypes,
15314: 'resetprelink' => 'both',
15315: 'resetemail' => ['critical','notify','permanent'],
15316: 'intauth_cost' => 10,
15317: 'intauth_check' => 0,
15318: 'intauth_switch' => 0,
15319: );
1.160.6.99 raeburn 15320: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 15321: foreach my $type (@oktypes) {
15322: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
15323: }
15324: my $linklife = $env{'form.passwords_link'};
15325: $linklife =~ s/^\s+|\s+$//g;
15326: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
15327: $newvalues{'resetlink'} = $linklife;
15328: if ($current{'resetlink'}) {
15329: if ($current{'resetlink'} ne $linklife) {
15330: $changes{'reset'} = 1;
15331: }
1.160.6.102 raeburn 15332: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15333: if ($staticdefaults{'resetlink'} ne $linklife) {
15334: $changes{'reset'} = 1;
15335: }
15336: }
15337: } elsif ($current{'resetlink'}) {
15338: $changes{'reset'} = 1;
15339: }
15340: my @casesens;
15341: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
15342: foreach my $case (sort(@posscase)) {
15343: if (grep(/^\Q$case\E$/,@oktypes)) {
15344: push(@casesens,$case);
15345: }
15346: }
15347: $newvalues{'resetcase'} = \@casesens;
15348: if (ref($current{'resetcase'}) eq 'ARRAY') {
15349: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
15350: if (@diffs > 0) {
15351: $changes{'reset'} = 1;
15352: }
1.160.6.102 raeburn 15353: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15354: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
15355: if (@diffs > 0) {
15356: $changes{'reset'} = 1;
15357: }
15358: }
15359: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
15360: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
15361: if (exists($current{'resetprelink'})) {
15362: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
15363: $changes{'reset'} = 1;
15364: }
1.160.6.102 raeburn 15365: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15366: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
15367: $changes{'reset'} = 1;
15368: }
15369: }
15370: } elsif ($current{'resetprelink'}) {
15371: $changes{'reset'} = 1;
15372: }
15373: foreach my $type (@oktypes) {
15374: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
15375: my @postlink;
15376: foreach my $item (sort(@possplink)) {
15377: if ($item =~ /^(email|username)$/) {
15378: push(@postlink,$item);
15379: }
15380: }
15381: $newvalues{'resetpostlink'}{$type} = \@postlink;
15382: unless ($changes{'reset'}) {
15383: if (ref($current{'resetpostlink'}) eq 'HASH') {
15384: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
15385: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
15386: if (@diffs > 0) {
15387: $changes{'reset'} = 1;
15388: }
15389: } else {
15390: $changes{'reset'} = 1;
15391: }
1.160.6.102 raeburn 15392: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15393: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
15394: if (@diffs > 0) {
15395: $changes{'reset'} = 1;
15396: }
15397: }
15398: }
15399: }
15400: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
15401: my @resetemail;
15402: foreach my $item (sort(@possemailsrc)) {
15403: if ($item =~ /^(permanent|critical|notify)$/) {
15404: push(@resetemail,$item);
15405: }
15406: }
15407: $newvalues{'resetemail'} = \@resetemail;
15408: unless ($changes{'reset'}) {
15409: if (ref($current{'resetemail'}) eq 'ARRAY') {
15410: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
15411: if (@diffs > 0) {
15412: $changes{'reset'} = 1;
15413: }
1.160.6.102 raeburn 15414: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15415: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
15416: if (@diffs > 0) {
15417: $changes{'reset'} = 1;
15418: }
15419: }
15420: }
15421: if ($env{'form.passwords_stdtext'} == 0) {
15422: $newvalues{'resetremove'} = 1;
15423: unless ($current{'resetremove'}) {
15424: $changes{'reset'} = 1;
15425: }
15426: } elsif ($current{'resetremove'}) {
15427: $changes{'reset'} = 1;
15428: }
15429: if ($env{'form.passwords_customfile.filename'} ne '') {
15430: my $servadm = $r->dir_config('lonAdmEMail');
15431: my ($configuserok,$author_ok,$switchserver) =
15432: &config_check($dom,$confname,$servadm);
15433: my $error;
15434: if ($configuserok eq 'ok') {
15435: if ($switchserver) {
15436: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
15437: } else {
15438: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 15439:23): my $modified = [];
1.160.6.98 raeburn 15440: my ($result,$customurl) =
1.160.6.118.2 14(raebu 15441:23): &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
15442:23): $confname,'customtext/resetpw','','',$customfn,
15443:23): $modified);
1.160.6.98 raeburn 15444: if ($result eq 'ok') {
15445: $newvalues{'resetcustom'} = $customurl;
15446: $changes{'reset'} = 1;
1.160.6.118.2 14(raebu 15447:23): &update_modify_urls($r,$modified);
1.160.6.98 raeburn 15448: } else {
15449: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
15450: }
15451: } else {
15452: $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].",$customfn,$confname,$dom,$author_ok);
15453: }
15454: }
15455: } else {
15456: $error = &mt("Upload of [_1] failed because a Domain Configuration user ([_2]) could not be created in domain: [_3]. Error was: [_4].",$customfn,$confname,$dom,$configuserok);
15457: }
15458: if ($error) {
15459: &Apache::lonnet::logthis($error);
15460: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15461: }
15462: } elsif ($current{'resetcustom'}) {
15463: if ($env{'form.passwords_custom_del'}) {
15464: $changes{'reset'} = 1;
15465: } else {
15466: $newvalues{'resetcustom'} = $current{'resetcustom'};
15467: }
15468: }
15469: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
15470: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
15471: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
15472: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
15473: $changes{'intauth'} = 1;
15474: }
15475: } else {
15476: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
15477: }
15478: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
15479: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
15480: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
15481: $changes{'intauth'} = 1;
15482: }
15483: } else {
15484: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
15485: }
15486: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
15487: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
15488: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
15489: $changes{'intauth'} = 1;
15490: }
15491: } else {
15492: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
15493: }
15494: foreach my $item ('cost','check','switch') {
15495: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
15496: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
15497: $updatedefaults = 1;
15498: }
15499: }
1.160.6.118.2 5(raebur 15500:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 15501: my %crsownerchg = (
15502: by => [],
15503: for => [],
15504: );
15505: foreach my $item ('by','for') {
15506: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
15507: foreach my $type (sort(@posstypes)) {
15508: if (grep(/^\Q$type\E$/,@oktypes)) {
15509: push(@{$crsownerchg{$item}},$type);
15510: }
15511: }
15512: }
15513: $newvalues{'crsownerchg'} = \%crsownerchg;
15514: if (ref($current{'crsownerchg'}) eq 'HASH') {
15515: foreach my $item ('by','for') {
15516: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
15517: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
15518: if (@diffs > 0) {
15519: $changes{'crsownerchg'} = 1;
15520: last;
15521: }
15522: }
15523: }
1.160.6.102 raeburn 15524: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 15525: foreach my $item ('by','for') {
15526: if (@{$crsownerchg{$item}} > 0) {
15527: $changes{'crsownerchg'} = 1;
15528: last;
15529: }
15530: }
15531: }
15532:
15533: my %confighash = (
15534: defaults => \%save_defaults,
15535: passwords => \%newvalues,
15536: );
15537: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
15538:
15539: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
15540: if ($putresult eq 'ok') {
15541: if (keys(%changes) > 0) {
15542: $resulttext = &mt('Changes made: ').'<ul>';
15543: foreach my $key ('reset','intauth','rules','crsownerchg') {
15544: if ($changes{$key}) {
15545: unless ($key eq 'intauth') {
15546: $updateconf = 1;
15547: }
15548: $resulttext .= '<li>'.$titles{$key}.':<ul>';
15549: if ($key eq 'reset') {
15550: if ($confighash{'passwords'}{'captcha'} eq 'original') {
15551: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
15552: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
15553: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 15554: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
15555: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
15556: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
15557: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
15558: }
1.160.6.98 raeburn 15559: } else {
15560: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
15561: }
15562: if ($confighash{'passwords'}{'resetlink'}) {
15563: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
15564: } else {
15565: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
15566: &mt('Will default to 2 hours').'</li>';
15567: }
15568: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
15569: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
15570: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
15571: } else {
15572: my $casesens;
15573: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
15574: if ($type eq 'default') {
15575: $casesens .= $othertitle.', ';
15576: } elsif ($usertypes->{$type} ne '') {
15577: $casesens .= $usertypes->{$type}.', ';
15578: }
15579: }
15580: $casesens =~ s/\Q, \E$//;
15581: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
15582: }
15583: } else {
15584: $resulttext .= '<li>'.&mt('Case-sensitivity not set for "Forgot Password" web form').' '.&mt('Will default to case-sensitive for username and/or e-mail address for all').'</li>';
15585: }
15586: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
15587: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
15588: } else {
15589: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
15590: }
15591: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
15592: my $output;
15593: if (ref($types) eq 'ARRAY') {
15594: foreach my $type (@{$types}) {
15595: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
15596: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
15597: $output .= $usertypes->{$type}.' -- '.&mt('none');
15598: } else {
15599: $output .= $usertypes->{$type}.' -- '.
15600: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
15601: }
15602: }
15603: }
15604: }
15605: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
15606: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
15607: $output .= $othertitle.' -- '.&mt('none');
15608: } else {
15609: $output .= $othertitle.' -- '.
15610: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
15611: }
15612: }
15613: if ($output) {
15614: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
15615: } else {
15616: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
15617: }
15618: } else {
15619: $resulttext .= '<li>'.&mt('Information required for new password form not set.').' '.&mt('Will default to requiring both the username and an e-mail address').'</li>';
15620: }
15621: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
15622: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
15623: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
15624: } else {
15625: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
15626: }
15627: } else {
1.160.6.110 raeburn 15628: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
1.160.6.98 raeburn 15629: }
15630: if ($confighash{'passwords'}{'resetremove'}) {
15631: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
15632: } else {
15633: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
15634: }
15635: if ($confighash{'passwords'}{'resetcustom'}) {
15636: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 15637: &mt('custom text'),600,500,undef,undef,
15638: undef,undef,'background-color:#ffffff');
15639: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 15640: } else {
15641: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
15642: }
15643: } elsif ($key eq 'intauth') {
15644: foreach my $item ('cost','switch','check') {
15645: my $value = $save_defaults{$key.'_'.$item};
15646: if ($item eq 'switch') {
15647: my %optiondesc = &Apache::lonlocal::texthash (
15648: 0 => 'No',
15649: 1 => 'Yes',
15650: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
15651: );
15652: if ($value =~ /^(0|1|2)$/) {
15653: $value = $optiondesc{$value};
15654: } else {
15655: $value = &mt('none -- defaults to No');
15656: }
15657: } elsif ($item eq 'check') {
15658: my %optiondesc = &Apache::lonlocal::texthash (
15659: 0 => 'No',
15660: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
15661: 2 => 'Yes, disallow login if stored cost is less than domain default',
15662: );
15663: if ($value =~ /^(0|1|2)$/) {
15664: $value = $optiondesc{$value};
15665: } else {
15666: $value = &mt('none -- defaults to No');
15667: }
15668: }
15669: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
15670: }
15671: } elsif ($key eq 'rules') {
15672: foreach my $rule ('min','max','numsaved') {
15673: if ($confighash{'passwords'}{$rule} eq '') {
15674: if ($rule eq 'min') {
15675: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 15676: ' '.&mt('Default of [_1] will be used',
15677: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 15678: } else {
15679: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15680: }
15681: } else {
15682: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
15683: }
15684: }
1.160.6.104 raeburn 15685: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
15686: if (@{$confighash{'passwords'}{'chars'}} > 0) {
15687: my %rulenames = &Apache::lonlocal::texthash(
15688: uc => 'At least one upper case letter',
15689: lc => 'At least one lower case letter',
15690: num => 'At least one number',
15691: spec => 'At least one non-alphanumeric',
15692: );
15693: my $needed = '<ul><li>'.
15694: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
15695: '</li></ul>';
15696: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15697: } else {
15698: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
15699: }
15700: } else {
15701: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
15702: }
1.160.6.98 raeburn 15703: } elsif ($key eq 'crsownerchg') {
15704: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
15705: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
15706: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
15707: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15708: } else {
15709: my %crsownerstr;
15710: foreach my $item ('by','for') {
15711: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
15712: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
15713: if ($type eq 'default') {
15714: $crsownerstr{$item} .= $othertitle.', ';
15715: } elsif ($usertypes->{$type} ne '') {
15716: $crsownerstr{$item} .= $usertypes->{$type}.', ';
15717: }
15718: }
15719: $crsownerstr{$item} =~ s/\Q, \E$//;
15720: }
15721: }
15722: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
15723: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
15724: }
15725: } else {
15726: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15727: }
15728: }
15729: $resulttext .= '</ul></li>';
15730: }
15731: }
15732: $resulttext .= '</ul>';
15733: } else {
15734: $resulttext = &mt('No changes made to password settings');
15735: }
15736: my $cachetime = 24*60*60;
15737: if ($updatedefaults) {
15738: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15739: if (ref($lastactref) eq 'HASH') {
15740: $lastactref->{'domdefaults'} = 1;
15741: }
15742: }
15743: if ($updateconf) {
15744: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
15745: if (ref($lastactref) eq 'HASH') {
15746: $lastactref->{'passwdconf'} = 1;
15747: }
15748: }
15749: } else {
15750: $resulttext = '<span class="LC_error">'.
15751: &mt('An error occurred: [_1]',$putresult).'</span>';
15752: }
15753: if ($errors) {
15754: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15755: $errors.'</ul></p>';
15756: }
15757: return $resulttext;
15758: }
15759:
1.160.6.118.2 5(raebur 15760:2): sub password_rule_changes {
15761:2): my ($prefix,$newvalues,$current,$changes) = @_;
15762:2): return unless ((ref($newvalues) eq 'HASH') &&
15763:2): (ref($current) eq 'HASH') &&
15764:2): (ref($changes) eq 'HASH'));
15765:2): my (@rules,%staticdefaults);
15766:2): if ($prefix eq 'passwords') {
15767:2): @rules = ('min','max','numsaved');
14(raebu 15768:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 15769:2): @rules = ('min','max');
15770:2): }
15771:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
15772:2): foreach my $rule (@rules) {
15773:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
15774:2): my $ruleok;
15775:2): if ($rule eq 'min') {
15776:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
15777:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
15778:2): $ruleok = 1;
15779:2): }
15780:2): }
15781:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
15782:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
15783:2): $ruleok = 1;
15784:2): }
15785:2): if ($ruleok) {
15786:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
15787:2): if (exists($current->{$rule})) {
15788:2): if ($newvalues->{$rule} ne $current->{$rule}) {
15789:2): $changes->{'rules'} = 1;
15790:2): }
15791:2): } elsif ($rule eq 'min') {
15792:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
15793:2): $changes->{'rules'} = 1;
15794:2): }
15795:2): } else {
15796:2): $changes->{'rules'} = 1;
15797:2): }
15798:2): } elsif (exists($current->{$rule})) {
15799:2): $changes->{'rules'} = 1;
15800:2): }
15801:2): }
15802:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
15803:2): my @chars;
15804:2): foreach my $item (sort(@posschars)) {
15805:2): if ($item =~ /^(uc|lc|num|spec)$/) {
15806:2): push(@chars,$item);
15807:2): }
15808:2): }
15809:2): $newvalues->{'chars'} = \@chars;
15810:2): unless ($changes->{'rules'}) {
15811:2): if (ref($current->{'chars'}) eq 'ARRAY') {
15812:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
15813:2): if (@diffs > 0) {
15814:2): $changes->{'rules'} = 1;
15815:2): }
15816:2): } else {
15817:2): if (@chars > 0) {
15818:2): $changes->{'rules'} = 1;
15819:2): }
15820:2): }
15821:2): }
15822:2): return;
15823:2): }
15824:2):
1.28 raeburn 15825: sub modify_usercreation {
1.27 raeburn 15826: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15827: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 15828: my $warningmsg;
1.27 raeburn 15829: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15830: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 15831: if ($key eq 'cancreate') {
15832: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15833: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 15834: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 15835: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 15836: } else {
15837: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 15838: }
1.50 raeburn 15839: }
1.43 raeburn 15840: }
1.160.6.34 raeburn 15841: } elsif ($key eq 'email_rule') {
15842: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
15843: } else {
15844: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 15845: }
15846: }
1.34 raeburn 15847: }
1.160.6.34 raeburn 15848: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
15849: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
15850: my @contexts = ('author','course','requestcrs');
15851: foreach my $item(@contexts) {
15852: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 15853: }
1.34 raeburn 15854: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
15855: foreach my $item (@contexts) {
1.160.6.34 raeburn 15856: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
15857: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 15858: }
1.27 raeburn 15859: }
1.34 raeburn 15860: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
15861: foreach my $item (@contexts) {
1.43 raeburn 15862: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 15863: if ($cancreate{$item} ne 'any') {
15864: push(@{$changes{'cancreate'}},$item);
15865: }
15866: } else {
15867: if ($cancreate{$item} ne 'none') {
15868: push(@{$changes{'cancreate'}},$item);
15869: }
1.27 raeburn 15870: }
15871: }
15872: } else {
1.43 raeburn 15873: foreach my $item (@contexts) {
1.34 raeburn 15874: push(@{$changes{'cancreate'}},$item);
15875: }
1.27 raeburn 15876: }
1.34 raeburn 15877:
1.27 raeburn 15878: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
15879: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
15880: if (!grep(/^\Q$type\E$/,@username_rule)) {
15881: push(@{$changes{'username_rule'}},$type);
15882: }
15883: }
15884: foreach my $type (@username_rule) {
15885: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
15886: push(@{$changes{'username_rule'}},$type);
15887: }
15888: }
15889: } else {
15890: push(@{$changes{'username_rule'}},@username_rule);
15891: }
15892:
1.32 raeburn 15893: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
15894: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
15895: if (!grep(/^\Q$type\E$/,@id_rule)) {
15896: push(@{$changes{'id_rule'}},$type);
15897: }
15898: }
15899: foreach my $type (@id_rule) {
15900: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
15901: push(@{$changes{'id_rule'}},$type);
15902: }
15903: }
15904: } else {
15905: push(@{$changes{'id_rule'}},@id_rule);
15906: }
15907:
1.43 raeburn 15908: my @authen_contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 15909:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 15910: my %authhash;
1.43 raeburn 15911: foreach my $item (@authen_contexts) {
1.28 raeburn 15912: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
15913: foreach my $auth (@authtypes) {
15914: if (grep(/^\Q$auth\E$/,@authallowed)) {
15915: $authhash{$item}{$auth} = 1;
15916: } else {
15917: $authhash{$item}{$auth} = 0;
15918: }
15919: }
15920: }
15921: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 15922: foreach my $item (@authen_contexts) {
1.28 raeburn 15923: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
15924: foreach my $auth (@authtypes) {
15925: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
15926: push(@{$changes{'authtypes'}},$item);
15927: last;
15928: }
15929: }
15930: }
15931: }
15932: } else {
1.43 raeburn 15933: foreach my $item (@authen_contexts) {
1.28 raeburn 15934: push(@{$changes{'authtypes'}},$item);
15935: }
15936: }
15937:
1.160.6.34 raeburn 15938: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
15939: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
15940: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
15941: $save_usercreate{'id_rule'} = \@id_rule;
15942: $save_usercreate{'username_rule'} = \@username_rule,
15943: $save_usercreate{'authtypes'} = \%authhash;
15944:
1.27 raeburn 15945: my %usercreation_hash = (
1.160.6.34 raeburn 15946: usercreation => \%save_usercreate,
15947: );
1.27 raeburn 15948:
15949: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
15950: $dom);
1.50 raeburn 15951:
1.160.6.34 raeburn 15952: if ($putresult eq 'ok') {
15953: if (keys(%changes) > 0) {
15954: $resulttext = &mt('Changes made:').'<ul>';
15955: if (ref($changes{'cancreate'}) eq 'ARRAY') {
15956: my %lt = &usercreation_types();
15957: foreach my $type (@{$changes{'cancreate'}}) {
15958: my $chgtext = $lt{$type}.', ';
15959: if ($cancreate{$type} eq 'none') {
15960: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
15961: } elsif ($cancreate{$type} eq 'any') {
15962: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
15963: } elsif ($cancreate{$type} eq 'official') {
15964: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
15965: } elsif ($cancreate{$type} eq 'unofficial') {
15966: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
15967: }
15968: $resulttext .= '<li>'.$chgtext.'</li>';
15969: }
15970: }
15971: if (ref($changes{'username_rule'}) eq 'ARRAY') {
15972: my ($rules,$ruleorder) =
15973: &Apache::lonnet::inst_userrules($dom,'username');
15974: my $chgtext = '<ul>';
15975: foreach my $type (@username_rule) {
15976: if (ref($rules->{$type}) eq 'HASH') {
15977: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
15978: }
15979: }
15980: $chgtext .= '</ul>';
15981: if (@username_rule > 0) {
15982: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15983: } else {
15984: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
15985: }
15986: }
15987: if (ref($changes{'id_rule'}) eq 'ARRAY') {
15988: my ($idrules,$idruleorder) =
15989: &Apache::lonnet::inst_userrules($dom,'id');
15990: my $chgtext = '<ul>';
15991: foreach my $type (@id_rule) {
15992: if (ref($idrules->{$type}) eq 'HASH') {
15993: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
15994: }
15995: }
15996: $chgtext .= '</ul>';
15997: if (@id_rule > 0) {
15998: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
15999: } else {
16000: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16001: }
16002: }
16003: my %authname = &authtype_names();
16004: my %context_title = &context_names();
16005: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16006: my $chgtext = '<ul>';
16007: foreach my $type (@{$changes{'authtypes'}}) {
16008: my @allowed;
16009: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16010: foreach my $auth (@authtypes) {
16011: if ($authhash{$type}{$auth}) {
16012: push(@allowed,$authname{$auth});
16013: }
16014: }
16015: if (@allowed > 0) {
16016: $chgtext .= join(', ',@allowed).'</li>';
16017: } else {
16018: $chgtext .= &mt('none').'</li>';
16019: }
16020: }
16021: $chgtext .= '</ul>';
16022: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16023: $resulttext .= '</li>';
16024: }
16025: $resulttext .= '</ul>';
16026: } else {
16027: $resulttext = &mt('No changes made to user creation settings');
16028: }
16029: } else {
16030: $resulttext = '<span class="LC_error">'.
16031: &mt('An error occurred: [_1]',$putresult).'</span>';
16032: }
16033: if ($warningmsg ne '') {
16034: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16035: }
16036: return $resulttext;
16037: }
16038:
16039: sub modify_selfcreation {
1.160.6.93 raeburn 16040: my ($dom,$lastactref,%domconfig) = @_;
16041: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16042: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16043: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16044: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16045: if (ref($typesref) eq 'ARRAY') {
16046: @types = @{$typesref};
16047: }
16048: if (ref($usertypesref) eq 'HASH') {
16049: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 16050: }
1.160.6.93 raeburn 16051: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 16052: #
16053: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16054: #
16055: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16056: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16057: if ($key eq 'cancreate') {
16058: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16059: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16060: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 16061: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16062: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16063: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16064: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16065: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 16066: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16067: } else {
16068: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16069: }
16070: }
16071: }
16072: } elsif ($key eq 'email_rule') {
16073: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16074: } else {
16075: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16076: }
16077: }
16078: }
16079: #
16080: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16081: #
16082: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16083: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16084: if ($key eq 'selfcreate') {
16085: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16086: } else {
16087: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16088: }
16089: }
16090: }
1.160.6.93 raeburn 16091: #
16092: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16093: #
16094: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16095: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16096: if ($key eq 'inststatusguest') {
16097: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16098: } else {
16099: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16100: }
16101: }
16102: }
1.160.6.34 raeburn 16103:
16104: my @contexts = ('selfcreate');
16105: @{$cancreate{'selfcreate'}} = ();
16106: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 16107: if (@types) {
16108: @{$cancreate{'statustocreate'}} = ();
16109: }
1.160.6.40 raeburn 16110: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 16111: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 16112: %{$cancreate{'emailverified'}} = ();
16113: %{$cancreate{'emailoptions'}} = ();
16114: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16115: my %selfcreatetypes = (
16116: sso => 'users authenticated by institutional single sign on',
16117: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 16118: email => 'users verified by e-mail',
1.50 raeburn 16119: );
1.160.6.34 raeburn 16120: #
16121: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16122: # is permitted.
16123: #
1.160.6.93 raeburn 16124: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 16125:
1.160.6.93 raeburn 16126: my (@statuses,%email_rule);
1.160.6.35 raeburn 16127: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 16128: if ($item eq 'email') {
1.160.6.40 raeburn 16129: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 16130: if (@types) {
16131: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16132: foreach my $status (@poss_statuses) {
16133: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16134: push(@statuses,$status);
16135: }
16136: }
16137: $save_inststatus{'inststatusguest'} = \@statuses;
16138: } else {
16139: push(@statuses,'default');
16140: }
16141: if (@statuses) {
16142: my %curr_rule;
16143: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16144: foreach my $type (@statuses) {
16145: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16146: }
16147: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16148: foreach my $type (@statuses) {
16149: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16150: }
16151: }
16152: push(@{$cancreate{'selfcreate'}},'email');
16153: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16154: my %curremaildom;
16155: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16156: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16157: }
16158: foreach my $type (@statuses) {
16159: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16160: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16161: }
16162: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16163: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16164: }
16165: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16166: #
16167: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16168: #
16169: my $chosen = $1;
16170: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16171: my $emaildom;
16172: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16173: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16174: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16175: if (ref($curremaildom{$type}) eq 'HASH') {
16176: if (exists($curremaildom{$type}{$chosen})) {
16177: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16178: push(@{$changes{'cancreate'}},'emaildomain');
16179: }
16180: } elsif ($emaildom ne '') {
16181: push(@{$changes{'cancreate'}},'emaildomain');
16182: }
16183: } elsif ($emaildom ne '') {
16184: push(@{$changes{'cancreate'}},'emaildomain');
16185: }
16186: }
16187: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16188: } elsif ($chosen eq 'custom') {
16189: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16190: $email_rule{$type} = [];
16191: if (ref($emailrules) eq 'HASH') {
16192: foreach my $rule (@possemail_rules) {
16193: if (exists($emailrules->{$rule})) {
16194: push(@{$email_rule{$type}},$rule);
16195: }
16196: }
16197: }
16198: if (@{$email_rule{$type}}) {
16199: $cancreate{'emailoptions'}{$type} = 'custom';
16200: if (ref($curr_rule{$type}) eq 'ARRAY') {
16201: if (@{$curr_rule{$type}} > 0) {
16202: foreach my $rule (@{$curr_rule{$type}}) {
16203: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16204: push(@{$changes{'email_rule'}},$type);
16205: }
16206: }
16207: }
16208: foreach my $type (@{$email_rule{$type}}) {
16209: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16210: push(@{$changes{'email_rule'}},$type);
16211: }
16212: }
16213: } else {
16214: push(@{$changes{'email_rule'}},$type);
16215: }
16216: }
16217: } else {
16218: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16219: }
16220: }
16221: }
16222: if (@types) {
16223: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16224: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16225: if (@changed) {
16226: push(@{$changes{'inststatus'}},'inststatusguest');
16227: }
16228: } else {
16229: push(@{$changes{'inststatus'}},'inststatusguest');
16230: }
16231: }
16232: } else {
16233: delete($env{'form.cancreate_email'});
16234: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16235: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16236: push(@{$changes{'inststatus'}},'inststatusguest');
16237: }
16238: }
16239: }
16240: } else {
16241: $save_inststatus{'inststatusguest'} = [];
16242: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16243: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16244: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 16245: }
16246: }
1.160.6.34 raeburn 16247: }
16248: } else {
16249: if ($env{'form.cancreate_'.$item}) {
16250: push(@{$cancreate{'selfcreate'}},$item);
16251: }
16252: }
16253: }
1.160.6.93 raeburn 16254: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 16255: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16256: #
1.160.6.35 raeburn 16257: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16258: # value set to one), if self-creation with e-mail address permitted, where $type is user type: faculty, staff, student etc.
1.160.6.34 raeburn 16259: #
1.160.6.40 raeburn 16260:
1.160.6.48 raeburn 16261: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 16262: push(@contexts,'emailusername');
1.160.6.93 raeburn 16263: if (@statuses) {
16264: foreach my $type (@statuses) {
1.160.6.35 raeburn 16265: if (ref($infofields) eq 'ARRAY') {
16266: foreach my $field (@{$infofields}) {
16267: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16268: $cancreate{'emailusername'}{$type}{$field} = $1;
16269: }
16270: }
1.160.6.34 raeburn 16271: }
16272: }
16273: }
16274: #
16275: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 16276: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 16277: #
16278:
16279: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16280: @approvalnotify = sort(@approvalnotify);
16281: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16282: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16283: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16284: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16285: push(@{$changes{'cancreate'}},'notify');
16286: }
16287: } else {
16288: if ($cancreate{'notify'}{'approval'}) {
16289: push(@{$changes{'cancreate'}},'notify');
16290: }
16291: }
16292: } elsif ($cancreate{'notify'}{'approval'}) {
16293: push(@{$changes{'cancreate'}},'notify');
16294: }
16295:
16296: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16297: }
16298: #
1.160.6.40 raeburn 16299: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 16300: # institutional log-in.
16301: #
16302: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16303: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16304: ($domdefaults{'auth_def'} eq 'localauth'))) {
16305: $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.').' '.
16306: &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.');
16307: }
16308: }
16309: my @fields = ('lastname','firstname','middlename','generation',
16310: 'permanentemail','id');
1.160.6.44 raeburn 16311: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 16312: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16313: #
16314: # Where usernames may created for institutional log-in and/or institutional single sign on:
16315: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16316: # may self-create accounts
16317: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
16318: # which the user may supply, if institutional data is unavailable.
16319: #
16320: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 16321: if (@types) {
16322: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
16323: push(@contexts,'statustocreate');
16324: foreach my $type (@types) {
1.160.6.34 raeburn 16325: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
16326: foreach my $field (@fields) {
16327: if (grep(/^\Q$field\E$/,@modifiable)) {
16328: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
16329: } else {
16330: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
16331: }
16332: }
16333: }
16334: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 16335: foreach my $type (@types) {
1.160.6.34 raeburn 16336: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
16337: foreach my $field (@fields) {
16338: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
16339: $curr_usermodify{'selfcreate'}{$type}{$field}) {
16340: push(@{$changes{'selfcreate'}},$type);
16341: last;
16342: }
16343: }
16344: }
16345: }
16346: } else {
1.160.6.93 raeburn 16347: foreach my $type (@types) {
1.160.6.34 raeburn 16348: push(@{$changes{'selfcreate'}},$type);
16349: }
16350: }
16351: }
1.160.6.44 raeburn 16352: foreach my $field (@shibfields) {
16353: if ($env{'form.shibenv_'.$field} ne '') {
16354: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
16355: }
16356: }
16357: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16358: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
16359: foreach my $field (@shibfields) {
16360: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
16361: push(@{$changes{'cancreate'}},'shibenv');
16362: }
16363: }
16364: } else {
16365: foreach my $field (@shibfields) {
16366: if ($env{'form.shibenv_'.$field}) {
16367: push(@{$changes{'cancreate'}},'shibenv');
16368: last;
16369: }
16370: }
16371: }
16372: }
1.160.6.34 raeburn 16373: }
16374: foreach my $item (@contexts) {
16375: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
16376: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
16377: if (ref($cancreate{$item}) eq 'ARRAY') {
16378: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
16379: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16380: push(@{$changes{'cancreate'}},$item);
16381: }
16382: }
16383: }
16384: }
16385: if (ref($cancreate{$item}) eq 'ARRAY') {
16386: foreach my $type (@{$cancreate{$item}}) {
16387: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
16388: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16389: push(@{$changes{'cancreate'}},$item);
16390: }
16391: }
16392: }
16393: }
16394: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
16395: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 16396: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
16397: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
16398: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
16399: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 16400: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16401: push(@{$changes{'cancreate'}},$item);
16402: }
16403: }
16404: }
1.160.6.93 raeburn 16405: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16406: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 16407: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16408: push(@{$changes{'cancreate'}},$item);
16409: }
1.160.6.34 raeburn 16410: }
16411: }
16412: }
1.160.6.93 raeburn 16413: foreach my $type (keys(%{$cancreate{$item}})) {
16414: if (ref($cancreate{$item}{$type}) eq 'HASH') {
16415: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
16416: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
16417: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 16418: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16419: push(@{$changes{'cancreate'}},$item);
16420: }
16421: }
16422: } else {
16423: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16424: push(@{$changes{'cancreate'}},$item);
16425: }
16426: }
16427: }
1.160.6.93 raeburn 16428: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16429: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 16430: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16431: push(@{$changes{'cancreate'}},$item);
16432: }
1.160.6.34 raeburn 16433: }
16434: }
16435: }
16436: }
16437: } elsif ($curr_usercreation{'cancreate'}{$item}) {
16438: if (ref($cancreate{$item}) eq 'ARRAY') {
16439: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
16440: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16441: push(@{$changes{'cancreate'}},$item);
16442: }
16443: }
1.160.6.93 raeburn 16444: }
16445: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16446: if (ref($cancreate{$item}) eq 'HASH') {
16447: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16448: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 16449: }
16450: }
16451: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 16452: if (ref($cancreate{$item}) eq 'HASH') {
16453: foreach my $type (keys(%{$cancreate{$item}})) {
16454: if (ref($cancreate{$item}{$type}) eq 'HASH') {
16455: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
16456: if ($cancreate{$item}{$type}{$field}) {
16457: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16458: push(@{$changes{'cancreate'}},$item);
16459: }
16460: last;
16461: }
16462: }
16463: }
16464: }
1.160.6.34 raeburn 16465: }
16466: }
16467: }
16468: #
16469: # Populate %save_usercreate hash with updates to self-creation configuration.
16470: #
16471: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
16472: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 16473: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 16474: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
16475: if (ref($cancreate{'notify'}) eq 'HASH') {
16476: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
16477: }
1.160.6.40 raeburn 16478: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
16479: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
16480: }
1.160.6.93 raeburn 16481: if (ref($cancreate{'emailverified'}) eq 'HASH') {
16482: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
16483: }
16484: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
16485: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
16486: }
16487: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
16488: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
16489: }
1.160.6.34 raeburn 16490: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
16491: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
16492: }
1.160.6.44 raeburn 16493: if (ref($cancreate{'shibenv'}) eq 'HASH') {
16494: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
16495: }
1.160.6.34 raeburn 16496: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 16497: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 16498:
16499: my %userconfig_hash = (
16500: usercreation => \%save_usercreate,
16501: usermodification => \%save_usermodify,
1.160.6.93 raeburn 16502: inststatus => \%save_inststatus,
1.160.6.34 raeburn 16503: );
1.160.6.93 raeburn 16504:
1.160.6.34 raeburn 16505: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
16506: $dom);
16507: #
1.160.6.93 raeburn 16508: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 16509: #
1.27 raeburn 16510: if ($putresult eq 'ok') {
16511: if (keys(%changes) > 0) {
16512: $resulttext = &mt('Changes made:').'<ul>';
16513: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 16514: my %lt = &selfcreation_types();
1.34 raeburn 16515: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 16516: my $chgtext = '';
1.45 raeburn 16517: if ($type eq 'selfcreate') {
1.50 raeburn 16518: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 16519: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 16520: } else {
1.160.6.34 raeburn 16521: $chgtext .= &mt('Self-creation of a new account is permitted for:').
16522: '<ul>';
1.50 raeburn 16523: foreach my $case (@{$cancreate{$type}}) {
16524: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
16525: }
16526: $chgtext .= '</ul>';
1.100 raeburn 16527: if (ref($cancreate{$type}) eq 'ARRAY') {
16528: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
16529: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
16530: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 16531: $chgtext .= '<span class="LC_warning">'.
16532: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
16533: '</span><br />';
1.100 raeburn 16534: }
16535: }
16536: }
1.160.6.93 raeburn 16537: if (grep(/^email$/,@{$cancreate{$type}})) {
16538: if (!@statuses) {
16539: $chgtext .= '<span class="LC_warning">'.
16540: &mt("However, e-mail verification is currently set to 'unavailable' for all user types (including 'other'), so self-creation of accounts is not possible for non-institutional log-in.").
16541: '</span><br />';
16542:
16543: }
16544: }
1.100 raeburn 16545: }
1.43 raeburn 16546: }
1.160.6.44 raeburn 16547: } elsif ($type eq 'shibenv') {
16548: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 16549: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 16550: } else {
16551: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
16552: '<ul>';
16553: foreach my $field (@shibfields) {
16554: next if ($cancreate{$type}{$field} eq '');
16555: if ($field eq 'inststatus') {
16556: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
16557: } else {
16558: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
16559: }
16560: }
16561: $chgtext .= '</ul>';
1.160.6.93 raeburn 16562: }
1.93 raeburn 16563: } elsif ($type eq 'statustocreate') {
1.96 raeburn 16564: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
16565: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
16566: if (@{$cancreate{'selfcreate'}} > 0) {
16567: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 16568: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 16569: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 16570: $chgtext .= '<br />'.
16571: '<span class="LC_warning">'.
16572: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
16573: '</span>';
16574: }
1.160.6.93 raeburn 16575: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 16576: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 16577: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
16578: } else {
16579: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
16580: }
16581: $chgtext .= '<ul>';
16582: foreach my $case (@{$cancreate{$type}}) {
16583: if ($case eq 'default') {
16584: $chgtext .= '<li>'.$othertitle.'</li>';
16585: } else {
1.160.6.93 raeburn 16586: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 16587: }
16588: }
1.100 raeburn 16589: $chgtext .= '</ul>';
16590: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 16591: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 16592: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
16593: '</span>';
1.100 raeburn 16594: }
16595: }
16596: } else {
16597: if (@{$cancreate{$type}} == 0) {
16598: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
16599: } else {
16600: $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 16601: }
16602: }
1.160.6.93 raeburn 16603: $chgtext .= '<br />';
1.93 raeburn 16604: }
1.160.6.40 raeburn 16605: } elsif ($type eq 'selfcreateprocessing') {
16606: my %choices = &Apache::lonlocal::texthash (
16607: automatic => 'Automatic approval',
16608: approval => 'Queued for approval',
16609: );
1.160.6.93 raeburn 16610: if (@types) {
16611: if (@statuses) {
16612: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
16613: '<ul>';
16614: foreach my $status (@statuses) {
16615: if ($status eq 'default') {
16616: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
16617: } else {
16618: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
16619: }
16620: }
16621: $chgtext .= '</ul>';
16622: }
16623: } else {
16624: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
16625: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
16626: }
16627: } elsif ($type eq 'emailverified') {
16628: my %options = &Apache::lonlocal::texthash (
16629: all => 'Same as e-mail',
16630: first => 'Omit @domain',
16631: free => 'Free to choose',
16632: );
16633: if (@types) {
16634: if (@statuses) {
16635: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
16636: '<ul>';
16637: foreach my $status (@statuses) {
16638: if ($status eq 'default') {
16639: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
16640: } else {
16641: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
16642: }
16643: }
16644: $chgtext .= '</ul>';
16645: }
1.160.6.40 raeburn 16646: } else {
1.160.6.93 raeburn 16647: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
16648: $options{$cancreate{'emailverified'}{'default'}});
16649: }
16650: } elsif ($type eq 'emailoptions') {
16651: my %options = &Apache::lonlocal::texthash (
16652: any => 'Any e-mail',
16653: inst => 'Institutional only',
16654: noninst => 'Non-institutional only',
16655: custom => 'Custom restrictions',
16656: );
16657: if (@types) {
16658: if (@statuses) {
16659: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
16660: '<ul>';
16661: foreach my $status (@statuses) {
16662: if ($type eq 'default') {
16663: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
16664: } else {
16665: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
16666: }
16667: }
16668: $chgtext .= '</ul>';
16669: }
16670: } else {
16671: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
16672: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
16673: } else {
16674: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
16675: $options{$cancreate{'emailoptions'}{'default'}});
16676: }
16677: }
16678: } elsif ($type eq 'emaildomain') {
16679: my $output;
16680: if (@statuses) {
16681: foreach my $type (@statuses) {
16682: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
16683: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
16684: if ($type eq 'default') {
16685: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16686: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
16687: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
16688: } else {
16689: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
16690: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
16691: }
16692: } else {
16693: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16694: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
16695: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
16696: } else {
16697: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
16698: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
16699: }
16700: }
16701: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
16702: if ($type eq 'default') {
16703: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16704: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
16705: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
16706: } else {
16707: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
16708: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
16709: }
16710: } else {
16711: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16712: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
16713: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
16714: } else {
16715: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
16716: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
16717: }
16718: }
16719: }
16720: }
16721: }
16722: }
16723: if ($output ne '') {
16724: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
16725: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 16726: }
1.160.6.5 raeburn 16727: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 16728: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 16729: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
16730: } else {
16731: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 16732: if ($captchas{$savecaptcha{$type}}) {
16733: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 16734: } else {
16735: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
16736: }
16737: }
16738: } elsif ($type eq 'recaptchakeys') {
16739: my ($privkey,$pubkey);
1.160.6.34 raeburn 16740: if (ref($savecaptcha{$type}) eq 'HASH') {
16741: $pubkey = $savecaptcha{$type}{'public'};
16742: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 16743: }
16744: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
16745: if (!$pubkey) {
16746: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
16747: } else {
16748: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
16749: }
16750: if (!$privkey) {
16751: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
16752: } else {
16753: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
16754: }
16755: $chgtext .= '</ul>';
1.160.6.69 raeburn 16756: } elsif ($type eq 'recaptchaversion') {
16757: if ($savecaptcha{'captcha'} eq 'recaptcha') {
16758: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
16759: }
1.160.6.34 raeburn 16760: } elsif ($type eq 'emailusername') {
16761: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 16762: if (@statuses) {
16763: foreach my $type (@statuses) {
1.160.6.35 raeburn 16764: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
16765: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 16766: $chgtext .= &mt('When self-creating account with e-mail verification, the following information will be provided by [_1]:',"'$usertypes{$type}'").
1.160.6.35 raeburn 16767: '<ul>';
16768: foreach my $field (@{$infofields}) {
16769: if ($cancreate{'emailusername'}{$type}{$field}) {
16770: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
16771: }
16772: }
1.160.6.50 raeburn 16773: $chgtext .= '</ul>';
16774: } else {
1.160.6.93 raeburn 16775: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.35 raeburn 16776: }
16777: } else {
1.160.6.93 raeburn 16778: $chgtext .= &mt('When self creating account with e-mail verification, no information besides e-mail address will be provided by [_1].',"'$usertypes{$type}'").'<br />';
1.160.6.34 raeburn 16779: }
16780: }
16781: }
16782: }
16783: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 16784: my $numapprove = 0;
1.160.6.34 raeburn 16785: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16786: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
16787: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 16788: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
16789: $numapprove ++;
1.160.6.34 raeburn 16790: }
16791: }
1.43 raeburn 16792: }
1.160.6.93 raeburn 16793: unless ($numapprove) {
16794: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
16795: }
1.34 raeburn 16796: }
1.160.6.34 raeburn 16797: if ($chgtext) {
16798: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 16799: }
16800: }
16801: }
1.160.6.93 raeburn 16802: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 16803: my ($emailrules,$emailruleorder) =
16804: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 16805: foreach my $type (@{$changes{'email_rule'}}) {
16806: if (ref($email_rule{$type}) eq 'ARRAY') {
16807: my $chgtext = '<ul>';
16808: foreach my $rule (@{$email_rule{$type}}) {
16809: if (ref($emailrules->{$rule}) eq 'HASH') {
16810: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16811: }
16812: }
16813: $chgtext .= '</ul>';
16814: my $typename;
16815: if (@types) {
16816: if ($type eq 'default') {
16817: $typename = $othertitle;
16818: } else {
16819: $typename = $usertypes{$type};
16820: }
16821: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16822: }
16823: if (@{$email_rule{$type}} > 0) {
16824: $resulttext .= '<li>'.
16825: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16826: $usertypes{$type}).
16827: $chgtext.
16828: '</li>';
16829: } else {
16830: $resulttext .= '<li>'.
16831: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16832: '</li>'.
16833: &mt('(Affiliation: [_1])',$typename);
16834: }
1.43 raeburn 16835: }
16836: }
1.160.6.93 raeburn 16837: }
16838: if (ref($changes{'inststatus'}) eq 'ARRAY') {
16839: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
16840: if (@{$save_inststatus{'inststatusguest'}} > 0) {
16841: my $chgtext = '<ul>';
16842: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
16843: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
16844: }
16845: $chgtext .= '</ul>';
16846: $resulttext .= '<li>'.
16847: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
16848: $chgtext.
16849: '</li>';
16850: } else {
16851: $resulttext .= '<li>'.
16852: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
16853: '</li>';
16854: }
1.43 raeburn 16855: }
16856: }
1.160.6.34 raeburn 16857: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
16858: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
16859: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16860: foreach my $type (@{$changes{'selfcreate'}}) {
16861: my $typename = $type;
1.160.6.93 raeburn 16862: if (keys(%usertypes) > 0) {
16863: if ($usertypes{$type} ne '') {
16864: $typename = $usertypes{$type};
1.28 raeburn 16865: }
16866: }
1.160.6.34 raeburn 16867: my @modifiable;
16868: $resulttext .= '<li>'.
16869: &mt('Self-creation of account by users with status: [_1]',
16870: '<span class="LC_cusr_emph">'.$typename.'</span>').
16871: ' - '.&mt('modifiable fields (if institutional data blank): ');
16872: foreach my $field (@fields) {
16873: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
16874: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
16875: }
16876: }
16877: if (@modifiable > 0) {
16878: $resulttext .= join(', ',@modifiable);
1.43 raeburn 16879: } else {
1.160.6.34 raeburn 16880: $resulttext .= &mt('none');
1.43 raeburn 16881: }
1.160.6.34 raeburn 16882: $resulttext .= '</li>';
1.28 raeburn 16883: }
1.160.6.34 raeburn 16884: $resulttext .= '</ul></li>';
1.28 raeburn 16885: }
1.27 raeburn 16886: $resulttext .= '</ul>';
1.160.6.93 raeburn 16887: my $cachetime = 24*60*60;
16888: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
16889: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16890: if (ref($lastactref) eq 'HASH') {
16891: $lastactref->{'domdefaults'} = 1;
16892: }
1.27 raeburn 16893: } else {
1.160.6.34 raeburn 16894: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 16895: }
16896: } else {
16897: $resulttext = '<span class="LC_error">'.
1.23 raeburn 16898: &mt('An error occurred: [_1]',$putresult).'</span>';
16899: }
1.43 raeburn 16900: if ($warningmsg ne '') {
16901: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16902: }
1.23 raeburn 16903: return $resulttext;
16904: }
16905:
1.160.6.5 raeburn 16906: sub process_captcha {
1.160.6.104 raeburn 16907: my ($container,$changes,$newsettings,$currsettings) = @_;
16908: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 16909: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
16910: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
16911: $newsettings->{'captcha'} = 'original';
16912: }
1.160.6.104 raeburn 16913: my %current;
16914: if (ref($currsettings) eq 'HASH') {
16915: %current = %{$currsettings};
16916: }
16917: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 16918: if ($container eq 'cancreate') {
16919: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16920: push(@{$changes->{'cancreate'}},'captcha');
16921: } elsif (!defined($changes->{'cancreate'})) {
16922: $changes->{'cancreate'} = ['captcha'];
16923: }
1.160.6.102 raeburn 16924: } elsif ($container eq 'passwords') {
16925: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16926: } else {
16927: $changes->{'captcha'} = 1;
16928: }
16929: }
1.160.6.69 raeburn 16930: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 16931: if ($newsettings->{'captcha'} eq 'recaptcha') {
16932: $newpub = $env{'form.'.$container.'_recaptchapub'};
16933: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 16934: $newpub =~ s/[^\w\-]//g;
16935: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 16936: $newsettings->{'recaptchakeys'} = {
16937: public => $newpub,
16938: private => $newpriv,
16939: };
1.160.6.69 raeburn 16940: $newversion = $env{'form.'.$container.'_recaptchaversion'};
16941: $newversion =~ s/\D//g;
16942: if ($newversion ne '2') {
16943: $newversion = 1;
16944: }
16945: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 16946: }
1.160.6.104 raeburn 16947: if (ref($current{'recaptchakeys'}) eq 'HASH') {
16948: $currpub = $current{'recaptchakeys'}{'public'};
16949: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 16950: unless ($newsettings->{'captcha'} eq 'recaptcha') {
16951: $newsettings->{'recaptchakeys'} = {
16952: public => '',
16953: private => '',
16954: }
16955: }
1.160.6.5 raeburn 16956: }
1.160.6.104 raeburn 16957: if ($current{'captcha'} eq 'recaptcha') {
16958: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 16959: if ($currversion ne '2') {
16960: $currversion = 1;
16961: }
16962: }
16963: if ($currversion ne $newversion) {
16964: if ($container eq 'cancreate') {
16965: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16966: push(@{$changes->{'cancreate'}},'recaptchaversion');
16967: } elsif (!defined($changes->{'cancreate'})) {
16968: $changes->{'cancreate'} = ['recaptchaversion'];
16969: }
1.160.6.102 raeburn 16970: } elsif ($container eq 'passwords') {
16971: $changes->{'reset'} = 1;
1.160.6.69 raeburn 16972: } else {
16973: $changes->{'recaptchaversion'} = 1;
16974: }
16975: }
1.160.6.5 raeburn 16976: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
16977: if ($container eq 'cancreate') {
16978: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
16979: push(@{$changes->{'cancreate'}},'recaptchakeys');
16980: } elsif (!defined($changes->{'cancreate'})) {
16981: $changes->{'cancreate'} = ['recaptchakeys'];
16982: }
1.160.6.102 raeburn 16983: } elsif ($container eq 'passwords') {
16984: $changes->{'reset'} = 1;
1.160.6.5 raeburn 16985: } else {
16986: $changes->{'recaptchakeys'} = 1;
16987: }
16988: }
16989: return;
16990: }
16991:
1.33 raeburn 16992: sub modify_usermodification {
16993: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16994: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 16995: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16996: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 16997: if ($key eq 'selfcreate') {
16998: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
16999: } else {
17000: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17001: }
1.33 raeburn 17002: }
17003: }
1.160.6.34 raeburn 17004: my @contexts = ('author','course');
1.33 raeburn 17005: my %context_title = (
17006: author => 'In author context',
17007: course => 'In course context',
17008: );
17009: my @fields = ('lastname','firstname','middlename','generation',
17010: 'permanentemail','id');
17011: my %roles = (
17012: author => ['ca','aa'],
17013: course => ['st','ep','ta','in','cr'],
17014: );
17015: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17016: foreach my $context (@contexts) {
17017: foreach my $role (@{$roles{$context}}) {
17018: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17019: foreach my $item (@fields) {
17020: if (grep(/^\Q$item\E$/,@modifiable)) {
17021: $modifyhash{$context}{$role}{$item} = 1;
17022: } else {
17023: $modifyhash{$context}{$role}{$item} = 0;
17024: }
17025: }
17026: }
17027: if (ref($curr_usermodification{$context}) eq 'HASH') {
17028: foreach my $role (@{$roles{$context}}) {
17029: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17030: foreach my $field (@fields) {
17031: if ($modifyhash{$context}{$role}{$field} ne
17032: $curr_usermodification{$context}{$role}{$field}) {
17033: push(@{$changes{$context}},$role);
17034: last;
17035: }
17036: }
17037: }
17038: }
17039: } else {
17040: foreach my $context (@contexts) {
17041: foreach my $role (@{$roles{$context}}) {
17042: push(@{$changes{$context}},$role);
17043: }
17044: }
17045: }
17046: }
17047: my %usermodification_hash = (
17048: usermodification => \%modifyhash,
17049: );
17050: my $putresult = &Apache::lonnet::put_dom('configuration',
17051: \%usermodification_hash,$dom);
17052: if ($putresult eq 'ok') {
17053: if (keys(%changes) > 0) {
17054: $resulttext = &mt('Changes made: ').'<ul>';
17055: foreach my $context (@contexts) {
17056: if (ref($changes{$context}) eq 'ARRAY') {
17057: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17058: if (ref($changes{$context}) eq 'ARRAY') {
17059: foreach my $role (@{$changes{$context}}) {
17060: my $rolename;
1.160.6.34 raeburn 17061: if ($role eq 'cr') {
17062: $rolename = &mt('Custom');
1.33 raeburn 17063: } else {
1.160.6.34 raeburn 17064: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17065: }
17066: my @modifiable;
1.160.6.34 raeburn 17067: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17068: foreach my $field (@fields) {
17069: if ($modifyhash{$context}{$role}{$field}) {
17070: push(@modifiable,$fieldtitles{$field});
17071: }
17072: }
17073: if (@modifiable > 0) {
17074: $resulttext .= join(', ',@modifiable);
17075: } else {
17076: $resulttext .= &mt('none');
17077: }
17078: $resulttext .= '</li>';
17079: }
17080: $resulttext .= '</ul></li>';
17081: }
17082: }
17083: }
17084: $resulttext .= '</ul>';
17085: } else {
17086: $resulttext = &mt('No changes made to user modification settings');
17087: }
17088: } else {
17089: $resulttext = '<span class="LC_error">'.
17090: &mt('An error occurred: [_1]',$putresult).'</span>';
17091: }
17092: return $resulttext;
17093: }
17094:
1.43 raeburn 17095: sub modify_defaults {
1.160.6.27 raeburn 17096: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17097: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 17098: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 17099: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 17100: 'portal_def');
1.160.6.118.2 14(raebu 17101:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17102: foreach my $item (@items) {
17103: $newvalues{$item} = $env{'form.'.$item};
17104: if ($item eq 'auth_def') {
17105: if ($newvalues{$item} ne '') {
17106: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17107: push(@errors,$item);
17108: }
17109: }
17110: } elsif ($item eq 'lang_def') {
17111: if ($newvalues{$item} ne '') {
17112: if ($newvalues{$item} =~ /^(\w+)/) {
17113: my $langcode = $1;
1.103 raeburn 17114: if ($langcode ne 'x_chef') {
17115: if (code2language($langcode) eq '') {
17116: push(@errors,$item);
17117: }
1.43 raeburn 17118: }
17119: } else {
17120: push(@errors,$item);
17121: }
17122: }
1.54 raeburn 17123: } elsif ($item eq 'timezone_def') {
17124: if ($newvalues{$item} ne '') {
1.62 raeburn 17125: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17126: push(@errors,$item);
17127: }
17128: }
1.68 raeburn 17129: } elsif ($item eq 'datelocale_def') {
17130: if ($newvalues{$item} ne '') {
17131: my @datelocale_ids = DateTime::Locale->ids();
17132: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17133: push(@errors,$item);
17134: }
17135: }
1.141 raeburn 17136: } elsif ($item eq 'portal_def') {
17137: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 17138:23): if ($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])\/?$/) {
17139:23): foreach my $field ('email','web') {
17140:23): if ($env{'form.'.$item.'_'.$field}) {
17141:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17142:23): }
17143:23): }
17144:23): } else {
1.141 raeburn 17145: push(@errors,$item);
17146: }
17147: }
1.43 raeburn 17148: }
17149: if (grep(/^\Q$item\E$/,@errors)) {
17150: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 17151:23): if ($item eq 'portal_def') {
17152:23): if ($domdefaults{$item}) {
17153:23): foreach my $field ('email','web') {
17154:23): if (exists($domdefaults{$item.'_'.$field})) {
17155:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17156:23): }
17157:23): }
17158:23): }
17159:23): }
1.43 raeburn 17160: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17161: $changes{$item} = 1;
17162: }
1.160.6.118.2 12(raebu 17163:23): if ($item eq 'portal_def') {
17164:23): unless (grep(/^\Q$item\E$/,@errors)) {
17165:23): if ($newvalues{$item} eq '') {
17166:23): foreach my $field ('email','web') {
17167:23): if (exists($domdefaults{$item.'_'.$field})) {
17168:23): delete($domdefaults{$item.'_'.$field});
17169:23): }
17170:23): }
17171:23): } else {
17172:23): unless ($changes{$item}) {
17173:23): foreach my $field ('email','web') {
17174:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17175:23): $changes{$item} = 1;
17176:23): last;
17177:23): }
17178:23): }
17179:23): }
17180:23): foreach my $field ('email','web') {
17181:23): if ($newvalues{$item.'_'.$field}) {
17182:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17183:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
17184:23): delete($domdefaults{$item.'_'.$field});
17185:23): }
17186:23): }
17187:23): }
17188:23): }
17189:23): }
1.72 raeburn 17190: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17191: }
1.160.6.98 raeburn 17192: my %staticdefaults = (
17193: 'intauth_cost' => 10,
17194: 'intauth_check' => 0,
17195: 'intauth_switch' => 0,
17196: );
17197: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17198: if (exists($domdefaults{$item})) {
17199: $newvalues{$item} = $domdefaults{$item};
17200: } else {
17201: $newvalues{$item} = $staticdefaults{$item};
17202: }
17203: }
1.160.6.118.2 8(raebur 17204:2): my ($unamemaprules,$ruleorder);
17205:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17206:2): if (@possunamemaprules) {
17207:2): ($unamemaprules,$ruleorder) =
17208:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
17209:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17210:2): if (@{$ruleorder} > 0) {
17211:2): my %possrules;
17212:2): map { $possrules{$_} = 1; } @possunamemaprules;
17213:2): foreach my $rule (@{$ruleorder}) {
17214:2): if ($possrules{$rule}) {
17215:2): push(@{$newvalues{'unamemap_rule'}},$rule);
17216:2): }
17217:2): }
17218:2): }
17219:2): }
17220:2): }
17221:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17222:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17223:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17224:2): $newvalues{'unamemap_rule'});
17225:2): if (@rulediffs) {
17226:2): $changes{'unamemap_rule'} = 1;
17227:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17228:2): }
17229:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17230:2): $changes{'unamemap_rule'} = 1;
17231:2): delete($domdefaults{'unamemap_rule'});
17232:2): }
17233:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17234:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
17235:2): $changes{'unamemap_rule'} = 1;
17236:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17237:2): }
17238:2): }
1.43 raeburn 17239: my %defaults_hash = (
1.72 raeburn 17240: defaults => \%newvalues,
17241: );
1.43 raeburn 17242: my $title = &defaults_titles();
1.160.6.40 raeburn 17243:
17244: my $currinststatus;
17245: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17246: $currinststatus = $domconfig{'inststatus'};
17247: } else {
17248: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17249: $currinststatus = {
17250: inststatustypes => $usertypes,
17251: inststatusorder => $types,
17252: inststatusguest => [],
17253: };
17254: }
17255: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17256: my @allpos;
17257: my %alltypes;
1.160.6.93 raeburn 17258: my @inststatusguest;
17259: if (ref($currinststatus) eq 'HASH') {
17260: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17261: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17262: unless (grep(/^\Q$type\E$/,@todelete)) {
17263: push(@inststatusguest,$type);
17264: }
17265: }
17266: }
17267: }
17268: my ($currtitles,$currorder);
1.160.6.40 raeburn 17269: if (ref($currinststatus) eq 'HASH') {
17270: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17271: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17272: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17273: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17274: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17275: }
17276: }
17277: unless (grep(/^\Q$type\E$/,@todelete)) {
17278: my $position = $env{'form.inststatus_pos_'.$type};
17279: $position =~ s/\D+//g;
17280: $allpos[$position] = $type;
17281: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17282: $alltypes{$type} =~ s/`//g;
17283: }
17284: }
17285: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17286: $currtitles =~ s/,$//;
17287: }
17288: }
17289: if ($env{'form.addinststatus'}) {
17290: my $newtype = $env{'form.addinststatus'};
17291: $newtype =~ s/\W//g;
17292: unless (exists($alltypes{$newtype})) {
17293: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17294: $alltypes{$newtype} =~ s/`//g;
17295: my $position = $env{'form.addinststatus_pos'};
17296: $position =~ s/\D+//g;
17297: if ($position ne '') {
17298: $allpos[$position] = $newtype;
17299: }
17300: }
17301: }
1.160.6.93 raeburn 17302: my @orderedstatus;
1.160.6.40 raeburn 17303: foreach my $type (@allpos) {
17304: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17305: push(@orderedstatus,$type);
17306: }
17307: }
17308: foreach my $type (keys(%alltypes)) {
17309: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17310: delete($alltypes{$type});
17311: }
17312: }
17313: $defaults_hash{'inststatus'} = {
17314: inststatustypes => \%alltypes,
17315: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 17316: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 17317: };
17318: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
17319: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
17320: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
17321: }
17322: }
17323: if ($currorder ne join(',',@orderedstatus)) {
17324: $changes{'inststatus'}{'inststatusorder'} = 1;
17325: }
17326: my $newtitles;
17327: foreach my $item (@orderedstatus) {
17328: $newtitles .= $alltypes{$item}.',';
17329: }
17330: $newtitles =~ s/,$//;
17331: if ($currtitles ne $newtitles) {
17332: $changes{'inststatus'}{'inststatustypes'} = 1;
17333: }
1.43 raeburn 17334: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
17335: $dom);
17336: if ($putresult eq 'ok') {
17337: if (keys(%changes) > 0) {
17338: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 17339: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 17340: 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";
17341: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 17342: if ($item eq 'inststatus') {
17343: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 17344: if (@orderedstatus) {
1.160.6.40 raeburn 17345: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
17346: foreach my $type (@orderedstatus) {
17347: $resulttext .= $alltypes{$type}.', ';
17348: }
17349: $resulttext =~ s/, $//;
17350: $resulttext .= '</li>';
1.160.6.93 raeburn 17351: } else {
17352: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 17353: }
17354: }
1.160.6.118.2 8(raebur 17355:2): } elsif ($item eq 'unamemap_rule') {
17356:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17357:2): my @rulenames;
17358:2): if (ref($unamemaprules) eq 'HASH') {
17359:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
17360:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
17361:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
17362:2): }
17363:2): }
17364:2): }
17365:2): if (@rulenames) {
17366:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
17367:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
17368:2): '</li>';
17369:2): } else {
14(raebu 17370:23): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
17371:23): }
8(raebur 17372:2): } else {
17373:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
17374:2): }
1.160.6.40 raeburn 17375: } else {
17376: my $value = $env{'form.'.$item};
17377: if ($value eq '') {
17378: $value = &mt('none');
17379: } elsif ($item eq 'auth_def') {
17380: my %authnames = &authtype_names();
17381: my %shortauth = (
17382: internal => 'int',
17383: krb4 => 'krb4',
17384: krb5 => 'krb5',
17385: localauth => 'loc',
1.160.6.118.2 14(raebu 17386:23): lti => 'lti',
1.160.6.40 raeburn 17387: );
17388: $value = $authnames{$shortauth{$value}};
17389: }
17390: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 17391:23): $mailmsgtext .= "$title->{$item} set to $value\n";
17392:23): if ($item eq 'portal_def') {
17393:23): if ($env{'form.'.$item} ne '') {
17394:23): foreach my $field ('email','web') {
17395:23): $value = $env{'form.'.$item.'_'.$field};
17396:23): if ($value) {
17397:23): $value = &mt('Yes');
17398:23): } else {
17399:23): $value = &mt('No');
17400:23): }
17401:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
17402:23): }
17403:23): }
17404:23): }
1.43 raeburn 17405: }
17406: }
17407: $resulttext .= '</ul>';
17408: $mailmsgtext .= "\n";
17409: my $cachetime = 24*60*60;
1.72 raeburn 17410: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17411: if (ref($lastactref) eq 'HASH') {
17412: $lastactref->{'domdefaults'} = 1;
17413: }
1.68 raeburn 17414: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 17415: my $notify = 1;
17416: if (ref($domconfig{'contacts'}) eq 'HASH') {
17417: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
17418: $notify = 0;
17419: }
17420: }
17421: if ($notify) {
17422: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
17423: "LON-CAPA Domain Settings Change - $dom",
17424: $mailmsgtext);
17425: }
1.54 raeburn 17426: }
1.43 raeburn 17427: } else {
1.54 raeburn 17428: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 17429: }
17430: } else {
17431: $resulttext = '<span class="LC_error">'.
17432: &mt('An error occurred: [_1]',$putresult).'</span>';
17433: }
17434: if (@errors > 0) {
17435: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
17436: foreach my $item (@errors) {
17437: $resulttext .= ' "'.$title->{$item}.'",';
17438: }
17439: $resulttext =~ s/,$//;
17440: }
17441: return $resulttext;
17442: }
17443:
1.46 raeburn 17444: sub modify_scantron {
1.160.6.24 raeburn 17445: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 17446: my ($resulttext,%confhash,%changes,$errors);
17447: my $custom = 'custom.tab';
17448: my $default = 'default.tab';
17449: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 17450: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 17451: &config_check($dom,$confname,$servadm);
17452: if ($env{'form.scantronformat.filename'} ne '') {
17453: my $error;
17454: if ($configuserok eq 'ok') {
17455: if ($switchserver) {
1.130 raeburn 17456: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 17457: } else {
17458: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 17459:23): my $modified = [];
1.46 raeburn 17460: my ($result,$scantronurl) =
1.160.6.118.2 14(raebu 17461:23): &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
17462:23): $confname,'scantron','','',$custom,
17463:23): $modified);
1.46 raeburn 17464: if ($result eq 'ok') {
17465: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 17466: $changes{'scantronformat'} = 1;
1.160.6.118.2 14(raebu 17467:23): &update_modify_urls($r,$modified);
1.46 raeburn 17468: } else {
17469: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
17470: }
17471: } else {
17472: $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);
17473: }
17474: }
17475: } else {
17476: $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);
17477: }
17478: if ($error) {
17479: &Apache::lonnet::logthis($error);
17480: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17481: }
17482: }
1.48 raeburn 17483: if (ref($domconfig{'scantron'}) eq 'HASH') {
17484: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
17485: if ($env{'form.scantronformat_del'}) {
17486: $confhash{'scantron'}{'scantronformat'} = '';
17487: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 17488: } else {
17489: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
17490: }
17491: }
17492: }
17493: my @options = ('hdr','pad','rem');
17494: my @fields = &scantroncsv_fields();
17495: my %titles = &scantronconfig_titles();
17496: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
17497: my ($newdat,$currdat,%newcol,%currcol);
17498: if (grep(/^dat$/,@formats)) {
17499: $confhash{'scantron'}{config}{dat} = 1;
17500: $newdat = 1;
17501: } else {
17502: $newdat = 0;
17503: }
17504: if (grep(/^csv$/,@formats)) {
17505: my %bynum;
17506: foreach my $field (@fields) {
17507: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
17508: my $posscol = $1;
17509: if (($posscol < 20) && (!$bynum{$posscol})) {
17510: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
17511: $bynum{$posscol} = $field;
17512: $newcol{$field} = $posscol;
17513: }
17514: }
17515: }
17516: if (keys(%newcol)) {
17517: foreach my $option (@options) {
17518: if ($env{'form.scantroncsv_'.$option}) {
17519: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
17520: }
17521: }
17522: }
17523: }
17524: $currdat = 1;
17525: if (ref($domconfig{'scantron'}) eq 'HASH') {
17526: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
17527: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
17528: $currdat = 0;
17529: }
17530: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
17531: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
17532: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
17533: }
17534: }
17535: }
17536: }
17537: if ($currdat != $newdat) {
17538: $changes{'config'} = 1;
17539: } else {
17540: foreach my $field (@fields) {
17541: if ($currcol{$field} ne '') {
17542: if ($currcol{$field} ne $newcol{$field}) {
17543: $changes{'config'} = 1;
17544: last;
17545: }
17546: } elsif ($newcol{$field} ne '') {
17547: $changes{'config'} = 1;
17548: last;
1.46 raeburn 17549: }
17550: }
17551: }
17552: if (keys(%confhash) > 0) {
17553: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
17554: $dom);
17555: if ($putresult eq 'ok') {
17556: if (keys(%changes) > 0) {
1.48 raeburn 17557: if (ref($confhash{'scantron'}) eq 'HASH') {
17558: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 17559: if ($changes{'scantronformat'}) {
17560: if ($confhash{'scantron'}{'scantronformat'} eq '') {
17561: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
17562: } else {
17563: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
17564: }
17565: }
17566: if ($changes{'config'}) {
17567: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
17568: if ($confhash{'scantron'}{'config'}{'dat'}) {
17569: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
17570: }
17571: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
17572: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
17573: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
17574: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
17575: foreach my $field (@fields) {
17576: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
17577: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
17578: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
17579: }
17580: }
17581: $resulttext .= '</ul></li>';
17582: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
17583: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
17584: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
17585: foreach my $option (@options) {
17586: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
17587: $resulttext .= '<li>'.$titles{$option}.'</li>';
17588: }
17589: }
17590: $resulttext .= '</ul></li>';
17591: }
17592: }
17593: }
17594: }
17595: }
17596: } else {
17597: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
17598: }
1.46 raeburn 17599: }
1.48 raeburn 17600: $resulttext .= '</ul>';
17601: } else {
1.130 raeburn 17602: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 17603: }
17604: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 17605: if (ref($lastactref) eq 'HASH') {
17606: $lastactref->{'domainconfig'} = 1;
17607: }
1.46 raeburn 17608: } else {
1.160.6.97 raeburn 17609: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 17610: }
17611: } else {
17612: $resulttext = '<span class="LC_error">'.
17613: &mt('An error occurred: [_1]',$putresult).'</span>';
17614: }
17615: } else {
1.160.6.97 raeburn 17616: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 17617: }
17618: if ($errors) {
1.160.6.118.2 14(raebu 17619:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17620:23): $errors.'</ul></p>';
1.46 raeburn 17621: }
17622: return $resulttext;
17623: }
17624:
1.48 raeburn 17625: sub modify_coursecategories {
1.160.6.43 raeburn 17626: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 17627: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
17628: $cathash);
1.48 raeburn 17629: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 17630: my @catitems = ('unauth','auth');
17631: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 17632: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 17633: $cathash = $domconfig{'coursecategories'}{'cats'};
17634: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
17635: $changes{'togglecats'} = 1;
17636: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
17637: }
17638: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
17639: $changes{'categorize'} = 1;
17640: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
17641: }
1.120 raeburn 17642: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
17643: $changes{'togglecatscomm'} = 1;
17644: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
17645: }
17646: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
17647: $changes{'categorizecomm'} = 1;
17648: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
17649: }
1.160.6.42 raeburn 17650: foreach my $item (@catitems) {
17651: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
17652: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
17653: $changes{$item} = 1;
17654: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
17655: }
17656: }
17657: }
1.57 raeburn 17658: } else {
17659: $changes{'togglecats'} = 1;
17660: $changes{'categorize'} = 1;
1.124 raeburn 17661: $changes{'togglecatscomm'} = 1;
17662: $changes{'categorizecomm'} = 1;
1.87 raeburn 17663: $domconfig{'coursecategories'} = {
17664: togglecats => $env{'form.togglecats'},
17665: categorize => $env{'form.categorize'},
1.124 raeburn 17666: togglecatscomm => $env{'form.togglecatscomm'},
17667: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 17668: };
1.160.6.42 raeburn 17669: foreach my $item (@catitems) {
17670: if ($env{'form.coursecat_'.$item} ne 'std') {
17671: $changes{$item} = 1;
17672: }
17673: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
17674: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
17675: }
17676: }
1.57 raeburn 17677: }
17678: if (ref($cathash) eq 'HASH') {
17679: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 17680: push (@deletecategory,'instcode::0');
17681: }
1.120 raeburn 17682: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
17683: push(@deletecategory,'communities::0');
17684: }
1.48 raeburn 17685: }
1.57 raeburn 17686: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
17687: if (ref($cathash) eq 'HASH') {
1.48 raeburn 17688: if (@deletecategory > 0) {
17689: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 17690: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 17691: foreach my $item (@deletecategory) {
1.57 raeburn 17692: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
17693: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 17694: $deletions{$item} = 1;
1.57 raeburn 17695: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 17696: }
17697: }
17698: }
1.57 raeburn 17699: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 17700: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 17701: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 17702: $reorderings{$item} = 1;
1.57 raeburn 17703: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 17704: }
17705: if ($env{'form.addcategory_name_'.$item} ne '') {
17706: my $newcat = $env{'form.addcategory_name_'.$item};
17707: my $newdepth = $depth+1;
17708: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 17709: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 17710: $adds{$newitem} = 1;
17711: }
17712: if ($env{'form.subcat_'.$item} ne '') {
17713: my $newcat = $env{'form.subcat_'.$item};
17714: my $newdepth = $depth+1;
17715: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 17716: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 17717: $adds{$newitem} = 1;
17718: }
17719: }
17720: }
17721: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 17722: if (ref($cathash) eq 'HASH') {
1.48 raeburn 17723: my $newitem = 'instcode::0';
1.57 raeburn 17724: if ($cathash->{$newitem} eq '') {
17725: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 17726: $adds{$newitem} = 1;
17727: }
17728: } else {
17729: my $newitem = 'instcode::0';
1.57 raeburn 17730: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 17731: $adds{$newitem} = 1;
17732: }
17733: }
1.120 raeburn 17734: if ($env{'form.communities'} eq '1') {
17735: if (ref($cathash) eq 'HASH') {
17736: my $newitem = 'communities::0';
17737: if ($cathash->{$newitem} eq '') {
17738: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17739: $adds{$newitem} = 1;
17740: }
17741: } else {
17742: my $newitem = 'communities::0';
17743: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17744: $adds{$newitem} = 1;
17745: }
17746: }
1.48 raeburn 17747: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 17748: if (($env{'form.addcategory_name'} ne 'instcode') &&
17749: ($env{'form.addcategory_name'} ne 'communities')) {
17750: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
17751: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
17752: $adds{$newitem} = 1;
17753: }
1.48 raeburn 17754: }
1.57 raeburn 17755: my $putresult;
1.48 raeburn 17756: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17757: if (keys(%deletions) > 0) {
17758: foreach my $key (keys(%deletions)) {
17759: if ($predelallitems{$key} ne '') {
17760: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
17761: }
17762: }
17763: }
17764: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 17765: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 17766: if (ref($chkcats[0]) eq 'ARRAY') {
17767: my $depth = 0;
17768: my $chg = 0;
17769: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
17770: my $name = $chkcats[0][$i];
17771: my $item;
17772: if ($name eq '') {
17773: $chg ++;
17774: } else {
17775: $item = &escape($name).'::0';
17776: if ($chg) {
1.57 raeburn 17777: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 17778: }
17779: $depth ++;
1.57 raeburn 17780: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 17781: $depth --;
17782: }
17783: }
17784: }
1.57 raeburn 17785: }
17786: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17787: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 17788: if ($putresult eq 'ok') {
1.57 raeburn 17789: my %title = (
1.120 raeburn 17790: togglecats => 'Show/Hide a course in catalog',
17791: categorize => 'Assign a category to a course',
17792: togglecatscomm => 'Show/Hide a community in catalog',
17793: categorizecomm => 'Assign a category to a community',
1.57 raeburn 17794: );
17795: my %level = (
1.120 raeburn 17796: dom => 'set in Domain ("Modify Course/Community")',
17797: crs => 'set in Course ("Course Configuration")',
17798: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 17799: none => 'No catalog',
17800: std => 'Standard catalog',
17801: domonly => 'Domain-only catalog',
17802: codesrch => 'Code search form',
1.57 raeburn 17803: );
1.48 raeburn 17804: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 17805: if ($changes{'togglecats'}) {
17806: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
17807: }
17808: if ($changes{'categorize'}) {
17809: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 17810: }
1.120 raeburn 17811: if ($changes{'togglecatscomm'}) {
17812: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
17813: }
17814: if ($changes{'categorizecomm'}) {
17815: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
17816: }
1.160.6.42 raeburn 17817: if ($changes{'unauth'}) {
17818: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
17819: }
17820: if ($changes{'auth'}) {
17821: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
17822: }
1.57 raeburn 17823: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17824: my $cathash;
17825: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
17826: $cathash = $domconfig{'coursecategories'}{'cats'};
17827: } else {
17828: $cathash = {};
17829: }
17830: my (@cats,@trails,%allitems);
17831: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
17832: if (keys(%deletions) > 0) {
17833: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
17834: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
17835: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
17836: }
17837: $resulttext .= '</ul></li>';
17838: }
17839: if (keys(%reorderings) > 0) {
17840: my %sort_by_trail;
17841: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
17842: foreach my $key (keys(%reorderings)) {
17843: if ($allitems{$key} ne '') {
17844: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17845: }
1.48 raeburn 17846: }
1.57 raeburn 17847: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17848: $resulttext .= '<li>'.$trails[$trail].'</li>';
17849: }
17850: $resulttext .= '</ul></li>';
1.48 raeburn 17851: }
1.57 raeburn 17852: if (keys(%adds) > 0) {
17853: my %sort_by_trail;
17854: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
17855: foreach my $key (keys(%adds)) {
17856: if ($allitems{$key} ne '') {
17857: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
17858: }
17859: }
17860: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
17861: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 17862: }
1.57 raeburn 17863: $resulttext .= '</ul></li>';
1.48 raeburn 17864: }
1.160.6.92 raeburn 17865: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
17866: if (ref($lastactref) eq 'HASH') {
17867: $lastactref->{'cats'} = 1;
17868: }
1.48 raeburn 17869: }
17870: $resulttext .= '</ul>';
1.160.6.43 raeburn 17871: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 17872: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
17873: if ($changes{'auth'}) {
17874: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
17875: }
17876: if ($changes{'unauth'}) {
17877: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
17878: }
17879: my $cachetime = 24*60*60;
17880: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 17881: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 17882: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 17883: }
17884: }
1.48 raeburn 17885: } else {
17886: $resulttext = '<span class="LC_error">'.
1.57 raeburn 17887: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 17888: }
17889: } else {
1.120 raeburn 17890: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 17891: }
17892: return $resulttext;
17893: }
17894:
1.69 raeburn 17895: sub modify_serverstatuses {
17896: my ($dom,%domconfig) = @_;
17897: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
17898: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
17899: %currserverstatus = %{$domconfig{'serverstatuses'}};
17900: }
17901: my @pages = &serverstatus_pages();
17902: foreach my $type (@pages) {
17903: $newserverstatus{$type}{'namedusers'} = '';
17904: $newserverstatus{$type}{'machines'} = '';
17905: if (defined($env{'form.'.$type.'_namedusers'})) {
17906: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
17907: my @okusers;
17908: foreach my $user (@users) {
17909: my ($uname,$udom) = split(/:/,$user);
17910: if (($udom =~ /^$match_domain$/) &&
17911: (&Apache::lonnet::domain($udom)) &&
17912: ($uname =~ /^$match_username$/)) {
17913: if (!grep(/^\Q$user\E/,@okusers)) {
17914: push(@okusers,$user);
17915: }
17916: }
17917: }
17918: if (@okusers > 0) {
17919: @okusers = sort(@okusers);
17920: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
17921: }
17922: }
17923: if (defined($env{'form.'.$type.'_machines'})) {
17924: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
17925: my @okmachines;
17926: foreach my $ip (@machines) {
17927: my @parts = split(/\./,$ip);
17928: next if (@parts < 4);
17929: my $badip = 0;
17930: for (my $i=0; $i<4; $i++) {
17931: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
17932: $badip = 1;
17933: last;
17934: }
17935: }
17936: if (!$badip) {
17937: push(@okmachines,$ip);
17938: }
17939: }
17940: @okmachines = sort(@okmachines);
17941: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
17942: }
17943: }
17944: my %serverstatushash = (
17945: serverstatuses => \%newserverstatus,
17946: );
17947: foreach my $type (@pages) {
1.83 raeburn 17948: foreach my $setting ('namedusers','machines') {
1.84 raeburn 17949: my (@current,@new);
1.83 raeburn 17950: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 17951: if ($currserverstatus{$type}{$setting} ne '') {
17952: @current = split(/,/,$currserverstatus{$type}{$setting});
17953: }
17954: }
17955: if ($newserverstatus{$type}{$setting} ne '') {
17956: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 17957: }
17958: if (@current > 0) {
17959: if (@new > 0) {
17960: foreach my $item (@current) {
17961: if (!grep(/^\Q$item\E$/,@new)) {
17962: $changes{$type}{$setting} = 1;
1.82 raeburn 17963: last;
17964: }
17965: }
1.84 raeburn 17966: foreach my $item (@new) {
17967: if (!grep(/^\Q$item\E$/,@current)) {
17968: $changes{$type}{$setting} = 1;
17969: last;
1.82 raeburn 17970: }
17971: }
17972: } else {
1.83 raeburn 17973: $changes{$type}{$setting} = 1;
1.69 raeburn 17974: }
1.83 raeburn 17975: } elsif (@new > 0) {
17976: $changes{$type}{$setting} = 1;
1.69 raeburn 17977: }
17978: }
17979: }
17980: if (keys(%changes) > 0) {
1.81 raeburn 17981: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 17982: my $putresult = &Apache::lonnet::put_dom('configuration',
17983: \%serverstatushash,$dom);
17984: if ($putresult eq 'ok') {
17985: $resulttext .= &mt('Changes made:').'<ul>';
17986: foreach my $type (@pages) {
1.84 raeburn 17987: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 17988: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 17989: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 17990: if ($newserverstatus{$type}{'namedusers'} eq '') {
17991: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
17992: } else {
17993: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
17994: }
1.84 raeburn 17995: }
17996: if ($changes{$type}{'machines'}) {
1.69 raeburn 17997: if ($newserverstatus{$type}{'machines'} eq '') {
17998: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
17999: } else {
18000: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18001: }
18002:
18003: }
18004: $resulttext .= '</ul></li>';
18005: }
18006: }
18007: $resulttext .= '</ul>';
18008: } else {
18009: $resulttext = '<span class="LC_error">'.
18010: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18011:
18012: }
18013: } else {
18014: $resulttext = &mt('No changes made to access to server status pages');
18015: }
18016: return $resulttext;
18017: }
18018:
1.118 jms 18019: sub modify_helpsettings {
1.160.6.77 raeburn 18020: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 18021: my ($resulttext,$errors,%changes,%helphash);
18022: my %defaultchecked = ('submitbugs' => 'on');
18023: my @offon = ('off','on');
1.118 jms 18024: my @toggles = ('submitbugs');
1.160.6.77 raeburn 18025: my %current = ('submitbugs' => '',
18026: 'adhoc' => {},
18027: );
1.118 jms 18028: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 18029: %current = %{$domconfig{'helpsettings'}};
18030: }
1.160.6.77 raeburn 18031: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 18032: foreach my $item (@toggles) {
18033: if ($defaultchecked{$item} eq 'on') {
18034: if ($current{$item} eq '') {
18035: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 18036: $changes{$item} = 1;
18037: }
1.160.6.73 raeburn 18038: } elsif ($current{$item} ne $env{'form.'.$item}) {
18039: $changes{$item} = 1;
18040: }
18041: } elsif ($defaultchecked{$item} eq 'off') {
18042: if ($current{$item} eq '') {
18043: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 18044: $changes{$item} = 1;
18045: }
1.160.6.73 raeburn 18046: } elsif ($current{$item} ne $env{'form.'.$item}) {
18047: $changes{$item} = 1;
18048: }
18049: }
18050: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18051: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18052: }
18053: }
1.160.6.77 raeburn 18054: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 18055: my $confname = $dom.'-domainconfig';
18056: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 18057: my (@allpos,%newsettings,%changedprivs,$newrole);
18058: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 18059: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18060: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 18061: my %lt = &Apache::lonlocal::texthash(
18062: s => 'system',
18063: d => 'domain',
18064: order => 'Display order',
18065: access => 'Role usage',
1.160.6.79 raeburn 18066: all => 'All with domain helpdesk or helpdesk assistant role',
18067: dh => 'All with domain helpdesk role',
18068: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 18069: none => 'None',
18070: status => 'Determined based on institutional status',
18071: inc => 'Include all, but exclude specific personnel',
18072: exc => 'Exclude all, but include specific personnel',
18073: );
18074: for (my $num=0; $num<=$maxnum; $num++) {
18075: my ($prefix,$identifier,$rolename,%curr);
18076: if ($num == $maxnum) {
18077: next unless ($env{'form.newcusthelp'} == $maxnum);
18078: $identifier = 'custhelp'.$num;
18079: $prefix = 'helproles_'.$num;
18080: $rolename = $env{'form.custhelpname'.$num};
18081: $rolename=~s/[^A-Za-z0-9]//gs;
18082: next if ($rolename eq '');
18083: next if (exists($existing{'rolesdef_'.$rolename}));
18084: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18085: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18086: $newprivs{'c'},$confname,$dom);
18087: if ($result ne 'ok') {
18088: $errors .= '<li><span class="LC_error">'.
18089: &mt('An error occurred storing the new custom role: [_1]',
18090: $result).'</span></li>';
18091: next;
18092: } else {
18093: $changedprivs{$rolename} = \%newprivs;
18094: $newrole = $rolename;
18095: }
18096: } else {
18097: $prefix = 'helproles_'.$num;
18098: $rolename = $env{'form.'.$prefix};
18099: next if ($rolename eq '');
18100: next unless (exists($existing{'rolesdef_'.$rolename}));
18101: $identifier = 'custhelp'.$num;
18102: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18103: my %currprivs;
18104: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18105: split(/\_/,$existing{'rolesdef_'.$rolename});
18106: foreach my $level ('c','d','s') {
18107: if ($newprivs{$level} ne $currprivs{$level}) {
18108: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18109: $newprivs{'c'},$confname,$dom);
18110: if ($result ne 'ok') {
18111: $errors .= '<li><span class="LC_error">'.
18112: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18113: $rolename,$result).'</span></li>';
18114: } else {
18115: $changedprivs{$rolename} = \%newprivs;
18116: }
18117: last;
18118: }
18119: }
18120: if (ref($current{'adhoc'}) eq 'HASH') {
18121: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18122: %curr = %{$current{'adhoc'}{$rolename}};
18123: }
18124: }
18125: }
18126: my $newpos = $env{'form.'.$prefix.'_pos'};
18127: $newpos =~ s/\D+//g;
18128: $allpos[$newpos] = $rolename;
18129: my $newdesc = $env{'form.'.$prefix.'_desc'};
18130: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18131: if ($curr{'desc'}) {
18132: if ($curr{'desc'} ne $newdesc) {
18133: $changes{'customrole'}{$rolename}{'desc'} = 1;
18134: $newsettings{$rolename}{'desc'} = $newdesc;
18135: }
18136: } elsif ($newdesc ne '') {
18137: $changes{'customrole'}{$rolename}{'desc'} = 1;
18138: $newsettings{$rolename}{'desc'} = $newdesc;
18139: }
18140: my $access = $env{'form.'.$prefix.'_access'};
18141: if (grep(/^\Q$access\E$/,@accesstypes)) {
18142: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18143: if ($access eq 'status') {
18144: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18145: if (scalar(@statuses) == 0) {
18146: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18147: } else {
18148: my (@shownstatus,$numtypes);
18149: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18150: if (ref($types) eq 'ARRAY') {
18151: $numtypes = scalar(@{$types});
18152: foreach my $type (sort(@statuses)) {
18153: if ($type eq 'default') {
18154: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18155: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18156: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18157: push(@shownstatus,$usertypes->{$type});
18158: }
1.160.6.73 raeburn 18159: }
18160: }
1.160.6.77 raeburn 18161: if (grep(/^default$/,@statuses)) {
18162: push(@shownstatus,$othertitle);
18163: }
18164: if (scalar(@shownstatus) == 1+$numtypes) {
18165: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18166: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18167: } else {
18168: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18169: if (ref($curr{'status'}) eq 'ARRAY') {
18170: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18171: if (@diffs) {
18172: $changes{'customrole'}{$rolename}{$access} = 1;
18173: }
18174: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18175: $changes{'customrole'}{$rolename}{$access} = 1;
18176: }
18177: }
18178: }
18179: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18180: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18181: my @newspecstaff;
18182: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18183: foreach my $person (sort(@personnel)) {
18184: if ($domhelpdesk{$person}) {
18185: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18186: }
18187: }
18188: if (ref($curr{$access}) eq 'ARRAY') {
18189: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18190: if (@diffs) {
18191: $changes{'customrole'}{$rolename}{$access} = 1;
18192: }
18193: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18194: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 18195: }
1.160.6.77 raeburn 18196: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18197: my ($uname,$udom) = split(/:/,$person);
18198: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18199: }
18200: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 18201: }
1.160.6.77 raeburn 18202: } else {
18203: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18204: }
18205: unless ($curr{'access'} eq $access) {
18206: $changes{'customrole'}{$rolename}{'access'} = 1;
18207: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 18208: }
18209: }
1.160.6.77 raeburn 18210: if (@allpos > 0) {
18211: my $idx = 0;
18212: foreach my $rolename (@allpos) {
18213: if ($rolename ne '') {
18214: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18215: if (ref($current{'adhoc'}) eq 'HASH') {
18216: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18217: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18218: $changes{'customrole'}{$rolename}{'order'} = 1;
18219: $newsettings{$rolename}{'order'} = $idx+1;
18220: }
18221: }
1.160.6.73 raeburn 18222: }
1.160.6.77 raeburn 18223: $idx ++;
1.122 jms 18224: }
18225: }
1.118 jms 18226: }
1.123 jms 18227: my $putresult;
18228: if (keys(%changes) > 0) {
1.160.6.5 raeburn 18229: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18230: if ($putresult eq 'ok') {
1.160.6.77 raeburn 18231: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18232: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18233: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18234: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18235: }
18236: }
18237: my $cachetime = 24*60*60;
18238: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18239: if (ref($lastactref) eq 'HASH') {
18240: $lastactref->{'domdefaults'} = 1;
18241: }
18242: } else {
18243: $errors .= '<li><span class="LC_error">'.
18244: &mt('An error occurred storing the settings: [_1]',
18245: $putresult).'</span></li>';
18246: }
18247: }
18248: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18249: $resulttext = &mt('Changes made:').'<ul>';
18250: my (%shownprivs,@levelorder);
18251: @levelorder = ('c','d','s');
18252: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 18253: foreach my $item (sort(keys(%changes))) {
18254: if ($item eq 'submitbugs') {
18255: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18256: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18257: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 18258: } elsif ($item eq 'customrole') {
18259: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 18260: my @keyorder = ('order','desc','access','status','exc','inc');
18261: my %keytext = &Apache::lonlocal::texthash(
18262: order => 'Order',
18263: desc => 'Role description',
18264: access => 'Role usage',
1.160.6.83 raeburn 18265: status => 'Allowed institutional types',
1.160.6.77 raeburn 18266: exc => 'Allowed personnel',
18267: inc => 'Disallowed personnel',
18268: );
1.160.6.73 raeburn 18269: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 18270: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18271: if ($role eq $newrole) {
18272: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18273: $role).'<ul>';
18274: } else {
18275: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18276: $role).'<ul>';
18277: }
18278: foreach my $key (@keyorder) {
18279: if ($changes{'customrole'}{$role}{$key}) {
18280: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18281: $keytext{$key},$newsettings{$role}{$key}).
18282: '</li>';
18283: }
18284: }
18285: if (ref($changedprivs{$role}) eq 'HASH') {
18286: $shownprivs{$role} = 1;
18287: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18288: foreach my $level (@levelorder) {
18289: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18290: next if ($item eq '');
18291: my ($priv) = split(/\&/,$item,2);
18292: if (&Apache::lonnet::plaintext($priv)) {
18293: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18294: unless ($level eq 'c') {
18295: $resulttext .= ' ('.$lt{$level}.')';
18296: }
18297: $resulttext .= '</li>';
18298: }
18299: }
18300: }
18301: $resulttext .= '</ul>';
18302: }
18303: $resulttext .= '</ul></li>';
18304: }
1.160.6.73 raeburn 18305: }
18306: }
1.160.6.5 raeburn 18307: }
18308: }
18309: }
1.160.6.77 raeburn 18310: if (keys(%changedprivs)) {
18311: foreach my $role (sort(keys(%changedprivs))) {
18312: unless ($shownprivs{$role}) {
18313: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18314: $role).'<ul>'.
18315: '<li>'.&mt('Privileges set to :').'<ul>';
18316: foreach my $level (@levelorder) {
18317: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18318: next if ($item eq '');
18319: my ($priv) = split(/\&/,$item,2);
18320: if (&Apache::lonnet::plaintext($priv)) {
18321: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18322: unless ($level eq 'c') {
18323: $resulttext .= ' ('.$lt{$level}.')';
18324: }
18325: $resulttext .= '</li>';
18326: }
18327: }
18328: }
18329: $resulttext .= '</ul></li></ul></li>';
18330: }
18331: }
18332: }
18333: $resulttext .= '</ul>';
18334: } else {
18335: $resulttext = &mt('No changes made to help settings');
1.118 jms 18336: }
18337: if ($errors) {
1.160.6.5 raeburn 18338: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 18339: $errors.'</ul>';
1.118 jms 18340: }
18341: return $resulttext;
18342: }
18343:
1.121 raeburn 18344: sub modify_coursedefaults {
1.160.6.27 raeburn 18345: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 18346: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 18347: my %defaultchecked = (
18348: 'uselcmath' => 'on',
1.160.6.115 raeburn 18349: 'usejsme' => 'on',
18350: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 18351:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 18352: );
1.160.6.118.2 4(raebur 18353:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 18354: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.118.2 15(raebu 18355:23): 'uploadquota_community','uploadquota_textbook','coursequota_official',
18356:23): 'coursequota_unofficial','coursequota_community','coursequota_textbook',
18357:23): 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
18358:23): 'mysqltables_textbook');
1.160.6.30 raeburn 18359: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 18360: my %staticdefaults = (
18361: anonsurvey_threshold => 10,
18362: uploadquota => 500,
1.160.6.118.2 15(raebu 18363:23): coursequota => 20,
1.160.6.57 raeburn 18364: postsubmit => 60,
1.160.6.70 raeburn 18365: mysqltables => 172800,
1.160.6.118.2 14(raebu 18366:23): domexttool => 1,
1.160.6.21 raeburn 18367: );
1.160.6.90 raeburn 18368: my %texoptions = (
18369: MathJax => 'MathJax',
18370: mimetex => &mt('Convert to Images'),
18371: tth => &mt('TeX to HTML'),
18372: );
1.121 raeburn 18373: $defaultshash{'coursedefaults'} = {};
18374:
18375: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
18376: if ($domconfig{'coursedefaults'} eq '') {
18377: $domconfig{'coursedefaults'} = {};
18378: }
18379: }
18380:
18381: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
18382: foreach my $item (@toggles) {
18383: if ($defaultchecked{$item} eq 'on') {
18384: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18385: ($env{'form.'.$item} eq '0')) {
18386: $changes{$item} = 1;
1.160.6.16 raeburn 18387: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 18388: $changes{$item} = 1;
18389: }
18390: } elsif ($defaultchecked{$item} eq 'off') {
18391: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18392: ($env{'form.'.$item} eq '1')) {
18393: $changes{$item} = 1;
18394: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18395: $changes{$item} = 1;
18396: }
18397: }
18398: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
18399: }
1.160.6.21 raeburn 18400: foreach my $item (@numbers) {
18401: my ($currdef,$newdef);
1.160.6.26 raeburn 18402: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 18403: if ($item eq 'anonsurvey_threshold') {
18404: $currdef = $domconfig{'coursedefaults'}{$item};
18405: $newdef =~ s/\D//g;
18406: if ($newdef eq '' || $newdef < 1) {
18407: $newdef = 1;
18408: }
18409: $defaultshash{'coursedefaults'}{$item} = $newdef;
18410: } else {
1.160.6.118.2 15(raebu 18411:23): my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.160.6.70 raeburn 18412: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
18413: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 18414: }
18415: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 18416: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 18417: }
18418: if ($currdef ne $newdef) {
18419: if ($item eq 'anonsurvey_threshold') {
18420: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
18421: $changes{$item} = 1;
18422: }
1.160.6.118.2 15(raebu 18423:23): } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.160.6.70 raeburn 18424: my $setting = $1;
18425: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
18426: $changes{$setting} = 1;
1.160.6.21 raeburn 18427: }
18428: }
1.139 raeburn 18429: }
18430: }
1.160.6.90 raeburn 18431: my $texengine;
18432: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
18433: $texengine = $env{'form.texengine'};
18434: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
18435: if ($currdef eq '') {
18436: unless ($texengine eq $Apache::lonnet::deftex) {
18437: $changes{'texengine'} = 1;
18438: }
18439: } elsif ($currdef ne $texengine) {
18440: $changes{'texengine'} = 1;
18441: }
18442: }
18443: if ($texengine ne '') {
18444: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
18445: }
1.160.6.64 raeburn 18446: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
18447: my @currclonecode;
18448: if (ref($currclone) eq 'HASH') {
18449: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
18450: @currclonecode = @{$currclone->{'instcode'}};
18451: }
18452: }
18453: my $newclone;
18454: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
18455: $newclone = $env{'form.canclone'};
18456: }
18457: if ($newclone eq 'instcode') {
18458: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
18459: my (%codedefaults,@code_order,@clonecode);
18460: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
18461: \@code_order);
18462: foreach my $item (@code_order) {
18463: if (grep(/^\Q$item\E$/,@newcodes)) {
18464: push(@clonecode,$item);
18465: }
18466: }
18467: if (@clonecode) {
18468: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
18469: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
18470: if (@diffs) {
18471: $changes{'canclone'} = 1;
18472: }
18473: } else {
18474: $newclone eq '';
18475: }
18476: } elsif ($newclone ne '') {
18477: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
18478: }
18479: if ($newclone ne $currclone) {
18480: $changes{'canclone'} = 1;
18481: }
1.160.6.57 raeburn 18482: my %credits;
18483: foreach my $type (@types) {
18484: unless ($type eq 'community') {
18485: $credits{$type} = $env{'form.'.$type.'_credits'};
18486: $credits{$type} =~ s/[^\d.]+//g;
18487: }
18488: }
18489: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
18490: ($env{'form.coursecredits'} eq '1')) {
18491: $changes{'coursecredits'} = 1;
18492: foreach my $type (keys(%credits)) {
18493: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
18494: }
18495: } else {
18496: if ($env{'form.coursecredits'} eq '1') {
18497: foreach my $type (@types) {
18498: unless ($type eq 'community') {
18499: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
18500: $changes{'coursecredits'} = 1;
18501: }
18502: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
18503: }
18504: }
18505: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18506: foreach my $type (@types) {
18507: unless ($type eq 'community') {
18508: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
18509: $changes{'coursecredits'} = 1;
18510: last;
18511: }
18512: }
18513: }
18514: }
18515: }
18516: if ($env{'form.postsubmit'} eq '1') {
18517: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
18518: my %currtimeout;
18519: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18520: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
18521: $changes{'postsubmit'} = 1;
18522: }
18523: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18524: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
18525: }
18526: } else {
18527: $changes{'postsubmit'} = 1;
18528: }
18529: foreach my $type (@types) {
18530: my $timeout = $env{'form.'.$type.'_timeout'};
18531: $timeout =~ s/\D//g;
18532: if ($timeout == $staticdefaults{'postsubmit'}) {
18533: $timeout = '';
18534: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
18535: $timeout = '0';
18536: }
18537: unless ($timeout eq '') {
18538: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
18539: }
18540: if (exists($currtimeout{$type})) {
18541: if ($timeout ne $currtimeout{$type}) {
18542: $changes{'postsubmit'} = 1;
18543: }
18544: } elsif ($timeout ne '') {
18545: $changes{'postsubmit'} = 1;
18546: }
18547: }
18548: } else {
18549: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
18550: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18551: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
18552: $changes{'postsubmit'} = 1;
18553: }
18554: } else {
18555: $changes{'postsubmit'} = 1;
18556: }
1.160.6.16 raeburn 18557: }
1.160.6.118.2 14(raebu 18558:23): my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
18559:23): map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
18560:23): map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
18561:23): if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18562:23): %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
18563:23): } else {
18564:23): foreach my $type (@types) {
18565:23): if ($staticdefaults{'domexttool'}) {
18566:23): $olddomexttool{$type} = 1;
18567:23): } else {
18568:23): $olddomexttool{$type} = 0;
18569:23): }
18570:23): }
18571:23): }
18572:23): if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
18573:23): %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
18574:23): } else {
18575:23): foreach my $type (@types) {
18576:23): if ($staticdefaults{'exttool'}) {
18577:23): $oldexttool{$type} = 1;
18578:23): } else {
18579:23): $oldexttool{$type} = 0;
18580:23): }
18581:23): }
18582:23): }
18583:23): foreach my $type (@types) {
18584:23): unless ($newdomexttool{$type}) {
18585:23): $newdomexttool{$type} = 0;
18586:23): }
18587:23): unless ($newexttool{$type}) {
18588:23): $newexttool{$type} = 0;
18589:23): }
18590:23): if ($newdomexttool{$type} != $olddomexttool{$type}) {
18591:23): $changes{'domexttool'} = 1;
18592:23): }
18593:23): if ($newexttool{$type} != $oldexttool{$type}) {
18594:23): $changes{'exttool'} = 1;
18595:23): }
18596:23): }
18597:23): $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
18598:23): $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.121 raeburn 18599: }
18600: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18601: $dom);
18602: if ($putresult eq 'ok') {
18603: if (keys(%changes) > 0) {
1.160.6.27 raeburn 18604: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 18605: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 18606: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 18607: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 14(raebu 18608:23): ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
15(raebu 18609:23): ($changes{'exttool'}) || ($changes{'coursequota'})) {
4(raebur 18610:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 18611: if ($changes{$item}) {
18612: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
18613: }
1.160.6.16 raeburn 18614: }
18615: if ($changes{'coursecredits'}) {
18616: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 18617: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
18618: $domdefaults{$type.'credits'} =
18619: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
18620: }
18621: }
18622: }
18623: if ($changes{'postsubmit'}) {
18624: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18625: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
18626: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18627: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
18628: $domdefaults{$type.'postsubtimeout'} =
18629: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
18630: }
18631: }
1.160.6.16 raeburn 18632: }
18633: }
1.160.6.21 raeburn 18634: if ($changes{'uploadquota'}) {
18635: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
18636: foreach my $type (@types) {
18637: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
18638: }
18639: }
18640: }
1.160.6.118.2 15(raebu 18641:23): if ($changes{'coursequota'}) {
18642:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
18643:23): foreach my $type (@types) {
18644:23): $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
18645:23): }
18646:23): }
18647:23): }
1.160.6.64 raeburn 18648: if ($changes{'canclone'}) {
18649: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
18650: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
18651: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
18652: if (@clonecodes) {
18653: $domdefaults{'canclone'} = join('+',@clonecodes);
18654: }
18655: }
18656: } else {
18657: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
18658: }
18659: }
1.160.6.118.2 14(raebu 18660:23): if ($changes{'domexttool'}) {
18661:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18662:23): foreach my $type (@types) {
18663:23): $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
18664:23): }
18665:23): }
18666:23): }
18667:23): if ($changes{'exttool'}) {
18668:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
18669:23): foreach my $type (@types) {
18670:23): $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
18671:23): }
18672:23): }
18673:23): }
1.121 raeburn 18674: my $cachetime = 24*60*60;
18675: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 18676: if (ref($lastactref) eq 'HASH') {
18677: $lastactref->{'domdefaults'} = 1;
18678: }
1.121 raeburn 18679: }
18680: $resulttext = &mt('Changes made:').'<ul>';
18681: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 18682: if ($item eq 'uselcmath') {
1.121 raeburn 18683: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 18684: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 18685: } else {
1.160.6.57 raeburn 18686: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
18687: }
18688: } elsif ($item eq 'usejsme') {
18689: if ($env{'form.'.$item} eq '1') {
18690: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
18691: } else {
18692: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 18693: }
1.160.6.115 raeburn 18694: } elsif ($item eq 'inline_chem') {
18695: if ($env{'form.'.$item} eq '1') {
18696: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
18697: } else {
18698: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
18699: }
1.160.6.90 raeburn 18700: } elsif ($item eq 'texengine') {
18701: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
18702: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
18703: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
18704: }
1.139 raeburn 18705: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 18706: $resulttext .= '<li>'.&mt('Responder count required for display of anonymous survey submissions set to [_1].',$defaultshash{'coursedefaults'}{'anonsurvey_threshold'}).'</li>';
1.160.6.21 raeburn 18707: } elsif ($item eq 'uploadquota') {
18708: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
18709: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
18710: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
18711: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 18712: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.160.6.21 raeburn 18713: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
18714: '</ul>'.
18715: '</li>';
18716: } else {
18717: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
18718: }
1.160.6.118.2 15(raebu 18719:23): } elsif ($item eq 'coursequota') {
18720:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
18721:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
18722:23): '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
18723:23): '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
18724:23): '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
18725:23): '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
18726:23): '</ul>'.
18727:23): '</li>';
18728:23): } else {
18729:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
18730:23): }
1.160.6.70 raeburn 18731: } elsif ($item eq 'mysqltables') {
18732: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
18733: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
18734: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
18735: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
18736: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
18737: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
18738: '</ul>'.
18739: '</li>';
18740: } else {
18741: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
18742: }
1.160.6.57 raeburn 18743: } elsif ($item eq 'postsubmit') {
18744: if ($domdefaults{'postsubmit'} eq 'off') {
18745: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
18746: } else {
18747: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
18748: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18749: $resulttext .= &mt('durations:').'<ul>';
18750: foreach my $type (@types) {
18751: $resulttext .= '<li>';
18752: my $timeout;
18753: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18754: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
18755: }
18756: my $display;
18757: if ($timeout eq '0') {
18758: $display = &mt('unlimited');
18759: } elsif ($timeout eq '') {
18760: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
18761: } else {
18762: $display = &mt('[quant,_1,second]',$timeout);
18763: }
18764: if ($type eq 'community') {
18765: $resulttext .= &mt('Communities');
18766: } elsif ($type eq 'official') {
18767: $resulttext .= &mt('Official courses');
18768: } elsif ($type eq 'unofficial') {
18769: $resulttext .= &mt('Unofficial courses');
18770: } elsif ($type eq 'textbook') {
18771: $resulttext .= &mt('Textbook courses');
18772: }
18773: $resulttext .= ' -- '.$display.'</li>';
18774: }
18775: $resulttext .= '</ul>';
18776: }
18777: $resulttext .= '</li>';
18778: }
1.160.6.16 raeburn 18779: } elsif ($item eq 'coursecredits') {
18780: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18781: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 18782: ($domdefaults{'unofficialcredits'} eq '') &&
18783: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 18784: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
18785: } else {
18786: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
18787: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
18788: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 18789: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 18790: '</ul>'.
18791: '</li>';
18792: }
18793: } else {
18794: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
18795: }
1.160.6.64 raeburn 18796: } elsif ($item eq 'canclone') {
18797: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
18798: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
18799: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
18800: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
18801: }
18802: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
18803: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
18804: } else {
18805: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
18806: }
1.160.6.118.2 4(raebur 18807:2): } elsif ($item eq 'ltiauth') {
18808:2): if ($env{'form.'.$item} eq '1') {
18809:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
18810:2): } else {
18811:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
18812:2): }
14(raebu 18813:23): } elsif ($item eq 'domexttool') {
18814:23): my @noyes = (&mt('no'),&mt('yes'));
18815:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18816:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
18817:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
18818:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
18819:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
18820:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
18821:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
18822:23): '</ul>'.
18823:23): '</li>';
18824:23): } else {
18825:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
18826:23): }
18827:23): } elsif ($item eq 'exttool') {
18828:23): my @noyes = (&mt('no'),&mt('yes'));
18829:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
18830:23): $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
18831:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
18832:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
18833:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
18834:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
18835:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
18836:23): '</ul>'.
18837:23): '</li>';
18838:23): } else {
18839:23): $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
18840:23): }
1.140 raeburn 18841: }
1.121 raeburn 18842: }
18843: $resulttext .= '</ul>';
18844: } else {
18845: $resulttext = &mt('No changes made to course defaults');
18846: }
18847: } else {
18848: $resulttext = '<span class="LC_error">'.
18849: &mt('An error occurred: [_1]',$putresult).'</span>';
18850: }
18851: return $resulttext;
18852: }
18853:
1.160.6.37 raeburn 18854: sub modify_selfenrollment {
18855: my ($dom,$lastactref,%domconfig) = @_;
18856: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
18857: my @types = ('official','unofficial','community','textbook');
18858: my %titles = &tool_titles();
18859: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
18860: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
18861: $ordered{'default'} = ['types','registered','approval','limit'];
18862:
18863: my (%roles,%shown,%toplevel);
18864: $roles{'0'} = &Apache::lonnet::plaintext('dc');
18865:
18866: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
18867: if ($domconfig{'selfenrollment'} eq '') {
18868: $domconfig{'selfenrollment'} = {};
18869: }
18870: }
18871: %toplevel = (
18872: admin => 'Configuration Rights',
18873: default => 'Default settings',
18874: validation => 'Validation of self-enrollment requests',
18875: );
18876: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
18877:
18878: if (ref($ordered{'admin'}) eq 'ARRAY') {
18879: foreach my $item (@{$ordered{'admin'}}) {
18880: foreach my $type (@types) {
18881: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
18882: $selfenrollhash{'admin'}{$type}{$item} = 1;
18883: } else {
18884: $selfenrollhash{'admin'}{$type}{$item} = 0;
18885: }
18886: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
18887: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
18888: if ($selfenrollhash{'admin'}{$type}{$item} ne
18889: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
18890: push(@{$changes{'admin'}{$type}},$item);
18891: }
18892: } else {
18893: if (!$selfenrollhash{'admin'}{$type}{$item}) {
18894: push(@{$changes{'admin'}{$type}},$item);
18895: }
18896: }
18897: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
18898: push(@{$changes{'admin'}{$type}},$item);
18899: }
18900: }
18901: }
18902: }
18903:
18904: foreach my $item (@{$ordered{'default'}}) {
18905: foreach my $type (@types) {
18906: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
18907: if ($item eq 'types') {
18908: unless (($value eq 'all') || ($value eq 'dom')) {
18909: $value = '';
18910: }
18911: } elsif ($item eq 'registered') {
18912: unless ($value eq '1') {
18913: $value = 0;
18914: }
18915: } elsif ($item eq 'approval') {
18916: unless ($value =~ /^[012]$/) {
18917: $value = 0;
18918: }
18919: } else {
18920: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18921: $value = 'none';
18922: }
18923: }
18924: $selfenrollhash{'default'}{$type}{$item} = $value;
18925: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
18926: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18927: if ($selfenrollhash{'default'}{$type}{$item} ne
18928: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
18929: push(@{$changes{'default'}{$type}},$item);
18930: }
18931: } else {
18932: push(@{$changes{'default'}{$type}},$item);
18933: }
18934: } else {
18935: push(@{$changes{'default'}{$type}},$item);
18936: }
18937: if ($item eq 'limit') {
18938: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
18939: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
18940: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
18941: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
18942: }
18943: } else {
18944: $selfenrollhash{'default'}{$type}{'cap'} = '';
18945: }
18946: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
18947: if ($selfenrollhash{'default'}{$type}{'cap'} ne
18948: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
18949: push(@{$changes{'default'}{$type}},'cap');
18950: }
18951: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
18952: push(@{$changes{'default'}{$type}},'cap');
18953: }
18954: }
18955: }
18956: }
18957:
18958: foreach my $item (@{$itemsref}) {
18959: if ($item eq 'fields') {
18960: my @changed;
18961: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
18962: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
18963: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
18964: }
18965: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18966: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
18967: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
18968: $domconfig{'selfenrollment'}{'validation'}{$item});
18969: } else {
18970: @changed = @{$selfenrollhash{'validation'}{$item}};
18971: }
18972: } else {
18973: @changed = @{$selfenrollhash{'validation'}{$item}};
18974: }
18975: if (@changed) {
18976: if ($selfenrollhash{'validation'}{$item}) {
18977: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
18978: } else {
18979: $changes{'validation'}{$item} = &mt('None');
18980: }
18981: }
18982: } else {
18983: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
18984: if ($item eq 'markup') {
18985: if ($env{'form.selfenroll_validation_'.$item}) {
18986: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
18987: }
18988: }
18989: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
18990: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
18991: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
18992: }
18993: }
18994: }
18995: }
18996:
18997: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
18998: $dom);
18999: if ($putresult eq 'ok') {
19000: if (keys(%changes) > 0) {
19001: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19002: $resulttext = &mt('Changes made:').'<ul>';
19003: foreach my $key ('admin','default','validation') {
19004: if (ref($changes{$key}) eq 'HASH') {
19005: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19006: if ($key eq 'validation') {
19007: foreach my $item (@{$itemsref}) {
19008: if (exists($changes{$key}{$item})) {
19009: if ($item eq 'markup') {
19010: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19011: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19012: } else {
19013: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19014: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19015: }
19016: }
19017: }
19018: } else {
19019: foreach my $type (@types) {
19020: if ($type eq 'community') {
19021: $roles{'1'} = &mt('Community personnel');
19022: } else {
19023: $roles{'1'} = &mt('Course personnel');
19024: }
19025: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19026: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19027: if ($key eq 'admin') {
19028: my @mgrdc = ();
19029: if (ref($ordered{$key}) eq 'ARRAY') {
19030: foreach my $item (@{$ordered{'admin'}}) {
19031: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19032: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19033: push(@mgrdc,$item);
19034: }
19035: }
19036: }
19037: if (@mgrdc) {
19038: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19039: } else {
19040: delete($domdefaults{$type.'selfenrolladmdc'});
19041: }
19042: }
19043: } else {
19044: if (ref($ordered{$key}) eq 'ARRAY') {
19045: foreach my $item (@{$ordered{$key}}) {
19046: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19047: $domdefaults{$type.'selfenroll'.$item} =
19048: $selfenrollhash{$key}{$type}{$item};
19049: }
19050: }
19051: }
19052: }
19053: }
19054: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19055: foreach my $item (@{$ordered{$key}}) {
19056: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19057: $resulttext .= '<li>';
19058: if ($key eq 'admin') {
19059: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19060: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19061: } else {
19062: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19063: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19064: }
19065: $resulttext .= '</li>';
19066: }
19067: }
19068: $resulttext .= '</ul></li>';
19069: }
19070: }
19071: $resulttext .= '</ul></li>';
19072: }
19073: }
1.160.6.93 raeburn 19074: }
19075: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19076: my $cachetime = 24*60*60;
19077: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19078: if (ref($lastactref) eq 'HASH') {
19079: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 19080: }
19081: }
19082: $resulttext .= '</ul>';
19083: } else {
19084: $resulttext = &mt('No changes made to self-enrollment settings');
19085: }
19086: } else {
19087: $resulttext = '<span class="LC_error">'.
19088: &mt('An error occurred: [_1]',$putresult).'</span>';
19089: }
19090: return $resulttext;
19091: }
19092:
1.160.6.113 raeburn 19093: sub modify_wafproxy {
19094: my ($dom,$action,$lastactref,%domconfig) = @_;
19095: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19096: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19097: %wafproxy,%changes,%expirecache,%expiresaml);
19098: foreach my $server (sort(keys(%servers))) {
19099: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19100: if ($serverhome eq $server) {
19101: my $serverdom = &Apache::lonnet::host_domain($server);
19102: if ($serverdom eq $dom) {
19103: $canset{$server} = 1;
19104: }
19105: }
19106: }
19107: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19108: %{$values{$dom}} = ();
19109: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19110: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19111: }
19112: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19113: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19114: }
19115: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19116: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19117: }
19118: }
19119: my $output;
19120: if (keys(%canset)) {
19121: %{$wafproxy{'alias'}} = ();
19122: %{$wafproxy{'saml'}} = ();
19123: foreach my $key (sort(keys(%canset))) {
19124: if ($env{'form.wafproxy_'.$dom}) {
19125: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19126: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19127: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19128: $changes{'alias'} = 1;
19129: }
19130: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19131: $wafproxy{'saml'}{$key} = 1;
19132: }
19133: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19134: $changes{'saml'} = 1;
19135: }
19136: } else {
19137: $wafproxy{'alias'}{$key} = '';
19138: $wafproxy{'saml'}{$key} = '';
19139: if ($curralias{$key}) {
19140: $changes{'alias'} = 1;
19141: }
19142: if ($currsaml{$key}) {
19143: $changes{'saml'} = 1;
19144: }
19145: }
19146: if ($wafproxy{'alias'}{$key} eq '') {
19147: if ($curralias{$key}) {
19148: $expirecache{$key} = 1;
19149: }
19150: delete($wafproxy{'alias'}{$key});
19151: }
19152: if ($wafproxy{'saml'}{$key} eq '') {
19153: if ($currsaml{$key}) {
19154: $expiresaml{$key} = 1;
19155: }
19156: delete($wafproxy{'saml'}{$key});
19157: }
19158: }
19159: unless (keys(%{$wafproxy{'alias'}})) {
19160: delete($wafproxy{'alias'});
19161: }
19162: unless (keys(%{$wafproxy{'saml'}})) {
19163: delete($wafproxy{'saml'});
19164: }
19165: # Localization for values in %warn occurs in &mt() calls separately.
19166: my %warn = (
19167: trusted => 'trusted IP range(s)',
19168: vpnint => 'internal IP range(s) for VPN sessions(s)',
19169: vpnext => 'IP range(s) for backend WAF connections',
19170: );
19171: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19172: my $possible = $env{'form.wafproxy_'.$item};
19173: $possible =~ s/^\s+|\s+$//g;
19174: if ($possible ne '') {
19175: if ($item eq 'remoteip') {
19176: if ($possible =~ /^[mhn]$/) {
19177: $wafproxy{$item} = $possible;
19178: }
19179: } elsif ($item eq 'ipheader') {
19180: if ($wafproxy{'remoteip'} eq 'h') {
19181: $wafproxy{$item} = $possible;
19182: }
19183: } elsif ($item eq 'sslopt') {
19184: if ($possible =~ /^0|1$/) {
19185: $wafproxy{$item} = $possible;
19186: }
19187: } else {
19188: my (@ok,$count);
19189: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19190: unless ($env{'form.wafproxy_vpnaccess'}) {
19191: $possible = '';
19192: }
19193: } elsif ($item eq 'trusted') {
19194: unless ($wafproxy{'remoteip'} eq 'h') {
19195: $possible = '';
19196: }
19197: }
19198: unless ($possible eq '') {
19199: $possible =~ s/[\r\n]+/\s/g;
19200: $possible =~ s/\s*-\s*/-/g;
19201: $possible =~ s/\s+/,/g;
19202: $possible =~ s/,+/,/g;
19203: }
19204: $count = 0;
19205: if ($possible ne '') {
19206: foreach my $poss (split(/\,/,$possible)) {
19207: $count ++;
19208: $poss = &validate_ip_pattern($poss);
19209: if ($poss ne '') {
19210: push(@ok,$poss);
19211: }
19212: }
19213: my $diff = $count - scalar(@ok);
19214: if ($diff) {
19215: push(@warnings,'<li>'.
19216: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19217: $diff,$warn{$item}).
19218: '</li>');
19219: }
19220: if (@ok) {
19221: my @cidr_list;
19222: foreach my $item (@ok) {
19223: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19224: }
19225: $wafproxy{$item} = join(',',@cidr_list);
19226: }
19227: }
19228: }
19229: if ($wafproxy{$item} ne $currvalue{$item}) {
19230: $changes{$item} = 1;
19231: }
19232: } elsif ($currvalue{$item}) {
19233: $changes{$item} = 1;
19234: }
19235: }
19236: } else {
19237: if (keys(%curralias)) {
19238: $changes{'alias'} = 1;
19239: }
19240: if (keys(%currsaml)) {
19241: $changes{'saml'} = 1;
19242: }
19243: if (keys(%currvalue)) {
19244: foreach my $key (keys(%currvalue)) {
19245: $changes{$key} = 1;
19246: }
19247: }
19248: }
19249: if (keys(%changes)) {
19250: my %defaultshash = (
19251: wafproxy => \%wafproxy,
19252: );
19253: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19254: $dom);
19255: if ($putresult eq 'ok') {
19256: my $cachetime = 24*60*60;
19257: my (%domdefaults,$updatedomdefs);
19258: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
19259: if ($changes{$item}) {
19260: unless ($updatedomdefs) {
19261: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19262: $updatedomdefs = 1;
19263: }
19264: if ($wafproxy{$item}) {
19265: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19266: } elsif (exists($domdefaults{'waf_'.$item})) {
19267: delete($domdefaults{'waf_'.$item});
19268: }
19269: }
19270: }
19271: if ($updatedomdefs) {
19272: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19273: if (ref($lastactref) eq 'HASH') {
19274: $lastactref->{'domdefaults'} = 1;
19275: }
19276: }
19277: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
19278: my %updates = %expirecache;
19279: foreach my $key (keys(%expirecache)) {
19280: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
19281: }
19282: if (ref($wafproxy{'alias'}) eq 'HASH') {
19283: my $cachetime = 24*60*60;
19284: foreach my $key (keys(%{$wafproxy{'alias'}})) {
19285: $updates{$key} = 1;
19286: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
19287: $cachetime);
19288: }
19289: }
19290: if (ref($lastactref) eq 'HASH') {
19291: $lastactref->{'proxyalias'} = \%updates;
19292: }
19293: }
19294: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
19295: my %samlupdates = %expiresaml;
19296: foreach my $key (keys(%expiresaml)) {
19297: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
19298: }
19299: if (ref($wafproxy{'saml'}) eq 'HASH') {
19300: my $cachetime = 24*60*60;
19301: foreach my $key (keys(%{$wafproxy{'saml'}})) {
19302: $samlupdates{$key} = 1;
19303: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
19304: $cachetime);
19305: }
19306: }
19307: if (ref($lastactref) eq 'HASH') {
19308: $lastactref->{'proxysaml'} = \%samlupdates;
19309: }
19310: }
19311: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 19312: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 19313: if ($changes{$item}) {
19314: if ($item eq 'alias') {
19315: my $numaliased = 0;
19316: if (ref($wafproxy{'alias'}) eq 'HASH') {
19317: my $shown;
19318: if (keys(%{$wafproxy{'alias'}})) {
19319: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
19320: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
19321: &Apache::lonnet::hostname($server),
19322: $wafproxy{'alias'}{$server}).'</li>';
19323: $numaliased ++;
19324: }
19325: if ($numaliased) {
19326: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
19327: '<ul>'.$shown.'</ul>').'</li>';
19328: }
19329: }
19330: }
19331: unless ($numaliased) {
19332: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
19333: }
19334: } elsif ($item eq 'saml') {
19335: my $shown;
19336: if (ref($wafproxy{'saml'}) eq 'HASH') {
19337: if (keys(%{$wafproxy{'saml'}})) {
19338: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
19339: }
19340: }
19341: if ($shown) {
19342: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
19343: $shown).'</li>';
19344: } else {
19345: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
19346: }
19347: } else {
19348: if ($item eq 'remoteip') {
19349: my %ip_methods = &remoteip_methods();
19350: if ($wafproxy{$item} =~ /^[mh]$/) {
19351: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
19352: $ip_methods{$wafproxy{$item}}).'</li>';
19353: } else {
19354: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
19355: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
19356: '</li>';
19357: } else {
19358: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
19359: }
19360: }
19361: } elsif ($item eq 'ipheader') {
19362: if ($wafproxy{$item}) {
19363: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
19364: $wafproxy{$item}).'</li>';
19365: } else {
19366: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
19367: }
19368: } elsif ($item eq 'trusted') {
19369: if ($wafproxy{$item}) {
19370: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
19371: $wafproxy{$item}).'</li>';
19372: } else {
19373: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
19374: }
19375: } elsif ($item eq 'vpnint') {
19376: if ($wafproxy{$item}) {
19377: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
19378: $wafproxy{$item}).'</li>';
19379: } else {
19380: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
19381: }
19382: } elsif ($item eq 'vpnext') {
19383: if ($wafproxy{$item}) {
19384: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
19385: $wafproxy{$item}).'</li>';
19386: } else {
19387: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
19388: }
19389: } elsif ($item eq 'sslopt') {
19390: if ($wafproxy{$item}) {
19391: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to forward requests to https on LON-CAPA node, regardless of original protocol in web browser (http or https).').'</li>';
19392: } else {
19393: $output .= '<li>'.&mt('WAF/Reverse Proxy expected to preserve original protocol in web browser (either http or https) when forwarding to LON-CAPA node.').'</li>';
19394: }
19395: }
19396: }
19397: }
19398: }
1.160.6.118.2 14(raebu 19399:23): $output .= '</ul>';
1.160.6.113 raeburn 19400: } else {
19401: $output = '<span class="LC_error">'.
19402: &mt('An error occurred: [_1]',$putresult).'</span>';
19403: }
19404: } elsif (keys(%canset)) {
19405: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
19406: }
19407: if (@warnings) {
19408: $output .= '<br />'.&mt('Warnings:').'<ul>'.
19409: join("\n",@warnings).'</ul>';
19410: }
19411: return $output;
19412: }
19413:
19414: sub validate_ip_pattern {
19415: my ($pattern) = @_;
19416: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
19417: my ($start,$end) = ($1,$2);
19418: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
19419: if (($start !~ m{/}) && ($end !~ m{/})) {
19420: return $start.'-'.$end;
19421: }
19422: }
19423: } elsif ($pattern ne '') {
19424: $pattern = &Net::CIDR::cidrvalidate($pattern);
19425: if ($pattern ne '') {
19426: return $pattern;
19427: }
19428: }
19429: return;
19430: }
19431:
1.137 raeburn 19432: sub modify_usersessions {
1.160.6.27 raeburn 19433: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 19434: my @hostingtypes = ('version','excludedomain','includedomain');
19435: my @offloadtypes = ('primary','default');
19436: my %types = (
19437: remote => \@hostingtypes,
19438: hosted => \@hostingtypes,
19439: spares => \@offloadtypes,
19440: );
19441: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 19442: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 19443: my (%by_ip,%by_location,@intdoms);
19444: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
19445: my @locations = sort(keys(%by_location));
1.137 raeburn 19446: my (%defaultshash,%changes);
19447: foreach my $prefix (@prefixes) {
19448: $defaultshash{'usersessions'}{$prefix} = {};
19449: }
1.160.6.27 raeburn 19450: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 19451: my $resulttext;
1.138 raeburn 19452: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 19453: foreach my $prefix (@prefixes) {
1.145 raeburn 19454: next if ($prefix eq 'spares');
19455: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 19456: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
19457: if ($type eq 'version') {
19458: my $value = $env{'form.'.$prefix.'_'.$type};
19459: my $okvalue;
19460: if ($value ne '') {
19461: if (grep(/^\Q$value\E$/,@lcversions)) {
19462: $okvalue = $value;
19463: }
19464: }
19465: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19466: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19467: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
19468: if ($inuse == 0) {
19469: $changes{$prefix}{$type} = 1;
19470: } else {
19471: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
19472: $changes{$prefix}{$type} = 1;
19473: }
19474: if ($okvalue ne '') {
19475: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19476: }
19477: }
19478: } else {
19479: if (($inuse == 1) && ($okvalue ne '')) {
19480: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19481: $changes{$prefix}{$type} = 1;
19482: }
19483: }
19484: } else {
19485: if (($inuse == 1) && ($okvalue ne '')) {
19486: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19487: $changes{$prefix}{$type} = 1;
19488: }
19489: }
19490: } else {
19491: if (($inuse == 1) && ($okvalue ne '')) {
19492: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19493: $changes{$prefix}{$type} = 1;
19494: }
19495: }
19496: } else {
19497: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
19498: my @okvals;
19499: foreach my $val (@vals) {
1.138 raeburn 19500: if ($val =~ /:/) {
19501: my @items = split(/:/,$val);
19502: foreach my $item (@items) {
19503: if (ref($by_location{$item}) eq 'ARRAY') {
19504: push(@okvals,$item);
19505: }
19506: }
19507: } else {
19508: if (ref($by_location{$val}) eq 'ARRAY') {
19509: push(@okvals,$val);
19510: }
1.137 raeburn 19511: }
19512: }
19513: @okvals = sort(@okvals);
19514: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19515: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19516: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19517: if ($inuse == 0) {
19518: $changes{$prefix}{$type} = 1;
19519: } else {
19520: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19521: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
19522: if (@changed > 0) {
19523: $changes{$prefix}{$type} = 1;
19524: }
19525: }
19526: } else {
19527: if ($inuse == 1) {
19528: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19529: $changes{$prefix}{$type} = 1;
19530: }
19531: }
19532: } else {
19533: if ($inuse == 1) {
19534: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19535: $changes{$prefix}{$type} = 1;
19536: }
19537: }
19538: } else {
19539: if ($inuse == 1) {
19540: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19541: $changes{$prefix}{$type} = 1;
19542: }
19543: }
19544: }
19545: }
19546: }
1.145 raeburn 19547:
19548: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 19549: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 19550: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
19551: my $savespares;
19552:
19553: foreach my $lonhost (sort(keys(%servers))) {
19554: my $serverhomeID =
19555: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 19556: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 19557: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
19558: my %spareschg;
19559: foreach my $type (@{$types{'spares'}}) {
19560: my @okspares;
19561: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
19562: foreach my $server (@checked) {
1.152 raeburn 19563: if (&Apache::lonnet::hostname($server) ne '') {
19564: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
19565: unless (grep(/^\Q$server\E$/,@okspares)) {
19566: push(@okspares,$server);
19567: }
1.145 raeburn 19568: }
19569: }
19570: }
19571: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
19572: my $newspare;
1.152 raeburn 19573: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
19574: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 19575: $newspare = $new;
19576: }
19577: }
1.152 raeburn 19578: my @spares;
19579: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
19580: @spares = sort(@okspares,$newspare);
19581: } else {
19582: @spares = sort(@okspares);
19583: }
19584: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 19585: if (ref($spareid{$lonhost}) eq 'HASH') {
19586: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 19587: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 19588: if (@diffs > 0) {
19589: $spareschg{$type} = 1;
19590: }
19591: }
19592: }
19593: }
19594: if (keys(%spareschg) > 0) {
19595: $changes{'spares'}{$lonhost} = \%spareschg;
19596: }
19597: }
1.160.6.61 raeburn 19598: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 19599: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 19600: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
19601: my @okoffload;
19602: if (@offloadnow) {
19603: foreach my $server (@offloadnow) {
19604: if (&Apache::lonnet::hostname($server) ne '') {
19605: unless (grep(/^\Q$server\E$/,@okoffload)) {
19606: push(@okoffload,$server);
19607: }
19608: }
19609: }
19610: if (@okoffload) {
19611: foreach my $lonhost (@okoffload) {
19612: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
19613: }
19614: }
19615: }
1.160.6.105 raeburn 19616: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
19617: my @okoffloadoth;
19618: if (@offloadoth) {
19619: foreach my $server (@offloadoth) {
19620: if (&Apache::lonnet::hostname($server) ne '') {
19621: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
19622: push(@okoffloadoth,$server);
19623: }
19624: }
19625: }
19626: if (@okoffloadoth) {
19627: foreach my $lonhost (@okoffloadoth) {
19628: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
19629: }
19630: }
19631: }
1.145 raeburn 19632: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19633: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
19634: if (ref($changes{'spares'}) eq 'HASH') {
19635: if (keys(%{$changes{'spares'}}) > 0) {
19636: $savespares = 1;
19637: }
19638: }
19639: } else {
19640: $savespares = 1;
19641: }
1.160.6.105 raeburn 19642: foreach my $offload ('offloadnow','offloadoth') {
19643: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
19644: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
19645: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
19646: $changes{$offload} = 1;
1.160.6.61 raeburn 19647: last;
19648: }
19649: }
1.160.6.105 raeburn 19650: unless ($changes{$offload}) {
19651: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
19652: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
19653: $changes{$offload} = 1;
19654: last;
19655: }
19656: }
19657: }
19658: } else {
19659: if (($offload eq 'offloadnow') && (@okoffload)) {
19660: $changes{'offloadnow'} = 1;
19661: }
19662: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
19663: $changes{'offloadoth'} = 1;
19664: }
1.160.6.61 raeburn 19665: }
1.160.6.105 raeburn 19666: }
19667: } else {
19668: if (@okoffload) {
1.160.6.61 raeburn 19669: $changes{'offloadnow'} = 1;
19670: }
1.160.6.105 raeburn 19671: if (@okoffloadoth) {
19672: $changes{'offloadoth'} = 1;
19673: }
1.145 raeburn 19674: }
1.147 raeburn 19675: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
19676: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 19677: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19678: $dom);
19679: if ($putresult eq 'ok') {
19680: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
19681: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
19682: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
19683: }
19684: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
19685: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
19686: }
1.160.6.61 raeburn 19687: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
19688: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
19689: }
1.160.6.105 raeburn 19690: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
19691: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
19692: }
1.137 raeburn 19693: }
19694: my $cachetime = 24*60*60;
19695: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 19696: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 19697: if (ref($lastactref) eq 'HASH') {
19698: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 19699: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 19700: }
1.147 raeburn 19701: if (keys(%changes) > 0) {
19702: my %lt = &usersession_titles();
19703: $resulttext = &mt('Changes made:').'<ul>';
19704: foreach my $prefix (@prefixes) {
19705: if (ref($changes{$prefix}) eq 'HASH') {
19706: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
19707: if ($prefix eq 'spares') {
19708: if (ref($changes{$prefix}) eq 'HASH') {
19709: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
19710: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 19711: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 19712: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
19713: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 19714: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
19715: foreach my $type (@{$types{$prefix}}) {
19716: if ($changes{$prefix}{$lonhost}{$type}) {
19717: my $offloadto = &mt('None');
19718: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
19719: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
19720: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
19721: }
1.145 raeburn 19722: }
1.147 raeburn 19723: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 19724: }
1.137 raeburn 19725: }
19726: }
1.147 raeburn 19727: $resulttext .= '</li>';
1.137 raeburn 19728: }
19729: }
1.147 raeburn 19730: } else {
19731: foreach my $type (@{$types{$prefix}}) {
19732: if (defined($changes{$prefix}{$type})) {
19733: my $newvalue;
19734: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
19735: if (ref($defaultshash{'usersessions'}{$prefix})) {
19736: if ($type eq 'version') {
19737: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
19738: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19739: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
19740: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
19741: }
1.145 raeburn 19742: }
19743: }
19744: }
1.147 raeburn 19745: if ($newvalue eq '') {
19746: if ($type eq 'version') {
19747: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
19748: } else {
19749: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
19750: }
1.145 raeburn 19751: } else {
1.147 raeburn 19752: if ($type eq 'version') {
1.160.6.118.2 14(raebu 19753:23): $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 19754: }
19755: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 19756: }
1.137 raeburn 19757: }
19758: }
19759: }
1.147 raeburn 19760: $resulttext .= '</ul>';
1.137 raeburn 19761: }
19762: }
1.160.6.61 raeburn 19763: if ($changes{'offloadnow'}) {
19764: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
19765: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 19766: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 19767: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
19768: $resulttext .= '<li>'.$lonhost.'</li>';
19769: }
19770: $resulttext .= '</ul>';
19771: } else {
1.160.6.105 raeburn 19772: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
19773: }
19774: } else {
19775: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
19776: }
19777: }
19778: if ($changes{'offloadoth'}) {
19779: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
19780: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
19781: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
19782: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
19783: $resulttext .= '<li>'.$lonhost.'</li>';
19784: }
19785: $resulttext .= '</ul>';
19786: } else {
19787: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 19788: }
19789: } else {
1.160.6.105 raeburn 19790: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 19791: }
19792: }
1.147 raeburn 19793: $resulttext .= '</ul>';
19794: } else {
19795: $resulttext = $nochgmsg;
1.137 raeburn 19796: }
19797: } else {
19798: $resulttext = '<span class="LC_error">'.
19799: &mt('An error occurred: [_1]',$putresult).'</span>';
19800: }
19801: } else {
1.147 raeburn 19802: $resulttext = $nochgmsg;
1.137 raeburn 19803: }
19804: return $resulttext;
19805: }
19806:
1.150 raeburn 19807: sub modify_loadbalancing {
19808: my ($dom,%domconfig) = @_;
19809: my $primary_id = &Apache::lonnet::domain($dom,'primary');
19810: my $intdom = &Apache::lonnet::internet_dom($primary_id);
19811: my ($othertitle,$usertypes,$types) =
19812: &Apache::loncommon::sorted_inst_types($dom);
19813: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 19814: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 19815: my @sparestypes = ('primary','default');
19816: my %typetitles = &sparestype_titles();
19817: my $resulttext;
1.160.6.94 raeburn 19818: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 19819: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
19820: %existing = %{$domconfig{'loadbalancing'}};
19821: }
19822: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 19823: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 19824: my ($saveloadbalancing,%defaultshash,%changes);
19825: my ($alltypes,$othertypes,$titles) =
19826: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
19827: my %ruletitles = &offloadtype_text();
19828: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
19829: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
19830: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
19831: if ($balancer eq '') {
19832: next;
19833: }
19834: if (!exists($servers{$balancer})) {
19835: if (exists($currbalancer{$balancer})) {
19836: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 19837: }
1.160.6.7 raeburn 19838: next;
19839: }
19840: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
19841: push(@{$changes{'delete'}},$balancer);
19842: next;
19843: }
19844: if (!exists($currbalancer{$balancer})) {
19845: push(@{$changes{'add'}},$balancer);
19846: }
19847: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
19848: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
19849: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
19850: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
19851: $saveloadbalancing = 1;
19852: }
19853: foreach my $sparetype (@sparestypes) {
19854: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
19855: my @offloadto;
19856: foreach my $target (@targets) {
19857: if (($servers{$target}) && ($target ne $balancer)) {
19858: if ($sparetype eq 'default') {
19859: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
19860: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 19861: }
19862: }
1.160.6.7 raeburn 19863: unless(grep(/^\Q$target\E$/,@offloadto)) {
19864: push(@offloadto,$target);
19865: }
1.150 raeburn 19866: }
19867: }
1.160.6.76 raeburn 19868: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
19869: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
19870: push(@offloadto,$balancer);
19871: }
19872: }
19873: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 19874: }
1.160.6.94 raeburn 19875: if ($env{'form.loadbalancing_cookie_'.$i}) {
19876: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
19877: if (exists($currbalancer{$balancer})) {
19878: unless ($currcookies{$balancer}) {
19879: $changes{'curr'}{$balancer}{'cookie'} = 1;
19880: }
19881: }
19882: } elsif (exists($currbalancer{$balancer})) {
19883: if ($currcookies{$balancer}) {
19884: $changes{'curr'}{$balancer}{'cookie'} = 1;
19885: }
19886: }
1.160.6.7 raeburn 19887: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 19888: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 19889: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
19890: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 19891: if (@targetdiffs > 0) {
1.160.6.7 raeburn 19892: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 19893: }
1.160.6.7 raeburn 19894: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19895: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19896: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 19897: }
19898: }
19899: }
19900: } else {
1.160.6.7 raeburn 19901: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
19902: foreach my $sparetype (@sparestypes) {
19903: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19904: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19905: $changes{'curr'}{$balancer}{'targets'} = 1;
19906: }
1.150 raeburn 19907: }
19908: }
1.160.6.7 raeburn 19909: }
1.150 raeburn 19910: }
19911: my $ishomedom;
1.160.6.7 raeburn 19912: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
19913: $ishomedom = 1;
1.150 raeburn 19914: }
19915: if (ref($alltypes) eq 'ARRAY') {
19916: foreach my $type (@{$alltypes}) {
19917: my $rule;
1.160.6.7 raeburn 19918: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 19919: (!$ishomedom)) {
1.160.6.7 raeburn 19920: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
19921: }
19922: if ($rule eq 'specific') {
1.160.6.55 raeburn 19923: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
19924: if (exists($servers{$specifiedhost})) {
19925: $rule = $specifiedhost;
19926: }
1.150 raeburn 19927: }
1.160.6.7 raeburn 19928: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
19929: if (ref($currrules{$balancer}) eq 'HASH') {
19930: if ($rule ne $currrules{$balancer}{$type}) {
19931: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 19932: }
19933: } elsif ($rule ne '') {
1.160.6.7 raeburn 19934: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 19935: }
19936: }
19937: }
1.160.6.7 raeburn 19938: }
19939: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
19940: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
19941: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
19942: $defaultshash{'loadbalancing'} = {};
19943: }
19944: my $putresult = &Apache::lonnet::put_dom('configuration',
19945: \%defaultshash,$dom);
19946: if ($putresult eq 'ok') {
19947: if (keys(%changes) > 0) {
1.160.6.54 raeburn 19948: my %toupdate;
1.160.6.7 raeburn 19949: if (ref($changes{'delete'}) eq 'ARRAY') {
19950: foreach my $balancer (sort(@{$changes{'delete'}})) {
19951: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 19952: $toupdate{$balancer} = 1;
1.150 raeburn 19953: }
1.160.6.7 raeburn 19954: }
19955: if (ref($changes{'add'}) eq 'ARRAY') {
19956: foreach my $balancer (sort(@{$changes{'add'}})) {
19957: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 19958: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 19959: }
19960: }
19961: if (ref($changes{'curr'}) eq 'HASH') {
19962: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 19963: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 19964: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
19965: if ($changes{'curr'}{$balancer}{'targets'}) {
19966: my %offloadstr;
19967: foreach my $sparetype (@sparestypes) {
19968: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
19969: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
19970: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
19971: }
19972: }
1.150 raeburn 19973: }
1.160.6.7 raeburn 19974: if (keys(%offloadstr) == 0) {
19975: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 19976: } else {
1.160.6.7 raeburn 19977: my $showoffload;
19978: foreach my $sparetype (@sparestypes) {
19979: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
19980: if (defined($offloadstr{$sparetype})) {
19981: $showoffload .= $offloadstr{$sparetype};
19982: } else {
19983: $showoffload .= &mt('None');
19984: }
19985: $showoffload .= (' 'x3);
19986: }
19987: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 19988: }
19989: }
19990: }
1.160.6.7 raeburn 19991: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
19992: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
19993: foreach my $type (@{$alltypes}) {
19994: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
19995: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
19996: my $balancetext;
19997: if ($rule eq '') {
19998: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 19999: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 20000: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20001: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 20002: foreach my $sparetype (@sparestypes) {
20003: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20004: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20005: }
20006: }
1.160.6.55 raeburn 20007: foreach my $item (@{$alltypes}) {
20008: next if ($item =~ /^_LC_ipchange/);
20009: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20010: if ($hasrule eq 'homeserver') {
20011: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20012: } else {
20013: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20014: if ($servers{$hasrule}) {
20015: $toupdate{$hasrule} = 1;
20016: }
20017: }
20018: }
20019: }
20020: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20021: $balancetext = $ruletitles{$rule};
20022: } else {
20023: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20024: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20025: if ($receiver) {
20026: $toupdate{$receiver};
20027: }
20028: }
20029: } else {
20030: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 20031: }
1.160.6.7 raeburn 20032: } else {
20033: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20034: }
1.160.6.26 raeburn 20035: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20036: }
20037: }
20038: }
20039: }
1.160.6.94 raeburn 20040: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 20041: if ($currcookies{$balancer}) {
20042: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20043: $balancer).'</li>';
20044: } else {
20045: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20046: $balancer).'</li>';
20047: }
1.160.6.94 raeburn 20048: }
1.160.6.106 raeburn 20049: }
20050: }
20051: if (keys(%toupdate)) {
20052: my %thismachine;
20053: my $updatedhere;
20054: my $cachetime = 60*60*24;
20055: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20056: foreach my $lonhost (keys(%toupdate)) {
20057: if ($thismachine{$lonhost}) {
20058: unless ($updatedhere) {
20059: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20060: $defaultshash{'loadbalancing'},
20061: $cachetime);
20062: $updatedhere = 1;
1.160.6.54 raeburn 20063: }
1.160.6.106 raeburn 20064: } else {
20065: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20066: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 20067: }
1.150 raeburn 20068: }
1.160.6.7 raeburn 20069: }
20070: if ($resulttext ne '') {
20071: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20072: } else {
20073: $resulttext = $nochgmsg;
20074: }
20075: } else {
1.160.6.7 raeburn 20076: $resulttext = $nochgmsg;
1.150 raeburn 20077: }
20078: } else {
1.160.6.7 raeburn 20079: $resulttext = '<span class="LC_error">'.
20080: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20081: }
20082: } else {
1.160.6.7 raeburn 20083: $resulttext = $nochgmsg;
1.150 raeburn 20084: }
20085: return $resulttext;
20086: }
20087:
1.48 raeburn 20088: sub recurse_check {
20089: my ($chkcats,$categories,$depth,$name) = @_;
20090: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20091: my $chg = 0;
20092: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20093: my $category = $chkcats->[$depth]{$name}[$j];
20094: my $item;
20095: if ($category eq '') {
20096: $chg ++;
20097: } else {
20098: my $deeper = $depth + 1;
20099: $item = &escape($category).':'.&escape($name).':'.$depth;
20100: if ($chg) {
20101: $categories->{$item} -= $chg;
20102: }
20103: &recurse_check($chkcats,$categories,$deeper,$category);
20104: $deeper --;
20105: }
20106: }
20107: }
20108: return;
20109: }
20110:
20111: sub recurse_cat_deletes {
20112: my ($item,$coursecategories,$deletions) = @_;
20113: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20114: my $subdepth = $depth + 1;
20115: if (ref($coursecategories) eq 'HASH') {
20116: foreach my $subitem (keys(%{$coursecategories})) {
20117: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20118: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20119: delete($coursecategories->{$subitem});
20120: $deletions->{$subitem} = 1;
20121: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 20122: }
1.48 raeburn 20123: }
20124: }
20125: return;
20126: }
20127:
1.125 raeburn 20128: sub active_dc_picker {
1.160.6.16 raeburn 20129: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 20130: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 20131: my @domcoord = keys(%domcoords);
20132: if (keys(%currhash)) {
20133: foreach my $dc (keys(%currhash)) {
20134: unless (exists($domcoords{$dc})) {
20135: push(@domcoord,$dc);
20136: }
20137: }
20138: }
20139: @domcoord = sort(@domcoord);
20140: my $numdcs = scalar(@domcoord);
20141: my $rows = 0;
20142: my $table;
1.125 raeburn 20143: if ($numdcs > 1) {
1.160.6.16 raeburn 20144: $table = '<table>';
20145: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20146: my $rem = $i%($numinrow);
20147: if ($rem == 0) {
20148: if ($i > 0) {
1.160.6.16 raeburn 20149: $table .= '</tr>';
1.125 raeburn 20150: }
1.160.6.16 raeburn 20151: $table .= '<tr>';
20152: $rows ++;
1.125 raeburn 20153: }
1.160.6.16 raeburn 20154: my $check = '';
20155: if ($inputtype eq 'radio') {
20156: if (keys(%currhash) == 0) {
20157: if (!$i) {
20158: $check = ' checked="checked"';
20159: }
20160: } elsif (exists($currhash{$domcoord[$i]})) {
20161: $check = ' checked="checked"';
20162: }
20163: } else {
20164: if (exists($currhash{$domcoord[$i]})) {
20165: $check = ' checked="checked"';
1.125 raeburn 20166: }
20167: }
1.160.6.16 raeburn 20168: if ($i == @domcoord - 1) {
1.125 raeburn 20169: my $colsleft = $numinrow - $rem;
20170: if ($colsleft > 1) {
1.160.6.16 raeburn 20171: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20172: } else {
1.160.6.16 raeburn 20173: $table .= '<td class="LC_left_item">';
1.125 raeburn 20174: }
20175: } else {
1.160.6.16 raeburn 20176: $table .= '<td class="LC_left_item">';
20177: }
20178: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20179: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20180: $table .= '<span class="LC_nobreak"><label>'.
20181: '<input type="'.$inputtype.'" name="'.$name.'"'.
20182: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20183: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 20184: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 20185: }
1.160.6.33 raeburn 20186: $table .= '</label></span></td>';
1.125 raeburn 20187: }
1.160.6.16 raeburn 20188: $table .= '</tr></table>';
20189: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 20190: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20191: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 20192: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 20193: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 20194: if ($user ne $dcname.':'.$dcdom) {
20195: $table .= ' ('.$dcname.':'.$dcdom.')';
20196: }
1.160.6.16 raeburn 20197: } else {
20198: my $check;
20199: if (exists($currhash{$domcoord[0]})) {
20200: $check = ' checked="checked"';
20201: }
1.160.6.50 raeburn 20202: $table = '<span class="LC_nobreak"><label>'.
20203: '<input type="checkbox" name="'.$name.'" '.
20204: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 20205: if ($user ne $dcname.':'.$dcdom) {
20206: $table .= ' ('.$dcname.':'.$dcdom.')';
20207: }
20208: $table .= '</label></span>';
1.160.6.16 raeburn 20209: $rows ++;
20210: }
1.125 raeburn 20211: }
1.160.6.16 raeburn 20212: return ($numdcs,$table,$rows);
1.125 raeburn 20213: }
20214:
1.137 raeburn 20215: sub usersession_titles {
20216: return &Apache::lonlocal::texthash(
20217: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20218: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20219: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20220: version => 'LON-CAPA version requirement',
1.138 raeburn 20221: excludedomain => 'Allow all, but exclude specific domains',
20222: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20223: primary => 'Primary (checked first)',
1.154 raeburn 20224: default => 'Default',
1.137 raeburn 20225: );
20226: }
20227:
1.152 raeburn 20228: sub id_for_thisdom {
20229: my (%servers) = @_;
20230: my %altids;
20231: foreach my $server (keys(%servers)) {
20232: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20233: if ($serverhome ne $server) {
20234: $altids{$serverhome} = $server;
20235: }
20236: }
20237: return %altids;
20238: }
20239:
1.150 raeburn 20240: sub count_servers {
20241: my ($currbalancer,%servers) = @_;
20242: my (@spares,$numspares);
20243: foreach my $lonhost (sort(keys(%servers))) {
20244: next if ($currbalancer eq $lonhost);
20245: push(@spares,$lonhost);
20246: }
20247: if ($currbalancer) {
20248: $numspares = scalar(@spares);
20249: } else {
20250: $numspares = scalar(@spares) - 1;
20251: }
20252: return ($numspares,@spares);
20253: }
20254:
20255: sub lonbalance_targets_js {
1.160.6.7 raeburn 20256: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 20257: my $select = &mt('Select');
20258: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20259: if (ref($servers) eq 'HASH') {
20260: $alltargets = join("','",sort(keys(%{$servers})));
20261: my @homedoms;
20262: foreach my $server (sort(keys(%{$servers}))) {
20263: if (&Apache::lonnet::host_domain($server) eq $dom) {
20264: push(@homedoms,'1');
20265: } else {
20266: push(@homedoms,'0');
20267: }
20268: }
20269: $allishome = join("','",@homedoms);
20270: }
20271: if (ref($types) eq 'ARRAY') {
20272: if (@{$types} > 0) {
20273: @alltypes = @{$types};
20274: }
20275: }
20276: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
20277: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 20278: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 20279: if (ref($settings) eq 'HASH') {
20280: %existing = %{$settings};
20281: }
20282: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 20283: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 20284: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 20285: return <<"END";
20286:
20287: <script type="text/javascript">
20288: // <![CDATA[
20289:
1.160.6.7 raeburn 20290: currBalancers = new Array('$balancers');
20291:
20292: function toggleTargets(balnum) {
20293: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20294: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
20295: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
20296: var prevbalancer = prevhostitem.value;
20297: var baltotal = document.getElementById('loadbalancing_total').value;
20298: prevhostitem.value = balancer;
20299: if (prevbalancer != '') {
20300: var prevIdx = currBalancers.indexOf(prevbalancer);
20301: if (prevIdx != -1) {
20302: currBalancers.splice(prevIdx,1);
20303: }
20304: }
1.150 raeburn 20305: if (balancer == '') {
1.160.6.7 raeburn 20306: hideSpares(balnum);
1.150 raeburn 20307: } else {
1.160.6.7 raeburn 20308: var currIdx = currBalancers.indexOf(balancer);
20309: if (currIdx == -1) {
20310: currBalancers.push(balancer);
20311: }
1.150 raeburn 20312: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 20313: var ishomedom = homedoms[lonhostitem.selectedIndex];
20314: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 20315: }
1.160.6.7 raeburn 20316: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 20317: return;
20318: }
20319:
1.160.6.7 raeburn 20320: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 20321: var alltargets = new Array('$alltargets');
20322: var insttypes = new Array('$allinsttypes');
1.151 raeburn 20323: var offloadtypes = new Array('primary','default');
20324:
1.160.6.7 raeburn 20325: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
20326: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 20327:
1.151 raeburn 20328: for (var i=0; i<offloadtypes.length; i++) {
20329: var count = 0;
20330: for (var j=0; j<alltargets.length; j++) {
20331: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 20332: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
20333: item.value = alltargets[j];
20334: item.style.textAlign='left';
20335: item.style.textFace='normal';
20336: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
20337: if (currBalancers.indexOf(alltargets[j]) == -1) {
20338: item.disabled = '';
20339: } else {
20340: item.disabled = 'disabled';
20341: item.checked = false;
20342: }
1.151 raeburn 20343: count ++;
20344: }
1.150 raeburn 20345: }
20346: }
1.151 raeburn 20347: for (var k=0; k<insttypes.length; k++) {
20348: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 20349: if (ishomedom == 1) {
1.160.6.7 raeburn 20350: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
20351: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 20352: } else {
1.160.6.7 raeburn 20353: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
20354: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 20355: }
20356: } else {
1.160.6.7 raeburn 20357: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
20358: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 20359: }
1.151 raeburn 20360: if ((insttypes[k] != '_LC_external') &&
20361: ((insttypes[k] != '_LC_internetdom') ||
20362: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 20363: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
20364: item.options.length = 0;
20365: item.options[0] = new Option("","",true,true);
20366: var idx = 0;
1.151 raeburn 20367: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 20368: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
20369: idx ++;
20370: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 20371: }
20372: }
20373: }
20374: }
20375: return;
20376: }
20377:
1.160.6.7 raeburn 20378: function hideSpares(balnum) {
1.150 raeburn 20379: var alltargets = new Array('$alltargets');
20380: var insttypes = new Array('$allinsttypes');
20381: var offloadtypes = new Array('primary','default');
20382:
1.160.6.7 raeburn 20383: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
20384: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 20385:
20386: var total = alltargets.length - 1;
20387: for (var i=0; i<offloadtypes; i++) {
20388: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 20389: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
20390: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
20391: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 20392: }
1.150 raeburn 20393: }
20394: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 20395: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
20396: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 20397: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 20398: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
20399: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 20400: }
20401: }
20402: return;
20403: }
20404:
1.160.6.7 raeburn 20405: function checkOffloads(item,balnum,type) {
1.150 raeburn 20406: var alltargets = new Array('$alltargets');
20407: var offloadtypes = new Array('primary','default');
20408: if (item.checked) {
20409: var total = alltargets.length - 1;
20410: var other;
20411: if (type == offloadtypes[0]) {
1.151 raeburn 20412: other = offloadtypes[1];
1.150 raeburn 20413: } else {
1.151 raeburn 20414: other = offloadtypes[0];
1.150 raeburn 20415: }
20416: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 20417: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 20418: if (server == item.value) {
1.160.6.7 raeburn 20419: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
20420: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 20421: }
20422: }
20423: }
20424: }
20425: return;
20426: }
20427:
1.160.6.7 raeburn 20428: function singleServerToggle(balnum,type) {
20429: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 20430: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 20431: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
20432: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 20433:
20434: } else {
1.160.6.7 raeburn 20435: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
20436: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 20437: }
20438: return;
20439: }
20440:
1.160.6.7 raeburn 20441: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 20442: if (type == '_LC_external') {
1.160.6.26 raeburn 20443: return;
1.150 raeburn 20444: }
1.160.6.7 raeburn 20445: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 20446: for (var i=0; i<typesRules.length; i++) {
20447: if (formname.elements[typesRules[i]].checked) {
20448: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 20449: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
20450: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 20451: } else {
1.160.6.7 raeburn 20452: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
20453: }
20454: }
20455: }
20456: return;
20457: }
20458:
20459: function balancerDeleteChange(balnum) {
20460: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20461: var baltotal = document.getElementById('loadbalancing_total').value;
20462: var addtarget;
20463: var removetarget;
20464: var action = 'delete';
20465: if (document.getElementById('loadbalancing_delete_'+balnum)) {
20466: var lonhost = hostitem.value;
20467: var currIdx = currBalancers.indexOf(lonhost);
20468: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
20469: if (currIdx != -1) {
20470: currBalancers.splice(currIdx,1);
20471: }
20472: addtarget = lonhost;
20473: } else {
20474: if (currIdx == -1) {
20475: currBalancers.push(lonhost);
20476: }
20477: removetarget = lonhost;
20478: action = 'undelete';
20479: }
20480: balancerChange(balnum,baltotal,action,addtarget,removetarget);
20481: }
20482: return;
20483: }
20484:
20485: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
20486: if (baltotal > 1) {
20487: var offloadtypes = new Array('primary','default');
20488: var alltargets = new Array('$alltargets');
20489: var insttypes = new Array('$allinsttypes');
20490: for (var i=0; i<baltotal; i++) {
20491: if (i != balnum) {
20492: for (var j=0; j<offloadtypes.length; j++) {
20493: var total = alltargets.length - 1;
20494: for (var k=0; k<total; k++) {
20495: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
20496: var server = serveritem.value;
20497: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
20498: if (server == addtarget) {
20499: serveritem.disabled = '';
20500: }
20501: }
20502: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
20503: if (server == removetarget) {
20504: serveritem.disabled = 'disabled';
20505: serveritem.checked = false;
20506: }
20507: }
20508: }
20509: }
20510: for (var j=0; j<insttypes.length; j++) {
20511: if (insttypes[j] != '_LC_external') {
20512: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
20513: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
20514: var currSel = singleserver.selectedIndex;
20515: var currVal = singleserver.options[currSel].value;
20516: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
20517: var numoptions = singleserver.options.length;
20518: var needsnew = 1;
20519: for (var k=0; k<numoptions; k++) {
20520: if (singleserver.options[k] == addtarget) {
20521: needsnew = 0;
20522: break;
20523: }
20524: }
20525: if (needsnew == 1) {
20526: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
20527: }
20528: }
20529: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
20530: singleserver.options.length = 0;
20531: if ((currVal) && (currVal != removetarget)) {
20532: singleserver.options[0] = new Option("","",false,false);
20533: } else {
20534: singleserver.options[0] = new Option("","",true,true);
20535: }
20536: var idx = 0;
20537: for (var m=0; m<alltargets.length; m++) {
20538: if (currBalancers.indexOf(alltargets[m]) == -1) {
20539: idx ++;
20540: if (currVal == alltargets[m]) {
20541: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
20542: } else {
20543: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
20544: }
20545: }
20546: }
20547: }
20548: }
20549: }
20550: }
1.150 raeburn 20551: }
20552: }
20553: }
20554: return;
20555: }
20556:
1.152 raeburn 20557: // ]]>
20558: </script>
20559:
20560: END
20561: }
20562:
20563: sub new_spares_js {
20564: my @sparestypes = ('primary','default');
20565: my $types = join("','",@sparestypes);
20566: my $select = &mt('Select');
20567: return <<"END";
20568:
20569: <script type="text/javascript">
20570: // <![CDATA[
20571:
20572: function updateNewSpares(formname,lonhost) {
20573: var types = new Array('$types');
20574: var include = new Array();
20575: var exclude = new Array();
20576: for (var i=0; i<types.length; i++) {
20577: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
20578: for (var j=0; j<spareboxes.length; j++) {
20579: if (formname.elements[spareboxes[j]].checked) {
20580: exclude.push(formname.elements[spareboxes[j]].value);
20581: } else {
20582: include.push(formname.elements[spareboxes[j]].value);
20583: }
20584: }
20585: }
20586: for (var i=0; i<types.length; i++) {
20587: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
20588: var selIdx = newSpare.selectedIndex;
20589: var currnew = newSpare.options[selIdx].value;
20590: var okSpares = new Array();
20591: for (var j=0; j<newSpare.options.length; j++) {
20592: var possible = newSpare.options[j].value;
20593: if (possible != '') {
20594: if (exclude.indexOf(possible) == -1) {
20595: okSpares.push(possible);
20596: } else {
20597: if (currnew == possible) {
20598: selIdx = 0;
20599: }
20600: }
20601: }
20602: }
20603: for (var k=0; k<include.length; k++) {
20604: if (okSpares.indexOf(include[k]) == -1) {
20605: okSpares.push(include[k]);
20606: }
20607: }
20608: okSpares.sort();
20609: newSpare.options.length = 0;
20610: if (selIdx == 0) {
20611: newSpare.options[0] = new Option("$select","",true,true);
20612: } else {
20613: newSpare.options[0] = new Option("$select","",false,false);
20614: }
20615: for (var m=0; m<okSpares.length; m++) {
20616: var idx = m+1;
20617: var selThis = 0;
20618: if (selIdx != 0) {
20619: if (okSpares[m] == currnew) {
20620: selThis = 1;
20621: }
20622: }
20623: if (selThis == 1) {
20624: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
20625: } else {
20626: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
20627: }
20628: }
20629: }
20630: return;
20631: }
20632:
20633: function checkNewSpares(lonhost,type) {
20634: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
20635: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.160.6.118.2 14(raebu 20636:23): if (chosen != '') {
1.152 raeburn 20637: var othertype;
20638: var othernewSpare;
20639: if (type == 'primary') {
20640: othernewSpare = document.getElementById('newspare_default_'+lonhost);
20641: }
20642: if (type == 'default') {
20643: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
20644: }
20645: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
20646: othernewSpare.selectedIndex = 0;
20647: }
20648: }
20649: return;
20650: }
20651:
20652: // ]]>
20653: </script>
20654:
20655: END
20656:
20657: }
20658:
20659: sub common_domprefs_js {
20660: return <<"END";
20661:
20662: <script type="text/javascript">
20663: // <![CDATA[
20664:
1.150 raeburn 20665: function getIndicesByName(formname,item) {
1.152 raeburn 20666: var group = new Array();
1.150 raeburn 20667: for (var i=0;i<formname.elements.length;i++) {
20668: if (formname.elements[i].name == item) {
1.152 raeburn 20669: group.push(formname.elements[i].id);
1.150 raeburn 20670: }
20671: }
1.152 raeburn 20672: return group;
1.150 raeburn 20673: }
20674:
20675: // ]]>
20676: </script>
20677:
20678: END
1.152 raeburn 20679:
1.150 raeburn 20680: }
20681:
1.160.6.5 raeburn 20682: sub recaptcha_js {
20683: my %lt = &captcha_phrases();
20684: return <<"END";
20685:
20686: <script type="text/javascript">
20687: // <![CDATA[
20688:
20689: function updateCaptcha(caller,context) {
20690: var privitem;
20691: var pubitem;
20692: var privtext;
20693: var pubtext;
1.160.6.69 raeburn 20694: var versionitem;
20695: var versiontext;
1.160.6.5 raeburn 20696: if (document.getElementById(context+'_recaptchapub')) {
20697: pubitem = document.getElementById(context+'_recaptchapub');
20698: } else {
20699: return;
20700: }
20701: if (document.getElementById(context+'_recaptchapriv')) {
20702: privitem = document.getElementById(context+'_recaptchapriv');
20703: } else {
20704: return;
20705: }
20706: if (document.getElementById(context+'_recaptchapubtxt')) {
20707: pubtext = document.getElementById(context+'_recaptchapubtxt');
20708: } else {
20709: return;
20710: }
20711: if (document.getElementById(context+'_recaptchaprivtxt')) {
20712: privtext = document.getElementById(context+'_recaptchaprivtxt');
20713: } else {
20714: return;
20715: }
1.160.6.69 raeburn 20716: if (document.getElementById(context+'_recaptchaversion')) {
20717: versionitem = document.getElementById(context+'_recaptchaversion');
20718: } else {
20719: return;
20720: }
20721: if (document.getElementById(context+'_recaptchavertxt')) {
20722: versiontext = document.getElementById(context+'_recaptchavertxt');
20723: } else {
20724: return;
20725: }
1.160.6.5 raeburn 20726: if (caller.checked) {
20727: if (caller.value == 'recaptcha') {
20728: pubitem.type = 'text';
20729: privitem.type = 'text';
20730: pubitem.size = '40';
20731: privitem.size = '40';
20732: pubtext.innerHTML = "$lt{'pub'}";
20733: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 20734: versionitem.type = 'text';
20735: versionitem.size = '3';
20736: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 20737: } else {
20738: pubitem.type = 'hidden';
20739: privitem.type = 'hidden';
1.160.6.69 raeburn 20740: versionitem.type = 'hidden';
1.160.6.5 raeburn 20741: pubtext.innerHTML = '';
20742: privtext.innerHTML = '';
1.160.6.69 raeburn 20743: versiontext.innerHTML = '';
1.160.6.5 raeburn 20744: }
20745: }
20746: return;
20747: }
20748:
20749: // ]]>
20750: </script>
20751:
20752: END
20753:
20754: }
20755:
1.160.6.40 raeburn 20756: sub toggle_display_js {
1.160.6.16 raeburn 20757: return <<"END";
20758:
20759: <script type="text/javascript">
20760: // <![CDATA[
20761:
1.160.6.40 raeburn 20762: function toggleDisplay(domForm,caller) {
20763: if (document.getElementById(caller)) {
20764: var divitem = document.getElementById(caller);
20765: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 20766: var checkval = 1;
20767: var dispval = 'block';
1.160.6.93 raeburn 20768: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 20769: if (caller == 'emailoptions') {
1.160.6.118.2 14(raebu 20770:23): optionsElement = domForm.cancreate_email;
1.160.6.40 raeburn 20771: }
1.160.6.57 raeburn 20772: if (caller == 'studentsubmission') {
20773: optionsElement = domForm.postsubmit;
20774: }
1.160.6.64 raeburn 20775: if (caller == 'cloneinstcode') {
20776: optionsElement = domForm.canclone;
20777: checkval = 'instcode';
20778: }
1.160.6.93 raeburn 20779: if (selfcreateRegExp.test(caller)) {
20780: optionsElement = domForm.elements[caller];
20781: checkval = 'other';
20782: dispval = 'inline'
20783: }
1.160.6.40 raeburn 20784: if (optionsElement.length) {
1.160.6.16 raeburn 20785: var currval;
1.160.6.40 raeburn 20786: for (var i=0; i<optionsElement.length; i++) {
20787: if (optionsElement[i].checked) {
20788: currval = optionsElement[i].value;
1.160.6.16 raeburn 20789: }
20790: }
1.160.6.64 raeburn 20791: if (currval == checkval) {
20792: divitem.style.display = dispval;
1.160.6.16 raeburn 20793: } else {
1.160.6.40 raeburn 20794: divitem.style.display = 'none';
1.160.6.16 raeburn 20795: }
20796: }
20797: }
20798: return;
20799: }
20800:
20801: // ]]>
20802: </script>
20803:
20804: END
20805:
20806: }
20807:
1.160.6.5 raeburn 20808: sub captcha_phrases {
20809: return &Apache::lonlocal::texthash (
20810: priv => 'Private key',
20811: pub => 'Public key',
20812: original => 'original (CAPTCHA)',
20813: recaptcha => 'successor (ReCAPTCHA)',
20814: notused => 'unused',
1.160.6.69 raeburn 20815: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 20816: );
20817: }
20818:
1.160.6.24 raeburn 20819: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 20820: my ($dom,$cachekeys) = @_;
20821: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 20822: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20823: my %thismachine;
20824: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 20825:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 20826: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
20827: 'ipaccess');
20828: my %cache_by_lonhost;
20829: if (exists($cachekeys->{'samllanding'})) {
20830: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
20831: my %landing = %{$cachekeys->{'samllanding'}};
20832: my %domservers = &Apache::lonnet::get_servers($dom);
20833: if (keys(%domservers)) {
20834: foreach my $server (keys(%domservers)) {
20835: my @cached;
20836: next if ($thismachine{$server});
20837: if ($landing{$server}) {
20838: push(@cached,&escape('samllanding').':'.&escape($server));
20839: }
20840: if (@cached) {
20841: $cache_by_lonhost{$server} = \@cached;
20842: }
20843: }
20844: }
20845: }
20846: }
1.160.6.61 raeburn 20847: if (keys(%servers)) {
1.160.6.24 raeburn 20848: foreach my $server (keys(%servers)) {
20849: next if ($thismachine{$server});
1.160.6.27 raeburn 20850: my @cached;
20851: foreach my $name (@posscached) {
20852: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 20853: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
20854: if (ref($cachekeys->{$name}) eq 'HASH') {
20855: foreach my $key (keys(%{$cachekeys->{$name}})) {
20856: push(@cached,&escape($name).':'.&escape($key));
20857: }
20858: }
20859: } else {
20860: push(@cached,&escape($name).':'.&escape($dom));
20861: }
1.160.6.27 raeburn 20862: }
20863: }
1.160.6.113 raeburn 20864: if ((exists($cache_by_lonhost{$server})) &&
20865: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
20866: push(@cached,@{$cache_by_lonhost{$server}});
20867: }
1.160.6.27 raeburn 20868: if (@cached) {
20869: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
20870: }
1.160.6.24 raeburn 20871: }
20872: }
20873: return;
20874: }
20875:
1.3 raeburn 20876: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>