Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.18
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 18(raebu 4:24): # $Id: domainprefs.pm,v 1.160.6.118.2.17 2024/01/02 02:46:18 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'},
18(raebu 598:24): {col1 => 'Link Protectors in Courses',
599:24): col2 => 'Values'},
5(raebur 600:2): {col1 => 'Link Protectors',
14(raebu 601:23): col2 => 'Settings'},
602:23): {col1 => 'Consumers',
5(raebur 603:2): col2 => 'Settings'},],
604:2): print => \&print_lti,
605:2): modify => \&modify_lti,
606:2): },
14(raebu 607:23): 'ipaccess' =>
1.160.6.113 raeburn 608: {text => 'IP-based access control',
609: help => 'Domain_Configuration_IP_Access',
610: header => [{col1 => 'Setting',
611: col2 => 'Value'},],
612: print => \&print_ipaccess,
613: modify => \&modify_ipaccess,
614: },
1.3 raeburn 615: );
1.110 raeburn 616: if (keys(%servers) > 1) {
617: $prefs{'login'} = { text => 'Log-in page options',
618: help => 'Domain_Configuration_Login_Page',
619: header => [{col1 => 'Log-in Service',
620: col2 => 'Server Setting',},
621: {col1 => 'Log-in Page Items',
1.160.6.118.2 5(raebur 622:2): col2 => 'Settings'},
1.160.6.5 raeburn 623: {col1 => 'Log-in Help',
1.160.6.56 raeburn 624: col2 => 'Value'},
625: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 626: col2 => 'Value'},
627: {col1 => 'SSO',
628: col2 => 'Dual login: SSO and non-SSO options'},
629: ],
1.160.6.37 raeburn 630: print => \&print_login,
631: modify => \&modify_login,
1.110 raeburn 632: };
633: }
1.160.6.13 raeburn 634:
1.6 raeburn 635: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 636: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 637: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 638: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 639: text=>"Settings to display/modify"});
1.9 raeburn 640: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 641:
1.3 raeburn 642: if ($phase eq 'process') {
1.160.6.27 raeburn 643: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
644: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 645: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 646: $r->rflush();
1.160.6.27 raeburn 647: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 648: }
1.30 raeburn 649: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 650: my $js = &recaptcha_js().
1.160.6.40 raeburn 651: &toggle_display_js();
1.160.6.7 raeburn 652: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 653: my ($othertitle,$usertypes,$types) =
654: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 655: $js .= &lonbalance_targets_js($dom,$types,\%servers,
656: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 657: &new_spares_js().
658: &common_domprefs_js().
659: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 660: }
1.160.6.30 raeburn 661: if (grep(/^requestcourses$/,@actions)) {
662: my $javascript_validations;
663: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
664: $js .= <<END;
665: <script type="text/javascript">
666: $javascript_validations
667: </script>
668: $coursebrowserjs
669: END
1.160.6.113 raeburn 670: } elsif (grep(/^ipaccess$/,@actions)) {
671: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 672: }
1.160.6.93 raeburn 673: if (grep(/^selfcreation$/,@actions)) {
674: $js .= &selfcreate_javascript();
675: }
1.160.6.78 raeburn 676: if (grep(/^contacts$/,@actions)) {
677: $js .= &contacts_javascript();
678: }
1.160.6.97 raeburn 679: if (grep(/^scantron$/,@actions)) {
680: $js .= &scantron_javascript();
681: }
1.150 raeburn 682: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 683: } else {
1.160.6.11 raeburn 684: # check if domconfig user exists for the domain.
685: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 686: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 687: &config_check($dom,$confname,$servadm);
688: unless ($configuserok eq 'ok') {
689: &Apache::lonconfigsettings::print_header($r,$phase,$context);
690: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
691: $confname).
692: '<br />'
693: );
694: if ($switchserver) {
695: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
696: '<br />'.
697: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
698: '<br />'.
699: &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).
700: '<br />'.
701: &mt('To do that now, use the following link: [_1]',$switchserver)
702: );
703: } else {
704: $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.').
705: '<br />'.
706: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
707: );
708: }
709: $r->print(&Apache::loncommon::end_page());
710: return OK;
711: }
1.21 raeburn 712: if (keys(%domconfig) == 0) {
713: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 714: my @ids=&Apache::lonnet::current_machine_ids();
715: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 716: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 717: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 718: my $custom_img_count = 0;
719: foreach my $img (@loginimages) {
720: if ($designhash{$dom.'.login.'.$img} ne '') {
721: $custom_img_count ++;
722: }
723: }
724: foreach my $role (@roles) {
725: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
726: $custom_img_count ++;
727: }
728: }
729: if ($custom_img_count > 0) {
1.94 raeburn 730: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 731: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 732: $r->print(
733: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
734: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
735: &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 />'.
736: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
737: if ($switch_server) {
1.30 raeburn 738: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 739: }
1.91 raeburn 740: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 741: return OK;
742: }
743: }
744: }
1.91 raeburn 745: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 746: }
747: return OK;
748: }
749:
750: sub process_changes {
1.160.6.24 raeburn 751: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 752: my %domconfig;
753: if (ref($values) eq 'HASH') {
754: %domconfig = %{$values};
755: }
1.3 raeburn 756: my $output;
757: if ($action eq 'login') {
1.160.6.24 raeburn 758: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 759: } elsif ($action eq 'rolecolors') {
1.9 raeburn 760: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 761: $lastactref,%domconfig);
1.3 raeburn 762: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 763: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 764: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 765: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 766: } elsif ($action eq 'autoupdate') {
767: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 768: } elsif ($action eq 'autocreate') {
769: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 770: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 771: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 772: } elsif ($action eq 'usercreation') {
1.28 raeburn 773: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 774: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 775: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 776: } elsif ($action eq 'usermodification') {
777: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 778: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 779: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 780: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 781: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 782: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 783: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 784: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 785: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 786: } elsif ($action eq 'serverstatuses') {
787: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 788: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 789: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 790: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 791: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 792: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 793: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 794: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 795: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 796: } elsif ($action eq 'selfenrollment') {
797: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 798: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 799: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 800: } elsif ($action eq 'loadbalancing') {
801: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2 14(raebu 802:23): } elsif ($action eq 'ltitools') {
803:23): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
5(raebur 804:2): } elsif ($action eq 'lti') {
805:2): $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98 raeburn 806: } elsif ($action eq 'passwords') {
807: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 808: } elsif ($action eq 'wafproxy') {
809: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
810: } elsif ($action eq 'ipaccess') {
811: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.3 raeburn 812: }
813: return $output;
814: }
815:
816: sub print_config_box {
1.9 raeburn 817: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 818: my $rowtotal = 0;
1.49 raeburn 819: my $output;
820: if ($action eq 'coursecategories') {
821: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 822: } elsif ($action eq 'defaults') {
823: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 824: } elsif ($action eq 'passwords') {
1.160.6.118.2 5(raebur 825:2): $output = &passwords_javascript($action);
1.160.6.73 raeburn 826: } elsif ($action eq 'helpsettings') {
827: my (%privs,%levelscurrent);
828: my %full=();
829: my %levels=(
830: course => {},
831: domain => {},
832: system => {},
833: );
834: my $context = 'domain';
835: my $crstype = 'Course';
836: my $formname = 'display';
837: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
838: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
839: $output =
840: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
841: \@templateroles);
1.160.6.118.2 1(raebur 842:1): } elsif ($action eq 'ltitools') {
14(raebu 843:23): $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
5(raebur 844:2): } elsif ($action eq 'lti') {
14(raebu 845:23): $output .= &passwords_javascript('ltisecrets')."\n".
5(raebur 846:2): <i_javascript($dom,$settings);
1.160.6.113 raeburn 847: } elsif ($action eq 'wafproxy') {
848: $output .= &wafproxy_javascript($dom);
849: } elsif ($action eq 'autoupdate') {
850: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 851: } elsif ($action eq 'autoenroll') {
852: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 853: } elsif ($action eq 'login') {
854: $output .= &saml_javascript();
855: } elsif ($action eq 'ipaccess') {
856: $output .= &ipaccess_javascript($settings);
1.91 raeburn 857: }
1.160.6.40 raeburn 858: $output .=
1.30 raeburn 859: '<table class="LC_nested_outer">
1.3 raeburn 860: <tr>
1.160.6.113 raeburn 861: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 862: &mt($item->{text}).' '.
863: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
864: '</tr>';
1.30 raeburn 865: $rowtotal ++;
1.110 raeburn 866: my $numheaders = 1;
867: if (ref($item->{'header'}) eq 'ARRAY') {
868: $numheaders = scalar(@{$item->{'header'}});
869: }
870: if ($numheaders > 1) {
1.64 raeburn 871: my $colspan = '';
1.145 raeburn 872: my $rightcolspan = '';
1.160.6.118.2 14(raebu 873:23): my $leftnobr = '';
1.160.6.42 raeburn 874: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 875: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 876: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 877: $colspan = ' colspan="2"';
878: }
1.145 raeburn 879: if ($action eq 'usersessions') {
880: $rightcolspan = ' colspan="3"';
881: }
1.160.6.104 raeburn 882: if ($action eq 'passwords') {
883: $leftnobr = ' LC_nobreak';
884: }
1.30 raeburn 885: $output .= '
1.3 raeburn 886: <tr>
887: <td>
888: <table class="LC_nested">
889: <tr class="LC_info_row">
1.160.6.104 raeburn 890: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 891: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 892: </tr>';
1.69 raeburn 893: $rowtotal ++;
1.160.6.37 raeburn 894: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 895: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 896: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2 14(raebu 897:23): ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') ||
898:23): ($action eq 'lti') || ($action eq 'ltitools')) {
1.160.6.37 raeburn 899: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 900: } elsif ($action eq 'passwords') {
901: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 902: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 903: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 904: } elsif ($action eq 'scantron') {
905: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 906: } elsif ($action eq 'login') {
1.160.6.113 raeburn 907: if ($numheaders == 5) {
1.160.6.5 raeburn 908: $colspan = ' colspan="2"';
909: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
910: } else {
911: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
912: }
1.160.6.37 raeburn 913: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 914: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 915: } elsif ($action eq 'rolecolors') {
1.30 raeburn 916: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 917: }
1.30 raeburn 918: $output .= '
1.6 raeburn 919: </table>
920: </td>
921: </tr>
922: <tr>
923: <td>
924: <table class="LC_nested">
925: <tr class="LC_info_row">
1.160.6.37 raeburn 926: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 927: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 928: </tr>';
929: $rowtotal ++;
1.160.6.37 raeburn 930: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
931: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 932: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2 8(raebur 933:2): ($action eq 'contacts') || ($action eq 'passwords') ||
14(raebu 934:23): ($action eq 'defaults') || ($action eq 'lti') ||
935:23): ($action eq 'ltitools')) {
1.160.6.42 raeburn 936: if ($action eq 'coursecategories') {
937: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
938: $colspan = ' colspan="2"';
1.160.6.98 raeburn 939: } elsif ($action eq 'passwords') {
940: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.118.2 18(raebu 941:24): } elsif ($action eq 'lti') {
942:24): $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
943:24): </table>
944:24): </td>
945:24): </tr>
946:24): <tr>
947:24): <td>
948:24): <table class="LC_nested">
949:24): <tr class="LC_info_row">
950:24): <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
951:24): <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
952:24): </tr>'."\n".
953:24): $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.160.6.42 raeburn 954: } else {
955: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
956: }
1.160.6.118.2 18(raebu 957:24): my $hdridx = 2;
958:24): if ($action eq 'lti') {
959:24): $hdridx = 3;
960:24): }
1.160.6.42 raeburn 961: $output .= '
1.63 raeburn 962: </table>
963: </td>
964: </tr>
965: <tr>
966: <td>
967: <table class="LC_nested">
968: <tr class="LC_info_row">
1.160.6.118.2 18(raebu 969:24): <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
970:24): <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.160.6.42 raeburn 971: </tr>'."\n";
972: if ($action eq 'coursecategories') {
973: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 974: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 975: if ($action eq 'passwords') {
976: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
977: } else {
978: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
979: }
1.160.6.118.2 18(raebu 980:24): $hdridx ++;
1.160.6.107 raeburn 981: $output .= '
1.160.6.98 raeburn 982: </tr>
983: </table>
984: </td>
985: </tr>
986: <tr>
987: <td>
988: <table class="LC_nested">
989: <tr class="LC_info_row">
1.160.6.118.2 18(raebu 990:24): <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
991:24): <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 992: if ($action eq 'passwords') {
993: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
994: } else {
995: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
996: }
997: $output .= '
1.160.6.98 raeburn 998: </table>
999: </td>
1000: </tr>
1001: <tr>';
1.160.6.42 raeburn 1002: } else {
1003: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1004: }
1.63 raeburn 1005: $rowtotal ++;
1.160.6.57 raeburn 1006: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.118.2 8(raebur 1007:2): ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
1008:2): ($action eq 'wafproxy')) {
1.160.6.37 raeburn 1009: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 1010: } elsif ($action eq 'scantron') {
1011: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1012: } elsif ($action eq 'login') {
1.160.6.113 raeburn 1013: if ($numheaders == 5) {
1.160.6.5 raeburn 1014: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1015: </table>
1016: </td>
1017: </tr>
1018: <tr>
1019: <td>
1020: <table class="LC_nested">
1021: <tr class="LC_info_row">
1022: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 1023: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 1024: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1025: $rowtotal ++;
1026: } else {
1027: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1028: }
1.160.6.56 raeburn 1029: $output .= '
1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">';
1.160.6.113 raeburn 1037: if ($numheaders == 5) {
1.160.6.56 raeburn 1038: $output .= '
1039: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1040: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1041: </tr>';
1042: } else {
1043: $output .= '
1044: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1045: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1046: </tr>';
1047: }
1048: $rowtotal ++;
1.160.6.113 raeburn 1049: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1050: </table>
1051: </td>
1052: </tr>
1053: <tr>
1054: <td>
1055: <table class="LC_nested">
1056: <tr class="LC_info_row">';
1057: if ($numheaders == 5) {
1058: $output .= '
1059: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1060: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1061: </tr>';
1062: } else {
1063: $output .= '
1064: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1065: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1066: </tr>';
1067: }
1068: $rowtotal ++;
1069: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1070: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 1071: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1072: $rowtotal ++;
1073: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 1074: </table>
1075: </td>
1076: </tr>
1077: <tr>
1078: <td>
1079: <table class="LC_nested">
1080: <tr class="LC_info_row">
1081: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1082: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 1083: &textbookcourses_javascript($settings).
1084: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1085: </table>
1086: </td>
1087: </tr>
1088: <tr>
1089: <td>
1090: <table class="LC_nested">
1091: <tr class="LC_info_row">
1092: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1093: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1094: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 1095: </table>
1096: </td>
1097: </tr>
1098: <tr>
1099: <td>
1100: <table class="LC_nested">
1101: <tr class="LC_info_row">
1.160.6.46 raeburn 1102: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1103: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1104: </tr>'.
1105: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1106: } elsif ($action eq 'requestauthor') {
1107: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1108: $rowtotal ++;
1.122 jms 1109: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1110: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1111: </table>
1112: </td>
1113: </tr>
1114: <tr>
1115: <td>
1116: <table class="LC_nested">
1117: <tr class="LC_info_row">
1.69 raeburn 1118: <td class="LC_left_item"'.$colspan.' valign="top">'.
1119: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1120: <td class="LC_right_item" valign="top">'.
1121: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1122: </tr>'.
1.30 raeburn 1123: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1124: </table>
1125: </td>
1126: </tr>
1127: <tr>
1128: <td>
1129: <table class="LC_nested">
1130: <tr class="LC_info_row">
1.59 bisitz 1131: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1132: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1133: </tr>'.
1.30 raeburn 1134: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1135: $rowtotal += 2;
1.6 raeburn 1136: }
1.3 raeburn 1137: } else {
1.30 raeburn 1138: $output .= '
1.3 raeburn 1139: <tr>
1140: <td>
1141: <table class="LC_nested">
1.30 raeburn 1142: <tr class="LC_info_row">';
1.160.6.72 raeburn 1143: if ($action eq 'login') {
1.30 raeburn 1144: $output .= '
1.59 bisitz 1145: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1146: } elsif ($action eq 'serverstatuses') {
1147: $output .= '
1148: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1149: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1150:
1.6 raeburn 1151: } else {
1.30 raeburn 1152: $output .= '
1.69 raeburn 1153: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1154: }
1.72 raeburn 1155: if (defined($item->{'header'}->[0]->{'col3'})) {
1156: $output .= '<td class="LC_left_item" valign="top">'.
1157: &mt($item->{'header'}->[0]->{'col2'});
1158: if ($action eq 'serverstatuses') {
1159: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1160: }
1.69 raeburn 1161: } else {
1162: $output .= '<td class="LC_right_item" valign="top">'.
1163: &mt($item->{'header'}->[0]->{'col2'});
1164: }
1165: $output .= '</td>';
1166: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1167: if (defined($item->{'header'}->[0]->{'col4'})) {
1168: $output .= '<td class="LC_left_item" valign="top">'.
1169: &mt($item->{'header'}->[0]->{'col3'});
1170: } else {
1171: $output .= '<td class="LC_right_item" valign="top">'.
1172: &mt($item->{'header'}->[0]->{'col3'});
1173: }
1.69 raeburn 1174: if ($action eq 'serverstatuses') {
1175: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1176: }
1177: $output .= '</td>';
1.6 raeburn 1178: }
1.150 raeburn 1179: if ($item->{'header'}->[0]->{'col4'}) {
1180: $output .= '<td class="LC_right_item" valign="top">'.
1181: &mt($item->{'header'}->[0]->{'col4'});
1182: }
1.69 raeburn 1183: $output .= '</tr>';
1.48 raeburn 1184: $rowtotal ++;
1.160.6.5 raeburn 1185: if ($action eq 'quotas') {
1.86 raeburn 1186: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1187: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1188: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 14(raebu 1189:23): ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1190: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1191: }
1.3 raeburn 1192: }
1.30 raeburn 1193: $output .= '
1.3 raeburn 1194: </table>
1195: </td>
1196: </tr>
1.30 raeburn 1197: </table><br />';
1198: return ($output,$rowtotal);
1.1 raeburn 1199: }
1200:
1.3 raeburn 1201: sub print_login {
1.160.6.5 raeburn 1202: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1203: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1204: my %choices = &login_choices();
1.160.6.113 raeburn 1205: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1206: %lt = &login_file_options();
1207: $switchserver = &check_switchserver($dom,$confname);
1208: }
1.160.6.5 raeburn 1209: if ($caller eq 'service') {
1.149 raeburn 1210: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1211: my $choice = $choices{'disallowlogin'};
1212: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1213: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1214: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1215: '<th>'.$choices{'server'}.'</th>'.
1216: '<th>'.$choices{'serverpath'}.'</th>'.
1217: '<th>'.$choices{'custompath'}.'</th>'.
1218: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1219: my %disallowed;
1220: if (ref($settings) eq 'HASH') {
1221: if (ref($settings->{'loginvia'}) eq 'HASH') {
1222: %disallowed = %{$settings->{'loginvia'}};
1223: }
1224: }
1225: foreach my $lonhost (sort(keys(%servers))) {
1226: my $direct = 'selected="selected"';
1.128 raeburn 1227: if (ref($disallowed{$lonhost}) eq 'HASH') {
1228: if ($disallowed{$lonhost}{'server'} ne '') {
1229: $direct = '';
1230: }
1.110 raeburn 1231: }
1.115 raeburn 1232: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1233: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1234: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1235: '</option>';
1.160.6.13 raeburn 1236: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1237: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1238: my $selected = '';
1.128 raeburn 1239: if (ref($disallowed{$lonhost}) eq 'HASH') {
1240: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1241: $selected = 'selected="selected"';
1242: }
1.110 raeburn 1243: }
1244: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1245: $servers{$hostid}.'</option>';
1246: }
1.128 raeburn 1247: $datatable .= '</select></td>'.
1248: '<td><select name="'.$lonhost.'_serverpath">';
1249: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1250: my $pathname = $path;
1251: if ($path eq 'custom') {
1252: $pathname = &mt('Custom Path').' ->';
1253: }
1254: my $selected = '';
1255: if (ref($disallowed{$lonhost}) eq 'HASH') {
1256: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1257: $selected = 'selected="selected"';
1258: }
1259: } elsif ($path eq '') {
1260: $selected = 'selected="selected"';
1261: }
1262: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1263: }
1264: $datatable .= '</select></td>';
1265: my ($custom,$exempt);
1266: if (ref($disallowed{$lonhost}) eq 'HASH') {
1267: $custom = $disallowed{$lonhost}{'custompath'};
1268: $exempt = $disallowed{$lonhost}{'exempt'};
1269: }
1270: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1271: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1272: '</tr>';
1.110 raeburn 1273: }
1274: $datatable .= '</table></td></tr>';
1275: return $datatable;
1.160.6.5 raeburn 1276: } elsif ($caller eq 'page') {
1277: my %defaultchecked = (
1278: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1279: 'helpdesk' => 'on',
1.160.6.5 raeburn 1280: 'adminmail' => 'off',
1281: 'newuser' => 'off',
1282: );
1.160.6.14 raeburn 1283: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1284: my (%checkedon,%checkedoff);
1.42 raeburn 1285: foreach my $item (@toggles) {
1.160.6.5 raeburn 1286: if ($defaultchecked{$item} eq 'on') {
1287: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1288: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1289: } elsif ($defaultchecked{$item} eq 'off') {
1290: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1291: $checkedon{$item} = ' ';
1292: }
1.1 raeburn 1293: }
1.160.6.5 raeburn 1294: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1295:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1296: my @logintext = ('textcol','bgcol');
1297: my @bgs = ('pgbg','mainbg','sidebg');
1298: my @links = ('link','alink','vlink');
1299: my %designhash = &Apache::loncommon::get_domainconf($dom);
1300: my %defaultdesign = %Apache::loncommon::defaultdesign;
1301: my (%is_custom,%designs);
1302: my %defaults = (
1303: font => $defaultdesign{'login.font'},
1304: );
1.6 raeburn 1305: foreach my $item (@images) {
1.160.6.5 raeburn 1306: $defaults{$item} = $defaultdesign{'login.'.$item};
1307: $defaults{'showlogo'}{$item} = 1;
1308: }
1309: foreach my $item (@bgs) {
1310: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1311: }
1.41 raeburn 1312: foreach my $item (@logintext) {
1.160.6.5 raeburn 1313: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1314: }
1.160.6.5 raeburn 1315: foreach my $item (@links) {
1316: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1317: }
1.160.6.5 raeburn 1318: if (ref($settings) eq 'HASH') {
1319: foreach my $item (@toggles) {
1320: if ($settings->{$item} eq '1') {
1321: $checkedon{$item} = ' checked="checked" ';
1322: $checkedoff{$item} = ' ';
1323: } elsif ($settings->{$item} eq '0') {
1324: $checkedoff{$item} = ' checked="checked" ';
1325: $checkedon{$item} = ' ';
1326: }
1.6 raeburn 1327: }
1.160.6.5 raeburn 1328: foreach my $item (@images) {
1329: if (defined($settings->{$item})) {
1330: $designs{$item} = $settings->{$item};
1331: $is_custom{$item} = 1;
1332: }
1333: if (defined($settings->{'showlogo'}{$item})) {
1334: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1335: }
1336: }
1.160.6.118.2 2(raebur 1337:2): foreach my $item (@alttext) {
1338:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1339:2): if ($settings->{'alttext'}->{$item} ne '') {
1340:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1341:2): }
1342:2): }
1343:2): }
1.160.6.5 raeburn 1344: foreach my $item (@logintext) {
1345: if ($settings->{$item} ne '') {
1346: $designs{'logintext'}{$item} = $settings->{$item};
1347: $is_custom{$item} = 1;
1348: }
1349: }
1350: if ($settings->{'font'} ne '') {
1351: $designs{'font'} = $settings->{'font'};
1352: $is_custom{'font'} = 1;
1353: }
1354: foreach my $item (@bgs) {
1355: if ($settings->{$item} ne '') {
1356: $designs{'bgs'}{$item} = $settings->{$item};
1357: $is_custom{$item} = 1;
1358: }
1359: }
1360: foreach my $item (@links) {
1361: if ($settings->{$item} ne '') {
1362: $designs{'links'}{$item} = $settings->{$item};
1363: $is_custom{$item} = 1;
1364: }
1365: }
1366: } else {
1367: if ($designhash{$dom.'.login.font'} ne '') {
1368: $designs{'font'} = $designhash{$dom.'.login.font'};
1369: $is_custom{'font'} = 1;
1370: }
1371: foreach my $item (@images) {
1372: if ($designhash{$dom.'.login.'.$item} ne '') {
1373: $designs{$item} = $designhash{$dom.'.login.'.$item};
1374: $is_custom{$item} = 1;
1375: }
1376: }
1377: foreach my $item (@bgs) {
1378: if ($designhash{$dom.'.login.'.$item} ne '') {
1379: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1380: $is_custom{$item} = 1;
1381: }
1382: }
1383: foreach my $item (@links) {
1384: if ($designhash{$dom.'.login.'.$item} ne '') {
1385: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1386: $is_custom{$item} = 1;
1387: }
1.6 raeburn 1388: }
1389: }
1.160.6.5 raeburn 1390: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1391: logo => 'Institution Logo',
1392: domlogo => 'Domain Logo',
1393: login => 'Login box');
1394: my $itemcount = 1;
1395: foreach my $item (@toggles) {
1396: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1397: $datatable .=
1398: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1399: '</td><td>'.
1400: '<span class="LC_nobreak"><label><input type="radio" name="'.
1401: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1402: '</label> <label><input type="radio" name="'.$item.'"'.
1403: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1404: '</tr>';
1405: $itemcount ++;
1.6 raeburn 1406: }
1.160.6.5 raeburn 1407: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1408: $datatable .= '</tr></table></td></tr>';
1409: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1410: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1411: my $itemcount = 1;
1412: $defaulturl = '/adm/loginproblems.html';
1413: $defaulttype = 'default';
1414: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1415: my @currlangs;
1416: if (ref($settings) eq 'HASH') {
1417: if (ref($settings->{'helpurl'}) eq 'HASH') {
1418: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1419: next if ($settings->{'helpurl'}{$key} eq '');
1420: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1421: $type{$key} = 'custom';
1422: unless ($key eq 'nolang') {
1423: push(@currlangs,$key);
1424: }
1425: }
1426: } elsif ($settings->{'helpurl'} ne '') {
1427: $type{'nolang'} = 'custom';
1428: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1429: }
1430: }
1.160.6.5 raeburn 1431: foreach my $lang ('nolang',sort(@currlangs)) {
1432: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1433: $datatable .= '<tr'.$css_class.'>';
1434: if ($url{$lang} eq '') {
1435: $url{$lang} = $defaulturl;
1436: }
1437: if ($type{$lang} eq '') {
1438: $type{$lang} = $defaulttype;
1439: }
1440: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1441: if ($lang eq 'nolang') {
1442: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1443: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1444: } else {
1445: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1446: $langchoices{$lang},
1447: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1448: }
1449: $datatable .= '</span></td>'."\n".
1450: '<td class="LC_left_item">';
1451: if ($type{$lang} eq 'custom') {
1452: $datatable .= '<span class="LC_nobreak"><label>'.
1453: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1454: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1455: } else {
1456: $datatable .= $lt{'upl'};
1457: }
1458: $datatable .='<br />';
1459: if ($switchserver) {
1460: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1461: } else {
1462: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1463: }
1.160.6.5 raeburn 1464: $datatable .= '</td></tr>';
1465: $itemcount ++;
1.6 raeburn 1466: }
1.160.6.5 raeburn 1467: my @addlangs;
1468: foreach my $lang (sort(keys(%langchoices))) {
1469: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1470: push(@addlangs,$lang);
1471: }
1472: if (@addlangs > 0) {
1473: my %toadd;
1474: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1475: $toadd{''} = &mt('Select');
1476: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1477: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1478: &mt('Add log-in help page for a specific language:').' '.
1479: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1480: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1481: if ($switchserver) {
1482: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1483: } else {
1484: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1485: }
1.160.6.5 raeburn 1486: $datatable .= '</td></tr>';
1487: $itemcount ++;
1.6 raeburn 1488: }
1.160.6.5 raeburn 1489: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1490: } elsif ($caller eq 'headtag') {
1491: my %domservers = &Apache::lonnet::get_servers($dom);
1492: my $choice = $choices{'headtag'};
1493: $css_class = ' class="LC_odd_row"';
1494: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1495: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1496: '<th>'.$choices{'current'}.'</th>'.
1497: '<th>'.$choices{'action'}.'</th>'.
1498: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1499: my (%currurls,%currexempt);
1500: if (ref($settings) eq 'HASH') {
1501: if (ref($settings->{'headtag'}) eq 'HASH') {
1502: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1503: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1504: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1505: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1506: }
1507: }
1508: }
1509: }
1510: foreach my $lonhost (sort(keys(%domservers))) {
1511: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1512: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1513: if ($currurls{$lonhost}) {
1514: $datatable .= '<td class="LC_right_item"><a href="'.
1515: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1516: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1517: '">'.$lt{'curr'}.'</a></td>'.
1518: '<td><span class="LC_nobreak"><label>'.
1519: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1520: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1521: } else {
1522: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1523: }
1524: $datatable .='<br />';
1525: if ($switchserver) {
1526: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1527: } else {
1528: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1529: }
1.160.6.87 raeburn 1530: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1531: }
1532: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1533: } elsif ($caller eq 'saml') {
1534: my %domservers = &Apache::lonnet::get_servers($dom);
1535: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1536: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1537: '<th>'.$choices{'samllanding'}.'</th>'.
1538: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.160.6.118.2 9(raebur 1539:2): my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.160.6.113 raeburn 1540: foreach my $lonhost (keys(%domservers)) {
1541: $samlurl{$lonhost} = '/adm/sso';
1542: $styleon{$lonhost} = 'display:none';
1543: $styleoff{$lonhost} = '';
1544: }
1.160.6.118.2 11(raebu 1545:23): if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.160.6.113 raeburn 1546: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1547: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1548: $saml{$lonhost} = 1;
1549: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1550: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1551: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1552: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1553: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 1554:2): $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 1555: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1556: $styleon{$lonhost} = '';
1557: $styleoff{$lonhost} = 'display:none';
1558: } else {
1559: $styleon{$lonhost} = 'display:none';
1560: $styleoff{$lonhost} = '';
1561: }
1562: }
1563: }
1564: my $itemcount = 1;
1565: foreach my $lonhost (sort(keys(%domservers))) {
1566: my $samlon = ' ';
1567: my $samloff = ' checked="checked" ';
1568: if ($saml{$lonhost}) {
1569: $samlon = $samloff;
1570: $samloff = ' ';
1571: }
1.160.6.118.2 9(raebur 1572:2): my $samlwinon = '';
1573:2): my $samlwinoff = ' checked="checked"';
1574:2): if ($samlwindow{$lonhost}) {
1575:2): $samlwinon = $samlwinoff;
1576:2): $samlwinoff = '';
1577:2): }
1.160.6.113 raeburn 1578: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1579: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1580: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1581: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1582: &mt('No').'</label>'.(' 'x2).
1583: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1584: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1585: &mt('Yes').'</label></span></td>'.
1586: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.160.6.118.2 9(raebur 1587:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.160.6.113 raeburn 1588: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.160.6.118.2 9(raebur 1589:2): '<th>'.&mt('Alt Text').'</th></tr>'.
1590:2): '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.160.6.113 raeburn 1591: $samltext{$lonhost}.'" /></td><td>';
1592: if ($samlimg{$lonhost}) {
1593: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1594: '<span class="LC_nobreak"><label>'.
1595: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1596: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1597: } else {
1598: $datatable .= $lt{'upl'};
1599: }
1600: $datatable .='<br />';
1601: if ($switchserver) {
1602: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1603: } else {
1604: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1605: }
1606: $datatable .= '</td>'.
1.160.6.118.2 9(raebur 1607:2): '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1608:2): 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1609:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1610:2): '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1611:2): '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1612:2): '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1613:2): '<tr'.$css_class.'>'.
1614:2): '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.160.6.113 raeburn 1615: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.160.6.118.2 9(raebur 1616:2): '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.160.6.113 raeburn 1617: $samltitle{$lonhost}.'</textarea></td>'.
1.160.6.118.2 9(raebur 1618:2): '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1619:2): &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1620:2): 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1621:2): '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.160.6.113 raeburn 1622: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1623: '</table></td>'.
1624: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1625: $itemcount ++;
1626: }
1627: $datatable .= '</table></td></tr>';
1.1 raeburn 1628: }
1.6 raeburn 1629: return $datatable;
1630: }
1631:
1632: sub login_choices {
1633: my %choices =
1634: &Apache::lonlocal::texthash (
1.116 bisitz 1635: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1636: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1637: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1638: disallowlogin => "Login page requests redirected",
1639: hostid => "Server",
1.128 raeburn 1640: server => "Redirect to:",
1641: serverpath => "Path",
1642: custompath => "Custom",
1643: exempt => "Exempt IP(s)",
1.110 raeburn 1644: directlogin => "No redirect",
1645: newuser => "Link to create a user account",
1646: img => "Header",
1647: logo => "Main Logo",
1648: domlogo => "Domain Logo",
1649: login => "Log-in Header",
1650: textcol => "Text color",
1651: bgcol => "Box color",
1652: bgs => "Background colors",
1653: links => "Link colors",
1654: font => "Font color",
1655: pgbg => "Header",
1656: mainbg => "Page",
1657: sidebg => "Login box",
1658: link => "Link",
1659: alink => "Active link",
1660: vlink => "Visited link",
1.160.6.56 raeburn 1661: headtag => "Custom markup",
1662: action => "Action",
1663: current => "Current",
1.160.6.113 raeburn 1664: samllanding => "Dual login?",
1665: samloptions => "Options",
1.160.6.118.2 2(raebur 1666:2): alttext => "Alt text",
1.6 raeburn 1667: );
1668: return %choices;
1669: }
1670:
1.160.6.113 raeburn 1671: sub login_file_options {
1672: return &Apache::lonlocal::texthash(
1673: del => 'Delete?',
1674: rep => 'Replace:',
1675: upl => 'Upload:',
1676: curr => 'View contents',
1677: default => 'Default',
1678: custom => 'Custom',
1679: none => 'None',
1680: );
1681: }
1682:
1683: sub print_ipaccess {
1684: my ($dom,$settings,$rowtotal) = @_;
1685: my $css_class;
1686: my $itemcount = 0;
1687: my $datatable;
1688: my %ordered;
1689: if (ref($settings) eq 'HASH') {
1690: foreach my $item (keys(%{$settings})) {
1691: if (ref($settings->{$item}) eq 'HASH') {
1692: my $num = $settings->{$item}{'order'};
1693: if ($num eq '') {
1694: $num = scalar(keys(%{$settings}));
1695: }
1696: $ordered{$num} = $item;
1697: }
1698: }
1699: }
1700: my $maxnum = scalar(keys(%ordered));
1701: if (keys(%ordered)) {
1702: my @items = sort { $a <=> $b } keys(%ordered);
1703: for (my $i=0; $i<@items; $i++) {
1704: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1705: my $item = $ordered{$items[$i]};
1706: my ($name,$ipranges,%commblocks,%courses);
1707: if (ref($settings->{$item}) eq 'HASH') {
1708: $name = $settings->{$item}->{'name'};
1709: $ipranges = $settings->{$item}->{'ip'};
1710: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1711: %commblocks = %{$settings->{$item}->{'commblocks'}};
1712: }
1713: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1714: %courses = %{$settings->{$item}->{'courses'}};
1715: }
1716: }
1717: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1718: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1719: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1720: for (my $k=0; $k<=$maxnum; $k++) {
1721: my $vpos = $k+1;
1722: my $selstr;
1723: if ($k == $i) {
1724: $selstr = ' selected="selected" ';
1725: }
1726: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1727: }
1728: $datatable .= '</select>'.(' 'x2).
1729: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1730: &mt('Delete?').'</label></span></td>'.
1731: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1732: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1733: '</td></tr>';
1734: $itemcount ++;
1735: }
1736: }
1737: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1738: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1739: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1740: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1741: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1742: for (my $k=0; $k<$maxnum+1; $k++) {
1743: my $vpos = $k+1;
1744: my $selstr;
1745: if ($k == $maxnum) {
1746: $selstr = ' selected="selected" ';
1747: }
1748: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1749: }
1750: $datatable .= '</select> '."\n".
1751: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1752: '<td colspan="2">'.
1753: &ipaccess_options('add',$itemcount,$dom).
1754: '</td>'."\n".
1755: '</tr>'."\n";
1756: $$rowtotal ++;
1757: return $datatable;
1758: }
1759:
1760: sub ipaccess_options {
1761: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1762: my (%currblocks,%currcourses,$output);
1763: if (ref($blocksref) eq 'HASH') {
1764: %currblocks = %{$blocksref};
1765: }
1766: if (ref($coursesref) eq 'HASH') {
1767: %currcourses = %{$coursesref};
1768: }
1769: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1770: '<span class="LC_nobreak">'.&mt('Name').': '.
1771: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1772: '</span></fieldset>'.
1773: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1774: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1775: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1776: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1777: $ipranges.'</textarea></fieldset>'.
1778: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1779: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1780: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1781: '<table>';
1782: foreach my $cid (sort(keys(%currcourses))) {
1783: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1784: $output .= '<tr><td><span class="LC_nobreak">'.
1785: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1786: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1787: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1788: }
1789: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1790: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1791: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1792: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1793: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1794: '</span></td></tr></table>'."\n".
1795: '</fieldset>';
1796: return $output;
1797: }
1798:
1799: sub blocker_checkboxes {
1800: my ($num,$blocks) = @_;
1801: my ($typeorder,$types) = &commblocktype_text();
1802: my $numinrow = 6;
1803: my $output = '<table>';
1804: for (my $i=0; $i<@{$typeorder}; $i++) {
1805: my $block = $typeorder->[$i];
1806: my $blockstatus;
1807: if (ref($blocks) eq 'HASH') {
1808: if ($blocks->{$block} eq 'on') {
1809: $blockstatus = 'checked="checked"';
1810: }
1811: }
1812: my $rem = $i%($numinrow);
1813: if ($rem == 0) {
1814: if ($i > 0) {
1815: $output .= '</tr>';
1816: }
1817: $output .= '<tr>';
1818: }
1819: if ($i == scalar(@{$typeorder})-1) {
1820: my $colsleft = $numinrow-$rem;
1821: if ($colsleft > 1) {
1822: $output .= '<td colspan="'.$colsleft.'">';
1823: } else {
1824: $output .= '<td>';
1825: }
1826: } else {
1827: $output .= '<td>';
1828: }
1829: my $item = 'ipaccess_block_'.$num;
1830: if ($blockstatus) {
1831: $blockstatus = ' '.$blockstatus;
1832: }
1833: $output .= '<span class="LC_nobreak"><label>'."\n".
1834: '<input type="checkbox" name="'.$item.'"'.
1835: $blockstatus.' value="'.$block.'"'.' />'.
1836: $types->{$block}.'</label></span>'."\n".
1837: '<br /></td>';
1838: }
1839: $output .= '</tr></table>';
1840: return $output;
1841: }
1842:
1843: sub commblocktype_text {
1844: my %types = &Apache::lonlocal::texthash(
1845: 'com' => 'Messaging',
1846: 'chat' => 'Chat Room',
1847: 'boards' => 'Discussion',
1848: 'port' => 'Portfolio',
1849: 'groups' => 'Groups',
1850: 'blogs' => 'Blogs',
1851: 'about' => 'User Information',
1852: 'printout' => 'Printouts',
1853: 'passwd' => 'Change Password',
1854: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1855: 'search' => 'Course search',
1856: 'wishlist' => 'Stored links',
1857: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1858: );
1.160.6.115 raeburn 1859: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1860: return ($typeorder,\%types);
1861: }
1862:
1.6 raeburn 1863: sub print_rolecolors {
1.30 raeburn 1864: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1865: my %choices = &color_font_choices();
1866: my @bgs = ('pgbg','tabbg','sidebg');
1867: my @links = ('link','alink','vlink');
1868: my @images = ('img');
1869: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1870: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1871: my %defaultdesign = %Apache::loncommon::defaultdesign;
1872: my (%is_custom,%designs);
1.160.6.22 raeburn 1873: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1874: if (ref($settings) eq 'HASH') {
1875: if (ref($settings->{$role}) eq 'HASH') {
1876: if ($settings->{$role}->{'img'} ne '') {
1877: $designs{'img'} = $settings->{$role}->{'img'};
1878: $is_custom{'img'} = 1;
1879: }
1880: if ($settings->{$role}->{'font'} ne '') {
1881: $designs{'font'} = $settings->{$role}->{'font'};
1882: $is_custom{'font'} = 1;
1883: }
1.97 tempelho 1884: if ($settings->{$role}->{'fontmenu'} ne '') {
1885: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1886: $is_custom{'fontmenu'} = 1;
1887: }
1.6 raeburn 1888: foreach my $item (@bgs) {
1889: if ($settings->{$role}->{$item} ne '') {
1890: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1891: $is_custom{$item} = 1;
1892: }
1893: }
1894: foreach my $item (@links) {
1895: if ($settings->{$role}->{$item} ne '') {
1896: $designs{'links'}{$item} = $settings->{$role}->{$item};
1897: $is_custom{$item} = 1;
1898: }
1899: }
1900: }
1901: } else {
1902: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1903: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1904: $is_custom{'img'} = 1;
1905: }
1.97 tempelho 1906: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1907: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1908: $is_custom{'fontmenu'} = 1;
1909: }
1.6 raeburn 1910: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1911: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1912: $is_custom{'font'} = 1;
1913: }
1914: foreach my $item (@bgs) {
1915: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1916: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1917: $is_custom{$item} = 1;
1918:
1919: }
1920: }
1921: foreach my $item (@links) {
1922: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1923: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1924: $is_custom{$item} = 1;
1925: }
1926: }
1927: }
1928: my $itemcount = 1;
1.30 raeburn 1929: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1930: $datatable .= '</tr></table></td></tr>';
1931: return $datatable;
1932: }
1933:
1.160.6.22 raeburn 1934: sub role_defaults {
1935: my ($role,$bgs,$links,$images,$logintext) = @_;
1936: my %defaults;
1937: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1938: return %defaults;
1939: }
1940: my %defaultdesign = %Apache::loncommon::defaultdesign;
1941: if ($role eq 'login') {
1942: %defaults = (
1943: font => $defaultdesign{$role.'.font'},
1944: );
1945: if (ref($logintext) eq 'ARRAY') {
1946: foreach my $item (@{$logintext}) {
1947: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1948: }
1949: }
1950: foreach my $item (@{$images}) {
1951: $defaults{'showlogo'}{$item} = 1;
1952: }
1953: } else {
1954: %defaults = (
1955: img => $defaultdesign{$role.'.img'},
1956: font => $defaultdesign{$role.'.font'},
1957: fontmenu => $defaultdesign{$role.'.fontmenu'},
1958: );
1959: }
1960: foreach my $item (@{$bgs}) {
1961: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1962: }
1963: foreach my $item (@{$links}) {
1964: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1965: }
1966: foreach my $item (@{$images}) {
1967: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1968: }
1969: return %defaults;
1970: }
1971:
1.6 raeburn 1972: sub display_color_options {
1.9 raeburn 1973: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1974: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1975: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1976: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1977: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1978: '<td>'.$choices->{'font'}.'</td>';
1979: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1980: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1981: } else {
1982: $datatable .= '<td> </td>';
1983: }
1.160.6.9 raeburn 1984: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1985:
1.8 raeburn 1986: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1987: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1988: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1989: ' </span></td></tr>';
1.107 raeburn 1990: unless ($role eq 'login') {
1991: $datatable .= '<tr'.$css_class.'>'.
1992: '<td>'.$choices->{'fontmenu'}.'</td>';
1993: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 1994: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 1995: } else {
1996: $datatable .= '<td> </td>';
1997: }
1.160.6.22 raeburn 1998: $current_color = $designs->{'fontmenu'} ?
1999: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2000: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 2001: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 2002: .$role.'_fontmenu"'.
1.160.6.9 raeburn 2003: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 2004: ' </span></td></tr>';
1.97 tempelho 2005: }
1.9 raeburn 2006: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2007: foreach my $img (@{$images}) {
1.18 albertel 2008: $itemcount ++;
1.6 raeburn 2009: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2010: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2011: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 2012:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2013: if ($role eq 'login') {
2014: if ($img eq 'login') {
2015: $login_hdr_pick =
1.135 bisitz 2016: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2017: $logincolors =
2018: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 2019: $designs,$defaults);
1.160.6.118.2 2(raebur 2020:2): } else {
2021:2): if ($img ne 'domlogo') {
2022:2): $datatable.= &logo_display_options($img,$defaults,$designs);
2023:2): }
2024:2): if (ref($designs->{'alttext'}) eq 'HASH') {
2025:2): $alttext = $designs->{'alttext'}{$img};
2026:2): }
1.70 raeburn 2027: }
2028: }
2029: $datatable .= '</td>';
1.6 raeburn 2030: if ($designs->{$img} ne '') {
2031: $imgfile = $designs->{$img};
1.18 albertel 2032: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2033: } else {
2034: $imgfile = $defaults->{$img};
2035: }
2036: if ($imgfile) {
1.9 raeburn 2037: my ($showfile,$fullsize);
2038: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2039: my $urldir = $1;
2040: my $filename = $2;
2041: my @info = &Apache::lonnet::stat_file($designs->{$img});
2042: if (@info) {
2043: my $thumbfile = 'tn-'.$filename;
2044: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2045: if (@thumb) {
2046: $showfile = $urldir.'/'.$thumbfile;
2047: } else {
2048: $showfile = $imgfile;
2049: }
2050: } else {
2051: $showfile = '';
2052: }
2053: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2054: $showfile = $imgfile;
1.6 raeburn 2055: my $imgdir = $1;
2056: my $filename = $2;
1.159 raeburn 2057: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2058: $showfile = "/$imgdir/tn-".$filename;
2059: } else {
1.159 raeburn 2060: my $input = $londocroot.$imgfile;
2061: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2062: if (!-e $output) {
1.9 raeburn 2063: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2064: my ($fullwidth,$fullheight) = &check_dimensions($input);
2065: if ($fullwidth ne '' && $fullheight ne '') {
2066: if ($fullwidth > $width && $fullheight > $height) {
2067: my $size = $width.'x'.$height;
1.160.6.88 raeburn 2068: my @args = ('convert','-sample',$size,$input,$output);
2069: system({$args[0]} @args);
1.159 raeburn 2070: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2071: }
2072: }
1.6 raeburn 2073: }
2074: }
1.16 raeburn 2075: }
1.6 raeburn 2076: if ($showfile) {
1.40 raeburn 2077: if ($showfile =~ m{^/(adm|res)/}) {
2078: if ($showfile =~ m{^/res/}) {
2079: my $local_showfile =
2080: &Apache::lonnet::filelocation('',$showfile);
2081: &Apache::lonnet::repcopy($local_showfile);
2082: }
2083: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2084: }
2085: if ($imgfile) {
2086: if ($imgfile =~ m{^/(adm|res)/}) {
2087: if ($imgfile =~ m{^/res/}) {
2088: my $local_imgfile =
2089: &Apache::lonnet::filelocation('',$imgfile);
2090: &Apache::lonnet::repcopy($local_imgfile);
2091: }
2092: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2093: } else {
2094: $fullsize = $imgfile;
2095: }
2096: }
1.41 raeburn 2097: $datatable .= '<td>';
2098: if ($img eq 'login') {
1.135 bisitz 2099: $datatable .= $login_hdr_pick;
2100: }
1.41 raeburn 2101: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2102: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2103: } else {
1.160.6.22 raeburn 2104: $datatable .= '<td> </td><td class="LC_left_item">'.
2105: &mt('Upload:').'<br />';
1.6 raeburn 2106: }
2107: } else {
1.160.6.22 raeburn 2108: $datatable .= '<td> </td><td class="LC_left_item">'.
2109: &mt('Upload:').'<br />';
1.6 raeburn 2110: }
1.9 raeburn 2111: if ($switchserver) {
2112: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2113: } else {
1.135 bisitz 2114: if ($img ne 'login') { # suppress file selection for Log-in header
2115: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2116: }
1.9 raeburn 2117: }
1.160.6.118.2 2(raebur 2118:2): if (($role eq 'login') && ($img ne 'login')) {
2119:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2120:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2121:2): '</label></span>';
2122:2): }
1.9 raeburn 2123: $datatable .= '</td></tr>';
1.6 raeburn 2124: }
2125: $itemcount ++;
2126: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2127: $datatable .= '<tr'.$css_class.'>'.
2128: '<td>'.$choices->{'bgs'}.'</td>';
2129: my $bgs_def;
2130: foreach my $item (@{$bgs}) {
2131: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2132: $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 2133: }
2134: }
2135: if ($bgs_def) {
1.8 raeburn 2136: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2137: } else {
2138: $datatable .= '<td> </td>';
2139: }
2140: $datatable .= '<td class="LC_right_item">'.
2141: '<table border="0"><tr>';
1.160.6.13 raeburn 2142:
1.6 raeburn 2143: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2144: $datatable .= '<td align="center">'.$choices->{$item};
2145: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2146: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2147: $datatable .= ' ';
1.6 raeburn 2148: }
1.160.6.9 raeburn 2149: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2150: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2151: }
2152: $datatable .= '</tr></table></td></tr>';
2153: $itemcount ++;
2154: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2155: $datatable .= '<tr'.$css_class.'>'.
2156: '<td>'.$choices->{'links'}.'</td>';
2157: my $links_def;
2158: foreach my $item (@{$links}) {
2159: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2160: $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 2161: }
2162: }
2163: if ($links_def) {
1.8 raeburn 2164: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2165: } else {
2166: $datatable .= '<td> </td>';
2167: }
2168: $datatable .= '<td class="LC_right_item">'.
2169: '<table border="0"><tr>';
2170: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2171: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2172: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2173: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2174: $datatable.=' ';
1.6 raeburn 2175: }
1.160.6.9 raeburn 2176: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2177: '" /></td>';
2178: }
1.30 raeburn 2179: $$rowtotal += $itemcount;
1.3 raeburn 2180: return $datatable;
2181: }
2182:
1.70 raeburn 2183: sub logo_display_options {
2184: my ($img,$defaults,$designs) = @_;
2185: my $checkedon;
2186: if (ref($defaults) eq 'HASH') {
2187: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2188: if ($defaults->{'showlogo'}{$img}) {
2189: $checkedon = 'checked="checked" ';
2190: }
2191: }
2192: }
2193: if (ref($designs) eq 'HASH') {
2194: if (ref($designs->{'showlogo'}) eq 'HASH') {
2195: if (defined($designs->{'showlogo'}{$img})) {
2196: if ($designs->{'showlogo'}{$img} == 0) {
2197: $checkedon = '';
2198: } elsif ($designs->{'showlogo'}{$img} == 1) {
2199: $checkedon = 'checked="checked" ';
2200: }
2201: }
2202: }
2203: }
2204: return '<br /><label> <input type="checkbox" name="'.
2205: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2206: &mt('show').'</label>'."\n";
2207: }
2208:
1.41 raeburn 2209: sub login_header_options {
1.135 bisitz 2210: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2211: my $output = '';
1.41 raeburn 2212: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2213: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2214: if (!$is_custom->{'textcol'}) {
2215: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2216: ' ';
2217: }
2218: if (!$is_custom->{'bgcol'}) {
2219: $output .= $choices->{'bgcol'}.': '.
2220: '<span id="css_'.$role.'_font" style="background-color: '.
2221: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2222: }
2223: $output .= '<br />';
2224: }
2225: $output .='<br />';
2226: return $output;
2227: }
2228:
2229: sub login_text_colors {
1.160.6.22 raeburn 2230: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2231: my $color_menu = '<table border="0"><tr>';
2232: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2233: $color_menu .= '<td align="center">'.$choices->{$item};
2234: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2235: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2236: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2237: }
2238: $color_menu .= '</tr></table><br />';
2239: return $color_menu;
2240: }
2241:
2242: sub image_changes {
2243: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2244: my $output;
1.135 bisitz 2245: if ($img eq 'login') {
1.160.6.87 raeburn 2246: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2247: } elsif (!$is_custom) {
1.70 raeburn 2248: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2249: $output = &mt('Default image:').'<br />';
1.41 raeburn 2250: } else {
1.160.6.87 raeburn 2251: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2252: }
2253: }
1.160.6.87 raeburn 2254: if ($img ne 'login') {
1.135 bisitz 2255: if ($img_import) {
2256: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2257: }
2258: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2259: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2260: if ($is_custom) {
2261: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2262: '<input type="checkbox" name="'.
2263: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2264: '</label> '.&mt('Replace:').'</span><br />';
2265: } else {
1.160.6.22 raeburn 2266: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2267: }
1.41 raeburn 2268: }
2269: return $output;
2270: }
2271:
1.3 raeburn 2272: sub print_quotas {
1.86 raeburn 2273: my ($dom,$settings,$rowtotal,$action) = @_;
2274: my $context;
2275: if ($action eq 'quotas') {
2276: $context = 'tools';
2277: } else {
2278: $context = $action;
2279: }
1.160.6.20 raeburn 2280: my ($datatable,$defaultquota,$authorquota,@usertools,@options,%validations);
1.44 raeburn 2281: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2282: my $typecount = 0;
1.101 raeburn 2283: my ($css_class,%titles);
1.86 raeburn 2284: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 2285:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 2286: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2287: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2288: %titles = &courserequest_titles();
1.160.6.5 raeburn 2289: } elsif ($context eq 'requestauthor') {
2290: @usertools = ('author');
2291: @options = ('norequest','approval','automatic');
2292: %titles = &authorrequest_titles();
1.86 raeburn 2293: } else {
1.160.6.118.2 10(raebu 2294:22): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 2295: %titles = &tool_titles();
1.86 raeburn 2296: }
1.26 raeburn 2297: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2298: foreach my $type (@{$types}) {
1.160.6.20 raeburn 2299: my ($currdefquota,$currauthorquota);
1.160.6.5 raeburn 2300: unless (($context eq 'requestcourses') ||
2301: ($context eq 'requestauthor')) {
1.86 raeburn 2302: if (ref($settings) eq 'HASH') {
2303: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2304: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2305: } else {
2306: $currdefquota = $settings->{$type};
2307: }
1.160.6.20 raeburn 2308: if (ref($settings->{authorquota}) eq 'HASH') {
2309: $currauthorquota = $settings->{authorquota}->{$type};
2310: }
1.78 raeburn 2311: }
1.72 raeburn 2312: }
1.3 raeburn 2313: if (defined($usertypes->{$type})) {
2314: $typecount ++;
2315: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2316: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2317: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2318: '<td class="LC_left_item">';
1.101 raeburn 2319: if ($context eq 'requestcourses') {
2320: $datatable .= '<table><tr>';
2321: }
2322: my %cell;
1.72 raeburn 2323: foreach my $item (@usertools) {
1.101 raeburn 2324: if ($context eq 'requestcourses') {
2325: my ($curroption,$currlimit);
2326: if (ref($settings) eq 'HASH') {
2327: if (ref($settings->{$item}) eq 'HASH') {
2328: $curroption = $settings->{$item}->{$type};
2329: if ($curroption =~ /^autolimit=(\d*)$/) {
2330: $currlimit = $1;
2331: }
2332: }
2333: }
2334: if (!$curroption) {
2335: $curroption = 'norequest';
2336: }
2337: $datatable .= '<th>'.$titles{$item}.'</th>';
2338: foreach my $option (@options) {
2339: my $val = $option;
2340: if ($option eq 'norequest') {
2341: $val = 0;
2342: }
2343: if ($option eq 'validate') {
2344: my $canvalidate = 0;
2345: if (ref($validations{$item}) eq 'HASH') {
2346: if ($validations{$item}{$type}) {
2347: $canvalidate = 1;
2348: }
2349: }
2350: next if (!$canvalidate);
2351: }
2352: my $checked = '';
2353: if ($option eq $curroption) {
2354: $checked = ' checked="checked"';
2355: } elsif ($option eq 'autolimit') {
2356: if ($curroption =~ /^autolimit/) {
2357: $checked = ' checked="checked"';
2358: }
2359: }
2360: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2361: '<input type="radio" name="crsreq_'.$item.
2362: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2363: $titles{$option}.'</label>';
1.101 raeburn 2364: if ($option eq 'autolimit') {
1.127 raeburn 2365: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2366: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2367: 'value="'.$currlimit.'" />';
1.101 raeburn 2368: }
1.127 raeburn 2369: $cell{$item} .= '</span> ';
1.103 raeburn 2370: if ($option eq 'autolimit') {
1.127 raeburn 2371: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2372: }
1.101 raeburn 2373: }
1.160.6.5 raeburn 2374: } elsif ($context eq 'requestauthor') {
2375: my $curroption;
2376: if (ref($settings) eq 'HASH') {
2377: $curroption = $settings->{$type};
2378: }
2379: if (!$curroption) {
2380: $curroption = 'norequest';
2381: }
2382: foreach my $option (@options) {
2383: my $val = $option;
2384: if ($option eq 'norequest') {
2385: $val = 0;
2386: }
2387: my $checked = '';
2388: if ($option eq $curroption) {
2389: $checked = ' checked="checked"';
2390: }
2391: $datatable .= '<span class="LC_nobreak"><label>'.
2392: '<input type="radio" name="authorreq_'.$type.
2393: '" value="'.$val.'"'.$checked.' />'.
2394: $titles{$option}.'</label></span> ';
2395: }
1.101 raeburn 2396: } else {
2397: my $checked = 'checked="checked" ';
1.160.6.118.2 10(raebu 2398:22): if ($item eq 'timezone') {
2399:22): $checked = '';
2400:22): }
1.101 raeburn 2401: if (ref($settings) eq 'HASH') {
2402: if (ref($settings->{$item}) eq 'HASH') {
1.160.6.118.2 10(raebu 2403:22): if (!$settings->{$item}->{$type}) {
1.101 raeburn 2404: $checked = '';
2405: } elsif ($settings->{$item}->{$type} == 1) {
2406: $checked = 'checked="checked" ';
2407: }
1.78 raeburn 2408: }
1.72 raeburn 2409: }
1.101 raeburn 2410: $datatable .= '<span class="LC_nobreak"><label>'.
2411: '<input type="checkbox" name="'.$context.'_'.$item.
2412: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2413: '</label></span> ';
1.72 raeburn 2414: }
1.101 raeburn 2415: }
2416: if ($context eq 'requestcourses') {
2417: $datatable .= '</tr><tr>';
2418: foreach my $item (@usertools) {
1.106 raeburn 2419: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2420: }
2421: $datatable .= '</tr></table>';
1.72 raeburn 2422: }
1.86 raeburn 2423: $datatable .= '</td>';
1.160.6.5 raeburn 2424: unless (($context eq 'requestcourses') ||
2425: ($context eq 'requestauthor')) {
1.86 raeburn 2426: $datatable .=
1.160.6.20 raeburn 2427: '<td class="LC_right_item">'.
2428: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.3 raeburn 2429: '<input type="text" name="quota_'.$type.
1.72 raeburn 2430: '" value="'.$currdefquota.
1.160.6.20 raeburn 2431: '" size="5" /></span>'.(' ' x 2).
2432: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2433: '<input type="text" name="authorquota_'.$type.
2434: '" value="'.$currauthorquota.
2435: '" size="5" /></span></td>';
1.86 raeburn 2436: }
2437: $datatable .= '</tr>';
1.3 raeburn 2438: }
2439: }
2440: }
1.160.6.5 raeburn 2441: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2442: $defaultquota = '20';
1.160.6.20 raeburn 2443: $authorquota = '500';
1.86 raeburn 2444: if (ref($settings) eq 'HASH') {
2445: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2446: $defaultquota = $settings->{'defaultquota'}->{'default'};
2447: } elsif (defined($settings->{'default'})) {
2448: $defaultquota = $settings->{'default'};
2449: }
1.160.6.20 raeburn 2450: if (ref($settings->{'authorquota'}) eq 'HASH') {
2451: $authorquota = $settings->{'authorquota'}->{'default'};
2452: }
1.3 raeburn 2453: }
2454: }
2455: $typecount ++;
2456: $css_class = $typecount%2?' class="LC_odd_row"':'';
2457: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2458: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2459: '<td class="LC_left_item">';
1.101 raeburn 2460: if ($context eq 'requestcourses') {
2461: $datatable .= '<table><tr>';
2462: }
2463: my %defcell;
1.72 raeburn 2464: foreach my $item (@usertools) {
1.101 raeburn 2465: if ($context eq 'requestcourses') {
2466: my ($curroption,$currlimit);
2467: if (ref($settings) eq 'HASH') {
2468: if (ref($settings->{$item}) eq 'HASH') {
2469: $curroption = $settings->{$item}->{'default'};
2470: if ($curroption =~ /^autolimit=(\d*)$/) {
2471: $currlimit = $1;
2472: }
2473: }
2474: }
2475: if (!$curroption) {
2476: $curroption = 'norequest';
2477: }
2478: $datatable .= '<th>'.$titles{$item}.'</th>';
2479: foreach my $option (@options) {
2480: my $val = $option;
2481: if ($option eq 'norequest') {
2482: $val = 0;
2483: }
2484: if ($option eq 'validate') {
2485: my $canvalidate = 0;
2486: if (ref($validations{$item}) eq 'HASH') {
2487: if ($validations{$item}{'default'}) {
2488: $canvalidate = 1;
2489: }
2490: }
2491: next if (!$canvalidate);
2492: }
2493: my $checked = '';
2494: if ($option eq $curroption) {
2495: $checked = ' checked="checked"';
2496: } elsif ($option eq 'autolimit') {
2497: if ($curroption =~ /^autolimit/) {
2498: $checked = ' checked="checked"';
2499: }
2500: }
2501: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2502: '<input type="radio" name="crsreq_'.$item.
2503: '_default" value="'.$val.'"'.$checked.' />'.
2504: $titles{$option}.'</label>';
2505: if ($option eq 'autolimit') {
1.127 raeburn 2506: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2507: $item.'_limit_default" size="1" '.
2508: 'value="'.$currlimit.'" />';
2509: }
1.127 raeburn 2510: $defcell{$item} .= '</span> ';
1.104 raeburn 2511: if ($option eq 'autolimit') {
1.127 raeburn 2512: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2513: }
1.101 raeburn 2514: }
1.160.6.5 raeburn 2515: } elsif ($context eq 'requestauthor') {
2516: my $curroption;
2517: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2518: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2519: }
2520: if (!$curroption) {
2521: $curroption = 'norequest';
2522: }
2523: foreach my $option (@options) {
2524: my $val = $option;
2525: if ($option eq 'norequest') {
2526: $val = 0;
2527: }
2528: my $checked = '';
2529: if ($option eq $curroption) {
2530: $checked = ' checked="checked"';
2531: }
2532: $datatable .= '<span class="LC_nobreak"><label>'.
2533: '<input type="radio" name="authorreq_default"'.
2534: ' value="'.$val.'"'.$checked.' />'.
2535: $titles{$option}.'</label></span> ';
2536: }
1.101 raeburn 2537: } else {
2538: my $checked = 'checked="checked" ';
2539: if (ref($settings) eq 'HASH') {
2540: if (ref($settings->{$item}) eq 'HASH') {
2541: if ($settings->{$item}->{'default'} == 0) {
2542: $checked = '';
2543: } elsif ($settings->{$item}->{'default'} == 1) {
2544: $checked = 'checked="checked" ';
2545: }
1.78 raeburn 2546: }
1.72 raeburn 2547: }
1.101 raeburn 2548: $datatable .= '<span class="LC_nobreak"><label>'.
2549: '<input type="checkbox" name="'.$context.'_'.$item.
2550: '" value="default" '.$checked.'/>'.$titles{$item}.
2551: '</label></span> ';
2552: }
2553: }
2554: if ($context eq 'requestcourses') {
2555: $datatable .= '</tr><tr>';
2556: foreach my $item (@usertools) {
1.106 raeburn 2557: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2558: }
1.101 raeburn 2559: $datatable .= '</tr></table>';
1.72 raeburn 2560: }
1.86 raeburn 2561: $datatable .= '</td>';
1.160.6.5 raeburn 2562: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2563: $datatable .= '<td class="LC_right_item">'.
2564: '<span class="LC_nobreak">'.&mt('Portfolio').': '.
1.86 raeburn 2565: '<input type="text" name="defaultquota" value="'.
1.160.6.20 raeburn 2566: $defaultquota.'" size="5" /></span>'.(' ' x2).
2567: '<span class="LC_nobreak">'.&mt('Authoring').': '.
2568: '<input type="text" name="authorquota" value="'.
2569: $authorquota.'" size="5" /></span></td>';
1.86 raeburn 2570: }
2571: $datatable .= '</tr>';
1.72 raeburn 2572: $typecount ++;
2573: $css_class = $typecount%2?' class="LC_odd_row"':'';
2574: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2575: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2576: if ($context eq 'requestcourses') {
1.109 raeburn 2577: $datatable .= &mt('(overrides affiliation, if set)').
2578: '</td>'.
2579: '<td class="LC_left_item">'.
2580: '<table><tr>';
1.101 raeburn 2581: } else {
1.109 raeburn 2582: $datatable .= &mt('(overrides affiliation, if checked)').
2583: '</td>'.
2584: '<td class="LC_left_item" colspan="2">'.
2585: '<br />';
1.101 raeburn 2586: }
2587: my %advcell;
1.72 raeburn 2588: foreach my $item (@usertools) {
1.101 raeburn 2589: if ($context eq 'requestcourses') {
2590: my ($curroption,$currlimit);
2591: if (ref($settings) eq 'HASH') {
2592: if (ref($settings->{$item}) eq 'HASH') {
2593: $curroption = $settings->{$item}->{'_LC_adv'};
2594: if ($curroption =~ /^autolimit=(\d*)$/) {
2595: $currlimit = $1;
2596: }
2597: }
2598: }
2599: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2600: my $checked = '';
2601: if ($curroption eq '') {
2602: $checked = ' checked="checked"';
2603: }
2604: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2605: '<input type="radio" name="crsreq_'.$item.
2606: '__LC_adv" value=""'.$checked.' />'.
2607: &mt('No override set').'</label></span> ';
1.101 raeburn 2608: foreach my $option (@options) {
2609: my $val = $option;
2610: if ($option eq 'norequest') {
2611: $val = 0;
2612: }
2613: if ($option eq 'validate') {
2614: my $canvalidate = 0;
2615: if (ref($validations{$item}) eq 'HASH') {
2616: if ($validations{$item}{'_LC_adv'}) {
2617: $canvalidate = 1;
2618: }
2619: }
2620: next if (!$canvalidate);
2621: }
2622: my $checked = '';
1.104 raeburn 2623: if ($val eq $curroption) {
1.101 raeburn 2624: $checked = ' checked="checked"';
2625: } elsif ($option eq 'autolimit') {
2626: if ($curroption =~ /^autolimit/) {
2627: $checked = ' checked="checked"';
2628: }
2629: }
2630: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2631: '<input type="radio" name="crsreq_'.$item.
2632: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2633: $titles{$option}.'</label>';
2634: if ($option eq 'autolimit') {
1.127 raeburn 2635: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2636: $item.'_limit__LC_adv" size="1" '.
2637: 'value="'.$currlimit.'" />';
2638: }
1.127 raeburn 2639: $advcell{$item} .= '</span> ';
1.104 raeburn 2640: if ($option eq 'autolimit') {
1.127 raeburn 2641: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2642: }
1.101 raeburn 2643: }
1.160.6.5 raeburn 2644: } elsif ($context eq 'requestauthor') {
2645: my $curroption;
2646: if (ref($settings) eq 'HASH') {
2647: $curroption = $settings->{'_LC_adv'};
2648: }
2649: my $checked = '';
2650: if ($curroption eq '') {
2651: $checked = ' checked="checked"';
2652: }
2653: $datatable .= '<span class="LC_nobreak"><label>'.
2654: '<input type="radio" name="authorreq__LC_adv"'.
2655: ' value=""'.$checked.' />'.
2656: &mt('No override set').'</label></span> ';
2657: foreach my $option (@options) {
2658: my $val = $option;
2659: if ($option eq 'norequest') {
2660: $val = 0;
2661: }
2662: my $checked = '';
2663: if ($val eq $curroption) {
2664: $checked = ' checked="checked"';
2665: }
2666: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2667: '<input type="radio" name="authorreq__LC_adv"'.
2668: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2669: $titles{$option}.'</label></span> ';
2670: }
1.101 raeburn 2671: } else {
2672: my $checked = 'checked="checked" ';
2673: if (ref($settings) eq 'HASH') {
2674: if (ref($settings->{$item}) eq 'HASH') {
2675: if ($settings->{$item}->{'_LC_adv'} == 0) {
2676: $checked = '';
2677: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2678: $checked = 'checked="checked" ';
2679: }
1.79 raeburn 2680: }
1.72 raeburn 2681: }
1.101 raeburn 2682: $datatable .= '<span class="LC_nobreak"><label>'.
2683: '<input type="checkbox" name="'.$context.'_'.$item.
2684: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2685: '</label></span> ';
2686: }
2687: }
2688: if ($context eq 'requestcourses') {
2689: $datatable .= '</tr><tr>';
2690: foreach my $item (@usertools) {
1.106 raeburn 2691: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2692: }
1.101 raeburn 2693: $datatable .= '</tr></table>';
1.72 raeburn 2694: }
1.98 raeburn 2695: $datatable .= '</td></tr>';
1.30 raeburn 2696: $$rowtotal += $typecount;
1.3 raeburn 2697: return $datatable;
2698: }
2699:
1.160.6.5 raeburn 2700: sub print_requestmail {
1.160.6.93 raeburn 2701: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2702: my ($now,$datatable,%currapp);
1.102 raeburn 2703: $now = time;
2704: if (ref($settings) eq 'HASH') {
2705: if (ref($settings->{'notify'}) eq 'HASH') {
2706: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2707: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2708: }
2709: }
2710: }
1.160.6.16 raeburn 2711: my $numinrow = 2;
1.160.6.34 raeburn 2712: my $css_class;
1.160.6.93 raeburn 2713: if ($$rowtotal%2) {
2714: $css_class = 'LC_odd_row';
2715: }
2716: if ($customcss) {
2717: $css_class .= " $customcss";
2718: }
2719: $css_class =~ s/^\s+//;
2720: if ($css_class) {
2721: $css_class = ' class="'.$css_class.'"';
2722: }
2723: if ($rowstyle) {
2724: $css_class .= ' style="'.$rowstyle.'"';
2725: }
1.160.6.5 raeburn 2726: my $text;
2727: if ($action eq 'requestcourses') {
2728: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2729: } elsif ($action eq 'requestauthor') {
2730: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2731: } else {
1.160.6.34 raeburn 2732: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2733: }
1.160.6.34 raeburn 2734: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2735: ' <td>'.$text.'</td>'.
1.102 raeburn 2736: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2737: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2738: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2739: if ($numdc > 0) {
2740: $datatable .= $table;
1.102 raeburn 2741: } else {
2742: $datatable .= &mt('There are no active Domain Coordinators');
2743: }
2744: $datatable .='</td></tr>';
2745: return $datatable;
2746: }
2747:
1.160.6.30 raeburn 2748: sub print_studentcode {
2749: my ($settings,$rowtotal) = @_;
2750: my $rownum = 0;
2751: my ($output,%current);
1.160.6.118.2 14(raebu 2752:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.51 raeburn 2753: if (ref($settings) eq 'HASH') {
2754: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2755: foreach my $type (@crstypes) {
2756: $current{$type} = $settings->{'uniquecode'}{$type};
2757: }
1.160.6.30 raeburn 2758: }
2759: }
2760: $output .= '<tr>'.
2761: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2762: '<td class="LC_left_item">';
2763: foreach my $type (@crstypes) {
2764: my $check = ' ';
2765: if ($current{$type}) {
2766: $check = ' checked="checked" ';
2767: }
2768: $output .= '<span class="LC_nobreak"><label>'.
2769: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2770: &mt($type).'</label></span>'.(' 'x2).' ';
2771: }
2772: $output .= '</td></tr>';
2773: $$rowtotal ++;
2774: return $output;
2775: }
2776:
2777: sub print_textbookcourses {
1.160.6.46 raeburn 2778: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2779: my $rownum = 0;
2780: my $css_class;
2781: my $itemcount = 1;
2782: my $maxnum = 0;
2783: my $bookshash;
2784: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2785: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2786: }
2787: my %ordered;
2788: if (ref($bookshash) eq 'HASH') {
2789: foreach my $item (keys(%{$bookshash})) {
2790: if (ref($bookshash->{$item}) eq 'HASH') {
2791: my $num = $bookshash->{$item}{'order'};
2792: $ordered{$num} = $item;
2793: }
2794: }
2795: }
2796: my $confname = $dom.'-domainconfig';
2797: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2798: my $maxnum = scalar(keys(%ordered));
2799: my $datatable;
1.160.6.30 raeburn 2800: if (keys(%ordered)) {
2801: my @items = sort { $a <=> $b } keys(%ordered);
2802: for (my $i=0; $i<@items; $i++) {
2803: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2804: my $key = $ordered{$items[$i]};
2805: my %coursehash=&Apache::lonnet::coursedescription($key);
2806: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2807: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2808: if (ref($bookshash->{$key}) eq 'HASH') {
2809: $subject = $bookshash->{$key}->{'subject'};
2810: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2811: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2812: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2813: $author = $bookshash->{$key}->{'author'};
2814: $image = $bookshash->{$key}->{'image'};
2815: if ($image ne '') {
2816: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2817: my $imagethumb = "$path/tn-".$imagefile;
2818: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2819: }
1.160.6.30 raeburn 2820: }
2821: }
1.160.6.46 raeburn 2822: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2823: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2824: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2825: for (my $k=0; $k<=$maxnum; $k++) {
2826: my $vpos = $k+1;
2827: my $selstr;
2828: if ($k == $i) {
2829: $selstr = ' selected="selected" ';
2830: }
2831: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2832: }
2833: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2834: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2835: &mt('Delete?').'</label></span></td>'.
2836: '<td colspan="2">'.
1.160.6.46 raeburn 2837: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2838: (' 'x2).
1.160.6.46 raeburn 2839: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2840: if ($type eq 'textbooks') {
2841: $datatable .= (' 'x2).
1.160.6.47 raeburn 2842: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2843: (' 'x2).
1.160.6.46 raeburn 2844: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2845: (' 'x2).
2846: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2847: if ($image) {
1.160.6.114 raeburn 2848: $datatable .= $imgsrc.
1.160.6.46 raeburn 2849: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2850: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2851: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2852: }
2853: if ($switchserver) {
2854: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2855: } else {
2856: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2857: }
1.160.6.30 raeburn 2858: }
1.160.6.46 raeburn 2859: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2860: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2861: $coursetitle.'</span></td></tr>'."\n";
2862: $itemcount ++;
2863: }
2864: }
2865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2866: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2867: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2868: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2869: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2870: for (my $k=0; $k<$maxnum+1; $k++) {
2871: my $vpos = $k+1;
2872: my $selstr;
2873: if ($k == $maxnum) {
2874: $selstr = ' selected="selected" ';
2875: }
2876: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2877: }
2878: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2879: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2880: '<td colspan="2">'.
1.160.6.46 raeburn 2881: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2882: (' 'x2).
1.160.6.46 raeburn 2883: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2884: (' 'x2);
2885: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2886: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2887: (' 'x2).
2888: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2889: (' 'x2).
2890: '<span class="LC_nobreak">'.&mt('Image:').' ';
2891: if ($switchserver) {
2892: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2893: } else {
2894: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2895: }
1.160.6.87 raeburn 2896: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2897: }
1.160.6.87 raeburn 2898: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2899: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2900: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2901: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2902: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2903: '</span></td>'."\n".
2904: '</tr>'."\n";
2905: $itemcount ++;
2906: return $datatable;
2907: }
2908:
2909: sub textbookcourses_javascript {
1.160.6.46 raeburn 2910: my ($settings) = @_;
2911: return unless(ref($settings) eq 'HASH');
2912: my (%ordered,%total,%jstext);
2913: foreach my $type ('textbooks','templates') {
2914: $total{$type} = 0;
2915: if (ref($settings->{$type}) eq 'HASH') {
2916: foreach my $item (keys(%{$settings->{$type}})) {
2917: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2918: my $num = $settings->{$type}->{$item}{'order'};
2919: $ordered{$type}{$num} = $item;
2920: }
2921: }
2922: $total{$type} = scalar(keys(%{$settings->{$type}}));
2923: }
2924: my @jsarray = ();
2925: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2926: push(@jsarray,$ordered{$type}{$item});
2927: }
2928: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2929: }
2930: return <<"ENDSCRIPT";
2931: <script type="text/javascript">
2932: // <![CDATA[
1.160.6.46 raeburn 2933: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2934: var changedVal;
1.160.6.46 raeburn 2935: $jstext{'textbooks'};
2936: $jstext{'templates'};
2937: var newpos;
2938: var maxh;
2939: if (caller == 'textbooks') {
2940: newpos = 'textbooks_addbook_pos';
2941: maxh = 1 + $total{'textbooks'};
2942: } else {
2943: newpos = 'templates_addbook_pos';
2944: maxh = 1 + $total{'templates'};
2945: }
1.160.6.30 raeburn 2946: var current = new Array;
2947: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2948: if (item == newpos) {
2949: changedVal = newitemVal;
2950: } else {
2951: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2952: current[newitemVal] = newpos;
2953: }
1.160.6.46 raeburn 2954: if (caller == 'textbooks') {
2955: for (var i=0; i<textbooks.length; i++) {
2956: var elementName = 'textbooks_'+textbooks[i];
2957: if (elementName != item) {
2958: if (form.elements[elementName]) {
2959: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2960: current[currVal] = elementName;
2961: }
2962: }
2963: }
2964: }
2965: if (caller == 'templates') {
2966: for (var i=0; i<templates.length; i++) {
2967: var elementName = 'templates_'+templates[i];
2968: if (elementName != item) {
2969: if (form.elements[elementName]) {
2970: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2971: current[currVal] = elementName;
2972: }
1.160.6.30 raeburn 2973: }
2974: }
2975: }
2976: var oldVal;
2977: for (var j=0; j<maxh; j++) {
2978: if (current[j] == undefined) {
2979: oldVal = j;
2980: }
2981: }
2982: if (oldVal < changedVal) {
2983: for (var k=oldVal+1; k<=changedVal ; k++) {
2984: var elementName = current[k];
2985: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2986: }
2987: } else {
2988: for (var k=changedVal; k<oldVal; k++) {
2989: var elementName = current[k];
2990: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2991: }
2992: }
2993: return;
2994: }
2995:
2996: // ]]>
2997: </script>
2998:
2999: ENDSCRIPT
3000: }
3001:
1.160.6.118.2 1(raebur 3002:1): sub ltitools_javascript {
3003:1): my ($settings) = @_;
3004:1): my $togglejs = <itools_toggle_js();
3005:1): unless (ref($settings) eq 'HASH') {
3006:1): return $togglejs;
3007:1): }
3008:1): my (%ordered,$total,%jstext);
3009:1): $total = 0;
3010:1): foreach my $item (keys(%{$settings})) {
3011:1): if (ref($settings->{$item}) eq 'HASH') {
3012:1): my $num = $settings->{$item}{'order'};
3013:1): $ordered{$num} = $item;
3014:1): }
3015:1): }
3016:1): $total = scalar(keys(%{$settings}));
3017:1): my @jsarray = ();
3018:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3019:1): push(@jsarray,$ordered{$item});
3020:1): }
3021:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3022:1): return <<"ENDSCRIPT";
3023:1): <script type="text/javascript">
3024:1): // <![CDATA[
3025:1): function reorderLTITools(form,item) {
3026:1): var changedVal;
3027:1): $jstext
3028:1): var newpos = 'ltitools_add_pos';
3029:1): var maxh = 1 + $total;
3030:1): var current = new Array;
3031:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3032:1): if (item == newpos) {
3033:1): changedVal = newitemVal;
3034:1): } else {
3035:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3036:1): current[newitemVal] = newpos;
3037:1): }
3038:1): for (var i=0; i<ltitools.length; i++) {
3039:1): var elementName = 'ltitools_'+ltitools[i];
3040:1): if (elementName != item) {
3041:1): if (form.elements[elementName]) {
3042:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3043:1): current[currVal] = elementName;
3044:1): }
3045:1): }
3046:1): }
3047:1): var oldVal;
3048:1): for (var j=0; j<maxh; j++) {
3049:1): if (current[j] == undefined) {
3050:1): oldVal = j;
3051:1): }
3052:1): }
3053:1): if (oldVal < changedVal) {
3054:1): for (var k=oldVal+1; k<=changedVal ; k++) {
3055:1): var elementName = current[k];
3056:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3057:1): }
3058:1): } else {
3059:1): for (var k=changedVal; k<oldVal; k++) {
3060:1): var elementName = current[k];
3061:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3062:1): }
3063:1): }
3064:1): return;
3065:1): }
3066:1):
3067:1): // ]]>
3068:1): </script>
3069:1):
3070:1): $togglejs
3071:1):
3072:1): ENDSCRIPT
3073:1): }
3074:1):
3075:1): sub ltitools_toggle_js {
3076:1): return <<"ENDSCRIPT";
3077:1): <script type="text/javascript">
3078:1): // <![CDATA[
3079:1):
3080:1): function toggleLTITools(form,setting,item) {
3081:1): var radioname = '';
3082:1): var divid = '';
14(raebu 3083:23): if ((setting == 'passback') || (setting == 'roster')) {
3084:23): radioname = 'ltitools_'+setting+'_'+item;
3085:23): divid = 'ltitools_'+setting+'time_'+item;
3086:23): var num = form.elements[radioname].length;
3087:23): if (num) {
3088:23): var setvis = '';
3089:23): for (var i=0; i<num; i++) {
3090:23): if (form.elements[radioname][i].checked) {
3091:23): if (form.elements[radioname][i].value == '1') {
3092:23): if (document.getElementById(divid)) {
3093:23): document.getElementById(divid).style.display = 'inline-block';
3094:23): }
3095:23): setvis = 1;
3096:23): }
3097:23): break;
3098:23): }
3099:23): }
3100:23): }
3101:23): if (!setvis) {
3102:23): if (document.getElementById(divid)) {
3103:23): document.getElementById(divid).style.display = 'none';
3104:23): }
3105:23): }
3106:23): }
1(raebur 3107:1): if (setting == 'user') {
3108:1): divid = 'ltitools_'+setting+'_div_'+item;
3109:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3110:1): if (document.getElementById(divid)) {
3111:1): if (document.getElementById(checkid)) {
3112:1): if (document.getElementById(checkid).checked) {
3113:1): document.getElementById(divid).style.display = 'inline-block';
3114:1): } else {
3115:1): document.getElementById(divid).style.display = 'none';
3116:1): }
3117:1): }
3118:1): }
3119:1): }
3120:1): return;
3121:1): }
3122:1): // ]]>
3123:1): </script>
3124:1):
3125:1): ENDSCRIPT
3126:1): }
3127:1):
1.160.6.113 raeburn 3128: sub wafproxy_javascript {
3129: my ($dom) = @_;
3130: return <<"ENDSCRIPT";
3131: <script type="text/javascript">
3132: // <![CDATA[
3133: function updateWAF() {
3134: if (document.getElementById('wafproxy_remoteip')) {
3135: var wafremote = 0;
3136: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3137: wafremote = 1;
3138: }
3139: var fields = new Array('header','trust');
3140: for (var i=0; i<fields.length; i++) {
3141: if (document.getElementById('wafproxy_'+fields[i])) {
3142: if (wafremote == 1) {
3143: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3144: }
3145: else {
3146: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3147: }
3148: }
3149: }
3150: if (document.getElementById('wafproxyranges_$dom')) {
3151: if (wafremote == 1) {
3152: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3153: } else {
3154: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3155: if (document.display.wafproxy_vpnaccess[i].checked) {
3156: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3157: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3158: }
3159: }
3160: }
3161: }
3162: }
3163: }
3164: return;
3165: }
3166:
3167: function checkWAF() {
3168: if (document.getElementById('wafproxy_remoteip')) {
3169: var wafvpn = 0;
3170: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3171: if (document.display.wafproxy_vpnaccess[i].checked) {
3172: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3173: wafvpn = 1;
3174: }
3175: break;
3176: }
3177: }
3178: var vpn = new Array('vpnint','vpnext');
3179: for (var i=0; i<vpn.length; i++) {
3180: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3181: if (wafvpn == 1) {
3182: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3183: }
3184: else {
3185: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3186: }
3187: }
3188: }
3189: if (document.getElementById('wafproxyranges_$dom')) {
3190: if (wafvpn == 1) {
3191: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3192: }
3193: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3194: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3195: }
3196: }
3197: }
3198: return;
3199: }
3200:
3201: function toggleWAF() {
3202: if (document.getElementById('wafproxy_table')) {
3203: var wafproxy = 0;
3204: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3205: if (document.display.wafproxy_${dom}[i].checked) {
3206: if (document.display.wafproxy_${dom}[i].value == 1) {
3207: wafproxy = 1;
3208: break;
3209: }
3210: }
3211: }
3212: if (wafproxy == 1) {
3213: document.getElementById('wafproxy_table').style.display='inline';
3214: }
3215: else {
3216: document.getElementById('wafproxy_table').style.display='none';
3217: }
3218: if (document.getElementById('wafproxyrow_${dom}')) {
3219: if (wafproxy == 1) {
3220: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3221: }
3222: else {
3223: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3224: }
3225: }
3226: if (document.getElementById('nowafproxyrow_$dom')) {
3227: if (wafproxy == 1) {
3228: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3229: }
3230: else {
3231: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3232: }
3233: }
3234: }
3235: return;
3236: }
3237: // ]]>
3238: </script>
3239:
3240: ENDSCRIPT
3241: }
3242:
1.160.6.118.2 5(raebur 3243:2): sub lti_javascript {
3244:2): my ($dom,$settings) = @_;
3245:2): my $togglejs = <i_toggle_js($dom);
3246:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
14(raebu 3247:23): unless (ref($settings) eq 'HASH') {
3248:23): return $togglejs.'
3249:23): <script type="text/javascript">
3250:23): // <![CDATA[
3251:23):
3252:23): '.$linkprot_js.'
3253:23):
3254:23): // ]]>
3255:23): </script>
3256:23): ';
3257:23): }
3258:23): my (%ordered,$total,%jstext);
3259:23): $total = scalar(keys(%{$settings}));
3260:23): foreach my $item (keys(%{$settings})) {
3261:23): if (ref($settings->{$item}) eq 'HASH') {
3262:23): my $num = $settings->{$item}{'order'};
3263:23): if ($num eq '') {
3264:23): $num = $total - 1;
3265:23): }
3266:23): $ordered{$num} = $item;
3267:23): }
3268:23): }
3269:23): my @jsarray = ();
3270:23): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3271:23): push(@jsarray,$ordered{$item});
3272:23): }
3273:23): my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
5(raebur 3274:2): return <<"ENDSCRIPT";
3275:2): <script type="text/javascript">
3276:2): // <![CDATA[
14(raebu 3277:23): function reorderLTI(form,item) {
3278:23): var changedVal;
3279:23): $jstext
3280:23): var newpos = 'lti_pos_add';
3281:23): var maxh = 1 + $total;
3282:23): var current = new Array;
3283:23): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3284:23): if (item == newpos) {
3285:23): changedVal = newitemVal;
3286:23): } else {
3287:23): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3288:23): current[newitemVal] = newpos;
3289:23): }
3290:23): for (var i=0; i<lti.length; i++) {
3291:23): var elementName = 'lti_pos_'+lti[i];
3292:23): if (elementName != item) {
3293:23): if (form.elements[elementName]) {
3294:23): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3295:23): current[currVal] = elementName;
3296:23): }
3297:23): }
3298:23): }
3299:23): var oldVal;
3300:23): for (var j=0; j<maxh; j++) {
3301:23): if (current[j] == undefined) {
3302:23): oldVal = j;
3303:23): }
3304:23): }
3305:23): if (oldVal < changedVal) {
3306:23): for (var k=oldVal+1; k<=changedVal ; k++) {
3307:23): var elementName = current[k];
3308:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3309:23): }
3310:23): } else {
3311:23): for (var k=changedVal; k<oldVal; k++) {
3312:23): var elementName = current[k];
3313:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3314:23): }
3315:23): }
3316:23): return;
3317:23): }
5(raebur 3318:2):
3319:2): $linkprot_js
3320:2):
3321:2): // ]]>
3322:2): </script>
3323:2):
3324:2): $togglejs
3325:2):
3326:2): ENDSCRIPT
3327:2): }
3328:2):
3329:2): sub lti_toggle_js {
3330:2): my ($dom) = @_;
14(raebu 3331:23): my %lcauthparmtext = &Apache::lonlocal::texthash (
3332:23): localauth => 'Local auth argument',
3333:23): krb => 'Kerberos domain',
3334:23): );
3335: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");
3336:23): &js_escape(\$crsincalert);
5(raebur 3337:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3338:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3339:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3340:2): return <<"ENDSCRIPT";
3341:2): <script type="text/javascript">
3342:2): // <![CDATA[
14(raebu 3343:23):
3344:23): function toggleLTI(form,setting,item) {
3345:23): if ((setting == 'requser') || (setting == 'crsinc')) {
3346:23): var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3347:23): var setvis = '';
3348:23): var radioname = 'lti_requser_'+item;
3349:23): var num = form.elements[radioname].length;
3350:23): if (num) {
3351:23): for (var i=0; i<num; i++) {
3352:23): if (form.elements[radioname][i].checked) {
3353:23): if (form.elements[radioname][i].value == '1') {
3354:23): setvis = 1;
3355:23): break;
5(raebur 3356:2): }
14(raebu 3357:23): }
3358:23): }
3359:23): }
3360:23): if (usrfieldsets.length) {
3361:23): for (var j=0; j<usrfieldsets.length; j++) {
3362:23): if (setvis) {
3363:23): usrfieldsets[j].style.display = 'block';
3364:23): } else {
3365:23): usrfieldsets[j].style.display = 'none';
3366:23): }
3367:23): }
3368:23): }
3369:23): var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3370:23): if (crsfieldsets.length) {
3371:23): radioname = 'lti_crsinc_'+item;
3372:23): var num = form.elements[radioname].length;
3373:23): if (num) {
3374:23): var crsvis = '';
3375:23): for (var i=0; i<num; i++) {
3376:23): if (form.elements[radioname][i].checked) {
3377:23): if (form.elements[radioname][i].value == '1') {
3378:23): if (setvis == '') {
3379:23): if (setting == 'crsinc'){
3380:23): alert("$crsincalert");
3381:23): form.elements[radioname][0].checked = true;
3382:23): }
3383:23): } else {
3384:23): crsvis = 1;
5(raebur 3385:2): }
14(raebu 3386:23): break;
5(raebur 3387:2): }
3388:2): }
3389:2): }
14(raebu 3390:23): setvis = crsvis;
5(raebur 3391:2): }
14(raebu 3392:23): for (var j=0; j<crsfieldsets.length; j++) {
3393:23): if (setvis) {
3394:23): crsfieldsets[j].style.display = 'block';
3395:23): } else {
3396:23): crsfieldsets[j].style.display = 'none';
5(raebur 3397:2): }
3398:2): }
3399:2): }
14(raebu 3400:23): } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
3401:23): var radioname = '';
3402:23): var divid = '';
3403:23): if (setting == 'user') {
3404:23): radioname = 'lti_mapuser_'+item;
3405:23): divid = 'lti_userfield_'+item;
3406:23): } else if (setting == 'crs') {
3407:23): radioname = 'lti_mapcrs_'+item;
3408:23): divid = 'lti_crsfield_'+item;
3409:23): } else if (setting == 'callback') {
3410:23): radioname = 'lti_callback_'+item;
3411:23): divid = 'lti_callbackfield_'+item;
3412:23): } else {
3413:23): radioname = 'lti_passback_'+item;
3414:23): divid = 'lti_passback_'+item;
3415:23): }
3416:23): var num = form.elements[radioname].length;
3417:23): if (num) {
3418:23): var setvis = '';
3419:23): for (var i=0; i<num; i++) {
3420:23): if (form.elements[radioname][i].checked) {
3421:23): if ((setting == 'passback') || (setting == 'callback')) {
3422:23): if (form.elements[radioname][i].value == '1') {
3423:23): if (document.getElementById(divid)) {
3424:23): document.getElementById(divid).style.display = 'inline-block';
3425:23): }
3426:23): setvis = 1;
3427:23): break;
3428:23): }
3429:23): } else {
3430:23): if (form.elements[radioname][i].value == 'other') {
3431:23): if (document.getElementById(divid)) {
3432:23): document.getElementById(divid).style.display = 'inline-block';
3433:23): }
3434:23): setvis = 1;
3435:23): break;
3436:23): }
3437:23): }
3438:23): }
3439:23): }
3440:23): if (!setvis) {
3441:23): if (document.getElementById(divid)) {
3442:23): document.getElementById(divid).style.display = 'none';
3443:23): }
5(raebur 3444:2): }
3445:2): }
14(raebu 3446:23): } else if ((setting == 'sec') || (setting == 'secsrc')) {
3447:23): var numsec = form.elements['lti_crssec_'+item].length;
3448:23): if (numsec) {
3449:23): var setvis = '';
3450:23): for (var i=0; i<numsec; i++) {
3451:23): if (form.elements['lti_crssec_'+item][i].checked) {
3452:23): if (form.elements['lti_crssec_'+item][i].value == '1') {
3453:23): if (document.getElementById('lti_crssecfield_'+item)) {
3454:23): document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3455:23): setvis = 1;
3456:23): var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3457:23): if (numsrcsec) {
3458:23): var setsrcvis = '';
3459:23): for (var j=0; j<numsrcsec; j++) {
3460:23): if (form.elements['lti_crssecsrc_'+item][j].checked) {
3461:23): if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3462:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3463:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3464:23): setsrcvis = 1;
3465:23): }
3466:23): }
3467:23): }
3468:23): }
3469:23): if (!setsrcvis) {
3470:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3471:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3472:23): }
3473:23): }
3474:23): }
3475:23): }
3476:23): }
3477:23): }
3478:23): }
3479:23): if (!setvis) {
3480:23): if (document.getElementById('lti_crssecfield_'+item)) {
3481:23): document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3482:23): }
3483:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3484:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3485:23): }
3486:23): }
5(raebur 3487:2): }
14(raebu 3488:23): } else if (setting == 'lcauth') {
3489:23): var numauth = form.elements['lti_lcauth_'+item].length;
3490:23): if (numauth) {
3491:23): for (var i=0; i<numauth; i++) {
3492:23): if (form.elements['lti_lcauth_'+item][i].checked) {
3493:23): if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3494:23): if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3495:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3496:23): } else {
3497:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3498:23): if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3499:23): if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3500:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3501:23): } else {
3502:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3503:23): }
3504:23): }
3505:23): }
3506:23): }
5(raebur 3507:2): }
3508:2): }
3509:2): }
14(raebu 3510:23): } else if (setting == 'lcmenu') {
3511:23): var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3512:23): var divid = 'lti_menufield_'+item;
3513:23): var setvis = '';
3514:23): for (var i=0; i<menus.length; i++) {
3515:23): var radioname = menus[i];
3516:23): var num = form.elements[radioname].length;
3517:23): if (num) {
3518:23): for (var j=0; j<num; j++) {
3519:23): if (form.elements[radioname][j].checked) {
3520:23): if (form.elements[radioname][j].value == '1') {
3521:23): if (document.getElementById(divid)) {
3522:23): document.getElementById(divid).style.display = 'inline-block';
3523:23): }
5(raebur 3524:2): setvis = 1;
14(raebu 3525:23): break;
5(raebur 3526:2): }
3527:2): }
3528:2): }
14(raebu 3529:23): }
3530:23): if (setvis == 1) {
3531:23): break;
3532:23): }
3533:23): }
3534:23): if (!setvis) {
3535:23): if (document.getElementById(divid)) {
3536:23): document.getElementById(divid).style.display = 'none';
5(raebur 3537:2): }
3538:2): }
3539:2): }
14(raebu 3540:23): return;
5(raebur 3541:2): }
3542:2):
3543:2): // ]]>
3544:2): </script>
3545:2):
3546:2): ENDSCRIPT
3547:2): }
3548:2):
1.160.6.113 raeburn 3549: sub autoupdate_javascript {
3550: return <<"ENDSCRIPT";
3551: <script type="text/javascript">
3552: // <![CDATA[
3553: function toggleLastActiveDays(form) {
3554: var radioname = 'lastactive';
3555: var divid = 'lastactive_div';
3556: var num = form.elements[radioname].length;
3557: if (num) {
3558: var setvis = '';
3559: for (var i=0; i<num; i++) {
3560: if (form.elements[radioname][i].checked) {
3561: if (form.elements[radioname][i].value == '1') {
3562: if (document.getElementById(divid)) {
3563: document.getElementById(divid).style.display = 'inline-block';
3564: }
3565: setvis = 1;
3566: }
3567: break;
3568: }
3569: }
3570: if (!setvis) {
3571: if (document.getElementById(divid)) {
3572: document.getElementById(divid).style.display = 'none';
3573: }
3574: }
3575: }
3576: return;
3577: }
3578: // ]]>
3579: </script>
3580:
3581: ENDSCRIPT
3582: }
3583:
1.160.6.116 raeburn 3584: sub autoenroll_javascript {
3585: return <<"ENDSCRIPT";
3586: <script type="text/javascript">
3587: // <![CDATA[
3588: function toggleFailsafe(form) {
3589: var radioname = 'autoenroll_failsafe';
3590: var divid = 'autoenroll_failsafe_div';
3591: var num = form.elements[radioname].length;
3592: if (num) {
3593: var setvis = '';
3594: for (var i=0; i<num; i++) {
3595: if (form.elements[radioname][i].checked) {
3596: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3597: if (document.getElementById(divid)) {
3598: document.getElementById(divid).style.display = 'inline-block';
3599: }
3600: setvis = 1;
3601: }
3602: break;
3603: }
3604: }
3605: if (!setvis) {
3606: if (document.getElementById(divid)) {
3607: document.getElementById(divid).style.display = 'none';
3608: }
3609: }
3610: }
3611: return;
3612: }
3613: // ]]>
3614: </script>
3615:
3616: ENDSCRIPT
3617: }
3618:
1.160.6.113 raeburn 3619: sub saml_javascript {
3620: return <<"ENDSCRIPT";
3621: <script type="text/javascript">
3622: // <![CDATA[
3623: function toggleSamlOptions(form,hostid) {
3624: var radioname = 'saml_'+hostid;
3625: var tablecellon = 'samloptionson_'+hostid;
3626: var tablecelloff = 'samloptionsoff_'+hostid;
3627: var num = form.elements[radioname].length;
3628: if (num) {
3629: var setvis = '';
3630: for (var i=0; i<num; i++) {
3631: if (form.elements[radioname][i].checked) {
3632: if (form.elements[radioname][i].value == '1') {
3633: if (document.getElementById(tablecellon)) {
3634: document.getElementById(tablecellon).style.display='';
3635: }
3636: if (document.getElementById(tablecelloff)) {
3637: document.getElementById(tablecelloff).style.display='none';
3638: }
3639: setvis = 1;
3640: }
3641: break;
3642: }
3643: }
3644: if (!setvis) {
3645: if (document.getElementById(tablecellon)) {
3646: document.getElementById(tablecellon).style.display='none';
3647: }
3648: if (document.getElementById(tablecelloff)) {
3649: document.getElementById(tablecelloff).style.display='';
3650: }
3651: }
3652: }
3653: return;
3654: }
3655: // ]]>
3656: </script>
3657:
3658: ENDSCRIPT
3659: }
3660:
3661: sub ipaccess_javascript {
3662: my ($settings) = @_;
3663: my (%ordered,$total,%jstext);
3664: $total = 0;
3665: if (ref($settings) eq 'HASH') {
3666: foreach my $item (keys(%{$settings})) {
3667: if (ref($settings->{$item}) eq 'HASH') {
3668: my $num = $settings->{$item}{'order'};
3669: $ordered{$num} = $item;
3670: }
3671: }
3672: $total = scalar(keys(%{$settings}));
3673: }
3674: my @jsarray = ();
3675: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3676: push(@jsarray,$ordered{$item});
3677: }
3678: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3679: return <<"ENDSCRIPT";
3680: <script type="text/javascript">
3681: // <![CDATA[
3682: function reorderIPaccess(form,item) {
3683: var changedVal;
3684: $jstext
3685: var newpos = 'ipaccess_pos_add';
3686: var maxh = 1 + $total;
3687: var current = new Array;
3688: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3689: if (item == newpos) {
3690: changedVal = newitemVal;
3691: } else {
3692: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3693: current[newitemVal] = newpos;
3694: }
3695: for (var i=0; i<ipaccess.length; i++) {
3696: var elementName = 'ipaccess_pos_'+ipaccess[i];
3697: if (elementName != item) {
3698: if (form.elements[elementName]) {
3699: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3700: current[currVal] = elementName;
3701: }
3702: }
3703: }
3704: var oldVal;
3705: for (var j=0; j<maxh; j++) {
3706: if (current[j] == undefined) {
3707: oldVal = j;
3708: }
3709: }
3710: if (oldVal < changedVal) {
3711: for (var k=oldVal+1; k<=changedVal ; k++) {
3712: var elementName = current[k];
3713: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3714: }
3715: } else {
3716: for (var k=changedVal; k<oldVal; k++) {
3717: var elementName = current[k];
3718: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3719: }
3720: }
3721: return;
3722: }
3723: // ]]>
3724: </script>
3725:
3726: ENDSCRIPT
3727: }
3728:
1.3 raeburn 3729: sub print_autoenroll {
1.30 raeburn 3730: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3731: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3732: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3733: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3734: $failsafesty = 'none';
3735: %failsafechecked = (
3736: off => ' checked="checked"',
3737: );
1.3 raeburn 3738: if (ref($settings) eq 'HASH') {
3739: if (exists($settings->{'run'})) {
3740: if ($settings->{'run'} eq '0') {
3741: $runoff = ' checked="checked" ';
3742: $runon = ' ';
3743: } else {
3744: $runon = ' checked="checked" ';
3745: $runoff = ' ';
3746: }
3747: } else {
3748: if ($autorun) {
3749: $runon = ' checked="checked" ';
3750: $runoff = ' ';
3751: } else {
3752: $runoff = ' checked="checked" ';
3753: $runon = ' ';
3754: }
3755: }
1.129 raeburn 3756: if (exists($settings->{'co-owners'})) {
3757: if ($settings->{'co-owners'} eq '0') {
3758: $coownersoff = ' checked="checked" ';
3759: $coownerson = ' ';
3760: } else {
3761: $coownerson = ' checked="checked" ';
3762: $coownersoff = ' ';
3763: }
3764: } else {
3765: $coownersoff = ' checked="checked" ';
3766: $coownerson = ' ';
3767: }
1.3 raeburn 3768: if (exists($settings->{'sender_domain'})) {
3769: $defdom = $settings->{'sender_domain'};
3770: }
1.160.6.116 raeburn 3771: if (exists($settings->{'failsafe'})) {
3772: $failsafe = $settings->{'failsafe'};
3773: if ($failsafe eq 'zero') {
3774: $failsafechecked{'zero'} = ' checked="checked"';
3775: $failsafechecked{'off'} = '';
3776: $failsafesty = 'inline-block';
3777: } elsif ($failsafe eq 'any') {
3778: $failsafechecked{'any'} = ' checked="checked"';
3779: $failsafechecked{'off'} = '';
3780: }
3781: $autofailsafe = $settings->{'autofailsafe'};
3782: } elsif (exists($settings->{'autofailsafe'})) {
3783: $autofailsafe = $settings->{'autofailsafe'};
3784: if ($autofailsafe ne '') {
3785: $failsafechecked{'zero'} = ' checked="checked"';
3786: $failsafe = 'zero';
3787: $failsafechecked{'off'} = '';
3788: }
1.160.6.68 raeburn 3789: }
1.14 raeburn 3790: } else {
3791: if ($autorun) {
3792: $runon = ' checked="checked" ';
3793: $runoff = ' ';
3794: } else {
3795: $runoff = ' checked="checked" ';
3796: $runon = ' ';
3797: }
1.3 raeburn 3798: }
3799: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3800: my $notif_sender;
3801: if (ref($settings) eq 'HASH') {
3802: $notif_sender = $settings->{'sender_uname'};
3803: }
1.3 raeburn 3804: my $datatable='<tr class="LC_odd_row">'.
3805: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3806: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3807: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3808: $runon.' value="1" />'.&mt('Yes').'</label> '.
3809: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3810: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3811: '</tr><tr>'.
3812: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3813: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3814: &mt('username').': '.
3815: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3816: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3817: ': '.$domform.'</span></td></tr>'.
3818: '<tr class="LC_odd_row">'.
3819: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3820: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3821: '<input type="radio" name="autoassign_coowners"'.
3822: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3823: '<label><input type="radio" name="autoassign_coowners"'.
3824: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3825: '</tr><tr>'.
3826: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3827: '<td class="LC_left_item"><span class="LC_nobreak">'.
3828: '<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> '.
3829: '<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 />'.
3830: '<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>'.
3831: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3832: '<span class="LC_nobreak">'.
3833: &mt('Threshold for number of students in section to drop: [_1]',
3834: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3835: '</span></div></td></tr>';
1.160.6.68 raeburn 3836: $$rowtotal += 4;
1.3 raeburn 3837: return $datatable;
3838: }
3839:
3840: sub print_autoupdate {
1.30 raeburn 3841: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3842: my ($enable,$datatable);
1.3 raeburn 3843: if ($position eq 'top') {
1.160.6.113 raeburn 3844: my %choices = &Apache::lonlocal::texthash (
3845: run => 'Auto-update active?',
3846: classlists => 'Update information in classlists?',
3847: unexpired => 'Skip updates for users without active or future roles?',
3848: lastactive => 'Skip updates for inactive users?',
3849: );
3850: my $itemcount = 0;
1.3 raeburn 3851: my $updateon = ' ';
3852: my $updateoff = ' checked="checked" ';
3853: if (ref($settings) eq 'HASH') {
3854: if ($settings->{'run'} eq '1') {
3855: $updateon = $updateoff;
3856: $updateoff = ' ';
3857: }
3858: }
1.160.6.118.2 14(raebu 3859:23): $enable = '<tr class="LC_odd_row">'.
3860:23): '<td>'.$choices{'run'}.'</td>'.
1.160.6.113 raeburn 3861: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3862: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3863: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3864: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3865: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3866: '</tr>';
1.160.6.113 raeburn 3867: my @toggles = ('classlists','unexpired');
3868: my %defaultchecked = ('classlists' => 'off',
3869: 'unexpired' => 'off'
3870: );
3871: $$rowtotal ++;
3872: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3873: \%choices,$itemcount,'','','left','no');
3874: $datatable = $enable.$datatable;
3875: $$rowtotal += $itemcount;
3876: my $lastactiveon = ' ';
3877: my $lastactiveoff = ' checked="checked" ';
3878: my $lastactivestyle = 'none';
3879: my $lastactivedays;
3880: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3881: if (ref($settings) eq 'HASH') {
3882: if ($settings->{'lastactive'} =~ /^\d+$/) {
3883: $lastactiveon = $lastactiveoff;
3884: $lastactiveoff = ' ';
3885: $lastactivestyle = 'inline-block';
3886: $lastactivedays = $settings->{'lastactive'};
3887: }
3888: }
3889: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3890: $datatable .= '<tr'.$css_class.'>'.
3891: '<td>'.$choices{'lastactive'}.'</td>'.
3892: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3893: '<input type="radio" name="lastactive"'.
3894: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3895: ' <label>'.
3896: '<input type="radio" name="lastactive"'.
3897: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3898: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3899: ': '.&mt('inactive = no activity in last [_1] days',
3900: '<input type="text" size="5" name="lastactivedays" value="'.
3901: $lastactivedays.'" />').
3902: '</span></td>'.
3903: '</tr>';
3904: $$rowtotal ++;
1.131 raeburn 3905: } elsif ($position eq 'middle') {
3906: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3907: my $numinrow = 3;
3908: my $locknamesettings;
3909: $datatable .= &insttypes_row($settings,$types,$usertypes,
3910: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3911: 'lockablenames',$rowtotal);
1.131 raeburn 3912: $$rowtotal ++;
1.3 raeburn 3913: } else {
1.44 raeburn 3914: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3915: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3916: 'permanentemail','id');
1.33 raeburn 3917: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3918: my $numrows = 0;
1.26 raeburn 3919: if (ref($types) eq 'ARRAY') {
3920: if (@{$types} > 0) {
3921: $datatable =
3922: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3923: \@fields,$types,\$numrows);
1.30 raeburn 3924: $$rowtotal += @{$types};
1.26 raeburn 3925: }
1.3 raeburn 3926: }
3927: $datatable .=
3928: &usertype_update_row($settings,{'default' => $othertitle},
3929: \%fieldtitles,\@fields,['default'],
3930: \$numrows);
1.30 raeburn 3931: $$rowtotal ++;
1.3 raeburn 3932: }
3933: return $datatable;
3934: }
3935:
1.125 raeburn 3936: sub print_autocreate {
3937: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3938: my (%createon,%createoff,%currhash);
1.125 raeburn 3939: my @types = ('xml','req');
3940: if (ref($settings) eq 'HASH') {
3941: foreach my $item (@types) {
3942: $createoff{$item} = ' checked="checked" ';
3943: $createon{$item} = ' ';
3944: if (exists($settings->{$item})) {
3945: if ($settings->{$item}) {
3946: $createon{$item} = ' checked="checked" ';
3947: $createoff{$item} = ' ';
3948: }
3949: }
3950: }
1.160.6.16 raeburn 3951: if ($settings->{'xmldc'} ne '') {
3952: $currhash{$settings->{'xmldc'}} = 1;
3953: }
1.125 raeburn 3954: } else {
3955: foreach my $item (@types) {
3956: $createoff{$item} = ' checked="checked" ';
3957: $createon{$item} = ' ';
3958: }
3959: }
3960: $$rowtotal += 2;
1.160.6.16 raeburn 3961: my $numinrow = 2;
1.125 raeburn 3962: my $datatable='<tr class="LC_odd_row">'.
3963: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3964: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3965: '<input type="radio" name="autocreate_xml"'.
3966: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3967: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3968: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3969: '</td></tr><tr>'.
3970: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3971: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3972: '<input type="radio" name="autocreate_req"'.
3973: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3974: '<label><input type="radio" name="autocreate_req"'.
3975: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 3976: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
3977: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 3978: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 3979: if ($numdc > 1) {
1.160.6.50 raeburn 3980: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
3981: '</td><td class="LC_left_item">';
1.125 raeburn 3982: } else {
1.160.6.50 raeburn 3983: $datatable .= &mt('Course creation processed as:').
3984: '</td><td class="LC_right_item">';
1.125 raeburn 3985: }
1.160.6.50 raeburn 3986: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 3987: $$rowtotal += $rows;
1.125 raeburn 3988: return $datatable;
3989: }
3990:
1.23 raeburn 3991: sub print_directorysrch {
1.160.6.72 raeburn 3992: my ($position,$dom,$settings,$rowtotal) = @_;
3993: my $datatable;
3994: if ($position eq 'top') {
3995: my $instsrchon = ' ';
3996: my $instsrchoff = ' checked="checked" ';
3997: my ($exacton,$containson,$beginson);
3998: my $instlocalon = ' ';
3999: my $instlocaloff = ' checked="checked" ';
4000: if (ref($settings) eq 'HASH') {
4001: if ($settings->{'available'} eq '1') {
4002: $instsrchon = $instsrchoff;
4003: $instsrchoff = ' ';
4004: }
4005: if ($settings->{'localonly'} eq '1') {
4006: $instlocalon = $instlocaloff;
4007: $instlocaloff = ' ';
4008: }
4009: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4010: foreach my $type (@{$settings->{'searchtypes'}}) {
4011: if ($type eq 'exact') {
4012: $exacton = ' checked="checked" ';
4013: } elsif ($type eq 'contains') {
4014: $containson = ' checked="checked" ';
4015: } elsif ($type eq 'begins') {
4016: $beginson = ' checked="checked" ';
4017: }
4018: }
4019: } else {
4020: if ($settings->{'searchtypes'} eq 'exact') {
4021: $exacton = ' checked="checked" ';
4022: } elsif ($settings->{'searchtypes'} eq 'contains') {
4023: $containson = ' checked="checked" ';
4024: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4025: $exacton = ' checked="checked" ';
4026: $containson = ' checked="checked" ';
4027: }
4028: }
1.23 raeburn 4029: }
1.160.6.72 raeburn 4030: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4031: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 4032:
1.160.6.72 raeburn 4033: my $numinrow = 4;
4034: my $cansrchrow = 0;
4035: $datatable='<tr class="LC_odd_row">'.
4036: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4037: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4038: '<input type="radio" name="dirsrch_available"'.
4039: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4040: '<label><input type="radio" name="dirsrch_available"'.
4041: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4042: '</tr><tr>'.
4043: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4044: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4045: '<input type="radio" name="dirsrch_instlocalonly"'.
4046: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4047: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4048: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4049: '</tr>';
4050: $$rowtotal += 2;
4051: if (ref($usertypes) eq 'HASH') {
4052: if (keys(%{$usertypes}) > 0) {
4053: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 4054: $numinrow,$othertitle,'cansearch',
4055: $rowtotal);
1.160.6.72 raeburn 4056: $cansrchrow = 1;
4057: }
1.26 raeburn 4058: }
1.160.6.72 raeburn 4059: if ($cansrchrow) {
4060: $$rowtotal ++;
4061: $datatable .= '<tr>';
4062: } else {
4063: $datatable .= '<tr class="LC_odd_row">';
4064: }
4065: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4066: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4067: foreach my $title (@{$titleorder}) {
4068: if (defined($searchtitles->{$title})) {
4069: my $check = ' ';
4070: if (ref($settings) eq 'HASH') {
4071: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4072: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4073: $check = ' checked="checked" ';
4074: }
1.39 raeburn 4075: }
1.25 raeburn 4076: }
1.160.6.72 raeburn 4077: $datatable .= '<td class="LC_left_item">'.
4078: '<span class="LC_nobreak"><label>'.
4079: '<input type="checkbox" name="searchby" '.
4080: 'value="'.$title.'"'.$check.'/>'.
4081: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4082: }
4083: }
1.160.6.72 raeburn 4084: $datatable .= '</tr></table></td></tr>';
4085: $$rowtotal ++;
4086: if ($cansrchrow) {
4087: $datatable .= '<tr class="LC_odd_row">';
4088: } else {
4089: $datatable .= '<tr>';
4090: }
4091: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4092: '<td class="LC_left_item" colspan="2">'.
4093: '<span class="LC_nobreak"><label>'.
4094: '<input type="checkbox" name="searchtypes" '.
4095: $exacton.' value="exact" />'.&mt('Exact match').
4096: '</label> '.
4097: '<label><input type="checkbox" name="searchtypes" '.
4098: $beginson.' value="begins" />'.&mt('Begins with').
4099: '</label> '.
4100: '<label><input type="checkbox" name="searchtypes" '.
4101: $containson.' value="contains" />'.&mt('Contains').
4102: '</label></span></td></tr>';
4103: $$rowtotal ++;
1.26 raeburn 4104: } else {
1.160.6.72 raeburn 4105: my $domsrchon = ' checked="checked" ';
4106: my $domsrchoff = ' ';
4107: my $domlocalon = ' ';
4108: my $domlocaloff = ' checked="checked" ';
4109: if (ref($settings) eq 'HASH') {
4110: if ($settings->{'lclocalonly'} eq '1') {
4111: $domlocalon = $domlocaloff;
4112: $domlocaloff = ' ';
4113: }
4114: if ($settings->{'lcavailable'} eq '0') {
4115: $domsrchoff = $domsrchon;
4116: $domsrchon = ' ';
4117: }
4118: }
4119: $datatable='<tr class="LC_odd_row">'.
4120: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4121: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4122: '<input type="radio" name="dirsrch_domavailable"'.
4123: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4124: '<label><input type="radio" name="dirsrch_domavailable"'.
4125: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4126: '</tr><tr>'.
4127: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4128: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4129: '<input type="radio" name="dirsrch_domlocalonly"'.
4130: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4131: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4132: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4133: '</tr>';
4134: $$rowtotal += 2;
1.26 raeburn 4135: }
1.25 raeburn 4136: return $datatable;
4137: }
4138:
1.28 raeburn 4139: sub print_contacts {
1.160.6.78 raeburn 4140: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4141: my $datatable;
4142: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 4143: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 4144: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 4145: if ($position eq 'top') {
4146: if (ref($settings) eq 'HASH') {
4147: foreach my $item (@contacts) {
4148: if (exists($settings->{$item})) {
4149: $to{$item} = $settings->{$item};
4150: }
1.28 raeburn 4151: }
4152: }
1.160.6.78 raeburn 4153: } elsif ($position eq 'middle') {
4154: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 4155: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 4156: foreach my $type (@mailings) {
1.160.6.78 raeburn 4157: $otheremails{$type} = '';
4158: }
1.160.6.107 raeburn 4159: } elsif ($position eq 'lower') {
4160: if (ref($settings) eq 'HASH') {
4161: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4162: %lonstatus = %{$settings->{'lonstatus'}};
4163: }
4164: }
1.160.6.78 raeburn 4165: } else {
4166: @mailings = ('helpdeskmail','otherdomsmail');
4167: foreach my $type (@mailings) {
4168: $otheremails{$type} = '';
4169: }
4170: $bccemails{'helpdeskmail'} = '';
4171: $bccemails{'otherdomsmail'} = '';
4172: $includestr{'helpdeskmail'} = '';
4173: $includestr{'otherdomsmail'} = '';
4174: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4175: }
4176: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 4177: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4178: foreach my $type (@mailings) {
4179: if (exists($settings->{$type})) {
4180: if (ref($settings->{$type}) eq 'HASH') {
4181: foreach my $item (@contacts) {
4182: if ($settings->{$type}{$item}) {
4183: $checked{$type}{$item} = ' checked="checked" ';
4184: }
1.28 raeburn 4185: }
1.160.6.78 raeburn 4186: $otheremails{$type} = $settings->{$type}{'others'};
4187: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4188: $bccemails{$type} = $settings->{$type}{'bcc'};
4189: if ($settings->{$type}{'include'} ne '') {
4190: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4191: $includestr{$type} = &unescape($includestr{$type});
4192: }
4193: }
4194: }
4195: } elsif ($type eq 'lonstatusmail') {
4196: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4197: }
4198: }
4199: }
4200: if ($position eq 'bottom') {
4201: foreach my $type (@mailings) {
4202: $bccemails{$type} = $settings->{$type}{'bcc'};
4203: if ($settings->{$type}{'include'} ne '') {
4204: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4205: $includestr{$type} = &unescape($includestr{$type});
4206: }
4207: }
4208: if (ref($settings->{'helpform'}) eq 'HASH') {
4209: if (ref($fields) eq 'ARRAY') {
4210: foreach my $field (@{$fields}) {
4211: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4212: }
1.160.6.78 raeburn 4213: }
4214: if (exists($settings->{'helpform'}{'maxsize'})) {
4215: $maxsize = $settings->{'helpform'}{'maxsize'};
4216: } else {
4217: $maxsize = '1.0';
4218: }
4219: } else {
4220: if (ref($fields) eq 'ARRAY') {
4221: foreach my $field (@{$fields}) {
4222: $currfield{$field} = 'yes';
1.134 raeburn 4223: }
1.28 raeburn 4224: }
1.160.6.78 raeburn 4225: $maxsize = '1.0';
1.28 raeburn 4226: }
4227: }
4228: } else {
1.160.6.78 raeburn 4229: if ($position eq 'top') {
4230: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4231: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4232: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4233: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
4234: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4235: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4236: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4237: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 4238: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 4239: } elsif ($position eq 'bottom') {
4240: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4241: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4242: if (ref($fields) eq 'ARRAY') {
4243: foreach my $field (@{$fields}) {
4244: $currfield{$field} = 'yes';
4245: }
4246: }
4247: $maxsize = '1.0';
4248: }
1.28 raeburn 4249: }
4250: my ($titles,$short_titles) = &contact_titles();
4251: my $rownum = 0;
4252: my $css_class;
1.160.6.78 raeburn 4253: if ($position eq 'top') {
4254: foreach my $item (@contacts) {
4255: $css_class = $rownum%2?' class="LC_odd_row"':'';
4256: $datatable .= '<tr'.$css_class.'>'.
4257: '<td><span class="LC_nobreak">'.$titles->{$item}.
4258: '</span></td><td class="LC_right_item">'.
4259: '<input type="text" name="'.$item.'" value="'.
4260: $to{$item}.'" /></td></tr>';
4261: $rownum ++;
4262: }
1.160.6.101 raeburn 4263: } elsif ($position eq 'bottom') {
4264: $css_class = $rownum%2?' class="LC_odd_row"':'';
4265: $datatable .= '<tr'.$css_class.'>'.
4266: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4267: &mt('(e-mail, subject, and description always shown)').
4268: '</td><td class="LC_left_item">';
4269: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4270: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4271: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4272: foreach my $field (@{$fields}) {
4273: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4274: if (($field eq 'screenshot') || ($field eq 'cc')) {
4275: $datatable .= ' '.&mt('(logged-in users)');
4276: }
4277: $datatable .='</td><td>';
4278: my $clickaction;
4279: if ($field eq 'screenshot') {
4280: $clickaction = ' onclick="screenshotSize(this);"';
4281: }
4282: if (ref($possoptions->{$field}) eq 'ARRAY') {
4283: foreach my $option (@{$possoptions->{$field}}) {
4284: my $checked;
4285: if ($currfield{$field} eq $option) {
4286: $checked = ' checked="checked"';
4287: }
4288: $datatable .= '<span class="LC_nobreak"><label>'.
4289: '<input type="radio" name="helpform_'.$field.'" '.
4290: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4291: '</label></span>'.(' 'x2);
4292: }
4293: }
4294: if ($field eq 'screenshot') {
4295: my $display;
4296: if ($currfield{$field} eq 'no') {
4297: $display = ' style="display:none"';
4298: }
4299: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4300: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4301: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4302: }
4303: $datatable .= '</td></tr>';
4304: }
4305: $datatable .= '</table>';
4306: }
4307: $datatable .= '</td></tr>'."\n";
4308: $rownum ++;
4309: }
1.160.6.107 raeburn 4310: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4311: foreach my $type (@mailings) {
4312: $css_class = $rownum%2?' class="LC_odd_row"':'';
4313: $datatable .= '<tr'.$css_class.'>'.
4314: '<td><span class="LC_nobreak">'.
4315: $titles->{$type}.': </span></td>'.
4316: '<td class="LC_left_item">';
4317: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4318: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4319: }
4320: $datatable .= '<span class="LC_nobreak">';
4321: foreach my $item (@contacts) {
4322: $datatable .= '<label>'.
4323: '<input type="checkbox" name="'.$type.'"'.
4324: $checked{$type}{$item}.
4325: ' value="'.$item.'" />'.$short_titles->{$item}.
4326: '</label> ';
4327: }
4328: $datatable .= '</span><br />'.&mt('Others').': '.
4329: '<input type="text" name="'.$type.'_others" '.
4330: 'value="'.$otheremails{$type}.'" />';
4331: my %locchecked;
4332: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4333: foreach my $loc ('s','b') {
4334: if ($includeloc{$type} eq $loc) {
4335: $locchecked{$loc} = ' checked="checked"';
4336: last;
4337: }
4338: }
4339: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4340: '<input type="text" name="'.$type.'_bcc" '.
4341: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4342: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4343: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4344: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4345: '<span class="LC_nobreak">'.&mt('Location:').' '.
4346: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4347: (' 'x2).
4348: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4349: '</span></fieldset>';
4350: }
4351: $datatable .= '</td></tr>'."\n";
4352: $rownum ++;
4353: }
1.28 raeburn 4354: }
1.160.6.78 raeburn 4355: if ($position eq 'middle') {
4356: my %choices;
1.160.6.107 raeburn 4357: my $corelink = &core_link_msu();
4358: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4359: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4360: $corelink);
4361: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4362: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4363: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4364: 'reportupdates' => 'on',
4365: 'reportstatus' => 'on');
1.160.6.78 raeburn 4366: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4367: \%choices,$rownum);
4368: $datatable .= $reports;
1.160.6.107 raeburn 4369: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4370: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4371: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4372: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4373: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4374: } else {
1.160.6.109 raeburn 4375: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4376: }
4377: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4378: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4379: } else {
1.160.6.109 raeburn 4380: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4381: }
4382: if (ref($lonstatus{'weights'}) eq 'HASH') {
4383: foreach my $type ('E','W','N','U') {
4384: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4385: $weights{$type} = $lonstatus{'weights'}{$type};
4386: } else {
4387: $weights{$type} = $defaults->{$type};
4388: }
4389: }
4390: } else {
4391: foreach my $type ('E','W','N','U') {
4392: $weights{$type} = $defaults->{$type};
4393: }
4394: }
4395: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4396: if (@{$lonstatus{'excluded'}} > 0) {
4397: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4398: }
4399: }
1.160.6.109 raeburn 4400: foreach my $item ('errorthreshold','errorsysmail') {
4401: $css_class = $rownum%2?' class="LC_odd_row"':'';
4402: $datatable .= '<tr'.$css_class.'>'.
4403: '<td class="LC_left_item"><span class="LC_nobreak">'.
4404: $titles->{$item}.
4405: '</span></td><td class="LC_left_item">'.
4406: '<input type="text" name="'.$item.'" value="'.
4407: $current{$item}.'" size="5" /></td></tr>';
4408: $rownum ++;
4409: }
1.160.6.107 raeburn 4410: $css_class = $rownum%2?' class="LC_odd_row"':'';
4411: $datatable .= '<tr'.$css_class.'>'.
4412: '<td class="LC_left_item">'.
4413: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4414: '</span></td><td class="LC_left_item"><table><tr>';
4415: foreach my $type ('E','W','N','U') {
4416: $datatable .= '<td>'.$names->{$type}.'<br />'.
4417: '<input type="text" name="errorweights_'.$type.'" value="'.
4418: $weights{$type}.'" size="5" /></td>';
4419: }
4420: $datatable .= '</tr></table></tr>';
4421: $rownum ++;
4422: $css_class = $rownum%2?' class="LC_odd_row"':'';
4423: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4424: $titles->{'errorexcluded'}.'</td>'.
4425: '<td class="LC_left_item"><table>';
4426: my $numinrow = 4;
4427: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4428: for (my $i=0; $i<@ids; $i++) {
4429: my $rem = $i%($numinrow);
4430: if ($rem == 0) {
4431: if ($i > 0) {
4432: $datatable .= '</tr>';
4433: }
4434: $datatable .= '<tr>';
4435: }
4436: my $check;
4437: if ($excluded{$ids[$i]}) {
4438: $check = ' checked="checked" ';
4439: }
4440: $datatable .= '<td class="LC_left_item">'.
4441: '<span class="LC_nobreak"><label>'.
4442: '<input type="checkbox" name="errorexcluded" '.
4443: 'value="'.$ids[$i].'"'.$check.' />'.
4444: $ids[$i].'</label></span></td>';
4445: }
4446: my $colsleft = $numinrow - @ids%($numinrow);
4447: if ($colsleft > 1 ) {
4448: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4449: ' </td>';
4450: } elsif ($colsleft == 1) {
4451: $datatable .= '<td class="LC_left_item"> </td>';
4452: }
4453: $datatable .= '</tr></table></td></tr>';
4454: $rownum ++;
1.160.6.78 raeburn 4455: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4456: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4457: my (@posstypes,%usertypeshash);
4458: if (ref($types) eq 'ARRAY') {
4459: @posstypes = @{$types};
4460: }
4461: if (@posstypes) {
4462: if (ref($usertypes) eq 'HASH') {
4463: %usertypeshash = %{$usertypes};
4464: }
4465: my @overridden;
4466: my $numinrow = 4;
4467: if (ref($settings) eq 'HASH') {
4468: if (ref($settings->{'overrides'}) eq 'HASH') {
4469: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4470: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4471: push(@overridden,$key);
4472: foreach my $item (@contacts) {
4473: if ($settings->{'overrides'}{$key}{$item}) {
4474: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4475: }
4476: }
4477: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4478: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4479: $includeloc{'override_'.$key} = '';
4480: $includestr{'override_'.$key} = '';
4481: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4482: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4483: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4484: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4485: }
1.160.6.78 raeburn 4486: }
4487: }
4488: }
1.160.6.101 raeburn 4489: }
4490: my $customclass = 'LC_helpdesk_override';
4491: my $optionsprefix = 'LC_options_helpdesk_';
4492:
4493: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4494: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4495: $numinrow,$othertitle,'overrides',
4496: \$rownum,$onclicktypes,$customclass);
4497: $rownum ++;
4498: $usertypeshash{'default'} = $othertitle;
4499: foreach my $status (@posstypes) {
4500: my $css_class;
4501: if ($rownum%2) {
4502: $css_class = 'LC_odd_row ';
4503: }
4504: $css_class .= $customclass;
4505: my $rowid = $optionsprefix.$status;
4506: my $hidden = 1;
4507: my $currstyle = 'display:none';
4508: if (grep(/^\Q$status\E$/,@overridden)) {
4509: $currstyle = 'display:table-row';
4510: $hidden = 0;
4511: }
4512: my $key = 'override_'.$status;
4513: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4514: $includeloc{$key},$includestr{$key},$status,$rowid,
4515: $usertypeshash{$status},$css_class,$currstyle,
4516: \@contacts,$short_titles);
4517: unless ($hidden) {
4518: $rownum ++;
1.160.6.78 raeburn 4519: }
4520: }
1.134 raeburn 4521: }
1.28 raeburn 4522: }
1.30 raeburn 4523: $$rowtotal += $rownum;
1.28 raeburn 4524: return $datatable;
4525: }
4526:
1.160.6.107 raeburn 4527: sub core_link_msu {
4528: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4529: &mt('LON-CAPA core group - MSU'),600,500);
4530: }
4531:
1.160.6.101 raeburn 4532: sub overridden_helpdesk {
4533: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4534: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4535: my $class = 'LC_left_item';
4536: if ($css_class) {
4537: $css_class = ' class="'.$css_class.'"';
4538: }
4539: if ($rowid) {
4540: $rowid = ' id="'.$rowid.'"';
4541: }
4542: if ($rowstyle) {
4543: $rowstyle = ' style="'.$rowstyle.'"';
4544: }
4545: my ($output,$description);
4546: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4547: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4548: "<td>$description</td>\n".
4549: '<td class="'.$class.'" colspan="2">'.
4550: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4551: '<span class="LC_nobreak">';
4552: if (ref($contacts) eq 'ARRAY') {
4553: foreach my $item (@{$contacts}) {
4554: my $check;
4555: if (ref($checked) eq 'HASH') {
4556: $check = $checked->{$item};
4557: }
4558: my $title;
4559: if (ref($short_titles) eq 'HASH') {
4560: $title = $short_titles->{$item};
4561: }
4562: $output .= '<label>'.
4563: '<input type="checkbox" name="override_'.$type.'"'.$check.
4564: ' value="'.$item.'" />'.$title.'</label> ';
4565: }
4566: }
4567: $output .= '</span><br />'.&mt('Others').': '.
4568: '<input type="text" name="override_'.$type.'_others" '.
4569: 'value="'.$otheremails.'" />';
4570: my %locchecked;
4571: foreach my $loc ('s','b') {
4572: if ($includeloc eq $loc) {
4573: $locchecked{$loc} = ' checked="checked"';
4574: last;
4575: }
4576: }
4577: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4578: '<input type="text" name="override_'.$type.'_bcc" '.
4579: 'value="'.$bccemails.'" /></fieldset>'.
4580: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4581: &mt('Text automatically added to e-mail:').' '.
4582: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4583: '<span class="LC_nobreak">'.&mt('Location:').' '.
4584: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4585: (' 'x2).
4586: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4587: '</span></fieldset>'.
4588: '</td></tr>'."\n";
4589: return $output;
4590: }
4591:
1.160.6.78 raeburn 4592: sub contacts_javascript {
4593: return <<"ENDSCRIPT";
4594:
4595: <script type="text/javascript">
4596: // <![CDATA[
4597:
4598: function screenshotSize(field) {
4599: if (document.getElementById('help_screenshotsize')) {
4600: if (field.value == 'no') {
4601: document.getElementById('help_screenshotsize').style.display="none";
4602: } else {
4603: document.getElementById('help_screenshotsize').style.display="";
4604: }
4605: }
4606: return;
4607: }
4608:
1.160.6.101 raeburn 4609: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4610: if (form.elements[checkbox].length != undefined) {
4611: var count = 0;
4612: if (docount) {
4613: for (var i=0; i<form.elements[checkbox].length; i++) {
4614: if (form.elements[checkbox][i].checked) {
4615: count ++;
4616: }
4617: }
4618: }
4619: for (var i=0; i<form.elements[checkbox].length; i++) {
4620: var type = form.elements[checkbox][i].value;
4621: if (document.getElementById(prefix+type)) {
4622: if (form.elements[checkbox][i].checked) {
4623: document.getElementById(prefix+type).style.display = 'table-row';
4624: if (count % 2 == 1) {
4625: document.getElementById(prefix+type).className = target+' LC_odd_row';
4626: } else {
4627: document.getElementById(prefix+type).className = target;
4628: }
4629: count ++;
4630: } else {
4631: document.getElementById(prefix+type).style.display = 'none';
4632: }
4633: }
4634: }
4635: }
4636: return;
4637: }
4638:
1.160.6.78 raeburn 4639: // ]]>
4640: </script>
4641:
4642: ENDSCRIPT
4643: }
4644:
1.118 jms 4645: sub print_helpsettings {
1.160.6.73 raeburn 4646: my ($position,$dom,$settings,$rowtotal) = @_;
4647: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4648: my $formname = 'display';
1.160.6.5 raeburn 4649: my ($datatable,$itemcount);
1.160.6.73 raeburn 4650: if ($position eq 'top') {
4651: $itemcount = 1;
4652: my (%choices,%defaultchecked,@toggles);
4653: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4654: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4655: &mt('LON-CAPA bug tracker'),600,500));
4656: %defaultchecked = ('submitbugs' => 'on');
4657: @toggles = ('submitbugs');
4658: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4659: \%choices,$itemcount);
4660: $$rowtotal ++;
4661: } else {
4662: my $css_class;
4663: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4664: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4665: if (ref($settings) eq 'HASH') {
4666: if (ref($settings->{'adhoc'}) eq 'HASH') {
4667: %current = %{$settings->{'adhoc'}};
4668: }
1.160.6.77 raeburn 4669: }
4670: my $count = 0;
4671: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4672: if ($key=~/^rolesdef\_(\w+)$/) {
4673: my $rolename = $1;
1.160.6.77 raeburn 4674: my (%privs,$order);
1.160.6.73 raeburn 4675: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4676: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4677: if (ref($current{$rolename}) eq 'HASH') {
4678: $order = $current{$rolename}{'order'};
4679: }
4680: if ($order eq '') {
4681: $order = $count;
4682: }
4683: $ordered{$order} = $rolename;
4684: $count++;
1.160.6.73 raeburn 4685: }
4686: }
1.160.6.77 raeburn 4687: my $maxnum = scalar(keys(%ordered));
4688: my @roles_by_num = ();
4689: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4690: push(@roles_by_num,$item);
4691: }
4692: my $context = 'domprefs';
4693: my $crstype = 'Course';
4694: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4695: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4696: my ($numstatustypes,@jsarray);
4697: if (ref($types) eq 'ARRAY') {
4698: if (@{$types} > 0) {
4699: $numstatustypes = scalar(@{$types});
4700: push(@accesstypes,'status');
4701: @jsarray = ('bystatus');
4702: }
4703: }
1.160.6.86 raeburn 4704: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4705: if (keys(%domhelpdesk)) {
4706: push(@accesstypes,('inc','exc'));
4707: push(@jsarray,('notinc','notexc'));
4708: }
4709: my $hiddenstr = join("','",@jsarray);
1.160.6.73 raeburn 4710: my $context = 'domprefs';
4711: my $crstype = 'Course';
1.160.6.77 raeburn 4712: my $prefix = 'helproles_';
4713: my $add_class = 'LC_hidden';
4714: foreach my $num (@roles_by_num) {
4715: my $role = $ordered{$num};
4716: my ($desc,$access,@statuses);
4717: if (ref($current{$role}) eq 'HASH') {
4718: $desc = $current{$role}{'desc'};
4719: $access = $current{$role}{'access'};
4720: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4721: @statuses = @{$current{$role}{'insttypes'}};
4722: }
4723: }
4724: if ($desc eq '') {
4725: $desc = $role;
4726: }
4727: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4728: my %full=();
4729: my %levels= (
4730: course => {},
4731: domain => {},
4732: system => {},
4733: );
4734: my %levelscurrent=(
4735: course => {},
4736: domain => {},
4737: system => {},
4738: );
4739: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4740: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4741: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4742: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4743: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4744: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4745: for (my $k=0; $k<=$maxnum; $k++) {
4746: my $vpos = $k+1;
4747: my $selstr;
4748: if ($k == $num) {
4749: $selstr = ' selected="selected" ';
4750: }
4751: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4752: }
4753: $datatable .= '</select>'.(' 'x2).
4754: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4755: '</td>'.
4756: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4757: &mt('Name shown to users:').
4758: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4759: '</fieldset>'.
4760: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4761: $othertitle,$usertypes,$types,\%domhelpdesk).
4762: '<fieldset>'.
4763: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4764: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4765: \%levelscurrent,$identifier,
4766: 'LC_hidden',$prefix.$num.'_privs').
4767: '</fieldset></td>';
1.160.6.73 raeburn 4768: $itemcount ++;
4769: }
4770: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4771: my $newcust = 'custhelp'.$count;
4772: my (%privs,%levelscurrent);
4773: my %full=();
4774: my %levels= (
4775: course => {},
4776: domain => {},
4777: system => {},
4778: );
4779: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4780: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4781: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4782: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4783: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4784: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4785: for (my $k=0; $k<$maxnum+1; $k++) {
4786: my $vpos = $k+1;
4787: my $selstr;
4788: if ($k == $maxnum) {
4789: $selstr = ' selected="selected" ';
4790: }
4791: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4792: }
4793: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4794: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4795: '</label></span></td>'.
1.160.6.77 raeburn 4796: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4797: '<span class="LC_nobreak">'.
4798: &mt('Internal name:').
4799: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4800: '</span>'.(' 'x4).
4801: '<span class="LC_nobreak">'.
4802: &mt('Name shown to users:').
4803: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4804: '</span></fieldset>'.
4805: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4806: $usertypes,$types,\%domhelpdesk).
4807: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4808: &Apache::lonuserutils::custom_role_header($context,$crstype,
4809: \@templateroles,$newcust).
4810: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4811: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4812: '</fieldset>'.
4813: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4814: '</td></tr>';
1.160.6.73 raeburn 4815: $count ++;
4816: $$rowtotal += $count;
4817: }
1.160.6.5 raeburn 4818: return $datatable;
1.121 raeburn 4819: }
4820:
1.160.6.77 raeburn 4821: sub adhocbutton {
4822: my ($prefix,$num,$field,$visibility) = @_;
4823: my %lt = &Apache::lonlocal::texthash(
4824: show => 'Show details',
4825: hide => 'Hide details',
4826: );
4827: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4828: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4829: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4830: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4831: }
4832:
4833: sub helpsettings_javascript {
4834: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4835: return unless(ref($roles_by_num) eq 'ARRAY');
4836: my %html_js_lt = &Apache::lonlocal::texthash(
4837: show => 'Show details',
4838: hide => 'Hide details',
4839: );
4840: &html_escape(\%html_js_lt);
4841: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4842: return <<"ENDSCRIPT";
4843: <script type="text/javascript">
4844: // <![CDATA[
4845:
4846: function reorderHelpRoles(form,item) {
4847: var changedVal;
4848: $jstext
4849: var newpos = 'helproles_${total}_pos';
4850: var maxh = 1 + $total;
4851: var current = new Array();
4852: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4853: if (item == newpos) {
4854: changedVal = newitemVal;
4855: } else {
4856: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4857: current[newitemVal] = newpos;
4858: }
4859: for (var i=0; i<helproles.length; i++) {
4860: var elementName = 'helproles_'+helproles[i]+'_pos';
4861: if (elementName != item) {
4862: if (form.elements[elementName]) {
4863: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4864: current[currVal] = elementName;
4865: }
4866: }
4867: }
4868: var oldVal;
4869: for (var j=0; j<maxh; j++) {
4870: if (current[j] == undefined) {
4871: oldVal = j;
4872: }
4873: }
4874: if (oldVal < changedVal) {
4875: for (var k=oldVal+1; k<=changedVal ; k++) {
4876: var elementName = current[k];
4877: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4878: }
4879: } else {
4880: for (var k=changedVal; k<oldVal; k++) {
4881: var elementName = current[k];
4882: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4883: }
4884: }
4885: return;
4886: }
4887:
4888: function helpdeskAccess(num) {
4889: var curraccess = null;
4890: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4891: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4892: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4893: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4894: }
4895: }
4896: }
4897: var shown = Array();
4898: var hidden = Array();
4899: if (curraccess == 'none') {
4900: hidden = Array('$hiddenstr');
4901: } else {
4902: if (curraccess == 'status') {
4903: shown = Array('bystatus');
4904: hidden = Array('notinc','notexc');
4905: } else {
4906: if (curraccess == 'exc') {
4907: shown = Array('notexc');
4908: hidden = Array('notinc','bystatus');
4909: }
4910: if (curraccess == 'inc') {
4911: shown = Array('notinc');
4912: hidden = Array('notexc','bystatus');
4913: }
1.160.6.79 raeburn 4914: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4915: hidden = Array('notinc','notexc','bystatus');
4916: }
4917: }
4918: }
4919: if (hidden.length > 0) {
4920: for (var i=0; i<hidden.length; i++) {
4921: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4922: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4923: }
4924: }
4925: }
4926: if (shown.length > 0) {
4927: for (var i=0; i<shown.length; i++) {
4928: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4929: if (shown[i] == 'privs') {
4930: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4931: } else {
4932: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4933: }
4934: }
4935: }
4936: }
4937: return;
4938: }
4939:
4940: function toggleHelpdeskItem(num,field) {
4941: if (document.getElementById('helproles_'+num+'_'+field)) {
4942: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4943: document.getElementById('helproles_'+num+'_'+field).className =
4944: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4945: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4946: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4947: }
4948: } else {
4949: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4950: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4951: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4952: }
4953: }
4954: }
4955: return;
4956: }
4957:
4958: // ]]>
4959: </script>
4960:
4961: ENDSCRIPT
4962: }
4963:
4964: sub helpdeskroles_access {
4965: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4966: $usertypes,$types,$domhelpdesk) = @_;
4967: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4968: my %lt = &Apache::lonlocal::texthash(
4969: 'rou' => 'Role usage',
4970: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4971: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4972: 'dh' => 'All with domain helpdesk role',
4973: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4974: 'none' => 'None',
4975: 'status' => 'Determined based on institutional status',
4976: 'inc' => 'Include all, but exclude specific personnel',
4977: 'exc' => 'Exclude all, but include specific personnel',
4978: );
4979: my %usecheck = (
4980: all => ' checked="checked"',
4981: );
4982: my %displaydiv = (
4983: status => 'none',
4984: inc => 'none',
4985: exc => 'none',
4986: priv => 'block',
4987: );
4988: my $output;
4989: if (ref($current) eq 'HASH') {
4990: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
4991: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
4992: $usecheck{$current->{access}} = $usecheck{'all'};
4993: delete($usecheck{'all'});
4994: if ($current->{access} =~ /^(status|inc|exc)$/) {
4995: my $access = $1;
4996: $displaydiv{$access} = 'inline';
4997: } elsif ($current->{access} eq 'none') {
4998: $displaydiv{'priv'} = 'none';
4999: }
5000: }
5001: }
5002: }
5003: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5004: '<p>'.$lt{'whi'}.'</p>';
5005: foreach my $access (@{$accesstypes}) {
5006: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5007: ' onclick="helpdeskAccess('."'$num'".');" />'.
5008: $lt{$access}.'</label>';
5009: if ($access eq 'status') {
5010: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5011: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5012: $othertitle,$usertypes,$types).
5013: '</div>';
5014: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5015: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5016: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5017: '</div>';
5018: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5019: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5020: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5021: '</div>';
5022: }
5023: $output .= '</p>';
5024: }
5025: $output .= '</fieldset>';
5026: return $output;
5027: }
5028:
1.121 raeburn 5029: sub radiobutton_prefs {
1.160.6.16 raeburn 5030: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 5031: $additional,$align,$firstval) = @_;
1.121 raeburn 5032: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5033: (ref($choices) eq 'HASH'));
5034:
5035: my (%checkedon,%checkedoff,$datatable,$css_class);
5036:
5037: foreach my $item (@{$toggles}) {
5038: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5039: $checkedon{$item} = ' checked="checked" ';
5040: $checkedoff{$item} = ' ';
1.121 raeburn 5041: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5042: $checkedoff{$item} = ' checked="checked" ';
5043: $checkedon{$item} = ' ';
5044: }
5045: }
5046: if (ref($settings) eq 'HASH') {
1.121 raeburn 5047: foreach my $item (@{$toggles}) {
1.118 jms 5048: if ($settings->{$item} eq '1') {
5049: $checkedon{$item} = ' checked="checked" ';
5050: $checkedoff{$item} = ' ';
5051: } elsif ($settings->{$item} eq '0') {
5052: $checkedoff{$item} = ' checked="checked" ';
5053: $checkedon{$item} = ' ';
5054: }
5055: }
1.121 raeburn 5056: }
1.160.6.16 raeburn 5057: if ($onclick) {
5058: $onclick = ' onclick="'.$onclick.'"';
5059: }
1.121 raeburn 5060: foreach my $item (@{$toggles}) {
1.118 jms 5061: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5062: $datatable .=
1.160.6.16 raeburn 5063: '<tr'.$css_class.'><td valign="top">'.
5064: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 5065: '</span></td>';
5066: if ($align eq 'left') {
5067: $datatable .= '<td class="LC_left_item">';
5068: } else {
5069: $datatable .= '<td class="LC_right_item">';
5070: }
1.160.6.113 raeburn 5071: $datatable .= '<span class="LC_nobreak">';
5072: if ($firstval eq 'no') {
5073: $datatable .=
5074: '<label><input type="radio" name="'.
5075: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5076: '</label> <label><input type="radio" name="'.$item.'" '.
5077: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5078: } else {
5079: $datatable .=
1.160.6.118.2 14(raebu 5080:23): '<label><input type="radio" name="'.
5081:23): $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5082:23): '</label> <label><input type="radio" name="'.$item.'" '.
5083:23): $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
1.160.6.113 raeburn 5084: }
5085: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5086: $itemcount ++;
1.121 raeburn 5087: }
5088: return ($datatable,$itemcount);
5089: }
5090:
1.160.6.118.2 1(raebur 5091:1): sub print_ltitools {
14(raebu 5092:23): my ($position,$dom,$settings,$rowtotal) = @_;
5093:23): my (%rules,%encrypt,%privkeys,%linkprot);
1(raebur 5094:1): if (ref($settings) eq 'HASH') {
14(raebu 5095:23): if ($position eq 'top') {
5096:23): if (exists($settings->{'encrypt'})) {
5097:23): if (ref($settings->{'encrypt'}) eq 'HASH') {
5098:23): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5099:23): $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1(raebur 5100:1): }
5101:1): }
5102:1): }
14(raebu 5103:23): if (exists($settings->{'private'})) {
5104:23): if (ref($settings->{'private'}) eq 'HASH') {
5105:23): if (ref($settings->{'private'}) eq 'HASH') {
5106:23): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5107:23): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1(raebur 5108:1): }
5109:1): }
5110:1): }
5111:1): }
14(raebu 5112:23): } elsif ($position eq 'middle') {
5113:23): if (exists($settings->{'rules'})) {
5114:23): if (ref($settings->{'rules'}) eq 'HASH') {
5115:23): %rules = %{$settings->{'rules'}};
1(raebur 5116:1): }
5117:1): }
14(raebu 5118:23): } else {
5119:23): foreach my $key ('encrypt','private','rules') {
5120:23): if (exists($settings->{$key})) {
5121:23): delete($settings->{$key});
1(raebur 5122:1): }
5123:1): }
5124:1): }
5125:1): }
14(raebu 5126:23): my $datatable;
5127:23): my $itemcount = 1;
5128:23): if ($position eq 'top') {
5129:23): $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5130:23): } elsif ($position eq 'middle') {
5131:23): $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5132:23): $$rowtotal += $itemcount;
5133:23): } else {
5134:23): $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1(raebur 5135:1): }
5136:1): return $datatable;
5137:1): }
5138:1):
5139:1): sub ltitools_names {
5140:1): my %lt = &Apache::lonlocal::texthash(
5141:1): 'title' => 'Title',
5142:1): 'version' => 'Version',
5143:1): 'msgtype' => 'Message Type',
5144:1): 'sigmethod' => 'Signature Method',
5145:1): 'url' => 'URL',
5146:1): 'key' => 'Key',
5147:1): 'lifetime' => 'Nonce lifetime (s)',
5148:1): 'secret' => 'Secret',
5149:1): 'icon' => 'Icon',
5150:1): 'user' => 'User',
5151:1): 'fullname' => 'Full Name',
5152:1): 'firstname' => 'First Name',
5153:1): 'lastname' => 'Last Name',
5154:1): 'email' => 'E-mail',
5155:1): 'roles' => 'Role',
5156:1): 'window' => 'Window',
5157:1): 'tab' => 'Tab',
5158:1): 'iframe' => 'iFrame',
5159:1): 'height' => 'Height',
5160:1): 'width' => 'Width',
5161:1): 'linktext' => 'Default Link Text',
5162:1): 'explanation' => 'Default Explanation',
14(raebu 5163:23): 'passback' => 'Tool can return grades:',
5164:23): 'roster' => 'Tool can retrieve roster:',
1(raebur 5165:1): 'crstarget' => 'Display target',
5166:1): 'crslabel' => 'Course label',
5167:1): 'crstitle' => 'Course title',
5168:1): 'crslinktext' => 'Link Text',
5169:1): 'crsexplanation' => 'Explanation',
5170:1): 'crsappend' => 'Provider URL',
5171:1): );
5172:1): return %lt;
5173:1): }
5174:1):
14(raebu 5175:23): sub secrets_form {
5176:23): my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5177:23): my @ids=&Apache::lonnet::current_machine_ids();
5178:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
5179:23): my $primary = &Apache::lonnet::domain($dom,'primary');
5180:23): my ($css_class,$extra,$numshown,$itemcount,$output);
5181:23): $itemcount = 0;
5182:23): foreach my $hostid (sort(keys(%servers))) {
5183:23): my ($showextra,$divsty,$switch);
5184:23): if ($hostid eq $primary) {
5185:23): if ($context eq 'ltisec') {
5186:23): if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5187:23): $showextra = 1;
5188:23): }
5189:23): if ($encrypt->{'ltisec_crslinkprot'}) {
5190:23): $showextra = 1;
5191:23): }
5192:23): } else {
5193:23): if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5194:23): $showextra = 1;
5195:23): }
5196:23): }
5197:23): unless (grep(/^\Q$hostid\E$/,@ids)) {
5198:23): $switch = 1;
5199:23): }
5200:23): if ($showextra) {
5201:23): $numshown ++;
5202:23): $divsty = 'display:inline-block';
5203:23): } else {
5204:23): $divsty = 'display:none';
5205:23): }
5206:23): $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5207:23): '<legend>'.$hostid.'</legend>';
5208:23): if ($switch) {
5209:23): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5210:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5211:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5212:23): if (exists($privkeys->{$hostid})) {
5213:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5214:23): '<span class="LC_nobreak">'.
5215:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5216:23): '<span class="LC_nobreak">'.&mt('Change?').
5217:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5218:23): (' 'x2).
5219:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5220:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5221:23): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5222:23): '</span></div>';
5223:23): } else {
5224:23): $extra .= '<span class="LC_nobreak">'.
5225:23): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5226:23): '</span>'."\n";
5227:23): }
5228:23): } elsif (exists($privkeys->{$hostid})) {
5229:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5230:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5231:23): '<span class="LC_nobreak">'.&mt('Change?').
5232:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5233:23): (' 'x2).
5234:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5235:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5236:23): '<span class="LC_nobreak">'.&mt('New Key').':'.
5237:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5238: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>'.
5239:23): '</span></div>';
5240:23): } else {
5241:23): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5242:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5243: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>';
5244:23): }
5245:23): $extra .= '</fieldset>';
5246:23): }
5247:23): }
5248:23): my (%choices,@toggles,%defaultchecked);
5249:23): if ($context eq 'ltisec') {
5250:23): %choices = &Apache::lonlocal::texthash (
5251:23): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5252:23): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5253:23): ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5254:23): );
5255:23): @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5256:23): %defaultchecked = (
5257:23): 'ltisec_crslinkprot' => 'off',
5258:23): 'ltisec_domlinkprot' => 'off',
5259:23): 'ltisec_consumers' => 'off',
5260:23): );
5261:23): } else {
5262:23): %choices = &Apache::lonlocal::texthash (
5263:23): toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5264:23): toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5265:23): );
5266:23): @toggles = qw(toolsec_crs toolsec_dom);
5267:23): %defaultchecked = (
5268:23): 'toolsec_crs' => 'off',
5269:23): 'toolsec_dom' => 'off',
5270:23): );
5271:23): }
5272:23): my ($onclick,$itemcount);
5273:23): $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5274:23): ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5275:23): \%choices,$itemcount,$onclick,'','left','no');
5276:23):
5277:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5278:23): my $noprivkeysty = 'display:inline-block';
5279:23): if ($numshown) {
5280:23): $noprivkeysty = 'display:none';
5281:23): }
5282:23): $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5283:23): '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5284:23): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5285:23): $extra.
5286:23): '</td></tr>';
5287:23): $itemcount ++;
5288:23): $$rowtotal += $itemcount;
5289:23): return $output;
5290:23): }
5291:23):
5(raebur 5292:2): sub print_lti {
5293:2): my ($position,$dom,$settings,$rowtotal) = @_;
5294:2): my $itemcount = 1;
5295:2): my ($datatable,$css_class);
18(raebu 5296:24): my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
5(raebur 5297:2): if (ref($settings) eq 'HASH') {
5298:2): if ($position eq 'top') {
5299:2): if (exists($settings->{'encrypt'})) {
5300:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5301:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
14(raebu 5302:23): if ($key eq 'consumers') {
5303:23): $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5304:23): } else {
5305:23): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5306:23): }
5(raebur 5307:2): }
5308:2): }
5309:2): }
5310:2): if (exists($settings->{'private'})) {
5311:2): if (ref($settings->{'private'}) eq 'HASH') {
5312:2): if (ref($settings->{'private'}) eq 'HASH') {
5313:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5314:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5315:2): }
5316:2): }
5317:2): }
5318:2): }
18(raebu 5319:24): } elsif ($position eq 'upper') {
5(raebur 5320:2): if (exists($settings->{'rules'})) {
5321:2): if (ref($settings->{'rules'}) eq 'HASH') {
5322:2): %rules = %{$settings->{'rules'}};
5323:2): }
5324:2): }
18(raebu 5325:24): } elsif ($position eq 'middle') {
5326:24): if (exists($settings->{'suggested'})) {
5327:24): if (ref($settings->{'suggested'}) eq 'HASH') {
5328:24): %suggestions = %{$settings->{'suggested'}};
5329:24): }
5330:24): }
14(raebu 5331:23): } elsif ($position eq 'lower') {
5(raebur 5332:2): if (exists($settings->{'linkprot'})) {
5333:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5334:2): %linkprot = %{$settings->{'linkprot'}};
5335:2): if ($linkprot{'lock'}) {
5336:2): delete($linkprot{'lock'});
5337:2): }
5338:2): }
5339:2): }
14(raebu 5340:23): } else {
18(raebu 5341:24): foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
14(raebu 5342:23): if (exists($settings->{$key})) {
5343:23): delete($settings->{$key});
5344:23): }
5345:23): }
5(raebur 5346:2): }
5347:2): }
5348:2): if ($position eq 'top') {
14(raebu 5349:23): $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
18(raebu 5350:24): } elsif ($position eq 'upper') {
14(raebu 5351:23): $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5352:23): $$rowtotal += $itemcount;
18(raebu 5353:24): } elsif ($position eq 'middle') {
5354:24): $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
5355:24): $$rowtotal += $itemcount;
14(raebu 5356:23): } elsif ($position eq 'lower') {
18(raebu 5357:24): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
14(raebu 5358:23): } else {
5359:23): my ($switchserver,$switchmessage);
5360:23): $switchserver = &check_switchserver($dom);
5361:23): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5362:23): my $maxnum = 0;
5363:23): my %ordered;
5364:23): if (ref($settings) eq 'HASH') {
5365:23): foreach my $item (keys(%{$settings})) {
5366:23): if (ref($settings->{$item}) eq 'HASH') {
5367:23): my $num = $settings->{$item}{'order'};
5368:23): if ($num eq '') {
5369:23): $num = scalar(keys(%{$settings}));
5370:23): }
5371:23): $ordered{$num} = $item;
5(raebur 5372:2): }
5373:2): }
14(raebu 5374:23): }
5375:23): $maxnum = scalar(keys(%ordered));
5376:23): my %lt = <i_names();
5377:23): if (keys(%ordered)) {
5378:23): my @items = sort { $a <=> $b } keys(%ordered);
5379:23): for (my $i=0; $i<@items; $i++) {
5380:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5381:23): my $item = $ordered{$items[$i]};
5382:23): my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5383:23): if (ref($settings->{$item}) eq 'HASH') {
5384:23): $key = $settings->{$item}->{'key'};
5385:23): $usable = $settings->{$item}->{'usable'};
5386:23): $lifetime = $settings->{$item}->{'lifetime'};
5387:23): $consumer = $settings->{$item}->{'consumer'};
5388:23): $requser = $settings->{$item}->{'requser'};
5389:23): $crsinc = $settings->{$item}->{'crsinc'};
5390:23): $current = $settings->{$item};
5391:23): }
5392:23): my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5393:23): my %checkedrequser = (
5394:23): yes => ' checked="checked"',
5395:23): no => '',
5396:23): );
5397:23): if (!$requser) {
5398:23): $checkedrequser{'no'} = $checkedrequser{'yes'};
5399:23): $checkedrequser{'yes'} = '';
5400:23): }
5401:23): my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5402:23): my %checkedcrsinc = (
5403:23): yes => ' checked="checked"',
5404:23): no => '',
5405:23): );
5406:23): if (!$crsinc) {
5407:23): $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5408:23): $checkedcrsinc{'yes'} = '';
5409:23): }
5410:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5411:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5412:23): .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5413:23): for (my $k=0; $k<=$maxnum; $k++) {
5414:23): my $vpos = $k+1;
5415:23): my $selstr;
5416:23): if ($k == $i) {
5417:23): $selstr = ' selected="selected" ';
5418:23): }
5419:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5420:23): }
5421:23): $datatable .= '</select>'.(' 'x2).
5422:23): '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5423:23): &mt('Delete?').'</label></span></td>'.
5424:23): '<td colspan="2">'.
5425:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5426:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5427:23): ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5428:23): (' 'x2).
5429:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5430:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5431:23): (' 'x2).
5432:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5433:23): 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5434:23): if ($key ne '') {
5435:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5436:23): if ($switchserver) {
5437:23): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5438:23): } else {
5439:23): $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5440:23): }
5441:23): $datatable .= '</span> '.(' 'x2);
5442:23): } elsif (!$switchserver) {
5443:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5444:23): '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5445:23): '</span> '.(' 'x2);
5446:23): }
5447:23): if ($switchserver) {
5448:23): if ($usable ne '') {
5449:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5450:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5451:23): '<span class="LC_nobreak">'.&mt('Change secret?').
5452:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5453:23): (' 'x2).
5454:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5455:23): '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5456:23): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5457:23): '</div>';
5458:23): } elsif ($key eq '') {
5459:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5460:23): } else {
5461:23): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5462:23): }
5463:23): } else {
5464:23): if ($usable ne '') {
5465:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5466:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5467:23): '<span class="LC_nobreak">'.&mt('Change?').
5468:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5469:23): (' 'x2).
5470:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5471:23): '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5472:23): '<span class="LC_nobreak">'.&mt('New Secret').':'.
5473:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5474: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>';
5475:23): } else {
5476:23): $datatable .=
5477:23): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5478:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5479: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>';
5480:23): }
5481:23): }
5482:23): $datatable .= '<br /><br />'.
5483:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5484:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5485:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5486:23): '<br /><br />'.
5487:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5488:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5489:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5490:23): (' 'x4).
5491:23): '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5492:23): '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5493:23): $itemcount ++;
5(raebur 5494:2): }
14(raebu 5495:23): }
5496:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5497:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5498:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5499:23): '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5500:23): '<select name="lti_pos_add"'.$chgstr.'>';
5501:23): for (my $k=0; $k<$maxnum+1; $k++) {
5502:23): my $vpos = $k+1;
5503:23): my $selstr;
5504:23): if ($k == $maxnum) {
5505:23): $selstr = ' selected="selected" ';
5(raebur 5506:2): }
14(raebu 5507:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5508:23): }
5509:23): $datatable .= '</select> '."\n".
5510:23): '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5511:23): '<td colspan="2">'.
5512:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5513:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5514:23): ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5515:23): (' 'x2).
5516:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5517:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5518:23): (' 'x2).
5519:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5520:23): if ($switchserver) {
5521:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5522:23): } else {
5523:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5524:23): (' 'x2).
5525:23): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5526: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";
5527:23): }
5528:23): $datatable .= '<br /><br />'.
5529:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5530:23): '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5531:23): '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5532:23): '<br /><br />'.
5533:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5534:23): '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5535:23): '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5536:23): '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5537:23): '</td>'."\n".
5538:23): '</tr>'."\n";
5539:23): $itemcount ++;
5540:23): }
5541:23): $$rowtotal += $itemcount;
5542:23): return $datatable;
5543:23): }
5544:23):
5545:23): sub lti_names {
5546:23): my %lt = &Apache::lonlocal::texthash(
5547:23): 'version' => 'LTI Version',
5548:23): 'url' => 'URL',
5549:23): 'key' => 'Key',
5550:23): 'lifetime' => 'Nonce lifetime (s)',
5551:23): 'consumer' => 'Consumer',
5552:23): 'secret' => 'Secret',
5553:23): 'requser' => "User's identity sent",
5554:23): 'crsinc' => "Course's identity sent",
5555:23): 'email' => 'Email address',
5556:23): 'sourcedid' => 'User ID',
5557:23): 'other' => 'Other',
5558:23): 'passback' => 'Can return grades to Consumer:',
5559:23): 'roster' => 'Can retrieve roster from Consumer:',
5560:23): 'topmenu' => 'Display LON-CAPA page header',
5561:23): 'inlinemenu'=> 'Display LON-CAPA inline menu',
5562:23): );
5563:23): return %lt;
5564:23): }
5565:23):
5566:23): sub lti_options {
5567:23): my ($num,$current,$itemcount,%lt) = @_;
5568:23): my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5569:23): $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5570:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5571:23): $checked{'storecrs'}{'Y'} = ' checked="checked"';
5572:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5573:23): $checked{'mapcrstype'} = {};
5574:23): $checked{'makeuser'} = {};
5575:23): $checked{'selfenroll'} = {};
5576:23): $checked{'crssec'} = {};
5577:23): $checked{'crssecsrc'} = {};
5578:23): $checked{'lcauth'} = {};
5579:23): $checked{'menuitem'} = {};
5580:23): if ($num eq 'add') {
5581:23): $checked{'lcauth'}{'lti'} = ' checked="checked"';
5582:23): }
5583:23): my $userfieldsty = 'none';
5584:23): my $crsfieldsty = 'none';
5585:23): my $crssecfieldsty = 'none';
5586:23): my $secsrcfieldsty = 'none';
5587:23): my $callbacksty = 'none';
5588:23): my $passbacksty = 'none';
5589:23): my $optionsty = 'block';
5590:23): my $crssty = 'block';
5591:23): my $lcauthparm;
5592:23): my $lcauthparmstyle = 'display:none';
5593:23): my $lcauthparmtext;
5594:23): my $menusty;
5595:23): my $numinrow = 4;
5596:23): my %menutitles = <imenu_titles();
5597:23):
5598:23): if (ref($current) eq 'HASH') {
5599:23): if (!$current->{'requser'}) {
5600:23): $optionsty = 'none';
5601:23): $crssty = 'none';
5602:23): } elsif (!$current->{'crsinc'}) {
5603:23): $crssty = 'none';
5604:23): }
5605:23): if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5606:23): $checked{'mapuser'}{'sourcedid'} = '';
5607:23): if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5608:23): $checked{'mapuser'}{'email'} = ' checked="checked"';
5(raebur 5609:2): } else {
14(raebu 5610:23): $checked{'mapuser'}{'other'} = ' checked="checked"';
5611:23): $userfield = $current->{'mapuser'};
5612:23): $userfieldsty = 'inline-block';
5(raebur 5613:2): }
14(raebu 5614:23): }
5615:23): if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5616:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5617:23): if ($current->{'mapcrs'} eq 'context_id') {
5618:23): $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5619:23): } else {
5620:23): $checked{'mapcrs'}{'other'} = ' checked="checked"';
5621:23): $cidfield = $current->{'mapcrs'};
5622:23): $crsfieldsty = 'inline-block';
5623:23): }
5624:23): }
5625:23): if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5626:23): foreach my $type (@{$current->{'mapcrstype'}}) {
5627:23): $checked{'mapcrstype'}{$type} = ' checked="checked"';
5628:23): }
5629:23): }
5630:23): if (!$current->{'storecrs'}) {
5631:23): $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5632:23): $checked{'storecrs'}{'Y'} = '';
5633:23): }
5634:23): if ($current->{'makecrs'}) {
5635:23): $checked{'makecrs'}{'Y'} = ' checked="checked"';
5636:23): }
5637:23): if (ref($current->{'makeuser'}) eq 'ARRAY') {
5638:23): foreach my $role (@{$current->{'makeuser'}}) {
5639:23): $checked{'makeuser'}{$role} = ' checked="checked"';
5640:23): }
5641:23): }
5642:23): if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5643:23): $checked{'lcauth'}{$1} = ' checked="checked"';
5644:23): unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5645:23): $lcauthparm = $current->{'lcauthparm'};
5646:23): $lcauthparmstyle = 'display:table-row';
5647:23): if ($current->{'lcauth'} eq 'localauth') {
5648:23): $lcauthparmtext = &mt('Local auth argument');
5(raebur 5649:2): } else {
14(raebu 5650:23): $lcauthparmtext = &mt('Kerberos domain');
5(raebur 5651:2): }
14(raebu 5652:23): }
5653:23): }
5654:23): if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5655:23): foreach my $role (@{$current->{'selfenroll'}}) {
5656:23): $checked{'selfenroll'}{$role} = ' checked="checked"';
5657:23): }
5658:23): }
5659:23): if (ref($current->{'maproles'}) eq 'HASH') {
5660:23): %rolemaps = %{$current->{'maproles'}};
5661:23): }
5662:23): if ($current->{'section'} ne '') {
5663:23): $checked{'crssec'}{'Y'} = ' checked="checked"';
5664:23): $crssecfieldsty = 'inline-block';
5665:23): if ($current->{'section'} eq 'course_section_sourcedid') {
5666:23): $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5(raebur 5667:2): } else {
14(raebu 5668:23): $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5669:23): $crssecsrc = $current->{'section'};
5670:23): $secsrcfieldsty = 'inline-block';
5(raebur 5671:2): }
14(raebu 5672:23): } else {
5673:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5(raebur 5674:2): }
14(raebu 5675:23): if ($current->{'callback'} ne '') {
5676:23): $callback = $current->{'callback'};
5677:23): $checked{'callback'}{'Y'} = ' checked="checked"';
5678:23): $callbacksty = 'inline-block';
5679:23): } else {
5680:23): $checked{'callback'}{'N'} = ' checked="checked"';
5681:23): }
5682:23): if ($current->{'topmenu'}) {
5683:23): $checked{'topmenu'}{'Y'} = ' checked="checked"';
5684:23): } else {
5685:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5686:23): }
5687:23): if ($current->{'inlinemenu'}) {
5688:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5689:23): } else {
5690:23): $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5691:23): }
5692:23): if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5693:23): $menusty = 'inline-block';
5694:23): if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5695:23): foreach my $item (@{$current->{'lcmenu'}}) {
5696:23): if (exists($menutitles{$item})) {
5697:23): $checked{'menuitem'}{$item} = ' checked="checked"';
5698:23): }
5699:23): }
5700:23): }
5701:23): } else {
5702:23): $menusty = 'none';
5703:23): }
5704:23): } else {
5705:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5706:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5707:23): $checked{'callback'}{'N'} = ' checked="checked"';
5708:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5709:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5710:23): $checked{'menuitem'}{'grades'} = ' checked="checked"';
5711:23): $menusty = 'inline-block';
5(raebur 5712:2): }
14(raebu 5713:23): my @coursetypes = ('official','unofficial','community','textbook','lti');
5714:23): my %coursetypetitles = &Apache::lonlocal::texthash (
5715:23): official => 'Official',
5716:23): unofficial => 'Unofficial',
5717:23): community => 'Community',
5718:23): textbook => 'Textbook',
5719:23): lti => 'LTI Provider',
5720:23): );
5721:23): my @authtypes = ('internal','krb4','krb5','localauth');
5722:23): my %shortauth = (
5723:23): internal => 'int',
5724:23): krb4 => 'krb4',
5725:23): krb5 => 'krb5',
5726:23): localauth => 'loc'
5727:23): );
5728:23): my %authnames = &authtype_names();
5729:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5730:23): my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5731:23): my @courseroles = ('cc','in','ta','ep','st');
5732:23): my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5733:23): my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5734:23): my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5735:23): my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5736:23): my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5737:23): my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5738:23): my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5739:23): my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5740:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5741:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5742:23): $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5743:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5744:23): $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5745:23): '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5746:23): '<span class="LC_nobreak">'.&mt('Parameter').': '.
5747:23): '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5748:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5749:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5750:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5751:23): foreach my $option ('sourcedid','email','other') {
5752:23): $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5753:23): $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5754:23): ($option eq 'other' ? '' : (' 'x2) );
5755:23): }
5756:23): $output .= '</span></div>'.
5757:23): '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5758:23): '<input type="text" name="lti_customuser_'.$num.'" '.
5759:23): 'value="'.$userfield.'" /></div></fieldset>'.
5760:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5761:23): foreach my $ltirole (@ltiroles) {
5762:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5763:23): $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5764:23): }
5765:23): $output .= '</fieldset>'.
5766:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5767:23): '<table>'.
5768:23): &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5769:23): '</table>'.
5770:23): '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5771:23): '<td class="LC_left_item">';
5772:23): foreach my $auth ('lti',@authtypes) {
5773:23): my $authtext;
5774:23): if ($auth eq 'lti') {
5775:23): $authtext = &mt('None');
5776:23): } else {
5777:23): $authtext = $authnames{$shortauth{$auth}};
5778:23): }
5779:23): $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5780:23): '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5781:23): $authtext.'</label></span> ';
5782:23): }
5783:23): $output .= '</td></tr>'.
5784:23): '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5785:23): '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5786:23): '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5787:23): '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5788:23): '</table></fieldset>'.
5789:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5790:23): &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5791:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5792:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5793:23): $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5794:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5795:23): $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5796:23): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5797:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5798:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5799:23): $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5800:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5801:23): $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5802:23): $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5803:23): '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5804:23): '<span class="LC_nobreak">'.&mt('Menu items').': ';
5805:23): foreach my $type ('fullname','coursetitle','role','logout','grades') {
5806:23): $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5807:23): $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5808:23): (' 'x2);
5809:23): }
5810:23): $output .= '</span></div></fieldset>'.
5811:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5812:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.
5813:23): &mt('Unique course identifier').': ';
5814:23): foreach my $option ('course_offering_sourcedid','context_id','other') {
5815:23): $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5816:23): $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5817:23): ($option eq 'other' ? '' : (' 'x2) );
5818:23): }
5819:23): $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5820:23): '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5821:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5822:23): '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5823:23): foreach my $type (@coursetypes) {
5824:23): $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5825:23): $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5826:23): (' 'x2);
5827:23): }
5828:23): $output .= '</span><br /><br />'.
5829:23): '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5830:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5831:23): $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5832:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5833:23): $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5834:23): '</fieldset>'.
5835:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5836:23): foreach my $ltirole (@lticourseroles) {
5837:23): my ($selected,$selectnone);
5838:23): if ($rolemaps{$ltirole} eq '') {
5839:23): $selectnone = ' selected="selected"';
5840:23): }
5841:23): $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5842:23): '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5843:23): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5844:23): foreach my $role (@courseroles) {
5845:23): unless ($selectnone) {
5846:23): if ($rolemaps{$ltirole} eq $role) {
5847:23): $selected = ' selected="selected"';
5848:23): } else {
5849:23): $selected = '';
5850:23): }
5851:23): }
5852:23): $output .= '<option value="'.$role.'"'.$selected.'>'.
5853:23): &Apache::lonnet::plaintext($role,'Course').
5854:23): '</option>';
5855:23): }
5856:23): $output .= '</select></td>';
5857:23): }
5858:23): $output .= '</tr></table></fieldset>'.
5859:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5860:23): '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5861:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5862:23): $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5863:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5864:23): $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5865:23): '</fieldset>'.
5866:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5867:23): foreach my $lticrsrole (@lticourseroles) {
5868:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5869:23): $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5870:23): }
5871:23): $output .= '</fieldset>'.
5872:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5873:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5874:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5875:23): $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5876:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5877:23): $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5878:23): '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5879:23): '<span class="LC_nobreak">'.&mt('From').':<label>'.
5880:23): '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5881:23): $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5882:23): &mt('Standard field').'</label>'.(' 'x2).
5883:23): '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5884:23): $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5885:23): '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5886:23): '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5887:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5888:23): my ($pb1p1chk,$pb1p0chk,$onclickpb);
5889:23): foreach my $extra ('roster','passback') {
5890:23): my $checkedon = '';
5891:23): my $checkedoff = ' checked="checked"';
5892:23): if ($extra eq 'passback') {
5893:23): $pb1p1chk = ' checked="checked"';
5894:23): $pb1p0chk = '';
5895:23): $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5896:23): } else {
5897:23): $onclickpb = '';
5898:23): }
5899:23): if (ref($current) eq 'HASH') {
5900:23): if (($current->{$extra})) {
5901:23): $checkedon = $checkedoff;
5902:23): $checkedoff = '';
5903:23): if ($extra eq 'passback') {
5904:23): $passbacksty = 'inline-block';
5905:23): }
5906:23): if ($current->{'passbackformat'} eq '1.0') {
5907:23): $pb1p0chk = ' checked="checked"';
5908:23): $pb1p1chk = '';
5909:23): }
5910:23): }
5911:23): }
5912:23): $output .= $lt{$extra}.' '.
5913:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5914:23): &mt('No').'</label>'.(' 'x2).
5915:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5916:23): &mt('Yes').'</label><br />';
5917:23): }
5918:23): $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5919:23): '<span class="LC_nobreak">'.&mt('Grade format').
5920:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5921:23): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5922:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5923:23): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5924:23): '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5925:23): $output .= '</span></div></fieldset>';
5926:23): # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5927:23): #
5928:23): # $output .= '</fieldset>'.
5929:23): # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5930:23): return $output;
5931:23): }
5932:23):
5933:23): sub ltimenu_titles {
5934:23): return &Apache::lonlocal::texthash(
5935:23): fullname => 'Full name',
5936:23): coursetitle => 'Course title',
5937:23): role => 'Role',
5938:23): logout => 'Logout',
5939:23): grades => 'Grades',
5940:23): );
5(raebur 5941:2): }
5942:2):
18(raebu 5943:24): sub linkprot_suggestions {
5944:24): my ($suggested,$itemcount) = @_;
5945:24): my $count = 0;
5946:24): my $next = 1;
5947:24): my %lt = &Apache::lonlocal::texthash(
5948:24): 'name' => 'Suggested Launcher',
5949:24): 'info' => 'Recommendations',
5950:24): );
5951:24): my ($datatable,$css_class,$dest);
5952:24): if (ref($suggested) eq 'HASH') {
5953:24): my @current = sort { $a <=> $b } keys(%{$suggested});
5954:24): $next += $current[-1];
5955:24): for (my $i=0; $i<@current; $i++) {
5956:24): my $num = $current[$i];
5957:24): my %values;
5958:24): if (ref($suggested->{$num}) eq 'HASH') {
5959:24): %values = %{$suggested->{$num}};
5960:24): } else {
5961:24): next;
5962:24): }
5963:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5964:24): $datatable .=
5965:24): '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5966:24): '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
5967:24): &mt('Delete?').'</label></span></td><td>'."\n".
5968:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
5969:24): '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
5970:24): '</fieldset></div>'.
5971:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
5972:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
5973:24): '</fieldset></div>'.
5974:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
5975:24): '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
5976:24): $$itemcount ++;
5977:24): }
5978:24): }
5979:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5980:24): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5981:24): '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
5982:24): '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5983:24): '<td>'."\n".
5984:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
5985:24): '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
5986:24): '</fieldset></div>'.
5987:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
5988:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
5989:24): '</fieldset></div>'.
5990:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
5991:24): '</td></tr>'."\n";
5992:24): return $datatable;
5993:24): }
14(raebu 5994:23):
1.121 raeburn 5995: sub print_coursedefaults {
1.139 raeburn 5996: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5997: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5998: my $itemcount = 1;
1.160.6.16 raeburn 5999: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 6000: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.118.2 15(raebu 6001:23): coursequota => 'Default cumulative quota for all group portfolio spaces in course',
1.160.6.16 raeburn 6002: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6003: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 6004: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6005: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 6006: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 6007: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 6008: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 6009: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 6010: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 6011:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
14(raebu 6012:23): domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6013:23): exttool => 'External Tools can be defined and configured in courses/communities (by type)',
7(raebur 6014:2): );
1.160.6.21 raeburn 6015: my %staticdefaults = (
6016: anonsurvey_threshold => 10,
6017: uploadquota => 500,
1.160.6.118.2 15(raebu 6018:23): coursequota => 20,
1.160.6.57 raeburn 6019: postsubmit => 60,
1.160.6.70 raeburn 6020: mysqltables => 172800,
1.160.6.118.2 14(raebu 6021:23): domexttool => 1,
6022:23): exttool => 0,
1.160.6.21 raeburn 6023: );
1.139 raeburn 6024: if ($position eq 'top') {
1.160.6.57 raeburn 6025: %defaultchecked = (
6026: 'uselcmath' => 'on',
6027: 'usejsme' => 'on',
1.160.6.115 raeburn 6028: 'inline_chem' => 'on',
1.160.6.64 raeburn 6029: 'canclone' => 'none',
1.160.6.57 raeburn 6030: );
1.160.6.115 raeburn 6031: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 6032: my $deftex = $Apache::lonnet::deftex;
6033: if (ref($settings) eq 'HASH') {
6034: if ($settings->{'texengine'}) {
6035: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6036: $deftex = $settings->{'texengine'};
6037: }
6038: }
6039: }
6040: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6041: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6042: '<span class="LC_nobreak">'.$choices{'texengine'}.
6043: '</span></td><td class="LC_right_item">'.
6044: '<select name="texengine">'."\n";
6045: my %texoptions = (
6046: MathJax => 'MathJax',
6047: mimetex => &mt('Convert to Images'),
6048: tth => &mt('TeX to HTML'),
6049: );
6050: foreach my $renderer ('MathJax','mimetex','tth') {
6051: my $selected = '';
6052: if ($renderer eq $deftex) {
6053: $selected = ' selected="selected"';
6054: }
6055: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6056: }
6057: $mathdisp .= '</select></td></tr>'."\n";
6058: $itemcount ++;
1.139 raeburn 6059: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6060: \%choices,$itemcount);
1.160.6.90 raeburn 6061: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 6062: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6063: $datatable .=
6064: '<tr'.$css_class.'><td valign="top">'.
6065: '<span class="LC_nobreak">'.$choices{'canclone'}.
6066: '</span></td><td class="LC_left_item">';
6067: my $currcanclone = 'none';
6068: my $onclick;
6069: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 6070: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 6071: none => 'No additional course requesters',
6072: domain => "Any course requester in course's domain",
6073: instcode => 'Course requests for official courses ...',
6074: );
6075: my (%codedefaults,@code_order,@posscodes);
6076: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6077: \@code_order) eq 'ok') {
6078: if (@code_order > 0) {
6079: push(@cloneoptions,'instcode');
6080: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6081: }
6082: }
6083: if (ref($settings) eq 'HASH') {
6084: if ($settings->{'canclone'}) {
6085: if (ref($settings->{'canclone'}) eq 'HASH') {
6086: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6087: if (@code_order > 0) {
6088: $currcanclone = 'instcode';
6089: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6090: }
6091: }
6092: } elsif ($settings->{'canclone'} eq 'domain') {
6093: $currcanclone = $settings->{'canclone'};
6094: }
6095: }
6096: }
6097: foreach my $option (@cloneoptions) {
6098: my ($checked,$additional);
6099: if ($currcanclone eq $option) {
6100: $checked = ' checked="checked"';
6101: }
6102: if ($option eq 'instcode') {
6103: if (@code_order) {
6104: my $show = 'none';
6105: if ($checked) {
6106: $show = 'block';
6107: }
1.160.6.118.2 14(raebu 6108:23): $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.160.6.64 raeburn 6109: &mt('Institutional codes for new and cloned course have identical:').
6110: '<br />';
6111: foreach my $item (@code_order) {
6112: my $codechk;
6113: if ($checked) {
6114: if (grep(/^\Q$item\E$/,@posscodes)) {
6115: $codechk = ' checked="checked"';
6116: }
6117: }
6118: $additional .= '<label>'.
6119: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6120: $item.'</label>';
6121: }
6122: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6123: }
6124: }
6125: $datatable .=
6126: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6127: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6128: '</label> '.$additional.'</span><br />';
6129: }
6130: $datatable .= '</td>'.
6131: '</tr>';
6132: $itemcount ++;
1.139 raeburn 6133: } else {
6134: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.118.2 15(raebu 6135:23): my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6136:23): %deftimeout,%currmysql);
1.160.6.16 raeburn 6137: my $currusecredits = 0;
1.160.6.57 raeburn 6138: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 6139:2): my $ltiauth = 0;
14(raebu 6140:23): my %domexttool;
6141:23): my %exttool;
1.160.6.30 raeburn 6142: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 6143: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 6144:2): if ($settings->{'ltiauth'}) {
6145:2): $ltiauth = 1;
6146:2): }
14(raebu 6147:23): if (ref($settings->{'domexttool'}) eq 'HASH') {
6148:23): foreach my $type (@types) {
6149:23): if ($settings->{'domexttool'}->{$type}) {
6150:23): $domexttool{$type} = ' checked="checked"';
6151:23): }
6152:23): }
6153:23): } else {
6154:23): foreach my $type (@types) {
6155:23): if ($staticdefaults{'domexttool'}) {
6156:23): $domexttool{$type} = ' checked="checked"';
6157:23): }
6158:23): }
6159:23): }
6160:23): if (ref($settings->{'exttool'}) eq 'HASH') {
6161:23): foreach my $type (@types) {
6162:23): if ($settings->{'exttool'}->{$type}) {
6163:23): $exttool{$type} = ' checked="checked"';
6164:23): }
6165:23): }
6166:23): }
1.139 raeburn 6167: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 6168: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6169: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6170: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6171: }
6172: }
1.160.6.118.2 15(raebu 6173:23): if (ref($settings->{'coursequota'}) eq 'HASH') {
6174:23): foreach my $type (keys(%{$settings->{'coursequota'}})) {
6175:23): $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6176:23): }
6177:23): }
1.160.6.16 raeburn 6178: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 6179: foreach my $type (@types) {
6180: next if ($type eq 'community');
6181: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6182: if ($defcredits{$type} ne '') {
6183: $currusecredits = 1;
6184: }
6185: }
6186: }
6187: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6188: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6189: $postsubmitclient = 0;
6190: foreach my $type (@types) {
6191: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6192: }
6193: } else {
6194: foreach my $type (@types) {
6195: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6196: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6197: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6198: } else {
6199: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6200: }
6201: } else {
6202: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6203: }
6204: }
6205: }
6206: } else {
6207: foreach my $type (@types) {
6208: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 6209: }
6210: }
1.160.6.70 raeburn 6211: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6212: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6213: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6214: }
6215: } else {
6216: foreach my $type (@types) {
6217: $currmysql{$type} = $staticdefaults{'mysqltables'};
6218: }
6219: }
1.160.6.58 raeburn 6220: } else {
6221: foreach my $type (@types) {
6222: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.118.2 14(raebu 6223:23): if ($staticdefaults{'domexttool'}) {
6224:23): $domexttool{$type} = ' checked="checked"';
6225:23): }
1.160.6.58 raeburn 6226: }
1.139 raeburn 6227: }
6228: if (!$currdefresponder) {
1.160.6.21 raeburn 6229: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6230: } elsif ($currdefresponder < 1) {
6231: $currdefresponder = 1;
6232: }
1.160.6.21 raeburn 6233: foreach my $type (@types) {
6234: if ($curruploadquota{$type} eq '') {
6235: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6236: }
1.160.6.118.2 15(raebu 6237:23): if ($currcoursequota{$type} eq '') {
6238:23): $currcoursequota{$type} = $staticdefaults{'coursequota'};
6239:23): }
1.160.6.21 raeburn 6240: }
1.139 raeburn 6241: $datatable .=
1.160.6.16 raeburn 6242: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6243: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6244: '</span></td>'.
6245: '<td class="LC_right_item"><span class="LC_nobreak">'.
6246: '<input type="text" name="anonsurvey_threshold"'.
6247: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 6248: '</td></tr>'."\n";
6249: $itemcount ++;
6250: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6251: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6252: $choices{'uploadquota'}.
6253: '</span></td>'.
6254: '<td align="right" class="LC_right_item">'.
6255: '<table><tr>';
1.160.6.21 raeburn 6256: foreach my $type (@types) {
6257: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6258: '<input type="text" name="uploadquota_'.$type.'"'.
6259: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6260: }
6261: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 6262: $itemcount ++;
1.160.6.118.2 15(raebu 6263:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6264:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6265:23): $choices{'coursequota'}.
6266:23): '</span></td>'.
6267:23): '<td style="text-align: right" class="LC_right_item">'.
6268:23): '<table><tr>';
6269:23): foreach my $type (@types) {
6270:23): $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6271:23): '<input type="text" name="coursequota_'.$type.'"'.
6272:23): ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6273:23): }
6274:23): $datatable .= '</tr></table></td></tr>'."\n";
6275:23): $itemcount ++;
1.160.6.40 raeburn 6276: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 6277: my $display = 'none';
6278: if ($currusecredits) {
6279: $display = 'block';
6280: }
6281: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 6282: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6283: foreach my $type (@types) {
6284: next if ($type eq 'community');
6285: $additional .= '<td align="center">'.&mt($type).'<br />'.
6286: '<input type="text" name="'.$type.'_credits"'.
6287: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6288: }
6289: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 6290: %defaultchecked = ('coursecredits' => 'off');
6291: @toggles = ('coursecredits');
6292: my $current = {
6293: 'coursecredits' => $currusecredits,
6294: };
6295: (my $table,$itemcount) =
6296: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6297: \%choices,$itemcount,$onclick,$additional,'left');
6298: $datatable .= $table;
6299: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6300: my $display = 'none';
6301: if ($postsubmitclient) {
6302: $display = 'block';
6303: }
6304: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 6305: &mt('Number of seconds submit is disabled').'<br />'.
6306: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6307: '<table><tr>';
1.160.6.57 raeburn 6308: foreach my $type (@types) {
6309: $additional .= '<td align="center">'.&mt($type).'<br />'.
6310: '<input type="text" name="'.$type.'_timeout" value="'.
6311: $deftimeout{$type}.'" size="5" /></td>';
6312: }
6313: $additional .= '</tr></table></div>'."\n";
6314: %defaultchecked = ('postsubmit' => 'on');
6315: @toggles = ('postsubmit');
1.160.6.70 raeburn 6316: $current = {
6317: 'postsubmit' => $postsubmitclient,
6318: };
1.160.6.57 raeburn 6319: ($table,$itemcount) =
6320: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6321: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 6322: $datatable .= $table;
1.160.6.70 raeburn 6323: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6324: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6325: $choices{'mysqltables'}.
6326: '</span></td>'.
6327: '<td align="right" class="LC_right_item">'.
6328: '<table><tr>';
6329: foreach my $type (@types) {
6330: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6331: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 6332: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 6333: }
6334: $datatable .= '</tr></table></td></tr>'."\n";
6335: $itemcount ++;
1.160.6.118.2 4(raebur 6336:2): %defaultchecked = ('ltiauth' => 'off');
6337:2): @toggles = ('ltiauth');
6338:2): $current = {
6339:2): 'ltiauth' => $ltiauth,
6340:2): };
6341:2): ($table,$itemcount) =
6342:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6343:2): \%choices,$itemcount,undef,undef,'left');
6344:2): $datatable .= $table;
14(raebu 6345:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6346:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6347:23): $choices{'domexttool'}.
6348:23): '</span></td>'.
6349:23): '<td style="text-align: right" class="LC_right_item">'.
6350:23): '<table><tr>';
6351:23): foreach my $type (@types) {
6352:23): $datatable .= '<td style="text-align: left">'.
6353:23): '<span class="LC_nobreak">'.
6354:23): '<input type="checkbox" name="domexttool"'.
6355:23): ' value="'.$type.'"'.$domexttool{$type}.' />'.
6356:23): &mt($type).'</span></td>'."\n";
6357:23): }
6358:23): $datatable .= '</tr></table></td></tr>'."\n";
4(raebur 6359:2): $itemcount ++;
14(raebu 6360:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6361:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6362:23): $choices{'exttool'}.
6363:23): '</span></td>'.
6364:23): '<td style="text-align: right" class="LC_right_item">'.
6365:23): '<table><tr>';
6366:23): foreach my $type (@types) {
6367:23): $datatable .= '<td style="text-align: left">'.
6368:23): '<span class="LC_nobreak">'.
6369:23): '<input type="checkbox" name="exttool"'.
6370:23): ' value="'.$type.'"'.$exttool{$type}.' />'.
6371:23): &mt($type).'</span></td>'."\n";
6372:23): }
6373:23): $datatable .= '</tr></table></td></tr>'."\n";
6374:23): }
6375:23): $$rowtotal += $itemcount;
6376:23): return $datatable;
6377:23): }
6378:23):
6379:23): sub print_selfenrollment {
1.160.6.37 raeburn 6380: my ($position,$dom,$settings,$rowtotal) = @_;
6381: my ($css_class,$datatable);
6382: my $itemcount = 1;
6383: my @types = ('official','unofficial','community','textbook');
6384: if (($position eq 'top') || ($position eq 'middle')) {
6385: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6386: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6387: my @rows;
6388: my $key;
6389: if ($position eq 'top') {
6390: $key = 'admin';
6391: if (ref($rowsref) eq 'ARRAY') {
6392: @rows = @{$rowsref};
6393: }
6394: } elsif ($position eq 'middle') {
6395: $key = 'default';
6396: @rows = ('types','registered','approval','limit');
6397: }
6398: foreach my $row (@rows) {
6399: if (defined($titlesref->{$row})) {
6400: $itemcount ++;
6401: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6402: $datatable .= '<tr'.$css_class.'>'.
6403: '<td>'.$titlesref->{$row}.'</td>'.
6404: '<td class="LC_left_item">'.
6405: '<table><tr>';
6406: my (%current,%currentcap);
6407: if (ref($settings) eq 'HASH') {
6408: if (ref($settings->{$key}) eq 'HASH') {
6409: foreach my $type (@types) {
6410: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6411: $current{$type} = $settings->{$key}->{$type}->{$row};
6412: }
6413: if (($row eq 'limit') && ($key eq 'default')) {
6414: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6415: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6416: }
6417: }
6418: }
6419: }
6420: }
6421: my %roles = (
6422: '0' => &Apache::lonnet::plaintext('dc'),
6423: );
6424:
6425: foreach my $type (@types) {
6426: unless (($row eq 'registered') && ($key eq 'default')) {
6427: $datatable .= '<th>'.&mt($type).'</th>';
6428: }
6429: }
6430: unless (($row eq 'registered') && ($key eq 'default')) {
6431: $datatable .= '</tr><tr>';
6432: }
6433: foreach my $type (@types) {
6434: if ($type eq 'community') {
6435: $roles{'1'} = &mt('Community personnel');
6436: } else {
6437: $roles{'1'} = &mt('Course personnel');
6438: }
6439: $datatable .= '<td style="vertical-align: top">';
6440: if ($position eq 'top') {
6441: my %checked;
6442: if ($current{$type} eq '0') {
6443: $checked{'0'} = ' checked="checked"';
6444: } else {
6445: $checked{'1'} = ' checked="checked"';
6446: }
6447: foreach my $role ('1','0') {
6448: $datatable .= '<span class="LC_nobreak"><label>'.
6449: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6450: 'value="'.$role.'"'.$checked{$role}.' />'.
6451: $roles{$role}.'</label></span> ';
6452: }
6453: } else {
6454: if ($row eq 'types') {
6455: my %checked;
6456: if ($current{$type} =~ /^(all|dom)$/) {
6457: $checked{$1} = ' checked="checked"';
6458: } else {
6459: $checked{''} = ' checked="checked"';
6460: }
6461: foreach my $val ('','dom','all') {
6462: $datatable .= '<span class="LC_nobreak"><label>'.
6463: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6464: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6465: }
6466: } elsif ($row eq 'registered') {
6467: my %checked;
6468: if ($current{$type} eq '1') {
6469: $checked{'1'} = ' checked="checked"';
6470: } else {
6471: $checked{'0'} = ' checked="checked"';
6472: }
6473: foreach my $val ('0','1') {
6474: $datatable .= '<span class="LC_nobreak"><label>'.
6475: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6476: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6477: }
6478: } elsif ($row eq 'approval') {
6479: my %checked;
6480: if ($current{$type} =~ /^([12])$/) {
6481: $checked{$1} = ' checked="checked"';
6482: } else {
6483: $checked{'0'} = ' checked="checked"';
6484: }
6485: for my $val (0..2) {
6486: $datatable .= '<span class="LC_nobreak"><label>'.
6487: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6488: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6489: }
6490: } elsif ($row eq 'limit') {
6491: my %checked;
6492: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6493: $checked{$1} = ' checked="checked"';
6494: } else {
6495: $checked{'none'} = ' checked="checked"';
6496: }
6497: my $cap;
6498: if ($currentcap{$type} =~ /^\d+$/) {
6499: $cap = $currentcap{$type};
6500: }
6501: foreach my $val ('none','allstudents','selfenrolled') {
6502: $datatable .= '<span class="LC_nobreak"><label>'.
6503: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6504: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6505: }
6506: $datatable .= '<br />'.
6507: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6508: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6509: '</span>';
6510: }
6511: }
6512: $datatable .= '</td>';
6513: }
6514: $datatable .= '</tr>';
6515: }
6516: $datatable .= '</table></td></tr>';
6517: }
6518: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 6519: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6520: }
6521: $$rowtotal += $itemcount;
6522: return $datatable;
6523: }
6524:
6525: sub print_validation_rows {
6526: my ($caller,$dom,$settings,$rowtotal) = @_;
6527: my ($itemsref,$namesref,$fieldsref);
6528: if ($caller eq 'selfenroll') {
6529: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6530: } elsif ($caller eq 'requestcourses') {
6531: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6532: }
6533: my %currvalidation;
6534: if (ref($settings) eq 'HASH') {
6535: if (ref($settings->{'validation'}) eq 'HASH') {
6536: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 6537: }
1.160.6.39 raeburn 6538: }
6539: my $datatable;
6540: my $itemcount = 0;
6541: foreach my $item (@{$itemsref}) {
6542: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6543: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6544: $namesref->{$item}.
6545: '</span></td>'.
6546: '<td class="LC_left_item">';
6547: if (($item eq 'url') || ($item eq 'button')) {
6548: $datatable .= '<span class="LC_nobreak">'.
6549: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6550: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6551: } elsif ($item eq 'fields') {
6552: my @currfields;
6553: if (ref($currvalidation{$item}) eq 'ARRAY') {
6554: @currfields = @{$currvalidation{$item}};
6555: }
6556: foreach my $field (@{$fieldsref}) {
6557: my $check = '';
6558: if (grep(/^\Q$field\E$/,@currfields)) {
6559: $check = ' checked="checked"';
6560: }
6561: $datatable .= '<span class="LC_nobreak"><label>'.
6562: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6563: ' value="'.$field.'"'.$check.' />'.$field.
6564: '</label></span> ';
6565: }
6566: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 6567: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 6568: $currvalidation{$item}.
1.160.6.37 raeburn 6569: '</textarea>';
1.160.6.39 raeburn 6570: }
6571: $datatable .= '</td></tr>'."\n";
6572: if (ref($rowtotal)) {
1.160.6.37 raeburn 6573: $itemcount ++;
6574: }
1.139 raeburn 6575: }
1.160.6.39 raeburn 6576: if ($caller eq 'requestcourses') {
6577: my %currhash;
1.160.6.51 raeburn 6578: if (ref($settings) eq 'HASH') {
6579: if (ref($settings->{'validation'}) eq 'HASH') {
6580: if ($settings->{'validation'}{'dc'} ne '') {
6581: $currhash{$settings->{'validation'}{'dc'}} = 1;
6582: }
1.160.6.39 raeburn 6583: }
6584: }
6585: my $numinrow = 2;
6586: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6587: 'validationdc',%currhash);
1.160.6.50 raeburn 6588: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 6589: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 6590: if ($numdc > 1) {
1.160.6.50 raeburn 6591: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 6592: } else {
1.160.6.50 raeburn 6593: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 6594: }
1.160.6.50 raeburn 6595: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 6596: $itemcount ++;
6597: }
6598: if (ref($rowtotal)) {
6599: $$rowtotal += $itemcount;
6600: }
1.121 raeburn 6601: return $datatable;
1.118 jms 6602: }
6603:
1.160.6.98 raeburn 6604: sub print_passwords {
6605: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6606: my ($datatable,$css_class);
6607: my $itemcount = 0;
6608: my %titles = &Apache::lonlocal::texthash (
6609: captcha => '"Forgot Password" CAPTCHA validation',
6610: link => 'Reset link expiration (hours)',
6611: case => 'Case-sensitive usernames/e-mail',
6612: prelink => 'Information required (form 1)',
6613: postlink => 'Information required (form 2)',
6614: emailsrc => 'LON-CAPA e-mail address type(s)',
6615: customtext => 'Domain specific text (HTML)',
6616: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6617: intauth_check => 'Check bcrypt cost if authenticated',
6618: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6619: permanent => 'Permanent e-mail address',
6620: critical => 'Critical notification address',
6621: notify => 'Notification address',
6622: min => 'Minimum password length',
6623: max => 'Maximum password length',
6624: chars => 'Required characters',
6625: numsaved => 'Number of previous passwords to save and disallow reuse',
6626: );
6627: if ($position eq 'top') {
6628: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6629: my $shownlinklife = 2;
6630: my $prelink = 'both';
6631: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6632: if (ref($settings) eq 'HASH') {
6633: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6634: $shownlinklife = $settings->{resetlink};
6635: }
6636: if (ref($settings->{resetcase}) eq 'ARRAY') {
6637: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6638: }
6639: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6640: $prelink = $settings->{resetprelink};
6641: }
6642: if (ref($settings->{resetpostlink}) eq 'HASH') {
6643: %postlink = %{$settings->{resetpostlink}};
6644: }
6645: if (ref($settings->{resetemail}) eq 'ARRAY') {
6646: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6647: }
6648: if ($settings->{resetremove}) {
6649: $nostdtext = 1;
6650: }
6651: if ($settings->{resetcustom}) {
6652: $customurl = $settings->{resetcustom};
6653: }
6654: } else {
6655: if (ref($types) eq 'ARRAY') {
6656: foreach my $item (@{$types}) {
6657: $casesens{$item} = 1;
6658: $postlink{$item} = ['username','email'];
6659: }
6660: }
6661: $casesens{'default'} = 1;
6662: $postlink{'default'} = ['username','email'];
6663: $prelink = 'both';
6664: %emailsrc = (
6665: permanent => 1,
6666: critical => 1,
6667: notify => 1,
6668: );
6669: }
6670: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6671: $itemcount ++;
6672: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6673: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6674: '<td class="LC_left_item">'.
6675: '<input type="textbox" value="'.$shownlinklife.'" '.
6676: 'name="passwords_link" size="3" /></td></tr>';
6677: $itemcount ++;
6678: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6679: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6680: '<td class="LC_left_item">';
6681: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6682: foreach my $item (@{$types}) {
6683: my $checkedcase;
6684: if ($casesens{$item}) {
6685: $checkedcase = ' checked="checked"';
6686: }
6687: $datatable .= '<span class="LC_nobreak"><label>'.
6688: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6689: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 6690: '</span> ';
1.160.6.98 raeburn 6691: }
6692: }
6693: my $checkedcase;
6694: if ($casesens{'default'}) {
6695: $checkedcase = ' checked="checked"';
6696: }
6697: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6698: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6699: $othertitle.'</label></span></td>';
6700: $itemcount ++;
6701: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6702: my %checkedpre = (
6703: both => ' checked="checked"',
6704: either => '',
6705: );
6706: if ($prelink eq 'either') {
6707: $checkedpre{either} = ' checked="checked"';
6708: $checkedpre{both} = '';
6709: }
6710: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6711: '<td class="LC_left_item"><span class="LC_nobreak">'.
6712: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6713: &mt('Both username and e-mail address').'</label></span> '.
6714: '<span class="LC_nobreak"><label>'.
6715: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6716: &mt('Either username or e-mail address').'</label></span></td></tr>';
6717: $itemcount ++;
6718: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6719: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6720: '<td class="LC_left_item">';
6721: my %postlinked;
6722: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6723: foreach my $item (@{$types}) {
6724: undef(%postlinked);
6725: $datatable .= '<fieldset style="display: inline-block;">'.
6726: '<legend>'.$usertypes->{$item}.'</legend>';
6727: if (ref($postlink{$item}) eq 'ARRAY') {
6728: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6729: }
6730: foreach my $field ('email','username') {
6731: my $checked;
6732: if ($postlinked{$field}) {
6733: $checked = ' checked="checked"';
6734: }
6735: $datatable .= '<span class="LC_nobreak"><label>'.
6736: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6737: $field.'"'.$checked.' />'.$field.'</label>'.
6738: '<span> ';
6739: }
6740: $datatable .= '</fieldset>';
6741: }
6742: }
6743: if (ref($postlink{'default'}) eq 'ARRAY') {
6744: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6745: }
6746: $datatable .= '<fieldset style="display: inline-block;">'.
6747: '<legend>'.$othertitle.'</legend>';
6748: foreach my $field ('email','username') {
6749: my $checked;
6750: if ($postlinked{$field}) {
6751: $checked = ' checked="checked"';
6752: }
6753: $datatable .= '<span class="LC_nobreak"><label>'.
6754: '<input type="checkbox" name="passwords_postlink_default" value="'.
6755: $field.'"'.$checked.' />'.$field.'</label>'.
6756: '<span> ';
6757: }
6758: $datatable .= '</fieldset></td></tr>';
6759: $itemcount ++;
6760: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6761: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
6762: '<td class="LC_left_item">';
6763: foreach my $type ('permanent','critical','notify') {
6764: my $checkedemail;
6765: if ($emailsrc{$type}) {
6766: $checkedemail = ' checked="checked"';
6767: }
6768: $datatable .= '<span class="LC_nobreak"><label>'.
6769: '<input type="checkbox" name="passwords_emailsrc" value="'.
6770: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
6771: '<span> ';
6772: }
6773: $datatable .= '</td></tr>';
6774: $itemcount ++;
6775: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6776: my $switchserver = &check_switchserver($dom,$confname);
6777: my ($showstd,$noshowstd);
6778: if ($nostdtext) {
6779: $noshowstd = ' checked="checked"';
6780: } else {
6781: $showstd = ' checked="checked"';
6782: }
6783: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
6784: '<td class="LC_left_item"><span class="LC_nobreak">'.
6785: &mt('Retain standard text:').
6786: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
6787: &mt('Yes').'</label>'.' '.
6788: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
6789: &mt('No').'</label></span><br />'.
6790: '<span class="LC_fontsize_small">'.
6791: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
6792: &mt('Include custom text:');
6793: if ($customurl) {
1.160.6.104 raeburn 6794: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 6795: undef,undef,undef,undef,'background-color:#ffffff');
6796: $datatable .= '<span class="LC_nobreak"> '.$link.
6797: '<label><input type="checkbox" name="passwords_custom_del"'.
6798: ' value="1" />'.&mt('Delete?').'</label></span>'.
6799: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
6800: }
6801: if ($switchserver) {
6802: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
6803: } else {
6804: $datatable .='<span class="LC_nobreak"> '.
6805: '<input type="file" name="passwords_customfile" /></span>';
6806: }
6807: $datatable .= '</td></tr>';
6808: } elsif ($position eq 'middle') {
6809: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
6810: my @items = ('intauth_cost','intauth_check','intauth_switch');
6811: my %defaults;
6812: if (ref($domconf{'defaults'}) eq 'HASH') {
6813: %defaults = %{$domconf{'defaults'}};
6814: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
6815: $defaults{'intauth_cost'} = 10;
6816: }
6817: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
6818: $defaults{'intauth_check'} = 0;
6819: }
6820: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
6821: $defaults{'intauth_switch'} = 0;
6822: }
6823: } else {
6824: %defaults = (
6825: 'intauth_cost' => 10,
6826: 'intauth_check' => 0,
6827: 'intauth_switch' => 0,
6828: );
6829: }
6830: foreach my $item (@items) {
6831: if ($itemcount%2) {
6832: $css_class = '';
6833: } else {
6834: $css_class = ' class="LC_odd_row" ';
6835: }
6836: $datatable .= '<tr'.$css_class.'>'.
6837: '<td><span class="LC_nobreak">'.$titles{$item}.
6838: '</span></td><td class="LC_left_item" colspan="3">';
6839: if ($item eq 'intauth_switch') {
6840: my @options = (0,1,2);
6841: my %optiondesc = &Apache::lonlocal::texthash (
6842: 0 => 'No',
6843: 1 => 'Yes',
6844: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
6845: );
6846: $datatable .= '<table width="100%">';
6847: foreach my $option (@options) {
6848: my $checked = ' ';
6849: if ($defaults{$item} eq $option) {
6850: $checked = ' checked="checked"';
6851: }
6852: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6853: '<label><input type="radio" name="'.$item.
6854: '" value="'.$option.'"'.$checked.' />'.
6855: $optiondesc{$option}.'</label></span></td></tr>';
6856: }
6857: $datatable .= '</table>';
6858: } elsif ($item eq 'intauth_check') {
6859: my @options = (0,1,2);
6860: my %optiondesc = &Apache::lonlocal::texthash (
6861: 0 => 'No',
6862: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
6863: 2 => 'Yes, disallow login if stored cost is less than domain default',
6864: );
6865: $datatable .= '<table width="100%">';
6866: foreach my $option (@options) {
6867: my $checked = ' ';
6868: my $onclick;
6869: if ($defaults{$item} eq $option) {
6870: $checked = ' checked="checked"';
6871: }
6872: if ($option == 2) {
6873: $onclick = ' onclick="javascript:warnIntAuth(this);"';
6874: }
6875: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
6876: '<label><input type="radio" name="'.$item.
6877: '" value="'.$option.'"'.$checked.$onclick.' />'.
6878: $optiondesc{$option}.'</label></span></td></tr>';
6879: }
6880: $datatable .= '</table>';
6881: } else {
6882: $datatable .= '<input type="text" name="'.$item.'" value="'.
6883: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
6884: }
6885: $datatable .= '</td></tr>';
6886: $itemcount ++;
6887: }
6888: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 6889:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 6890: } else {
6891: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6892: my %ownerchg = (
6893: by => {},
6894: for => {},
6895: );
6896: my %ownertitles = &Apache::lonlocal::texthash (
6897: by => 'Course owner status(es) allowed',
6898: for => 'Student status(es) allowed',
6899: );
6900: if (ref($settings) eq 'HASH') {
6901: if (ref($settings->{crsownerchg}) eq 'HASH') {
6902: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
6903: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
6904: }
6905: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
6906: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
6907: }
6908: }
6909: }
6910: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6911: $datatable .= '<tr '.$css_class.'>'.
6912: '<td>'.
6913: &mt('Requirements').'<ul>'.
6914: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
6915: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
6916: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
6917: '<li>'.&mt('User, course, and student share same domain').'</li>'.
6918: '</ul>'.
6919: '</td>'.
6920: '<td class="LC_left_item">';
6921: foreach my $item ('by','for') {
6922: $datatable .= '<fieldset style="display: inline-block;">'.
6923: '<legend>'.$ownertitles{$item}.'</legend>';
6924: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6925: foreach my $type (@{$types}) {
6926: my $checked;
6927: if ($ownerchg{$item}{$type}) {
6928: $checked = ' checked="checked"';
6929: }
6930: $datatable .= '<span class="LC_nobreak"><label>'.
6931: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
6932: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 6933: '</span> ';
1.160.6.98 raeburn 6934: }
6935: }
6936: my $checked;
6937: if ($ownerchg{$item}{'default'}) {
6938: $checked = ' checked="checked"';
6939: }
6940: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6941: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
6942: $othertitle.'</label></span></fieldset>';
6943: }
6944: $datatable .= '</td></tr>';
6945: }
6946: return $datatable;
6947: }
6948:
1.160.6.118.2 5(raebur 6949:2): sub password_rules {
6950:2): my ($prefix,$itemcountref,$settings) = @_;
6951:2): my ($min,$max,%chars,$numsaved,$numinrow);
6952:2): my %titles;
6953:2): if ($prefix eq 'passwords') {
6954:2): %titles = &Apache::lonlocal::texthash (
6955:2): min => 'Minimum password length',
6956:2): max => 'Maximum password length',
6957:2): chars => 'Required characters',
6958:2): );
14(raebu 6959:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 6960:2): %titles = &Apache::lonlocal::texthash (
6961:2): min => 'Minimum secret length',
6962:2): max => 'Maximum secret length',
6963:2): chars => 'Required characters',
6964:2): );
6965:2): }
6966:2): $min = $Apache::lonnet::passwdmin;
6967:2): my $datatable;
6968:2): my $itemcount;
6969:2): if (ref($itemcountref)) {
6970:2): $itemcount = $$itemcountref;
6971:2): }
6972:2): if (ref($settings) eq 'HASH') {
6973:2): if ($settings->{min}) {
6974:2): $min = $settings->{min};
6975:2): }
6976:2): if ($settings->{max}) {
6977:2): $max = $settings->{max};
6978:2): }
6979:2): if (ref($settings->{chars}) eq 'ARRAY') {
6980:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
6981:2): }
6982:2): if ($prefix eq 'passwords') {
6983:2): if ($settings->{numsaved}) {
6984:2): $numsaved = $settings->{numsaved};
6985:2): }
6986:2): }
6987:2): }
6988:2): my %rulenames = &Apache::lonlocal::texthash(
6989:2): uc => 'At least one upper case letter',
6990:2): lc => 'At least one lower case letter',
6991:2): num => 'At least one number',
6992:2): spec => 'At least one non-alphanumeric',
6993:2): );
6994:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
6995:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
6996:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
6997:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
6998:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
6999:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7000:2): '</span></td></tr>';
7001:2): $itemcount ++;
7002:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7003:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7004:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7005:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7006:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7007:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7008:2): '</span></td></tr>';
7009:2): $itemcount ++;
7010:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7011:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7012:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7013:2): '</span></td>';
7014:2): my $numinrow = 2;
7015:2): my @possrules = ('uc','lc','num','spec');
7016:2): $datatable .= '<td class="LC_left_item"><table>';
7017:2): for (my $i=0; $i<@possrules; $i++) {
7018:2): my ($rem,$checked);
7019:2): if ($chars{$possrules[$i]}) {
7020:2): $checked = ' checked="checked"';
7021:2): }
7022:2): $rem = $i%($numinrow);
7023:2): if ($rem == 0) {
7024:2): if ($i > 0) {
7025:2): $datatable .= '</tr>';
7026:2): }
7027:2): $datatable .= '<tr>';
7028:2): }
7029:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
7030:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7031:2): $rulenames{$possrules[$i]}.'</label></span></td>';
7032:2): }
7033:2): my $rem = @possrules%($numinrow);
7034:2): my $colsleft = $numinrow - $rem;
7035:2): if ($colsleft > 1 ) {
7036:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7037:2): ' </td>';
7038:2): } elsif ($colsleft == 1) {
7039:2): $datatable .= '<td class="LC_left_item"> </td>';
7040:2): }
7041:2): $datatable .='</table></td></tr>';
7042:2): $itemcount ++;
7043:2): if ($prefix eq 'passwords') {
7044:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7045:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7046:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7047:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7048:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7049:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7050:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7051:2): '</span></td></tr>';
7052:2): $itemcount ++;
7053:2): }
7054:2): if (ref($itemcountref)) {
7055:2): $$itemcountref += $itemcount;
7056:2): }
7057:2): return $datatable;
7058:2): }
7059:2):
1.160.6.113 raeburn 7060: sub print_wafproxy {
7061: my ($position,$dom,$settings,$rowtotal) = @_;
7062: my $css_class;
7063: my $itemcount = 0;
7064: my $datatable;
7065: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7066: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
7067: my %lt = &wafproxy_titles();
7068: foreach my $server (sort(keys(%servers))) {
7069: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7070: next if ($serverhome eq '');
7071: my $serverdom;
7072: if ($serverhome ne $server) {
7073: $serverdom = &Apache::lonnet::host_domain($serverhome);
7074: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7075: $othercontrol{$server} = $serverdom;
7076: }
7077: } else {
7078: $serverdom = &Apache::lonnet::host_domain($server);
7079: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7080: if ($serverdom ne $dom) {
7081: $othercontrol{$server} = $serverdom;
7082: } else {
7083: $setdom = 1;
7084: if (ref($settings) eq 'HASH') {
7085: if (ref($settings->{'alias'}) eq 'HASH') {
7086: $aliases{$dom} = $settings->{'alias'};
7087: if ($aliases{$dom} ne '') {
7088: $showdom = 1;
7089: }
7090: }
7091: if (ref($settings->{'saml'}) eq 'HASH') {
7092: $saml{$dom} = $settings->{'saml'};
7093: }
7094: }
7095: }
7096: }
7097: }
7098: if ($setdom) {
7099: %{$values{$dom}} = ();
7100: if (ref($settings) eq 'HASH') {
7101: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7102: $values{$dom}{$item} = $settings->{$item};
7103: }
7104: }
7105: }
7106: if (keys(%othercontrol)) {
7107: %otherdoms = reverse(%othercontrol);
7108: foreach my $domain (keys(%otherdoms)) {
7109: %{$values{$domain}} = ();
7110: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7111: if (ref($config{'wafproxy'}) eq 'HASH') {
7112: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7113: if (exists($config{'wafproxy'}{'saml'})) {
7114: $saml{$domain} = $config{'wafproxy'}{'saml'};
7115: }
7116: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7117: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7118: }
7119: }
7120: }
7121: }
7122: if ($position eq 'top') {
7123: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7124: my %aliasinfo;
7125: foreach my $server (sort(keys(%servers))) {
7126: $itemcount ++;
7127: my $dom_in_effect;
7128: my $aliasrows = '<tr>'.
7129: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.118.2 17(raebu 7130:24): &mt('Hostname').': '.
16(raebu 7131:24): '<span class="LC_nobreak LC_cusr_emph">'.
7132:24): &Apache::lonnet::hostname($server).'</span></td><td> </td>';
1.160.6.113 raeburn 7133: if ($othercontrol{$server}) {
7134: $dom_in_effect = $othercontrol{$server};
7135: my ($current,$forsaml);
7136: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7137: $current = $aliases{$dom_in_effect}{$server};
7138: }
7139: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7140: if ($saml{$dom_in_effect}{$server}) {
7141: $forsaml = 1;
7142: }
7143: }
7144: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7145: &mt('Alias').': ';
7146: if ($current) {
7147: $aliasrows .= $current;
7148: if ($forsaml) {
7149: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7150: }
7151: } else {
7152: $aliasrows .= &mt('None');
7153: }
7154: $aliasrows .= ' <span class="LC_small">('.
7155: &mt('controlled by domain: [_1]',
7156: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7157: } else {
7158: $dom_in_effect = $dom;
7159: my ($current,$samlon,$samloff);
7160: $samloff = ' checked="checked"';
7161: if (ref($aliases{$dom}) eq 'HASH') {
7162: if ($aliases{$dom}{$server}) {
7163: $current = $aliases{$dom}{$server};
7164: }
7165: }
7166: if (ref($saml{$dom}) eq 'HASH') {
7167: if ($saml{$dom}{$server}) {
7168: $samlon = $samloff;
7169: undef($samloff);
7170: }
7171: }
7172: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7173: &mt('Alias').': '.
7174: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7175: 'value="'.$current.'" size="30" />'.
7176: (' 'x2).'<span class="LC_nobreak">'.
7177: &mt('Alias used for SSO Auth').': <label>'.
7178: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7179: &mt('No').'</label> <label>'.
7180: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7181: &mt('Yes').'</label></span>'.
7182: '</td>';
7183: }
7184: $aliasrows .= '</tr>';
7185: $aliasinfo{$dom_in_effect} .= $aliasrows;
7186: }
7187: if ($aliasinfo{$dom}) {
7188: my ($onclick,$wafon,$wafoff,$showtable);
7189: $onclick = ' onclick="javascript:toggleWAF();"';
7190: $wafoff = ' checked="checked"';
7191: $showtable = ' style="display:none";';
7192: if ($showdom) {
7193: $wafon = $wafoff;
7194: $wafoff = '';
7195: $showtable = ' style="display:inline;"';
7196: }
7197: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7198: $datatable = '<tr'.$css_class.'>'.
7199: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7200: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7201: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7202: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7203: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7204: &mt('No').'</label></span></td>'.
7205: '<td class="LC_left_item">'.
7206: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7207: '</table></td></tr>';
7208: $itemcount++;
7209: }
7210: if (keys(%otherdoms)) {
7211: foreach my $key (sort(keys(%otherdoms))) {
7212: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7213: $datatable .= '<tr'.$css_class.'>'.
7214: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7215: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7216: '</table></td></tr>';
7217: $itemcount++;
7218: }
7219: }
7220: } else {
7221: my %ip_methods = &remoteip_methods();
7222: if ($setdom) {
7223: $itemcount ++;
7224: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7225: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7226: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7227: $wafstyle = ' style="display:none;"';
7228: $nowafstyle = ' style="display:table-row;"';
7229: $currwafdisplay = ' style="display: none"';
7230: $wafrangestyle = ' style="display: none"';
7231: $curr_remotip = 'n';
7232: $ssltossl = ' checked="checked"';
7233: if ($showdom) {
7234: $wafstyle = ' style="display:table-row;"';
7235: $nowafstyle = ' style="display:none;"';
7236: if (keys(%{$values{$dom}})) {
7237: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7238: $curr_remotip = $values{$dom}{remoteip};
7239: }
7240: if ($curr_remotip eq 'h') {
7241: $currwafdisplay = ' style="display:table-row"';
7242: $wafrangestyle = ' style="display:inline-block;"';
7243: }
7244: if ($values{$dom}{'sslopt'}) {
7245: $alltossl = ' checked="checked"';
7246: $ssltossl = '';
7247: }
7248: }
7249: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7250: $vpndircheck = ' checked="checked"';
7251: $currwafvpn = ' style="display:table-row;"';
7252: $wafrangestyle = ' style="display:inline-block;"';
7253: } else {
7254: $vpnaliascheck = ' checked="checked"';
7255: $currwafvpn = ' style="display:none;"';
7256: }
7257: }
7258: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7259: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7260: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7261: '</tr>'.
7262: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7263: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7264: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7265: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7266: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7267: '<td class="LC_left_item"><table>'.
7268: '<tr>'.
7269: '<td valign="top">'.$lt{'remoteip'}.': '.
7270: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7271: foreach my $option ('m','h','n') {
7272: my $sel;
1.160.6.114 raeburn 7273: if ($option eq $curr_remotip) {
7274: $sel = ' selected="selected"';
7275: }
7276: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7277: $ip_methods{$option}.'</option>';
7278: }
7279: $datatable .= '</select></td></tr>'."\n".
7280: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7281: $lt{'ipheader'}.': '.
7282: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7283: 'name="wafproxy_ipheader" />'.
7284: '</td></tr>'."\n".
7285: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7286: $lt{'trusted'}.':<br />'.
7287: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7288: $values{$dom}{'trusted'}.'</textarea>'.
7289: '</td></tr>'."\n".
7290: '<tr><td><hr /></td></tr>'."\n".
7291: '<tr>'.
1.160.6.113 raeburn 7292: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7293: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7294: $lt{'vpndirect'}.'</label>'.(' 'x2).
7295: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7296: $lt{'vpnaliased'}.'</label></span></td></tr>';
7297: foreach my $item ('vpnint','vpnext') {
7298: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7299: '<td valign="top">'.$lt{$item}.':<br />'.
7300: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7301: $values{$dom}{$item}.'</textarea>'.
7302: '</td></tr>'."\n";
7303: }
7304: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7305: '<tr>'.
7306: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7307: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7308: $lt{'alltossl'}.'</label>'.(' 'x2).
7309: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7310: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7311: '</table></td></tr>';
7312: }
7313: if (keys(%otherdoms)) {
7314: foreach my $domain (sort(keys(%otherdoms))) {
7315: $itemcount ++;
7316: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7317: $datatable .= '<tr'.$css_class.'>'.
7318: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7319: '<td class="LC_left_item"><table>';
7320: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7321: my $showval = &mt('None');
7322: if ($item eq 'ssl') {
7323: $showval = $lt{'ssltossl'};
7324: }
7325: if ($values{$domain}{$item}) {
7326: $showval = $values{$domain}{$item};
7327: if ($item eq 'ssl') {
7328: $showval = $lt{'alltossl'};
7329: } elsif ($item eq 'remoteip') {
7330: $showval = $ip_methods{$values{$domain}{$item}};
7331: }
7332: }
7333: $datatable .= '<tr>'.
7334: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7335: }
7336: $datatable .= '</table></td></tr>';
7337: }
7338: }
7339: }
7340: $$rowtotal += $itemcount;
7341: return $datatable;
7342: }
7343:
7344: sub wafproxy_titles {
7345: return &Apache::lonlocal::texthash(
7346: remoteip => "Method for determining user's IP",
7347: ipheader => 'Request header containing remote IP',
7348: trusted => 'Trusted IP range(s)',
7349: vpnaccess => 'Access from institutional VPN',
7350: vpndirect => 'via regular hostname (no WAF)',
7351: vpnaliased => 'via aliased hostname (WAF)',
7352: vpnint => 'Internal IP Range(s) for VPN sessions',
7353: vpnext => 'IP Range(s) for backend WAF connections',
7354: sslopt => 'Forwarding http/https',
7355: alltossl => 'WAF forwards both http and https requests to https',
7356: ssltossl => 'WAF forwards http requests to http and https to https',
7357: );
7358: }
7359:
7360: sub remoteip_methods {
7361: return &Apache::lonlocal::texthash(
7362: m => 'Use Apache mod_remoteip',
7363: h => 'Use headers parsed by LON-CAPA',
7364: n => 'Not in use',
7365: );
7366: }
7367:
1.137 raeburn 7368: sub print_usersessions {
7369: my ($position,$dom,$settings,$rowtotal) = @_;
7370: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 7371: my (%by_ip,%by_location,@intdoms);
7372: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 7373:
7374: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7375: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7376: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7377: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7378: my $itemcount = 1;
7379: if ($position eq 'top') {
1.152 raeburn 7380: if (keys(%serverhomes) > 1) {
1.145 raeburn 7381: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 7382: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 7383: if (ref($settings) eq 'HASH') {
7384: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7385: $curroffloadnow = $settings->{'offloadnow'};
7386: }
1.160.6.105 raeburn 7387: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7388: $curroffloadoth = $settings->{'offloadoth'};
7389: }
1.160.6.61 raeburn 7390: }
1.160.6.105 raeburn 7391: my $other_insts = scalar(keys(%by_location));
7392: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7393: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7394: } else {
1.140 raeburn 7395: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7396:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7397:23): '</td></tr>';
1.140 raeburn 7398: }
1.137 raeburn 7399: } else {
1.145 raeburn 7400: if (keys(%by_location) == 0) {
7401: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7402:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7403:23): '</td></tr>';
1.145 raeburn 7404: } else {
7405: my %lt = &usersession_titles();
7406: my $numinrow = 5;
7407: my $prefix;
7408: my @types;
7409: if ($position eq 'bottom') {
7410: $prefix = 'remote';
7411: @types = ('version','excludedomain','includedomain');
7412: } else {
7413: $prefix = 'hosted';
7414: @types = ('excludedomain','includedomain');
7415: }
7416: my (%current,%checkedon,%checkedoff);
7417: my @lcversions = &Apache::lonnet::all_loncaparevs();
7418: my @locations = sort(keys(%by_location));
7419: foreach my $type (@types) {
7420: $checkedon{$type} = '';
7421: $checkedoff{$type} = ' checked="checked"';
7422: }
7423: if (ref($settings) eq 'HASH') {
7424: if (ref($settings->{$prefix}) eq 'HASH') {
7425: foreach my $key (keys(%{$settings->{$prefix}})) {
7426: $current{$key} = $settings->{$prefix}{$key};
7427: if ($key eq 'version') {
7428: if ($current{$key} ne '') {
7429: $checkedon{$key} = ' checked="checked"';
7430: $checkedoff{$key} = '';
7431: }
7432: } elsif (ref($current{$key}) eq 'ARRAY') {
7433: $checkedon{$key} = ' checked="checked"';
7434: $checkedoff{$key} = '';
7435: }
1.137 raeburn 7436: }
7437: }
7438: }
1.145 raeburn 7439: foreach my $type (@types) {
7440: next if ($type ne 'version' && !@locations);
7441: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7442: $datatable .= '<tr'.$css_class.'>
7443: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7444: <span class="LC_nobreak">
7445: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7446: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7447: if ($type eq 'version') {
7448: my $selector = '<select name="'.$prefix.'_version">';
7449: foreach my $version (@lcversions) {
7450: my $selected = '';
7451: if ($current{'version'} eq $version) {
7452: $selected = ' selected="selected"';
7453: }
7454: $selector .= ' <option value="'.$version.'"'.
7455: $selected.'>'.$version.'</option>';
7456: }
7457: $selector .= '</select> ';
7458: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7459: } else {
7460: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7461: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7462: ' />'.(' 'x2).
7463: '<input type="button" value="'.&mt('uncheck all').'" '.
7464: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7465: "\n".
7466: '</div><div><table>';
7467: my $rem;
7468: for (my $i=0; $i<@locations; $i++) {
7469: my ($showloc,$value,$checkedtype);
7470: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7471: my $ip = $by_location{$locations[$i]}->[0];
7472: if (ref($by_ip{$ip}) eq 'ARRAY') {
7473: $value = join(':',@{$by_ip{$ip}});
7474: $showloc = join(', ',@{$by_ip{$ip}});
7475: if (ref($current{$type}) eq 'ARRAY') {
7476: foreach my $loc (@{$by_ip{$ip}}) {
7477: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7478: $checkedtype = ' checked="checked"';
7479: last;
7480: }
7481: }
1.138 raeburn 7482: }
7483: }
7484: }
1.145 raeburn 7485: $rem = $i%($numinrow);
7486: if ($rem == 0) {
7487: if ($i > 0) {
7488: $datatable .= '</tr>';
7489: }
7490: $datatable .= '<tr>';
7491: }
7492: $datatable .= '<td class="LC_left_item">'.
7493: '<span class="LC_nobreak"><label>'.
7494: '<input type="checkbox" name="'.$prefix.'_'.$type.
7495: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7496: '</label></span></td>';
1.137 raeburn 7497: }
1.145 raeburn 7498: $rem = @locations%($numinrow);
7499: my $colsleft = $numinrow - $rem;
7500: if ($colsleft > 1 ) {
7501: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7502: ' </td>';
7503: } elsif ($colsleft == 1) {
7504: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7505: }
1.145 raeburn 7506: $datatable .= '</tr></table>';
1.137 raeburn 7507: }
1.145 raeburn 7508: $datatable .= '</td></tr>';
7509: $itemcount ++;
1.137 raeburn 7510: }
7511: }
7512: }
7513: $$rowtotal += $itemcount;
7514: return $datatable;
7515: }
7516:
1.138 raeburn 7517: sub build_location_hashes {
7518: my ($intdoms,$by_ip,$by_location) = @_;
7519: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7520: (ref($by_location) eq 'HASH'));
7521: my %iphost = &Apache::lonnet::get_iphost();
7522: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7523: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7524: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7525: foreach my $id (@{$iphost{$primary_ip}}) {
7526: my $intdom = &Apache::lonnet::internet_dom($id);
7527: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7528: push(@{$intdoms},$intdom);
7529: }
7530: }
7531: }
7532: foreach my $ip (keys(%iphost)) {
7533: if (ref($iphost{$ip}) eq 'ARRAY') {
7534: foreach my $id (@{$iphost{$ip}}) {
7535: my $location = &Apache::lonnet::internet_dom($id);
7536: if ($location) {
7537: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7538: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7539: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7540: push(@{$by_ip->{$ip}},$location);
7541: }
7542: } else {
7543: $by_ip->{$ip} = [$location];
7544: }
7545: }
7546: }
7547: }
7548: }
7549: foreach my $ip (sort(keys(%{$by_ip}))) {
7550: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7551: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7552: my $first = $by_ip->{$ip}->[0];
7553: if (ref($by_location->{$first}) eq 'ARRAY') {
7554: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7555: push(@{$by_location->{$first}},$ip);
7556: }
7557: } else {
7558: $by_location->{$first} = [$ip];
7559: }
7560: }
7561: }
7562: return;
7563: }
7564:
1.145 raeburn 7565: sub current_offloads_to {
7566: my ($dom,$settings,$servers) = @_;
7567: my (%spareid,%otherdomconfigs);
1.152 raeburn 7568: if (ref($servers) eq 'HASH') {
1.145 raeburn 7569: foreach my $lonhost (sort(keys(%{$servers}))) {
7570: my $gotspares;
1.152 raeburn 7571: if (ref($settings) eq 'HASH') {
7572: if (ref($settings->{'spares'}) eq 'HASH') {
7573: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7574: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7575: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7576: $gotspares = 1;
7577: }
1.145 raeburn 7578: }
7579: }
7580: unless ($gotspares) {
7581: my $gotspares;
7582: my $serverhomeID =
7583: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7584: my $serverhomedom =
7585: &Apache::lonnet::host_domain($serverhomeID);
7586: if ($serverhomedom ne $dom) {
7587: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7588: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7589: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7590: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7591: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7592: $gotspares = 1;
7593: }
7594: }
7595: } else {
7596: $otherdomconfigs{$serverhomedom} =
7597: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7598: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7599: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7600: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7601: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7602: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7603: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7604: $gotspares = 1;
7605: }
7606: }
7607: }
7608: }
7609: }
7610: }
7611: }
7612: unless ($gotspares) {
7613: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7614: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7615: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7616: } else {
7617: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7618: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7619: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7620: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7621: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7622: } else {
1.150 raeburn 7623: my %what = (
7624: spareid => 1,
7625: );
7626: my ($result,$returnhash) =
7627: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7628: if ($result eq 'ok') {
7629: if (ref($returnhash) eq 'HASH') {
7630: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7631: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7632: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7633: }
7634: }
1.145 raeburn 7635: }
7636: }
7637: }
7638: }
7639: }
7640: }
7641: return %spareid;
7642: }
7643:
7644: sub spares_row {
1.160.6.105 raeburn 7645: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7646: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7647: my $css_class;
7648: my $numinrow = 4;
7649: my $itemcount = 1;
7650: my $datatable;
1.152 raeburn 7651: my %typetitles = &sparestype_titles();
7652: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7653: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7654: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7655: my ($othercontrol,$serverdom);
7656: if ($serverhome ne $server) {
7657: $serverdom = &Apache::lonnet::host_domain($serverhome);
7658: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7659: } else {
7660: $serverdom = &Apache::lonnet::host_domain($server);
7661: if ($serverdom ne $dom) {
7662: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7663: }
7664: }
7665: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 7666: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 7667: if (ref($curroffloadnow) eq 'HASH') {
7668: if ($curroffloadnow->{$server}) {
7669: $checkednow = ' checked="checked"';
7670: }
7671: }
1.160.6.105 raeburn 7672: if (ref($curroffloadoth) eq 'HASH') {
7673: if ($curroffloadoth->{$server}) {
7674: $checkedoth = ' checked="checked"';
7675: }
7676: }
1.145 raeburn 7677: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7678: $datatable .= '<tr'.$css_class.'>
7679: <td rowspan="2">
1.160.6.13 raeburn 7680: <span class="LC_nobreak">'.
7681: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 7682: ,'<b>'.$server.'</b>').'</span><br />'.
7683: '<span class="LC_nobreak">'."\n".
7684: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 7685: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 7686: "\n";
1.160.6.105 raeburn 7687: if ($other_insts) {
7688: $datatable .= '<br />'.
7689: '<span class="LC_nobreak">'."\n".
7690: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7691: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7692: "\n";
7693: }
1.145 raeburn 7694: my (%current,%canselect);
1.152 raeburn 7695: my @choices =
7696: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7697: foreach my $type ('primary','default') {
7698: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7699: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7700: my @spares = @{$spareid->{$server}{$type}};
7701: if (@spares > 0) {
1.152 raeburn 7702: if ($othercontrol) {
7703: $current{$type} = join(', ',@spares);
7704: } else {
7705: $current{$type} .= '<table>';
7706: my $numspares = scalar(@spares);
7707: for (my $i=0; $i<@spares; $i++) {
7708: my $rem = $i%($numinrow);
7709: if ($rem == 0) {
7710: if ($i > 0) {
7711: $current{$type} .= '</tr>';
7712: }
7713: $current{$type} .= '<tr>';
1.145 raeburn 7714: }
1.152 raeburn 7715: $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'".');" /> '.
7716: $spareid->{$server}{$type}[$i].
7717: '</label></td>'."\n";
7718: }
7719: my $rem = @spares%($numinrow);
7720: my $colsleft = $numinrow - $rem;
7721: if ($colsleft > 1 ) {
7722: $current{$type} .= '<td colspan="'.$colsleft.
7723: '" class="LC_left_item">'.
7724: ' </td>';
7725: } elsif ($colsleft == 1) {
7726: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7727: }
1.152 raeburn 7728: $current{$type} .= '</tr></table>';
1.150 raeburn 7729: }
1.145 raeburn 7730: }
7731: }
7732: if ($current{$type} eq '') {
7733: $current{$type} = &mt('None specified');
7734: }
1.152 raeburn 7735: if ($othercontrol) {
7736: if ($type eq 'primary') {
7737: $canselect{$type} = $othercontrol;
7738: }
7739: } else {
7740: $canselect{$type} =
7741: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7742: '<select name="newspare_'.$type.'_'.$server.'" '.
7743: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7744: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7745: if (@choices > 0) {
7746: foreach my $lonhost (@choices) {
7747: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7748: }
7749: }
7750: $canselect{$type} .= '</select>'."\n";
7751: }
7752: } else {
7753: $current{$type} = &mt('Could not be determined');
7754: if ($type eq 'primary') {
7755: $canselect{$type} = $othercontrol;
7756: }
1.145 raeburn 7757: }
1.152 raeburn 7758: if ($type eq 'default') {
7759: $datatable .= '<tr'.$css_class.'>';
7760: }
7761: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
7762: '<td>'.$current{$type}.'</td>'."\n".
7763: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 7764: }
7765: $itemcount ++;
7766: }
7767: }
7768: $$rowtotal += $itemcount;
7769: return $datatable;
7770: }
7771:
1.152 raeburn 7772: sub possible_newspares {
7773: my ($server,$currspares,$serverhomes,$altids) = @_;
7774: my $serverhostname = &Apache::lonnet::hostname($server);
7775: my %excluded;
7776: if ($serverhostname ne '') {
7777: %excluded = (
7778: $serverhostname => 1,
7779: );
7780: }
7781: if (ref($currspares) eq 'HASH') {
7782: foreach my $type (keys(%{$currspares})) {
7783: if (ref($currspares->{$type}) eq 'ARRAY') {
7784: if (@{$currspares->{$type}} > 0) {
7785: foreach my $curr (@{$currspares->{$type}}) {
7786: my $hostname = &Apache::lonnet::hostname($curr);
7787: $excluded{$hostname} = 1;
7788: }
7789: }
7790: }
7791: }
7792: }
7793: my @choices;
7794: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
7795: if (keys(%{$serverhomes}) > 1) {
7796: foreach my $name (sort(keys(%{$serverhomes}))) {
7797: unless ($excluded{$name}) {
7798: if (exists($altids->{$serverhomes->{$name}})) {
7799: push(@choices,$altids->{$serverhomes->{$name}});
7800: } else {
7801: push(@choices,$serverhomes->{$name});
1.145 raeburn 7802: }
7803: }
7804: }
7805: }
7806: }
1.152 raeburn 7807: return sort(@choices);
1.145 raeburn 7808: }
7809:
1.150 raeburn 7810: sub print_loadbalancing {
7811: my ($dom,$settings,$rowtotal) = @_;
7812: my $primary_id = &Apache::lonnet::domain($dom,'primary');
7813: my $intdom = &Apache::lonnet::internet_dom($primary_id);
7814: my $numinrow = 1;
7815: my $datatable;
7816: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 7817: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 7818: if (ref($settings) eq 'HASH') {
7819: %existing = %{$settings};
7820: }
7821: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
7822: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 7823: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 7824: } else {
7825: return;
7826: }
7827: my ($othertitle,$usertypes,$types) =
7828: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 7829: my $rownum = 8;
1.150 raeburn 7830: if (ref($types) eq 'ARRAY') {
7831: $rownum += scalar(@{$types});
7832: }
1.160.6.7 raeburn 7833: my @css_class = ('LC_odd_row','LC_even_row');
7834: my $balnum = 0;
7835: my $islast;
7836: my (@toshow,$disabledtext);
7837: if (keys(%currbalancer) > 0) {
7838: @toshow = sort(keys(%currbalancer));
7839: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
7840: push(@toshow,'');
7841: }
7842: } else {
7843: @toshow = ('');
7844: $disabledtext = &mt('No existing load balancer');
7845: }
7846: foreach my $lonhost (@toshow) {
7847: if ($balnum == scalar(@toshow)-1) {
7848: $islast = 1;
7849: } else {
7850: $islast = 0;
7851: }
7852: my $cssidx = $balnum%2;
7853: my $targets_div_style = 'display: none';
7854: my $disabled_div_style = 'display: block';
7855: my $homedom_div_style = 'display: none';
7856: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
7857: '<td rowspan="'.$rownum.'" valign="top">'.
7858: '<p>';
7859: if ($lonhost eq '') {
7860: $datatable .= '<span class="LC_nobreak">';
7861: if (keys(%currbalancer) > 0) {
7862: $datatable .= &mt('Add balancer:');
7863: } else {
7864: $datatable .= &mt('Enable balancer:');
7865: }
7866: $datatable .= ' '.
7867: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
7868: ' id="loadbalancing_lonhost_'.$balnum.'"'.
7869: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
7870: '<option value="" selected="selected">'.&mt('None').
7871: '</option>'."\n";
7872: foreach my $server (sort(keys(%servers))) {
7873: next if ($currbalancer{$server});
7874: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
7875: }
7876: $datatable .=
7877: '</select>'."\n".
7878: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
7879: } else {
7880: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
7881: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
7882: &mt('Stop balancing').'</label>'.
7883: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
7884: $targets_div_style = 'display: block';
7885: $disabled_div_style = 'display: none';
7886: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
7887: $homedom_div_style = 'display: block';
7888: }
7889: }
7890: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
7891: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
7892: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
7893: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
7894: my ($numspares,@spares) = &count_servers($lonhost,%servers);
7895: my @sparestypes = ('primary','default');
7896: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 7897: my %hostherechecked = (
7898: no => ' checked="checked"',
7899: );
1.160.6.94 raeburn 7900: my %balcookiechecked = (
7901: no => ' checked="checked"',
7902: );
1.160.6.7 raeburn 7903: foreach my $sparetype (@sparestypes) {
7904: my $targettable;
7905: for (my $i=0; $i<$numspares; $i++) {
7906: my $checked;
7907: if (ref($currtargets{$lonhost}) eq 'HASH') {
7908: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7909: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7910: $checked = ' checked="checked"';
7911: }
7912: }
7913: }
7914: my ($chkboxval,$disabled);
7915: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
7916: $chkboxval = $spares[$i];
7917: }
7918: if (exists($currbalancer{$spares[$i]})) {
7919: $disabled = ' disabled="disabled"';
7920: }
7921: $targettable .=
1.160.6.55 raeburn 7922: '<td><span class="LC_nobreak"><label>'.
7923: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 7924: $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 7925: '</span></label></span></td>';
1.160.6.7 raeburn 7926: my $rem = $i%($numinrow);
7927: if ($rem == 0) {
7928: if (($i > 0) && ($i < $numspares-1)) {
7929: $targettable .= '</tr>';
7930: }
7931: if ($i < $numspares-1) {
7932: $targettable .= '<tr>';
1.150 raeburn 7933: }
7934: }
7935: }
1.160.6.7 raeburn 7936: if ($targettable ne '') {
7937: my $rem = $numspares%($numinrow);
7938: my $colsleft = $numinrow - $rem;
7939: if ($colsleft > 1 ) {
7940: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7941: ' </td>';
7942: } elsif ($colsleft == 1) {
7943: $targettable .= '<td class="LC_left_item"> </td>';
7944: }
7945: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
7946: '<table><tr>'.$targettable.'</tr></table><br />';
7947: }
1.160.6.76 raeburn 7948: $hostherechecked{$sparetype} = '';
7949: if (ref($currtargets{$lonhost}) eq 'HASH') {
7950: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
7951: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
7952: $hostherechecked{$sparetype} = ' checked="checked"';
7953: $hostherechecked{'no'} = '';
7954: }
7955: }
7956: }
7957: }
1.160.6.94 raeburn 7958: if ($currcookies{$lonhost}) {
7959: %balcookiechecked = (
7960: yes => ' checked="checked"',
7961: );
7962: }
1.160.6.76 raeburn 7963: $datatable .= &mt('Hosting on balancer itself').'<br />'.
7964: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
7965: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
7966: foreach my $sparetype (@sparestypes) {
7967: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
7968: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
7969: '</i></label><br />';
1.160.6.7 raeburn 7970: }
1.160.6.94 raeburn 7971: $datatable .= &mt('Use balancer cookie').'<br />'.
7972: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
7973: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
7974: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
7975: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
7976: '</div></td></tr>'.
1.160.6.7 raeburn 7977: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
7978: $othertitle,$usertypes,$types,\%servers,
7979: \%currbalancer,$lonhost,
7980: $targets_div_style,$homedom_div_style,
7981: $css_class[$cssidx],$balnum,$islast);
7982: $$rowtotal += $rownum;
7983: $balnum ++;
7984: }
7985: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
7986: return $datatable;
7987: }
7988:
7989: sub get_loadbalancers_config {
1.160.6.94 raeburn 7990: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 7991: return unless ((ref($servers) eq 'HASH') &&
7992: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 7993: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
7994: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 7995: if (keys(%{$existing}) > 0) {
7996: my $oldlonhost;
7997: foreach my $key (sort(keys(%{$existing}))) {
7998: if ($key eq 'lonhost') {
7999: $oldlonhost = $existing->{'lonhost'};
8000: $currbalancer->{$oldlonhost} = 1;
8001: } elsif ($key eq 'targets') {
8002: if ($oldlonhost) {
8003: $currtargets->{$oldlonhost} = $existing->{'targets'};
8004: }
8005: } elsif ($key eq 'rules') {
8006: if ($oldlonhost) {
8007: $currrules->{$oldlonhost} = $existing->{'rules'};
8008: }
8009: } elsif (ref($existing->{$key}) eq 'HASH') {
8010: $currbalancer->{$key} = 1;
8011: $currtargets->{$key} = $existing->{$key}{'targets'};
8012: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 8013: if ($existing->{$key}{'cookie'}) {
8014: $currcookies->{$key} = 1;
8015: }
1.150 raeburn 8016: }
8017: }
1.160.6.7 raeburn 8018: } else {
8019: my ($balancerref,$targetsref) =
8020: &Apache::lonnet::get_lonbalancer_config($servers);
8021: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8022: foreach my $server (sort(keys(%{$balancerref}))) {
8023: $currbalancer->{$server} = 1;
8024: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8025: }
8026: }
8027: }
1.160.6.7 raeburn 8028: return;
1.150 raeburn 8029: }
8030:
8031: sub loadbalancing_rules {
8032: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 8033: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8034: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8035: my $output;
1.160.6.7 raeburn 8036: my $num = 0;
8037: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8038: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8039: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8040: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 8041: $num ++;
1.150 raeburn 8042: my $current;
8043: if (ref($currrules) eq 'HASH') {
8044: $current = $currrules->{$type};
8045: }
1.160.6.55 raeburn 8046: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 8047: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8048: $current = '';
8049: }
8050: }
8051: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 8052: $servers,$currbalancer,$lonhost,$dom,
8053: $targets_div_style,$homedom_div_style,
8054: $css_class,$balnum,$num,$islast);
1.150 raeburn 8055: }
8056: }
8057: return $output;
8058: }
8059:
8060: sub loadbalancing_titles {
8061: my ($dom,$intdom,$usertypes,$types) = @_;
8062: my %othertypes = (
8063: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8064: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8065: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8066: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 8067: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8068: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8069: );
1.160.6.26 raeburn 8070: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 8071: my @available;
1.150 raeburn 8072: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8073: @available = @{$types};
1.150 raeburn 8074: }
1.160.6.89 raeburn 8075: unless (grep(/^default$/,@available)) {
8076: push(@available,'default');
8077: }
8078: unshift(@alltypes,@available);
1.150 raeburn 8079: my %titles;
8080: foreach my $type (@alltypes) {
8081: if ($type =~ /^_LC_/) {
8082: $titles{$type} = $othertypes{$type};
8083: } elsif ($type eq 'default') {
8084: $titles{$type} = &mt('All users from [_1]',$dom);
8085: if (ref($types) eq 'ARRAY') {
8086: if (@{$types} > 0) {
8087: $titles{$type} = &mt('Other users from [_1]',$dom);
8088: }
8089: }
8090: } elsif (ref($usertypes) eq 'HASH') {
8091: $titles{$type} = $usertypes->{$type};
8092: }
8093: }
8094: return (\@alltypes,\%othertypes,\%titles);
8095: }
8096:
8097: sub loadbalance_rule_row {
1.160.6.7 raeburn 8098: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8099: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 8100: my @rulenames;
1.150 raeburn 8101: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 8102: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 8103: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8104: } else {
1.160.6.26 raeburn 8105: @rulenames = ('default','homeserver');
8106: if ($type eq '_LC_external') {
8107: push(@rulenames,'externalbalancer');
8108: } else {
8109: push(@rulenames,'specific');
8110: }
8111: push(@rulenames,'none');
1.150 raeburn 8112: }
8113: my $style = $targets_div_style;
1.160.6.55 raeburn 8114: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8115: $style = $homedom_div_style;
8116: }
1.160.6.7 raeburn 8117: my $space;
8118: if ($islast && $num == 1) {
1.160.6.118.2 14(raebu 8119:23): $space = '<div style="display:inline-block;"> </div>';
1.160.6.7 raeburn 8120: }
8121: my $output =
8122: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8123: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8124: '<td valaign="top">'.$space.
8125: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8126: for (my $i=0; $i<@rulenames; $i++) {
8127: my $rule = $rulenames[$i];
8128: my ($checked,$extra);
8129: if ($rulenames[$i] eq 'default') {
8130: $rule = '';
8131: }
8132: if ($rulenames[$i] eq 'specific') {
8133: if (ref($servers) eq 'HASH') {
8134: my $default;
8135: if (($current ne '') && (exists($servers->{$current}))) {
8136: $checked = ' checked="checked"';
8137: }
8138: unless ($checked) {
8139: $default = ' selected="selected"';
8140: }
1.160.6.7 raeburn 8141: $extra =
8142: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8143: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8144: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8145: '<option value=""'.$default.'></option>'."\n";
8146: foreach my $server (sort(keys(%{$servers}))) {
8147: if (ref($currbalancer) eq 'HASH') {
8148: next if (exists($currbalancer->{$server}));
8149: }
1.150 raeburn 8150: my $selected;
1.160.6.7 raeburn 8151: if ($server eq $current) {
1.150 raeburn 8152: $selected = ' selected="selected"';
8153: }
1.160.6.7 raeburn 8154: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8155: }
8156: $extra .= '</select>';
8157: }
8158: } elsif ($rule eq $current) {
8159: $checked = ' checked="checked"';
8160: }
8161: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 8162: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8163: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8164: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 8165: ')"'.$checked.' /> ';
1.160.6.56 raeburn 8166: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 8167: $output .= $ruletitles{'particular'};
8168: } else {
8169: $output .= $ruletitles{$rulenames[$i]};
8170: }
8171: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8172: }
8173: $output .= '</div></td></tr>'."\n";
8174: return $output;
8175: }
8176:
8177: sub offloadtype_text {
8178: my %ruletitles = &Apache::lonlocal::texthash (
8179: 'default' => 'Offloads to default destinations',
8180: 'homeserver' => "Offloads to user's home server",
8181: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8182: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 8183: 'none' => 'No offload',
1.160.6.26 raeburn 8184: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8185: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 8186: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8187: );
8188: return %ruletitles;
8189: }
8190:
8191: sub sparestype_titles {
8192: my %typestitles = &Apache::lonlocal::texthash (
8193: 'primary' => 'primary',
8194: 'default' => 'default',
8195: );
8196: return %typestitles;
8197: }
8198:
1.28 raeburn 8199: sub contact_titles {
8200: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 8201: 'supportemail' => 'Support E-mail address',
8202: 'adminemail' => 'Default Server Admin E-mail address',
8203: 'errormail' => 'Error reports to be e-mailed to',
8204: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 8205: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8206: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 8207: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8208: 'requestsmail' => 'E-mail from course requests requiring approval',
8209: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 8210: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 8211: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 8212: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8213: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 8214: 'errorweights' => 'Weights used to compute error count',
8215: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8216: );
8217: my %short_titles = &Apache::lonlocal::texthash (
8218: adminemail => 'Admin E-mail address',
8219: supportemail => 'Support E-mail',
8220: );
8221: return (\%titles,\%short_titles);
8222: }
8223:
1.160.6.78 raeburn 8224: sub helpform_fields {
8225: my %titles = &Apache::lonlocal::texthash (
8226: 'username' => 'Name',
8227: 'user' => 'Username/domain',
8228: 'phone' => 'Phone',
8229: 'cc' => 'Cc e-mail',
8230: 'course' => 'Course Details',
8231: 'section' => 'Sections',
8232: 'screenshot' => 'File upload',
8233: );
8234: my @fields = ('username','phone','user','course','section','cc','screenshot');
8235: my %possoptions = (
8236: username => ['yes','no','req'],
8237: phone => ['yes','no','req'],
8238: user => ['yes','no'],
8239: cc => ['yes','no'],
8240: course => ['yes','no'],
8241: section => ['yes','no'],
8242: screenshot => ['yes','no'],
8243: );
8244: my %fieldoptions = &Apache::lonlocal::texthash (
8245: 'yes' => 'Optional',
8246: 'req' => 'Required',
8247: 'no' => "Not shown",
8248: );
8249: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8250: }
8251:
1.72 raeburn 8252: sub tool_titles {
8253: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 8254: aboutme => 'Personal web page',
1.86 raeburn 8255: blog => 'Blog',
1.160.6.4 raeburn 8256: webdav => 'WebDAV',
1.86 raeburn 8257: portfolio => 'Portfolio',
1.160.6.118.2 10(raebu 8258:22): timezone => 'Can set time zone',
1.88 bisitz 8259: official => 'Official courses (with institutional codes)',
8260: unofficial => 'Unofficial courses',
1.98 raeburn 8261: community => 'Communities',
1.160.6.30 raeburn 8262: textbook => 'Textbook courses',
1.86 raeburn 8263: );
1.72 raeburn 8264: return %titles;
8265: }
8266:
1.101 raeburn 8267: sub courserequest_titles {
8268: my %titles = &Apache::lonlocal::texthash (
8269: official => 'Official',
8270: unofficial => 'Unofficial',
8271: community => 'Communities',
1.160.6.30 raeburn 8272: textbook => 'Textbook',
1.160.6.118.2 14(raebu 8273:23): lti => 'LTI Provider',
1.101 raeburn 8274: norequest => 'Not allowed',
1.104 raeburn 8275: approval => 'Approval by Dom. Coord.',
1.101 raeburn 8276: validate => 'With validation',
8277: autolimit => 'Numerical limit',
1.103 raeburn 8278: unlimited => '(blank for unlimited)',
1.101 raeburn 8279: );
8280: return %titles;
8281: }
8282:
1.160.6.5 raeburn 8283: sub authorrequest_titles {
8284: my %titles = &Apache::lonlocal::texthash (
8285: norequest => 'Not allowed',
8286: approval => 'Approval by Dom. Coord.',
8287: automatic => 'Automatic approval',
8288: );
8289: return %titles;
8290: }
8291:
1.101 raeburn 8292: sub courserequest_conditions {
8293: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8294: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 8295: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8296: );
8297: return %conditions;
8298: }
8299:
8300:
1.27 raeburn 8301: sub print_usercreation {
1.30 raeburn 8302: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8303: my $numinrow = 4;
1.28 raeburn 8304: my $datatable;
8305: if ($position eq 'top') {
1.30 raeburn 8306: $$rowtotal ++;
1.34 raeburn 8307: my $rowcount = 0;
1.32 raeburn 8308: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8309: if (ref($rules) eq 'HASH') {
8310: if (keys(%{$rules}) > 0) {
1.32 raeburn 8311: $datatable .= &user_formats_row('username',$settings,$rules,
8312: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8313: $$rowtotal ++;
1.32 raeburn 8314: $rowcount ++;
8315: }
8316: }
8317: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8318: if (ref($idrules) eq 'HASH') {
8319: if (keys(%{$idrules}) > 0) {
8320: $datatable .= &user_formats_row('id',$settings,$idrules,
8321: $idruleorder,$numinrow,$rowcount);
8322: $$rowtotal ++;
8323: $rowcount ++;
1.28 raeburn 8324: }
8325: }
1.39 raeburn 8326: if ($rowcount == 0) {
8327: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8328: $$rowtotal ++;
8329: $rowcount ++;
8330: }
1.34 raeburn 8331: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 8332: my @creators = ('author','course','requestcrs');
1.37 raeburn 8333: my ($rules,$ruleorder) =
8334: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8335: my %lt = &usercreation_types();
8336: my %checked;
8337: if (ref($settings) eq 'HASH') {
8338: if (ref($settings->{'cancreate'}) eq 'HASH') {
8339: foreach my $item (@creators) {
8340: $checked{$item} = $settings->{'cancreate'}{$item};
8341: }
8342: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8343: foreach my $item (@creators) {
8344: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8345: $checked{$item} = 'none';
8346: }
8347: }
8348: }
8349: }
8350: my $rownum = 0;
8351: foreach my $item (@creators) {
8352: $rownum ++;
1.160.6.34 raeburn 8353: if ($checked{$item} eq '') {
8354: $checked{$item} = 'any';
1.34 raeburn 8355: }
8356: my $css_class;
8357: if ($rownum%2) {
8358: $css_class = '';
8359: } else {
8360: $css_class = ' class="LC_odd_row" ';
8361: }
8362: $datatable .= '<tr'.$css_class.'>'.
8363: '<td><span class="LC_nobreak">'.$lt{$item}.
8364: '</span></td><td align="right">';
1.160.6.34 raeburn 8365: my @options = ('any');
8366: if (ref($rules) eq 'HASH') {
8367: if (keys(%{$rules}) > 0) {
8368: push(@options,('official','unofficial'));
1.37 raeburn 8369: }
8370: }
1.160.6.34 raeburn 8371: push(@options,'none');
1.37 raeburn 8372: foreach my $option (@options) {
1.50 raeburn 8373: my $type = 'radio';
1.34 raeburn 8374: my $check = ' ';
1.160.6.34 raeburn 8375: if ($checked{$item} eq $option) {
8376: $check = ' checked="checked" ';
1.34 raeburn 8377: }
8378: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8379: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8380: $item.'" value="'.$option.'"'.$check.'/> '.
8381: $lt{$option}.'</label> </span>';
8382: }
8383: $datatable .= '</td></tr>';
8384: }
1.28 raeburn 8385: } else {
8386: my @contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 8387:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8388: my %checked;
8389: if (ref($settings) eq 'HASH') {
8390: if (ref($settings->{'authtypes'}) eq 'HASH') {
8391: foreach my $item (@contexts) {
8392: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8393: foreach my $auth (@authtypes) {
8394: if ($settings->{'authtypes'}{$item}{$auth}) {
8395: $checked{$item}{$auth} = ' checked="checked" ';
8396: }
8397: }
8398: }
8399: }
1.27 raeburn 8400: }
1.35 raeburn 8401: } else {
8402: foreach my $item (@contexts) {
1.36 raeburn 8403: foreach my $auth (@authtypes) {
1.35 raeburn 8404: $checked{$item}{$auth} = ' checked="checked" ';
8405: }
8406: }
1.27 raeburn 8407: }
1.28 raeburn 8408: my %title = &context_names();
8409: my %authname = &authtype_names();
8410: my $rownum = 0;
8411: my $css_class;
8412: foreach my $item (@contexts) {
8413: if ($rownum%2) {
8414: $css_class = '';
8415: } else {
8416: $css_class = ' class="LC_odd_row" ';
8417: }
1.30 raeburn 8418: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8419: '<td>'.$title{$item}.
8420: '</td><td class="LC_left_item">'.
8421: '<span class="LC_nobreak">';
8422: foreach my $auth (@authtypes) {
8423: $datatable .= '<label>'.
8424: '<input type="checkbox" name="'.$item.'_auth" '.
8425: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8426: $authname{$auth}.'</label> ';
8427: }
8428: $datatable .= '</span></td></tr>';
8429: $rownum ++;
1.27 raeburn 8430: }
1.30 raeburn 8431: $$rowtotal += $rownum;
1.27 raeburn 8432: }
8433: return $datatable;
8434: }
8435:
1.160.6.34 raeburn 8436: sub print_selfcreation {
8437: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 8438: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8439: $emaildomain,$datatable);
1.160.6.34 raeburn 8440: if (ref($settings) eq 'HASH') {
8441: if (ref($settings->{'cancreate'}) eq 'HASH') {
8442: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 8443: if (ref($createsettings) eq 'HASH') {
8444: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8445: @selfcreate = @{$createsettings->{'selfcreate'}};
8446: } elsif ($createsettings->{'selfcreate'} ne '') {
8447: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8448: @selfcreate = ('email','login','sso');
8449: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8450: @selfcreate = ($createsettings->{'selfcreate'});
8451: }
8452: }
8453: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8454: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 8455: }
1.160.6.93 raeburn 8456: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8457: $emailoptions = $createsettings->{'emailoptions'};
8458: }
8459: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8460: $emailverified = $createsettings->{'emailverified'};
8461: }
8462: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8463: $emaildomain = $createsettings->{'emaildomain'};
8464: }
1.160.6.34 raeburn 8465: }
8466: }
8467: }
8468: my %radiohash;
8469: my $numinrow = 4;
8470: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 8471: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 8472: if ($position eq 'top') {
8473: my %choices = &Apache::lonlocal::texthash (
8474: cancreate_login => 'Institutional Login',
8475: cancreate_sso => 'Institutional Single Sign On',
8476: );
8477: my @toggles = sort(keys(%choices));
8478: my %defaultchecked = (
8479: 'cancreate_login' => 'off',
8480: 'cancreate_sso' => 'off',
8481: );
1.160.6.35 raeburn 8482: my ($onclick,$itemcount);
1.160.6.34 raeburn 8483: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8484: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 8485: $$rowtotal += $itemcount;
1.160.6.34 raeburn 8486:
8487: if (ref($usertypes) eq 'HASH') {
8488: if (keys(%{$usertypes}) > 0) {
8489: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8490: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 8491: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 8492: $$rowtotal ++;
8493: }
8494: }
1.160.6.44 raeburn 8495: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8496: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8497: $fieldtitles{'inststatus'} = &mt('Institutional status');
8498: my $rem;
8499: my $numperrow = 2;
8500: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8501: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 8502: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 8503: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 8504: '<table>'."\n";
1.160.6.44 raeburn 8505: for (my $i=0; $i<@fields; $i++) {
8506: $rem = $i%($numperrow);
8507: if ($rem == 0) {
8508: if ($i > 0) {
8509: $datatable .= '</tr>';
8510: }
8511: $datatable .= '<tr>';
8512: }
8513: my $currval;
1.160.6.51 raeburn 8514: if (ref($createsettings) eq 'HASH') {
8515: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8516: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8517: }
1.160.6.44 raeburn 8518: }
8519: $datatable .= '<td class="LC_left_item">'.
8520: '<span class="LC_nobreak">'.
8521: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8522: 'value="'.$currval.'" size="10" /> '.
8523: $fieldtitles{$fields[$i]}.'</span></td>';
8524: }
8525: my $colsleft = $numperrow - $rem;
8526: if ($colsleft > 1 ) {
8527: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8528: ' </td>';
8529: } elsif ($colsleft == 1) {
8530: $datatable .= '<td class="LC_left_item"> </td>';
8531: }
8532: $datatable .= '</tr></table></td></tr>';
8533: $$rowtotal ++;
1.160.6.34 raeburn 8534: } elsif ($position eq 'middle') {
8535: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 8536: my @posstypes;
1.160.6.34 raeburn 8537: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8538: @posstypes = @{$types};
8539: }
8540: unless (grep(/^default$/,@posstypes)) {
8541: push(@posstypes,'default');
8542: }
8543: my %usertypeshash;
8544: if (ref($usertypes) eq 'HASH') {
8545: %usertypeshash = %{$usertypes};
8546: }
8547: $usertypeshash{'default'} = $othertitle;
8548: foreach my $status (@posstypes) {
8549: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8550: $numinrow,$$rowtotal,\%usertypeshash);
8551: $$rowtotal ++;
1.160.6.34 raeburn 8552: }
8553: } else {
1.160.6.40 raeburn 8554: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 8555: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 8556: );
8557: my @toggles = sort(keys(%choices));
8558: my %defaultchecked = (
8559: 'cancreate_email' => 'off',
8560: );
1.160.6.93 raeburn 8561: my $customclass = 'LC_selfcreate_email';
8562: my $classprefix = 'LC_canmodify_emailusername_';
8563: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 8564: my $display = 'none';
1.160.6.93 raeburn 8565: my $rowstyle = 'display:none';
1.160.6.40 raeburn 8566: if (grep(/^\Qemail\E$/,@selfcreate)) {
8567: $display = 'block';
1.160.6.93 raeburn 8568: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 8569: }
1.160.6.93 raeburn 8570: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8571: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8572: \%choices,$$rowtotal,$onclick);
8573: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8574: $rowstyle);
8575: $$rowtotal ++;
8576: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8577: $rowstyle);
8578: $$rowtotal ++;
8579: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 8580: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 8581: my ($emailrules,$emailruleorder) =
8582: &Apache::lonnet::inst_userrules($dom,'email');
8583: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8584: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8585: if (ref($types) eq 'ARRAY') {
8586: @posstypes = @{$types};
8587: }
8588: if (@posstypes) {
8589: unless (grep(/^default$/,@posstypes)) {
8590: push(@posstypes,'default');
1.160.6.89 raeburn 8591: }
8592: if (ref($usertypes) eq 'HASH') {
8593: %usertypeshash = %{$usertypes};
8594: }
1.160.6.93 raeburn 8595: my $currassign;
8596: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8597: $currassign = {
8598: selfassign => $domdefaults{'inststatusguest'},
8599: };
8600: @ordered = @{$domdefaults{'inststatusguest'}};
8601: } else {
8602: $currassign = { selfassign => [] };
8603: }
8604: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8605: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8606: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8607: $numinrow,$othertitle,'selfassign',
8608: $rowtotal,$onclicktypes,$customclass,
8609: $rowstyle);
8610: $$rowtotal ++;
1.160.6.89 raeburn 8611: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8612: foreach my $status (@posstypes) {
8613: my $css_class;
8614: if ($$rowtotal%2) {
8615: $css_class = 'LC_odd_row ';
8616: }
8617: $css_class .= $customclass;
8618: my $rowid = $optionsprefix.$status;
8619: my $hidden = 1;
8620: my $currstyle = 'display:none';
8621: if (grep(/^\Q$status\E$/,@ordered)) {
8622: $currstyle = $rowstyle;
8623: $hidden = 0;
8624: }
8625: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8626: $emailrules,$emailruleorder,$settings,$status,$rowid,
8627: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8628: unless ($hidden) {
8629: $$rowtotal ++;
8630: }
1.160.6.89 raeburn 8631: }
8632: } else {
1.160.6.93 raeburn 8633: my $css_class;
8634: if ($$rowtotal%2) {
8635: $css_class = 'LC_odd_row ';
8636: }
8637: $css_class .= $customclass;
1.160.6.89 raeburn 8638: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8639: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8640: $emailrules,$emailruleorder,$settings,'default','',
8641: $othertitle,$css_class,$rowstyle,$intdom);
8642: $$rowtotal ++;
1.160.6.34 raeburn 8643: }
1.160.6.35 raeburn 8644: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8645: $numinrow = 1;
1.160.6.93 raeburn 8646: if (@posstypes) {
8647: foreach my $status (@posstypes) {
8648: my $rowid = $classprefix.$status;
8649: my $datarowstyle = 'display:none';
8650: if (grep(/^\Q$status\E$/,@ordered)) {
8651: $datarowstyle = $rowstyle;
8652: }
8653: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8654: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8655: $infotitles,$rowid,$customclass,$datarowstyle);
8656: unless ($datarowstyle eq 'display:none') {
8657: $$rowtotal ++;
8658: }
1.160.6.34 raeburn 8659: }
1.160.6.93 raeburn 8660: } else {
8661: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8662: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8663: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 8664: }
8665: }
8666: return $datatable;
8667: }
8668:
1.160.6.93 raeburn 8669: sub selfcreate_javascript {
8670: return <<"ENDSCRIPT";
8671:
8672: <script type="text/javascript">
8673: // <![CDATA[
8674:
8675: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8676: var x = document.getElementsByClassName(target);
8677: var insttypes = 0;
8678: var insttypeRegExp = new RegExp(prefix);
8679: if ((x.length != undefined) && (x.length > 0)) {
8680: if (form.elements[radio].length != undefined) {
8681: for (var i=0; i<form.elements[radio].length; i++) {
8682: if (form.elements[radio][i].checked) {
8683: if (form.elements[radio][i].value == 1) {
8684: for (var j=0; j<x.length; j++) {
8685: if (x[j].id == 'undefined') {
8686: x[j].style.display = 'table-row';
8687: } else if (insttypeRegExp.test(x[j].id)) {
8688: insttypes ++;
8689: } else {
8690: x[j].style.display = 'table-row';
8691: }
8692: }
8693: } else {
8694: for (var j=0; j<x.length; j++) {
8695: x[j].style.display = 'none';
8696: }
1.160.6.40 raeburn 8697: }
1.160.6.93 raeburn 8698: break;
8699: }
8700: }
8701: if (insttypes > 0) {
8702: toggleDataRow(form,checkbox,target,altprefix);
8703: toggleDataRow(form,checkbox,target,prefix,1);
8704: }
8705: }
8706: }
8707: return;
8708: }
8709:
8710: function toggleDataRow(form,checkbox,target,prefix,docount) {
8711: if (form.elements[checkbox].length != undefined) {
8712: var count = 0;
8713: if (docount) {
8714: for (var i=0; i<form.elements[checkbox].length; i++) {
8715: if (form.elements[checkbox][i].checked) {
8716: count ++;
8717: }
8718: }
8719: }
8720: for (var i=0; i<form.elements[checkbox].length; i++) {
8721: var type = form.elements[checkbox][i].value;
8722: if (document.getElementById(prefix+type)) {
8723: if (form.elements[checkbox][i].checked) {
8724: document.getElementById(prefix+type).style.display = 'table-row';
8725: if (count % 2 == 1) {
8726: document.getElementById(prefix+type).className = target+' LC_odd_row';
8727: } else {
8728: document.getElementById(prefix+type).className = target;
8729: }
8730: count ++;
1.160.6.40 raeburn 8731: } else {
1.160.6.93 raeburn 8732: document.getElementById(prefix+type).style.display = 'none';
8733: }
8734: }
8735: }
8736: }
8737: return;
8738: }
8739:
8740: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8741: var caller = radio+'_'+status;
8742: if (form.elements[caller].length != undefined) {
8743: for (var i=0; i<form.elements[caller].length; i++) {
8744: if (form.elements[caller][i].checked) {
8745: if (document.getElementById(altprefix+'_inst_'+status)) {
8746: var curr = form.elements[caller][i].value;
8747: if (prefix) {
8748: document.getElementById(prefix+'_'+status).style.display = 'none';
8749: }
8750: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
8751: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
8752: if (curr == 'custom') {
8753: if (prefix) {
8754: document.getElementById(prefix+'_'+status).style.display = 'inline';
8755: }
8756: } else if (curr == 'inst') {
8757: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
8758: } else if (curr == 'noninst') {
8759: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 8760: }
1.160.6.93 raeburn 8761: break;
1.160.6.40 raeburn 8762: }
1.160.6.93 raeburn 8763: }
8764: }
8765: }
8766: }
8767:
8768: // ]]>
8769: </script>
8770:
8771: ENDSCRIPT
8772: }
8773:
8774: sub noninst_users {
8775: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
8776: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
8777: my $class = 'LC_left_item';
8778: if ($css_class) {
8779: $css_class = ' class="'.$css_class.'"';
8780: }
8781: if ($rowid) {
8782: $rowid = ' id="'.$rowid.'"';
8783: }
8784: if ($rowstyle) {
8785: $rowstyle = ' style="'.$rowstyle.'"';
8786: }
8787: my ($output,$description);
8788: if ($type eq 'default') {
8789: $description = &mt('Requests for: [_1]',$typetitle);
8790: } else {
8791: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
8792: }
8793: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
8794: "<td>$description</td>\n".
8795: '<td class="'.$class.'" colspan="2">'.
8796: '<table><tr>';
8797: my %headers = &Apache::lonlocal::texthash(
8798: approve => 'Processing',
8799: email => 'E-mail',
8800: username => 'Username',
8801: );
8802: foreach my $item ('approve','email','username') {
8803: $output .= '<th>'.$headers{$item}.'</th>';
8804: }
8805: $output .= '</tr><tr>';
8806: foreach my $item ('approve','email','username') {
8807: $output .= '<td valign="top">';
8808: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
8809: if ($item eq 'approve') {
8810: %choices = &Apache::lonlocal::texthash (
8811: automatic => 'Automatically approved',
8812: approval => 'Queued for approval',
8813: );
8814: @options = ('automatic','approval');
8815: $hashref = $processing;
8816: $defoption = 'automatic';
8817: $name = 'cancreate_emailprocess_'.$type;
8818: } elsif ($item eq 'email') {
8819: %choices = &Apache::lonlocal::texthash (
8820: any => 'Any e-mail',
8821: inst => 'Institutional only',
8822: noninst => 'Non-institutional only',
8823: custom => 'Custom restrictions',
8824: );
8825: @options = ('any','inst','noninst');
8826: my $showcustom;
8827: if (ref($emailrules) eq 'HASH') {
8828: if (keys(%{$emailrules}) > 0) {
8829: push(@options,'custom');
8830: $showcustom = 'cancreate_emailrule';
8831: if (ref($settings) eq 'HASH') {
8832: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
8833: foreach my $rule (@{$settings->{'email_rule'}}) {
8834: if (exists($emailrules->{$rule})) {
8835: $hascustom ++;
8836: }
8837: }
8838: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
8839: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
8840: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
8841: if (exists($emailrules->{$rule})) {
8842: $hascustom ++;
8843: }
8844: }
8845: }
8846: }
8847: }
8848: }
8849: }
8850: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
8851: "'cancreate_emaildomain','$type'".');"';
8852: $hashref = $emailoptions;
8853: $defoption = 'any';
8854: $name = 'cancreate_emailoptions_'.$type;
8855: } elsif ($item eq 'username') {
8856: %choices = &Apache::lonlocal::texthash (
8857: all => 'Same as e-mail',
8858: first => 'Omit @domain',
8859: free => 'Free to choose',
8860: );
8861: @options = ('all','first','free');
8862: $hashref = $emailverified;
8863: $defoption = 'all';
8864: $name = 'cancreate_usernameoptions_'.$type;
8865: }
8866: foreach my $option (@options) {
8867: my $checked;
8868: if (ref($hashref) eq 'HASH') {
8869: if ($type eq '') {
8870: if (!exists($hashref->{'default'})) {
8871: if ($option eq $defoption) {
8872: $checked = ' checked="checked"';
8873: }
8874: } else {
8875: if ($hashref->{'default'} eq $option) {
8876: $checked = ' checked="checked"';
8877: }
1.160.6.40 raeburn 8878: }
8879: } else {
1.160.6.93 raeburn 8880: if (!exists($hashref->{$type})) {
8881: if ($option eq $defoption) {
8882: $checked = ' checked="checked"';
8883: }
8884: } else {
8885: if ($hashref->{$type} eq $option) {
8886: $checked = ' checked="checked"';
8887: }
1.160.6.40 raeburn 8888: }
8889: }
1.160.6.93 raeburn 8890: } elsif (($item eq 'email') && ($hascustom)) {
8891: if ($option eq 'custom') {
8892: $checked = ' checked="checked"';
8893: }
8894: } elsif ($option eq $defoption) {
8895: $checked = ' checked="checked"';
8896: }
8897: $output .= '<span class="LC_nobreak"><label>'.
8898: '<input type="radio" name="'.$name.'"'.
8899: $checked.' value="'.$option.'"'.$onclick.' />'.
8900: $choices{$option}.'</label></span><br />';
8901: if ($item eq 'email') {
8902: if ($option eq 'custom') {
8903: my $id = 'cancreate_emailrule_'.$type;
8904: my $display = 'none';
8905: if ($checked) {
8906: $display = 'inline';
8907: }
8908: my $numinrow = 2;
8909: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
8910: '<legend>'.&mt('Disallow').'</legend><table>'.
8911: &user_formats_row('email',$settings,$emailrules,
8912: $emailruleorder,$numinrow,'',$type);
8913: '</table></fieldset>';
8914: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
8915: my %text = &Apache::lonlocal::texthash (
8916: inst => 'must end:',
8917: noninst => 'cannot end:',
8918: );
8919: my $value;
8920: if (ref($emaildomain) eq 'HASH') {
8921: if (ref($emaildomain->{$type}) eq 'HASH') {
8922: $value = $emaildomain->{$type}->{$option};
8923: }
8924: }
8925: if ($value eq '') {
8926: $value = '@'.$intdom;
8927: }
8928: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
8929: my $display = 'none';
8930: if ($checked) {
8931: $display = 'inline';
8932: }
8933: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
8934: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
8935: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
8936: '</div>';
8937: }
1.160.6.40 raeburn 8938: }
8939: }
1.160.6.93 raeburn 8940: $output .= '</td>'."\n";
1.160.6.40 raeburn 8941: }
1.160.6.93 raeburn 8942: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 8943: return $output;
8944: }
8945:
1.160.6.5 raeburn 8946: sub captcha_choice {
1.160.6.93 raeburn 8947: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 8948: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
1.160.6.118.2 14(raebu 8949:23): $vertext,$currver);
1.160.6.5 raeburn 8950: my %lt = &captcha_phrases();
8951: $keyentry = 'hidden';
1.160.6.98 raeburn 8952: my $colspan=2;
1.160.6.5 raeburn 8953: if ($context eq 'cancreate') {
1.160.6.34 raeburn 8954: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 8955: } elsif ($context eq 'login') {
8956: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 8957: } elsif ($context eq 'passwords') {
8958: $rowname = &mt('"Forgot Password" CAPTCHA validation');
8959: $colspan=1;
1.160.6.5 raeburn 8960: }
8961: if (ref($settings) eq 'HASH') {
8962: if ($settings->{'captcha'}) {
8963: $checked{$settings->{'captcha'}} = ' checked="checked"';
8964: } else {
8965: $checked{'original'} = ' checked="checked"';
8966: }
8967: if ($settings->{'captcha'} eq 'recaptcha') {
8968: $pubtext = $lt{'pub'};
8969: $privtext = $lt{'priv'};
8970: $keyentry = 'text';
1.160.6.69 raeburn 8971: $vertext = $lt{'ver'};
8972: $currver = $settings->{'recaptchaversion'};
8973: if ($currver ne '2') {
8974: $currver = 1;
8975: }
1.160.6.5 raeburn 8976: }
8977: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
8978: $currpub = $settings->{'recaptchakeys'}{'public'};
8979: $currpriv = $settings->{'recaptchakeys'}{'private'};
8980: }
8981: } else {
8982: $checked{'original'} = ' checked="checked"';
8983: }
1.160.6.93 raeburn 8984: my $css_class;
8985: if ($itemcount%2) {
8986: $css_class = 'LC_odd_row';
8987: }
8988: if ($customcss) {
8989: $css_class .= " $customcss";
8990: }
8991: $css_class =~ s/^\s+//;
8992: if ($css_class) {
8993: $css_class = ' class="'.$css_class.'"';
8994: }
8995: if ($rowstyle) {
8996: $css_class .= ' style="'.$rowstyle.'"';
8997: }
1.160.6.5 raeburn 8998: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 8999: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 9000: '<table><tr><td>'."\n";
9001: foreach my $option ('original','recaptcha','notused') {
9002: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9003: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9004: $lt{$option}.'</label></span>';
9005: unless ($option eq 'notused') {
9006: $output .= (' 'x2)."\n";
9007: }
9008: }
9009: #
9010: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9011: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
9012: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
9013: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
9014: #
9015: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 9016: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 9017: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9018: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9019: $currpub.'" size="40" /></span><br />'."\n".
9020: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9021: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 9022: $currpriv.'" size="40" /></span><br />'.
9023: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9024: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9025: $currver.'" size="3" /></span><br />'.
9026: '</td></tr></table>'."\n".
1.160.6.5 raeburn 9027: '</td></tr>';
9028: return $output;
9029: }
9030:
1.32 raeburn 9031: sub user_formats_row {
1.160.6.93 raeburn 9032: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9033: my $output;
9034: my %text = (
9035: 'username' => 'new usernames',
9036: 'id' => 'IDs',
9037: );
1.160.6.118.2 8(raebur 9038:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 9039: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9040: $output = '<tr '.$css_class.'>'.
9041: '<td><span class="LC_nobreak">'.
9042: &mt("Format rules to check for $text{$type}: ").
9043: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9044: }
1.27 raeburn 9045: my $rem;
9046: if (ref($ruleorder) eq 'ARRAY') {
9047: for (my $i=0; $i<@{$ruleorder}; $i++) {
9048: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9049: my $rem = $i%($numinrow);
9050: if ($rem == 0) {
9051: if ($i > 0) {
9052: $output .= '</tr>';
9053: }
9054: $output .= '<tr>';
9055: }
9056: my $check = ' ';
1.39 raeburn 9057: if (ref($settings) eq 'HASH') {
9058: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9059: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9060: $check = ' checked="checked" ';
9061: }
1.160.6.93 raeburn 9062: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9063: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9064: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9065: $check = ' checked="checked" ';
9066: }
9067: }
1.27 raeburn 9068: }
9069: }
1.160.6.93 raeburn 9070: my $name = $type.'_rule';
9071: if ($type eq 'email') {
9072: $name .= '_'.$status;
9073: }
1.27 raeburn 9074: $output .= '<td class="LC_left_item">'.
9075: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 9076: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9077: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9078: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9079: }
9080: }
9081: $rem = @{$ruleorder}%($numinrow);
9082: }
1.160.6.93 raeburn 9083: my $colsleft;
9084: if ($rem) {
9085: $colsleft = $numinrow - $rem;
9086: }
1.27 raeburn 9087: if ($colsleft > 1 ) {
9088: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9089: ' </td>';
9090: } elsif ($colsleft == 1) {
9091: $output .= '<td class="LC_left_item"> </td>';
9092: }
1.160.6.118.2 8(raebur 9093:2): $output .= '</tr>';
9094:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
9095:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 9096: }
1.27 raeburn 9097: return $output;
9098: }
9099:
1.34 raeburn 9100: sub usercreation_types {
9101: my %lt = &Apache::lonlocal::texthash (
9102: author => 'When adding a co-author',
9103: course => 'When adding a user to a course',
1.100 raeburn 9104: requestcrs => 'When requesting a course',
1.34 raeburn 9105: any => 'Any',
9106: official => 'Institutional only ',
9107: unofficial => 'Non-institutional only',
9108: none => 'None',
9109: );
9110: return %lt;
1.48 raeburn 9111: }
1.34 raeburn 9112:
1.160.6.34 raeburn 9113: sub selfcreation_types {
9114: my %lt = &Apache::lonlocal::texthash (
9115: selfcreate => 'User creates own account',
9116: any => 'Any',
9117: official => 'Institutional only ',
9118: unofficial => 'Non-institutional only',
9119: email => 'E-mail address',
9120: login => 'Institutional Login',
9121: sso => 'SSO',
9122: );
9123: }
9124:
1.28 raeburn 9125: sub authtype_names {
9126: my %lt = &Apache::lonlocal::texthash(
9127: int => 'Internal',
9128: krb4 => 'Kerberos 4',
9129: krb5 => 'Kerberos 5',
9130: loc => 'Local',
1.160.6.118.2 14(raebu 9131:23): lti => 'LTI',
1.28 raeburn 9132: );
9133: return %lt;
9134: }
9135:
9136: sub context_names {
9137: my %context_title = &Apache::lonlocal::texthash(
9138: author => 'Creating users when an Author',
9139: course => 'Creating users when in a course',
9140: domain => 'Creating users when a Domain Coordinator',
9141: );
9142: return %context_title;
9143: }
9144:
1.33 raeburn 9145: sub print_usermodification {
9146: my ($position,$dom,$settings,$rowtotal) = @_;
9147: my $numinrow = 4;
9148: my ($context,$datatable,$rowcount);
9149: if ($position eq 'top') {
9150: $rowcount = 0;
9151: $context = 'author';
9152: foreach my $role ('ca','aa') {
9153: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9154: $numinrow,$rowcount);
9155: $$rowtotal ++;
9156: $rowcount ++;
9157: }
1.160.6.37 raeburn 9158: } elsif ($position eq 'bottom') {
1.33 raeburn 9159: $context = 'course';
9160: $rowcount = 0;
9161: foreach my $role ('st','ep','ta','in','cr') {
9162: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9163: $numinrow,$rowcount);
9164: $$rowtotal ++;
9165: $rowcount ++;
9166: }
9167: }
9168: return $datatable;
9169: }
9170:
1.43 raeburn 9171: sub print_defaults {
1.160.6.40 raeburn 9172: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9173: my $rownum = 0;
1.160.6.80 raeburn 9174: my ($datatable,$css_class,$titles);
9175: unless ($position eq 'bottom') {
9176: $titles = &defaults_titles($dom);
9177: }
1.160.6.40 raeburn 9178: if ($position eq 'top') {
9179: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9180: 'datelocale_def','portal_def');
9181: my %defaults;
9182: if (ref($settings) eq 'HASH') {
9183: %defaults = %{$settings};
1.43 raeburn 9184: } else {
1.160.6.40 raeburn 9185: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9186: foreach my $item (@items) {
9187: $defaults{$item} = $domdefaults{$item};
9188: }
1.43 raeburn 9189: }
1.160.6.40 raeburn 9190: foreach my $item (@items) {
9191: if ($rownum%2) {
9192: $css_class = '';
9193: } else {
9194: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 9195: }
1.160.6.40 raeburn 9196: $datatable .= '<tr'.$css_class.'>'.
9197: '<td><span class="LC_nobreak">'.$titles->{$item}.
9198: '</span></td><td class="LC_right_item" colspan="3">';
9199: if ($item eq 'auth_def') {
1.160.6.118.2 14(raebu 9200:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.160.6.40 raeburn 9201: my %shortauth = (
9202: internal => 'int',
9203: krb4 => 'krb4',
9204: krb5 => 'krb5',
1.160.6.118.2 14(raebu 9205:23): localauth => 'loc',
9206:23): lti => 'lti',
1.160.6.40 raeburn 9207: );
9208: my %authnames = &authtype_names();
9209: foreach my $auth (@authtypes) {
9210: my $checked = ' ';
9211: if ($defaults{$item} eq $auth) {
9212: $checked = ' checked="checked" ';
9213: }
9214: $datatable .= '<label><input type="radio" name="'.$item.
9215: '" value="'.$auth.'"'.$checked.'/>'.
9216: $authnames{$shortauth{$auth}}.'</label> ';
9217: }
9218: } elsif ($item eq 'timezone_def') {
9219: my $includeempty = 1;
9220: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9221: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 9222: my $includeempty = 1;
9223: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9224: } elsif ($item eq 'lang_def') {
9225: my $includeempty = 1;
9226: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 9227:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 9228: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 9229:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9230:23): my $portalsty = 'none';
9231:23): if ($defaults{$item}) {
9232:23): $portalsty = 'block';
9233:23): }
9234:23): foreach my $field ('email','web') {
9235:23): my $checkedoff = ' checked="checked"';
9236:23): my $checkedon;
9237:23): if ($defaults{$item.'_'.$field}) {
9238:23): $checkedon = $checkedoff;
9239:23): $checkedoff = '';
9240:23): }
9241:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9242:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
9243:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9244:23): (' 'x2).
9245:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9246:23): '</div>';
9247:23): }
9248:23): } else {
9249:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 9250: }
9251: $datatable .= '</td></tr>';
9252: $rownum ++;
9253: }
1.160.6.118.2 8(raebur 9254:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 9255: my %defaults;
1.160.6.40 raeburn 9256: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 9257: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 9258: my $maxnum = @{$settings->{'inststatusorder'}};
9259: for (my $i=0; $i<$maxnum; $i++) {
9260: $css_class = $rownum%2?' class="LC_odd_row"':'';
9261: my $item = $settings->{'inststatusorder'}->[$i];
9262: my $title = $settings->{'inststatustypes'}->{$item};
9263: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9264: $datatable .= '<tr'.$css_class.'>'.
9265: '<td><span class="LC_nobreak">'.
9266: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9267: for (my $k=0; $k<=$maxnum; $k++) {
9268: my $vpos = $k+1;
9269: my $selstr;
9270: if ($k == $i) {
9271: $selstr = ' selected="selected" ';
9272: }
9273: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9274: }
9275: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9276: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9277: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 9278: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 9279: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 9280: '</span></td></tr>';
1.160.6.40 raeburn 9281: }
9282: $css_class = $rownum%2?' class="LC_odd_row"':'';
9283: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9284: $datatable .= '<tr '.$css_class.'>'.
9285: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9286: for (my $k=0; $k<=$maxnum; $k++) {
9287: my $vpos = $k+1;
9288: my $selstr;
9289: if ($k == $maxnum) {
9290: $selstr = ' selected="selected" ';
9291: }
9292: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9293: }
9294: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 9295: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 9296: ' '.&mt('(new)').
9297: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 9298: &mt('Name displayed').':'.
1.160.6.40 raeburn 9299: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9300: '</tr>'."\n";
9301: $rownum ++;
1.141 raeburn 9302: }
1.43 raeburn 9303: }
1.160.6.118.2 8(raebur 9304:2): } else {
9305:2): my ($unamemaprules,$ruleorder) =
9306:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
9307:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
9308:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9309:2): my $numinrow = 2;
9310:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9311:2): &user_formats_row('unamemap',$settings,$unamemaprules,
9312:2): $ruleorder,$numinrow).
9313:2): '</table></td></tr>';
9314:2): }
9315:2): if ($datatable eq '') {
9316:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9317:2): &mt('No rules set for domain in customized localenroll.pm').
9318:2): '</td></tr>';
9319:2): }
1.43 raeburn 9320: }
9321: $$rowtotal += $rownum;
9322: return $datatable;
9323: }
9324:
1.160.6.5 raeburn 9325: sub get_languages_hash {
9326: my %langchoices;
9327: foreach my $id (&Apache::loncommon::languageids()) {
9328: my $code = &Apache::loncommon::supportedlanguagecode($id);
9329: if ($code ne '') {
9330: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9331: }
9332: }
9333: return %langchoices;
9334: }
9335:
1.43 raeburn 9336: sub defaults_titles {
1.141 raeburn 9337: my ($dom) = @_;
1.43 raeburn 9338: my %titles = &Apache::lonlocal::texthash (
9339: 'auth_def' => 'Default authentication type',
9340: 'auth_arg_def' => 'Default authentication argument',
9341: 'lang_def' => 'Default language',
1.54 raeburn 9342: 'timezone_def' => 'Default timezone',
1.68 raeburn 9343: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9344: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 9345:23): 'email' => 'Email links use portal URL',
9346:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 9347: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9348: 'intauth_check' => 'Check bcrypt cost if authenticated',
9349: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9350: );
1.141 raeburn 9351: if ($dom) {
9352: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9353: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9354: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9355: $protocol = 'http' if ($protocol ne 'https');
9356: if ($uint_dom) {
9357: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9358: $uint_dom);
9359: }
9360: }
1.43 raeburn 9361: return (\%titles);
9362: }
9363:
1.160.6.97 raeburn 9364: sub print_scantron {
9365: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9366: if ($position eq 'top') {
9367: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9368: } else {
9369: return &print_scantronconfig($dom,$settings,\$rowtotal);
9370: }
9371: }
9372:
9373: sub scantron_javascript {
9374: return <<"ENDSCRIPT";
9375:
9376: <script type="text/javascript">
9377: // <![CDATA[
9378:
9379: function toggleScantron(form) {
9380: var csvfieldset = new Array();
9381: if (document.getElementById('scantroncsv_cols')) {
9382: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9383: }
9384: if (document.getElementById('scantroncsv_options')) {
9385: csvfieldset.push(document.getElementById('scantroncsv_options'));
9386: }
9387: if (csvfieldset.length) {
9388: if (document.getElementById('scantronconfcsv')) {
9389: var scantroncsv = document.getElementById('scantronconfcsv');
9390: if (scantroncsv.checked) {
9391: for (var i=0; i<csvfieldset.length; i++) {
9392: csvfieldset[i].style.display = 'block';
9393: }
9394: } else {
9395: for (var i=0; i<csvfieldset.length; i++) {
9396: csvfieldset[i].style.display = 'none';
9397: }
9398: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9399: if (csvselects.length) {
9400: for (var j=0; j<csvselects.length; j++) {
9401: csvselects[j].selectedIndex = 0;
9402: }
9403: }
9404: }
9405: }
9406: }
9407: return;
9408: }
9409: // ]]>
9410: </script>
9411:
9412: ENDSCRIPT
9413:
9414: }
9415:
1.46 raeburn 9416: sub print_scantronformat {
9417: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9418: my $itemcount = 1;
1.60 raeburn 9419: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9420: %confhash);
1.46 raeburn 9421: my $switchserver = &check_switchserver($dom,$confname);
9422: my %lt = &Apache::lonlocal::texthash (
1.95 www 9423: default => 'Default bubblesheet format file error',
9424: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9425: );
9426: my %scantronfiles = (
9427: default => 'default.tab',
9428: custom => 'custom.tab',
9429: );
9430: foreach my $key (keys(%scantronfiles)) {
9431: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9432: .$scantronfiles{$key};
9433: }
9434: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9435: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9436: if (!$switchserver) {
9437: my $servadm = $r->dir_config('lonAdmEMail');
9438: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9439: if ($configuserok eq 'ok') {
9440: if ($author_ok eq 'ok') {
9441: my %legacyfile = (
1.160.6.97 raeburn 9442: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9443: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9444: );
9445: my %md5chk;
9446: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9447: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9448: chomp($md5chk{$type});
1.46 raeburn 9449: }
9450: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9451: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 9452: ($scantronurls{$type},my $error) =
1.46 raeburn 9453: &legacy_scantronformat($r,$dom,$confname,
9454: $type,$legacyfile{$type},
9455: $scantronurls{$type},
9456: $scantronfiles{$type});
1.60 raeburn 9457: if ($error ne '') {
9458: $error{$type} = $error;
9459: }
9460: }
9461: if (keys(%error) == 0) {
9462: $is_custom = 1;
1.160.6.97 raeburn 9463: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9464: $scantronurls{'custom'};
1.160.6.97 raeburn 9465: my $putresult =
1.60 raeburn 9466: &Apache::lonnet::put_dom('configuration',
9467: \%confhash,$dom);
9468: if ($putresult ne 'ok') {
1.160.6.97 raeburn 9469: $error{'custom'} =
1.60 raeburn 9470: '<span class="LC_error">'.
9471: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9472: }
1.46 raeburn 9473: }
9474: } else {
1.60 raeburn 9475: ($scantronurls{'default'},my $error) =
1.46 raeburn 9476: &legacy_scantronformat($r,$dom,$confname,
9477: 'default',$legacyfile{'default'},
9478: $scantronurls{'default'},
9479: $scantronfiles{'default'});
1.60 raeburn 9480: if ($error eq '') {
9481: $confhash{'scantron'}{'scantronformat'} = '';
9482: my $putresult =
9483: &Apache::lonnet::put_dom('configuration',
9484: \%confhash,$dom);
9485: if ($putresult ne 'ok') {
9486: $error{'default'} =
9487: '<span class="LC_error">'.
9488: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9489: }
9490: } else {
9491: $error{'default'} = $error;
9492: }
1.46 raeburn 9493: }
9494: }
9495: }
9496: } else {
1.95 www 9497: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9498: }
9499: }
9500: if (ref($settings) eq 'HASH') {
9501: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9502: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9503: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9504: $scantronurl = '';
9505: } else {
9506: $scantronurl = $settings->{'scantronformat'};
9507: }
9508: $is_custom = 1;
9509: } else {
9510: $scantronurl = $scantronurls{'default'};
9511: }
9512: } else {
1.60 raeburn 9513: if ($is_custom) {
9514: $scantronurl = $scantronurls{'custom'};
9515: } else {
9516: $scantronurl = $scantronurls{'default'};
9517: }
1.46 raeburn 9518: }
9519: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9520: $datatable .= '<tr'.$css_class.'>';
9521: if (!$is_custom) {
1.65 raeburn 9522: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9523: '<span class="LC_nobreak">';
1.46 raeburn 9524: if ($scantronurl) {
1.160.6.21 raeburn 9525: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9526: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9527: } else {
9528: $datatable = &mt('File unavailable for display');
9529: }
1.65 raeburn 9530: $datatable .= '</span></td>';
1.60 raeburn 9531: if (keys(%error) == 0) {
9532: $datatable .= '<td valign="bottom">';
9533: if (!$switchserver) {
9534: $datatable .= &mt('Upload:').'<br />';
9535: }
9536: } else {
9537: my $errorstr;
9538: foreach my $key (sort(keys(%error))) {
9539: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9540: }
9541: $datatable .= '<td>'.$errorstr;
9542: }
1.46 raeburn 9543: } else {
9544: if (keys(%error) > 0) {
9545: my $errorstr;
9546: foreach my $key (sort(keys(%error))) {
9547: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9548: }
1.60 raeburn 9549: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9550: } elsif ($scantronurl) {
1.160.6.26 raeburn 9551: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 9552: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9553: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 9554: $link.
9555: '<label><input type="checkbox" name="scantronformat_del"'.
9556: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9557: '<td><span class="LC_nobreak"> '.
9558: &mt('Replace:').'</span><br />';
1.46 raeburn 9559: }
9560: }
9561: if (keys(%error) == 0) {
9562: if ($switchserver) {
9563: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9564: } else {
1.65 raeburn 9565: $datatable .='<span class="LC_nobreak"> '.
9566: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9567: }
9568: }
9569: $datatable .= '</td></tr>';
9570: $$rowtotal ++;
9571: return $datatable;
9572: }
9573:
9574: sub legacy_scantronformat {
9575: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9576: my ($url,$error);
9577: my @statinfo = &Apache::lonnet::stat_file($newurl);
9578: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.160.6.118.2 14(raebu 9579:23): my $modified = [];
1.46 raeburn 9580: (my $result,$url) =
1.160.6.118.2 14(raebu 9581:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9582:23): 'scantron','','',$newfile,$modified);
9583:23): if ($result eq 'ok') {
9584:23): &update_modify_urls($r,$modified);
9585:23): } else {
1.130 raeburn 9586: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9587: }
9588: }
9589: return ($url,$error);
9590: }
1.43 raeburn 9591:
1.160.6.97 raeburn 9592: sub print_scantronconfig {
9593: my ($dom,$settings,$rowtotal) = @_;
9594: my $itemcount = 2;
9595: my $is_checked = ' checked="checked"';
9596: my %optionson = (
9597: hdr => ' checked="checked"',
9598: pad => ' checked="checked"',
9599: rem => ' checked="checked"',
9600: );
9601: my %optionsoff = (
9602: hdr => '',
9603: pad => '',
9604: rem => '',
9605: );
9606: my $currcsvsty = 'none';
9607: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9608: my @fields = &scantroncsv_fields();
9609: my %titles = &scantronconfig_titles();
9610: if (ref($settings) eq 'HASH') {
9611: if (ref($settings->{config}) eq 'HASH') {
9612: if ($settings->{config}->{dat}) {
9613: $checked{'dat'} = $is_checked;
9614: }
9615: if (ref($settings->{config}->{csv}) eq 'HASH') {
9616: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9617: %csvfields = %{$settings->{config}->{csv}->{fields}};
9618: if (keys(%csvfields) > 0) {
9619: $checked{'csv'} = $is_checked;
9620: $currcsvsty = 'block';
9621: }
9622: }
9623: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9624: %csvoptions = %{$settings->{config}->{csv}->{options}};
9625: foreach my $option (keys(%optionson)) {
9626: unless ($csvoptions{$option}) {
9627: $optionsoff{$option} = $optionson{$option};
9628: $optionson{$option} = '';
9629: }
9630: }
9631: }
9632: }
9633: } else {
9634: $checked{'dat'} = $is_checked;
9635: }
9636: } else {
9637: $checked{'dat'} = $is_checked;
9638: }
9639: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9640: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9641: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9642: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9643: foreach my $item ('dat','csv') {
9644: my $id;
9645: if ($item eq 'csv') {
9646: $id = 'id="scantronconfcsv" ';
9647: }
9648: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9649: $titles{$item}.'</label>'.(' 'x3);
9650: if ($item eq 'csv') {
9651: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9652: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9653: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9654: foreach my $col (@fields) {
9655: my $selnone;
9656: if ($csvfields{$col} eq '') {
9657: $selnone = ' selected="selected"';
9658: }
9659: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9660: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9661: '<option value=""'.$selnone.'></option>';
9662: for (my $i=0; $i<20; $i++) {
9663: my $shown = $i+1;
9664: my $sel;
9665: unless ($selnone) {
9666: if (exists($csvfields{$col})) {
9667: if ($csvfields{$col} == $i) {
9668: $sel = ' selected="selected"';
9669: }
9670: }
9671: }
9672: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9673: }
9674: $datatable .= '</select></td></tr>';
9675: }
9676: $datatable .= '</table></fieldset>'.
9677: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9678: '<legend>'.&mt('CSV Options').'</legend>';
9679: foreach my $option ('hdr','pad','rem') {
9680: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9681: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9682: &mt('Yes').'</label>'.(' 'x2)."\n".
9683: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9684: }
9685: $datatable .= '</fieldset>';
9686: $itemcount ++;
9687: }
9688: }
9689: $datatable .= '</td></tr>';
9690: $$rowtotal ++;
9691: return $datatable;
9692: }
9693:
9694: sub scantronconfig_titles {
9695: return &Apache::lonlocal::texthash(
9696: dat => 'Standard format (.dat)',
9697: csv => 'Comma separated values (.csv)',
9698: hdr => 'Remove first line in file (contains column titles)',
9699: pad => 'Prepend 0s to PaperID',
9700: rem => 'Remove leading spaces (except Question Response columns)',
9701: CODE => 'CODE',
9702: ID => 'Student ID',
9703: PaperID => 'Paper ID',
9704: FirstName => 'First Name',
9705: LastName => 'Last Name',
9706: FirstQuestion => 'First Question Response',
9707: Section => 'Section',
9708: );
9709: }
9710:
9711: sub scantroncsv_fields {
9712: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9713: }
9714:
1.49 raeburn 9715: sub print_coursecategories {
1.57 raeburn 9716: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9717: my $datatable;
9718: if ($position eq 'top') {
1.160.6.42 raeburn 9719: my (%checked);
9720: my @catitems = ('unauth','auth');
9721: my @cattypes = ('std','domonly','codesrch','none');
9722: $checked{'unauth'} = 'std';
9723: $checked{'auth'} = 'std';
9724: if (ref($settings) eq 'HASH') {
9725: foreach my $type (@cattypes) {
9726: if ($type eq $settings->{'unauth'}) {
9727: $checked{'unauth'} = $type;
9728: }
9729: if ($type eq $settings->{'auth'}) {
9730: $checked{'auth'} = $type;
9731: }
9732: }
9733: }
9734: my %lt = &Apache::lonlocal::texthash (
9735: unauth => 'Catalog type for unauthenticated users',
9736: auth => 'Catalog type for authenticated users',
9737: none => 'No catalog',
9738: std => 'Standard catalog',
9739: domonly => 'Domain-only catalog',
9740: codesrch => "Code search form",
9741: );
9742: my $itemcount = 0;
9743: foreach my $item (@catitems) {
9744: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9745: $datatable .= '<tr '.$css_class.'>'.
9746: '<td>'.$lt{$item}.'</td>'.
9747: '<td class="LC_right_item"><span class="LC_nobreak">';
9748: foreach my $type (@cattypes) {
9749: my $ischecked;
9750: if ($checked{$item} eq $type) {
9751: $ischecked=' checked="checked"';
9752: }
9753: $datatable .= '<label>'.
9754: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
9755: ' />'.$lt{$type}.'</label> ';
9756: }
1.160.6.87 raeburn 9757: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 9758: $itemcount ++;
9759: }
9760: $$rowtotal += $itemcount;
9761: } elsif ($position eq 'middle') {
1.57 raeburn 9762: my $toggle_cats_crs = ' ';
9763: my $toggle_cats_dom = ' checked="checked" ';
9764: my $can_cat_crs = ' ';
9765: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 9766: my $toggle_catscomm_comm = ' ';
9767: my $toggle_catscomm_dom = ' checked="checked" ';
9768: my $can_catcomm_comm = ' ';
9769: my $can_catcomm_dom = ' checked="checked" ';
9770:
1.57 raeburn 9771: if (ref($settings) eq 'HASH') {
9772: if ($settings->{'togglecats'} eq 'crs') {
9773: $toggle_cats_crs = $toggle_cats_dom;
9774: $toggle_cats_dom = ' ';
9775: }
9776: if ($settings->{'categorize'} eq 'crs') {
9777: $can_cat_crs = $can_cat_dom;
9778: $can_cat_dom = ' ';
9779: }
1.120 raeburn 9780: if ($settings->{'togglecatscomm'} eq 'comm') {
9781: $toggle_catscomm_comm = $toggle_catscomm_dom;
9782: $toggle_catscomm_dom = ' ';
9783: }
9784: if ($settings->{'categorizecomm'} eq 'comm') {
9785: $can_catcomm_comm = $can_catcomm_dom;
9786: $can_catcomm_dom = ' ';
9787: }
1.57 raeburn 9788: }
9789: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 9790: togglecats => 'Show/Hide a course in catalog',
9791: togglecatscomm => 'Show/Hide a community in catalog',
9792: categorize => 'Assign a category to a course',
9793: categorizecomm => 'Assign a category to a community',
1.57 raeburn 9794: );
9795: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 9796: dom => 'Set in Domain',
9797: crs => 'Set in Course',
9798: comm => 'Set in Community',
1.57 raeburn 9799: );
9800: $datatable = '<tr class="LC_odd_row">'.
9801: '<td>'.$title{'togglecats'}.'</td>'.
9802: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9803: '<input type="radio" name="togglecats"'.
9804: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9805: '<label><input type="radio" name="togglecats"'.
9806: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
9807: '</tr><tr>'.
9808: '<td>'.$title{'categorize'}.'</td>'.
9809: '<td class="LC_right_item"><span class="LC_nobreak">'.
9810: '<label><input type="radio" name="categorize"'.
9811: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9812: '<label><input type="radio" name="categorize"'.
9813: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 9814: '</tr><tr class="LC_odd_row">'.
9815: '<td>'.$title{'togglecatscomm'}.'</td>'.
9816: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
9817: '<input type="radio" name="togglecatscomm"'.
9818: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9819: '<label><input type="radio" name="togglecatscomm"'.
9820: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
9821: '</tr><tr>'.
9822: '<td>'.$title{'categorizecomm'}.'</td>'.
9823: '<td class="LC_right_item"><span class="LC_nobreak">'.
9824: '<label><input type="radio" name="categorizecomm"'.
9825: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
9826: '<label><input type="radio" name="categorizecomm"'.
9827: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 9828: '</tr>';
1.120 raeburn 9829: $$rowtotal += 4;
1.57 raeburn 9830: } else {
9831: my $css_class;
9832: my $itemcount = 1;
9833: my $cathash;
9834: if (ref($settings) eq 'HASH') {
9835: $cathash = $settings->{'cats'};
9836: }
9837: if (ref($cathash) eq 'HASH') {
9838: my (@cats,@trails,%allitems,%idx,@jsarray);
9839: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
9840: \%allitems,\%idx,\@jsarray);
9841: my $maxdepth = scalar(@cats);
9842: my $colattrib = '';
9843: if ($maxdepth > 2) {
9844: $colattrib = ' colspan="2" ';
9845: }
9846: my @path;
9847: if (@cats > 0) {
9848: if (ref($cats[0]) eq 'ARRAY') {
9849: my $numtop = @{$cats[0]};
9850: my $maxnum = $numtop;
1.120 raeburn 9851: my %default_names = (
9852: instcode => &mt('Official courses'),
9853: communities => &mt('Communities'),
9854: );
9855:
9856: if ((!grep(/^instcode$/,@{$cats[0]})) ||
9857: ($cathash->{'instcode::0'} eq '') ||
9858: (!grep(/^communities$/,@{$cats[0]})) ||
9859: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 9860: $maxnum ++;
9861: }
9862: my $lastidx;
9863: for (my $i=0; $i<$numtop; $i++) {
9864: my $parent = $cats[0][$i];
9865: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9866: my $item = &escape($parent).'::0';
9867: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
9868: $lastidx = $idx{$item};
9869: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
9870: .'<select name="'.$item.'"'.$chgstr.'>';
9871: for (my $k=0; $k<=$maxnum; $k++) {
9872: my $vpos = $k+1;
9873: my $selstr;
9874: if ($k == $i) {
9875: $selstr = ' selected="selected" ';
9876: }
9877: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9878: }
1.160.6.29 raeburn 9879: $datatable .= '</select></span></td><td>';
1.120 raeburn 9880: if ($parent eq 'instcode' || $parent eq 'communities') {
9881: $datatable .= '<span class="LC_nobreak">'
9882: .$default_names{$parent}.'</span>';
9883: if ($parent eq 'instcode') {
9884: $datatable .= '<br /><span class="LC_nobreak">('
9885: .&mt('with institutional codes')
9886: .')</span></td><td'.$colattrib.'>';
9887: } else {
9888: $datatable .= '<table><tr><td>';
9889: }
9890: $datatable .= '<span class="LC_nobreak">'
9891: .'<label><input type="radio" name="'
9892: .$parent.'" value="1" checked="checked" />'
9893: .&mt('Display').'</label>';
9894: if ($parent eq 'instcode') {
9895: $datatable .= ' ';
9896: } else {
9897: $datatable .= '</span></td></tr><tr><td>'
9898: .'<span class="LC_nobreak">';
9899: }
9900: $datatable .= '<label><input type="radio" name="'
9901: .$parent.'" value="0" />'
9902: .&mt('Do not display').'</label></span>';
9903: if ($parent eq 'communities') {
9904: $datatable .= '</td></tr></table>';
9905: }
9906: $datatable .= '</td>';
1.57 raeburn 9907: } else {
9908: $datatable .= $parent
1.160.6.29 raeburn 9909: .' <span class="LC_nobreak"><label>'
9910: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 9911: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
9912: }
9913: my $depth = 1;
9914: push(@path,$parent);
9915: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
9916: pop(@path);
9917: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
9918: $itemcount ++;
9919: }
1.48 raeburn 9920: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 9921: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
9922: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 9923: for (my $k=0; $k<=$maxnum; $k++) {
9924: my $vpos = $k+1;
9925: my $selstr;
1.57 raeburn 9926: if ($k == $numtop) {
1.48 raeburn 9927: $selstr = ' selected="selected" ';
9928: }
9929: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9930: }
1.59 bisitz 9931: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 9932: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
9933: .'</tr>'."\n";
1.48 raeburn 9934: $itemcount ++;
1.120 raeburn 9935: foreach my $default ('instcode','communities') {
9936: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
9937: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9938: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
9939: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
9940: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
9941: for (my $k=0; $k<=$maxnum; $k++) {
9942: my $vpos = $k+1;
9943: my $selstr;
9944: if ($k == $maxnum) {
9945: $selstr = ' selected="selected" ';
9946: }
9947: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 9948: }
1.120 raeburn 9949: $datatable .= '</select></span></td>'.
9950: '<td><span class="LC_nobreak">'.
9951: $default_names{$default}.'</span>';
9952: if ($default eq 'instcode') {
9953: $datatable .= '<br /><span class="LC_nobreak">('
9954: .&mt('with institutional codes').')</span>';
9955: }
9956: $datatable .= '</td>'
9957: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
9958: .&mt('Display').'</label> '
9959: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
9960: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 9961: }
9962: }
9963: }
1.57 raeburn 9964: } else {
9965: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 9966: }
9967: } else {
1.160.6.87 raeburn 9968: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 9969: .&initialize_categories($itemcount);
1.48 raeburn 9970: }
1.57 raeburn 9971: $$rowtotal += $itemcount;
1.48 raeburn 9972: }
9973: return $datatable;
9974: }
9975:
1.69 raeburn 9976: sub print_serverstatuses {
9977: my ($dom,$settings,$rowtotal) = @_;
9978: my $datatable;
9979: my @pages = &serverstatus_pages();
9980: my (%namedaccess,%machineaccess);
9981: foreach my $type (@pages) {
9982: $namedaccess{$type} = '';
9983: $machineaccess{$type}= '';
9984: }
9985: if (ref($settings) eq 'HASH') {
9986: foreach my $type (@pages) {
9987: if (exists($settings->{$type})) {
9988: if (ref($settings->{$type}) eq 'HASH') {
9989: foreach my $key (keys(%{$settings->{$type}})) {
9990: if ($key eq 'namedusers') {
9991: $namedaccess{$type} = $settings->{$type}->{$key};
9992: } elsif ($key eq 'machines') {
9993: $machineaccess{$type} = $settings->{$type}->{$key};
9994: }
9995: }
9996: }
9997: }
9998: }
9999: }
1.81 raeburn 10000: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10001: my $rownum = 0;
10002: my $css_class;
10003: foreach my $type (@pages) {
10004: $rownum ++;
10005: $css_class = $rownum%2?' class="LC_odd_row"':'';
10006: $datatable .= '<tr'.$css_class.'>'.
10007: '<td><span class="LC_nobreak">'.
10008: $titles->{$type}.'</span></td>'.
10009: '<td class="LC_left_item">'.
10010: '<input type="text" name="'.$type.'_namedusers" '.
10011: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10012: '<td class="LC_right_item">'.
10013: '<span class="LC_nobreak">'.
10014: '<input type="text" name="'.$type.'_machines" '.
10015: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 10016: '</span></td></tr>'."\n";
1.69 raeburn 10017: }
10018: $$rowtotal += $rownum;
10019: return $datatable;
10020: }
10021:
10022: sub serverstatus_pages {
10023: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 10024: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 10025: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 10026: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10027: }
10028:
1.160.6.40 raeburn 10029: sub defaults_javascript {
10030: my ($settings) = @_;
1.160.6.98 raeburn 10031: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 10032:23): my $portal_js = <<"ENDPORTAL";
10033:23):
10034:23): function portalExtras(caller) {
10035:23): var x = caller.value;
10036:23): var y = new Array('email','web');
10037:23): for (var i=0; i<y.length; i++) {
10038:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
10039:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
10040:23): if (x.length > 0) {
10041:23): z.style.display = 'block';
10042:23): } else {
10043:23): z.style.display = 'none';
10044:23): }
10045:23): }
10046:23): }
10047:23): }
10048:23): ENDPORTAL
1.160.6.40 raeburn 10049: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10050: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10051: if ($maxnum eq '') {
10052: $maxnum = 0;
10053: }
10054: $maxnum ++;
1.160.6.51 raeburn 10055: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 10056: return <<"ENDSCRIPT";
10057: <script type="text/javascript">
10058: // <![CDATA[
10059: function reorderTypes(form,caller) {
10060: var changedVal;
10061: $jstext
10062: var newpos = 'addinststatus_pos';
10063: var current = new Array;
10064: var maxh = $maxnum;
10065: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10066: var oldVal;
10067: if (caller == newpos) {
10068: changedVal = newitemVal;
10069: } else {
10070: var curritem = 'inststatus_pos_'+caller;
10071: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10072: current[newitemVal] = newpos;
10073: }
10074: for (var i=0; i<inststatuses.length; i++) {
10075: if (inststatuses[i] != caller) {
10076: var elementName = 'inststatus_pos_'+inststatuses[i];
10077: if (form.elements[elementName]) {
10078: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10079: current[currVal] = elementName;
10080: }
10081: }
10082: }
10083: for (var j=0; j<maxh; j++) {
10084: if (current[j] == undefined) {
10085: oldVal = j;
10086: }
10087: }
10088: if (oldVal < changedVal) {
10089: for (var k=oldVal+1; k<=changedVal ; k++) {
10090: var elementName = current[k];
10091: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10092: }
10093: } else {
10094: for (var k=changedVal; k<oldVal; k++) {
10095: var elementName = current[k];
10096: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10097: }
10098: }
10099: return;
10100: }
10101:
1.160.6.118.2 12(raebu 10102:23): $portal_js
10103:23):
10104:23): // ]]>
10105:23): </script>
10106:23):
10107:23): ENDSCRIPT
10108:23): } else {
10109:23): return <<"ENDSCRIPT";
10110:23): <script type="text/javascript">
10111:23): // <![CDATA[
10112:23): $portal_js
1.160.6.40 raeburn 10113: // ]]>
10114: </script>
10115:
10116: ENDSCRIPT
10117: }
1.160.6.118.2 14(raebu 10118:23): return;
1.160.6.40 raeburn 10119: }
10120:
1.160.6.98 raeburn 10121: sub passwords_javascript {
1.160.6.118.2 5(raebur 10122:2): my ($prefix) = @_;
10123:2): my %intalert;
10124:2): if ($prefix eq 'passwords') {
10125:2): %intalert = &Apache::lonlocal::texthash (
10126: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.',
10127:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10128:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10129:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10130:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10131:2): );
14(raebu 10132:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 10133:2): %intalert = &Apache::lonlocal::texthash (
10134:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10135:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10136:2): );
10137:2): }
1.160.6.99 raeburn 10138: &js_escape(\%intalert);
10139: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 10140:2): my $intauthjs;
10141:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 10142:
10143: function warnIntAuth(field) {
10144: if (field.name == 'intauth_check') {
10145: if (field.value == '2') {
1.160.6.99 raeburn 10146: alert('$intalert{authcheck}');
1.160.6.98 raeburn 10147: }
10148: }
10149: if (field.name == 'intauth_cost') {
10150: field.value.replace(/\s/g,'');
10151: if (field.value != '') {
10152: var regexdigit=/^\\d+\$/;
10153: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 10154: alert('$intalert{authcost}');
10155: }
10156: }
10157: }
10158: return;
10159: }
10160:
1.160.6.118.2 5(raebur 10161:2): ENDSCRIPT
10162:2):
10163:2): }
10164:2):
10165:2): $intauthjs .= <<"ENDSCRIPT";
10166:2):
10167:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 10168: field.value.replace(/^\s+/,'');
10169: field.value.replace(/\s+\$/,'');
10170: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 10171:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 10172: if (field.value == '') {
10173: alert('$intalert{passmin}');
10174: field.value = '$defmin';
10175: } else {
10176: if (!regexdigit.test(field.value)) {
10177: alert('$intalert{passmin}');
10178: field.value = '$defmin';
10179: }
10180: var minval = parseInt(field.value,10);
10181: if (minval < $defmin) {
10182: alert('$intalert{passmin}');
10183: field.value = '$defmin';
10184: }
10185: }
10186: } else {
10187: if (field.value == '0') {
10188: field.value = '';
10189: }
10190: if (field.value != '') {
1.160.6.118.2 5(raebur 10191:2): if (!regexdigit.test(field.value)) {
10192:2): if (field.name == '${prefix}_max') {
10193:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 10194: } else {
1.160.6.118.2 5(raebur 10195:2): if (field.name == '${prefix}_numsaved') {
10196:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 10197: }
10198: }
1.160.6.118.2 5(raebur 10199:2): field.value = '';
1.160.6.98 raeburn 10200: }
10201: }
10202: }
10203: return;
10204: }
10205:
10206: ENDSCRIPT
10207: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10208: }
10209:
1.49 raeburn 10210: sub coursecategories_javascript {
10211: my ($settings) = @_;
1.57 raeburn 10212: my ($output,$jstext,$cathash);
1.49 raeburn 10213: if (ref($settings) eq 'HASH') {
1.57 raeburn 10214: $cathash = $settings->{'cats'};
10215: }
10216: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10217: my (@cats,@jsarray,%idx);
1.57 raeburn 10218: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10219: if (@jsarray > 0) {
10220: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10221: for (my $i=0; $i<@jsarray; $i++) {
10222: if (ref($jsarray[$i]) eq 'ARRAY') {
10223: my $catstr = join('","',@{$jsarray[$i]});
10224: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10225: }
10226: }
10227: }
10228: } else {
10229: $jstext = ' var categories = Array(1);'."\n".
10230: ' categories[0] = Array("instcode_pos");'."\n";
10231: }
1.160.6.42 raeburn 10232: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10233: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 10234: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10235: &js_escape(\$instcode_reserved);
10236: &js_escape(\$communities_reserved);
10237: &js_escape(\$choose_again);
1.49 raeburn 10238: $output = <<"ENDSCRIPT";
10239: <script type="text/javascript">
1.109 raeburn 10240: // <![CDATA[
1.49 raeburn 10241: function reorderCats(form,parent,item,idx) {
10242: var changedVal;
10243: $jstext
10244: var newpos = 'addcategory_pos';
10245: if (parent == '') {
10246: var has_instcode = 0;
10247: var maxtop = categories[idx].length;
10248: for (var j=0; j<maxtop; j++) {
10249: if (categories[idx][j] == 'instcode::0') {
10250: has_instcode == 1;
10251: }
10252: }
10253: if (has_instcode == 0) {
10254: categories[idx][maxtop] = 'instcode_pos';
10255: }
10256: } else {
10257: newpos += '_'+parent;
10258: }
10259: var maxh = 1 + categories[idx].length;
10260: var current = new Array;
10261: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10262: if (item == newpos) {
10263: changedVal = newitemVal;
10264: } else {
10265: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10266: current[newitemVal] = newpos;
10267: }
10268: for (var i=0; i<categories[idx].length; i++) {
10269: var elementName = categories[idx][i];
10270: if (elementName != item) {
10271: if (form.elements[elementName]) {
10272: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10273: current[currVal] = elementName;
10274: }
10275: }
10276: }
10277: var oldVal;
10278: for (var j=0; j<maxh; j++) {
10279: if (current[j] == undefined) {
10280: oldVal = j;
10281: }
10282: }
10283: if (oldVal < changedVal) {
10284: for (var k=oldVal+1; k<=changedVal ; k++) {
10285: var elementName = current[k];
10286: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10287: }
10288: } else {
10289: for (var k=changedVal; k<oldVal; k++) {
10290: var elementName = current[k];
10291: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10292: }
10293: }
10294: return;
10295: }
1.120 raeburn 10296:
10297: function categoryCheck(form) {
10298: if (form.elements['addcategory_name'].value == 'instcode') {
10299: alert('$instcode_reserved\\n$choose_again');
10300: return false;
10301: }
10302: if (form.elements['addcategory_name'].value == 'communities') {
10303: alert('$communities_reserved\\n$choose_again');
10304: return false;
10305: }
10306: return true;
10307: }
10308:
1.109 raeburn 10309: // ]]>
1.49 raeburn 10310: </script>
10311:
10312: ENDSCRIPT
10313: return $output;
10314: }
10315:
1.48 raeburn 10316: sub initialize_categories {
10317: my ($itemcount) = @_;
1.120 raeburn 10318: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 10319: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10320: instcode => 'Official courses (with institutional codes)',
10321: communities => 'Communities',
10322: );
10323: my $select0 = ' selected="selected"';
10324: my $select1 = '';
10325: foreach my $default ('instcode','communities') {
10326: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 10327: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 10328: if ($default eq 'communities') {
10329: $select1 = $select0;
10330: $select0 = '';
10331: }
10332: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10333: .'<select name="'.$default.'_pos">'
10334: .'<option value="0"'.$select0.'>1</option>'
10335: .'<option value="1"'.$select1.'>2</option>'
10336: .'<option value="2">3</option></select> '
10337: .$default_names{$default}
10338: .'</span></td><td><span class="LC_nobreak">'
10339: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10340: .&mt('Display').'</label> <label>'
10341: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10342: .'</label></span></td></tr>';
1.120 raeburn 10343: $itemcount ++;
10344: }
1.48 raeburn 10345: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10346: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10347: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10348: .'<select name="addcategory_pos"'.$chgstr.'>'
10349: .'<option value="0">1</option>'
10350: .'<option value="1">2</option>'
10351: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 10352: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 10353: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10354: .'</td></tr>';
1.48 raeburn 10355: return $datatable;
10356: }
10357:
10358: sub build_category_rows {
1.49 raeburn 10359: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10360: my ($text,$name,$item,$chgstr);
1.48 raeburn 10361: if (ref($cats) eq 'ARRAY') {
10362: my $maxdepth = scalar(@{$cats});
10363: if (ref($cats->[$depth]) eq 'HASH') {
10364: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10365: my $numchildren = @{$cats->[$depth]{$parent}};
10366: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 10367: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10368: my ($idxnum,$parent_name,$parent_item);
10369: my $higher = $depth - 1;
10370: if ($higher == 0) {
10371: $parent_name = &escape($parent).'::'.$higher;
10372: } else {
10373: if (ref($path) eq 'ARRAY') {
10374: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10375: }
10376: }
10377: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10378: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10379: if ($j < $numchildren) {
1.48 raeburn 10380: $name = $cats->[$depth]{$parent}[$j];
10381: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10382: $idxnum = $idx->{$item};
10383: } else {
10384: $name = $parent_name;
10385: $item = $parent_item;
1.48 raeburn 10386: }
1.49 raeburn 10387: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10388: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10389: for (my $i=0; $i<=$numchildren; $i++) {
10390: my $vpos = $i+1;
10391: my $selstr;
10392: if ($j == $i) {
10393: $selstr = ' selected="selected" ';
10394: }
10395: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10396: }
10397: $text .= '</select> ';
10398: if ($j < $numchildren) {
10399: my $deeper = $depth+1;
10400: $text .= $name.' '
10401: .'<label><input type="checkbox" name="deletecategory" value="'
10402: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10403: if(ref($path) eq 'ARRAY') {
10404: push(@{$path},$name);
1.49 raeburn 10405: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10406: pop(@{$path});
10407: }
10408: } else {
1.160.6.87 raeburn 10409: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10410: if ($j == $numchildren) {
10411: $text .= $name;
10412: } else {
10413: $text .= $item;
10414: }
10415: $text .= '" value="" />';
10416: }
10417: $text .= '</td></tr>';
10418: }
10419: $text .= '</table></td>';
10420: } else {
10421: my $higher = $depth-1;
10422: if ($higher == 0) {
10423: $name = &escape($parent).'::'.$higher;
10424: } else {
10425: if (ref($path) eq 'ARRAY') {
10426: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10427: }
10428: }
10429: my $colspan;
10430: if ($parent ne 'instcode') {
10431: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 10432: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10433: }
10434: }
10435: }
10436: }
10437: return $text;
10438: }
10439:
1.33 raeburn 10440: sub modifiable_userdata_row {
1.160.6.93 raeburn 10441: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.160.6.118.2 14(raebu 10442:23): $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.160.6.35 raeburn 10443: my ($role,$rolename,$statustype);
10444: $role = $item;
1.160.6.34 raeburn 10445: if ($context eq 'cancreate') {
1.160.6.93 raeburn 10446: if ($item =~ /^(emailusername)_(.+)$/) {
10447: $role = $1;
10448: $statustype = $2;
1.160.6.35 raeburn 10449: if (ref($usertypes) eq 'HASH') {
10450: if ($usertypes->{$statustype}) {
10451: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10452: } else {
10453: $rolename = &mt('Data provided by user');
10454: }
10455: }
1.160.6.34 raeburn 10456: }
10457: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10458: if (ref($usertypes) eq 'HASH') {
10459: $rolename = $usertypes->{$role};
10460: } else {
10461: $rolename = $role;
10462: }
1.160.6.118.2 14(raebu 10463:23): } elsif ($context eq 'lti') {
10464:23): $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 10465: } else {
1.63 raeburn 10466: if ($role eq 'cr') {
10467: $rolename = &mt('Custom role');
10468: } else {
10469: $rolename = &Apache::lonnet::plaintext($role);
10470: }
1.33 raeburn 10471: }
1.160.6.34 raeburn 10472: my (@fields,%fieldtitles);
10473: if (ref($fieldsref) eq 'ARRAY') {
10474: @fields = @{$fieldsref};
10475: } else {
10476: @fields = ('lastname','firstname','middlename','generation',
10477: 'permanentemail','id');
10478: }
10479: if ((ref($titlesref) eq 'HASH')) {
10480: %fieldtitles = %{$titlesref};
10481: } else {
10482: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10483: }
1.33 raeburn 10484: my $output;
1.160.6.93 raeburn 10485: my $css_class;
10486: if ($rowcount%2) {
10487: $css_class = 'LC_odd_row';
10488: }
10489: if ($customcss) {
10490: $css_class .= " $customcss";
10491: }
10492: $css_class =~ s/^\s+//;
10493: if ($css_class) {
10494: $css_class = ' class="'.$css_class.'"';
10495: }
10496: if ($rowstyle) {
10497: $css_class .= ' style="'.$rowstyle.'"';
10498: }
10499: if ($rowid) {
10500: $rowid = ' id="'.$rowid.'"';
10501: }
10502: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10503: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10504: '<td class="LC_left_item" colspan="2"><table>';
10505: my $rem;
10506: my %checks;
10507: if (ref($settings) eq 'HASH') {
1.160.6.118.2 14(raebu 10508:23): my $hashref;
10509:23): if ($context eq 'lti') {
10510:23): if (ref($settings) eq 'HASH') {
10511:23): $hashref = $settings->{'instdata'};
10512:23): }
10513:23): } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10514: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.118.2 14(raebu 10515:23): $hashref = $settings->{'lti_instdata'};
10516:23): }
10517:23): if ($role eq 'emailusername') {
10518:23): if ($statustype) {
10519:23): if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10520:23): $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.35 raeburn 10521: }
1.160.6.118.2 14(raebu 10522:23): }
10523:23): }
10524:23): }
10525:23): if (ref($hashref) eq 'HASH') {
10526:23): foreach my $field (@fields) {
10527:23): if ($hashref->{$field}) {
10528:23): if ($role eq 'emailusername') {
10529:23): $checks{$field} = $hashref->{$field};
10530:23): } else {
10531:23): $checks{$field} = ' checked="checked" ';
1.33 raeburn 10532: }
10533: }
10534: }
10535: }
10536: }
1.160.6.93 raeburn 10537: my $total = scalar(@fields);
10538: for (my $i=0; $i<$total; $i++) {
10539: $rem = $i%($numinrow);
1.33 raeburn 10540: if ($rem == 0) {
10541: if ($i > 0) {
10542: $output .= '</tr>';
10543: }
10544: $output .= '<tr>';
10545: }
10546: my $check = ' ';
1.160.6.35 raeburn 10547: unless ($role eq 'emailusername') {
10548: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 10549: $check = $checks{$fields[$i]};
1.160.6.118.2 14(raebu 10550:23): } elsif ($context ne 'lti') {
1.160.6.35 raeburn 10551: if ($role eq 'st') {
10552: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 10553: $check = ' checked="checked" ';
1.160.6.35 raeburn 10554: }
1.33 raeburn 10555: }
10556: }
10557: }
10558: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 10559: '<span class="LC_nobreak">';
1.160.6.118.2 14(raebu 10560:23): my $prefix = 'canmodify';
1.160.6.35 raeburn 10561: if ($role eq 'emailusername') {
10562: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10563: $checks{$fields[$i]} = 'omit';
10564: }
10565: foreach my $option ('required','optional','omit') {
10566: my $checked='';
10567: if ($checks{$fields[$i]} eq $option) {
10568: $checked='checked="checked" ';
10569: }
10570: $output .= '<label>'.
1.160.6.118.2 14(raebu 10571:23): '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.160.6.35 raeburn 10572: &mt($option).'</label>'.(' ' x2);
10573: }
10574: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10575: } else {
1.160.6.118.2 14(raebu 10576:23): if ($context eq 'lti') {
10577:23): $prefix = 'lti';
10578:23): }
1.160.6.35 raeburn 10579: $output .= '<label>'.
1.160.6.118.2 14(raebu 10580:23): '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.160.6.35 raeburn 10581: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10582: '</label>';
10583: }
10584: $output .= '</span></td>';
1.33 raeburn 10585: }
1.160.6.93 raeburn 10586: $rem = $total%$numinrow;
10587: my $colsleft;
10588: if ($rem) {
10589: $colsleft = $numinrow - $rem;
10590: }
10591: if ($colsleft > 1) {
1.33 raeburn 10592: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10593: ' </td>';
10594: } elsif ($colsleft == 1) {
10595: $output .= '<td class="LC_left_item"> </td>';
10596: }
10597: $output .= '</tr></table></td></tr>';
10598: return $output;
10599: }
1.28 raeburn 10600:
1.93 raeburn 10601: sub insttypes_row {
1.160.6.93 raeburn 10602: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10603: $customcss,$rowstyle) = @_;
1.93 raeburn 10604: my %lt = &Apache::lonlocal::texthash (
10605: cansearch => 'Users allowed to search',
10606: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.131 raeburn 10607: lockablenames => 'User preference to lock name',
1.160.6.93 raeburn 10608: selfassign => 'Self-reportable affiliations',
1.160.6.101 raeburn 10609: overrides => "Override domain's helpdesk settings based on requester's affiliation",
1.93 raeburn 10610: );
10611: my $showdom;
10612: if ($context eq 'cansearch') {
10613: $showdom = ' ('.$dom.')';
10614: }
1.160.6.5 raeburn 10615: my $class = 'LC_left_item';
10616: if ($context eq 'statustocreate') {
10617: $class = 'LC_right_item';
10618: }
1.160.6.93 raeburn 10619: my $css_class;
10620: if ($$rowtotal%2) {
10621: $css_class = 'LC_odd_row';
10622: }
10623: if ($customcss) {
10624: $css_class .= ' '.$customcss;
10625: }
10626: $css_class =~ s/^\s+//;
10627: if ($css_class) {
10628: $css_class = ' class="'.$css_class.'"';
10629: }
10630: if ($rowstyle) {
10631: $css_class .= ' style="'.$rowstyle.'"';
10632: }
10633: if ($onclick) {
10634: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 10635: }
10636: my $output = '<tr'.$css_class.'>'.
10637: '<td>'.$lt{$context}.$showdom.
10638: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10639: my $rem;
10640: if (ref($types) eq 'ARRAY') {
10641: for (my $i=0; $i<@{$types}; $i++) {
10642: if (defined($usertypes->{$types->[$i]})) {
10643: my $rem = $i%($numinrow);
10644: if ($rem == 0) {
10645: if ($i > 0) {
10646: $output .= '</tr>';
10647: }
10648: $output .= '<tr>';
1.23 raeburn 10649: }
1.26 raeburn 10650: my $check = ' ';
1.99 raeburn 10651: if (ref($settings) eq 'HASH') {
10652: if (ref($settings->{$context}) eq 'ARRAY') {
10653: if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10654: $check = ' checked="checked" ';
10655: }
1.160.6.101 raeburn 10656: } elsif (ref($settings->{$context}) eq 'HASH') {
10657: if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10658: $check = ' checked="checked" ';
10659: }
1.99 raeburn 10660: } elsif ($context eq 'statustocreate') {
1.26 raeburn 10661: $check = ' checked="checked" ';
10662: }
1.23 raeburn 10663: }
1.26 raeburn 10664: $output .= '<td class="LC_left_item">'.
10665: '<span class="LC_nobreak"><label>'.
1.93 raeburn 10666: '<input type="checkbox" name="'.$context.'" '.
1.160.6.118.2 14(raebu 10667:23): 'value="'.$types->[$i].'"'.$check.$onclick.' />'.
1.26 raeburn 10668: $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10669: }
10670: }
1.26 raeburn 10671: $rem = @{$types}%($numinrow);
1.23 raeburn 10672: }
10673: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 10674: if ($context eq 'overrides') {
10675: if ($colsleft > 1) {
10676: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10677: } else {
10678: $output .= '<td class="LC_left_item">';
10679: }
10680: $output .= ' ';
1.23 raeburn 10681: } else {
1.160.6.101 raeburn 10682: if ($rem == 0) {
10683: $output .= '<tr>';
10684: }
10685: if ($colsleft > 1) {
10686: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10687: } else {
10688: $output .= '<td class="LC_left_item">';
10689: }
10690: my $defcheck = ' ';
10691: if (ref($settings) eq 'HASH') {
10692: if (ref($settings->{$context}) eq 'ARRAY') {
10693: if (grep(/^default$/,@{$settings->{$context}})) {
10694: $defcheck = ' checked="checked" ';
10695: }
10696: } elsif ($context eq 'statustocreate') {
1.99 raeburn 10697: $defcheck = ' checked="checked" ';
10698: }
1.26 raeburn 10699: }
1.160.6.101 raeburn 10700: $output .= '<span class="LC_nobreak"><label>'.
10701: '<input type="checkbox" name="'.$context.'" '.
10702: 'value="default"'.$defcheck.$onclick.' />'.
10703: $othertitle.'</label></span>';
1.23 raeburn 10704: }
1.160.6.101 raeburn 10705: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 10706: return $output;
1.23 raeburn 10707: }
10708:
10709: sub sorted_searchtitles {
10710: my %searchtitles = &Apache::lonlocal::texthash(
10711: 'uname' => 'username',
10712: 'lastname' => 'last name',
10713: 'lastfirst' => 'last name, first name',
10714: );
10715: my @titleorder = ('uname','lastname','lastfirst');
10716: return (\%searchtitles,\@titleorder);
10717: }
10718:
1.25 raeburn 10719: sub sorted_searchtypes {
10720: my %srchtypes_desc = (
10721: exact => 'is exact match',
10722: contains => 'contains ..',
10723: begins => 'begins with ..',
10724: );
10725: my @srchtypeorder = ('exact','begins','contains');
10726: return (\%srchtypes_desc,\@srchtypeorder);
10727: }
10728:
1.3 raeburn 10729: sub usertype_update_row {
10730: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
10731: my $datatable;
10732: my $numinrow = 4;
10733: foreach my $type (@{$types}) {
10734: if (defined($usertypes->{$type})) {
10735: $$rownums ++;
10736: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
10737: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
10738: '</td><td class="LC_left_item"><table>';
10739: for (my $i=0; $i<@{$fields}; $i++) {
10740: my $rem = $i%($numinrow);
10741: if ($rem == 0) {
10742: if ($i > 0) {
10743: $datatable .= '</tr>';
10744: }
10745: $datatable .= '<tr>';
10746: }
10747: my $check = ' ';
1.39 raeburn 10748: if (ref($settings) eq 'HASH') {
10749: if (ref($settings->{'fields'}) eq 'HASH') {
10750: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
10751: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
10752: $check = ' checked="checked" ';
10753: }
1.3 raeburn 10754: }
10755: }
10756: }
10757:
10758: if ($i == @{$fields}-1) {
10759: my $colsleft = $numinrow - $rem;
10760: if ($colsleft > 1) {
10761: $datatable .= '<td colspan="'.$colsleft.'">';
10762: } else {
10763: $datatable .= '<td>';
10764: }
10765: } else {
10766: $datatable .= '<td>';
10767: }
1.8 raeburn 10768: $datatable .= '<span class="LC_nobreak"><label>'.
10769: '<input type="checkbox" name="updateable_'.$type.
10770: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
10771: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 10772: }
10773: $datatable .= '</tr></table></td></tr>';
10774: }
10775: }
10776: return $datatable;
1.1 raeburn 10777: }
10778:
10779: sub modify_login {
1.160.6.24 raeburn 10780: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 10781: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 10782: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 10783:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 10784: %title = ( coursecatalog => 'Display course catalog',
10785: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 10786: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 10787: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 10788: loginheader => 'Log-in box header',
10789: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 10790: @offon = ('off','on');
1.112 raeburn 10791: if (ref($domconfig{login}) eq 'HASH') {
10792: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
10793: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
10794: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
10795: }
10796: }
1.160.6.113 raeburn 10797: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
10798: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
10799: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
10800: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
10801: $saml{$lonhost} = 1;
10802: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
10803: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
10804: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
10805: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
10806: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 10807:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 10808: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
10809: }
10810: }
10811: }
1.112 raeburn 10812: }
1.9 raeburn 10813: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
10814: \%domconfig,\%loginhash);
1.160.6.14 raeburn 10815: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 10816: foreach my $item (@toggles) {
10817: $loginhash{login}{$item} = $env{'form.'.$item};
10818: }
1.41 raeburn 10819: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 10820: if (ref($colchanges{'login'}) eq 'HASH') {
10821: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
10822: \%loginhash);
10823: }
1.110 raeburn 10824:
1.149 raeburn 10825: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 10826: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 10827: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 10828: if (keys(%servers) > 1) {
10829: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 10830: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
10831: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
10832: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
10833: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
10834: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
10835: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10836: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10837: $changes{'loginvia'}{$lonhost} = 1;
10838: } else {
10839: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
10840: $changes{'loginvia'}{$lonhost} = 1;
10841: }
10842: } else {
10843: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10844: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
10845: $changes{'loginvia'}{$lonhost} = 1;
10846: }
10847: }
10848: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
10849: foreach my $item (@loginvia_attribs) {
10850: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
10851: }
10852: } else {
10853: foreach my $item (@loginvia_attribs) {
10854: my $new = $env{'form.'.$lonhost.'_'.$item};
10855: if (($item eq 'serverpath') && ($new eq 'custom')) {
10856: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
10857: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10858: $new = '/';
10859: }
10860: }
10861: if (($item eq 'custompath') &&
10862: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10863: $new = '';
10864: }
10865: if ($new ne $curr_loginvia{$lonhost}{$item}) {
10866: $changes{'loginvia'}{$lonhost} = 1;
10867: }
10868: if ($item eq 'exempt') {
1.160.6.56 raeburn 10869: $new = &check_exempt_addresses($new);
1.128 raeburn 10870: }
10871: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10872: }
10873: }
1.112 raeburn 10874: } else {
1.128 raeburn 10875: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
10876: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 10877: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 10878: foreach my $item (@loginvia_attribs) {
10879: my $new = $env{'form.'.$lonhost.'_'.$item};
10880: if (($item eq 'serverpath') && ($new eq 'custom')) {
10881: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
10882: $new = '/';
10883: }
10884: }
10885: if (($item eq 'custompath') &&
10886: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
10887: $new = '';
10888: }
10889: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
10890: }
1.110 raeburn 10891: }
10892: }
10893: }
10894: }
1.119 raeburn 10895:
1.160.6.5 raeburn 10896: my $servadm = $r->dir_config('lonAdmEMail');
10897: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
10898: if (ref($domconfig{'login'}) eq 'HASH') {
10899: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
10900: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
10901: if ($lang eq 'nolang') {
10902: push(@currlangs,$lang);
10903: } elsif (defined($langchoices{$lang})) {
10904: push(@currlangs,$lang);
10905: } else {
10906: next;
10907: }
10908: }
10909: }
10910: }
10911: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
10912: if (@currlangs > 0) {
10913: foreach my $lang (@currlangs) {
10914: if (grep(/^\Q$lang\E$/,@delurls)) {
10915: $changes{'helpurl'}{$lang} = 1;
10916: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
10917: $changes{'helpurl'}{$lang} = 1;
10918: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
10919: push(@newlangs,$lang);
10920: } else {
10921: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10922: }
10923: }
10924: }
10925: unless (grep(/^nolang$/,@currlangs)) {
10926: if ($env{'form.loginhelpurl_nolang.filename'}) {
10927: $changes{'helpurl'}{'nolang'} = 1;
10928: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
10929: push(@newlangs,'nolang');
10930: }
10931: }
10932: if ($env{'form.loginhelpurl_add_lang'}) {
10933: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
10934: ($env{'form.loginhelpurl_add_file.filename'})) {
10935: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
10936: $addedfile = $env{'form.loginhelpurl_add_lang'};
10937: }
10938: }
10939: if ((@newlangs > 0) || ($addedfile)) {
10940: my $error;
10941: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
10942: if ($configuserok eq 'ok') {
10943: if ($switchserver) {
10944: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
10945: } elsif ($author_ok eq 'ok') {
10946: my @allnew = @newlangs;
10947: if ($addedfile ne '') {
10948: push(@allnew,$addedfile);
10949: }
1.160.6.118.2 14(raebu 10950:23): my $modified = [];
1.160.6.5 raeburn 10951: foreach my $lang (@allnew) {
10952: my $formelem = 'loginhelpurl_'.$lang;
10953: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
10954: $formelem = 'loginhelpurl_add_file';
10955: }
1.160.6.118.2 14(raebu 10956:23): (my $result,$newurl{$lang}) =
10957:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
10958:23): "help/$lang",'','',$newfile{$lang},
10959:23): $modified);
1.160.6.5 raeburn 10960: if ($result eq 'ok') {
10961: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
10962: $changes{'helpurl'}{$lang} = 1;
10963: } else {
10964: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
10965: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
10966: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
10967: (!grep(/^\Q$lang\E$/,@delurls))) {
10968: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
10969: }
10970: }
10971: }
1.160.6.118.2 14(raebu 10972:23): &update_modify_urls($r,$modified);
1.160.6.5 raeburn 10973: } else {
10974: $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);
10975: }
10976: } else {
10977: $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);
10978: }
10979: if ($error) {
10980: &Apache::lonnet::logthis($error);
10981: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
10982: }
10983: }
1.160.6.56 raeburn 10984:
10985: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
10986: if (ref($domconfig{'login'}) eq 'HASH') {
10987: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
10988: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
10989: if ($domservers{$lonhost}) {
10990: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
10991: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 10992: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 10993: }
10994: }
10995: }
10996: }
10997: }
10998: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
10999: foreach my $lonhost (sort(keys(%domservers))) {
11000: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11001: $changes{'headtag'}{$lonhost} = 1;
11002: } else {
11003: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11004: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11005: }
11006: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11007: push(@newhosts,$lonhost);
11008: } elsif ($currheadtagurls{$lonhost}) {
11009: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11010: if ($currexempt{$lonhost}) {
11011: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
11012: $changes{'headtag'}{$lonhost} = 1;
11013: }
11014: } elsif ($possexempt{$lonhost}) {
11015: $changes{'headtag'}{$lonhost} = 1;
11016: }
11017: if ($possexempt{$lonhost}) {
11018: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11019: }
11020: }
11021: }
11022: }
11023: if (@newhosts) {
11024: my $error;
11025: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11026: if ($configuserok eq 'ok') {
11027: if ($switchserver) {
11028: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11029: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11030:23): my $modified = [];
1.160.6.56 raeburn 11031: foreach my $lonhost (@newhosts) {
11032: my $formelem = 'loginheadtag_'.$lonhost;
1.160.6.118.2 14(raebu 11033:23): (my $result,$newheadtagurls{$lonhost}) =
11034:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11035:23): "login/headtag/$lonhost",'','',
11036:23): $env{'form.loginheadtag_'.$lonhost.'.filename'},
11037:23): $modified);
1.160.6.56 raeburn 11038: if ($result eq 'ok') {
1.160.6.113 raeburn 11039: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11040: $changes{'headtag'}{$lonhost} = 1;
11041: if ($possexempt{$lonhost}) {
11042: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11043: }
11044: } else {
11045: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11046: $newheadtagurls{$lonhost},$result);
11047: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11048: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11049: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11050: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11051: }
11052: }
11053: }
1.160.6.118.2 14(raebu 11054:23): &update_modify_urls($r,$modified);
1.160.6.113 raeburn 11055: } else {
11056: $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);
11057: }
11058: } else {
11059: $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);
11060: }
11061: if ($error) {
11062: &Apache::lonnet::logthis($error);
11063: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11064: }
11065: }
11066: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11067: my @newsamlimgs;
11068: foreach my $lonhost (keys(%domservers)) {
11069: if ($env{'form.saml_'.$lonhost}) {
11070: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11071: push(@newsamlimgs,$lonhost);
11072: }
1.160.6.118.2 9(raebur 11073:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11074: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11075: }
11076: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 11077:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
11078:2): $env{'form.saml_window_'.$lonhost} = '';
11079:2): }
1.160.6.113 raeburn 11080: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11081: #FIXME Need to obsolete published image
11082: delete($currsaml{$lonhost}{'img'});
11083: $changes{'saml'}{$lonhost} = 1;
11084: }
11085: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11086: $changes{'saml'}{$lonhost} = 1;
11087: }
11088: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11089: $changes{'saml'}{$lonhost} = 1;
11090: }
11091: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11092: $changes{'saml'}{$lonhost} = 1;
11093: }
11094: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11095: $changes{'saml'}{$lonhost} = 1;
11096: }
1.160.6.118.2 9(raebur 11097:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11098:2): $changes{'saml'}{$lonhost} = 1;
11099:2): }
1.160.6.113 raeburn 11100: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11101: $changes{'saml'}{$lonhost} = 1;
11102: }
11103: } else {
11104: $changes{'saml'}{$lonhost} = 1;
11105: }
1.160.6.118.2 9(raebur 11106:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11107: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11108: }
11109: } else {
11110: if ($saml{$lonhost}) {
11111: $changes{'saml'}{$lonhost} = 1;
11112: delete($currsaml{$lonhost});
11113: }
11114: }
11115: }
11116: foreach my $posshost (keys(%currsaml)) {
11117: unless (exists($domservers{$posshost})) {
11118: delete($currsaml{$posshost});
11119: }
11120: }
11121: %{$loginhash{'login'}{'saml'}} = %currsaml;
11122: if (@newsamlimgs) {
11123: my $error;
11124: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11125: if ($configuserok eq 'ok') {
11126: if ($switchserver) {
11127: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11128: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11129:23): my $modified = [];
1.160.6.113 raeburn 11130: foreach my $lonhost (@newsamlimgs) {
11131: my $formelem = 'saml_img_'.$lonhost;
1.160.6.118.2 14(raebu 11132:23): my ($result,$imgurl) =
11133:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11134:23): "login/saml/$lonhost",'','',
11135:23): $env{'form.saml_img_'.$lonhost.'.filename'},
11136:23): $modified);
1.160.6.113 raeburn 11137: if ($result eq 'ok') {
11138: $currsaml{$lonhost}{'img'} = $imgurl;
11139: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11140: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 11141: } else {
1.160.6.113 raeburn 11142: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11143: $lonhost,$result);
1.160.6.56 raeburn 11144: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11145: }
11146: }
1.160.6.118.2 14(raebu 11147:23): &update_modify_urls($r,$modified);
1.160.6.56 raeburn 11148: } else {
1.160.6.113 raeburn 11149: $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 11150: }
11151: } else {
1.160.6.113 raeburn 11152: $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 11153: }
11154: if ($error) {
11155: &Apache::lonnet::logthis($error);
11156: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11157: }
11158: }
1.160.6.5 raeburn 11159: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11160:
11161: my $defaulthelpfile = '/adm/loginproblems.html';
11162: my $defaulttext = &mt('Default in use');
11163:
1.1 raeburn 11164: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11165: $dom);
11166: if ($putresult eq 'ok') {
1.160.6.14 raeburn 11167: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11168: my %defaultchecked = (
11169: 'coursecatalog' => 'on',
1.160.6.14 raeburn 11170: 'helpdesk' => 'on',
1.42 raeburn 11171: 'adminmail' => 'off',
1.43 raeburn 11172: 'newuser' => 'off',
1.42 raeburn 11173: );
1.55 raeburn 11174: if (ref($domconfig{'login'}) eq 'HASH') {
11175: foreach my $item (@toggles) {
11176: if ($defaultchecked{$item} eq 'on') {
11177: if (($domconfig{'login'}{$item} eq '0') &&
11178: ($env{'form.'.$item} eq '1')) {
11179: $changes{$item} = 1;
11180: } elsif (($domconfig{'login'}{$item} eq '' ||
11181: $domconfig{'login'}{$item} eq '1') &&
11182: ($env{'form.'.$item} eq '0')) {
11183: $changes{$item} = 1;
11184: }
11185: } elsif ($defaultchecked{$item} eq 'off') {
11186: if (($domconfig{'login'}{$item} eq '1') &&
11187: ($env{'form.'.$item} eq '0')) {
11188: $changes{$item} = 1;
11189: } elsif (($domconfig{'login'}{$item} eq '' ||
11190: $domconfig{'login'}{$item} eq '0') &&
11191: ($env{'form.'.$item} eq '1')) {
11192: $changes{$item} = 1;
11193: }
1.42 raeburn 11194: }
11195: }
1.41 raeburn 11196: }
1.6 raeburn 11197: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11198: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 11199: if (exists($changes{'saml'})) {
11200: my $hostid_in_use;
11201: my @hosts = &Apache::lonnet::current_machine_ids();
11202: if (@hosts > 1) {
11203: foreach my $hostid (@hosts) {
11204: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11205: $hostid_in_use = $hostid;
11206: last;
11207: }
11208: }
11209: } else {
11210: $hostid_in_use = $r->dir_config('lonHostID');
11211: }
11212: if (($hostid_in_use) &&
11213: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11214: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11215: }
11216: if (ref($lastactref) eq 'HASH') {
11217: if (ref($changes{'saml'}) eq 'HASH') {
11218: my %updates;
11219: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11220: $lastactref->{'samllanding'} = \%updates;
11221: }
11222: }
11223: }
1.160.6.27 raeburn 11224: if (ref($lastactref) eq 'HASH') {
11225: $lastactref->{'domainconfig'} = 1;
11226: }
1.1 raeburn 11227: $resulttext = &mt('Changes made:').'<ul>';
11228: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11229: if ($item eq 'loginvia') {
1.112 raeburn 11230: if (ref($changes{$item}) eq 'HASH') {
11231: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11232: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11233: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11234: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11235: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11236: $protocol = 'http' if ($protocol ne 'https');
11237: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11238:
11239: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11240: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11241: } else {
11242: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11243: }
11244: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11245: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11246: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11247: }
11248: $resulttext .= '</li>';
11249: } else {
11250: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11251: }
1.112 raeburn 11252: } else {
1.128 raeburn 11253: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11254: }
11255: }
1.128 raeburn 11256: $resulttext .= '</ul></li>';
1.112 raeburn 11257: }
1.160.6.5 raeburn 11258: } elsif ($item eq 'helpurl') {
11259: if (ref($changes{$item}) eq 'HASH') {
11260: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11261: if (grep(/^\Q$lang\E$/,@delurls)) {
11262: my ($chg,$link);
11263: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11264: if ($lang eq 'nolang') {
11265: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11266: } else {
11267: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11268: }
11269: $resulttext .= '<li>'.$chg.'</li>';
11270: } else {
11271: my $chg;
11272: if ($lang eq 'nolang') {
11273: $chg = &mt('custom log-in help file for no preferred language');
11274: } else {
11275: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11276: }
11277: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11278: $loginhash{'login'}{'helpurl'}{$lang}.
11279: '?inhibitmenu=yes',$chg,600,500).
11280: '</li>';
11281: }
11282: }
11283: }
1.160.6.56 raeburn 11284: } elsif ($item eq 'headtag') {
11285: if (ref($changes{$item}) eq 'HASH') {
11286: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11287: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11288: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11289: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11290: $resulttext .= '<li><a href="'.
11291: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11292: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11293: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11294: if ($possexempt{$lonhost}) {
11295: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11296: } else {
11297: $resulttext .= &mt('included for any client IP');
11298: }
11299: $resulttext .= '</li>';
11300: }
11301: }
11302: }
1.160.6.113 raeburn 11303: } elsif ($item eq 'saml') {
11304: if (ref($changes{$item}) eq 'HASH') {
11305: my %notlt = (
11306: text => 'Text for log-in by SSO',
11307: img => 'SSO button image',
11308: alt => 'Alt text for button image',
11309: url => 'SSO URL',
11310: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 11311:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 11312: notsso => 'Text for non-SSO log-in',
11313: );
11314: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11315: if (ref($currsaml{$lonhost}) eq 'HASH') {
11316: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11317: '<ul>';
1.160.6.118.2 9(raebur 11318:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11319: if ($currsaml{$lonhost}{$key} eq '') {
11320: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11321: } else {
11322: my $value = "'$currsaml{$lonhost}{$key}'";
11323: if ($key eq 'img') {
11324: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 11325:2): } elsif ($key eq 'window') {
11326:2): $value = 'On';
1.160.6.113 raeburn 11327: }
11328: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11329: $value).'</li>';
11330: }
11331: }
11332: $resulttext .= '</ul></li>';
11333: } else {
11334: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11335: }
11336: }
11337: }
1.160.6.5 raeburn 11338: } elsif ($item eq 'captcha') {
11339: if (ref($loginhash{'login'}) eq 'HASH') {
11340: my $chgtxt;
11341: if ($loginhash{'login'}{$item} eq 'notused') {
11342: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11343: } else {
11344: my %captchas = &captcha_phrases();
11345: if ($captchas{$loginhash{'login'}{$item}}) {
11346: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11347: } else {
11348: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11349: }
11350: }
11351: $resulttext .= '<li>'.$chgtxt.'</li>';
11352: }
11353: } elsif ($item eq 'recaptchakeys') {
11354: if (ref($loginhash{'login'}) eq 'HASH') {
11355: my ($privkey,$pubkey);
11356: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11357: $pubkey = $loginhash{'login'}{$item}{'public'};
11358: $privkey = $loginhash{'login'}{$item}{'private'};
11359: }
11360: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11361: if (!$pubkey) {
11362: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11363: } else {
11364: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11365: }
11366: if (!$privkey) {
11367: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11368: } else {
1.160.6.53 raeburn 11369: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 11370: }
11371: $chgtxt .= '</ul>';
11372: $resulttext .= '<li>'.$chgtxt.'</li>';
11373: }
1.160.6.69 raeburn 11374: } elsif ($item eq 'recaptchaversion') {
11375: if (ref($loginhash{'login'}) eq 'HASH') {
11376: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11377: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11378: '</li>';
11379: }
11380: }
1.41 raeburn 11381: } else {
11382: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11383: }
1.1 raeburn 11384: }
1.6 raeburn 11385: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11386: } else {
11387: $resulttext = &mt('No changes made to log-in page settings');
11388: }
11389: } else {
1.11 albertel 11390: $resulttext = '<span class="LC_error">'.
11391: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11392: }
1.6 raeburn 11393: if ($errors) {
1.9 raeburn 11394: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11395: $errors.'</ul>';
11396: }
11397: return $resulttext;
11398: }
11399:
1.160.6.56 raeburn 11400: sub check_exempt_addresses {
11401: my ($iplist) = @_;
11402: $iplist =~ s/^\s+//;
11403: $iplist =~ s/\s+$//;
11404: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11405: my (@okips,$new);
11406: foreach my $ip (@poss_ips) {
11407: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11408: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11409: push(@okips,$ip);
11410: }
11411: }
11412: }
11413: if (@okips > 0) {
11414: $new = join(',',@okips);
11415: } else {
11416: $new = '';
11417: }
11418: return $new;
11419: }
11420:
1.6 raeburn 11421: sub color_font_choices {
11422: my %choices =
11423: &Apache::lonlocal::texthash (
11424: img => "Header",
11425: bgs => "Background colors",
11426: links => "Link colors",
1.55 raeburn 11427: images => "Images",
1.6 raeburn 11428: font => "Font color",
1.160.6.22 raeburn 11429: fontmenu => "Font menu",
1.76 raeburn 11430: pgbg => "Page",
1.6 raeburn 11431: tabbg => "Header",
11432: sidebg => "Border",
11433: link => "Link",
11434: alink => "Active link",
11435: vlink => "Visited link",
11436: );
11437: return %choices;
11438: }
11439:
1.160.6.113 raeburn 11440: sub modify_ipaccess {
11441: my ($dom,$lastactref,%domconfig) = @_;
11442: my (@allpos,%changes,%confhash,$errors,$resulttext);
11443: my (@items,%deletions,%itemids,@warnings);
11444: my ($typeorder,$types) = &commblocktype_text();
11445: if ($env{'form.ipaccess_add'}) {
11446: my $name = $env{'form.ipaccess_name_add'};
11447: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11448: if ($newid) {
11449: $itemids{'add'} = $newid;
11450: push(@items,'add');
11451: $changes{$newid} = 1;
11452: } else {
11453: $error = &mt('Failed to acquire unique ID for new IP access control item');
11454: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11455: }
11456: }
11457: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11458: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11459: if (@todelete) {
11460: map { $deletions{$_} = 1; } @todelete;
11461: }
11462: my $maxnum = $env{'form.ipaccess_maxnum'};
11463: for (my $i=0; $i<$maxnum; $i++) {
11464: my $itemid = $env{'form.ipaccess_id_'.$i};
11465: $itemid =~ s/\D+//g;
11466: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11467: if ($deletions{$itemid}) {
11468: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11469: } else {
11470: push(@items,$i);
11471: $itemids{$i} = $itemid;
11472: }
11473: }
11474: }
11475: }
11476: foreach my $idx (@items) {
11477: my $itemid = $itemids{$idx};
11478: next unless ($itemid);
11479: my %current;
11480: unless ($idx eq 'add') {
11481: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11482: %current = %{$domconfig{'ipaccess'}{$itemid}};
11483: }
11484: }
11485: my $position = $env{'form.ipaccess_pos_'.$itemid};
11486: $position =~ s/\D+//g;
11487: if ($position ne '') {
11488: $allpos[$position] = $itemid;
11489: }
11490: my $name = $env{'form.ipaccess_name_'.$idx};
11491: $name =~ s/^\s+|\s+$//g;
11492: $confhash{$itemid}{'name'} = $name;
11493: my $possrange = $env{'form.ipaccess_range_'.$idx};
11494: $possrange =~ s/^\s+|\s+$//g;
11495: unless ($possrange eq '') {
11496: $possrange =~ s/[\r\n]+/\s/g;
11497: $possrange =~ s/\s*-\s*/-/g;
11498: $possrange =~ s/\s+/,/g;
11499: $possrange =~ s/,+/,/g;
11500: if ($possrange ne '') {
11501: my (@ok,$count);
11502: $count = 0;
11503: foreach my $poss (split(/\,/,$possrange)) {
11504: $count ++;
11505: $poss = &validate_ip_pattern($poss);
11506: if ($poss ne '') {
11507: push(@ok,$poss);
11508: }
11509: }
11510: my $diff = $count - scalar(@ok);
11511: if ($diff) {
11512: $errors .= '<li><span class="LC_error">'.
11513: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11514: $diff,$name).
11515: '</span></li>';
11516: }
11517: if (@ok) {
11518: my @cidr_list;
11519: foreach my $item (@ok) {
11520: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11521: }
11522: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11523: }
11524: }
11525: }
11526: foreach my $field ('name','ip') {
11527: unless (($idx eq 'add') || ($changes{$itemid})) {
11528: if ($current{$field} ne $confhash{$itemid}{$field}) {
11529: $changes{$itemid} = 1;
11530: last;
11531: }
11532: }
11533: }
11534: $confhash{$itemid}{'commblocks'} = {};
11535:
11536: my %commblocks;
11537: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11538: foreach my $type (@{$typeorder}) {
11539: if ($commblocks{$type}) {
11540: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11541: }
11542: unless (($idx eq 'add') || ($changes{$itemid})) {
11543: if (ref($current{'commblocks'}) eq 'HASH') {
11544: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11545: $changes{$itemid} = 1;
11546: }
11547: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11548: $changes{$itemid} = 1;
11549: }
11550: }
11551: }
11552: $confhash{$itemid}{'courses'} = {};
11553: my %crsdeletions;
11554: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11555: if (@delcrs) {
11556: map { $crsdeletions{$_} = 1; } @delcrs;
11557: }
11558: if (ref($current{'courses'}) eq 'HASH') {
11559: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11560: if ($crsdeletions{$cid}) {
11561: $changes{$itemid} = 1;
11562: } else {
11563: $confhash{$itemid}{'courses'}{$cid} = 1;
11564: }
11565: }
11566: }
11567: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11568: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11569: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11570: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11571: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11572: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11573: $errors .= '<li><span class="LC_error">'.
11574: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11575: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11576: '</span></li>';
11577: } else {
11578: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11579: $changes{$itemid} = 1;
11580: }
11581: }
11582: }
11583: if (@allpos > 0) {
11584: my $idx = 0;
11585: foreach my $itemid (@allpos) {
11586: if ($itemid ne '') {
11587: $confhash{$itemid}{'order'} = $idx;
11588: unless ($changes{$itemid}) {
11589: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11590: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11591: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11592: $changes{$itemid} = 1;
11593: }
11594: }
11595: }
11596: }
11597: $idx ++;
11598: }
11599: }
11600: }
11601: if (keys(%changes)) {
11602: my %defaultshash = (
11603: ipaccess => \%confhash,
11604: );
11605: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11606: $dom);
11607: if ($putresult eq 'ok') {
11608: my $cachetime = 1800;
11609: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11610: if (ref($lastactref) eq 'HASH') {
11611: $lastactref->{'ipaccess'} = 1;
11612: }
11613: $resulttext = &mt('Changes made:').'<ul>';
11614: my %bynum;
11615: foreach my $itemid (sort(keys(%changes))) {
11616: if (ref($confhash{$itemid}) eq 'HASH') {
11617: my $position = $confhash{$itemid}{'order'};
11618: if ($position =~ /^\d+$/) {
11619: $bynum{$position} = $itemid;
11620: }
11621: }
11622: }
11623: if (keys(%deletions)) {
11624: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11625: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11626: }
11627: }
11628: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11629: my $itemid = $bynum{$pos};
11630: if (ref($confhash{$itemid}) eq 'HASH') {
11631: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11632: my $position = $pos + 1;
11633: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11634: if ($confhash{$itemid}{'ip'} eq '') {
11635: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11636: } else {
11637: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11638: }
11639: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11640: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11641: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11642: '</li>';
11643: } else {
11644: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11645: }
11646: if (keys(%{$confhash{$itemid}{'courses'}})) {
11647: my @courses;
11648: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11649: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11650: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
11651: }
11652: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
11653: join('</li><li>',@courses).'</li></ul>';
11654: } else {
11655: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
11656: }
11657: $resulttext .= '</ul></li>';
11658: }
11659: }
11660: $resulttext .= '</ul>';
11661: } else {
11662: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11663: }
11664: } else {
11665: $resulttext = &mt('No changes made');
11666: }
11667: if ($errors) {
11668: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11669: $errors.'</ul></p>';
11670: }
11671: return $resulttext;
11672: }
11673:
11674: sub get_ipaccess_id {
11675: my ($domain,$location) = @_;
11676: # get lock on ipaccess db
11677: my $lockhash = {
11678: lock => $env{'user.name'}.
11679: ':'.$env{'user.domain'},
11680: };
11681: my $tries = 0;
11682: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11683: my ($id,$error);
11684:
11685: while (($gotlock ne 'ok') && ($tries<10)) {
11686: $tries ++;
11687: sleep (0.1);
11688: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11689: }
11690: if ($gotlock eq 'ok') {
11691: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
11692: if ($currids{'lock'}) {
11693: delete($currids{'lock'});
11694: if (keys(%currids)) {
11695: my @curr = sort { $a <=> $b } keys(%currids);
11696: if ($curr[-1] =~ /^\d+$/) {
11697: $id = 1 + $curr[-1];
11698: }
11699: } else {
11700: $id = 1;
11701: }
11702: if ($id) {
11703: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
11704: $error = 'nostore';
11705: }
11706: } else {
11707: $error = 'nonumber';
11708: }
11709: }
11710: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
11711: } else {
11712: $error = 'nolock';
11713: }
11714: return ($id,$error);
11715: }
11716:
1.6 raeburn 11717: sub modify_rolecolors {
1.160.6.24 raeburn 11718: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 11719: my ($resulttext,%rolehash);
11720: $rolehash{'rolecolors'} = {};
1.55 raeburn 11721: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
11722: if ($domconfig{'rolecolors'} eq '') {
11723: $domconfig{'rolecolors'} = {};
11724: }
11725: }
1.9 raeburn 11726: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 11727: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
11728: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
11729: $dom);
11730: if ($putresult eq 'ok') {
11731: if (keys(%changes) > 0) {
1.41 raeburn 11732: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 11733: if (ref($lastactref) eq 'HASH') {
11734: $lastactref->{'domainconfig'} = 1;
11735: }
1.6 raeburn 11736: $resulttext = &display_colorchgs($dom,\%changes,$roles,
11737: $rolehash{'rolecolors'});
11738: } else {
11739: $resulttext = &mt('No changes made to default color schemes');
11740: }
11741: } else {
1.11 albertel 11742: $resulttext = '<span class="LC_error">'.
11743: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 11744: }
11745: if ($errors) {
11746: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
11747: $errors.'</ul>';
11748: }
11749: return $resulttext;
11750: }
11751:
11752: sub modify_colors {
1.9 raeburn 11753: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 11754: my (%changes,%choices);
1.51 raeburn 11755: my @bgs;
1.6 raeburn 11756: my @links = ('link','alink','vlink');
1.41 raeburn 11757: my @logintext;
1.6 raeburn 11758: my @images;
11759: my $servadm = $r->dir_config('lonAdmEMail');
11760: my $errors;
1.160.6.22 raeburn 11761: my %defaults;
1.6 raeburn 11762: foreach my $role (@{$roles}) {
11763: if ($role eq 'login') {
1.12 raeburn 11764: %choices = &login_choices();
1.41 raeburn 11765: @logintext = ('textcol','bgcol');
1.12 raeburn 11766: } else {
11767: %choices = &color_font_choices();
11768: }
11769: if ($role eq 'login') {
1.41 raeburn 11770: @images = ('img','logo','domlogo','login');
1.51 raeburn 11771: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 11772: } else {
11773: @images = ('img');
1.160.6.22 raeburn 11774: @bgs = ('pgbg','tabbg','sidebg');
11775: }
11776: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
11777: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
11778: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
11779: }
11780: if ($role eq 'login') {
11781: foreach my $item (@logintext) {
1.160.6.39 raeburn 11782: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11783: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11784: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11785: }
11786: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 11787: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11788: }
11789: }
11790: } else {
1.160.6.39 raeburn 11791: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
11792: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
11793: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
11794: }
11795: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 11796: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
11797: }
1.6 raeburn 11798: }
1.160.6.22 raeburn 11799: foreach my $item (@bgs) {
1.160.6.39 raeburn 11800: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11801: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11802: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11803: }
11804: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 11805: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11806: }
11807: }
11808: foreach my $item (@links) {
1.160.6.39 raeburn 11809: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
11810: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
11811: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
11812: }
11813: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 11814: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
11815: }
1.6 raeburn 11816: }
1.46 raeburn 11817: my ($configuserok,$author_ok,$switchserver) =
11818: &config_check($dom,$confname,$servadm);
1.9 raeburn 11819: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 11820: if (ref($domconfig->{$role}) ne 'HASH') {
11821: $domconfig->{$role} = {};
11822: }
1.8 raeburn 11823: foreach my $img (@images) {
1.160.6.118.2 2(raebur 11824:2): if ($role eq 'login') {
11825:2): if (($img eq 'img') || ($img eq 'logo')) {
11826:2): if (defined($env{'form.login_showlogo_'.$img})) {
11827:2): $confhash->{$role}{'showlogo'}{$img} = 1;
11828:2): } else {
11829:2): $confhash->{$role}{'showlogo'}{$img} = 0;
11830:2): }
1.70 raeburn 11831: }
1.160.6.118.2 2(raebur 11832:2): if ($env{'form.login_alt_'.$img} ne '') {
11833:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
11834:2): }
11835:2): }
1.18 albertel 11836: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
11837: && !defined($domconfig->{$role}{$img})
11838: && !$env{'form.'.$role.'_del_'.$img}
11839: && $env{'form.'.$role.'_import_'.$img}) {
11840: # import the old configured image from the .tab setting
11841: # if they haven't provided a new one
11842: $domconfig->{$role}{$img} =
11843: $env{'form.'.$role.'_import_'.$img};
11844: }
1.6 raeburn 11845: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 11846: my $error;
1.6 raeburn 11847: if ($configuserok eq 'ok') {
1.9 raeburn 11848: if ($switchserver) {
1.12 raeburn 11849: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 11850: } else {
11851: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11852:23): my $modified = [];
1.9 raeburn 11853: my ($result,$logourl) =
1.160.6.118.2 14(raebu 11854:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
11855:23): $dom,$confname,$img,$width,$height,
11856:23): '',$modified);
1.9 raeburn 11857: if ($result eq 'ok') {
11858: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 11859: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 11860:23): &update_modify_urls($r,$modified);
1.9 raeburn 11861: } else {
1.12 raeburn 11862: $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 11863: }
11864: } else {
1.46 raeburn 11865: $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 11866: }
11867: }
11868: } else {
1.46 raeburn 11869: $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 11870: }
11871: if ($error) {
1.8 raeburn 11872: &Apache::lonnet::logthis($error);
1.11 albertel 11873: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 11874: }
11875: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 11876: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
11877: my $error;
11878: if ($configuserok eq 'ok') {
11879: # is confname an author?
11880: if ($switchserver eq '') {
11881: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11882:23): my $modified = [];
1.9 raeburn 11883: my ($result,$logourl) =
1.160.6.118.2 14(raebu 11884:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
11885:23): $dom,$confname,$img,$width,$height,
11886:23): '',$modified);
1.9 raeburn 11887: if ($result eq 'ok') {
11888: $confhash->{$role}{$img} = $logourl;
1.18 albertel 11889: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 11890:23): &update_modify_urls($r,$modified);
1.9 raeburn 11891: }
11892: }
11893: }
11894: }
1.6 raeburn 11895: }
11896: }
11897: }
11898: if (ref($domconfig) eq 'HASH') {
11899: if (ref($domconfig->{$role}) eq 'HASH') {
11900: foreach my $img (@images) {
11901: if ($domconfig->{$role}{$img} ne '') {
11902: if ($env{'form.'.$role.'_del_'.$img}) {
11903: $confhash->{$role}{$img} = '';
1.12 raeburn 11904: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11905: } else {
1.9 raeburn 11906: if ($confhash->{$role}{$img} eq '') {
11907: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
11908: }
1.6 raeburn 11909: }
11910: } else {
11911: if ($env{'form.'.$role.'_del_'.$img}) {
11912: $confhash->{$role}{$img} = '';
1.12 raeburn 11913: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 11914: }
11915: }
1.160.6.118.2 2(raebur 11916:2): if ($role eq 'login') {
11917:2): if (($img eq 'logo') || ($img eq 'img')) {
11918:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
11919:2): if ($confhash->{$role}{'showlogo'}{$img} ne
11920:2): $domconfig->{$role}{'showlogo'}{$img}) {
11921:2): $changes{$role}{'showlogo'}{$img} = 1;
11922:2): }
11923:2): } else {
11924:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
11925:2): $changes{$role}{'showlogo'}{$img} = 1;
11926:2): }
1.70 raeburn 11927: }
1.160.6.118.2 2(raebur 11928:2): }
11929:2): if ($img ne 'login') {
11930:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
11931:2): if ($confhash->{$role}{'alttext'}{$img} ne
11932:2): $domconfig->{$role}{'alttext'}{$img}) {
11933:2): $changes{$role}{'alttext'}{$img} = 1;
11934:2): }
11935:2): } else {
11936:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
11937:2): $changes{$role}{'alttext'}{$img} = 1;
11938:2): }
1.70 raeburn 11939: }
11940: }
11941: }
11942: }
1.6 raeburn 11943: if ($domconfig->{$role}{'font'} ne '') {
11944: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
11945: $changes{$role}{'font'} = 1;
11946: }
11947: } else {
11948: if ($confhash->{$role}{'font'}) {
11949: $changes{$role}{'font'} = 1;
11950: }
11951: }
1.107 raeburn 11952: if ($role ne 'login') {
11953: if ($domconfig->{$role}{'fontmenu'} ne '') {
11954: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
11955: $changes{$role}{'fontmenu'} = 1;
11956: }
11957: } else {
11958: if ($confhash->{$role}{'fontmenu'}) {
11959: $changes{$role}{'fontmenu'} = 1;
11960: }
1.97 tempelho 11961: }
11962: }
1.6 raeburn 11963: foreach my $item (@bgs) {
11964: if ($domconfig->{$role}{$item} ne '') {
11965: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11966: $changes{$role}{'bgs'}{$item} = 1;
11967: }
11968: } else {
11969: if ($confhash->{$role}{$item}) {
11970: $changes{$role}{'bgs'}{$item} = 1;
11971: }
11972: }
11973: }
11974: foreach my $item (@links) {
11975: if ($domconfig->{$role}{$item} ne '') {
11976: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11977: $changes{$role}{'links'}{$item} = 1;
11978: }
11979: } else {
11980: if ($confhash->{$role}{$item}) {
11981: $changes{$role}{'links'}{$item} = 1;
11982: }
11983: }
11984: }
1.41 raeburn 11985: foreach my $item (@logintext) {
11986: if ($domconfig->{$role}{$item} ne '') {
11987: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
11988: $changes{$role}{'logintext'}{$item} = 1;
11989: }
11990: } else {
11991: if ($confhash->{$role}{$item}) {
11992: $changes{$role}{'logintext'}{$item} = 1;
11993: }
11994: }
11995: }
1.6 raeburn 11996: } else {
11997: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 11998: \@logintext,$confhash,\%changes);
1.6 raeburn 11999: }
12000: } else {
12001: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12002: \@logintext,$confhash,\%changes);
1.6 raeburn 12003: }
12004: }
12005: return ($errors,%changes);
12006: }
12007:
1.46 raeburn 12008: sub config_check {
12009: my ($dom,$confname,$servadm) = @_;
12010: my ($configuserok,$author_ok,$switchserver,%currroles);
12011: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12012: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12013: $confname,$servadm);
12014: if ($configuserok eq 'ok') {
12015: $switchserver = &check_switchserver($dom,$confname);
12016: if ($switchserver eq '') {
12017: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12018: }
12019: }
12020: return ($configuserok,$author_ok,$switchserver);
12021: }
12022:
1.6 raeburn 12023: sub default_change_checker {
1.41 raeburn 12024: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12025: foreach my $item (@{$links}) {
12026: if ($confhash->{$role}{$item}) {
12027: $changes->{$role}{'links'}{$item} = 1;
12028: }
12029: }
12030: foreach my $item (@{$bgs}) {
12031: if ($confhash->{$role}{$item}) {
12032: $changes->{$role}{'bgs'}{$item} = 1;
12033: }
12034: }
1.41 raeburn 12035: foreach my $item (@{$logintext}) {
12036: if ($confhash->{$role}{$item}) {
12037: $changes->{$role}{'logintext'}{$item} = 1;
12038: }
12039: }
1.6 raeburn 12040: foreach my $img (@{$images}) {
12041: if ($env{'form.'.$role.'_del_'.$img}) {
12042: $confhash->{$role}{$img} = '';
1.12 raeburn 12043: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12044: }
1.70 raeburn 12045: if ($role eq 'login') {
12046: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12047: $changes->{$role}{'showlogo'}{$img} = 1;
12048: }
1.160.6.118.2 2(raebur 12049:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
12050:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12051:2): $changes->{$role}{'alttext'}{$img} = 1;
12052:2): }
12053:2): }
1.70 raeburn 12054: }
1.6 raeburn 12055: }
12056: if ($confhash->{$role}{'font'}) {
12057: $changes->{$role}{'font'} = 1;
12058: }
1.48 raeburn 12059: }
1.6 raeburn 12060:
12061: sub display_colorchgs {
12062: my ($dom,$changes,$roles,$confhash) = @_;
12063: my (%choices,$resulttext);
12064: if (!grep(/^login$/,@{$roles})) {
12065: $resulttext = &mt('Changes made:').'<br />';
12066: }
12067: foreach my $role (@{$roles}) {
12068: if ($role eq 'login') {
12069: %choices = &login_choices();
12070: } else {
12071: %choices = &color_font_choices();
12072: }
12073: if (ref($changes->{$role}) eq 'HASH') {
12074: if ($role ne 'login') {
12075: $resulttext .= '<h4>'.&mt($role).'</h4>';
12076: }
12077: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12078: if ($role ne 'login') {
12079: $resulttext .= '<ul>';
12080: }
12081: if (ref($changes->{$role}{$key}) eq 'HASH') {
12082: if ($role ne 'login') {
12083: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12084: }
12085: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12086: if (($role eq 'login') && ($key eq 'showlogo')) {
12087: if ($confhash->{$role}{$key}{$item}) {
12088: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12089: } else {
12090: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12091: }
1.160.6.118.2 2(raebur 12092:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
12093:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 12094:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 12095:2): $confhash->{$role}{$key}{$item}).'</li>';
12096:2): } else {
12097:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12098:2): }
1.70 raeburn 12099: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12100: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12101: } else {
1.12 raeburn 12102: my $newitem = $confhash->{$role}{$item};
12103: if ($key eq 'images') {
12104: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12105: }
12106: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12107: }
12108: }
12109: if ($role ne 'login') {
12110: $resulttext .= '</ul></li>';
12111: }
12112: } else {
12113: if ($confhash->{$role}{$key} eq '') {
12114: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12115: } else {
12116: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12117: }
12118: }
12119: if ($role ne 'login') {
12120: $resulttext .= '</ul>';
12121: }
12122: }
12123: }
12124: }
1.3 raeburn 12125: return $resulttext;
1.1 raeburn 12126: }
12127:
1.9 raeburn 12128: sub thumb_dimensions {
12129: return ('200','50');
12130: }
12131:
1.16 raeburn 12132: sub check_dimensions {
12133: my ($inputfile) = @_;
12134: my ($fullwidth,$fullheight);
12135: if ($inputfile =~ m|^[/\w.\-]+$|) {
12136: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12137: my $imageinfo = <PIPE>;
12138: if (!close(PIPE)) {
12139: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12140: }
12141: chomp($imageinfo);
12142: my ($fullsize) =
1.21 raeburn 12143: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12144: if ($fullsize) {
12145: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12146: }
12147: }
12148: }
12149: return ($fullwidth,$fullheight);
12150: }
12151:
1.9 raeburn 12152: sub check_configuser {
12153: my ($uhome,$dom,$confname,$servadm) = @_;
12154: my ($configuserok,%currroles);
12155: if ($uhome eq 'no_host') {
12156: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 12157: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12158: $configuserok =
12159: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12160: $configpass,'','','','','',undef,$servadm);
12161: } else {
12162: $configuserok = 'ok';
12163: %currroles =
12164: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12165: }
12166: return ($configuserok,%currroles);
12167: }
12168:
12169: sub check_authorstatus {
12170: my ($dom,$confname,%currroles) = @_;
12171: my $author_ok;
1.40 raeburn 12172: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12173: my $start = time;
12174: my $end = 0;
12175: $author_ok =
12176: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12177: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12178: } else {
12179: $author_ok = 'ok';
12180: }
12181: return $author_ok;
12182: }
12183:
1.160.6.118.2 14(raebu 12184:23): sub update_modify_urls {
12185:23): my ($r,$modified) = @_;
12186:23): if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12187:23): push(@{$modified_urls},$modified);
12188:23): unless ($registered_cleanup) {
12189:23): my $handlers = $r->get_handlers('PerlCleanupHandler');
12190:23): $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12191:23): $registered_cleanup=1;
1.9 raeburn 12192: }
12193: }
1.155 raeburn 12194: }
12195:
12196: sub notifysubscribed {
12197: foreach my $targetsource (@{$modified_urls}){
12198: next unless (ref($targetsource) eq 'ARRAY');
12199: my ($target,$source)=@{$targetsource};
12200: if ($source ne '') {
1.160.6.88 raeburn 12201: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12202: print $logfh "\nCleanup phase: Notifications\n";
12203: my @subscribed=&subscribed_hosts($target);
12204: foreach my $subhost (@subscribed) {
12205: print $logfh "\nNotifying host ".$subhost.':';
12206: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12207: print $logfh $reply;
12208: }
12209: my @subscribedmeta=&subscribed_hosts("$target.meta");
12210: foreach my $subhost (@subscribedmeta) {
12211: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12212: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12213: $subhost);
12214: print $logfh $reply;
12215: }
12216: print $logfh "\n============ Done ============\n";
1.160 raeburn 12217: close($logfh);
1.155 raeburn 12218: }
12219: }
12220: }
12221: return OK;
12222: }
12223:
12224: sub subscribed_hosts {
12225: my ($target) = @_;
12226: my @subscribed;
1.160.6.88 raeburn 12227: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12228: while (my $subline=<$fh>) {
12229: if ($subline =~ /^($match_lonid):/) {
12230: my $host = $1;
12231: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12232: unless (grep(/^\Q$host\E$/,@subscribed)) {
12233: push(@subscribed,$host);
12234: }
12235: }
12236: }
12237: }
12238: }
12239: return @subscribed;
1.9 raeburn 12240: }
12241:
12242: sub check_switchserver {
12243: my ($dom,$confname) = @_;
1.160.6.118.2 14(raebu 12244:23): my ($allowed,$switchserver,$home);
12245:23): if ($confname eq '') {
1.9 raeburn 12246: $home = &Apache::lonnet::domain($dom,'primary');
1.160.6.118.2 14(raebu 12247:23): } else {
12248:23): $home = &Apache::lonnet::homeserver($confname,$dom);
12249:23): if ($home eq 'no_host') {
12250:23): $home = &Apache::lonnet::domain($dom,'primary');
12251:23): }
1.9 raeburn 12252: }
12253: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12254: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12255: if (!$allowed) {
1.160.6.118.2 14(raebu 12256:23): $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12257:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12258:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12259: }
12260: return $switchserver;
12261: }
12262:
1.1 raeburn 12263: sub modify_quotas {
1.160.6.30 raeburn 12264: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12265: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 12266: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 12267: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12268: $validationfieldsref);
1.86 raeburn 12269: if ($action eq 'quotas') {
12270: $context = 'tools';
1.160.6.26 raeburn 12271: } else {
1.86 raeburn 12272: $context = $action;
12273: }
12274: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 12275:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 12276: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12277: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12278: %titles = &courserequest_titles();
12279: $toolregexp = join('|',@usertools);
12280: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 12281: $confname = $dom.'-domainconfig';
12282: my $servadm = $r->dir_config('lonAdmEMail');
12283: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 12284: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12285: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 12286: } elsif ($context eq 'requestauthor') {
12287: @usertools = ('author');
12288: %titles = &authorrequest_titles();
1.86 raeburn 12289: } else {
1.160.6.118.2 10(raebu 12290:22): @usertools = ('aboutme','blog','webdav','portfolio','timezone');
1.101 raeburn 12291: %titles = &tool_titles();
1.86 raeburn 12292: }
1.160.6.27 raeburn 12293: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12295: foreach my $key (keys(%env)) {
1.101 raeburn 12296: if ($context eq 'requestcourses') {
12297: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12298: my $item = $1;
12299: my $type = $2;
12300: if ($type =~ /^limit_(.+)/) {
12301: $limithash{$item}{$1} = $env{$key};
12302: } else {
12303: $confhash{$item}{$type} = $env{$key};
12304: }
12305: }
1.160.6.5 raeburn 12306: } elsif ($context eq 'requestauthor') {
12307: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12308: $confhash{$1} = $env{$key};
12309: }
1.101 raeburn 12310: } else {
1.86 raeburn 12311: if ($key =~ /^form\.quota_(.+)$/) {
12312: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 12313: } elsif ($key =~ /^form\.authorquota_(.+)$/) {
12314: $confhash{'authorquota'}{$1} = $env{$key};
12315: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12316: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12317: }
1.72 raeburn 12318: }
12319: }
1.160.6.5 raeburn 12320: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 12321: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12322: @approvalnotify = sort(@approvalnotify);
12323: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.118.2 14(raebu 12324:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.30 raeburn 12325: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12326: foreach my $type (@hasuniquecode) {
12327: if (grep(/^\Q$type\E$/,@crstypes)) {
12328: $confhash{'uniquecode'}{$type} = 1;
12329: }
12330: }
1.160.6.46 raeburn 12331: my (%newbook,%allpos);
1.160.6.30 raeburn 12332: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12333: foreach my $type ('textbooks','templates') {
12334: @{$allpos{$type}} = ();
12335: my $invalid;
12336: if ($type eq 'textbooks') {
12337: $invalid = &mt('Invalid LON-CAPA course for textbook');
12338: } else {
12339: $invalid = &mt('Invalid LON-CAPA course for template');
12340: }
12341: if ($env{'form.'.$type.'_addbook'}) {
12342: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12343: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12344: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12345: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12346: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12347: } else {
12348: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12349: my $position = $env{'form.'.$type.'_addbook_pos'};
12350: $position =~ s/\D+//g;
12351: if ($position ne '') {
12352: $allpos{$type}[$position] = $newbook{$type};
12353: }
1.160.6.30 raeburn 12354: }
1.160.6.46 raeburn 12355: } else {
12356: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 12357: }
12358: }
1.160.6.46 raeburn 12359: }
1.160.6.30 raeburn 12360: }
1.102 raeburn 12361: if (ref($domconfig{$action}) eq 'HASH') {
12362: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12363: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12364: $changes{'notify'}{'approval'} = 1;
12365: }
12366: } else {
1.144 raeburn 12367: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12368: $changes{'notify'}{'approval'} = 1;
12369: }
12370: }
1.160.6.30 raeburn 12371: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12372: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12373: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12374: unless ($confhash{'uniquecode'}{$crstype}) {
12375: $changes{'uniquecode'} = 1;
12376: }
12377: }
12378: unless ($changes{'uniquecode'}) {
12379: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12380: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12381: $changes{'uniquecode'} = 1;
12382: }
12383: }
12384: }
12385: } else {
12386: $changes{'uniquecode'} = 1;
12387: }
12388: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12389: $changes{'uniquecode'} = 1;
12390: }
12391: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12392: foreach my $type ('textbooks','templates') {
12393: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12394: my %deletions;
12395: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12396: if (@todelete) {
12397: map { $deletions{$_} = 1; } @todelete;
12398: }
12399: my %imgdeletions;
12400: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12401: if (@todeleteimages) {
12402: map { $imgdeletions{$_} = 1; } @todeleteimages;
12403: }
12404: my $maxnum = $env{'form.'.$type.'_maxnum'};
12405: for (my $i=0; $i<=$maxnum; $i++) {
12406: my $itemid = $env{'form.'.$type.'_id_'.$i};
12407: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12408: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12409: if ($deletions{$key}) {
12410: if ($domconfig{$action}{$type}{$key}{'image'}) {
12411: #FIXME need to obsolete item in RES space
12412: }
12413: next;
12414: } else {
12415: my $newpos = $env{'form.'.$itemid};
12416: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 12417: foreach my $item ('subject','title','publisher','author') {
12418: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12419: ($type eq 'templates'));
1.160.6.46 raeburn 12420: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12421: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12422: $changes{$type}{$key} = 1;
12423: }
12424: }
12425: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 12426: }
1.160.6.46 raeburn 12427: if ($imgdeletions{$key}) {
12428: $changes{$type}{$key} = 1;
12429: #FIXME need to obsolete item in RES space
12430: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12431: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 12432: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12433: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12434: } else {
12435: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12436: $cdom,$cnum,$type,$configuserok,
12437: $switchserver,$author_ok);
12438: if ($imgurl) {
12439: $confhash{$type}{$key}{'image'} = $imgurl;
12440: $changes{$type}{$key} = 1;
12441: }
12442: if ($error) {
12443: &Apache::lonnet::logthis($error);
12444: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12445: }
1.160.6.118.2 14(raebu 12446:23): }
1.160.6.46 raeburn 12447: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
12448: $confhash{$type}{$key}{'image'} =
12449: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 12450: }
12451: }
12452: }
12453: }
12454: }
12455: }
1.102 raeburn 12456: } else {
1.144 raeburn 12457: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12458: $changes{'notify'}{'approval'} = 1;
12459: }
1.160.6.30 raeburn 12460: if (ref($confhash{'uniquecode'} eq 'HASH')) {
12461: $changes{'uniquecode'} = 1;
12462: }
12463: }
12464: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12465: foreach my $type ('textbooks','templates') {
12466: if ($newbook{$type}) {
12467: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 12468: foreach my $item ('subject','title','publisher','author') {
12469: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12470: ($type eq 'template'));
1.160.6.46 raeburn 12471: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
12472: if ($env{'form.'.$type.'_addbook_'.$item}) {
12473: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
12474: }
12475: }
12476: if ($type eq 'textbooks') {
12477: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
12478: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 12479: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12480: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12481: } else {
12482: my ($imageurl,$error) =
12483: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
12484: $configuserok,$switchserver,$author_ok);
12485: if ($imageurl) {
12486: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
12487: }
12488: if ($error) {
12489: &Apache::lonnet::logthis($error);
12490: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12491: }
1.160.6.46 raeburn 12492: }
12493: }
1.160.6.30 raeburn 12494: }
12495: }
1.160.6.46 raeburn 12496: if (@{$allpos{$type}} > 0) {
12497: my $idx = 0;
12498: foreach my $item (@{$allpos{$type}}) {
12499: if ($item ne '') {
12500: $confhash{$type}{$item}{'order'} = $idx;
12501: if (ref($domconfig{$action}) eq 'HASH') {
12502: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12503: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
12504: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
12505: $changes{$type}{$item} = 1;
12506: }
1.160.6.30 raeburn 12507: }
12508: }
12509: }
1.160.6.46 raeburn 12510: $idx ++;
1.160.6.30 raeburn 12511: }
12512: }
12513: }
12514: }
1.160.6.39 raeburn 12515: if (ref($validationitemsref) eq 'ARRAY') {
12516: foreach my $item (@{$validationitemsref}) {
12517: if ($item eq 'fields') {
12518: my @changed;
12519: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
12520: if (@{$confhash{'validation'}{$item}} > 0) {
12521: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
12522: }
1.160.6.65 raeburn 12523: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12524: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12525: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
12526: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
12527: $domconfig{'requestcourses'}{'validation'}{$item});
12528: } else {
12529: @changed = @{$confhash{'validation'}{$item}};
12530: }
1.160.6.39 raeburn 12531: } else {
12532: @changed = @{$confhash{'validation'}{$item}};
12533: }
12534: } else {
12535: @changed = @{$confhash{'validation'}{$item}};
12536: }
12537: if (@changed) {
12538: if ($confhash{'validation'}{$item}) {
12539: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
12540: } else {
12541: $changes{'validation'}{$item} = &mt('None');
12542: }
12543: }
12544: } else {
12545: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
12546: if ($item eq 'markup') {
12547: if ($env{'form.requestcourses_validation_'.$item}) {
12548: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
12549: }
12550: }
1.160.6.65 raeburn 12551: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12552: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12553: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
12554: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12555: }
12556: } else {
12557: if ($confhash{'validation'}{$item} ne '') {
12558: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12559: }
1.160.6.39 raeburn 12560: }
12561: } else {
12562: if ($confhash{'validation'}{$item} ne '') {
12563: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
12564: }
12565: }
12566: }
12567: }
12568: }
12569: if ($env{'form.validationdc'}) {
12570: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 12571: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 12572: if (exists($domcoords{$newval})) {
12573: $confhash{'validation'}{'dc'} = $newval;
12574: }
12575: }
12576: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 12577: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12578: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12579: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12580: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
12581: if ($confhash{'validation'}{'dc'} eq '') {
12582: $changes{'validation'}{'dc'} = &mt('None');
12583: } else {
12584: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12585: }
1.160.6.39 raeburn 12586: }
1.160.6.65 raeburn 12587: } elsif ($confhash{'validation'}{'dc'} ne '') {
12588: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 12589: }
12590: } elsif ($confhash{'validation'}{'dc'} ne '') {
12591: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12592: }
12593: } elsif ($confhash{'validation'}{'dc'} ne '') {
12594: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
12595: }
1.160.6.65 raeburn 12596: } else {
12597: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
12598: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
12599: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
12600: $changes{'validation'}{'dc'} = &mt('None');
12601: }
12602: }
1.160.6.39 raeburn 12603: }
12604: }
1.102 raeburn 12605: }
12606: } else {
1.86 raeburn 12607: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
1.160.6.20 raeburn 12608: $confhash{'authorquota'}{'default'} = $env{'form.authorquota'};
1.86 raeburn 12609: }
1.72 raeburn 12610: foreach my $item (@usertools) {
12611: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 12612: my $unset;
1.101 raeburn 12613: if ($context eq 'requestcourses') {
1.104 raeburn 12614: $unset = '0';
12615: if ($type eq '_LC_adv') {
12616: $unset = '';
12617: }
1.101 raeburn 12618: if ($confhash{$item}{$type} eq 'autolimit') {
12619: $confhash{$item}{$type} .= '=';
12620: unless ($limithash{$item}{$type} =~ /\D/) {
12621: $confhash{$item}{$type} .= $limithash{$item}{$type};
12622: }
12623: }
1.160.6.5 raeburn 12624: } elsif ($context eq 'requestauthor') {
12625: $unset = '0';
12626: if ($type eq '_LC_adv') {
12627: $unset = '';
12628: }
1.72 raeburn 12629: } else {
1.101 raeburn 12630: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
12631: $confhash{$item}{$type} = 1;
12632: } else {
12633: $confhash{$item}{$type} = 0;
12634: }
1.72 raeburn 12635: }
1.86 raeburn 12636: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 12637: if ($action eq 'requestauthor') {
12638: if ($domconfig{$action}{$type} ne $confhash{$type}) {
12639: $changes{$type} = 1;
12640: }
12641: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 12642: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
12643: $changes{$item}{$type} = 1;
12644: }
12645: } else {
12646: if ($context eq 'requestcourses') {
1.104 raeburn 12647: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 12648: $changes{$item}{$type} = 1;
12649: }
12650: } else {
12651: if (!$confhash{$item}{$type}) {
12652: $changes{$item}{$type} = 1;
12653: }
12654: }
12655: }
12656: } else {
12657: if ($context eq 'requestcourses') {
1.104 raeburn 12658: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 12659: $changes{$item}{$type} = 1;
12660: }
1.160.6.5 raeburn 12661: } elsif ($context eq 'requestauthor') {
12662: if ($confhash{$type} ne $unset) {
12663: $changes{$type} = 1;
12664: }
1.72 raeburn 12665: } else {
12666: if (!$confhash{$item}{$type}) {
12667: $changes{$item}{$type} = 1;
12668: }
12669: }
12670: }
1.1 raeburn 12671: }
12672: }
1.160.6.5 raeburn 12673: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 12674: if (ref($domconfig{'quotas'}) eq 'HASH') {
12675: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12676: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
12677: if (exists($confhash{'defaultquota'}{$key})) {
12678: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
12679: $changes{'defaultquota'}{$key} = 1;
12680: }
12681: } else {
12682: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 12683: }
12684: }
1.86 raeburn 12685: } else {
12686: foreach my $key (keys(%{$domconfig{'quotas'}})) {
12687: if (exists($confhash{'defaultquota'}{$key})) {
12688: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
12689: $changes{'defaultquota'}{$key} = 1;
12690: }
12691: } else {
12692: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 12693: }
1.1 raeburn 12694: }
12695: }
1.160.6.20 raeburn 12696: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12697: foreach my $key (keys(%{$domconfig{'quotas'}{'authorquota'}})) {
12698: if (exists($confhash{'authorquota'}{$key})) {
12699: if ($confhash{'authorquota'}{$key} ne $domconfig{'quotas'}{'authorquota'}{$key}) {
12700: $changes{'authorquota'}{$key} = 1;
12701: }
12702: } else {
12703: $confhash{'authorquota'}{$key} = $domconfig{'quotas'}{'authorquota'}{$key};
12704: }
12705: }
12706: }
1.1 raeburn 12707: }
1.86 raeburn 12708: if (ref($confhash{'defaultquota'}) eq 'HASH') {
12709: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
12710: if (ref($domconfig{'quotas'}) eq 'HASH') {
12711: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
12712: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
12713: $changes{'defaultquota'}{$key} = 1;
12714: }
12715: } else {
12716: if (!exists($domconfig{'quotas'}{$key})) {
12717: $changes{'defaultquota'}{$key} = 1;
12718: }
1.72 raeburn 12719: }
12720: } else {
1.86 raeburn 12721: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 12722: }
1.1 raeburn 12723: }
12724: }
1.160.6.20 raeburn 12725: if (ref($confhash{'authorquota'}) eq 'HASH') {
12726: foreach my $key (keys(%{$confhash{'authorquota'}})) {
12727: if (ref($domconfig{'quotas'}) eq 'HASH') {
12728: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
12729: if (!exists($domconfig{'quotas'}{'authorquota'}{$key})) {
12730: $changes{'authorquota'}{$key} = 1;
12731: }
12732: } else {
12733: $changes{'authorquota'}{$key} = 1;
12734: }
12735: } else {
12736: $changes{'authorquota'}{$key} = 1;
12737: }
12738: }
12739: }
1.1 raeburn 12740: }
1.72 raeburn 12741:
1.160.6.5 raeburn 12742: if ($context eq 'requestauthor') {
12743: $domdefaults{'requestauthor'} = \%confhash;
12744: } else {
12745: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 12746: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 12747: $domdefaults{$key} = $confhash{$key};
12748: }
1.160.6.5 raeburn 12749: }
1.72 raeburn 12750: }
1.160.6.5 raeburn 12751:
1.1 raeburn 12752: my %quotahash = (
1.86 raeburn 12753: $action => { %confhash }
1.1 raeburn 12754: );
12755: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
12756: $dom);
12757: if ($putresult eq 'ok') {
12758: if (keys(%changes) > 0) {
1.72 raeburn 12759: my $cachetime = 24*60*60;
12760: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 12761: if (ref($lastactref) eq 'HASH') {
12762: $lastactref->{'domdefaults'} = 1;
12763: }
1.1 raeburn 12764: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 12765: unless (($context eq 'requestcourses') ||
12766: ($context eq 'requestauthor')) {
1.86 raeburn 12767: if (ref($changes{'defaultquota'}) eq 'HASH') {
12768: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
12769: foreach my $type (@{$types},'default') {
12770: if (defined($changes{'defaultquota'}{$type})) {
12771: my $typetitle = $usertypes->{$type};
12772: if ($type eq 'default') {
12773: $typetitle = $othertitle;
12774: }
1.160.6.28 raeburn 12775: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 12776: }
12777: }
1.86 raeburn 12778: $resulttext .= '</ul></li>';
1.72 raeburn 12779: }
1.160.6.20 raeburn 12780: if (ref($changes{'authorquota'}) eq 'HASH') {
1.160.6.34 raeburn 12781: $resulttext .= '<li>'.&mt('Authoring Space default quotas').'<ul>';
1.160.6.20 raeburn 12782: foreach my $type (@{$types},'default') {
12783: if (defined($changes{'authorquota'}{$type})) {
12784: my $typetitle = $usertypes->{$type};
12785: if ($type eq 'default') {
12786: $typetitle = $othertitle;
12787: }
1.160.6.28 raeburn 12788: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'authorquota'}{$type}).'</li>';
1.160.6.20 raeburn 12789: }
12790: }
12791: $resulttext .= '</ul></li>';
12792: }
1.72 raeburn 12793: }
1.80 raeburn 12794: my %newenv;
1.72 raeburn 12795: foreach my $item (@usertools) {
1.160.6.5 raeburn 12796: my (%haschgs,%inconf);
12797: if ($context eq 'requestauthor') {
12798: %haschgs = %changes;
12799: %inconf = %confhash;
12800: } else {
12801: if (ref($changes{$item}) eq 'HASH') {
12802: %haschgs = %{$changes{$item}};
12803: }
12804: if (ref($confhash{$item}) eq 'HASH') {
12805: %inconf = %{$confhash{$item}};
12806: }
12807: }
12808: if (keys(%haschgs) > 0) {
1.80 raeburn 12809: my $newacc =
12810: &Apache::lonnet::usertools_access($env{'user.name'},
12811: $env{'user.domain'},
1.86 raeburn 12812: $item,'reload',$context);
1.160.6.5 raeburn 12813: if (($context eq 'requestcourses') ||
12814: ($context eq 'requestauthor')) {
1.108 raeburn 12815: if ($env{'environment.canrequest.'.$item} ne $newacc) {
12816: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 12817: }
12818: } else {
12819: if ($env{'environment.availabletools.'.$item} ne $newacc) {
12820: $newenv{'environment.availabletools.'.$item} = $newacc;
12821: }
1.80 raeburn 12822: }
1.160.6.5 raeburn 12823: unless ($context eq 'requestauthor') {
12824: $resulttext .= '<li>'.$titles{$item}.'<ul>';
12825: }
1.72 raeburn 12826: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 12827: if ($haschgs{$type}) {
1.72 raeburn 12828: my $typetitle = $usertypes->{$type};
12829: if ($type eq 'default') {
12830: $typetitle = $othertitle;
12831: } elsif ($type eq '_LC_adv') {
12832: $typetitle = 'LON-CAPA Advanced Users';
12833: }
1.160.6.5 raeburn 12834: if ($inconf{$type}) {
1.101 raeburn 12835: if ($context eq 'requestcourses') {
12836: my $cond;
1.160.6.5 raeburn 12837: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 12838: if ($1 eq '') {
12839: $cond = &mt('(Automatic processing of any request).');
12840: } else {
12841: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
12842: }
12843: } else {
1.160.6.5 raeburn 12844: $cond = $conditions{$inconf{$type}};
1.101 raeburn 12845: }
12846: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 12847: } elsif ($context eq 'requestauthor') {
12848: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
12849: $titles{$inconf{$type}},$typetitle);
12850:
1.101 raeburn 12851: } else {
12852: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
12853: }
1.72 raeburn 12854: } else {
1.104 raeburn 12855: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 12856: if ($inconf{$type} eq '0') {
1.104 raeburn 12857: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12858: } else {
12859: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
12860: }
12861: } else {
12862: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
12863: }
1.72 raeburn 12864: }
12865: }
1.26 raeburn 12866: }
1.160.6.5 raeburn 12867: unless ($context eq 'requestauthor') {
12868: $resulttext .= '</ul></li>';
12869: }
1.26 raeburn 12870: }
1.1 raeburn 12871: }
1.160.6.5 raeburn 12872: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 12873: if (ref($changes{'notify'}) eq 'HASH') {
12874: if ($changes{'notify'}{'approval'}) {
12875: if (ref($confhash{'notify'}) eq 'HASH') {
12876: if ($confhash{'notify'}{'approval'}) {
12877: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
12878: } else {
1.160.6.5 raeburn 12879: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 12880: }
12881: }
12882: }
12883: }
12884: }
1.160.6.30 raeburn 12885: if ($action eq 'requestcourses') {
12886: my @offon = ('off','on');
12887: if ($changes{'uniquecode'}) {
12888: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12889: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
12890: $resulttext .= '<li>'.
12891: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
12892: '</li>';
12893: } else {
12894: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
12895: '</li>';
12896: }
12897: }
1.160.6.46 raeburn 12898: foreach my $type ('textbooks','templates') {
12899: if (ref($changes{$type}) eq 'HASH') {
12900: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
12901: foreach my $key (sort(keys(%{$changes{$type}}))) {
12902: my %coursehash = &Apache::lonnet::coursedescription($key);
12903: my $coursetitle = $coursehash{'description'};
12904: my $position = $confhash{$type}{$key}{'order'} + 1;
12905: $resulttext .= '<li>';
1.160.6.47 raeburn 12906: foreach my $item ('subject','title','publisher','author') {
12907: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12908: ($type eq 'templates'));
1.160.6.46 raeburn 12909: my $name = $item.':';
12910: $name =~ s/^(\w)/\U$1/;
12911: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
12912: }
12913: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
12914: if ($type eq 'textbooks') {
12915: if ($confhash{$type}{$key}{'image'}) {
12916: $resulttext .= ' '.&mt('Image: [_1]',
12917: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
12918: ' alt="Textbook cover" />').'<br />';
12919: }
12920: }
12921: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 12922: }
1.160.6.46 raeburn 12923: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 12924: }
12925: }
1.160.6.39 raeburn 12926: if (ref($changes{'validation'}) eq 'HASH') {
12927: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
12928: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
12929: foreach my $item (@{$validationitemsref}) {
12930: if (exists($changes{'validation'}{$item})) {
12931: if ($item eq 'markup') {
12932: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12933: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
12934: } else {
12935: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
12936: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
12937: }
12938: }
12939: }
12940: if (exists($changes{'validation'}{'dc'})) {
12941: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
12942: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
12943: }
12944: }
12945: }
1.160.6.30 raeburn 12946: }
1.1 raeburn 12947: $resulttext .= '</ul>';
1.80 raeburn 12948: if (keys(%newenv)) {
12949: &Apache::lonnet::appenv(\%newenv);
12950: }
1.1 raeburn 12951: } else {
1.86 raeburn 12952: if ($context eq 'requestcourses') {
12953: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 12954: } elsif ($context eq 'requestauthor') {
12955: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 12956: } else {
1.90 weissno 12957: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 12958: }
1.1 raeburn 12959: }
12960: } else {
1.11 albertel 12961: $resulttext = '<span class="LC_error">'.
12962: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 12963: }
1.160.6.30 raeburn 12964: if ($errors) {
12965: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
12966: '<ul>'.$errors.'</ul></p>';
12967: }
1.3 raeburn 12968: return $resulttext;
1.1 raeburn 12969: }
12970:
1.160.6.30 raeburn 12971: sub process_textbook_image {
1.160.6.46 raeburn 12972: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 12973: my $filename = $env{'form.'.$caller.'.filename'};
12974: my ($error,$url);
12975: my ($width,$height) = (50,50);
12976: if ($configuserok eq 'ok') {
12977: if ($switchserver) {
12978: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
12979: $switchserver);
12980: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12981:23): my $modified = [];
1.160.6.30 raeburn 12982: my ($result,$imageurl) =
1.160.6.118.2 14(raebu 12983:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
12984:23): "$type/$cdom/$cnum/cover",$width,$height,
12985:23): '',$modified);
1.160.6.30 raeburn 12986: if ($result eq 'ok') {
12987: $url = $imageurl;
1.160.6.118.2 14(raebu 12988:23): &update_modify_urls($r,$modified);
1.160.6.30 raeburn 12989: } else {
12990: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
12991: }
12992: } else {
12993: $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);
12994: }
12995: } else {
12996: $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);
12997: }
12998: return ($url,$error);
12999: }
13000:
1.160.6.118.2 1(raebur 13001:1): sub modify_ltitools {
13002:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14(raebu 13003:23): my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
13004:23): &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
13005:23):
1(raebur 13006:1): my $confname = $dom.'-domainconfig';
13007:1): my $servadm = $r->dir_config('lonAdmEMail');
13008:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14(raebu 13009:23):
13010:23): my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
13011:23): my $toolserror =
13012:23): &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
13013:23): $lastactref,$configuserok,$switchserver,$author_ok);
13014:23):
13015:23): my $home = &Apache::lonnet::domain($dom,'primary');
13016:23): unless (($home eq 'no_host') || ($home eq '')) {
13017:23): my @ids=&Apache::lonnet::current_machine_ids();
13018:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
13019:23): }
13020:23):
13021:23): if (keys(%ltitoolschg)) {
13022:23): foreach my $id (keys(%ltitoolschg)) {
13023:23): if (ref($ltitoolschg{$id}) eq 'HASH') {
13024:23): foreach my $inner (keys(%{$ltitoolschg{$id}})) {
13025:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13026:23): if ($is_home) {
13027:23): $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
13028:23): }
13029:23): }
1(raebur 13030:1): }
14(raebu 13031:23): }
13032:23): }
13033:23): $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
13034:23): if (keys(%ltitoolschg)) {
13035:23): %newltitools = %ltitoolschg;
13036:23): }
13037:23): }
13038:23): if (ref($domconfig{'ltitools'}) eq 'HASH') {
13039:23): foreach my $id (%{$domconfig{'ltitools'}}) {
13040:23): next if ($id !~ /^\d+$/);
13041:23): unless (exists($ltitoolschg{$id})) {
13042:23): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
13043:23): foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
13044:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13045:23): if ($is_home) {
13046:23): $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13047:23): }
13048:23): } else {
13049:23): $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13050:23): }
1(raebur 13051:1): }
14(raebu 13052:23): } else {
13053:23): $newltitools{$id} = $domconfig{'ltitools'}{$id};
1(raebur 13054:1): }
13055:1): }
14(raebu 13056:23): }
13057:23): }
13058:23): if ($toolserror) {
13059:23): $errors = '<li>'.$toolserror.'</li>';
13060:23): }
13061:23): if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
13062:23): $resulttext = &mt('No changes made.');
13063:23): if ($errors) {
13064:23): $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13065:23): $errors.'</ul>';
13066:23): }
13067:23): return $resulttext;
13068:23): }
13069:23): my %ltitoolshash = (
13070:23): $action => { %newltitools }
13071:23): );
13072:23): if (keys(%secchanges)) {
13073:23): $ltitoolshash{'toolsec'} = \%newtoolsec;
13074:23): }
13075:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
13076:23): if ($putresult eq 'ok') {
13077:23): my %keystore;
13078:23): if ($is_home) {
13079:23): my %toolsenchash = (
13080:23): $action => { %newtoolsenc }
13081:23): );
13082:23): &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13083:23): my $cachetime = 24*60*60;
13084:23): &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13085:23): &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13086:23): }
13087:23): $resulttext = &mt('Changes made:').'<ul>';
13088:23): if (keys(%secchanges) > 0) {
13089:23): $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13090:23): }
13091:23): if (keys(%ltitoolschg) > 0) {
13092:23): $resulttext .= $ltitoolsoutput;
13093:23): }
13094:23): my $cachetime = 24*60*60;
13095:23): &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13096:23): if (ref($lastactref) eq 'HASH') {
13097:23): $lastactref->{'ltitools'} = 1;
13098:23): }
13099:23): } else {
13100:23): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13101:23): }
13102:23): if ($errors) {
13103:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13104:23): $errors.'</ul></p>';
13105:23): }
13106:23): return $resulttext;
13107:23): }
13108:23):
13109:23): sub fetch_secrets {
13110:23): my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13111:23): my %keyset;
13112:23): %{$currsec} = ();
13113:23): $newsec->{'private'}{'keys'} = [];
13114:23): $newsec->{'encrypt'} = {};
13115:23): $newsec->{'rules'} = {};
13116:23): if ($context eq 'ltisec') {
13117:23): $newsec->{'linkprot'} = {};
13118:23): }
13119:23): if (ref($domconfig->{$context}) eq 'HASH') {
13120:23): %{$currsec} = %{$domconfig->{$context}};
13121:23): if ($context eq 'ltisec') {
13122:23): if (ref($currsec->{'linkprot'}) eq 'HASH') {
13123:23): foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13124:23): unless ($id =~ /^\d+$/) {
13125:23): delete($currsec->{'linkprot'}{$id});
13126:23): }
13127:23): }
1(raebur 13128:1): }
14(raebu 13129:23): }
13130:23): if (ref($currsec->{'private'}) eq 'HASH') {
13131:23): if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13132:23): $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13133:23): map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1(raebur 13134:1): }
14(raebu 13135:23): }
13136:23): }
13137:23): my @items= ('crs','dom');
13138:23): if ($context eq 'ltisec') {
13139:23): push(@items,'consumers');
13140:23): }
13141:23): foreach my $item (@items) {
13142:23): my $formelement;
13143:23): if (($context eq 'toolsec') || ($item eq 'consumers')) {
13144:23): $formelement = 'form.'.$context.'_'.$item;
13145:23): } else {
13146:23): $formelement = 'form.'.$context.'_'.$item.'linkprot';
13147:23): }
13148:23): if ($env{$formelement}) {
13149:23): $newsec->{'encrypt'}{$item} = 1;
13150:23): if (ref($currsec->{'encrypt'}) eq 'HASH') {
13151:23): unless ($currsec->{'encrypt'}{$item}) {
13152:23): $secchanges->{'encrypt'} = 1;
13153:23): }
1(raebur 13154:1): } else {
14(raebu 13155:23): $secchanges->{'encrypt'} = 1;
13156:23): }
13157:23): } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13158:23): if ($currsec->{'encrypt'}{$item}) {
13159:23): $secchanges->{'encrypt'} = 1;
1(raebur 13160:1): }
14(raebu 13161:23): }
13162:23): }
13163:23): my $secrets;
13164:23): if ($context eq 'ltisec') {
13165:23): $secrets = 'ltisecrets';
13166:23): } else {
13167:23): $secrets = 'toolsecrets';
13168:23): }
13169:23): unless (exists($currsec->{'rules'})) {
13170:23): $currsec->{'rules'} = {};
13171:23): }
13172:23): &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13173:23):
13174:23): my @ids=&Apache::lonnet::current_machine_ids();
13175:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
13176:23):
13177:23): foreach my $hostid (keys(%servers)) {
13178:23): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13179:23): my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13180:23): if (exists($env{$keyitem})) {
13181:23): $env{$keyitem} =~ s/(`)/'/g;
13182:23): if ($keyset{$hostid}) {
13183:23): if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13184:23): if ($env{$keyitem} ne '') {
13185:23): $secchanges->{'private'} = 1;
13186:23): $newkeyset->{$hostid} = $env{$keyitem};
13187:23): }
1(raebur 13188:1): }
14(raebu 13189:23): } elsif ($env{$keyitem} ne '') {
13190:23): unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13191:23): push(@{$newsec->{'private'}{'keys'}},$hostid);
1(raebur 13192:1): }
14(raebu 13193:23): $secchanges->{'private'} = 1;
13194:23): $newkeyset->{$hostid} = $env{$keyitem};
1(raebur 13195:1): }
13196:1): }
14(raebu 13197:23): }
13198:23): }
13199:23): }
13200:23):
13201:23): sub store_security {
13202:23): my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13203:23): return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13204:23): (ref($keystore) eq 'HASH'));
13205:23): if (keys(%{$secchanges})) {
13206:23): if ($secchanges->{'private'}) {
13207:23): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13208:23): foreach my $hostid (keys(%{$newkeyset})) {
13209:23): my $storehash = {
13210:23): key => $newkeyset->{$hostid},
13211:23): who => $env{'user.name'}.':'.$env{'user.domain'},
13212:23): };
13213:23): $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13214:23): $dom,$hostid);
13215:23): }
13216:23): }
13217:23): }
13218:23): }
13219:23):
13220:23): sub lti_security_results {
13221:23): my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13222:23): my $output;
13223:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13224:23): my $needs_update;
13225:23): foreach my $item (keys(%{$secchanges})) {
13226:23): if ($item eq 'encrypt') {
13227:23): $needs_update = 1;
13228:23): my %encrypted;
13229:23): if ($context eq 'lti') {
13230:23): %encrypted = (
13231:23): crs => {
13232:23): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13233:23): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13234:23): },
13235:23): dom => {
13236:23): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13237:23): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13238:23): },
13239:23): consumers => {
13240:23): on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13241:23): off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13242:23): },
13243:23): );
1(raebur 13244:1): } else {
14(raebu 13245:23): %encrypted = (
13246:23): crs => {
13247:23): on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13248:23): off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13249:23): },
13250:23): dom => {
13251:23): on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13252:23): off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13253:23): },
13254:23): );
1(raebur 13255:1): }
14(raebu 13256:23): my @types= ('crs','dom');
13257:23): if ($context eq 'lti') {
13258:23): foreach my $type (@types) {
13259:23): undef($domdefaults{'linkprotenc_'.$type});
1(raebur 13260:1): }
14(raebu 13261:23): push(@types,'consumers');
13262:23): undef($domdefaults{'ltienc_consumers'});
13263:23): } elsif ($context eq 'ltitools') {
13264:23): foreach my $type (@types) {
13265:23): undef($domdefaults{'toolenc_'.$type});
1(raebur 13266:1): }
13267:1): }
14(raebu 13268:23): foreach my $type (@types) {
13269:23): my $shown = $encrypted{$type}{'off'};
13270:23): if (ref($newsec->{$item}) eq 'HASH') {
13271:23): if ($newsec->{$item}{$type}) {
13272:23): if ($context eq 'lti') {
13273:23): if ($type eq 'consumers') {
13274:23): $domdefaults{'ltienc_consumers'} = 1;
13275:23): } else {
13276:23): $domdefaults{'linkprotenc_'.$type} = 1;
1(raebur 13277:1): }
14(raebu 13278:23): } elsif ($context eq 'ltitools') {
13279:23): $domdefaults{'toolenc_'.$type} = 1;
1(raebur 13280:1): }
14(raebu 13281:23): $shown = $encrypted{$type}{'on'};
1(raebur 13282:1): }
13283:1): }
14(raebu 13284:23): $output .= '<li>'.$shown.'</li>';
13285:23): }
13286:23): } elsif ($item eq 'rules') {
13287:23): my %titles = &Apache::lonlocal::texthash(
13288:23): min => 'Minimum password length',
13289:23): max => 'Maximum password length',
13290:23): chars => 'Required characters',
13291:23): );
13292:23): foreach my $rule ('min','max') {
13293:23): if ($newsec->{rules}{$rule} eq '') {
13294:23): if ($rule eq 'min') {
13295:23): $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13296:23): ' '.&mt('Default of [_1] will be used',
13297:23): $Apache::lonnet::passwdmin).'</li>';
13298:23): } else {
13299:23): $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13300:23): }
13301:23): } else {
13302:23): $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13303:23): }
13304:23): }
13305:23): if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13306:23): if (@{$newsec->{'rules'}{'chars'}} > 0) {
13307:23): my %rulenames = &Apache::lonlocal::texthash(
13308:23): uc => 'At least one upper case letter',
13309:23): lc => 'At least one lower case letter',
13310:23): num => 'At least one number',
13311:23): spec => 'At least one non-alphanumeric',
13312:23): );
13313:23): my $needed = '<ul><li>'.
13314:23): join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13315:23): '</li></ul>';
13316:23): $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13317:23): } else {
13318:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13319:23): }
13320:23): } else {
13321:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1(raebur 13322:1): }
14(raebu 13323:23): } elsif ($item eq 'private') {
13324:23): $needs_update = 1;
13325:23): if ($context eq 'lti') {
13326:23): undef($domdefaults{'ltiprivhosts'});
13327:23): } elsif ($context eq 'ltitools') {
13328:23): undef($domdefaults{'toolprivhosts'});
13329:23): }
13330:23): if (keys(%{$newkeyset})) {
13331:23): my @privhosts;
13332:23): foreach my $hostid (sort(keys(%{$newkeyset}))) {
13333:23): if ($keystore->{$hostid} eq 'ok') {
13334:23): $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13335:23): unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13336:23): push(@privhosts,$hostid);
13337:23): }
13338:23): }
13339:23): }
13340:23): if (@privhosts) {
13341:23): if ($context eq 'lti') {
13342:23): $domdefaults{'ltiprivhosts'} = \@privhosts;
13343:23): } elsif ($context eq 'ltitools') {
13344:23): $domdefaults{'toolprivhosts'} = \@privhosts;
1(raebur 13345:1): }
13346:1): }
13347:1): }
14(raebu 13348:23): } elsif ($item eq 'linkprot') {
13349:23): next;
18(raebu 13350:24): } elsif ($item eq 'suggested') {
13351:24): if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
13352:24): (ref($newsec->{'suggested'}) eq 'HASH')) {
13353:24): my $suggestions;
13354:24): foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
13355:24): if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
13356:24): my $name = $newsec->{'suggested'}->{$id}->{'name'};
13357:24): my $info = $newsec->{'suggested'}->{$id}->{'info'};
13358:24): $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
13359:24): &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
13360:24): '</li>';
13361:24): } else {
13362:24): $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
13363:24): $newsec->{'suggested'}->{$id}).'</li>';
13364:24): }
13365:24): }
13366:24): if ($suggestions) {
13367:24): $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
13368:24): '<ul>'.$suggestions.'</ul>'.
13369:24): '</li>';
13370:24): }
13371:24): }
14(raebu 13372:23): }
13373:23): }
13374:23): if ($needs_update) {
13375:23): my $cachetime = 24*60*60;
13376:23): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13377:23): }
13378:23): return $output;
13379:23): }
13380:23):
13381:23): sub modify_lti {
13382:23): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13383:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13384:23): my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13385:23): my (%posslti,%posslticrs,%posscrstype);
13386:23): my @courseroles = ('cc','in','ta','ep','st');
13387:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13388:23): my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13389:23): my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13390:23): my %coursetypetitles = &Apache::lonlocal::texthash (
13391:23): official => 'Official',
13392:23): unofficial => 'Unofficial',
13393:23): community => 'Community',
13394:23): textbook => 'Textbook',
13395:23): placement => 'Placement Test',
13396:23): lti => 'LTI Provider',
13397:23): );
13398:23): my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13399:23): my %lt = <i_names();
13400:23): map { $posslti{$_} = 1; } @ltiroles;
13401:23): map { $posslticrs{$_} = 1; } @lticourseroles;
13402:23): map { $posscrstype{$_} = 1; } @coursetypes;
13403:23):
13404:23): my %menutitles = <imenu_titles();
13405:23): my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13406:23):
13407:23): &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13408:23):
13409:23): my (%linkprotchg,$linkprotoutput,$is_home);
13410:23): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13411:23): \%linkprotchg,'domain');
13412:23): my $home = &Apache::lonnet::domain($dom,'primary');
13413:23): unless (($home eq 'no_host') || ($home eq '')) {
13414:23): my @ids=&Apache::lonnet::current_machine_ids();
13415:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13416:23): }
13417:23):
13418:23): if (keys(%linkprotchg)) {
13419:23): $secchanges{'linkprot'} = 1;
13420:23): my %oldlinkprot;
13421:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13422:23): %oldlinkprot = %{$currltisec{'linkprot'}};
13423:23): }
13424:23): foreach my $id (keys(%linkprotchg)) {
13425:23): if (ref($linkprotchg{$id}) eq 'HASH') {
13426:23): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13427:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13428:23): if ($is_home) {
13429:23): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13430:23): }
13431:23): }
13432:23): }
13433:23): } else {
13434:23): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
1(raebur 13435:1): }
14(raebu 13436:23): }
13437:23): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13438:23): if (keys(%linkprotchg)) {
13439:23): %{$newltisec{'linkprot'}} = %linkprotchg;
13440:23): }
13441:23): }
13442:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
18(raebu 13443:24): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
14(raebu 13444:23): next if ($id !~ /^\d+$/);
13445:23): unless (exists($linkprotchg{$id})) {
13446:23): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13447:23): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13448:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13449:23): if ($is_home) {
13450:23): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13451:23): }
13452:23): } else {
13453:23): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13454:23): }
13455:23): }
13456:23): } else {
13457:23): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13458:23): }
1(raebur 13459:1): }
14(raebu 13460:23): }
13461:23): }
13462:23): if ($proterror) {
13463:23): $errors .= '<li>'.$proterror.'</li>';
13464:23): }
18(raebu 13465:24):
13466:24): my (%delsuggested,%suggids,@suggested);;
13467:24): if (ref($currltisec{'suggested'}) eq 'HASH') {
13468:24): my $maxnum = $env{'form.linkprot_suggested_maxnum'};
13469:24): my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
13470:24): for (my $i=0; $i<$maxnum; $i++) {
13471:24): my $itemid = $env{'form.linkprot_suggested_id_'.$i};
13472:24): $itemid =~ s/\D+//g;
13473:24): if ($itemid) {
13474:24): if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
13475:24): push(@suggested,$i);
13476:24): $suggids{$i} = $itemid;
13477:24): if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
13478:24): if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
13479:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
13480:24): }
13481:24): } else {
13482:24): if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
13483:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
13484:24): } else {
13485:24): $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
13486:24): $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
13487:24): $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
13488:24): $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
13489:24): if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
13490:24): ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
13491:24): $secchanges{'suggested'}{$itemid} = 1;
13492:24): }
13493:24): }
13494:24): }
13495:24): }
13496:24): }
13497:24): }
13498:24): }
13499:24): foreach my $key (keys(%delsuggested)) {
13500:24): $newltisec{'suggested'}{$key} = $delsuggested{$key};
13501:24): $secchanges{'suggested'}{$key} = 1;
13502:24): }
13503:24): if (($env{'form.linkprot_suggested_add'}) &&
13504:24): ($env{'form.linkprot_suggested_name_add'} ne '')) {
13505:24): $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
13506:24): $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
13507:24): my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
13508:24): if ($newsuggid) {
13509:24): $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
13510:24): $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
13511:24): $secchanges{'suggested'}{$newsuggid} = 1;
13512:24): } else {
13513:24): my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
13514:24): if ($errormsg) {
13515:24): $error .= ' ('.$errormsg.')';
13516:24): }
13517:24): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13518:24): }
13519:24): }
14(raebu 13520:23): my (@items,%deletions,%itemids);
13521:23): if ($env{'form.lti_add'}) {
13522:23): my $consumer = $env{'form.lti_consumer_add'};
13523:23): $consumer =~ s/(`)/'/g;
18(raebu 13524:24): ($newid,my $errormsg) = &get_lti_id($dom,$consumea,'lt'r);
14(raebu 13525:23): if ($newid) {
13526:23): $itemids{'add'} = $newid;
13527:23): push(@items,'add');
13528:23): $changes{$newid} = 1;
1(raebur 13529:1): } else {
14(raebu 13530:23): my $error = &mt('Failed to acquire unique ID for new LTI configuration');
18(raebu 13531:24): if ($errormsg) {
13532:24): $error .= ' ('.$errormsg.')';
13533:24): }
1(raebur 13534:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13535:1): }
13536:1): }
13537:1): if (ref($domconfig{$action}) eq 'HASH') {
14(raebu 13538:23): my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
1(raebur 13539:1): if (@todelete) {
13540:1): map { $deletions{$_} = 1; } @todelete;
13541:1): }
14(raebu 13542:23): my $maxnum = $env{'form.lti_maxnum'};
13543:23): for (my $i=0; $i<$maxnum; $i++) {
13544:23): my $itemid = $env{'form.lti_id_'.$i};
1(raebur 13545:1): $itemid =~ s/\D+//g;
13546:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13547:1): if ($deletions{$itemid}) {
14(raebu 13548:23): $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
1(raebur 13549:1): } else {
14(raebu 13550:23): push(@items,$i);
13551:23): $itemids{$i} = $itemid;
13552:23): }
13553:23): }
13554:23): }
13555:23): }
13556:23): my (%keystore,$secstored);
13557:23): if ($is_home) {
13558:23): &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
13559:23): }
13560:23):
13561:23): my ($cipher,$privnum);
13562:23): if ((@items > 0) && ($is_home)) {
13563:23): ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
13564:23): $newltisec{'encrypt'},$keystore{$home});
13565:23): }
13566:23): foreach my $idx (@items) {
13567:23): my $itemid = $itemids{$idx};
13568:23): next unless ($itemid);
13569:23): my %currlti;
13570:23): unless ($idx eq 'add') {
13571:23): if (ref($domconfig{$action}) eq 'HASH') {
13572:23): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13573:23): %currlti = %{$domconfig{$action}{$itemid}};
13574:23): }
13575:23): }
13576:23): }
13577:23): my $position = $env{'form.lti_pos_'.$itemid};
13578:23): $position =~ s/\D+//g;
13579:23): if ($position ne '') {
13580:23): $allpos[$position] = $itemid;
13581:23): }
13582:23): foreach my $item ('consumer','lifetime','requser','crsinc') {
13583:23): my $formitem = 'form.lti_'.$item.'_'.$idx;
13584:23): $env{$formitem} =~ s/(`)/'/g;
13585:23): if ($item eq 'lifetime') {
13586:23): $env{$formitem} =~ s/[^\d.]//g;
13587:23): }
13588:23): if ($env{$formitem} ne '') {
13589:23): $confhash{$itemid}{$item} = $env{$formitem};
13590:23): unless (($idx eq 'add') || ($changes{$itemid})) {
13591:23): if ($currlti{$item} ne $confhash{$itemid}{$item}) {
13592:23): $changes{$itemid} = 1;
13593:23): }
13594:23): }
13595:23): }
13596:23): }
13597:23): if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
13598:23): $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
13599:23): }
13600:23): if ($confhash{$itemid}{'requser'}) {
13601:23): if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
13602:23): $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
13603:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
13604:23): $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
13605:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
13606:23): my $mapuser = $env{'form.lti_customuser_'.$idx};
13607:23): $mapuser =~ s/(`)/'/g;
13608:23): $mapuser =~ s/^\s+|\s+$//g;
13609:23): $confhash{$itemid}{'mapuser'} = $mapuser;
13610:23): }
13611:23): my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
13612:23): my @makeuser;
13613:23): foreach my $ltirole (sort(@possmakeuser)) {
13614:23): if ($posslti{$ltirole}) {
13615:23): push(@makeuser,$ltirole);
13616:23): }
13617:23): }
13618:23): $confhash{$itemid}{'makeuser'} = \@makeuser;
13619:23): if (@makeuser) {
13620:23): my $lcauth = $env{'form.lti_lcauth_'.$idx};
13621:23): if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
13622:23): $confhash{$itemid}{'lcauth'} = $lcauth;
13623:23): if ($lcauth ne 'internal') {
13624:23): my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
13625:23): $lcauthparm =~ s/^(\s+|\s+)$//g;
13626:23): $lcauthparm =~ s/`//g;
13627:23): if ($lcauthparm ne '') {
13628:23): $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
1(raebur 13629:1): }
13630:1): }
14(raebu 13631:23): } else {
13632:23): $confhash{$itemid}{'lcauth'} = 'lti';
13633:23): }
13634:23): }
13635:23): my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
13636:23): if (@possinstdata) {
13637:23): foreach my $field (@possinstdata) {
13638:23): if (exists($fieldtitles{$field})) {
13639:23): push(@{$confhash{$itemid}{'instdata'}});
13640:23): }
13641:23): }
13642:23): }
13643:23): if ($env{'form.lti_callback_'.$idx}) {
13644:23): if ($env{'form.lti_callbackparam_'.$idx}) {
13645:23): my $callback = $env{'form.lti_callbackparam_'.$idx};
13646:23): $callback =~ s/^\s+|\s+$//g;
13647:23): $confhash{$itemid}{'callback'} = $callback;
13648:23): }
13649:23): }
13650:23): foreach my $field ('topmenu','inlinemenu') {
13651:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
13652:23): $confhash{$itemid}{$field} = 1;
13653:23): }
13654:23): }
13655:23): if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
13656:23): $confhash{$itemid}{lcmenu} = [];
13657:23): my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
13658:23): foreach my $field (@possmenu) {
13659:23): if (exists($menutitles{$field})) {
13660:23): if ($field eq 'grades') {
13661:23): next unless ($env{'form.lti_inlinemenu_'.$idx});
1(raebur 13662:1): }
14(raebu 13663:23): push(@{$confhash{$itemid}{lcmenu}},$field);
13664:23): }
13665:23): }
13666:23): }
13667:23): if ($confhash{$itemid}{'crsinc'}) {
13668:23): if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
13669:23): ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
13670:23): $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
13671:23): } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
13672:23): my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
13673:23): $mapcrs =~ s/(`)/'/g;
13674:23): $mapcrs =~ s/^\s+|\s+$//g;
13675:23): $confhash{$itemid}{'mapcrs'} = $mapcrs;
13676:23): }
13677:23): my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
13678:23): my @crstypes;
13679:23): foreach my $type (sort(@posstypes)) {
13680:23): if ($posscrstype{$type}) {
13681:23): push(@crstypes,$type);
13682:23): }
13683:23): }
13684:23): $confhash{$itemid}{'mapcrstype'} = \@crstypes;
13685:23): if ($env{'form.lti_storecrs_'.$idx}) {
13686:23): $confhash{$itemid}{'storecrs'} = 1;
13687:23): }
13688:23): if ($env{'form.lti_makecrs_'.$idx}) {
13689:23): $confhash{$itemid}{'makecrs'} = 1;
13690:23): }
13691:23): foreach my $ltirole (@lticourseroles) {
13692:23): my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
13693:23): if (grep(/^\Q$possrole\E$/,@courseroles)) {
13694:23): $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
1(raebur 13695:1): }
14(raebu 13696:23): }
13697:23): my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
13698:23): my @selfenroll;
13699:23): foreach my $type (sort(@possenroll)) {
13700:23): if ($posslticrs{$type}) {
13701:23): push(@selfenroll,$type);
13702:23): }
13703:23): }
13704:23): $confhash{$itemid}{'selfenroll'} = \@selfenroll;
13705:23): if ($env{'form.lti_crssec_'.$idx}) {
13706:23): if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
13707:23): $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
13708:23): } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
13709:23): my $section = $env{'form.lti_customsection_'.$idx};
13710:23): $section =~ s/(`)/'/g;
13711:23): $section =~ s/^\s+|\s+$//g;
13712:23): if ($section ne '') {
13713:23): $confhash{$itemid}{'section'} = $section;
13714:23): }
1(raebur 13715:1): }
14(raebu 13716:23): }
13717:23): foreach my $field ('passback','roster') {
13718:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
13719:23): $confhash{$itemid}{$field} = 1;
1(raebur 13720:1): }
14(raebu 13721:23): }
13722:23): if ($env{'form.lti_passback_'.$idx}) {
13723:23): if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
13724:23): $confhash{$itemid}{'passbackformat'} = '1.0';
1(raebur 13725:1): } else {
14(raebu 13726:23): $confhash{$itemid}{'passbackformat'} = '1.1';
1(raebur 13727:1): }
14(raebu 13728:23): }
13729:23): }
13730:23): unless (($idx eq 'add') || ($changes{$itemid})) {
13731:23): if ($confhash{$itemid}{'crsinc'}) {
13732:23): foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
13733:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1(raebur 13734:1): $changes{$itemid} = 1;
13735:1): }
13736:1): }
14(raebu 13737:23): unless ($changes{$itemid}) {
13738:23): if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
13739:23): if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1(raebur 13740:1): $changes{$itemid} = 1;
13741:1): }
13742:1): }
13743:1): }
14(raebu 13744:23): foreach my $field ('mapcrstype','selfenroll') {
13745:23): unless ($changes{$itemid}) {
13746:23): if (ref($currlti{$field}) eq 'ARRAY') {
13747:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13748:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
13749:23): $confhash{$itemid}{$field});
13750:23): if (@diffs) {
13751:23): $changes{$itemid} = 1;
13752:23): }
13753:23): } elsif (@{$currlti{$field}} > 0) {
1(raebur 13754:1): $changes{$itemid} = 1;
13755:1): }
14(raebu 13756:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13757:23): if (@{$confhash{$itemid}{$field}} > 0) {
1(raebur 13758:1): $changes{$itemid} = 1;
13759:1): }
13760:1): }
13761:1): }
13762:1): }
14(raebu 13763:23): unless ($changes{$itemid}) {
13764:23): if (ref($currlti{'maproles'}) eq 'HASH') {
13765:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13766:23): foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
13767:23): if ($currlti{'maproles'}{$ltirole} ne
13768:23): $confhash{$itemid}{'maproles'}{$ltirole}) {
13769:23): $changes{$itemid} = 1;
13770:23): last;
1(raebur 13771:1): }
14(raebu 13772:23): }
13773:23): unless ($changes{$itemid}) {
13774:23): foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
13775:23): if ($confhash{$itemid}{'maproles'}{$ltirole} ne
13776:23): $currlti{'maproles'}{$ltirole}) {
1(raebur 13777:1): $changes{$itemid} = 1;
14(raebu 13778:23): last;
1(raebur 13779:1): }
13780:1): }
13781:1): }
14(raebu 13782:23): } elsif (keys(%{$currlti{'maproles'}}) > 0) {
13783:23): $changes{$itemid} = 1;
13784:23): }
13785:23): } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
13786:23): unless ($changes{$itemid}) {
13787:23): if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
1(raebur 13788:1): $changes{$itemid} = 1;
13789:1): }
13790:1): }
13791:1): }
13792:1): }
14(raebu 13793:23): }
13794:23): unless ($changes{$itemid}) {
13795:23): foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
13796:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
13797:23): $changes{$itemid} = 1;
13798:23): }
13799:23): }
13800:23): unless ($changes{$itemid}) {
13801:23): foreach my $field ('makeuser','lcmenu') {
13802:23): if (ref($currlti{$field}) eq 'ARRAY') {
13803:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13804:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
13805:23): $confhash{$itemid}{$field});
13806:23): if (@diffs) {
13807:23): $changes{$itemid} = 1;
13808:23): }
13809:23): } elsif (@{$currlti{$field}} > 0) {
13810:23): $changes{$itemid} = 1;
13811:23): }
13812:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
13813:23): if (@{$confhash{$itemid}{$field}} > 0) {
13814:23): $changes{$itemid} = 1;
13815:23): }
1(raebur 13816:1): }
13817:1): }
13818:1): }
13819:1): }
14(raebu 13820:23): }
13821:23): }
13822:23): if ($is_home) {
13823:23): my $keyitem = 'form.lti_key_'.$idx;
13824:23): $env{$keyitem} =~ s/(`)/'/g;
13825:23): if ($env{$keyitem} ne '') {
13826:23): $ltienc{$itemid}{'key'} = $env{$keyitem};
13827:23): unless ($changes{$itemid}) {
13828:23): if ($currlti{'key'} ne $env{$keyitem}) {
1(raebur 13829:1): $changes{$itemid} = 1;
13830:1): }
14(raebu 13831:23): }
13832:23): }
13833:23): my $secretitem = 'form.lti_secret_'.$idx;
13834:23): $env{$secretitem} =~ s/(`)/'/g;
13835:23): if ($currlti{'usable'}) {
13836:23): if ($env{'form.lti_changesecret_'.$idx}) {
13837:23): if ($env{$secretitem} ne '') {
13838:23): if ($privnum && $cipher) {
13839:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
13840:23): $confhash{$itemid}{'cipher'} = $privnum;
13841:23): } else {
13842:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
13843:23): }
1(raebur 13844:1): $changes{$itemid} = 1;
13845:1): }
14(raebu 13846:23): } else {
13847:23): $ltienc{$itemid}{'secret'} = $currlti{'secret'};
13848:23): $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
1(raebur 13849:1): }
14(raebu 13850:23): if (ref($ltienc{$itemid}) eq 'HASH') {
13851:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
13852:23): $confhash{$itemid}{'usable'} = 1;
13853:23): }
1(raebur 13854:1): }
14(raebu 13855:23): } elsif ($env{$secretitem} ne '') {
13856:23): if ($privnum && $cipher) {
13857:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
13858:23): $confhash{$itemid}{'cipher'} = $privnum;
13859:23): } else {
13860:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
13861:23): }
13862:23): if (ref($ltienc{$itemid}) eq 'HASH') {
13863:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
13864:23): $confhash{$itemid}{'usable'} = 1;
1(raebur 13865:1): }
13866:1): }
14(raebu 13867:23): $changes{$itemid} = 1;
13868:23): }
13869:23): }
13870:23): unless ($changes{$itemid}) {
13871:23): foreach my $key (keys(%currlti)) {
13872:23): if (ref($currlti{$key}) eq 'HASH') {
13873:23): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
13874:23): foreach my $innerkey (keys(%{$currlti{$key}})) {
13875:23): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
1(raebur 13876:1): $changes{$itemid} = 1;
14(raebu 13877:23): last;
1(raebur 13878:1): }
13879:1): }
14(raebu 13880:23): } elsif (keys(%{$currlti{$key}}) > 0) {
13881:23): $changes{$itemid} = 1;
1(raebur 13882:1): }
13883:1): }
14(raebu 13884:23): last if ($changes{$itemid});
1(raebur 13885:1): }
13886:1): }
13887:1): }
13888:1): if (@allpos > 0) {
13889:1): my $idx = 0;
13890:1): foreach my $itemid (@allpos) {
13891:1): if ($itemid ne '') {
13892:1): $confhash{$itemid}{'order'} = $idx;
13893:1): if (ref($domconfig{$action}) eq 'HASH') {
13894:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
13895:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
13896:1): $changes{$itemid} = 1;
13897:1): }
13898:1): }
13899:1): }
13900:1): $idx ++;
13901:1): }
13902:1): }
13903:1): }
14(raebu 13904:23):
13905:23): if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
13906:23): return &mt('No changes made.');
13907:23): }
13908:23):
13909:23): my %ltihash = (
13910:23): $action => { %confhash }
13911:23): );
13912:23): my %ltienchash;
13913:23):
13914:23): if ($is_home) {
13915:23): %ltienchash = (
13916:23): $action => { %ltienc }
13917:23): );
13918:23): }
13919:23): if (keys(%secchanges)) {
13920:23): $ltihash{'ltisec'} = \%newltisec;
13921:23): if ($secchanges{'linkprot'}) {
13922:23): if ($is_home) {
13923:23): $ltienchash{'linkprot'} = \%newltienc;
13924:23): }
13925:23): }
13926:23): }
13927:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1(raebur 13928:1): if ($putresult eq 'ok') {
14(raebu 13929:23): if (keys(%ltienchash)) {
13930:23): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
13931:23): }
13932:23): $resulttext = &mt('Changes made:').'<ul>';
13933:23): if (keys(%secchanges) > 0) {
13934:23): $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
13935:23): if (exists($secchanges{'linkprot'})) {
13936:23): $resulttext .= $linkprotoutput;
13937:23): }
13938:23): }
1(raebur 13939:1): if (keys(%changes) > 0) {
13940:1): my $cachetime = 24*60*60;
14(raebu 13941:23): &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1(raebur 13942:1): if (ref($lastactref) eq 'HASH') {
14(raebu 13943:23): $lastactref->{'lti'} = 1;
1(raebur 13944:1): }
13945:1): my %bynum;
13946:1): foreach my $itemid (sort(keys(%changes))) {
14(raebu 13947:23): if (ref($confhash{$itemid}) eq 'HASH') {
13948:23): my $position = $confhash{$itemid}{'order'};
13949:23): $bynum{$position} = $itemid;
13950:23): }
1(raebur 13951:1): }
13952:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
13953:1): my $itemid = $bynum{$pos};
14(raebu 13954:23): if (ref($confhash{$itemid}) eq 'HASH') {
13955:23): $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1(raebur 13956:1): my $position = $pos + 1;
13957:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14(raebu 13958:23): foreach my $item ('version','lifetime') {
1(raebur 13959:1): if ($confhash{$itemid}{$item} ne '') {
13960:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
13961:1): }
13962:1): }
14(raebu 13963:23): if ($ltienc{$itemid}{'key'} ne '') {
13964:23): $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
13965:23): }
13966:23): if ($ltienc{$itemid}{'secret'} ne '') {
13967:23): $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1(raebur 13968:1): }
14(raebu 13969:23): if ($confhash{$itemid}{'requser'}) {
13970:23): if ($confhash{$itemid}{'callback'}) {
13971:23): $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
13972:23): } else {
13973:23): $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
13974:23): }
13975:23): if ($confhash{$itemid}{'mapuser'}) {
13976:23): my $shownmapuser;
13977:23): if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
13978:23): $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
13979:23): } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
13980:23): $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
13981:23): } else {
13982:23): $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
13983:23): }
13984:23): $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
13985:23): }
13986:23): if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
13987:23): if (@{$confhash{$itemid}{'makeuser'}} > 0) {
13988:23): $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
13989:23): join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
13990:23): if ($confhash{$itemid}{'lcauth'} eq 'lti') {
13991:23): $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
13992:23): } else {
13993:23): $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
13994:23): $confhash{$itemid}{'lcauth'});
13995:23): if ($confhash{$itemid}{'lcauth'} eq 'internal') {
13996:23): $resulttext .= '; '.&mt('a randomly generated password will be created');
13997:23): } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
13998:23): if ($confhash{$itemid}{'lcauthparm'} ne '') {
13999:23): $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14000:23): }
14001:23): } else {
14002:23): $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14003:23): }
14004:23): }
14005:23): $resulttext .= '</li>';
14006:23): } else {
14007:23): $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
1(raebur 14008:1): }
14009:1): }
14(raebu 14010:23): if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14011:23): if (@{$confhash{$itemid}{'instdata'}} > 0) {
14012:23): $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14013:23): join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
14014:23): } else {
14015:23): $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1(raebur 14016:1): }
14017:1): }
14(raebu 14018:23): foreach my $item ('topmenu','inlinemenu') {
14019:23): $resulttext .= '<li>'.$lt{$item}.': ';
14020:23): if ($confhash{$itemid}{$item}) {
14021:23): $resulttext .= &mt('Yes');
14022:23): } else {
14023:23): $resulttext .= &mt('No');
1(raebur 14024:1): }
14(raebu 14025:23): $resulttext .= '</li>';
1(raebur 14026:1): }
14(raebu 14027:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14028:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14029:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14030:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14031:23): } else {
14032:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
1(raebur 14033:1): }
14034:1): }
14(raebu 14035:23): if ($confhash{$itemid}{'crsinc'}) {
14036:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14037:23): my $rolemaps;
14038:23): foreach my $role (@ltiroles) {
14039:23): if ($confhash{$itemid}{'maproles'}{$role}) {
14040:23): $rolemaps .= (' 'x2).$role.'='.
14041:23): &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14042:23): 'Course').',';
14043:23): }
14044:23): }
14045:23): if ($rolemaps) {
14046:23): $rolemaps =~ s/,$//;
14047:23): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14048:23): }
14049:23): }
14050:23): if ($confhash{$itemid}{'mapcrs'}) {
14051:23): $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14052:23): }
14053:23): if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14054:23): if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14055:23): $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14056:23): join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14057:23): '</li>';
1(raebur 14058:1): } else {
14(raebu 14059:23): $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
1(raebur 14060:1): }
14061:1): }
14(raebu 14062:23): if ($confhash{$itemid}{'storecrs'}) {
14063:23): $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
1(raebur 14064:1): }
14(raebu 14065:23): if ($confhash{$itemid}{'makecrs'}) {
14066:23): $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
14067:23): } else {
14068:23): $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
14069:23): }
14070:23): if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14071:23): if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14072:23): $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14073:23): join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14074:23): '</li>';
14075:23): } else {
14076:23): $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14077:23): }
14078:23): }
14079:23): if ($confhash{$itemid}{'section'}) {
14080:23): if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14081:23): $resulttext .= '<li>'.&mt('User section from standard field:').
14082:23): ' (course_section_sourcedid)'.'</li>';
14083:23): } else {
14084:23): $resulttext .= '<li>'.&mt('User section from:').' '.
14085:23): $confhash{$itemid}{'section'}.'</li>';
14086:23): }
14087:23): } else {
14088:23): $resulttext .= '<li>'.&mt('No section assignment').'</li>';
14089:23): }
14090:23): foreach my $item ('passback','roster','topmenu','inlinemenu') {
14091:23): $resulttext .= '<li>'.$lt{$item}.': ';
14092:23): if ($confhash{$itemid}{$item}) {
14093:23): $resulttext .= &mt('Yes');
14094:23): if ($item eq 'passback') {
14095:23): if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14096:23): $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14097:23): } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14098:23): $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14099:23): }
14100:23): }
14101:23): } else {
14102:23): $resulttext .= &mt('No');
14103:23): }
14104:23): $resulttext .= '</li>';
14105:23): }
14106:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14107:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14108:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14109:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14110:23): } else {
14111:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14112:23): }
1(raebur 14113:1): }
14114:1): }
14115:1): }
14116:1): $resulttext .= '</ul></li>';
14117:1): }
14118:1): }
14(raebu 14119:23): if (keys(%deletions)) {
14120:23): foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
14121:23): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14122:23): }
14123:23): }
14124:23): }
14125:23): $resulttext .= '</ul>';
14126:23): if (ref($lastactref) eq 'HASH') {
18(raebu 14127:24): if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
14128:24): &Apache::lonnet::get_domain_defaults($dom,1);
14(raebu 14129:23): $lastactref->{'domdefaults'} = 1;
14130:23): }
1(raebur 14131:1): }
14132:1): } else {
14133:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14134:1): }
14135:1): if ($errors) {
14136:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14137:1): $errors.'</ul>';
14138:1): }
14139:1): return $resulttext;
14140:1): }
14141:1):
14(raebu 14142:23): sub get_priv_creds {
14143:23): my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
14144:23): my ($needenc,$cipher,$privnum);
14145:23): my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
14146:23): if (($encchg) && (ref($encrypt) eq 'HASH')) {
14147:23): $needenc = $encrypt->{'consumers'}
14148:23): } else {
14149:23): $needenc = $domdefs{'ltienc_consumers'};
14150:23): }
14151:23): if ($needenc) {
14152:23): if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
14153:23): (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
14154:23): my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
14155:23): my $privkey = $privhash{'key'};
14156:23): $privnum = $privhash{'version'};
14157:23): if (($privnum) && ($privkey ne '')) {
14158:23): $cipher = Crypt::CBC->new({'key' => $privkey,
14159:23): 'cipher' => 'DES'});
1(raebur 14160:1): }
14161:1): }
14162:1): }
14(raebu 14163:23): return ($cipher,$privnum);
1(raebur 14164:1): }
14165:1):
14(raebu 14166:23): sub get_lti_id {
18(raebu 14167:24): my ($domain,$consumer,$dbname) = @_;
14168:24): unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
14169:24): return ('','invalid db');
14170:24): }
14171:24): # get lock on db
1(raebur 14172:1): my $lockhash = {
14173:1): lock => $env{'user.name'}.
14174:1): ':'.$env{'user.domain'},
14175:1): };
14176:1): my $tries = 0;
18(raebu 14177:24): my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14178:1): my ($id,$error);
14179:1):
14180:1): while (($gotlock ne 'ok') && ($tries<10)) {
14181:1): $tries ++;
14182:1): sleep (0.1);
18(raebu 14183:24): $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14184:1): }
14185:1): if ($gotlock eq 'ok') {
18(raebu 14186:24): my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1(raebur 14187:1): if ($currids{'lock'}) {
14188:1): delete($currids{'lock'});
14189:1): if (keys(%currids)) {
14190:1): my @curr = sort { $a <=> $b } keys(%currids);
14191:1): if ($curr[-1] =~ /^\d+$/) {
14192:1): $id = 1 + $curr[-1];
14193:1): }
14194:1): } else {
14195:1): $id = 1;
14196:1): }
14197:1): if ($id) {
18(raebu 14198:24): unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1(raebur 14199:1): $error = 'nostore';
14200:1): }
14201:1): } else {
14202:1): $error = 'nonumber';
14203:1): }
14204:1): }
18(raebu 14205:24): my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1(raebur 14206:1): } else {
14207:1): $error = 'nolock';
14208:1): }
14209:1): return ($id,$error);
14210:1): }
14211:1):
1.3 raeburn 14212: sub modify_autoenroll {
1.160.6.24 raeburn 14213: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14214: my ($resulttext,%changes);
14215: my %currautoenroll;
14216: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14217: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14218: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14219: }
14220: }
14221: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14222: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14223: sender => 'Sender for notification messages',
1.160.6.68 raeburn 14224: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 14225: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14226: my @offon = ('off','on');
1.17 raeburn 14227: my $sender_uname = $env{'form.sender_uname'};
14228: my $sender_domain = $env{'form.sender_domain'};
14229: if ($sender_domain eq '') {
14230: $sender_uname = '';
14231: } elsif ($sender_uname eq '') {
14232: $sender_domain = '';
14233: }
1.129 raeburn 14234: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 14235: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14236: $autofailsafe =~ s{^\s+|\s+$}{}g;
14237: if ($autofailsafe =~ /\D/) {
14238: undef($autofailsafe);
14239: }
1.160.6.68 raeburn 14240: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 14241: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14242: $failsafe = 'off';
14243: undef($autofailsafe);
1.160.6.68 raeburn 14244: }
1.1 raeburn 14245: my %autoenrollhash = (
1.129 raeburn 14246: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14247: 'sender_uname' => $sender_uname,
14248: 'sender_domain' => $sender_domain,
14249: 'co-owners' => $coowners,
1.160.6.116 raeburn 14250: 'autofailsafe' => $autofailsafe,
14251: 'failsafe' => $failsafe,
1.1 raeburn 14252: }
14253: );
1.4 raeburn 14254: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14255: $dom);
1.1 raeburn 14256: if ($putresult eq 'ok') {
14257: if (exists($currautoenroll{'run'})) {
14258: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14259: $changes{'run'} = 1;
14260: }
14261: } elsif ($autorun) {
14262: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14263: $changes{'run'} = 1;
1.1 raeburn 14264: }
14265: }
1.17 raeburn 14266: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14267: $changes{'sender'} = 1;
14268: }
1.17 raeburn 14269: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14270: $changes{'sender'} = 1;
14271: }
1.129 raeburn 14272: if ($currautoenroll{'co-owners'} ne '') {
14273: if ($currautoenroll{'co-owners'} ne $coowners) {
14274: $changes{'coowners'} = 1;
14275: }
14276: } elsif ($coowners) {
14277: $changes{'coowners'} = 1;
1.160.6.68 raeburn 14278: }
1.160.6.116 raeburn 14279: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 14280: $changes{'autofailsafe'} = 1;
14281: }
1.160.6.116 raeburn 14282: if ($currautoenroll{'failsafe'} ne $failsafe) {
14283: $changes{'failsafe'} = 1;
14284: }
1.1 raeburn 14285: if (keys(%changes) > 0) {
14286: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14287: if ($changes{'run'}) {
1.1 raeburn 14288: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14289: }
14290: if ($changes{'sender'}) {
1.17 raeburn 14291: if ($sender_uname eq '' || $sender_domain eq '') {
14292: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14293: } else {
14294: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14295: }
1.1 raeburn 14296: }
1.129 raeburn 14297: if ($changes{'coowners'}) {
14298: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14299: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14300: if (ref($lastactref) eq 'HASH') {
14301: $lastactref->{'domainconfig'} = 1;
14302: }
1.129 raeburn 14303: }
1.160.6.68 raeburn 14304: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 14305: if ($autofailsafe ne '') {
14306: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 14307: } else {
1.160.6.116 raeburn 14308: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 14309: }
1.160.6.116 raeburn 14310: }
14311: if ($changes{'failsafe'}) {
14312: if ($failsafe eq 'off') {
14313: unless ($changes{'autofailsafe'}) {
14314: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14315: }
14316: } elsif ($failsafe eq 'zero') {
14317: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14318: } else {
14319: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14320: }
14321: }
14322: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 14323: &Apache::lonnet::get_domain_defaults($dom,1);
14324: if (ref($lastactref) eq 'HASH') {
14325: $lastactref->{'domdefaults'} = 1;
14326: }
14327: }
1.1 raeburn 14328: $resulttext .= '</ul>';
14329: } else {
14330: $resulttext = &mt('No changes made to auto-enrollment settings');
14331: }
14332: } else {
1.11 albertel 14333: $resulttext = '<span class="LC_error">'.
14334: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14335: }
1.3 raeburn 14336: return $resulttext;
1.1 raeburn 14337: }
14338:
14339: sub modify_autoupdate {
1.3 raeburn 14340: my ($dom,%domconfig) = @_;
1.1 raeburn 14341: my ($resulttext,%currautoupdate,%fields,%changes);
14342: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14343: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14344: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14345: }
14346: }
14347: my @offon = ('off','on');
14348: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 14349: run => 'Auto-update:',
14350: classlists => 'Updates to user information in classlists?',
14351: unexpired => 'Skip updates for users without active or future roles?',
14352: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 14353: );
1.44 raeburn 14354: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14355: my %fieldtitles = &Apache::lonlocal::texthash (
14356: id => 'Student/Employee ID',
1.20 raeburn 14357: permanentemail => 'E-mail address',
1.1 raeburn 14358: lastname => 'Last Name',
14359: firstname => 'First Name',
14360: middlename => 'Middle Name',
1.132 raeburn 14361: generation => 'Generation',
1.1 raeburn 14362: );
1.142 raeburn 14363: $othertitle = &mt('All users');
1.1 raeburn 14364: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14365: $othertitle = &mt('Other users');
1.1 raeburn 14366: }
14367: foreach my $key (keys(%env)) {
14368: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14369: my ($usertype,$item) = ($1,$2);
14370: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14371: if ($usertype eq 'default') {
14372: push(@{$fields{$1}},$2);
14373: } elsif (ref($types) eq 'ARRAY') {
14374: if (grep(/^\Q$usertype\E$/,@{$types})) {
14375: push(@{$fields{$1}},$2);
14376: }
14377: }
14378: }
1.1 raeburn 14379: }
14380: }
1.131 raeburn 14381: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14382: @lockablenames = sort(@lockablenames);
14383: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14384: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14385: if (@changed) {
14386: $changes{'lockablenames'} = 1;
14387: }
14388: } else {
14389: if (@lockablenames) {
14390: $changes{'lockablenames'} = 1;
14391: }
14392: }
1.1 raeburn 14393: my %updatehash = (
14394: autoupdate => { run => $env{'form.autoupdate_run'},
14395: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 14396: unexpired => $env{'form.unexpired'},
1.1 raeburn 14397: fields => {%fields},
1.131 raeburn 14398: lockablenames => \@lockablenames,
1.1 raeburn 14399: }
14400: );
1.160.6.113 raeburn 14401: my $lastactivedays;
14402: if ($env{'form.lastactive'}) {
14403: $lastactivedays = $env{'form.lastactivedays'};
14404: $lastactivedays =~ s/^\s+|\s+$//g;
14405: unless ($lastactivedays =~ /^\d+$/) {
14406: undef($lastactivedays);
14407: $env{'form.lastactive'} = 0;
14408: }
14409: }
14410: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 14411: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 14412: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 14413: if (exists($updatehash{autoupdate}{$key})) {
14414: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14415: $changes{$key} = 1;
14416: }
14417: }
14418: } elsif ($key eq 'fields') {
14419: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14420: foreach my $item (@{$types},'default') {
1.1 raeburn 14421: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14422: my $change = 0;
14423: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14424: if (!exists($fields{$item})) {
14425: $change = 1;
1.132 raeburn 14426: last;
1.1 raeburn 14427: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14428: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14429: $change = 1;
1.132 raeburn 14430: last;
1.1 raeburn 14431: }
14432: }
14433: }
14434: if ($change) {
14435: push(@{$changes{$key}},$item);
14436: }
1.26 raeburn 14437: }
1.1 raeburn 14438: }
14439: }
1.131 raeburn 14440: } elsif ($key eq 'lockablenames') {
14441: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14442: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14443: if (@changed) {
14444: $changes{'lockablenames'} = 1;
14445: }
14446: } else {
14447: if (@lockablenames) {
14448: $changes{'lockablenames'} = 1;
14449: }
14450: }
14451: }
14452: }
14453: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14454: if (@lockablenames) {
14455: $changes{'lockablenames'} = 1;
1.1 raeburn 14456: }
14457: }
1.160.6.113 raeburn 14458: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
14459: if ($updatehash{'autoupdate'}{'unexpired'}) {
14460: $changes{'unexpired'} = 1;
14461: }
14462: }
14463: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
14464: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
14465: $changes{'lastactive'} = 1;
14466: }
14467: }
1.26 raeburn 14468: foreach my $item (@{$types},'default') {
14469: if (defined($fields{$item})) {
14470: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 14471: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14472: my $change = 0;
14473: if (ref($fields{$item}) eq 'ARRAY') {
14474: foreach my $type (@{$fields{$item}}) {
14475: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14476: $change = 1;
14477: last;
14478: }
14479: }
14480: }
14481: if ($change) {
14482: push(@{$changes{'fields'}},$item);
14483: }
14484: } else {
1.26 raeburn 14485: push(@{$changes{'fields'}},$item);
14486: }
14487: } else {
14488: push(@{$changes{'fields'}},$item);
1.1 raeburn 14489: }
14490: }
14491: }
14492: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
14493: $dom);
14494: if ($putresult eq 'ok') {
14495: if (keys(%changes) > 0) {
14496: $resulttext = &mt('Changes made:').'<ul>';
14497: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 14498: if ($key eq 'lockablenames') {
14499: $resulttext .= '<li>';
14500: if (@lockablenames) {
14501: $usertypes->{'default'} = $othertitle;
14502: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
14503: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
14504: } else {
14505: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
14506: }
14507: $resulttext .= '</li>';
14508: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 14509: foreach my $item (@{$changes{$key}}) {
14510: my @newvalues;
14511: foreach my $type (@{$fields{$item}}) {
14512: push(@newvalues,$fieldtitles{$type});
14513: }
1.3 raeburn 14514: my $newvaluestr;
14515: if (@newvalues > 0) {
14516: $newvaluestr = join(', ',@newvalues);
14517: } else {
14518: $newvaluestr = &mt('none');
1.6 raeburn 14519: }
1.1 raeburn 14520: if ($item eq 'default') {
1.26 raeburn 14521: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 14522: } else {
1.26 raeburn 14523: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 14524: }
14525: }
14526: } else {
14527: my $newvalue;
14528: if ($key eq 'run') {
14529: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 14530: } elsif ($key eq 'lastactive') {
14531: $newvalue = $offon[$env{'form.lastactive'}];
14532: unless ($lastactivedays eq '') {
14533: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
14534: }
1.1 raeburn 14535: } else {
14536: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 14537: }
1.1 raeburn 14538: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
14539: }
14540: }
14541: $resulttext .= '</ul>';
14542: } else {
1.3 raeburn 14543: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 14544: }
14545: } else {
1.11 albertel 14546: $resulttext = '<span class="LC_error">'.
14547: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14548: }
1.3 raeburn 14549: return $resulttext;
1.1 raeburn 14550: }
14551:
1.125 raeburn 14552: sub modify_autocreate {
14553: my ($dom,%domconfig) = @_;
14554: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
14555: if (ref($domconfig{'autocreate'}) eq 'HASH') {
14556: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
14557: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
14558: }
14559: }
14560: my %title= ( xml => 'Auto-creation of courses in XML course description files',
14561: req => 'Auto-creation of validated requests for official courses',
14562: xmldc => 'Identity of course creator of courses from XML files',
14563: );
14564: my @types = ('xml','req');
14565: foreach my $item (@types) {
14566: $newvals{$item} = $env{'form.autocreate_'.$item};
14567: $newvals{$item} =~ s/\D//g;
14568: $newvals{$item} = 0 if ($newvals{$item} eq '');
14569: }
14570: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 14571: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 14572: unless (exists($domcoords{$newvals{'xmldc'}})) {
14573: $newvals{'xmldc'} = '';
14574: }
14575: %autocreatehash = (
14576: autocreate => { xml => $newvals{'xml'},
14577: req => $newvals{'req'},
14578: }
14579: );
14580: if ($newvals{'xmldc'} ne '') {
14581: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
14582: }
14583: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
14584: $dom);
14585: if ($putresult eq 'ok') {
14586: my @items = @types;
14587: if ($newvals{'xml'}) {
14588: push(@items,'xmldc');
14589: }
14590: foreach my $item (@items) {
14591: if (exists($currautocreate{$item})) {
14592: if ($currautocreate{$item} ne $newvals{$item}) {
14593: $changes{$item} = 1;
14594: }
14595: } elsif ($newvals{$item}) {
14596: $changes{$item} = 1;
14597: }
14598: }
14599: if (keys(%changes) > 0) {
14600: my @offon = ('off','on');
14601: $resulttext = &mt('Changes made:').'<ul>';
14602: foreach my $item (@types) {
14603: if ($changes{$item}) {
14604: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 14605: $resulttext .= '<li>'.
14606: &mt("$title{$item} set to [_1]$newtxt [_2]",
14607: '<b>','</b>').
14608: '</li>';
1.125 raeburn 14609: }
14610: }
14611: if ($changes{'xmldc'}) {
14612: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
14613: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 14614: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 14615: }
14616: $resulttext .= '</ul>';
14617: } else {
14618: $resulttext = &mt('No changes made to auto-creation settings');
14619: }
14620: } else {
14621: $resulttext = '<span class="LC_error">'.
14622: &mt('An error occurred: [_1]',$putresult).'</span>';
14623: }
14624: return $resulttext;
14625: }
14626:
1.23 raeburn 14627: sub modify_directorysrch {
1.160.6.81 raeburn 14628: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 14629: my ($resulttext,%changes);
14630: my %currdirsrch;
14631: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
14632: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
14633: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
14634: }
14635: }
1.160.6.72 raeburn 14636: my %title = ( available => 'Institutional directory search available',
14637: localonly => 'Other domains can search institution',
14638: lcavailable => 'LON-CAPA directory search available',
14639: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 14640: searchby => 'Search types',
14641: searchtypes => 'Search latitude');
14642: my @offon = ('off','on');
1.24 raeburn 14643: my @otherdoms = ('Yes','No');
1.23 raeburn 14644:
1.25 raeburn 14645: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 14646: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
14647: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
14648:
1.44 raeburn 14649: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 14650: if (keys(%{$usertypes}) == 0) {
14651: @cansearch = ('default');
14652: } else {
14653: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
14654: foreach my $type (@{$currdirsrch{'cansearch'}}) {
14655: if (!grep(/^\Q$type\E$/,@cansearch)) {
14656: push(@{$changes{'cansearch'}},$type);
14657: }
1.23 raeburn 14658: }
1.26 raeburn 14659: foreach my $type (@cansearch) {
14660: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
14661: push(@{$changes{'cansearch'}},$type);
14662: }
1.23 raeburn 14663: }
1.26 raeburn 14664: } else {
14665: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 14666: }
14667: }
14668:
14669: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
14670: foreach my $by (@{$currdirsrch{'searchby'}}) {
14671: if (!grep(/^\Q$by\E$/,@searchby)) {
14672: push(@{$changes{'searchby'}},$by);
14673: }
14674: }
14675: foreach my $by (@searchby) {
14676: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
14677: push(@{$changes{'searchby'}},$by);
14678: }
14679: }
14680: } else {
14681: push(@{$changes{'searchby'}},@searchby);
14682: }
1.25 raeburn 14683:
14684: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
14685: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
14686: if (!grep(/^\Q$type\E$/,@searchtypes)) {
14687: push(@{$changes{'searchtypes'}},$type);
14688: }
14689: }
14690: foreach my $type (@searchtypes) {
14691: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
14692: push(@{$changes{'searchtypes'}},$type);
14693: }
14694: }
14695: } else {
14696: if (exists($currdirsrch{'searchtypes'})) {
14697: foreach my $type (@searchtypes) {
14698: if ($type ne $currdirsrch{'searchtypes'}) {
14699: push(@{$changes{'searchtypes'}},$type);
14700: }
14701: }
14702: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
14703: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
14704: }
14705: } else {
14706: push(@{$changes{'searchtypes'}},@searchtypes);
14707: }
14708: }
14709:
1.23 raeburn 14710: my %dirsrch_hash = (
14711: directorysrch => { available => $env{'form.dirsrch_available'},
14712: cansearch => \@cansearch,
1.160.6.72 raeburn 14713: localonly => $env{'form.dirsrch_instlocalonly'},
14714: lclocalonly => $env{'form.dirsrch_domlocalonly'},
14715: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 14716: searchby => \@searchby,
1.25 raeburn 14717: searchtypes => \@searchtypes,
1.23 raeburn 14718: }
14719: );
14720: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
14721: $dom);
14722: if ($putresult eq 'ok') {
14723: if (exists($currdirsrch{'available'})) {
14724: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
14725: $changes{'available'} = 1;
14726: }
14727: } else {
14728: if ($env{'form.dirsrch_available'} eq '1') {
14729: $changes{'available'} = 1;
14730: }
14731: }
1.160.6.72 raeburn 14732: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 14733: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
14734: $changes{'lcavailable'} = 1;
14735: }
1.24 raeburn 14736: } else {
1.160.6.72 raeburn 14737: if ($env{'form.dirsrch_lcavailable'} eq '1') {
14738: $changes{'lcavailable'} = 1;
14739: }
14740: }
14741: if (exists($currdirsrch{'localonly'})) {
14742: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 14743: $changes{'localonly'} = 1;
14744: }
1.160.6.72 raeburn 14745: } else {
14746: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
14747: $changes{'localonly'} = 1;
14748: }
14749: }
14750: if (exists($currdirsrch{'lclocalonly'})) {
14751: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
14752: $changes{'lclocalonly'} = 1;
14753: }
14754: } else {
14755: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
14756: $changes{'lclocalonly'} = 1;
14757: }
1.24 raeburn 14758: }
1.23 raeburn 14759: if (keys(%changes) > 0) {
14760: $resulttext = &mt('Changes made:').'<ul>';
14761: if ($changes{'available'}) {
14762: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
14763: }
1.160.6.72 raeburn 14764: if ($changes{'lcavailable'}) {
14765: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
14766: }
1.24 raeburn 14767: if ($changes{'localonly'}) {
1.160.6.72 raeburn 14768: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
14769: }
14770: if ($changes{'lclocalonly'}) {
14771: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 14772: }
1.23 raeburn 14773: if (ref($changes{'cansearch'}) eq 'ARRAY') {
14774: my $chgtext;
1.26 raeburn 14775: if (ref($usertypes) eq 'HASH') {
14776: if (keys(%{$usertypes}) > 0) {
14777: foreach my $type (@{$types}) {
14778: if (grep(/^\Q$type\E$/,@cansearch)) {
14779: $chgtext .= $usertypes->{$type}.'; ';
14780: }
14781: }
14782: if (grep(/^default$/,@cansearch)) {
14783: $chgtext .= $othertitle;
14784: } else {
14785: $chgtext =~ s/\; $//;
14786: }
1.160.6.13 raeburn 14787: $resulttext .=
14788: '<li>'.
14789: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
14790: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
14791: '</li>';
1.23 raeburn 14792: }
14793: }
14794: }
14795: if (ref($changes{'searchby'}) eq 'ARRAY') {
14796: my ($searchtitles,$titleorder) = &sorted_searchtitles();
14797: my $chgtext;
14798: foreach my $type (@{$titleorder}) {
14799: if (grep(/^\Q$type\E$/,@searchby)) {
14800: if (defined($searchtitles->{$type})) {
14801: $chgtext .= $searchtitles->{$type}.'; ';
14802: }
14803: }
14804: }
14805: $chgtext =~ s/\; $//;
14806: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
14807: }
1.25 raeburn 14808: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
14809: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
14810: my $chgtext;
14811: foreach my $type (@{$srchtypeorder}) {
14812: if (grep(/^\Q$type\E$/,@searchtypes)) {
14813: if (defined($srchtypes_desc->{$type})) {
14814: $chgtext .= $srchtypes_desc->{$type}.'; ';
14815: }
14816: }
14817: }
14818: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 14819: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 14820: }
14821: $resulttext .= '</ul>';
1.160.6.81 raeburn 14822: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
14823: if (ref($lastactref) eq 'HASH') {
14824: $lastactref->{'directorysrch'} = 1;
14825: }
1.23 raeburn 14826: } else {
1.160.6.72 raeburn 14827: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 14828: }
14829: } else {
14830: $resulttext = '<span class="LC_error">'.
1.27 raeburn 14831: &mt('An error occurred: [_1]',$putresult).'</span>';
14832: }
14833: return $resulttext;
14834: }
14835:
1.28 raeburn 14836: sub modify_contacts {
1.160.6.24 raeburn 14837: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 14838: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
14839: if (ref($domconfig{'contacts'}) eq 'HASH') {
14840: foreach my $key (keys(%{$domconfig{'contacts'}})) {
14841: $currsetting{$key} = $domconfig{'contacts'}{$key};
14842: }
14843: }
1.160.6.78 raeburn 14844: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 14845: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 14846: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 14847: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 14848: my @toggles = ('reporterrors','reportupdates','reportstatus');
14849: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 14850: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 14851: foreach my $type (@mailings) {
14852: @{$newsetting{$type}} =
14853: &Apache::loncommon::get_env_multiple('form.'.$type);
14854: foreach my $item (@contacts) {
14855: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
14856: $contacts_hash{contacts}{$type}{$item} = 1;
14857: } else {
14858: $contacts_hash{contacts}{$type}{$item} = 0;
14859: }
1.160.6.78 raeburn 14860: }
1.28 raeburn 14861: $others{$type} = $env{'form.'.$type.'_others'};
14862: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 14863: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14864: $bcc{$type} = $env{'form.'.$type.'_bcc'};
14865: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 14866: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
14867: $includestr{$type} = $env{'form.'.$type.'_includestr'};
14868: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
14869: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14870: }
1.134 raeburn 14871: }
1.28 raeburn 14872: }
14873: foreach my $item (@contacts) {
14874: $to{$item} = $env{'form.'.$item};
14875: $contacts_hash{'contacts'}{$item} = $to{$item};
14876: }
1.160.6.23 raeburn 14877: foreach my $item (@toggles) {
14878: if ($env{'form.'.$item} =~ /^(0|1)$/) {
14879: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
14880: }
14881: }
1.160.6.107 raeburn 14882: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
14883: foreach my $item (@lonstatus) {
14884: if ($item eq 'excluded') {
14885: my (%serverhomes,@excluded);
14886: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
14887: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
14888: if (@possexcluded) {
14889: foreach my $id (sort(@possexcluded)) {
14890: if ($serverhomes{$id}) {
14891: push(@excluded,$id);
14892: }
14893: }
14894: }
14895: if (@excluded) {
14896: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
14897: }
14898: } elsif ($item eq 'weights') {
14899: foreach my $type ('E','W','N','U') {
14900: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
14901: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
14902: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
14903: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
14904: $env{'form.error'.$item.'_'.$type};
14905: }
14906: }
14907: }
14908: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
14909: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
14910: if ($env{'form.error'.$item} =~ /^\d+$/) {
14911: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
14912: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
14913: }
14914: }
14915: }
14916: }
1.160.6.78 raeburn 14917: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
14918: foreach my $field (@{$fields}) {
14919: if (ref($possoptions->{$field}) eq 'ARRAY') {
14920: my $value = $env{'form.helpform_'.$field};
14921: $value =~ s/^\s+|\s+$//g;
14922: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 14923: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 14924: if ($field eq 'screenshot') {
14925: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
14926: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 14927: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 14928: }
14929: }
14930: }
14931: }
14932: }
14933: }
1.160.6.101 raeburn 14934: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
14935: my (@statuses,%usertypeshash,@overrides);
14936: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
14937: @statuses = @{$types};
14938: if (ref($usertypes) eq 'HASH') {
14939: %usertypeshash = %{$usertypes};
14940: }
14941: }
14942: if (@statuses) {
14943: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
14944: foreach my $type (@possoverrides) {
14945: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
14946: push(@overrides,$type);
14947: }
14948: }
14949: if (@overrides) {
14950: foreach my $type (@overrides) {
14951: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
14952: foreach my $item (@contacts) {
14953: if (grep(/^\Q$item\E$/,@standard)) {
14954: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
14955: $newsetting{'override_'.$type}{$item} = 1;
14956: } else {
14957: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
14958: $newsetting{'override_'.$type}{$item} = 0;
14959: }
14960: }
14961: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
14962: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14963: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
14964: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
14965: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
14966: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
14967: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
14968: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
14969: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
14970: }
1.160.6.118.2 14(raebu 14971:23): }
1.160.6.101 raeburn 14972: }
14973: }
1.28 raeburn 14974: if (keys(%currsetting) > 0) {
14975: foreach my $item (@contacts) {
14976: if ($to{$item} ne $currsetting{$item}) {
14977: $changes{$item} = 1;
14978: }
14979: }
14980: foreach my $type (@mailings) {
14981: foreach my $item (@contacts) {
14982: if (ref($currsetting{$type}) eq 'HASH') {
14983: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
14984: push(@{$changes{$type}},$item);
14985: }
14986: } else {
14987: push(@{$changes{$type}},@{$newsetting{$type}});
14988: }
14989: }
14990: if ($others{$type} ne $currsetting{$type}{'others'}) {
14991: push(@{$changes{$type}},'others');
14992: }
1.160.6.78 raeburn 14993: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 14994: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
14995: push(@{$changes{$type}},'bcc');
14996: }
1.160.6.78 raeburn 14997: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
14998: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
14999: push(@{$changes{$type}},'include');
15000: }
15001: }
15002: }
15003: if (ref($fields) eq 'ARRAY') {
15004: if (ref($currsetting{'helpform'}) eq 'HASH') {
15005: foreach my $field (@{$fields}) {
15006: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15007: push(@{$changes{'helpform'}},$field);
15008: }
15009: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15010: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15011: push(@{$changes{'helpform'}},'maxsize');
15012: }
15013: }
15014: }
15015: } else {
15016: foreach my $field (@{$fields}) {
15017: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15018: push(@{$changes{'helpform'}},$field);
15019: }
15020: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15021: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15022: push(@{$changes{'helpform'}},'maxsize');
15023: }
15024: }
15025: }
1.134 raeburn 15026: }
1.28 raeburn 15027: }
1.160.6.101 raeburn 15028: if (@statuses) {
15029: if (ref($currsetting{'overrides'}) eq 'HASH') {
15030: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15031: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15032: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15033: foreach my $item (@contacts,'bcc','others','include') {
15034: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15035: push(@{$changes{'overrides'}},$key);
15036: last;
15037: }
15038: }
15039: } else {
15040: push(@{$changes{'overrides'}},$key);
15041: }
15042: }
15043: }
15044: foreach my $key (@overrides) {
15045: unless (exists($currsetting{'overrides'}{$key})) {
15046: push(@{$changes{'overrides'}},$key);
15047: }
15048: }
15049: } else {
15050: foreach my $key (@overrides) {
15051: push(@{$changes{'overrides'}},$key);
15052: }
15053: }
15054: }
1.160.6.107 raeburn 15055: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15056: foreach my $key ('excluded','weights','threshold','sysmail') {
15057: if ($key eq 'excluded') {
15058: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15059: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15060: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15061: (@{$currsetting{'lonstatus'}{$key}})) {
15062: my @diffs =
15063: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15064: $currsetting{'lonstatus'}{$key});
15065: if (@diffs) {
15066: push(@{$changes{'lonstatus'}},$key);
15067: }
15068: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15069: push(@{$changes{'lonstatus'}},$key);
15070: }
15071: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15072: (@{$currsetting{'lonstatus'}{$key}})) {
15073: push(@{$changes{'lonstatus'}},$key);
15074: }
15075: } elsif ($key eq 'weights') {
15076: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15077: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15078: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15079: foreach my $type ('E','W','N','U') {
15080: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15081: $currsetting{'lonstatus'}{$key}{$type}) {
15082: push(@{$changes{'lonstatus'}},$key);
15083: last;
15084: }
15085: }
15086: } else {
15087: foreach my $type ('E','W','N','U') {
15088: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15089: push(@{$changes{'lonstatus'}},$key);
15090: last;
15091: }
15092: }
15093: }
15094: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15095: foreach my $type ('E','W','N','U') {
15096: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15097: push(@{$changes{'lonstatus'}},$key);
15098: last;
15099: }
15100: }
15101: }
15102: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15103: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15104: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15105: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15106: push(@{$changes{'lonstatus'}},$key);
15107: }
15108: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15109: push(@{$changes{'lonstatus'}},$key);
15110: }
15111: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15112: push(@{$changes{'lonstatus'}},$key);
15113: }
15114: }
15115: }
15116: } else {
15117: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15118: foreach my $key ('excluded','weights','threshold','sysmail') {
15119: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15120: push(@{$changes{'lonstatus'}},$key);
15121: }
15122: }
15123: }
15124: }
1.28 raeburn 15125: } else {
15126: my %default;
15127: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15128: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15129: $default{'errormail'} = 'adminemail';
15130: $default{'packagesmail'} = 'adminemail';
15131: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 15132: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15133: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15134: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 15135: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 15136: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15137: foreach my $item (@contacts) {
15138: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 15139: $changes{$item} = 1;
1.160.6.23 raeburn 15140: }
1.28 raeburn 15141: }
15142: foreach my $type (@mailings) {
15143: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15144: push(@{$changes{$type}},@{$newsetting{$type}});
15145: }
15146: if ($others{$type} ne '') {
15147: push(@{$changes{$type}},'others');
1.134 raeburn 15148: }
1.160.6.78 raeburn 15149: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15150: if ($bcc{$type} ne '') {
15151: push(@{$changes{$type}},'bcc');
15152: }
1.160.6.78 raeburn 15153: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15154: push(@{$changes{$type}},'include');
15155: }
15156: }
15157: }
15158: if (ref($fields) eq 'ARRAY') {
15159: foreach my $field (@{$fields}) {
15160: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15161: push(@{$changes{'helpform'}},$field);
15162: }
15163: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15164: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15165: push(@{$changes{'helpform'}},'maxsize');
15166: }
15167: }
1.134 raeburn 15168: }
1.28 raeburn 15169: }
1.160.6.107 raeburn 15170: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15171: foreach my $key ('excluded','weights','threshold','sysmail') {
15172: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15173: push(@{$changes{'lonstatus'}},$key);
15174: }
15175: }
15176: }
1.28 raeburn 15177: }
1.160.6.23 raeburn 15178: foreach my $item (@toggles) {
15179: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15180: $changes{$item} = 1;
15181: } elsif ((!$env{'form.'.$item}) &&
15182: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15183: $changes{$item} = 1;
15184: }
15185: }
1.28 raeburn 15186: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15187: $dom);
15188: if ($putresult eq 'ok') {
15189: if (keys(%changes) > 0) {
1.160.6.24 raeburn 15190: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 15191: if (ref($lastactref) eq 'HASH') {
15192: $lastactref->{'domainconfig'} = 1;
15193: }
1.28 raeburn 15194: my ($titles,$short_titles) = &contact_titles();
15195: $resulttext = &mt('Changes made:').'<ul>';
15196: foreach my $item (@contacts) {
15197: if ($changes{$item}) {
15198: $resulttext .= '<li>'.$titles->{$item}.
15199: &mt(' set to: ').
15200: '<span class="LC_cusr_emph">'.
15201: $to{$item}.'</span></li>';
15202: }
15203: }
15204: foreach my $type (@mailings) {
15205: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 15206: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15207: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15208: } else {
15209: $resulttext .= '<li>'.$titles->{$type}.': ';
15210: }
1.28 raeburn 15211: my @text;
15212: foreach my $item (@{$newsetting{$type}}) {
15213: push(@text,$short_titles->{$item});
15214: }
15215: if ($others{$type} ne '') {
15216: push(@text,$others{$type});
15217: }
1.160.6.78 raeburn 15218: if (@text) {
15219: $resulttext .= '<span class="LC_cusr_emph">'.
15220: join(', ',@text).'</span>';
15221: }
15222: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15223: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 15224: my $bcctext;
15225: if (@text) {
15226: $bcctext = ' '.&mt('with Bcc to');
15227: } else {
15228: $bcctext = '(Bcc)';
15229: }
15230: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15231: } elsif (!@text) {
15232: $resulttext .= &mt('No one');
1.134 raeburn 15233: }
1.160.6.78 raeburn 15234: if ($includestr{$type} ne '') {
15235: if ($includeloc{$type} eq 'b') {
15236: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15237: } elsif ($includeloc{$type} eq 's') {
15238: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15239: }
15240: }
15241: } elsif (!@text) {
15242: $resulttext .= &mt('No recipients');
1.134 raeburn 15243: }
15244: $resulttext .= '</li>';
1.28 raeburn 15245: }
15246: }
1.160.6.101 raeburn 15247: if (ref($changes{'overrides'}) eq 'ARRAY') {
15248: my @deletions;
15249: foreach my $type (@{$changes{'overrides'}}) {
15250: if ($usertypeshash{$type}) {
15251: if (grep(/^\Q$type\E/,@overrides)) {
15252: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15253: $usertypeshash{$type}).'<ul><li>';
15254: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15255: my @text;
15256: foreach my $item (@contacts) {
15257: if ($newsetting{'override_'.$type}{$item}) {
15258: push(@text,$short_titles->{$item});
15259: }
15260: }
15261: if ($newsetting{'override_'.$type}{'others'} ne '') {
15262: push(@text,$newsetting{'override_'.$type}{'others'});
15263: }
15264:
15265: if (@text) {
15266: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15267: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15268: }
15269: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15270: my $bcctext;
15271: if (@text) {
15272: $bcctext = ' '.&mt('with Bcc to');
15273: } else {
15274: $bcctext = '(Bcc)';
15275: }
15276: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15277: } elsif (!@text) {
15278: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15279: }
15280: $resulttext .= '</li>';
15281: if ($newsetting{'override_'.$type}{'include'} ne '') {
15282: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15283: if ($loc eq 'b') {
15284: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15285: } elsif ($loc eq 's') {
15286: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15287: }
15288: }
15289: }
15290: $resulttext .= '</li></ul></li>';
15291: } else {
15292: push(@deletions,$usertypeshash{$type});
15293: }
15294: }
15295: }
15296: if (@deletions) {
15297: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15298: join(', ',@deletions)).'</li>';
15299: }
15300: }
1.160.6.23 raeburn 15301: my @offon = ('off','on');
1.160.6.107 raeburn 15302: my $corelink = &core_link_msu();
1.160.6.23 raeburn 15303: if ($changes{'reporterrors'}) {
15304: $resulttext .= '<li>'.
15305: &mt('E-mail error reports to [_1] set to "'.
15306: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 15307: $corelink).
1.160.6.23 raeburn 15308: '</li>';
15309: }
15310: if ($changes{'reportupdates'}) {
15311: $resulttext .= '<li>'.
15312: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15313: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 15314: $corelink).
1.160.6.23 raeburn 15315: '</li>';
15316: }
1.160.6.107 raeburn 15317: if ($changes{'reportstatus'}) {
15318: $resulttext .= '<li>'.
15319: &mt('E-mail status if errors above threshold to [_1] set to "'.
15320: $offon[$env{'form.reportstatus'}].'".',
15321: $corelink).
15322: '</li>';
15323: }
15324: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15325: $resulttext .= '<li>'.
15326: &mt('Nightly status check e-mail settings').':<ul>';
15327: my (%defval,%use_def,%shown);
15328: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15329: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15330: $defval{'weights'} =
15331: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15332: $defval{'excluded'} = &mt('None');
15333: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15334: foreach my $item ('threshold','sysmail','weights','excluded') {
15335: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15336: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15337: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15338: } elsif ($item eq 'weights') {
15339: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15340: foreach my $type ('E','W','N','U') {
15341: $shown{$item} .= $lonstatus_names->{$type}.'=';
15342: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15343: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15344: } else {
15345: $shown{$item} .= $lonstatus_defs->{$type};
15346: }
15347: $shown{$item} .= ', ';
15348: }
15349: $shown{$item} =~ s/, $//;
15350: } else {
15351: $shown{$item} = $defval{$item};
15352: }
15353: } elsif ($item eq 'excluded') {
15354: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15355: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15356: } else {
15357: $shown{$item} = $defval{$item};
15358: }
15359: }
15360: } else {
15361: $shown{$item} = $defval{$item};
15362: }
15363: }
15364: } else {
15365: foreach my $item ('threshold','weights','excluded','sysmail') {
15366: $shown{$item} = $defval{$item};
15367: }
15368: }
15369: foreach my $item ('threshold','weights','excluded','sysmail') {
15370: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15371: $shown{$item}).'</li>';
15372: }
15373: $resulttext .= '</ul></li>';
15374: }
1.160.6.78 raeburn 15375: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15376: my (@optional,@required,@unused,$maxsizechg);
15377: foreach my $field (@{$changes{'helpform'}}) {
15378: if ($field eq 'maxsize') {
15379: $maxsizechg = 1;
15380: next;
15381: }
15382: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15383: push(@optional,$field);
15384: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15385: push(@unused,$field);
15386: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15387: push(@required,$field);
15388: }
15389: }
15390: if (@optional) {
15391: $resulttext .= '<li>'.
15392: &mt('Help form fields changed to "Optional": [_1].',
15393: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15394: '</li>';
15395: }
15396: if (@required) {
15397: $resulttext .= '<li>'.
15398: &mt('Help form fields changed to "Required": [_1].',
15399: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15400: '</li>';
15401: }
15402: if (@unused) {
15403: $resulttext .= '<li>'.
15404: &mt('Help form fields changed to "Not shown": [_1].',
15405: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15406: '</li>';
15407: }
15408: if ($maxsizechg) {
15409: $resulttext .= '<li>'.
15410: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15411: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15412: '</li>';
15413: }
15414: }
1.28 raeburn 15415: $resulttext .= '</ul>';
15416: } else {
1.160.6.78 raeburn 15417: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15418: }
15419: } else {
15420: $resulttext = '<span class="LC_error">'.
1.160.6.118.2 14(raebu 15421:23): &mt('An error occurred: [_1]',$putresult).'</span>';
1.28 raeburn 15422: }
15423: return $resulttext;
15424: }
15425:
1.160.6.98 raeburn 15426: sub modify_passwords {
15427: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15428: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15429: $updatedefaults,$updateconf);
15430: my $customfn = 'resetpw.html';
15431: if (ref($domconfig{'passwords'}) eq 'HASH') {
15432: %current = %{$domconfig{'passwords'}};
15433: }
15434: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15435: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15436: if (ref($types) eq 'ARRAY') {
15437: @oktypes = @{$types};
15438: }
15439: push(@oktypes,'default');
15440:
15441: my %titles = &Apache::lonlocal::texthash (
15442: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15443: intauth_check => 'Check bcrypt cost if authenticated',
15444: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15445: permanent => 'Permanent e-mail address',
15446: critical => 'Critical notification address',
15447: notify => 'Notification address',
15448: min => 'Minimum password length',
15449: max => 'Maximum password length',
15450: chars => 'Required characters',
15451: numsaved => 'Number of previous passwords to save',
15452: reset => 'Resetting Forgotten Password',
15453: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15454: rules => 'Rules for LON-CAPA Passwords',
15455: crsownerchg => 'Course Owner Changing Student Passwords',
15456: username => 'Username',
15457: email => 'E-mail address',
15458: );
15459:
15460: #
15461: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15462: #
15463: my (%curr_defaults,%save_defaults);
15464: if (ref($domconfig{'defaults'}) eq 'HASH') {
15465: foreach my $key (keys(%{$domconfig{'defaults'}})) {
15466: if ($key =~ /^intauth_(cost|check|switch)$/) {
15467: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
15468: } else {
15469: $save_defaults{$key} = $domconfig{'defaults'}{$key};
15470: }
15471: }
15472: }
15473: my %staticdefaults = (
15474: 'resetlink' => 2,
15475: 'resetcase' => \@oktypes,
15476: 'resetprelink' => 'both',
15477: 'resetemail' => ['critical','notify','permanent'],
15478: 'intauth_cost' => 10,
15479: 'intauth_check' => 0,
15480: 'intauth_switch' => 0,
15481: );
1.160.6.99 raeburn 15482: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 15483: foreach my $type (@oktypes) {
15484: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
15485: }
15486: my $linklife = $env{'form.passwords_link'};
15487: $linklife =~ s/^\s+|\s+$//g;
15488: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
15489: $newvalues{'resetlink'} = $linklife;
15490: if ($current{'resetlink'}) {
15491: if ($current{'resetlink'} ne $linklife) {
15492: $changes{'reset'} = 1;
15493: }
1.160.6.102 raeburn 15494: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15495: if ($staticdefaults{'resetlink'} ne $linklife) {
15496: $changes{'reset'} = 1;
15497: }
15498: }
15499: } elsif ($current{'resetlink'}) {
15500: $changes{'reset'} = 1;
15501: }
15502: my @casesens;
15503: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
15504: foreach my $case (sort(@posscase)) {
15505: if (grep(/^\Q$case\E$/,@oktypes)) {
15506: push(@casesens,$case);
15507: }
15508: }
15509: $newvalues{'resetcase'} = \@casesens;
15510: if (ref($current{'resetcase'}) eq 'ARRAY') {
15511: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
15512: if (@diffs > 0) {
15513: $changes{'reset'} = 1;
15514: }
1.160.6.102 raeburn 15515: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15516: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
15517: if (@diffs > 0) {
15518: $changes{'reset'} = 1;
15519: }
15520: }
15521: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
15522: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
15523: if (exists($current{'resetprelink'})) {
15524: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
15525: $changes{'reset'} = 1;
15526: }
1.160.6.102 raeburn 15527: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15528: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
15529: $changes{'reset'} = 1;
15530: }
15531: }
15532: } elsif ($current{'resetprelink'}) {
15533: $changes{'reset'} = 1;
15534: }
15535: foreach my $type (@oktypes) {
15536: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
15537: my @postlink;
15538: foreach my $item (sort(@possplink)) {
15539: if ($item =~ /^(email|username)$/) {
15540: push(@postlink,$item);
15541: }
15542: }
15543: $newvalues{'resetpostlink'}{$type} = \@postlink;
15544: unless ($changes{'reset'}) {
15545: if (ref($current{'resetpostlink'}) eq 'HASH') {
15546: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
15547: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
15548: if (@diffs > 0) {
15549: $changes{'reset'} = 1;
15550: }
15551: } else {
15552: $changes{'reset'} = 1;
15553: }
1.160.6.102 raeburn 15554: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15555: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
15556: if (@diffs > 0) {
15557: $changes{'reset'} = 1;
15558: }
15559: }
15560: }
15561: }
15562: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
15563: my @resetemail;
15564: foreach my $item (sort(@possemailsrc)) {
15565: if ($item =~ /^(permanent|critical|notify)$/) {
15566: push(@resetemail,$item);
15567: }
15568: }
15569: $newvalues{'resetemail'} = \@resetemail;
15570: unless ($changes{'reset'}) {
15571: if (ref($current{'resetemail'}) eq 'ARRAY') {
15572: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
15573: if (@diffs > 0) {
15574: $changes{'reset'} = 1;
15575: }
1.160.6.102 raeburn 15576: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 15577: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
15578: if (@diffs > 0) {
15579: $changes{'reset'} = 1;
15580: }
15581: }
15582: }
15583: if ($env{'form.passwords_stdtext'} == 0) {
15584: $newvalues{'resetremove'} = 1;
15585: unless ($current{'resetremove'}) {
15586: $changes{'reset'} = 1;
15587: }
15588: } elsif ($current{'resetremove'}) {
15589: $changes{'reset'} = 1;
15590: }
15591: if ($env{'form.passwords_customfile.filename'} ne '') {
15592: my $servadm = $r->dir_config('lonAdmEMail');
15593: my ($configuserok,$author_ok,$switchserver) =
15594: &config_check($dom,$confname,$servadm);
15595: my $error;
15596: if ($configuserok eq 'ok') {
15597: if ($switchserver) {
15598: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
15599: } else {
15600: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 15601:23): my $modified = [];
1.160.6.98 raeburn 15602: my ($result,$customurl) =
1.160.6.118.2 14(raebu 15603:23): &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
15604:23): $confname,'customtext/resetpw','','',$customfn,
15605:23): $modified);
1.160.6.98 raeburn 15606: if ($result eq 'ok') {
15607: $newvalues{'resetcustom'} = $customurl;
15608: $changes{'reset'} = 1;
1.160.6.118.2 14(raebu 15609:23): &update_modify_urls($r,$modified);
1.160.6.98 raeburn 15610: } else {
15611: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
15612: }
15613: } else {
15614: $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);
15615: }
15616: }
15617: } else {
15618: $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);
15619: }
15620: if ($error) {
15621: &Apache::lonnet::logthis($error);
15622: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
15623: }
15624: } elsif ($current{'resetcustom'}) {
15625: if ($env{'form.passwords_custom_del'}) {
15626: $changes{'reset'} = 1;
15627: } else {
15628: $newvalues{'resetcustom'} = $current{'resetcustom'};
15629: }
15630: }
15631: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
15632: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
15633: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
15634: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
15635: $changes{'intauth'} = 1;
15636: }
15637: } else {
15638: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
15639: }
15640: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
15641: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
15642: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
15643: $changes{'intauth'} = 1;
15644: }
15645: } else {
15646: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
15647: }
15648: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
15649: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
15650: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
15651: $changes{'intauth'} = 1;
15652: }
15653: } else {
15654: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
15655: }
15656: foreach my $item ('cost','check','switch') {
15657: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
15658: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
15659: $updatedefaults = 1;
15660: }
15661: }
1.160.6.118.2 5(raebur 15662:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 15663: my %crsownerchg = (
15664: by => [],
15665: for => [],
15666: );
15667: foreach my $item ('by','for') {
15668: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
15669: foreach my $type (sort(@posstypes)) {
15670: if (grep(/^\Q$type\E$/,@oktypes)) {
15671: push(@{$crsownerchg{$item}},$type);
15672: }
15673: }
15674: }
15675: $newvalues{'crsownerchg'} = \%crsownerchg;
15676: if (ref($current{'crsownerchg'}) eq 'HASH') {
15677: foreach my $item ('by','for') {
15678: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
15679: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
15680: if (@diffs > 0) {
15681: $changes{'crsownerchg'} = 1;
15682: last;
15683: }
15684: }
15685: }
1.160.6.102 raeburn 15686: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 15687: foreach my $item ('by','for') {
15688: if (@{$crsownerchg{$item}} > 0) {
15689: $changes{'crsownerchg'} = 1;
15690: last;
15691: }
15692: }
15693: }
15694:
15695: my %confighash = (
15696: defaults => \%save_defaults,
15697: passwords => \%newvalues,
15698: );
15699: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
15700:
15701: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
15702: if ($putresult eq 'ok') {
15703: if (keys(%changes) > 0) {
15704: $resulttext = &mt('Changes made: ').'<ul>';
15705: foreach my $key ('reset','intauth','rules','crsownerchg') {
15706: if ($changes{$key}) {
15707: unless ($key eq 'intauth') {
15708: $updateconf = 1;
15709: }
15710: $resulttext .= '<li>'.$titles{$key}.':<ul>';
15711: if ($key eq 'reset') {
15712: if ($confighash{'passwords'}{'captcha'} eq 'original') {
15713: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
15714: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
15715: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 15716: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
15717: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
15718: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
15719: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
15720: }
1.160.6.98 raeburn 15721: } else {
15722: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
15723: }
15724: if ($confighash{'passwords'}{'resetlink'}) {
15725: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
15726: } else {
15727: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
15728: &mt('Will default to 2 hours').'</li>';
15729: }
15730: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
15731: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
15732: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
15733: } else {
15734: my $casesens;
15735: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
15736: if ($type eq 'default') {
15737: $casesens .= $othertitle.', ';
15738: } elsif ($usertypes->{$type} ne '') {
15739: $casesens .= $usertypes->{$type}.', ';
15740: }
15741: }
15742: $casesens =~ s/\Q, \E$//;
15743: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
15744: }
15745: } else {
15746: $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>';
15747: }
15748: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
15749: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
15750: } else {
15751: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
15752: }
15753: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
15754: my $output;
15755: if (ref($types) eq 'ARRAY') {
15756: foreach my $type (@{$types}) {
15757: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
15758: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
15759: $output .= $usertypes->{$type}.' -- '.&mt('none');
15760: } else {
15761: $output .= $usertypes->{$type}.' -- '.
15762: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
15763: }
15764: }
15765: }
15766: }
15767: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
15768: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
15769: $output .= $othertitle.' -- '.&mt('none');
15770: } else {
15771: $output .= $othertitle.' -- '.
15772: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
15773: }
15774: }
15775: if ($output) {
15776: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
15777: } else {
15778: $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>';
15779: }
15780: } else {
15781: $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>';
15782: }
15783: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
15784: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
15785: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
15786: } else {
15787: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
15788: }
15789: } else {
1.160.6.110 raeburn 15790: $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 15791: }
15792: if ($confighash{'passwords'}{'resetremove'}) {
15793: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
15794: } else {
15795: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
15796: }
15797: if ($confighash{'passwords'}{'resetcustom'}) {
15798: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 15799: &mt('custom text'),600,500,undef,undef,
15800: undef,undef,'background-color:#ffffff');
15801: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 15802: } else {
15803: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
15804: }
15805: } elsif ($key eq 'intauth') {
15806: foreach my $item ('cost','switch','check') {
15807: my $value = $save_defaults{$key.'_'.$item};
15808: if ($item eq 'switch') {
15809: my %optiondesc = &Apache::lonlocal::texthash (
15810: 0 => 'No',
15811: 1 => 'Yes',
15812: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
15813: );
15814: if ($value =~ /^(0|1|2)$/) {
15815: $value = $optiondesc{$value};
15816: } else {
15817: $value = &mt('none -- defaults to No');
15818: }
15819: } elsif ($item eq 'check') {
15820: my %optiondesc = &Apache::lonlocal::texthash (
15821: 0 => 'No',
15822: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
15823: 2 => 'Yes, disallow login if stored cost is less than domain default',
15824: );
15825: if ($value =~ /^(0|1|2)$/) {
15826: $value = $optiondesc{$value};
15827: } else {
15828: $value = &mt('none -- defaults to No');
15829: }
15830: }
15831: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
15832: }
15833: } elsif ($key eq 'rules') {
15834: foreach my $rule ('min','max','numsaved') {
15835: if ($confighash{'passwords'}{$rule} eq '') {
15836: if ($rule eq 'min') {
15837: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 15838: ' '.&mt('Default of [_1] will be used',
15839: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 15840: } else {
15841: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
15842: }
15843: } else {
15844: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
15845: }
15846: }
1.160.6.104 raeburn 15847: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
15848: if (@{$confighash{'passwords'}{'chars'}} > 0) {
15849: my %rulenames = &Apache::lonlocal::texthash(
15850: uc => 'At least one upper case letter',
15851: lc => 'At least one lower case letter',
15852: num => 'At least one number',
15853: spec => 'At least one non-alphanumeric',
15854: );
15855: my $needed = '<ul><li>'.
15856: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
15857: '</li></ul>';
15858: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
15859: } else {
15860: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
15861: }
15862: } else {
15863: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
15864: }
1.160.6.98 raeburn 15865: } elsif ($key eq 'crsownerchg') {
15866: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
15867: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
15868: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
15869: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15870: } else {
15871: my %crsownerstr;
15872: foreach my $item ('by','for') {
15873: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
15874: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
15875: if ($type eq 'default') {
15876: $crsownerstr{$item} .= $othertitle.', ';
15877: } elsif ($usertypes->{$type} ne '') {
15878: $crsownerstr{$item} .= $usertypes->{$type}.', ';
15879: }
15880: }
15881: $crsownerstr{$item} =~ s/\Q, \E$//;
15882: }
15883: }
15884: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
15885: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
15886: }
15887: } else {
15888: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
15889: }
15890: }
15891: $resulttext .= '</ul></li>';
15892: }
15893: }
15894: $resulttext .= '</ul>';
15895: } else {
15896: $resulttext = &mt('No changes made to password settings');
15897: }
15898: my $cachetime = 24*60*60;
15899: if ($updatedefaults) {
15900: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
15901: if (ref($lastactref) eq 'HASH') {
15902: $lastactref->{'domdefaults'} = 1;
15903: }
15904: }
15905: if ($updateconf) {
15906: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
15907: if (ref($lastactref) eq 'HASH') {
15908: $lastactref->{'passwdconf'} = 1;
15909: }
15910: }
15911: } else {
15912: $resulttext = '<span class="LC_error">'.
15913: &mt('An error occurred: [_1]',$putresult).'</span>';
15914: }
15915: if ($errors) {
15916: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
15917: $errors.'</ul></p>';
15918: }
15919: return $resulttext;
15920: }
15921:
1.160.6.118.2 5(raebur 15922:2): sub password_rule_changes {
15923:2): my ($prefix,$newvalues,$current,$changes) = @_;
15924:2): return unless ((ref($newvalues) eq 'HASH') &&
15925:2): (ref($current) eq 'HASH') &&
15926:2): (ref($changes) eq 'HASH'));
15927:2): my (@rules,%staticdefaults);
15928:2): if ($prefix eq 'passwords') {
15929:2): @rules = ('min','max','numsaved');
14(raebu 15930:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 15931:2): @rules = ('min','max');
15932:2): }
15933:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
15934:2): foreach my $rule (@rules) {
15935:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
15936:2): my $ruleok;
15937:2): if ($rule eq 'min') {
15938:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
15939:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
15940:2): $ruleok = 1;
15941:2): }
15942:2): }
15943:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
15944:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
15945:2): $ruleok = 1;
15946:2): }
15947:2): if ($ruleok) {
15948:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
15949:2): if (exists($current->{$rule})) {
15950:2): if ($newvalues->{$rule} ne $current->{$rule}) {
15951:2): $changes->{'rules'} = 1;
15952:2): }
15953:2): } elsif ($rule eq 'min') {
15954:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
15955:2): $changes->{'rules'} = 1;
15956:2): }
15957:2): } else {
15958:2): $changes->{'rules'} = 1;
15959:2): }
15960:2): } elsif (exists($current->{$rule})) {
15961:2): $changes->{'rules'} = 1;
15962:2): }
15963:2): }
15964:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
15965:2): my @chars;
15966:2): foreach my $item (sort(@posschars)) {
15967:2): if ($item =~ /^(uc|lc|num|spec)$/) {
15968:2): push(@chars,$item);
15969:2): }
15970:2): }
15971:2): $newvalues->{'chars'} = \@chars;
15972:2): unless ($changes->{'rules'}) {
15973:2): if (ref($current->{'chars'}) eq 'ARRAY') {
15974:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
15975:2): if (@diffs > 0) {
15976:2): $changes->{'rules'} = 1;
15977:2): }
15978:2): } else {
15979:2): if (@chars > 0) {
15980:2): $changes->{'rules'} = 1;
15981:2): }
15982:2): }
15983:2): }
15984:2): return;
15985:2): }
15986:2):
1.28 raeburn 15987: sub modify_usercreation {
1.27 raeburn 15988: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 15989: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 15990: my $warningmsg;
1.27 raeburn 15991: if (ref($domconfig{'usercreation'}) eq 'HASH') {
15992: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 15993: if ($key eq 'cancreate') {
15994: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
15995: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 15996: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 15997: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 15998: } else {
15999: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 16000: }
1.50 raeburn 16001: }
1.43 raeburn 16002: }
1.160.6.34 raeburn 16003: } elsif ($key eq 'email_rule') {
16004: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16005: } else {
16006: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 16007: }
16008: }
1.34 raeburn 16009: }
1.160.6.34 raeburn 16010: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
16011: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
16012: my @contexts = ('author','course','requestcrs');
16013: foreach my $item(@contexts) {
16014: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16015: }
1.34 raeburn 16016: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16017: foreach my $item (@contexts) {
1.160.6.34 raeburn 16018: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16019: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16020: }
1.27 raeburn 16021: }
1.34 raeburn 16022: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16023: foreach my $item (@contexts) {
1.43 raeburn 16024: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16025: if ($cancreate{$item} ne 'any') {
16026: push(@{$changes{'cancreate'}},$item);
16027: }
16028: } else {
16029: if ($cancreate{$item} ne 'none') {
16030: push(@{$changes{'cancreate'}},$item);
16031: }
1.27 raeburn 16032: }
16033: }
16034: } else {
1.43 raeburn 16035: foreach my $item (@contexts) {
1.34 raeburn 16036: push(@{$changes{'cancreate'}},$item);
16037: }
1.27 raeburn 16038: }
1.34 raeburn 16039:
1.27 raeburn 16040: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16041: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16042: if (!grep(/^\Q$type\E$/,@username_rule)) {
16043: push(@{$changes{'username_rule'}},$type);
16044: }
16045: }
16046: foreach my $type (@username_rule) {
16047: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16048: push(@{$changes{'username_rule'}},$type);
16049: }
16050: }
16051: } else {
16052: push(@{$changes{'username_rule'}},@username_rule);
16053: }
16054:
1.32 raeburn 16055: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16056: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16057: if (!grep(/^\Q$type\E$/,@id_rule)) {
16058: push(@{$changes{'id_rule'}},$type);
16059: }
16060: }
16061: foreach my $type (@id_rule) {
16062: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16063: push(@{$changes{'id_rule'}},$type);
16064: }
16065: }
16066: } else {
16067: push(@{$changes{'id_rule'}},@id_rule);
16068: }
16069:
1.43 raeburn 16070: my @authen_contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 16071:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16072: my %authhash;
1.43 raeburn 16073: foreach my $item (@authen_contexts) {
1.28 raeburn 16074: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16075: foreach my $auth (@authtypes) {
16076: if (grep(/^\Q$auth\E$/,@authallowed)) {
16077: $authhash{$item}{$auth} = 1;
16078: } else {
16079: $authhash{$item}{$auth} = 0;
16080: }
16081: }
16082: }
16083: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16084: foreach my $item (@authen_contexts) {
1.28 raeburn 16085: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16086: foreach my $auth (@authtypes) {
16087: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16088: push(@{$changes{'authtypes'}},$item);
16089: last;
16090: }
16091: }
16092: }
16093: }
16094: } else {
1.43 raeburn 16095: foreach my $item (@authen_contexts) {
1.28 raeburn 16096: push(@{$changes{'authtypes'}},$item);
16097: }
16098: }
16099:
1.160.6.34 raeburn 16100: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16101: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16102: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16103: $save_usercreate{'id_rule'} = \@id_rule;
16104: $save_usercreate{'username_rule'} = \@username_rule,
16105: $save_usercreate{'authtypes'} = \%authhash;
16106:
1.27 raeburn 16107: my %usercreation_hash = (
1.160.6.34 raeburn 16108: usercreation => \%save_usercreate,
16109: );
1.27 raeburn 16110:
16111: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16112: $dom);
1.50 raeburn 16113:
1.160.6.34 raeburn 16114: if ($putresult eq 'ok') {
16115: if (keys(%changes) > 0) {
16116: $resulttext = &mt('Changes made:').'<ul>';
16117: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16118: my %lt = &usercreation_types();
16119: foreach my $type (@{$changes{'cancreate'}}) {
16120: my $chgtext = $lt{$type}.', ';
16121: if ($cancreate{$type} eq 'none') {
16122: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16123: } elsif ($cancreate{$type} eq 'any') {
16124: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16125: } elsif ($cancreate{$type} eq 'official') {
16126: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16127: } elsif ($cancreate{$type} eq 'unofficial') {
16128: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16129: }
16130: $resulttext .= '<li>'.$chgtext.'</li>';
16131: }
16132: }
16133: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16134: my ($rules,$ruleorder) =
16135: &Apache::lonnet::inst_userrules($dom,'username');
16136: my $chgtext = '<ul>';
16137: foreach my $type (@username_rule) {
16138: if (ref($rules->{$type}) eq 'HASH') {
16139: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16140: }
16141: }
16142: $chgtext .= '</ul>';
16143: if (@username_rule > 0) {
16144: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16145: } else {
16146: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16147: }
16148: }
16149: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16150: my ($idrules,$idruleorder) =
16151: &Apache::lonnet::inst_userrules($dom,'id');
16152: my $chgtext = '<ul>';
16153: foreach my $type (@id_rule) {
16154: if (ref($idrules->{$type}) eq 'HASH') {
16155: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16156: }
16157: }
16158: $chgtext .= '</ul>';
16159: if (@id_rule > 0) {
16160: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16161: } else {
16162: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16163: }
16164: }
16165: my %authname = &authtype_names();
16166: my %context_title = &context_names();
16167: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16168: my $chgtext = '<ul>';
16169: foreach my $type (@{$changes{'authtypes'}}) {
16170: my @allowed;
16171: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16172: foreach my $auth (@authtypes) {
16173: if ($authhash{$type}{$auth}) {
16174: push(@allowed,$authname{$auth});
16175: }
16176: }
16177: if (@allowed > 0) {
16178: $chgtext .= join(', ',@allowed).'</li>';
16179: } else {
16180: $chgtext .= &mt('none').'</li>';
16181: }
16182: }
16183: $chgtext .= '</ul>';
16184: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16185: $resulttext .= '</li>';
16186: }
16187: $resulttext .= '</ul>';
16188: } else {
16189: $resulttext = &mt('No changes made to user creation settings');
16190: }
16191: } else {
16192: $resulttext = '<span class="LC_error">'.
16193: &mt('An error occurred: [_1]',$putresult).'</span>';
16194: }
16195: if ($warningmsg ne '') {
16196: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16197: }
16198: return $resulttext;
16199: }
16200:
16201: sub modify_selfcreation {
1.160.6.93 raeburn 16202: my ($dom,$lastactref,%domconfig) = @_;
16203: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16204: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16205: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16206: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16207: if (ref($typesref) eq 'ARRAY') {
16208: @types = @{$typesref};
16209: }
16210: if (ref($usertypesref) eq 'HASH') {
16211: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 16212: }
1.160.6.93 raeburn 16213: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 16214: #
16215: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16216: #
16217: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16218: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16219: if ($key eq 'cancreate') {
16220: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16221: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16222: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 16223: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16224: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16225: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16226: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16227: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 16228: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16229: } else {
16230: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16231: }
16232: }
16233: }
16234: } elsif ($key eq 'email_rule') {
16235: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16236: } else {
16237: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16238: }
16239: }
16240: }
16241: #
16242: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16243: #
16244: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16245: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16246: if ($key eq 'selfcreate') {
16247: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16248: } else {
16249: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16250: }
16251: }
16252: }
1.160.6.93 raeburn 16253: #
16254: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16255: #
16256: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16257: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16258: if ($key eq 'inststatusguest') {
16259: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16260: } else {
16261: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16262: }
16263: }
16264: }
1.160.6.34 raeburn 16265:
16266: my @contexts = ('selfcreate');
16267: @{$cancreate{'selfcreate'}} = ();
16268: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 16269: if (@types) {
16270: @{$cancreate{'statustocreate'}} = ();
16271: }
1.160.6.40 raeburn 16272: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 16273: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 16274: %{$cancreate{'emailverified'}} = ();
16275: %{$cancreate{'emailoptions'}} = ();
16276: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16277: my %selfcreatetypes = (
16278: sso => 'users authenticated by institutional single sign on',
16279: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 16280: email => 'users verified by e-mail',
1.50 raeburn 16281: );
1.160.6.34 raeburn 16282: #
16283: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16284: # is permitted.
16285: #
1.160.6.93 raeburn 16286: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 16287:
1.160.6.93 raeburn 16288: my (@statuses,%email_rule);
1.160.6.35 raeburn 16289: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 16290: if ($item eq 'email') {
1.160.6.40 raeburn 16291: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 16292: if (@types) {
16293: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16294: foreach my $status (@poss_statuses) {
16295: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16296: push(@statuses,$status);
16297: }
16298: }
16299: $save_inststatus{'inststatusguest'} = \@statuses;
16300: } else {
16301: push(@statuses,'default');
16302: }
16303: if (@statuses) {
16304: my %curr_rule;
16305: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16306: foreach my $type (@statuses) {
16307: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16308: }
16309: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16310: foreach my $type (@statuses) {
16311: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16312: }
16313: }
16314: push(@{$cancreate{'selfcreate'}},'email');
16315: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16316: my %curremaildom;
16317: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16318: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16319: }
16320: foreach my $type (@statuses) {
16321: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16322: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16323: }
16324: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16325: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16326: }
16327: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16328: #
16329: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16330: #
16331: my $chosen = $1;
16332: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16333: my $emaildom;
16334: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16335: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16336: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16337: if (ref($curremaildom{$type}) eq 'HASH') {
16338: if (exists($curremaildom{$type}{$chosen})) {
16339: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16340: push(@{$changes{'cancreate'}},'emaildomain');
16341: }
16342: } elsif ($emaildom ne '') {
16343: push(@{$changes{'cancreate'}},'emaildomain');
16344: }
16345: } elsif ($emaildom ne '') {
16346: push(@{$changes{'cancreate'}},'emaildomain');
16347: }
16348: }
16349: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16350: } elsif ($chosen eq 'custom') {
16351: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16352: $email_rule{$type} = [];
16353: if (ref($emailrules) eq 'HASH') {
16354: foreach my $rule (@possemail_rules) {
16355: if (exists($emailrules->{$rule})) {
16356: push(@{$email_rule{$type}},$rule);
16357: }
16358: }
16359: }
16360: if (@{$email_rule{$type}}) {
16361: $cancreate{'emailoptions'}{$type} = 'custom';
16362: if (ref($curr_rule{$type}) eq 'ARRAY') {
16363: if (@{$curr_rule{$type}} > 0) {
16364: foreach my $rule (@{$curr_rule{$type}}) {
16365: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16366: push(@{$changes{'email_rule'}},$type);
16367: }
16368: }
16369: }
16370: foreach my $type (@{$email_rule{$type}}) {
16371: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16372: push(@{$changes{'email_rule'}},$type);
16373: }
16374: }
16375: } else {
16376: push(@{$changes{'email_rule'}},$type);
16377: }
16378: }
16379: } else {
16380: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16381: }
16382: }
16383: }
16384: if (@types) {
16385: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16386: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16387: if (@changed) {
16388: push(@{$changes{'inststatus'}},'inststatusguest');
16389: }
16390: } else {
16391: push(@{$changes{'inststatus'}},'inststatusguest');
16392: }
16393: }
16394: } else {
16395: delete($env{'form.cancreate_email'});
16396: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16397: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16398: push(@{$changes{'inststatus'}},'inststatusguest');
16399: }
16400: }
16401: }
16402: } else {
16403: $save_inststatus{'inststatusguest'} = [];
16404: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16405: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16406: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 16407: }
16408: }
1.160.6.34 raeburn 16409: }
16410: } else {
16411: if ($env{'form.cancreate_'.$item}) {
16412: push(@{$cancreate{'selfcreate'}},$item);
16413: }
16414: }
16415: }
1.160.6.93 raeburn 16416: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 16417: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16418: #
1.160.6.35 raeburn 16419: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16420: # 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 16421: #
1.160.6.40 raeburn 16422:
1.160.6.48 raeburn 16423: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 16424: push(@contexts,'emailusername');
1.160.6.93 raeburn 16425: if (@statuses) {
16426: foreach my $type (@statuses) {
1.160.6.35 raeburn 16427: if (ref($infofields) eq 'ARRAY') {
16428: foreach my $field (@{$infofields}) {
16429: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16430: $cancreate{'emailusername'}{$type}{$field} = $1;
16431: }
16432: }
1.160.6.34 raeburn 16433: }
16434: }
16435: }
16436: #
16437: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 16438: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 16439: #
16440:
16441: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16442: @approvalnotify = sort(@approvalnotify);
16443: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16444: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16445: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16446: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16447: push(@{$changes{'cancreate'}},'notify');
16448: }
16449: } else {
16450: if ($cancreate{'notify'}{'approval'}) {
16451: push(@{$changes{'cancreate'}},'notify');
16452: }
16453: }
16454: } elsif ($cancreate{'notify'}{'approval'}) {
16455: push(@{$changes{'cancreate'}},'notify');
16456: }
16457:
16458: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16459: }
16460: #
1.160.6.40 raeburn 16461: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 16462: # institutional log-in.
16463: #
16464: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16465: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16466: ($domdefaults{'auth_def'} eq 'localauth'))) {
16467: $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.').' '.
16468: &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.');
16469: }
16470: }
16471: my @fields = ('lastname','firstname','middlename','generation',
16472: 'permanentemail','id');
1.160.6.44 raeburn 16473: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 16474: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16475: #
16476: # Where usernames may created for institutional log-in and/or institutional single sign on:
16477: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16478: # may self-create accounts
16479: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
16480: # which the user may supply, if institutional data is unavailable.
16481: #
16482: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 16483: if (@types) {
16484: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
16485: push(@contexts,'statustocreate');
16486: foreach my $type (@types) {
1.160.6.34 raeburn 16487: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
16488: foreach my $field (@fields) {
16489: if (grep(/^\Q$field\E$/,@modifiable)) {
16490: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
16491: } else {
16492: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
16493: }
16494: }
16495: }
16496: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 16497: foreach my $type (@types) {
1.160.6.34 raeburn 16498: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
16499: foreach my $field (@fields) {
16500: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
16501: $curr_usermodify{'selfcreate'}{$type}{$field}) {
16502: push(@{$changes{'selfcreate'}},$type);
16503: last;
16504: }
16505: }
16506: }
16507: }
16508: } else {
1.160.6.93 raeburn 16509: foreach my $type (@types) {
1.160.6.34 raeburn 16510: push(@{$changes{'selfcreate'}},$type);
16511: }
16512: }
16513: }
1.160.6.44 raeburn 16514: foreach my $field (@shibfields) {
16515: if ($env{'form.shibenv_'.$field} ne '') {
16516: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
16517: }
16518: }
16519: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16520: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
16521: foreach my $field (@shibfields) {
16522: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
16523: push(@{$changes{'cancreate'}},'shibenv');
16524: }
16525: }
16526: } else {
16527: foreach my $field (@shibfields) {
16528: if ($env{'form.shibenv_'.$field}) {
16529: push(@{$changes{'cancreate'}},'shibenv');
16530: last;
16531: }
16532: }
16533: }
16534: }
1.160.6.34 raeburn 16535: }
16536: foreach my $item (@contexts) {
16537: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
16538: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
16539: if (ref($cancreate{$item}) eq 'ARRAY') {
16540: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
16541: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16542: push(@{$changes{'cancreate'}},$item);
16543: }
16544: }
16545: }
16546: }
16547: if (ref($cancreate{$item}) eq 'ARRAY') {
16548: foreach my $type (@{$cancreate{$item}}) {
16549: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
16550: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16551: push(@{$changes{'cancreate'}},$item);
16552: }
16553: }
16554: }
16555: }
16556: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
16557: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 16558: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
16559: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
16560: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
16561: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 16562: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16563: push(@{$changes{'cancreate'}},$item);
16564: }
16565: }
16566: }
1.160.6.93 raeburn 16567: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16568: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 16569: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16570: push(@{$changes{'cancreate'}},$item);
16571: }
1.160.6.34 raeburn 16572: }
16573: }
16574: }
1.160.6.93 raeburn 16575: foreach my $type (keys(%{$cancreate{$item}})) {
16576: if (ref($cancreate{$item}{$type}) eq 'HASH') {
16577: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
16578: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
16579: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 16580: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16581: push(@{$changes{'cancreate'}},$item);
16582: }
16583: }
16584: } else {
16585: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16586: push(@{$changes{'cancreate'}},$item);
16587: }
16588: }
16589: }
1.160.6.93 raeburn 16590: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16591: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 16592: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16593: push(@{$changes{'cancreate'}},$item);
16594: }
1.160.6.34 raeburn 16595: }
16596: }
16597: }
16598: }
16599: } elsif ($curr_usercreation{'cancreate'}{$item}) {
16600: if (ref($cancreate{$item}) eq 'ARRAY') {
16601: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
16602: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16603: push(@{$changes{'cancreate'}},$item);
16604: }
16605: }
1.160.6.93 raeburn 16606: }
16607: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
16608: if (ref($cancreate{$item}) eq 'HASH') {
16609: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16610: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 16611: }
16612: }
16613: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 16614: if (ref($cancreate{$item}) eq 'HASH') {
16615: foreach my $type (keys(%{$cancreate{$item}})) {
16616: if (ref($cancreate{$item}{$type}) eq 'HASH') {
16617: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
16618: if ($cancreate{$item}{$type}{$field}) {
16619: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
16620: push(@{$changes{'cancreate'}},$item);
16621: }
16622: last;
16623: }
16624: }
16625: }
16626: }
1.160.6.34 raeburn 16627: }
16628: }
16629: }
16630: #
16631: # Populate %save_usercreate hash with updates to self-creation configuration.
16632: #
16633: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
16634: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 16635: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 16636: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
16637: if (ref($cancreate{'notify'}) eq 'HASH') {
16638: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
16639: }
1.160.6.40 raeburn 16640: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
16641: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
16642: }
1.160.6.93 raeburn 16643: if (ref($cancreate{'emailverified'}) eq 'HASH') {
16644: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
16645: }
16646: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
16647: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
16648: }
16649: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
16650: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
16651: }
1.160.6.34 raeburn 16652: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
16653: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
16654: }
1.160.6.44 raeburn 16655: if (ref($cancreate{'shibenv'}) eq 'HASH') {
16656: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
16657: }
1.160.6.34 raeburn 16658: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 16659: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 16660:
16661: my %userconfig_hash = (
16662: usercreation => \%save_usercreate,
16663: usermodification => \%save_usermodify,
1.160.6.93 raeburn 16664: inststatus => \%save_inststatus,
1.160.6.34 raeburn 16665: );
1.160.6.93 raeburn 16666:
1.160.6.34 raeburn 16667: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
16668: $dom);
16669: #
1.160.6.93 raeburn 16670: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 16671: #
1.27 raeburn 16672: if ($putresult eq 'ok') {
16673: if (keys(%changes) > 0) {
16674: $resulttext = &mt('Changes made:').'<ul>';
16675: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 16676: my %lt = &selfcreation_types();
1.34 raeburn 16677: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 16678: my $chgtext = '';
1.45 raeburn 16679: if ($type eq 'selfcreate') {
1.50 raeburn 16680: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 16681: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 16682: } else {
1.160.6.34 raeburn 16683: $chgtext .= &mt('Self-creation of a new account is permitted for:').
16684: '<ul>';
1.50 raeburn 16685: foreach my $case (@{$cancreate{$type}}) {
16686: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
16687: }
16688: $chgtext .= '</ul>';
1.100 raeburn 16689: if (ref($cancreate{$type}) eq 'ARRAY') {
16690: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
16691: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
16692: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 16693: $chgtext .= '<span class="LC_warning">'.
16694: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
16695: '</span><br />';
1.100 raeburn 16696: }
16697: }
16698: }
1.160.6.93 raeburn 16699: if (grep(/^email$/,@{$cancreate{$type}})) {
16700: if (!@statuses) {
16701: $chgtext .= '<span class="LC_warning">'.
16702: &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.").
16703: '</span><br />';
16704:
16705: }
16706: }
1.100 raeburn 16707: }
1.43 raeburn 16708: }
1.160.6.44 raeburn 16709: } elsif ($type eq 'shibenv') {
16710: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 16711: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 16712: } else {
16713: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
16714: '<ul>';
16715: foreach my $field (@shibfields) {
16716: next if ($cancreate{$type}{$field} eq '');
16717: if ($field eq 'inststatus') {
16718: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
16719: } else {
16720: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
16721: }
16722: }
16723: $chgtext .= '</ul>';
1.160.6.93 raeburn 16724: }
1.93 raeburn 16725: } elsif ($type eq 'statustocreate') {
1.96 raeburn 16726: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
16727: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
16728: if (@{$cancreate{'selfcreate'}} > 0) {
16729: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 16730: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 16731: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 16732: $chgtext .= '<br />'.
16733: '<span class="LC_warning">'.
16734: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
16735: '</span>';
16736: }
1.160.6.93 raeburn 16737: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 16738: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 16739: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
16740: } else {
16741: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
16742: }
16743: $chgtext .= '<ul>';
16744: foreach my $case (@{$cancreate{$type}}) {
16745: if ($case eq 'default') {
16746: $chgtext .= '<li>'.$othertitle.'</li>';
16747: } else {
1.160.6.93 raeburn 16748: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 16749: }
16750: }
1.100 raeburn 16751: $chgtext .= '</ul>';
16752: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 16753: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 16754: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
16755: '</span>';
1.100 raeburn 16756: }
16757: }
16758: } else {
16759: if (@{$cancreate{$type}} == 0) {
16760: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
16761: } else {
16762: $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 16763: }
16764: }
1.160.6.93 raeburn 16765: $chgtext .= '<br />';
1.93 raeburn 16766: }
1.160.6.40 raeburn 16767: } elsif ($type eq 'selfcreateprocessing') {
16768: my %choices = &Apache::lonlocal::texthash (
16769: automatic => 'Automatic approval',
16770: approval => 'Queued for approval',
16771: );
1.160.6.93 raeburn 16772: if (@types) {
16773: if (@statuses) {
16774: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
16775: '<ul>';
16776: foreach my $status (@statuses) {
16777: if ($status eq 'default') {
16778: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
16779: } else {
16780: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
16781: }
16782: }
16783: $chgtext .= '</ul>';
16784: }
16785: } else {
16786: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
16787: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
16788: }
16789: } elsif ($type eq 'emailverified') {
16790: my %options = &Apache::lonlocal::texthash (
16791: all => 'Same as e-mail',
16792: first => 'Omit @domain',
16793: free => 'Free to choose',
16794: );
16795: if (@types) {
16796: if (@statuses) {
16797: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
16798: '<ul>';
16799: foreach my $status (@statuses) {
16800: if ($status eq 'default') {
16801: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
16802: } else {
16803: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
16804: }
16805: }
16806: $chgtext .= '</ul>';
16807: }
1.160.6.40 raeburn 16808: } else {
1.160.6.93 raeburn 16809: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
16810: $options{$cancreate{'emailverified'}{'default'}});
16811: }
16812: } elsif ($type eq 'emailoptions') {
16813: my %options = &Apache::lonlocal::texthash (
16814: any => 'Any e-mail',
16815: inst => 'Institutional only',
16816: noninst => 'Non-institutional only',
16817: custom => 'Custom restrictions',
16818: );
16819: if (@types) {
16820: if (@statuses) {
16821: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
16822: '<ul>';
16823: foreach my $status (@statuses) {
16824: if ($type eq 'default') {
16825: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
16826: } else {
16827: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
16828: }
16829: }
16830: $chgtext .= '</ul>';
16831: }
16832: } else {
16833: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
16834: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
16835: } else {
16836: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
16837: $options{$cancreate{'emailoptions'}{'default'}});
16838: }
16839: }
16840: } elsif ($type eq 'emaildomain') {
16841: my $output;
16842: if (@statuses) {
16843: foreach my $type (@statuses) {
16844: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
16845: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
16846: if ($type eq 'default') {
16847: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16848: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
16849: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
16850: } else {
16851: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
16852: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
16853: }
16854: } else {
16855: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16856: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
16857: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
16858: } else {
16859: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
16860: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
16861: }
16862: }
16863: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
16864: if ($type eq 'default') {
16865: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16866: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
16867: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
16868: } else {
16869: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
16870: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
16871: }
16872: } else {
16873: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
16874: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
16875: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
16876: } else {
16877: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
16878: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
16879: }
16880: }
16881: }
16882: }
16883: }
16884: }
16885: if ($output ne '') {
16886: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
16887: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 16888: }
1.160.6.5 raeburn 16889: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 16890: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 16891: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
16892: } else {
16893: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 16894: if ($captchas{$savecaptcha{$type}}) {
16895: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 16896: } else {
16897: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
16898: }
16899: }
16900: } elsif ($type eq 'recaptchakeys') {
16901: my ($privkey,$pubkey);
1.160.6.34 raeburn 16902: if (ref($savecaptcha{$type}) eq 'HASH') {
16903: $pubkey = $savecaptcha{$type}{'public'};
16904: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 16905: }
16906: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
16907: if (!$pubkey) {
16908: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
16909: } else {
16910: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
16911: }
16912: if (!$privkey) {
16913: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
16914: } else {
16915: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
16916: }
16917: $chgtext .= '</ul>';
1.160.6.69 raeburn 16918: } elsif ($type eq 'recaptchaversion') {
16919: if ($savecaptcha{'captcha'} eq 'recaptcha') {
16920: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
16921: }
1.160.6.34 raeburn 16922: } elsif ($type eq 'emailusername') {
16923: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 16924: if (@statuses) {
16925: foreach my $type (@statuses) {
1.160.6.35 raeburn 16926: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
16927: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 16928: $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 16929: '<ul>';
16930: foreach my $field (@{$infofields}) {
16931: if ($cancreate{'emailusername'}{$type}{$field}) {
16932: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
16933: }
16934: }
1.160.6.50 raeburn 16935: $chgtext .= '</ul>';
16936: } else {
1.160.6.93 raeburn 16937: $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 16938: }
16939: } else {
1.160.6.93 raeburn 16940: $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 16941: }
16942: }
16943: }
16944: }
16945: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 16946: my $numapprove = 0;
1.160.6.34 raeburn 16947: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16948: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
16949: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 16950: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
16951: $numapprove ++;
1.160.6.34 raeburn 16952: }
16953: }
1.43 raeburn 16954: }
1.160.6.93 raeburn 16955: unless ($numapprove) {
16956: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
16957: }
1.34 raeburn 16958: }
1.160.6.34 raeburn 16959: if ($chgtext) {
16960: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 16961: }
16962: }
16963: }
1.160.6.93 raeburn 16964: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 16965: my ($emailrules,$emailruleorder) =
16966: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 16967: foreach my $type (@{$changes{'email_rule'}}) {
16968: if (ref($email_rule{$type}) eq 'ARRAY') {
16969: my $chgtext = '<ul>';
16970: foreach my $rule (@{$email_rule{$type}}) {
16971: if (ref($emailrules->{$rule}) eq 'HASH') {
16972: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
16973: }
16974: }
16975: $chgtext .= '</ul>';
16976: my $typename;
16977: if (@types) {
16978: if ($type eq 'default') {
16979: $typename = $othertitle;
16980: } else {
16981: $typename = $usertypes{$type};
16982: }
16983: $chgtext .= &mt('(Affiliation: [_1])',$typename);
16984: }
16985: if (@{$email_rule{$type}} > 0) {
16986: $resulttext .= '<li>'.
16987: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
16988: $usertypes{$type}).
16989: $chgtext.
16990: '</li>';
16991: } else {
16992: $resulttext .= '<li>'.
16993: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
16994: '</li>'.
16995: &mt('(Affiliation: [_1])',$typename);
16996: }
1.43 raeburn 16997: }
16998: }
1.160.6.93 raeburn 16999: }
17000: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17001: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17002: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17003: my $chgtext = '<ul>';
17004: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17005: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17006: }
17007: $chgtext .= '</ul>';
17008: $resulttext .= '<li>'.
17009: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17010: $chgtext.
17011: '</li>';
17012: } else {
17013: $resulttext .= '<li>'.
17014: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17015: '</li>';
17016: }
1.43 raeburn 17017: }
17018: }
1.160.6.34 raeburn 17019: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17020: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17021: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17022: foreach my $type (@{$changes{'selfcreate'}}) {
17023: my $typename = $type;
1.160.6.93 raeburn 17024: if (keys(%usertypes) > 0) {
17025: if ($usertypes{$type} ne '') {
17026: $typename = $usertypes{$type};
1.28 raeburn 17027: }
17028: }
1.160.6.34 raeburn 17029: my @modifiable;
17030: $resulttext .= '<li>'.
17031: &mt('Self-creation of account by users with status: [_1]',
17032: '<span class="LC_cusr_emph">'.$typename.'</span>').
17033: ' - '.&mt('modifiable fields (if institutional data blank): ');
17034: foreach my $field (@fields) {
17035: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17036: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
17037: }
17038: }
17039: if (@modifiable > 0) {
17040: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17041: } else {
1.160.6.34 raeburn 17042: $resulttext .= &mt('none');
1.43 raeburn 17043: }
1.160.6.34 raeburn 17044: $resulttext .= '</li>';
1.28 raeburn 17045: }
1.160.6.34 raeburn 17046: $resulttext .= '</ul></li>';
1.28 raeburn 17047: }
1.27 raeburn 17048: $resulttext .= '</ul>';
1.160.6.93 raeburn 17049: my $cachetime = 24*60*60;
17050: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17051: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17052: if (ref($lastactref) eq 'HASH') {
17053: $lastactref->{'domdefaults'} = 1;
17054: }
1.27 raeburn 17055: } else {
1.160.6.34 raeburn 17056: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17057: }
17058: } else {
17059: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17060: &mt('An error occurred: [_1]',$putresult).'</span>';
17061: }
1.43 raeburn 17062: if ($warningmsg ne '') {
17063: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17064: }
1.23 raeburn 17065: return $resulttext;
17066: }
17067:
1.160.6.5 raeburn 17068: sub process_captcha {
1.160.6.104 raeburn 17069: my ($container,$changes,$newsettings,$currsettings) = @_;
17070: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 17071: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17072: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17073: $newsettings->{'captcha'} = 'original';
17074: }
1.160.6.104 raeburn 17075: my %current;
17076: if (ref($currsettings) eq 'HASH') {
17077: %current = %{$currsettings};
17078: }
17079: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 17080: if ($container eq 'cancreate') {
17081: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17082: push(@{$changes->{'cancreate'}},'captcha');
17083: } elsif (!defined($changes->{'cancreate'})) {
17084: $changes->{'cancreate'} = ['captcha'];
17085: }
1.160.6.102 raeburn 17086: } elsif ($container eq 'passwords') {
17087: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17088: } else {
17089: $changes->{'captcha'} = 1;
17090: }
17091: }
1.160.6.69 raeburn 17092: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 17093: if ($newsettings->{'captcha'} eq 'recaptcha') {
17094: $newpub = $env{'form.'.$container.'_recaptchapub'};
17095: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 17096: $newpub =~ s/[^\w\-]//g;
17097: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 17098: $newsettings->{'recaptchakeys'} = {
17099: public => $newpub,
17100: private => $newpriv,
17101: };
1.160.6.69 raeburn 17102: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17103: $newversion =~ s/\D//g;
17104: if ($newversion ne '2') {
17105: $newversion = 1;
17106: }
17107: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 17108: }
1.160.6.104 raeburn 17109: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17110: $currpub = $current{'recaptchakeys'}{'public'};
17111: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 17112: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17113: $newsettings->{'recaptchakeys'} = {
17114: public => '',
17115: private => '',
17116: }
17117: }
1.160.6.5 raeburn 17118: }
1.160.6.104 raeburn 17119: if ($current{'captcha'} eq 'recaptcha') {
17120: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 17121: if ($currversion ne '2') {
17122: $currversion = 1;
17123: }
17124: }
17125: if ($currversion ne $newversion) {
17126: if ($container eq 'cancreate') {
17127: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17128: push(@{$changes->{'cancreate'}},'recaptchaversion');
17129: } elsif (!defined($changes->{'cancreate'})) {
17130: $changes->{'cancreate'} = ['recaptchaversion'];
17131: }
1.160.6.102 raeburn 17132: } elsif ($container eq 'passwords') {
17133: $changes->{'reset'} = 1;
1.160.6.69 raeburn 17134: } else {
17135: $changes->{'recaptchaversion'} = 1;
17136: }
17137: }
1.160.6.5 raeburn 17138: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
17139: if ($container eq 'cancreate') {
17140: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17141: push(@{$changes->{'cancreate'}},'recaptchakeys');
17142: } elsif (!defined($changes->{'cancreate'})) {
17143: $changes->{'cancreate'} = ['recaptchakeys'];
17144: }
1.160.6.102 raeburn 17145: } elsif ($container eq 'passwords') {
17146: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17147: } else {
17148: $changes->{'recaptchakeys'} = 1;
17149: }
17150: }
17151: return;
17152: }
17153:
1.33 raeburn 17154: sub modify_usermodification {
17155: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 17156: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17157: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17158: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 17159: if ($key eq 'selfcreate') {
17160: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17161: } else {
17162: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17163: }
1.33 raeburn 17164: }
17165: }
1.160.6.34 raeburn 17166: my @contexts = ('author','course');
1.33 raeburn 17167: my %context_title = (
17168: author => 'In author context',
17169: course => 'In course context',
17170: );
17171: my @fields = ('lastname','firstname','middlename','generation',
17172: 'permanentemail','id');
17173: my %roles = (
17174: author => ['ca','aa'],
17175: course => ['st','ep','ta','in','cr'],
17176: );
17177: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17178: foreach my $context (@contexts) {
17179: foreach my $role (@{$roles{$context}}) {
17180: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17181: foreach my $item (@fields) {
17182: if (grep(/^\Q$item\E$/,@modifiable)) {
17183: $modifyhash{$context}{$role}{$item} = 1;
17184: } else {
17185: $modifyhash{$context}{$role}{$item} = 0;
17186: }
17187: }
17188: }
17189: if (ref($curr_usermodification{$context}) eq 'HASH') {
17190: foreach my $role (@{$roles{$context}}) {
17191: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17192: foreach my $field (@fields) {
17193: if ($modifyhash{$context}{$role}{$field} ne
17194: $curr_usermodification{$context}{$role}{$field}) {
17195: push(@{$changes{$context}},$role);
17196: last;
17197: }
17198: }
17199: }
17200: }
17201: } else {
17202: foreach my $context (@contexts) {
17203: foreach my $role (@{$roles{$context}}) {
17204: push(@{$changes{$context}},$role);
17205: }
17206: }
17207: }
17208: }
17209: my %usermodification_hash = (
17210: usermodification => \%modifyhash,
17211: );
17212: my $putresult = &Apache::lonnet::put_dom('configuration',
17213: \%usermodification_hash,$dom);
17214: if ($putresult eq 'ok') {
17215: if (keys(%changes) > 0) {
17216: $resulttext = &mt('Changes made: ').'<ul>';
17217: foreach my $context (@contexts) {
17218: if (ref($changes{$context}) eq 'ARRAY') {
17219: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17220: if (ref($changes{$context}) eq 'ARRAY') {
17221: foreach my $role (@{$changes{$context}}) {
17222: my $rolename;
1.160.6.34 raeburn 17223: if ($role eq 'cr') {
17224: $rolename = &mt('Custom');
1.33 raeburn 17225: } else {
1.160.6.34 raeburn 17226: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17227: }
17228: my @modifiable;
1.160.6.34 raeburn 17229: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17230: foreach my $field (@fields) {
17231: if ($modifyhash{$context}{$role}{$field}) {
17232: push(@modifiable,$fieldtitles{$field});
17233: }
17234: }
17235: if (@modifiable > 0) {
17236: $resulttext .= join(', ',@modifiable);
17237: } else {
17238: $resulttext .= &mt('none');
17239: }
17240: $resulttext .= '</li>';
17241: }
17242: $resulttext .= '</ul></li>';
17243: }
17244: }
17245: }
17246: $resulttext .= '</ul>';
17247: } else {
17248: $resulttext = &mt('No changes made to user modification settings');
17249: }
17250: } else {
17251: $resulttext = '<span class="LC_error">'.
17252: &mt('An error occurred: [_1]',$putresult).'</span>';
17253: }
17254: return $resulttext;
17255: }
17256:
1.43 raeburn 17257: sub modify_defaults {
1.160.6.27 raeburn 17258: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17259: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 17260: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 17261: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 17262: 'portal_def');
1.160.6.118.2 14(raebu 17263:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17264: foreach my $item (@items) {
17265: $newvalues{$item} = $env{'form.'.$item};
17266: if ($item eq 'auth_def') {
17267: if ($newvalues{$item} ne '') {
17268: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17269: push(@errors,$item);
17270: }
17271: }
17272: } elsif ($item eq 'lang_def') {
17273: if ($newvalues{$item} ne '') {
17274: if ($newvalues{$item} =~ /^(\w+)/) {
17275: my $langcode = $1;
1.103 raeburn 17276: if ($langcode ne 'x_chef') {
17277: if (code2language($langcode) eq '') {
17278: push(@errors,$item);
17279: }
1.43 raeburn 17280: }
17281: } else {
17282: push(@errors,$item);
17283: }
17284: }
1.54 raeburn 17285: } elsif ($item eq 'timezone_def') {
17286: if ($newvalues{$item} ne '') {
1.62 raeburn 17287: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17288: push(@errors,$item);
17289: }
17290: }
1.68 raeburn 17291: } elsif ($item eq 'datelocale_def') {
17292: if ($newvalues{$item} ne '') {
17293: my @datelocale_ids = DateTime::Locale->ids();
17294: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17295: push(@errors,$item);
17296: }
17297: }
1.141 raeburn 17298: } elsif ($item eq 'portal_def') {
17299: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 17300: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])\/?$/) {
17301:23): foreach my $field ('email','web') {
17302:23): if ($env{'form.'.$item.'_'.$field}) {
17303:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17304:23): }
17305:23): }
17306:23): } else {
1.141 raeburn 17307: push(@errors,$item);
17308: }
17309: }
1.43 raeburn 17310: }
17311: if (grep(/^\Q$item\E$/,@errors)) {
17312: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 17313:23): if ($item eq 'portal_def') {
17314:23): if ($domdefaults{$item}) {
17315:23): foreach my $field ('email','web') {
17316:23): if (exists($domdefaults{$item.'_'.$field})) {
17317:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17318:23): }
17319:23): }
17320:23): }
17321:23): }
1.43 raeburn 17322: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17323: $changes{$item} = 1;
17324: }
1.160.6.118.2 12(raebu 17325:23): if ($item eq 'portal_def') {
17326:23): unless (grep(/^\Q$item\E$/,@errors)) {
17327:23): if ($newvalues{$item} eq '') {
17328:23): foreach my $field ('email','web') {
17329:23): if (exists($domdefaults{$item.'_'.$field})) {
17330:23): delete($domdefaults{$item.'_'.$field});
17331:23): }
17332:23): }
17333:23): } else {
17334:23): unless ($changes{$item}) {
17335:23): foreach my $field ('email','web') {
17336:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17337:23): $changes{$item} = 1;
17338:23): last;
17339:23): }
17340:23): }
17341:23): }
17342:23): foreach my $field ('email','web') {
17343:23): if ($newvalues{$item.'_'.$field}) {
17344:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17345:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
17346:23): delete($domdefaults{$item.'_'.$field});
17347:23): }
17348:23): }
17349:23): }
17350:23): }
17351:23): }
1.72 raeburn 17352: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17353: }
1.160.6.98 raeburn 17354: my %staticdefaults = (
17355: 'intauth_cost' => 10,
17356: 'intauth_check' => 0,
17357: 'intauth_switch' => 0,
17358: );
17359: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17360: if (exists($domdefaults{$item})) {
17361: $newvalues{$item} = $domdefaults{$item};
17362: } else {
17363: $newvalues{$item} = $staticdefaults{$item};
17364: }
17365: }
1.160.6.118.2 8(raebur 17366:2): my ($unamemaprules,$ruleorder);
17367:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17368:2): if (@possunamemaprules) {
17369:2): ($unamemaprules,$ruleorder) =
17370:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
17371:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17372:2): if (@{$ruleorder} > 0) {
17373:2): my %possrules;
17374:2): map { $possrules{$_} = 1; } @possunamemaprules;
17375:2): foreach my $rule (@{$ruleorder}) {
17376:2): if ($possrules{$rule}) {
17377:2): push(@{$newvalues{'unamemap_rule'}},$rule);
17378:2): }
17379:2): }
17380:2): }
17381:2): }
17382:2): }
17383:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17384:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17385:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17386:2): $newvalues{'unamemap_rule'});
17387:2): if (@rulediffs) {
17388:2): $changes{'unamemap_rule'} = 1;
17389:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17390:2): }
17391:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17392:2): $changes{'unamemap_rule'} = 1;
17393:2): delete($domdefaults{'unamemap_rule'});
17394:2): }
17395:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17396:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
17397:2): $changes{'unamemap_rule'} = 1;
17398:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17399:2): }
17400:2): }
1.43 raeburn 17401: my %defaults_hash = (
1.72 raeburn 17402: defaults => \%newvalues,
17403: );
1.43 raeburn 17404: my $title = &defaults_titles();
1.160.6.40 raeburn 17405:
17406: my $currinststatus;
17407: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17408: $currinststatus = $domconfig{'inststatus'};
17409: } else {
17410: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17411: $currinststatus = {
17412: inststatustypes => $usertypes,
17413: inststatusorder => $types,
17414: inststatusguest => [],
17415: };
17416: }
17417: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17418: my @allpos;
17419: my %alltypes;
1.160.6.93 raeburn 17420: my @inststatusguest;
17421: if (ref($currinststatus) eq 'HASH') {
17422: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17423: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17424: unless (grep(/^\Q$type\E$/,@todelete)) {
17425: push(@inststatusguest,$type);
17426: }
17427: }
17428: }
17429: }
17430: my ($currtitles,$currorder);
1.160.6.40 raeburn 17431: if (ref($currinststatus) eq 'HASH') {
17432: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17433: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17434: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17435: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17436: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17437: }
17438: }
17439: unless (grep(/^\Q$type\E$/,@todelete)) {
17440: my $position = $env{'form.inststatus_pos_'.$type};
17441: $position =~ s/\D+//g;
17442: $allpos[$position] = $type;
17443: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17444: $alltypes{$type} =~ s/`//g;
17445: }
17446: }
17447: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17448: $currtitles =~ s/,$//;
17449: }
17450: }
17451: if ($env{'form.addinststatus'}) {
17452: my $newtype = $env{'form.addinststatus'};
17453: $newtype =~ s/\W//g;
17454: unless (exists($alltypes{$newtype})) {
17455: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17456: $alltypes{$newtype} =~ s/`//g;
17457: my $position = $env{'form.addinststatus_pos'};
17458: $position =~ s/\D+//g;
17459: if ($position ne '') {
17460: $allpos[$position] = $newtype;
17461: }
17462: }
17463: }
1.160.6.93 raeburn 17464: my @orderedstatus;
1.160.6.40 raeburn 17465: foreach my $type (@allpos) {
17466: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17467: push(@orderedstatus,$type);
17468: }
17469: }
17470: foreach my $type (keys(%alltypes)) {
17471: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17472: delete($alltypes{$type});
17473: }
17474: }
17475: $defaults_hash{'inststatus'} = {
17476: inststatustypes => \%alltypes,
17477: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 17478: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 17479: };
17480: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
17481: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
17482: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
17483: }
17484: }
17485: if ($currorder ne join(',',@orderedstatus)) {
17486: $changes{'inststatus'}{'inststatusorder'} = 1;
17487: }
17488: my $newtitles;
17489: foreach my $item (@orderedstatus) {
17490: $newtitles .= $alltypes{$item}.',';
17491: }
17492: $newtitles =~ s/,$//;
17493: if ($currtitles ne $newtitles) {
17494: $changes{'inststatus'}{'inststatustypes'} = 1;
17495: }
1.43 raeburn 17496: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
17497: $dom);
17498: if ($putresult eq 'ok') {
17499: if (keys(%changes) > 0) {
17500: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 17501: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 17502: 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";
17503: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 17504: if ($item eq 'inststatus') {
17505: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 17506: if (@orderedstatus) {
1.160.6.40 raeburn 17507: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
17508: foreach my $type (@orderedstatus) {
17509: $resulttext .= $alltypes{$type}.', ';
17510: }
17511: $resulttext =~ s/, $//;
17512: $resulttext .= '</li>';
1.160.6.93 raeburn 17513: } else {
17514: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 17515: }
17516: }
1.160.6.118.2 8(raebur 17517:2): } elsif ($item eq 'unamemap_rule') {
17518:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17519:2): my @rulenames;
17520:2): if (ref($unamemaprules) eq 'HASH') {
17521:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
17522:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
17523:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
17524:2): }
17525:2): }
17526:2): }
17527:2): if (@rulenames) {
17528:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
17529:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
17530:2): '</li>';
17531:2): } else {
14(raebu 17532:23): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
17533:23): }
8(raebur 17534:2): } else {
17535:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
17536:2): }
1.160.6.40 raeburn 17537: } else {
17538: my $value = $env{'form.'.$item};
17539: if ($value eq '') {
17540: $value = &mt('none');
17541: } elsif ($item eq 'auth_def') {
17542: my %authnames = &authtype_names();
17543: my %shortauth = (
17544: internal => 'int',
17545: krb4 => 'krb4',
17546: krb5 => 'krb5',
17547: localauth => 'loc',
1.160.6.118.2 14(raebu 17548:23): lti => 'lti',
1.160.6.40 raeburn 17549: );
17550: $value = $authnames{$shortauth{$value}};
17551: }
17552: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 17553:23): $mailmsgtext .= "$title->{$item} set to $value\n";
17554:23): if ($item eq 'portal_def') {
17555:23): if ($env{'form.'.$item} ne '') {
17556:23): foreach my $field ('email','web') {
17557:23): $value = $env{'form.'.$item.'_'.$field};
17558:23): if ($value) {
17559:23): $value = &mt('Yes');
17560:23): } else {
17561:23): $value = &mt('No');
17562:23): }
17563:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
17564:23): }
17565:23): }
17566:23): }
1.43 raeburn 17567: }
17568: }
17569: $resulttext .= '</ul>';
17570: $mailmsgtext .= "\n";
17571: my $cachetime = 24*60*60;
1.72 raeburn 17572: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 17573: if (ref($lastactref) eq 'HASH') {
17574: $lastactref->{'domdefaults'} = 1;
17575: }
1.68 raeburn 17576: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 17577: my $notify = 1;
17578: if (ref($domconfig{'contacts'}) eq 'HASH') {
17579: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
17580: $notify = 0;
17581: }
17582: }
17583: if ($notify) {
17584: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
17585: "LON-CAPA Domain Settings Change - $dom",
17586: $mailmsgtext);
17587: }
1.54 raeburn 17588: }
1.43 raeburn 17589: } else {
1.54 raeburn 17590: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 17591: }
17592: } else {
17593: $resulttext = '<span class="LC_error">'.
17594: &mt('An error occurred: [_1]',$putresult).'</span>';
17595: }
17596: if (@errors > 0) {
17597: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
17598: foreach my $item (@errors) {
17599: $resulttext .= ' "'.$title->{$item}.'",';
17600: }
17601: $resulttext =~ s/,$//;
17602: }
17603: return $resulttext;
17604: }
17605:
1.46 raeburn 17606: sub modify_scantron {
1.160.6.24 raeburn 17607: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 17608: my ($resulttext,%confhash,%changes,$errors);
17609: my $custom = 'custom.tab';
17610: my $default = 'default.tab';
17611: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 17612: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 17613: &config_check($dom,$confname,$servadm);
17614: if ($env{'form.scantronformat.filename'} ne '') {
17615: my $error;
17616: if ($configuserok eq 'ok') {
17617: if ($switchserver) {
1.130 raeburn 17618: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 17619: } else {
17620: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 17621:23): my $modified = [];
1.46 raeburn 17622: my ($result,$scantronurl) =
1.160.6.118.2 14(raebu 17623:23): &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
17624:23): $confname,'scantron','','',$custom,
17625:23): $modified);
1.46 raeburn 17626: if ($result eq 'ok') {
17627: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 17628: $changes{'scantronformat'} = 1;
1.160.6.118.2 14(raebu 17629:23): &update_modify_urls($r,$modified);
1.46 raeburn 17630: } else {
17631: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
17632: }
17633: } else {
17634: $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);
17635: }
17636: }
17637: } else {
17638: $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);
17639: }
17640: if ($error) {
17641: &Apache::lonnet::logthis($error);
17642: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
17643: }
17644: }
1.48 raeburn 17645: if (ref($domconfig{'scantron'}) eq 'HASH') {
17646: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
17647: if ($env{'form.scantronformat_del'}) {
17648: $confhash{'scantron'}{'scantronformat'} = '';
17649: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 17650: } else {
17651: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
17652: }
17653: }
17654: }
17655: my @options = ('hdr','pad','rem');
17656: my @fields = &scantroncsv_fields();
17657: my %titles = &scantronconfig_titles();
17658: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
17659: my ($newdat,$currdat,%newcol,%currcol);
17660: if (grep(/^dat$/,@formats)) {
17661: $confhash{'scantron'}{config}{dat} = 1;
17662: $newdat = 1;
17663: } else {
17664: $newdat = 0;
17665: }
17666: if (grep(/^csv$/,@formats)) {
17667: my %bynum;
17668: foreach my $field (@fields) {
17669: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
17670: my $posscol = $1;
17671: if (($posscol < 20) && (!$bynum{$posscol})) {
17672: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
17673: $bynum{$posscol} = $field;
17674: $newcol{$field} = $posscol;
17675: }
17676: }
17677: }
17678: if (keys(%newcol)) {
17679: foreach my $option (@options) {
17680: if ($env{'form.scantroncsv_'.$option}) {
17681: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
17682: }
17683: }
17684: }
17685: }
17686: $currdat = 1;
17687: if (ref($domconfig{'scantron'}) eq 'HASH') {
17688: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
17689: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
17690: $currdat = 0;
17691: }
17692: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
17693: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
17694: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
17695: }
17696: }
17697: }
17698: }
17699: if ($currdat != $newdat) {
17700: $changes{'config'} = 1;
17701: } else {
17702: foreach my $field (@fields) {
17703: if ($currcol{$field} ne '') {
17704: if ($currcol{$field} ne $newcol{$field}) {
17705: $changes{'config'} = 1;
17706: last;
17707: }
17708: } elsif ($newcol{$field} ne '') {
17709: $changes{'config'} = 1;
17710: last;
1.46 raeburn 17711: }
17712: }
17713: }
17714: if (keys(%confhash) > 0) {
17715: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
17716: $dom);
17717: if ($putresult eq 'ok') {
17718: if (keys(%changes) > 0) {
1.48 raeburn 17719: if (ref($confhash{'scantron'}) eq 'HASH') {
17720: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 17721: if ($changes{'scantronformat'}) {
17722: if ($confhash{'scantron'}{'scantronformat'} eq '') {
17723: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
17724: } else {
17725: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
17726: }
17727: }
17728: if ($changes{'config'}) {
17729: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
17730: if ($confhash{'scantron'}{'config'}{'dat'}) {
17731: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
17732: }
17733: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
17734: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
17735: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
17736: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
17737: foreach my $field (@fields) {
17738: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
17739: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
17740: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
17741: }
17742: }
17743: $resulttext .= '</ul></li>';
17744: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
17745: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
17746: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
17747: foreach my $option (@options) {
17748: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
17749: $resulttext .= '<li>'.$titles{$option}.'</li>';
17750: }
17751: }
17752: $resulttext .= '</ul></li>';
17753: }
17754: }
17755: }
17756: }
17757: }
17758: } else {
17759: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
17760: }
1.46 raeburn 17761: }
1.48 raeburn 17762: $resulttext .= '</ul>';
17763: } else {
1.130 raeburn 17764: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 17765: }
17766: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 17767: if (ref($lastactref) eq 'HASH') {
17768: $lastactref->{'domainconfig'} = 1;
17769: }
1.46 raeburn 17770: } else {
1.160.6.97 raeburn 17771: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 17772: }
17773: } else {
17774: $resulttext = '<span class="LC_error">'.
17775: &mt('An error occurred: [_1]',$putresult).'</span>';
17776: }
17777: } else {
1.160.6.97 raeburn 17778: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 17779: }
17780: if ($errors) {
1.160.6.118.2 14(raebu 17781:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
17782:23): $errors.'</ul></p>';
1.46 raeburn 17783: }
17784: return $resulttext;
17785: }
17786:
1.48 raeburn 17787: sub modify_coursecategories {
1.160.6.43 raeburn 17788: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 17789: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
17790: $cathash);
1.48 raeburn 17791: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 17792: my @catitems = ('unauth','auth');
17793: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 17794: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 17795: $cathash = $domconfig{'coursecategories'}{'cats'};
17796: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
17797: $changes{'togglecats'} = 1;
17798: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
17799: }
17800: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
17801: $changes{'categorize'} = 1;
17802: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
17803: }
1.120 raeburn 17804: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
17805: $changes{'togglecatscomm'} = 1;
17806: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
17807: }
17808: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
17809: $changes{'categorizecomm'} = 1;
17810: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
17811: }
1.160.6.42 raeburn 17812: foreach my $item (@catitems) {
17813: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
17814: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
17815: $changes{$item} = 1;
17816: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
17817: }
17818: }
17819: }
1.57 raeburn 17820: } else {
17821: $changes{'togglecats'} = 1;
17822: $changes{'categorize'} = 1;
1.124 raeburn 17823: $changes{'togglecatscomm'} = 1;
17824: $changes{'categorizecomm'} = 1;
1.87 raeburn 17825: $domconfig{'coursecategories'} = {
17826: togglecats => $env{'form.togglecats'},
17827: categorize => $env{'form.categorize'},
1.124 raeburn 17828: togglecatscomm => $env{'form.togglecatscomm'},
17829: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 17830: };
1.160.6.42 raeburn 17831: foreach my $item (@catitems) {
17832: if ($env{'form.coursecat_'.$item} ne 'std') {
17833: $changes{$item} = 1;
17834: }
17835: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
17836: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
17837: }
17838: }
1.57 raeburn 17839: }
17840: if (ref($cathash) eq 'HASH') {
17841: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 17842: push (@deletecategory,'instcode::0');
17843: }
1.120 raeburn 17844: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
17845: push(@deletecategory,'communities::0');
17846: }
1.48 raeburn 17847: }
1.57 raeburn 17848: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
17849: if (ref($cathash) eq 'HASH') {
1.48 raeburn 17850: if (@deletecategory > 0) {
17851: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 17852: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 17853: foreach my $item (@deletecategory) {
1.57 raeburn 17854: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
17855: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 17856: $deletions{$item} = 1;
1.57 raeburn 17857: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 17858: }
17859: }
17860: }
1.57 raeburn 17861: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 17862: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 17863: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 17864: $reorderings{$item} = 1;
1.57 raeburn 17865: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 17866: }
17867: if ($env{'form.addcategory_name_'.$item} ne '') {
17868: my $newcat = $env{'form.addcategory_name_'.$item};
17869: my $newdepth = $depth+1;
17870: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 17871: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 17872: $adds{$newitem} = 1;
17873: }
17874: if ($env{'form.subcat_'.$item} ne '') {
17875: my $newcat = $env{'form.subcat_'.$item};
17876: my $newdepth = $depth+1;
17877: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 17878: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 17879: $adds{$newitem} = 1;
17880: }
17881: }
17882: }
17883: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 17884: if (ref($cathash) eq 'HASH') {
1.48 raeburn 17885: my $newitem = 'instcode::0';
1.57 raeburn 17886: if ($cathash->{$newitem} eq '') {
17887: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 17888: $adds{$newitem} = 1;
17889: }
17890: } else {
17891: my $newitem = 'instcode::0';
1.57 raeburn 17892: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 17893: $adds{$newitem} = 1;
17894: }
17895: }
1.120 raeburn 17896: if ($env{'form.communities'} eq '1') {
17897: if (ref($cathash) eq 'HASH') {
17898: my $newitem = 'communities::0';
17899: if ($cathash->{$newitem} eq '') {
17900: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17901: $adds{$newitem} = 1;
17902: }
17903: } else {
17904: my $newitem = 'communities::0';
17905: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
17906: $adds{$newitem} = 1;
17907: }
17908: }
1.48 raeburn 17909: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 17910: if (($env{'form.addcategory_name'} ne 'instcode') &&
17911: ($env{'form.addcategory_name'} ne 'communities')) {
17912: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
17913: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
17914: $adds{$newitem} = 1;
17915: }
1.48 raeburn 17916: }
1.57 raeburn 17917: my $putresult;
1.48 raeburn 17918: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17919: if (keys(%deletions) > 0) {
17920: foreach my $key (keys(%deletions)) {
17921: if ($predelallitems{$key} ne '') {
17922: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
17923: }
17924: }
17925: }
17926: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 17927: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 17928: if (ref($chkcats[0]) eq 'ARRAY') {
17929: my $depth = 0;
17930: my $chg = 0;
17931: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
17932: my $name = $chkcats[0][$i];
17933: my $item;
17934: if ($name eq '') {
17935: $chg ++;
17936: } else {
17937: $item = &escape($name).'::0';
17938: if ($chg) {
1.57 raeburn 17939: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 17940: }
17941: $depth ++;
1.57 raeburn 17942: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 17943: $depth --;
17944: }
17945: }
17946: }
1.57 raeburn 17947: }
17948: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17949: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 17950: if ($putresult eq 'ok') {
1.57 raeburn 17951: my %title = (
1.120 raeburn 17952: togglecats => 'Show/Hide a course in catalog',
17953: categorize => 'Assign a category to a course',
17954: togglecatscomm => 'Show/Hide a community in catalog',
17955: categorizecomm => 'Assign a category to a community',
1.57 raeburn 17956: );
17957: my %level = (
1.120 raeburn 17958: dom => 'set in Domain ("Modify Course/Community")',
17959: crs => 'set in Course ("Course Configuration")',
17960: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 17961: none => 'No catalog',
17962: std => 'Standard catalog',
17963: domonly => 'Domain-only catalog',
17964: codesrch => 'Code search form',
1.57 raeburn 17965: );
1.48 raeburn 17966: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 17967: if ($changes{'togglecats'}) {
17968: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
17969: }
17970: if ($changes{'categorize'}) {
17971: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 17972: }
1.120 raeburn 17973: if ($changes{'togglecatscomm'}) {
17974: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
17975: }
17976: if ($changes{'categorizecomm'}) {
17977: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
17978: }
1.160.6.42 raeburn 17979: if ($changes{'unauth'}) {
17980: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
17981: }
17982: if ($changes{'auth'}) {
17983: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
17984: }
1.57 raeburn 17985: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
17986: my $cathash;
17987: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
17988: $cathash = $domconfig{'coursecategories'}{'cats'};
17989: } else {
17990: $cathash = {};
17991: }
17992: my (@cats,@trails,%allitems);
17993: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
17994: if (keys(%deletions) > 0) {
17995: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
17996: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
17997: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
17998: }
17999: $resulttext .= '</ul></li>';
18000: }
18001: if (keys(%reorderings) > 0) {
18002: my %sort_by_trail;
18003: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18004: foreach my $key (keys(%reorderings)) {
18005: if ($allitems{$key} ne '') {
18006: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18007: }
1.48 raeburn 18008: }
1.57 raeburn 18009: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18010: $resulttext .= '<li>'.$trails[$trail].'</li>';
18011: }
18012: $resulttext .= '</ul></li>';
1.48 raeburn 18013: }
1.57 raeburn 18014: if (keys(%adds) > 0) {
18015: my %sort_by_trail;
18016: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18017: foreach my $key (keys(%adds)) {
18018: if ($allitems{$key} ne '') {
18019: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18020: }
18021: }
18022: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18023: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18024: }
1.57 raeburn 18025: $resulttext .= '</ul></li>';
1.48 raeburn 18026: }
1.160.6.92 raeburn 18027: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18028: if (ref($lastactref) eq 'HASH') {
18029: $lastactref->{'cats'} = 1;
18030: }
1.48 raeburn 18031: }
18032: $resulttext .= '</ul>';
1.160.6.43 raeburn 18033: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 18034: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18035: if ($changes{'auth'}) {
18036: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18037: }
18038: if ($changes{'unauth'}) {
18039: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18040: }
18041: my $cachetime = 24*60*60;
18042: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 18043: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 18044: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 18045: }
18046: }
1.48 raeburn 18047: } else {
18048: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18049: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18050: }
18051: } else {
1.120 raeburn 18052: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18053: }
18054: return $resulttext;
18055: }
18056:
1.69 raeburn 18057: sub modify_serverstatuses {
18058: my ($dom,%domconfig) = @_;
18059: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18060: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18061: %currserverstatus = %{$domconfig{'serverstatuses'}};
18062: }
18063: my @pages = &serverstatus_pages();
18064: foreach my $type (@pages) {
18065: $newserverstatus{$type}{'namedusers'} = '';
18066: $newserverstatus{$type}{'machines'} = '';
18067: if (defined($env{'form.'.$type.'_namedusers'})) {
18068: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18069: my @okusers;
18070: foreach my $user (@users) {
18071: my ($uname,$udom) = split(/:/,$user);
18072: if (($udom =~ /^$match_domain$/) &&
18073: (&Apache::lonnet::domain($udom)) &&
18074: ($uname =~ /^$match_username$/)) {
18075: if (!grep(/^\Q$user\E/,@okusers)) {
18076: push(@okusers,$user);
18077: }
18078: }
18079: }
18080: if (@okusers > 0) {
18081: @okusers = sort(@okusers);
18082: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18083: }
18084: }
18085: if (defined($env{'form.'.$type.'_machines'})) {
18086: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18087: my @okmachines;
18088: foreach my $ip (@machines) {
18089: my @parts = split(/\./,$ip);
18090: next if (@parts < 4);
18091: my $badip = 0;
18092: for (my $i=0; $i<4; $i++) {
18093: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18094: $badip = 1;
18095: last;
18096: }
18097: }
18098: if (!$badip) {
18099: push(@okmachines,$ip);
18100: }
18101: }
18102: @okmachines = sort(@okmachines);
18103: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18104: }
18105: }
18106: my %serverstatushash = (
18107: serverstatuses => \%newserverstatus,
18108: );
18109: foreach my $type (@pages) {
1.83 raeburn 18110: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18111: my (@current,@new);
1.83 raeburn 18112: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18113: if ($currserverstatus{$type}{$setting} ne '') {
18114: @current = split(/,/,$currserverstatus{$type}{$setting});
18115: }
18116: }
18117: if ($newserverstatus{$type}{$setting} ne '') {
18118: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18119: }
18120: if (@current > 0) {
18121: if (@new > 0) {
18122: foreach my $item (@current) {
18123: if (!grep(/^\Q$item\E$/,@new)) {
18124: $changes{$type}{$setting} = 1;
1.82 raeburn 18125: last;
18126: }
18127: }
1.84 raeburn 18128: foreach my $item (@new) {
18129: if (!grep(/^\Q$item\E$/,@current)) {
18130: $changes{$type}{$setting} = 1;
18131: last;
1.82 raeburn 18132: }
18133: }
18134: } else {
1.83 raeburn 18135: $changes{$type}{$setting} = 1;
1.69 raeburn 18136: }
1.83 raeburn 18137: } elsif (@new > 0) {
18138: $changes{$type}{$setting} = 1;
1.69 raeburn 18139: }
18140: }
18141: }
18142: if (keys(%changes) > 0) {
1.81 raeburn 18143: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18144: my $putresult = &Apache::lonnet::put_dom('configuration',
18145: \%serverstatushash,$dom);
18146: if ($putresult eq 'ok') {
18147: $resulttext .= &mt('Changes made:').'<ul>';
18148: foreach my $type (@pages) {
1.84 raeburn 18149: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18150: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18151: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18152: if ($newserverstatus{$type}{'namedusers'} eq '') {
18153: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18154: } else {
18155: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18156: }
1.84 raeburn 18157: }
18158: if ($changes{$type}{'machines'}) {
1.69 raeburn 18159: if ($newserverstatus{$type}{'machines'} eq '') {
18160: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18161: } else {
18162: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18163: }
18164:
18165: }
18166: $resulttext .= '</ul></li>';
18167: }
18168: }
18169: $resulttext .= '</ul>';
18170: } else {
18171: $resulttext = '<span class="LC_error">'.
18172: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18173:
18174: }
18175: } else {
18176: $resulttext = &mt('No changes made to access to server status pages');
18177: }
18178: return $resulttext;
18179: }
18180:
1.118 jms 18181: sub modify_helpsettings {
1.160.6.77 raeburn 18182: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 18183: my ($resulttext,$errors,%changes,%helphash);
18184: my %defaultchecked = ('submitbugs' => 'on');
18185: my @offon = ('off','on');
1.118 jms 18186: my @toggles = ('submitbugs');
1.160.6.77 raeburn 18187: my %current = ('submitbugs' => '',
18188: 'adhoc' => {},
18189: );
1.118 jms 18190: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 18191: %current = %{$domconfig{'helpsettings'}};
18192: }
1.160.6.77 raeburn 18193: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 18194: foreach my $item (@toggles) {
18195: if ($defaultchecked{$item} eq 'on') {
18196: if ($current{$item} eq '') {
18197: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 18198: $changes{$item} = 1;
18199: }
1.160.6.73 raeburn 18200: } elsif ($current{$item} ne $env{'form.'.$item}) {
18201: $changes{$item} = 1;
18202: }
18203: } elsif ($defaultchecked{$item} eq 'off') {
18204: if ($current{$item} eq '') {
18205: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 18206: $changes{$item} = 1;
18207: }
1.160.6.73 raeburn 18208: } elsif ($current{$item} ne $env{'form.'.$item}) {
18209: $changes{$item} = 1;
18210: }
18211: }
18212: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18213: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18214: }
18215: }
1.160.6.77 raeburn 18216: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 18217: my $confname = $dom.'-domainconfig';
18218: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 18219: my (@allpos,%newsettings,%changedprivs,$newrole);
18220: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 18221: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18222: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 18223: my %lt = &Apache::lonlocal::texthash(
18224: s => 'system',
18225: d => 'domain',
18226: order => 'Display order',
18227: access => 'Role usage',
1.160.6.79 raeburn 18228: all => 'All with domain helpdesk or helpdesk assistant role',
18229: dh => 'All with domain helpdesk role',
18230: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 18231: none => 'None',
18232: status => 'Determined based on institutional status',
18233: inc => 'Include all, but exclude specific personnel',
18234: exc => 'Exclude all, but include specific personnel',
18235: );
18236: for (my $num=0; $num<=$maxnum; $num++) {
18237: my ($prefix,$identifier,$rolename,%curr);
18238: if ($num == $maxnum) {
18239: next unless ($env{'form.newcusthelp'} == $maxnum);
18240: $identifier = 'custhelp'.$num;
18241: $prefix = 'helproles_'.$num;
18242: $rolename = $env{'form.custhelpname'.$num};
18243: $rolename=~s/[^A-Za-z0-9]//gs;
18244: next if ($rolename eq '');
18245: next if (exists($existing{'rolesdef_'.$rolename}));
18246: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18247: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18248: $newprivs{'c'},$confname,$dom);
18249: if ($result ne 'ok') {
18250: $errors .= '<li><span class="LC_error">'.
18251: &mt('An error occurred storing the new custom role: [_1]',
18252: $result).'</span></li>';
18253: next;
18254: } else {
18255: $changedprivs{$rolename} = \%newprivs;
18256: $newrole = $rolename;
18257: }
18258: } else {
18259: $prefix = 'helproles_'.$num;
18260: $rolename = $env{'form.'.$prefix};
18261: next if ($rolename eq '');
18262: next unless (exists($existing{'rolesdef_'.$rolename}));
18263: $identifier = 'custhelp'.$num;
18264: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18265: my %currprivs;
18266: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18267: split(/\_/,$existing{'rolesdef_'.$rolename});
18268: foreach my $level ('c','d','s') {
18269: if ($newprivs{$level} ne $currprivs{$level}) {
18270: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18271: $newprivs{'c'},$confname,$dom);
18272: if ($result ne 'ok') {
18273: $errors .= '<li><span class="LC_error">'.
18274: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18275: $rolename,$result).'</span></li>';
18276: } else {
18277: $changedprivs{$rolename} = \%newprivs;
18278: }
18279: last;
18280: }
18281: }
18282: if (ref($current{'adhoc'}) eq 'HASH') {
18283: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18284: %curr = %{$current{'adhoc'}{$rolename}};
18285: }
18286: }
18287: }
18288: my $newpos = $env{'form.'.$prefix.'_pos'};
18289: $newpos =~ s/\D+//g;
18290: $allpos[$newpos] = $rolename;
18291: my $newdesc = $env{'form.'.$prefix.'_desc'};
18292: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18293: if ($curr{'desc'}) {
18294: if ($curr{'desc'} ne $newdesc) {
18295: $changes{'customrole'}{$rolename}{'desc'} = 1;
18296: $newsettings{$rolename}{'desc'} = $newdesc;
18297: }
18298: } elsif ($newdesc ne '') {
18299: $changes{'customrole'}{$rolename}{'desc'} = 1;
18300: $newsettings{$rolename}{'desc'} = $newdesc;
18301: }
18302: my $access = $env{'form.'.$prefix.'_access'};
18303: if (grep(/^\Q$access\E$/,@accesstypes)) {
18304: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18305: if ($access eq 'status') {
18306: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18307: if (scalar(@statuses) == 0) {
18308: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18309: } else {
18310: my (@shownstatus,$numtypes);
18311: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18312: if (ref($types) eq 'ARRAY') {
18313: $numtypes = scalar(@{$types});
18314: foreach my $type (sort(@statuses)) {
18315: if ($type eq 'default') {
18316: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18317: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18318: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18319: push(@shownstatus,$usertypes->{$type});
18320: }
1.160.6.73 raeburn 18321: }
18322: }
1.160.6.77 raeburn 18323: if (grep(/^default$/,@statuses)) {
18324: push(@shownstatus,$othertitle);
18325: }
18326: if (scalar(@shownstatus) == 1+$numtypes) {
18327: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18328: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18329: } else {
18330: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18331: if (ref($curr{'status'}) eq 'ARRAY') {
18332: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18333: if (@diffs) {
18334: $changes{'customrole'}{$rolename}{$access} = 1;
18335: }
18336: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18337: $changes{'customrole'}{$rolename}{$access} = 1;
18338: }
18339: }
18340: }
18341: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18342: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18343: my @newspecstaff;
18344: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18345: foreach my $person (sort(@personnel)) {
18346: if ($domhelpdesk{$person}) {
18347: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18348: }
18349: }
18350: if (ref($curr{$access}) eq 'ARRAY') {
18351: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18352: if (@diffs) {
18353: $changes{'customrole'}{$rolename}{$access} = 1;
18354: }
18355: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18356: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 18357: }
1.160.6.77 raeburn 18358: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18359: my ($uname,$udom) = split(/:/,$person);
18360: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18361: }
18362: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 18363: }
1.160.6.77 raeburn 18364: } else {
18365: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18366: }
18367: unless ($curr{'access'} eq $access) {
18368: $changes{'customrole'}{$rolename}{'access'} = 1;
18369: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 18370: }
18371: }
1.160.6.77 raeburn 18372: if (@allpos > 0) {
18373: my $idx = 0;
18374: foreach my $rolename (@allpos) {
18375: if ($rolename ne '') {
18376: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18377: if (ref($current{'adhoc'}) eq 'HASH') {
18378: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18379: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18380: $changes{'customrole'}{$rolename}{'order'} = 1;
18381: $newsettings{$rolename}{'order'} = $idx+1;
18382: }
18383: }
1.160.6.73 raeburn 18384: }
1.160.6.77 raeburn 18385: $idx ++;
1.122 jms 18386: }
18387: }
1.118 jms 18388: }
1.123 jms 18389: my $putresult;
18390: if (keys(%changes) > 0) {
1.160.6.5 raeburn 18391: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18392: if ($putresult eq 'ok') {
1.160.6.77 raeburn 18393: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18394: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18395: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18396: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18397: }
18398: }
18399: my $cachetime = 24*60*60;
18400: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18401: if (ref($lastactref) eq 'HASH') {
18402: $lastactref->{'domdefaults'} = 1;
18403: }
18404: } else {
18405: $errors .= '<li><span class="LC_error">'.
18406: &mt('An error occurred storing the settings: [_1]',
18407: $putresult).'</span></li>';
18408: }
18409: }
18410: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18411: $resulttext = &mt('Changes made:').'<ul>';
18412: my (%shownprivs,@levelorder);
18413: @levelorder = ('c','d','s');
18414: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 18415: foreach my $item (sort(keys(%changes))) {
18416: if ($item eq 'submitbugs') {
18417: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18418: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18419: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 18420: } elsif ($item eq 'customrole') {
18421: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 18422: my @keyorder = ('order','desc','access','status','exc','inc');
18423: my %keytext = &Apache::lonlocal::texthash(
18424: order => 'Order',
18425: desc => 'Role description',
18426: access => 'Role usage',
1.160.6.83 raeburn 18427: status => 'Allowed institutional types',
1.160.6.77 raeburn 18428: exc => 'Allowed personnel',
18429: inc => 'Disallowed personnel',
18430: );
1.160.6.73 raeburn 18431: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 18432: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18433: if ($role eq $newrole) {
18434: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18435: $role).'<ul>';
18436: } else {
18437: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18438: $role).'<ul>';
18439: }
18440: foreach my $key (@keyorder) {
18441: if ($changes{'customrole'}{$role}{$key}) {
18442: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18443: $keytext{$key},$newsettings{$role}{$key}).
18444: '</li>';
18445: }
18446: }
18447: if (ref($changedprivs{$role}) eq 'HASH') {
18448: $shownprivs{$role} = 1;
18449: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18450: foreach my $level (@levelorder) {
18451: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18452: next if ($item eq '');
18453: my ($priv) = split(/\&/,$item,2);
18454: if (&Apache::lonnet::plaintext($priv)) {
18455: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18456: unless ($level eq 'c') {
18457: $resulttext .= ' ('.$lt{$level}.')';
18458: }
18459: $resulttext .= '</li>';
18460: }
18461: }
18462: }
18463: $resulttext .= '</ul>';
18464: }
18465: $resulttext .= '</ul></li>';
18466: }
1.160.6.73 raeburn 18467: }
18468: }
1.160.6.5 raeburn 18469: }
18470: }
18471: }
1.160.6.77 raeburn 18472: if (keys(%changedprivs)) {
18473: foreach my $role (sort(keys(%changedprivs))) {
18474: unless ($shownprivs{$role}) {
18475: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18476: $role).'<ul>'.
18477: '<li>'.&mt('Privileges set to :').'<ul>';
18478: foreach my $level (@levelorder) {
18479: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18480: next if ($item eq '');
18481: my ($priv) = split(/\&/,$item,2);
18482: if (&Apache::lonnet::plaintext($priv)) {
18483: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18484: unless ($level eq 'c') {
18485: $resulttext .= ' ('.$lt{$level}.')';
18486: }
18487: $resulttext .= '</li>';
18488: }
18489: }
18490: }
18491: $resulttext .= '</ul></li></ul></li>';
18492: }
18493: }
18494: }
18495: $resulttext .= '</ul>';
18496: } else {
18497: $resulttext = &mt('No changes made to help settings');
1.118 jms 18498: }
18499: if ($errors) {
1.160.6.5 raeburn 18500: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 18501: $errors.'</ul>';
1.118 jms 18502: }
18503: return $resulttext;
18504: }
18505:
1.121 raeburn 18506: sub modify_coursedefaults {
1.160.6.27 raeburn 18507: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 18508: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 18509: my %defaultchecked = (
18510: 'uselcmath' => 'on',
1.160.6.115 raeburn 18511: 'usejsme' => 'on',
18512: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 18513:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 18514: );
1.160.6.118.2 4(raebur 18515:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 18516: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.118.2 15(raebu 18517:23): 'uploadquota_community','uploadquota_textbook','coursequota_official',
18518:23): 'coursequota_unofficial','coursequota_community','coursequota_textbook',
18519:23): 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
18520:23): 'mysqltables_textbook');
1.160.6.30 raeburn 18521: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 18522: my %staticdefaults = (
18523: anonsurvey_threshold => 10,
18524: uploadquota => 500,
1.160.6.118.2 15(raebu 18525:23): coursequota => 20,
1.160.6.57 raeburn 18526: postsubmit => 60,
1.160.6.70 raeburn 18527: mysqltables => 172800,
1.160.6.118.2 14(raebu 18528:23): domexttool => 1,
1.160.6.21 raeburn 18529: );
1.160.6.90 raeburn 18530: my %texoptions = (
18531: MathJax => 'MathJax',
18532: mimetex => &mt('Convert to Images'),
18533: tth => &mt('TeX to HTML'),
18534: );
1.121 raeburn 18535: $defaultshash{'coursedefaults'} = {};
18536:
18537: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
18538: if ($domconfig{'coursedefaults'} eq '') {
18539: $domconfig{'coursedefaults'} = {};
18540: }
18541: }
18542:
18543: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
18544: foreach my $item (@toggles) {
18545: if ($defaultchecked{$item} eq 'on') {
18546: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18547: ($env{'form.'.$item} eq '0')) {
18548: $changes{$item} = 1;
1.160.6.16 raeburn 18549: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 18550: $changes{$item} = 1;
18551: }
18552: } elsif ($defaultchecked{$item} eq 'off') {
18553: if (($domconfig{'coursedefaults'}{$item} eq '') &&
18554: ($env{'form.'.$item} eq '1')) {
18555: $changes{$item} = 1;
18556: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
18557: $changes{$item} = 1;
18558: }
18559: }
18560: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
18561: }
1.160.6.21 raeburn 18562: foreach my $item (@numbers) {
18563: my ($currdef,$newdef);
1.160.6.26 raeburn 18564: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 18565: if ($item eq 'anonsurvey_threshold') {
18566: $currdef = $domconfig{'coursedefaults'}{$item};
18567: $newdef =~ s/\D//g;
18568: if ($newdef eq '' || $newdef < 1) {
18569: $newdef = 1;
18570: }
18571: $defaultshash{'coursedefaults'}{$item} = $newdef;
18572: } else {
1.160.6.118.2 15(raebu 18573:23): my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.160.6.70 raeburn 18574: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
18575: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 18576: }
18577: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 18578: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 18579: }
18580: if ($currdef ne $newdef) {
18581: if ($item eq 'anonsurvey_threshold') {
18582: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
18583: $changes{$item} = 1;
18584: }
1.160.6.118.2 15(raebu 18585:23): } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.160.6.70 raeburn 18586: my $setting = $1;
18587: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
18588: $changes{$setting} = 1;
1.160.6.21 raeburn 18589: }
18590: }
1.139 raeburn 18591: }
18592: }
1.160.6.90 raeburn 18593: my $texengine;
18594: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
18595: $texengine = $env{'form.texengine'};
18596: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
18597: if ($currdef eq '') {
18598: unless ($texengine eq $Apache::lonnet::deftex) {
18599: $changes{'texengine'} = 1;
18600: }
18601: } elsif ($currdef ne $texengine) {
18602: $changes{'texengine'} = 1;
18603: }
18604: }
18605: if ($texengine ne '') {
18606: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
18607: }
1.160.6.64 raeburn 18608: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
18609: my @currclonecode;
18610: if (ref($currclone) eq 'HASH') {
18611: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
18612: @currclonecode = @{$currclone->{'instcode'}};
18613: }
18614: }
18615: my $newclone;
18616: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
18617: $newclone = $env{'form.canclone'};
18618: }
18619: if ($newclone eq 'instcode') {
18620: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
18621: my (%codedefaults,@code_order,@clonecode);
18622: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
18623: \@code_order);
18624: foreach my $item (@code_order) {
18625: if (grep(/^\Q$item\E$/,@newcodes)) {
18626: push(@clonecode,$item);
18627: }
18628: }
18629: if (@clonecode) {
18630: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
18631: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
18632: if (@diffs) {
18633: $changes{'canclone'} = 1;
18634: }
18635: } else {
18636: $newclone eq '';
18637: }
18638: } elsif ($newclone ne '') {
18639: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
18640: }
18641: if ($newclone ne $currclone) {
18642: $changes{'canclone'} = 1;
18643: }
1.160.6.57 raeburn 18644: my %credits;
18645: foreach my $type (@types) {
18646: unless ($type eq 'community') {
18647: $credits{$type} = $env{'form.'.$type.'_credits'};
18648: $credits{$type} =~ s/[^\d.]+//g;
18649: }
18650: }
18651: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
18652: ($env{'form.coursecredits'} eq '1')) {
18653: $changes{'coursecredits'} = 1;
18654: foreach my $type (keys(%credits)) {
18655: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
18656: }
18657: } else {
18658: if ($env{'form.coursecredits'} eq '1') {
18659: foreach my $type (@types) {
18660: unless ($type eq 'community') {
18661: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
18662: $changes{'coursecredits'} = 1;
18663: }
18664: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
18665: }
18666: }
18667: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18668: foreach my $type (@types) {
18669: unless ($type eq 'community') {
18670: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
18671: $changes{'coursecredits'} = 1;
18672: last;
18673: }
18674: }
18675: }
18676: }
18677: }
18678: if ($env{'form.postsubmit'} eq '1') {
18679: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
18680: my %currtimeout;
18681: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18682: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
18683: $changes{'postsubmit'} = 1;
18684: }
18685: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18686: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
18687: }
18688: } else {
18689: $changes{'postsubmit'} = 1;
18690: }
18691: foreach my $type (@types) {
18692: my $timeout = $env{'form.'.$type.'_timeout'};
18693: $timeout =~ s/\D//g;
18694: if ($timeout == $staticdefaults{'postsubmit'}) {
18695: $timeout = '';
18696: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
18697: $timeout = '0';
18698: }
18699: unless ($timeout eq '') {
18700: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
18701: }
18702: if (exists($currtimeout{$type})) {
18703: if ($timeout ne $currtimeout{$type}) {
18704: $changes{'postsubmit'} = 1;
18705: }
18706: } elsif ($timeout ne '') {
18707: $changes{'postsubmit'} = 1;
18708: }
18709: }
18710: } else {
18711: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
18712: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18713: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
18714: $changes{'postsubmit'} = 1;
18715: }
18716: } else {
18717: $changes{'postsubmit'} = 1;
18718: }
1.160.6.16 raeburn 18719: }
1.160.6.118.2 14(raebu 18720:23): my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool);
18721:23): map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
18722:23): map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
18723:23): if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18724:23): %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
18725:23): } else {
18726:23): foreach my $type (@types) {
18727:23): if ($staticdefaults{'domexttool'}) {
18728:23): $olddomexttool{$type} = 1;
18729:23): } else {
18730:23): $olddomexttool{$type} = 0;
18731:23): }
18732:23): }
18733:23): }
18734:23): if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
18735:23): %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
18736:23): } else {
18737:23): foreach my $type (@types) {
18738:23): if ($staticdefaults{'exttool'}) {
18739:23): $oldexttool{$type} = 1;
18740:23): } else {
18741:23): $oldexttool{$type} = 0;
18742:23): }
18743:23): }
18744:23): }
18745:23): foreach my $type (@types) {
18746:23): unless ($newdomexttool{$type}) {
18747:23): $newdomexttool{$type} = 0;
18748:23): }
18749:23): unless ($newexttool{$type}) {
18750:23): $newexttool{$type} = 0;
18751:23): }
18752:23): if ($newdomexttool{$type} != $olddomexttool{$type}) {
18753:23): $changes{'domexttool'} = 1;
18754:23): }
18755:23): if ($newexttool{$type} != $oldexttool{$type}) {
18756:23): $changes{'exttool'} = 1;
18757:23): }
18758:23): }
18759:23): $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
18760:23): $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
1.121 raeburn 18761: }
18762: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
18763: $dom);
18764: if ($putresult eq 'ok') {
18765: if (keys(%changes) > 0) {
1.160.6.27 raeburn 18766: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 18767: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 18768: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 18769: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 14(raebu 18770:23): ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
15(raebu 18771:23): ($changes{'exttool'}) || ($changes{'coursequota'})) {
4(raebur 18772:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 18773: if ($changes{$item}) {
18774: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
18775: }
1.160.6.16 raeburn 18776: }
18777: if ($changes{'coursecredits'}) {
18778: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 18779: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
18780: $domdefaults{$type.'credits'} =
18781: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
18782: }
18783: }
18784: }
18785: if ($changes{'postsubmit'}) {
18786: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18787: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
18788: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18789: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
18790: $domdefaults{$type.'postsubtimeout'} =
18791: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
18792: }
18793: }
1.160.6.16 raeburn 18794: }
18795: }
1.160.6.21 raeburn 18796: if ($changes{'uploadquota'}) {
18797: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
18798: foreach my $type (@types) {
18799: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
18800: }
18801: }
18802: }
1.160.6.118.2 15(raebu 18803:23): if ($changes{'coursequota'}) {
18804:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
18805:23): foreach my $type (@types) {
18806:23): $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
18807:23): }
18808:23): }
18809:23): }
1.160.6.64 raeburn 18810: if ($changes{'canclone'}) {
18811: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
18812: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
18813: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
18814: if (@clonecodes) {
18815: $domdefaults{'canclone'} = join('+',@clonecodes);
18816: }
18817: }
18818: } else {
18819: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
18820: }
18821: }
1.160.6.118.2 14(raebu 18822:23): if ($changes{'domexttool'}) {
18823:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18824:23): foreach my $type (@types) {
18825:23): $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
18826:23): }
18827:23): }
18828:23): }
18829:23): if ($changes{'exttool'}) {
18830:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
18831:23): foreach my $type (@types) {
18832:23): $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
18833:23): }
18834:23): }
18835:23): }
1.121 raeburn 18836: my $cachetime = 24*60*60;
18837: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 18838: if (ref($lastactref) eq 'HASH') {
18839: $lastactref->{'domdefaults'} = 1;
18840: }
1.121 raeburn 18841: }
18842: $resulttext = &mt('Changes made:').'<ul>';
18843: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 18844: if ($item eq 'uselcmath') {
1.121 raeburn 18845: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 18846: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 18847: } else {
1.160.6.57 raeburn 18848: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
18849: }
18850: } elsif ($item eq 'usejsme') {
18851: if ($env{'form.'.$item} eq '1') {
18852: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
18853: } else {
18854: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 18855: }
1.160.6.115 raeburn 18856: } elsif ($item eq 'inline_chem') {
18857: if ($env{'form.'.$item} eq '1') {
18858: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
18859: } else {
18860: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
18861: }
1.160.6.90 raeburn 18862: } elsif ($item eq 'texengine') {
18863: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
18864: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
18865: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
18866: }
1.139 raeburn 18867: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 18868: $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 18869: } elsif ($item eq 'uploadquota') {
18870: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
18871: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
18872: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
18873: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 18874: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.160.6.21 raeburn 18875: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
18876: '</ul>'.
18877: '</li>';
18878: } else {
18879: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
18880: }
1.160.6.118.2 15(raebu 18881:23): } elsif ($item eq 'coursequota') {
18882:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
18883:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
18884:23): '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
18885:23): '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
18886:23): '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
18887:23): '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
18888:23): '</ul>'.
18889:23): '</li>';
18890:23): } else {
18891:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
18892:23): }
1.160.6.70 raeburn 18893: } elsif ($item eq 'mysqltables') {
18894: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
18895: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
18896: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
18897: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
18898: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
18899: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
18900: '</ul>'.
18901: '</li>';
18902: } else {
18903: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
18904: }
1.160.6.57 raeburn 18905: } elsif ($item eq 'postsubmit') {
18906: if ($domdefaults{'postsubmit'} eq 'off') {
18907: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
18908: } else {
18909: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
18910: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
18911: $resulttext .= &mt('durations:').'<ul>';
18912: foreach my $type (@types) {
18913: $resulttext .= '<li>';
18914: my $timeout;
18915: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
18916: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
18917: }
18918: my $display;
18919: if ($timeout eq '0') {
18920: $display = &mt('unlimited');
18921: } elsif ($timeout eq '') {
18922: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
18923: } else {
18924: $display = &mt('[quant,_1,second]',$timeout);
18925: }
18926: if ($type eq 'community') {
18927: $resulttext .= &mt('Communities');
18928: } elsif ($type eq 'official') {
18929: $resulttext .= &mt('Official courses');
18930: } elsif ($type eq 'unofficial') {
18931: $resulttext .= &mt('Unofficial courses');
18932: } elsif ($type eq 'textbook') {
18933: $resulttext .= &mt('Textbook courses');
18934: }
18935: $resulttext .= ' -- '.$display.'</li>';
18936: }
18937: $resulttext .= '</ul>';
18938: }
18939: $resulttext .= '</li>';
18940: }
1.160.6.16 raeburn 18941: } elsif ($item eq 'coursecredits') {
18942: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
18943: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 18944: ($domdefaults{'unofficialcredits'} eq '') &&
18945: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 18946: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
18947: } else {
18948: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
18949: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
18950: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 18951: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 18952: '</ul>'.
18953: '</li>';
18954: }
18955: } else {
18956: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
18957: }
1.160.6.64 raeburn 18958: } elsif ($item eq 'canclone') {
18959: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
18960: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
18961: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
18962: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
18963: }
18964: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
18965: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
18966: } else {
18967: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
18968: }
1.160.6.118.2 4(raebur 18969:2): } elsif ($item eq 'ltiauth') {
18970:2): if ($env{'form.'.$item} eq '1') {
18971:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
18972:2): } else {
18973:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
18974:2): }
14(raebu 18975:23): } elsif ($item eq 'domexttool') {
18976:23): my @noyes = (&mt('no'),&mt('yes'));
18977:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
18978:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
18979:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
18980:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
18981:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
18982:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
18983:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
18984:23): '</ul>'.
18985:23): '</li>';
18986:23): } else {
18987:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
18988:23): }
18989:23): } elsif ($item eq 'exttool') {
18990:23): my @noyes = (&mt('no'),&mt('yes'));
18991:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
18992:23): $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
18993:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
18994:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
18995:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
18996:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
18997:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
18998:23): '</ul>'.
18999:23): '</li>';
19000:23): } else {
19001:23): $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
19002:23): }
1.140 raeburn 19003: }
1.121 raeburn 19004: }
19005: $resulttext .= '</ul>';
19006: } else {
19007: $resulttext = &mt('No changes made to course defaults');
19008: }
19009: } else {
19010: $resulttext = '<span class="LC_error">'.
19011: &mt('An error occurred: [_1]',$putresult).'</span>';
19012: }
19013: return $resulttext;
19014: }
19015:
1.160.6.37 raeburn 19016: sub modify_selfenrollment {
19017: my ($dom,$lastactref,%domconfig) = @_;
19018: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
19019: my @types = ('official','unofficial','community','textbook');
19020: my %titles = &tool_titles();
19021: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19022: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
19023: $ordered{'default'} = ['types','registered','approval','limit'];
19024:
19025: my (%roles,%shown,%toplevel);
19026: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19027:
19028: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19029: if ($domconfig{'selfenrollment'} eq '') {
19030: $domconfig{'selfenrollment'} = {};
19031: }
19032: }
19033: %toplevel = (
19034: admin => 'Configuration Rights',
19035: default => 'Default settings',
19036: validation => 'Validation of self-enrollment requests',
19037: );
19038: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
19039:
19040: if (ref($ordered{'admin'}) eq 'ARRAY') {
19041: foreach my $item (@{$ordered{'admin'}}) {
19042: foreach my $type (@types) {
19043: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19044: $selfenrollhash{'admin'}{$type}{$item} = 1;
19045: } else {
19046: $selfenrollhash{'admin'}{$type}{$item} = 0;
19047: }
19048: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19049: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19050: if ($selfenrollhash{'admin'}{$type}{$item} ne
19051: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19052: push(@{$changes{'admin'}{$type}},$item);
19053: }
19054: } else {
19055: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19056: push(@{$changes{'admin'}{$type}},$item);
19057: }
19058: }
19059: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19060: push(@{$changes{'admin'}{$type}},$item);
19061: }
19062: }
19063: }
19064: }
19065:
19066: foreach my $item (@{$ordered{'default'}}) {
19067: foreach my $type (@types) {
19068: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19069: if ($item eq 'types') {
19070: unless (($value eq 'all') || ($value eq 'dom')) {
19071: $value = '';
19072: }
19073: } elsif ($item eq 'registered') {
19074: unless ($value eq '1') {
19075: $value = 0;
19076: }
19077: } elsif ($item eq 'approval') {
19078: unless ($value =~ /^[012]$/) {
19079: $value = 0;
19080: }
19081: } else {
19082: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19083: $value = 'none';
19084: }
19085: }
19086: $selfenrollhash{'default'}{$type}{$item} = $value;
19087: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19088: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19089: if ($selfenrollhash{'default'}{$type}{$item} ne
19090: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19091: push(@{$changes{'default'}{$type}},$item);
19092: }
19093: } else {
19094: push(@{$changes{'default'}{$type}},$item);
19095: }
19096: } else {
19097: push(@{$changes{'default'}{$type}},$item);
19098: }
19099: if ($item eq 'limit') {
19100: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19101: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19102: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19103: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19104: }
19105: } else {
19106: $selfenrollhash{'default'}{$type}{'cap'} = '';
19107: }
19108: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19109: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19110: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19111: push(@{$changes{'default'}{$type}},'cap');
19112: }
19113: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19114: push(@{$changes{'default'}{$type}},'cap');
19115: }
19116: }
19117: }
19118: }
19119:
19120: foreach my $item (@{$itemsref}) {
19121: if ($item eq 'fields') {
19122: my @changed;
19123: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19124: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19125: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19126: }
19127: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19128: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19129: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19130: $domconfig{'selfenrollment'}{'validation'}{$item});
19131: } else {
19132: @changed = @{$selfenrollhash{'validation'}{$item}};
19133: }
19134: } else {
19135: @changed = @{$selfenrollhash{'validation'}{$item}};
19136: }
19137: if (@changed) {
19138: if ($selfenrollhash{'validation'}{$item}) {
19139: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19140: } else {
19141: $changes{'validation'}{$item} = &mt('None');
19142: }
19143: }
19144: } else {
19145: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19146: if ($item eq 'markup') {
19147: if ($env{'form.selfenroll_validation_'.$item}) {
19148: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19149: }
19150: }
19151: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19152: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19153: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19154: }
19155: }
19156: }
19157: }
19158:
19159: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19160: $dom);
19161: if ($putresult eq 'ok') {
19162: if (keys(%changes) > 0) {
19163: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19164: $resulttext = &mt('Changes made:').'<ul>';
19165: foreach my $key ('admin','default','validation') {
19166: if (ref($changes{$key}) eq 'HASH') {
19167: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19168: if ($key eq 'validation') {
19169: foreach my $item (@{$itemsref}) {
19170: if (exists($changes{$key}{$item})) {
19171: if ($item eq 'markup') {
19172: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19173: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19174: } else {
19175: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19176: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19177: }
19178: }
19179: }
19180: } else {
19181: foreach my $type (@types) {
19182: if ($type eq 'community') {
19183: $roles{'1'} = &mt('Community personnel');
19184: } else {
19185: $roles{'1'} = &mt('Course personnel');
19186: }
19187: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19188: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19189: if ($key eq 'admin') {
19190: my @mgrdc = ();
19191: if (ref($ordered{$key}) eq 'ARRAY') {
19192: foreach my $item (@{$ordered{'admin'}}) {
19193: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19194: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19195: push(@mgrdc,$item);
19196: }
19197: }
19198: }
19199: if (@mgrdc) {
19200: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19201: } else {
19202: delete($domdefaults{$type.'selfenrolladmdc'});
19203: }
19204: }
19205: } else {
19206: if (ref($ordered{$key}) eq 'ARRAY') {
19207: foreach my $item (@{$ordered{$key}}) {
19208: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19209: $domdefaults{$type.'selfenroll'.$item} =
19210: $selfenrollhash{$key}{$type}{$item};
19211: }
19212: }
19213: }
19214: }
19215: }
19216: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19217: foreach my $item (@{$ordered{$key}}) {
19218: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19219: $resulttext .= '<li>';
19220: if ($key eq 'admin') {
19221: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19222: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19223: } else {
19224: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19225: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19226: }
19227: $resulttext .= '</li>';
19228: }
19229: }
19230: $resulttext .= '</ul></li>';
19231: }
19232: }
19233: $resulttext .= '</ul></li>';
19234: }
19235: }
1.160.6.93 raeburn 19236: }
19237: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19238: my $cachetime = 24*60*60;
19239: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19240: if (ref($lastactref) eq 'HASH') {
19241: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 19242: }
19243: }
19244: $resulttext .= '</ul>';
19245: } else {
19246: $resulttext = &mt('No changes made to self-enrollment settings');
19247: }
19248: } else {
19249: $resulttext = '<span class="LC_error">'.
19250: &mt('An error occurred: [_1]',$putresult).'</span>';
19251: }
19252: return $resulttext;
19253: }
19254:
1.160.6.113 raeburn 19255: sub modify_wafproxy {
19256: my ($dom,$action,$lastactref,%domconfig) = @_;
19257: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19258: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19259: %wafproxy,%changes,%expirecache,%expiresaml);
19260: foreach my $server (sort(keys(%servers))) {
19261: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19262: if ($serverhome eq $server) {
19263: my $serverdom = &Apache::lonnet::host_domain($server);
19264: if ($serverdom eq $dom) {
19265: $canset{$server} = 1;
19266: }
19267: }
19268: }
19269: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19270: %{$values{$dom}} = ();
19271: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19272: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19273: }
19274: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19275: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19276: }
19277: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19278: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19279: }
19280: }
19281: my $output;
19282: if (keys(%canset)) {
19283: %{$wafproxy{'alias'}} = ();
19284: %{$wafproxy{'saml'}} = ();
19285: foreach my $key (sort(keys(%canset))) {
19286: if ($env{'form.wafproxy_'.$dom}) {
19287: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19288: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19289: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19290: $changes{'alias'} = 1;
19291: }
19292: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19293: $wafproxy{'saml'}{$key} = 1;
19294: }
19295: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19296: $changes{'saml'} = 1;
19297: }
19298: } else {
19299: $wafproxy{'alias'}{$key} = '';
19300: $wafproxy{'saml'}{$key} = '';
19301: if ($curralias{$key}) {
19302: $changes{'alias'} = 1;
19303: }
19304: if ($currsaml{$key}) {
19305: $changes{'saml'} = 1;
19306: }
19307: }
19308: if ($wafproxy{'alias'}{$key} eq '') {
19309: if ($curralias{$key}) {
19310: $expirecache{$key} = 1;
19311: }
19312: delete($wafproxy{'alias'}{$key});
19313: }
19314: if ($wafproxy{'saml'}{$key} eq '') {
19315: if ($currsaml{$key}) {
19316: $expiresaml{$key} = 1;
19317: }
19318: delete($wafproxy{'saml'}{$key});
19319: }
19320: }
19321: unless (keys(%{$wafproxy{'alias'}})) {
19322: delete($wafproxy{'alias'});
19323: }
19324: unless (keys(%{$wafproxy{'saml'}})) {
19325: delete($wafproxy{'saml'});
19326: }
19327: # Localization for values in %warn occurs in &mt() calls separately.
19328: my %warn = (
19329: trusted => 'trusted IP range(s)',
19330: vpnint => 'internal IP range(s) for VPN sessions(s)',
19331: vpnext => 'IP range(s) for backend WAF connections',
19332: );
19333: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19334: my $possible = $env{'form.wafproxy_'.$item};
19335: $possible =~ s/^\s+|\s+$//g;
19336: if ($possible ne '') {
19337: if ($item eq 'remoteip') {
19338: if ($possible =~ /^[mhn]$/) {
19339: $wafproxy{$item} = $possible;
19340: }
19341: } elsif ($item eq 'ipheader') {
19342: if ($wafproxy{'remoteip'} eq 'h') {
19343: $wafproxy{$item} = $possible;
19344: }
19345: } elsif ($item eq 'sslopt') {
19346: if ($possible =~ /^0|1$/) {
19347: $wafproxy{$item} = $possible;
19348: }
19349: } else {
19350: my (@ok,$count);
19351: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19352: unless ($env{'form.wafproxy_vpnaccess'}) {
19353: $possible = '';
19354: }
19355: } elsif ($item eq 'trusted') {
19356: unless ($wafproxy{'remoteip'} eq 'h') {
19357: $possible = '';
19358: }
19359: }
19360: unless ($possible eq '') {
19361: $possible =~ s/[\r\n]+/\s/g;
19362: $possible =~ s/\s*-\s*/-/g;
19363: $possible =~ s/\s+/,/g;
19364: $possible =~ s/,+/,/g;
19365: }
19366: $count = 0;
19367: if ($possible ne '') {
19368: foreach my $poss (split(/\,/,$possible)) {
19369: $count ++;
19370: $poss = &validate_ip_pattern($poss);
19371: if ($poss ne '') {
19372: push(@ok,$poss);
19373: }
19374: }
19375: my $diff = $count - scalar(@ok);
19376: if ($diff) {
19377: push(@warnings,'<li>'.
19378: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19379: $diff,$warn{$item}).
19380: '</li>');
19381: }
19382: if (@ok) {
19383: my @cidr_list;
19384: foreach my $item (@ok) {
19385: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19386: }
19387: $wafproxy{$item} = join(',',@cidr_list);
19388: }
19389: }
19390: }
19391: if ($wafproxy{$item} ne $currvalue{$item}) {
19392: $changes{$item} = 1;
19393: }
19394: } elsif ($currvalue{$item}) {
19395: $changes{$item} = 1;
19396: }
19397: }
19398: } else {
19399: if (keys(%curralias)) {
19400: $changes{'alias'} = 1;
19401: }
19402: if (keys(%currsaml)) {
19403: $changes{'saml'} = 1;
19404: }
19405: if (keys(%currvalue)) {
19406: foreach my $key (keys(%currvalue)) {
19407: $changes{$key} = 1;
19408: }
19409: }
19410: }
19411: if (keys(%changes)) {
19412: my %defaultshash = (
19413: wafproxy => \%wafproxy,
19414: );
19415: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19416: $dom);
19417: if ($putresult eq 'ok') {
19418: my $cachetime = 24*60*60;
19419: my (%domdefaults,$updatedomdefs);
19420: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
19421: if ($changes{$item}) {
19422: unless ($updatedomdefs) {
19423: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19424: $updatedomdefs = 1;
19425: }
19426: if ($wafproxy{$item}) {
19427: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19428: } elsif (exists($domdefaults{'waf_'.$item})) {
19429: delete($domdefaults{'waf_'.$item});
19430: }
19431: }
19432: }
19433: if ($updatedomdefs) {
19434: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19435: if (ref($lastactref) eq 'HASH') {
19436: $lastactref->{'domdefaults'} = 1;
19437: }
19438: }
19439: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
19440: my %updates = %expirecache;
19441: foreach my $key (keys(%expirecache)) {
19442: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
19443: }
19444: if (ref($wafproxy{'alias'}) eq 'HASH') {
19445: my $cachetime = 24*60*60;
19446: foreach my $key (keys(%{$wafproxy{'alias'}})) {
19447: $updates{$key} = 1;
19448: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
19449: $cachetime);
19450: }
19451: }
19452: if (ref($lastactref) eq 'HASH') {
19453: $lastactref->{'proxyalias'} = \%updates;
19454: }
19455: }
19456: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
19457: my %samlupdates = %expiresaml;
19458: foreach my $key (keys(%expiresaml)) {
19459: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
19460: }
19461: if (ref($wafproxy{'saml'}) eq 'HASH') {
19462: my $cachetime = 24*60*60;
19463: foreach my $key (keys(%{$wafproxy{'saml'}})) {
19464: $samlupdates{$key} = 1;
19465: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
19466: $cachetime);
19467: }
19468: }
19469: if (ref($lastactref) eq 'HASH') {
19470: $lastactref->{'proxysaml'} = \%samlupdates;
19471: }
19472: }
19473: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 19474: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 19475: if ($changes{$item}) {
19476: if ($item eq 'alias') {
19477: my $numaliased = 0;
19478: if (ref($wafproxy{'alias'}) eq 'HASH') {
19479: my $shown;
19480: if (keys(%{$wafproxy{'alias'}})) {
19481: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
19482: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
19483: &Apache::lonnet::hostname($server),
19484: $wafproxy{'alias'}{$server}).'</li>';
19485: $numaliased ++;
19486: }
19487: if ($numaliased) {
19488: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
19489: '<ul>'.$shown.'</ul>').'</li>';
19490: }
19491: }
19492: }
19493: unless ($numaliased) {
19494: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
19495: }
19496: } elsif ($item eq 'saml') {
19497: my $shown;
19498: if (ref($wafproxy{'saml'}) eq 'HASH') {
19499: if (keys(%{$wafproxy{'saml'}})) {
19500: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
19501: }
19502: }
19503: if ($shown) {
19504: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
19505: $shown).'</li>';
19506: } else {
19507: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
19508: }
19509: } else {
19510: if ($item eq 'remoteip') {
19511: my %ip_methods = &remoteip_methods();
19512: if ($wafproxy{$item} =~ /^[mh]$/) {
19513: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
19514: $ip_methods{$wafproxy{$item}}).'</li>';
19515: } else {
19516: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
19517: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
19518: '</li>';
19519: } else {
19520: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
19521: }
19522: }
19523: } elsif ($item eq 'ipheader') {
19524: if ($wafproxy{$item}) {
19525: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
19526: $wafproxy{$item}).'</li>';
19527: } else {
19528: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
19529: }
19530: } elsif ($item eq 'trusted') {
19531: if ($wafproxy{$item}) {
19532: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
19533: $wafproxy{$item}).'</li>';
19534: } else {
19535: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
19536: }
19537: } elsif ($item eq 'vpnint') {
19538: if ($wafproxy{$item}) {
19539: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
19540: $wafproxy{$item}).'</li>';
19541: } else {
19542: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
19543: }
19544: } elsif ($item eq 'vpnext') {
19545: if ($wafproxy{$item}) {
19546: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
19547: $wafproxy{$item}).'</li>';
19548: } else {
19549: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
19550: }
19551: } elsif ($item eq 'sslopt') {
19552: if ($wafproxy{$item}) {
19553: $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>';
19554: } else {
19555: $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>';
19556: }
19557: }
19558: }
19559: }
19560: }
1.160.6.118.2 14(raebu 19561:23): $output .= '</ul>';
1.160.6.113 raeburn 19562: } else {
19563: $output = '<span class="LC_error">'.
19564: &mt('An error occurred: [_1]',$putresult).'</span>';
19565: }
19566: } elsif (keys(%canset)) {
19567: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
19568: }
19569: if (@warnings) {
19570: $output .= '<br />'.&mt('Warnings:').'<ul>'.
19571: join("\n",@warnings).'</ul>';
19572: }
19573: return $output;
19574: }
19575:
19576: sub validate_ip_pattern {
19577: my ($pattern) = @_;
19578: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
19579: my ($start,$end) = ($1,$2);
19580: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
19581: if (($start !~ m{/}) && ($end !~ m{/})) {
19582: return $start.'-'.$end;
19583: }
19584: }
19585: } elsif ($pattern ne '') {
19586: $pattern = &Net::CIDR::cidrvalidate($pattern);
19587: if ($pattern ne '') {
19588: return $pattern;
19589: }
19590: }
19591: return;
19592: }
19593:
1.137 raeburn 19594: sub modify_usersessions {
1.160.6.27 raeburn 19595: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 19596: my @hostingtypes = ('version','excludedomain','includedomain');
19597: my @offloadtypes = ('primary','default');
19598: my %types = (
19599: remote => \@hostingtypes,
19600: hosted => \@hostingtypes,
19601: spares => \@offloadtypes,
19602: );
19603: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 19604: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 19605: my (%by_ip,%by_location,@intdoms);
19606: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
19607: my @locations = sort(keys(%by_location));
1.137 raeburn 19608: my (%defaultshash,%changes);
19609: foreach my $prefix (@prefixes) {
19610: $defaultshash{'usersessions'}{$prefix} = {};
19611: }
1.160.6.27 raeburn 19612: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 19613: my $resulttext;
1.138 raeburn 19614: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 19615: foreach my $prefix (@prefixes) {
1.145 raeburn 19616: next if ($prefix eq 'spares');
19617: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 19618: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
19619: if ($type eq 'version') {
19620: my $value = $env{'form.'.$prefix.'_'.$type};
19621: my $okvalue;
19622: if ($value ne '') {
19623: if (grep(/^\Q$value\E$/,@lcversions)) {
19624: $okvalue = $value;
19625: }
19626: }
19627: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19628: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19629: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
19630: if ($inuse == 0) {
19631: $changes{$prefix}{$type} = 1;
19632: } else {
19633: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
19634: $changes{$prefix}{$type} = 1;
19635: }
19636: if ($okvalue ne '') {
19637: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19638: }
19639: }
19640: } else {
19641: if (($inuse == 1) && ($okvalue ne '')) {
19642: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19643: $changes{$prefix}{$type} = 1;
19644: }
19645: }
19646: } else {
19647: if (($inuse == 1) && ($okvalue ne '')) {
19648: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19649: $changes{$prefix}{$type} = 1;
19650: }
19651: }
19652: } else {
19653: if (($inuse == 1) && ($okvalue ne '')) {
19654: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
19655: $changes{$prefix}{$type} = 1;
19656: }
19657: }
19658: } else {
19659: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
19660: my @okvals;
19661: foreach my $val (@vals) {
1.138 raeburn 19662: if ($val =~ /:/) {
19663: my @items = split(/:/,$val);
19664: foreach my $item (@items) {
19665: if (ref($by_location{$item}) eq 'ARRAY') {
19666: push(@okvals,$item);
19667: }
19668: }
19669: } else {
19670: if (ref($by_location{$val}) eq 'ARRAY') {
19671: push(@okvals,$val);
19672: }
1.137 raeburn 19673: }
19674: }
19675: @okvals = sort(@okvals);
19676: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19677: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
19678: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19679: if ($inuse == 0) {
19680: $changes{$prefix}{$type} = 1;
19681: } else {
19682: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19683: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
19684: if (@changed > 0) {
19685: $changes{$prefix}{$type} = 1;
19686: }
19687: }
19688: } else {
19689: if ($inuse == 1) {
19690: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19691: $changes{$prefix}{$type} = 1;
19692: }
19693: }
19694: } else {
19695: if ($inuse == 1) {
19696: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19697: $changes{$prefix}{$type} = 1;
19698: }
19699: }
19700: } else {
19701: if ($inuse == 1) {
19702: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
19703: $changes{$prefix}{$type} = 1;
19704: }
19705: }
19706: }
19707: }
19708: }
1.145 raeburn 19709:
19710: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 19711: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 19712: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
19713: my $savespares;
19714:
19715: foreach my $lonhost (sort(keys(%servers))) {
19716: my $serverhomeID =
19717: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 19718: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 19719: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
19720: my %spareschg;
19721: foreach my $type (@{$types{'spares'}}) {
19722: my @okspares;
19723: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
19724: foreach my $server (@checked) {
1.152 raeburn 19725: if (&Apache::lonnet::hostname($server) ne '') {
19726: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
19727: unless (grep(/^\Q$server\E$/,@okspares)) {
19728: push(@okspares,$server);
19729: }
1.145 raeburn 19730: }
19731: }
19732: }
19733: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
19734: my $newspare;
1.152 raeburn 19735: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
19736: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 19737: $newspare = $new;
19738: }
19739: }
1.152 raeburn 19740: my @spares;
19741: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
19742: @spares = sort(@okspares,$newspare);
19743: } else {
19744: @spares = sort(@okspares);
19745: }
19746: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 19747: if (ref($spareid{$lonhost}) eq 'HASH') {
19748: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 19749: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 19750: if (@diffs > 0) {
19751: $spareschg{$type} = 1;
19752: }
19753: }
19754: }
19755: }
19756: if (keys(%spareschg) > 0) {
19757: $changes{'spares'}{$lonhost} = \%spareschg;
19758: }
19759: }
1.160.6.61 raeburn 19760: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 19761: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 19762: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
19763: my @okoffload;
19764: if (@offloadnow) {
19765: foreach my $server (@offloadnow) {
19766: if (&Apache::lonnet::hostname($server) ne '') {
19767: unless (grep(/^\Q$server\E$/,@okoffload)) {
19768: push(@okoffload,$server);
19769: }
19770: }
19771: }
19772: if (@okoffload) {
19773: foreach my $lonhost (@okoffload) {
19774: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
19775: }
19776: }
19777: }
1.160.6.105 raeburn 19778: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
19779: my @okoffloadoth;
19780: if (@offloadoth) {
19781: foreach my $server (@offloadoth) {
19782: if (&Apache::lonnet::hostname($server) ne '') {
19783: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
19784: push(@okoffloadoth,$server);
19785: }
19786: }
19787: }
19788: if (@okoffloadoth) {
19789: foreach my $lonhost (@okoffloadoth) {
19790: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
19791: }
19792: }
19793: }
1.145 raeburn 19794: if (ref($domconfig{'usersessions'}) eq 'HASH') {
19795: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
19796: if (ref($changes{'spares'}) eq 'HASH') {
19797: if (keys(%{$changes{'spares'}}) > 0) {
19798: $savespares = 1;
19799: }
19800: }
19801: } else {
19802: $savespares = 1;
19803: }
1.160.6.105 raeburn 19804: foreach my $offload ('offloadnow','offloadoth') {
19805: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
19806: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
19807: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
19808: $changes{$offload} = 1;
1.160.6.61 raeburn 19809: last;
19810: }
19811: }
1.160.6.105 raeburn 19812: unless ($changes{$offload}) {
19813: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
19814: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
19815: $changes{$offload} = 1;
19816: last;
19817: }
19818: }
19819: }
19820: } else {
19821: if (($offload eq 'offloadnow') && (@okoffload)) {
19822: $changes{'offloadnow'} = 1;
19823: }
19824: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
19825: $changes{'offloadoth'} = 1;
19826: }
1.160.6.61 raeburn 19827: }
1.160.6.105 raeburn 19828: }
19829: } else {
19830: if (@okoffload) {
1.160.6.61 raeburn 19831: $changes{'offloadnow'} = 1;
19832: }
1.160.6.105 raeburn 19833: if (@okoffloadoth) {
19834: $changes{'offloadoth'} = 1;
19835: }
1.145 raeburn 19836: }
1.147 raeburn 19837: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
19838: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 19839: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19840: $dom);
19841: if ($putresult eq 'ok') {
19842: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
19843: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
19844: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
19845: }
19846: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
19847: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
19848: }
1.160.6.61 raeburn 19849: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
19850: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
19851: }
1.160.6.105 raeburn 19852: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
19853: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
19854: }
1.137 raeburn 19855: }
19856: my $cachetime = 24*60*60;
19857: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 19858: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 19859: if (ref($lastactref) eq 'HASH') {
19860: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 19861: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 19862: }
1.147 raeburn 19863: if (keys(%changes) > 0) {
19864: my %lt = &usersession_titles();
19865: $resulttext = &mt('Changes made:').'<ul>';
19866: foreach my $prefix (@prefixes) {
19867: if (ref($changes{$prefix}) eq 'HASH') {
19868: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
19869: if ($prefix eq 'spares') {
19870: if (ref($changes{$prefix}) eq 'HASH') {
19871: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
19872: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 19873: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 19874: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
19875: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 19876: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
19877: foreach my $type (@{$types{$prefix}}) {
19878: if ($changes{$prefix}{$lonhost}{$type}) {
19879: my $offloadto = &mt('None');
19880: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
19881: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
19882: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
19883: }
1.145 raeburn 19884: }
1.147 raeburn 19885: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 19886: }
1.137 raeburn 19887: }
19888: }
1.147 raeburn 19889: $resulttext .= '</li>';
1.137 raeburn 19890: }
19891: }
1.147 raeburn 19892: } else {
19893: foreach my $type (@{$types{$prefix}}) {
19894: if (defined($changes{$prefix}{$type})) {
19895: my $newvalue;
19896: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
19897: if (ref($defaultshash{'usersessions'}{$prefix})) {
19898: if ($type eq 'version') {
19899: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
19900: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
19901: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
19902: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
19903: }
1.145 raeburn 19904: }
19905: }
19906: }
1.147 raeburn 19907: if ($newvalue eq '') {
19908: if ($type eq 'version') {
19909: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
19910: } else {
19911: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
19912: }
1.145 raeburn 19913: } else {
1.147 raeburn 19914: if ($type eq 'version') {
1.160.6.118.2 14(raebu 19915:23): $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 19916: }
19917: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 19918: }
1.137 raeburn 19919: }
19920: }
19921: }
1.147 raeburn 19922: $resulttext .= '</ul>';
1.137 raeburn 19923: }
19924: }
1.160.6.61 raeburn 19925: if ($changes{'offloadnow'}) {
19926: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
19927: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 19928: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 19929: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
19930: $resulttext .= '<li>'.$lonhost.'</li>';
19931: }
19932: $resulttext .= '</ul>';
19933: } else {
1.160.6.105 raeburn 19934: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
19935: }
19936: } else {
19937: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
19938: }
19939: }
19940: if ($changes{'offloadoth'}) {
19941: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
19942: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
19943: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
19944: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
19945: $resulttext .= '<li>'.$lonhost.'</li>';
19946: }
19947: $resulttext .= '</ul>';
19948: } else {
19949: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 19950: }
19951: } else {
1.160.6.105 raeburn 19952: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 19953: }
19954: }
1.147 raeburn 19955: $resulttext .= '</ul>';
19956: } else {
19957: $resulttext = $nochgmsg;
1.137 raeburn 19958: }
19959: } else {
19960: $resulttext = '<span class="LC_error">'.
19961: &mt('An error occurred: [_1]',$putresult).'</span>';
19962: }
19963: } else {
1.147 raeburn 19964: $resulttext = $nochgmsg;
1.137 raeburn 19965: }
19966: return $resulttext;
19967: }
19968:
1.150 raeburn 19969: sub modify_loadbalancing {
19970: my ($dom,%domconfig) = @_;
19971: my $primary_id = &Apache::lonnet::domain($dom,'primary');
19972: my $intdom = &Apache::lonnet::internet_dom($primary_id);
19973: my ($othertitle,$usertypes,$types) =
19974: &Apache::loncommon::sorted_inst_types($dom);
19975: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 19976: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 19977: my @sparestypes = ('primary','default');
19978: my %typetitles = &sparestype_titles();
19979: my $resulttext;
1.160.6.94 raeburn 19980: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 19981: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
19982: %existing = %{$domconfig{'loadbalancing'}};
19983: }
19984: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 19985: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 19986: my ($saveloadbalancing,%defaultshash,%changes);
19987: my ($alltypes,$othertypes,$titles) =
19988: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
19989: my %ruletitles = &offloadtype_text();
19990: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
19991: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
19992: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
19993: if ($balancer eq '') {
19994: next;
19995: }
19996: if (!exists($servers{$balancer})) {
19997: if (exists($currbalancer{$balancer})) {
19998: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 19999: }
1.160.6.7 raeburn 20000: next;
20001: }
20002: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20003: push(@{$changes{'delete'}},$balancer);
20004: next;
20005: }
20006: if (!exists($currbalancer{$balancer})) {
20007: push(@{$changes{'add'}},$balancer);
20008: }
20009: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20010: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20011: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20012: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20013: $saveloadbalancing = 1;
20014: }
20015: foreach my $sparetype (@sparestypes) {
20016: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20017: my @offloadto;
20018: foreach my $target (@targets) {
20019: if (($servers{$target}) && ($target ne $balancer)) {
20020: if ($sparetype eq 'default') {
20021: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20022: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20023: }
20024: }
1.160.6.7 raeburn 20025: unless(grep(/^\Q$target\E$/,@offloadto)) {
20026: push(@offloadto,$target);
20027: }
1.150 raeburn 20028: }
20029: }
1.160.6.76 raeburn 20030: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20031: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20032: push(@offloadto,$balancer);
20033: }
20034: }
20035: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20036: }
1.160.6.94 raeburn 20037: if ($env{'form.loadbalancing_cookie_'.$i}) {
20038: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20039: if (exists($currbalancer{$balancer})) {
20040: unless ($currcookies{$balancer}) {
20041: $changes{'curr'}{$balancer}{'cookie'} = 1;
20042: }
20043: }
20044: } elsif (exists($currbalancer{$balancer})) {
20045: if ($currcookies{$balancer}) {
20046: $changes{'curr'}{$balancer}{'cookie'} = 1;
20047: }
20048: }
1.160.6.7 raeburn 20049: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20050: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 20051: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20052: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20053: if (@targetdiffs > 0) {
1.160.6.7 raeburn 20054: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20055: }
1.160.6.7 raeburn 20056: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20057: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20058: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20059: }
20060: }
20061: }
20062: } else {
1.160.6.7 raeburn 20063: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
20064: foreach my $sparetype (@sparestypes) {
20065: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20066: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20067: $changes{'curr'}{$balancer}{'targets'} = 1;
20068: }
1.150 raeburn 20069: }
20070: }
1.160.6.7 raeburn 20071: }
1.150 raeburn 20072: }
20073: my $ishomedom;
1.160.6.7 raeburn 20074: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20075: $ishomedom = 1;
1.150 raeburn 20076: }
20077: if (ref($alltypes) eq 'ARRAY') {
20078: foreach my $type (@{$alltypes}) {
20079: my $rule;
1.160.6.7 raeburn 20080: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20081: (!$ishomedom)) {
1.160.6.7 raeburn 20082: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20083: }
20084: if ($rule eq 'specific') {
1.160.6.55 raeburn 20085: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
20086: if (exists($servers{$specifiedhost})) {
20087: $rule = $specifiedhost;
20088: }
1.150 raeburn 20089: }
1.160.6.7 raeburn 20090: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20091: if (ref($currrules{$balancer}) eq 'HASH') {
20092: if ($rule ne $currrules{$balancer}{$type}) {
20093: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20094: }
20095: } elsif ($rule ne '') {
1.160.6.7 raeburn 20096: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20097: }
20098: }
20099: }
1.160.6.7 raeburn 20100: }
20101: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20102: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20103: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20104: $defaultshash{'loadbalancing'} = {};
20105: }
20106: my $putresult = &Apache::lonnet::put_dom('configuration',
20107: \%defaultshash,$dom);
20108: if ($putresult eq 'ok') {
20109: if (keys(%changes) > 0) {
1.160.6.54 raeburn 20110: my %toupdate;
1.160.6.7 raeburn 20111: if (ref($changes{'delete'}) eq 'ARRAY') {
20112: foreach my $balancer (sort(@{$changes{'delete'}})) {
20113: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 20114: $toupdate{$balancer} = 1;
1.150 raeburn 20115: }
1.160.6.7 raeburn 20116: }
20117: if (ref($changes{'add'}) eq 'ARRAY') {
20118: foreach my $balancer (sort(@{$changes{'add'}})) {
20119: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 20120: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20121: }
20122: }
20123: if (ref($changes{'curr'}) eq 'HASH') {
20124: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 20125: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20126: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20127: if ($changes{'curr'}{$balancer}{'targets'}) {
20128: my %offloadstr;
20129: foreach my $sparetype (@sparestypes) {
20130: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20131: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20132: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20133: }
20134: }
1.150 raeburn 20135: }
1.160.6.7 raeburn 20136: if (keys(%offloadstr) == 0) {
20137: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20138: } else {
1.160.6.7 raeburn 20139: my $showoffload;
20140: foreach my $sparetype (@sparestypes) {
20141: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20142: if (defined($offloadstr{$sparetype})) {
20143: $showoffload .= $offloadstr{$sparetype};
20144: } else {
20145: $showoffload .= &mt('None');
20146: }
20147: $showoffload .= (' 'x3);
20148: }
20149: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20150: }
20151: }
20152: }
1.160.6.7 raeburn 20153: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20154: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20155: foreach my $type (@{$alltypes}) {
20156: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20157: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20158: my $balancetext;
20159: if ($rule eq '') {
20160: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 20161: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 20162: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20163: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 20164: foreach my $sparetype (@sparestypes) {
20165: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20166: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20167: }
20168: }
1.160.6.55 raeburn 20169: foreach my $item (@{$alltypes}) {
20170: next if ($item =~ /^_LC_ipchange/);
20171: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20172: if ($hasrule eq 'homeserver') {
20173: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20174: } else {
20175: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20176: if ($servers{$hasrule}) {
20177: $toupdate{$hasrule} = 1;
20178: }
20179: }
20180: }
20181: }
20182: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20183: $balancetext = $ruletitles{$rule};
20184: } else {
20185: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20186: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20187: if ($receiver) {
20188: $toupdate{$receiver};
20189: }
20190: }
20191: } else {
20192: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 20193: }
1.160.6.7 raeburn 20194: } else {
20195: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20196: }
1.160.6.26 raeburn 20197: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20198: }
20199: }
20200: }
20201: }
1.160.6.94 raeburn 20202: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 20203: if ($currcookies{$balancer}) {
20204: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20205: $balancer).'</li>';
20206: } else {
20207: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20208: $balancer).'</li>';
20209: }
1.160.6.94 raeburn 20210: }
1.160.6.106 raeburn 20211: }
20212: }
20213: if (keys(%toupdate)) {
20214: my %thismachine;
20215: my $updatedhere;
20216: my $cachetime = 60*60*24;
20217: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20218: foreach my $lonhost (keys(%toupdate)) {
20219: if ($thismachine{$lonhost}) {
20220: unless ($updatedhere) {
20221: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20222: $defaultshash{'loadbalancing'},
20223: $cachetime);
20224: $updatedhere = 1;
1.160.6.54 raeburn 20225: }
1.160.6.106 raeburn 20226: } else {
20227: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20228: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 20229: }
1.150 raeburn 20230: }
1.160.6.7 raeburn 20231: }
20232: if ($resulttext ne '') {
20233: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20234: } else {
20235: $resulttext = $nochgmsg;
20236: }
20237: } else {
1.160.6.7 raeburn 20238: $resulttext = $nochgmsg;
1.150 raeburn 20239: }
20240: } else {
1.160.6.7 raeburn 20241: $resulttext = '<span class="LC_error">'.
20242: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20243: }
20244: } else {
1.160.6.7 raeburn 20245: $resulttext = $nochgmsg;
1.150 raeburn 20246: }
20247: return $resulttext;
20248: }
20249:
1.48 raeburn 20250: sub recurse_check {
20251: my ($chkcats,$categories,$depth,$name) = @_;
20252: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20253: my $chg = 0;
20254: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20255: my $category = $chkcats->[$depth]{$name}[$j];
20256: my $item;
20257: if ($category eq '') {
20258: $chg ++;
20259: } else {
20260: my $deeper = $depth + 1;
20261: $item = &escape($category).':'.&escape($name).':'.$depth;
20262: if ($chg) {
20263: $categories->{$item} -= $chg;
20264: }
20265: &recurse_check($chkcats,$categories,$deeper,$category);
20266: $deeper --;
20267: }
20268: }
20269: }
20270: return;
20271: }
20272:
20273: sub recurse_cat_deletes {
20274: my ($item,$coursecategories,$deletions) = @_;
20275: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20276: my $subdepth = $depth + 1;
20277: if (ref($coursecategories) eq 'HASH') {
20278: foreach my $subitem (keys(%{$coursecategories})) {
20279: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20280: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20281: delete($coursecategories->{$subitem});
20282: $deletions->{$subitem} = 1;
20283: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 20284: }
1.48 raeburn 20285: }
20286: }
20287: return;
20288: }
20289:
1.125 raeburn 20290: sub active_dc_picker {
1.160.6.16 raeburn 20291: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 20292: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 20293: my @domcoord = keys(%domcoords);
20294: if (keys(%currhash)) {
20295: foreach my $dc (keys(%currhash)) {
20296: unless (exists($domcoords{$dc})) {
20297: push(@domcoord,$dc);
20298: }
20299: }
20300: }
20301: @domcoord = sort(@domcoord);
20302: my $numdcs = scalar(@domcoord);
20303: my $rows = 0;
20304: my $table;
1.125 raeburn 20305: if ($numdcs > 1) {
1.160.6.16 raeburn 20306: $table = '<table>';
20307: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20308: my $rem = $i%($numinrow);
20309: if ($rem == 0) {
20310: if ($i > 0) {
1.160.6.16 raeburn 20311: $table .= '</tr>';
1.125 raeburn 20312: }
1.160.6.16 raeburn 20313: $table .= '<tr>';
20314: $rows ++;
1.125 raeburn 20315: }
1.160.6.16 raeburn 20316: my $check = '';
20317: if ($inputtype eq 'radio') {
20318: if (keys(%currhash) == 0) {
20319: if (!$i) {
20320: $check = ' checked="checked"';
20321: }
20322: } elsif (exists($currhash{$domcoord[$i]})) {
20323: $check = ' checked="checked"';
20324: }
20325: } else {
20326: if (exists($currhash{$domcoord[$i]})) {
20327: $check = ' checked="checked"';
1.125 raeburn 20328: }
20329: }
1.160.6.16 raeburn 20330: if ($i == @domcoord - 1) {
1.125 raeburn 20331: my $colsleft = $numinrow - $rem;
20332: if ($colsleft > 1) {
1.160.6.16 raeburn 20333: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20334: } else {
1.160.6.16 raeburn 20335: $table .= '<td class="LC_left_item">';
1.125 raeburn 20336: }
20337: } else {
1.160.6.16 raeburn 20338: $table .= '<td class="LC_left_item">';
20339: }
20340: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20341: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20342: $table .= '<span class="LC_nobreak"><label>'.
20343: '<input type="'.$inputtype.'" name="'.$name.'"'.
20344: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20345: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 20346: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 20347: }
1.160.6.33 raeburn 20348: $table .= '</label></span></td>';
1.125 raeburn 20349: }
1.160.6.16 raeburn 20350: $table .= '</tr></table>';
20351: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 20352: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20353: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 20354: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 20355: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 20356: if ($user ne $dcname.':'.$dcdom) {
20357: $table .= ' ('.$dcname.':'.$dcdom.')';
20358: }
1.160.6.16 raeburn 20359: } else {
20360: my $check;
20361: if (exists($currhash{$domcoord[0]})) {
20362: $check = ' checked="checked"';
20363: }
1.160.6.50 raeburn 20364: $table = '<span class="LC_nobreak"><label>'.
20365: '<input type="checkbox" name="'.$name.'" '.
20366: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 20367: if ($user ne $dcname.':'.$dcdom) {
20368: $table .= ' ('.$dcname.':'.$dcdom.')';
20369: }
20370: $table .= '</label></span>';
1.160.6.16 raeburn 20371: $rows ++;
20372: }
1.125 raeburn 20373: }
1.160.6.16 raeburn 20374: return ($numdcs,$table,$rows);
1.125 raeburn 20375: }
20376:
1.137 raeburn 20377: sub usersession_titles {
20378: return &Apache::lonlocal::texthash(
20379: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20380: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20381: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20382: version => 'LON-CAPA version requirement',
1.138 raeburn 20383: excludedomain => 'Allow all, but exclude specific domains',
20384: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20385: primary => 'Primary (checked first)',
1.154 raeburn 20386: default => 'Default',
1.137 raeburn 20387: );
20388: }
20389:
1.152 raeburn 20390: sub id_for_thisdom {
20391: my (%servers) = @_;
20392: my %altids;
20393: foreach my $server (keys(%servers)) {
20394: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20395: if ($serverhome ne $server) {
20396: $altids{$serverhome} = $server;
20397: }
20398: }
20399: return %altids;
20400: }
20401:
1.150 raeburn 20402: sub count_servers {
20403: my ($currbalancer,%servers) = @_;
20404: my (@spares,$numspares);
20405: foreach my $lonhost (sort(keys(%servers))) {
20406: next if ($currbalancer eq $lonhost);
20407: push(@spares,$lonhost);
20408: }
20409: if ($currbalancer) {
20410: $numspares = scalar(@spares);
20411: } else {
20412: $numspares = scalar(@spares) - 1;
20413: }
20414: return ($numspares,@spares);
20415: }
20416:
20417: sub lonbalance_targets_js {
1.160.6.7 raeburn 20418: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 20419: my $select = &mt('Select');
20420: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20421: if (ref($servers) eq 'HASH') {
20422: $alltargets = join("','",sort(keys(%{$servers})));
20423: my @homedoms;
20424: foreach my $server (sort(keys(%{$servers}))) {
20425: if (&Apache::lonnet::host_domain($server) eq $dom) {
20426: push(@homedoms,'1');
20427: } else {
20428: push(@homedoms,'0');
20429: }
20430: }
20431: $allishome = join("','",@homedoms);
20432: }
20433: if (ref($types) eq 'ARRAY') {
20434: if (@{$types} > 0) {
20435: @alltypes = @{$types};
20436: }
20437: }
20438: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
20439: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 20440: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 20441: if (ref($settings) eq 'HASH') {
20442: %existing = %{$settings};
20443: }
20444: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 20445: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 20446: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 20447: return <<"END";
20448:
20449: <script type="text/javascript">
20450: // <![CDATA[
20451:
1.160.6.7 raeburn 20452: currBalancers = new Array('$balancers');
20453:
20454: function toggleTargets(balnum) {
20455: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20456: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
20457: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
20458: var prevbalancer = prevhostitem.value;
20459: var baltotal = document.getElementById('loadbalancing_total').value;
20460: prevhostitem.value = balancer;
20461: if (prevbalancer != '') {
20462: var prevIdx = currBalancers.indexOf(prevbalancer);
20463: if (prevIdx != -1) {
20464: currBalancers.splice(prevIdx,1);
20465: }
20466: }
1.150 raeburn 20467: if (balancer == '') {
1.160.6.7 raeburn 20468: hideSpares(balnum);
1.150 raeburn 20469: } else {
1.160.6.7 raeburn 20470: var currIdx = currBalancers.indexOf(balancer);
20471: if (currIdx == -1) {
20472: currBalancers.push(balancer);
20473: }
1.150 raeburn 20474: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 20475: var ishomedom = homedoms[lonhostitem.selectedIndex];
20476: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 20477: }
1.160.6.7 raeburn 20478: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 20479: return;
20480: }
20481:
1.160.6.7 raeburn 20482: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 20483: var alltargets = new Array('$alltargets');
20484: var insttypes = new Array('$allinsttypes');
1.151 raeburn 20485: var offloadtypes = new Array('primary','default');
20486:
1.160.6.7 raeburn 20487: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
20488: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 20489:
1.151 raeburn 20490: for (var i=0; i<offloadtypes.length; i++) {
20491: var count = 0;
20492: for (var j=0; j<alltargets.length; j++) {
20493: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 20494: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
20495: item.value = alltargets[j];
20496: item.style.textAlign='left';
20497: item.style.textFace='normal';
20498: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
20499: if (currBalancers.indexOf(alltargets[j]) == -1) {
20500: item.disabled = '';
20501: } else {
20502: item.disabled = 'disabled';
20503: item.checked = false;
20504: }
1.151 raeburn 20505: count ++;
20506: }
1.150 raeburn 20507: }
20508: }
1.151 raeburn 20509: for (var k=0; k<insttypes.length; k++) {
20510: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 20511: if (ishomedom == 1) {
1.160.6.7 raeburn 20512: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
20513: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 20514: } else {
1.160.6.7 raeburn 20515: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
20516: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 20517: }
20518: } else {
1.160.6.7 raeburn 20519: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
20520: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 20521: }
1.151 raeburn 20522: if ((insttypes[k] != '_LC_external') &&
20523: ((insttypes[k] != '_LC_internetdom') ||
20524: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 20525: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
20526: item.options.length = 0;
20527: item.options[0] = new Option("","",true,true);
20528: var idx = 0;
1.151 raeburn 20529: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 20530: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
20531: idx ++;
20532: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 20533: }
20534: }
20535: }
20536: }
20537: return;
20538: }
20539:
1.160.6.7 raeburn 20540: function hideSpares(balnum) {
1.150 raeburn 20541: var alltargets = new Array('$alltargets');
20542: var insttypes = new Array('$allinsttypes');
20543: var offloadtypes = new Array('primary','default');
20544:
1.160.6.7 raeburn 20545: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
20546: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 20547:
20548: var total = alltargets.length - 1;
20549: for (var i=0; i<offloadtypes; i++) {
20550: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 20551: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
20552: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
20553: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 20554: }
1.150 raeburn 20555: }
20556: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 20557: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
20558: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 20559: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 20560: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
20561: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 20562: }
20563: }
20564: return;
20565: }
20566:
1.160.6.7 raeburn 20567: function checkOffloads(item,balnum,type) {
1.150 raeburn 20568: var alltargets = new Array('$alltargets');
20569: var offloadtypes = new Array('primary','default');
20570: if (item.checked) {
20571: var total = alltargets.length - 1;
20572: var other;
20573: if (type == offloadtypes[0]) {
1.151 raeburn 20574: other = offloadtypes[1];
1.150 raeburn 20575: } else {
1.151 raeburn 20576: other = offloadtypes[0];
1.150 raeburn 20577: }
20578: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 20579: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 20580: if (server == item.value) {
1.160.6.7 raeburn 20581: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
20582: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 20583: }
20584: }
20585: }
20586: }
20587: return;
20588: }
20589:
1.160.6.7 raeburn 20590: function singleServerToggle(balnum,type) {
20591: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 20592: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 20593: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
20594: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 20595:
20596: } else {
1.160.6.7 raeburn 20597: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
20598: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 20599: }
20600: return;
20601: }
20602:
1.160.6.7 raeburn 20603: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 20604: if (type == '_LC_external') {
1.160.6.26 raeburn 20605: return;
1.150 raeburn 20606: }
1.160.6.7 raeburn 20607: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 20608: for (var i=0; i<typesRules.length; i++) {
20609: if (formname.elements[typesRules[i]].checked) {
20610: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 20611: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
20612: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 20613: } else {
1.160.6.7 raeburn 20614: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
20615: }
20616: }
20617: }
20618: return;
20619: }
20620:
20621: function balancerDeleteChange(balnum) {
20622: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
20623: var baltotal = document.getElementById('loadbalancing_total').value;
20624: var addtarget;
20625: var removetarget;
20626: var action = 'delete';
20627: if (document.getElementById('loadbalancing_delete_'+balnum)) {
20628: var lonhost = hostitem.value;
20629: var currIdx = currBalancers.indexOf(lonhost);
20630: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
20631: if (currIdx != -1) {
20632: currBalancers.splice(currIdx,1);
20633: }
20634: addtarget = lonhost;
20635: } else {
20636: if (currIdx == -1) {
20637: currBalancers.push(lonhost);
20638: }
20639: removetarget = lonhost;
20640: action = 'undelete';
20641: }
20642: balancerChange(balnum,baltotal,action,addtarget,removetarget);
20643: }
20644: return;
20645: }
20646:
20647: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
20648: if (baltotal > 1) {
20649: var offloadtypes = new Array('primary','default');
20650: var alltargets = new Array('$alltargets');
20651: var insttypes = new Array('$allinsttypes');
20652: for (var i=0; i<baltotal; i++) {
20653: if (i != balnum) {
20654: for (var j=0; j<offloadtypes.length; j++) {
20655: var total = alltargets.length - 1;
20656: for (var k=0; k<total; k++) {
20657: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
20658: var server = serveritem.value;
20659: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
20660: if (server == addtarget) {
20661: serveritem.disabled = '';
20662: }
20663: }
20664: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
20665: if (server == removetarget) {
20666: serveritem.disabled = 'disabled';
20667: serveritem.checked = false;
20668: }
20669: }
20670: }
20671: }
20672: for (var j=0; j<insttypes.length; j++) {
20673: if (insttypes[j] != '_LC_external') {
20674: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
20675: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
20676: var currSel = singleserver.selectedIndex;
20677: var currVal = singleserver.options[currSel].value;
20678: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
20679: var numoptions = singleserver.options.length;
20680: var needsnew = 1;
20681: for (var k=0; k<numoptions; k++) {
20682: if (singleserver.options[k] == addtarget) {
20683: needsnew = 0;
20684: break;
20685: }
20686: }
20687: if (needsnew == 1) {
20688: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
20689: }
20690: }
20691: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
20692: singleserver.options.length = 0;
20693: if ((currVal) && (currVal != removetarget)) {
20694: singleserver.options[0] = new Option("","",false,false);
20695: } else {
20696: singleserver.options[0] = new Option("","",true,true);
20697: }
20698: var idx = 0;
20699: for (var m=0; m<alltargets.length; m++) {
20700: if (currBalancers.indexOf(alltargets[m]) == -1) {
20701: idx ++;
20702: if (currVal == alltargets[m]) {
20703: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
20704: } else {
20705: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
20706: }
20707: }
20708: }
20709: }
20710: }
20711: }
20712: }
1.150 raeburn 20713: }
20714: }
20715: }
20716: return;
20717: }
20718:
1.152 raeburn 20719: // ]]>
20720: </script>
20721:
20722: END
20723: }
20724:
20725: sub new_spares_js {
20726: my @sparestypes = ('primary','default');
20727: my $types = join("','",@sparestypes);
20728: my $select = &mt('Select');
20729: return <<"END";
20730:
20731: <script type="text/javascript">
20732: // <![CDATA[
20733:
20734: function updateNewSpares(formname,lonhost) {
20735: var types = new Array('$types');
20736: var include = new Array();
20737: var exclude = new Array();
20738: for (var i=0; i<types.length; i++) {
20739: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
20740: for (var j=0; j<spareboxes.length; j++) {
20741: if (formname.elements[spareboxes[j]].checked) {
20742: exclude.push(formname.elements[spareboxes[j]].value);
20743: } else {
20744: include.push(formname.elements[spareboxes[j]].value);
20745: }
20746: }
20747: }
20748: for (var i=0; i<types.length; i++) {
20749: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
20750: var selIdx = newSpare.selectedIndex;
20751: var currnew = newSpare.options[selIdx].value;
20752: var okSpares = new Array();
20753: for (var j=0; j<newSpare.options.length; j++) {
20754: var possible = newSpare.options[j].value;
20755: if (possible != '') {
20756: if (exclude.indexOf(possible) == -1) {
20757: okSpares.push(possible);
20758: } else {
20759: if (currnew == possible) {
20760: selIdx = 0;
20761: }
20762: }
20763: }
20764: }
20765: for (var k=0; k<include.length; k++) {
20766: if (okSpares.indexOf(include[k]) == -1) {
20767: okSpares.push(include[k]);
20768: }
20769: }
20770: okSpares.sort();
20771: newSpare.options.length = 0;
20772: if (selIdx == 0) {
20773: newSpare.options[0] = new Option("$select","",true,true);
20774: } else {
20775: newSpare.options[0] = new Option("$select","",false,false);
20776: }
20777: for (var m=0; m<okSpares.length; m++) {
20778: var idx = m+1;
20779: var selThis = 0;
20780: if (selIdx != 0) {
20781: if (okSpares[m] == currnew) {
20782: selThis = 1;
20783: }
20784: }
20785: if (selThis == 1) {
20786: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
20787: } else {
20788: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
20789: }
20790: }
20791: }
20792: return;
20793: }
20794:
20795: function checkNewSpares(lonhost,type) {
20796: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
20797: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.160.6.118.2 14(raebu 20798:23): if (chosen != '') {
1.152 raeburn 20799: var othertype;
20800: var othernewSpare;
20801: if (type == 'primary') {
20802: othernewSpare = document.getElementById('newspare_default_'+lonhost);
20803: }
20804: if (type == 'default') {
20805: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
20806: }
20807: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
20808: othernewSpare.selectedIndex = 0;
20809: }
20810: }
20811: return;
20812: }
20813:
20814: // ]]>
20815: </script>
20816:
20817: END
20818:
20819: }
20820:
20821: sub common_domprefs_js {
20822: return <<"END";
20823:
20824: <script type="text/javascript">
20825: // <![CDATA[
20826:
1.150 raeburn 20827: function getIndicesByName(formname,item) {
1.152 raeburn 20828: var group = new Array();
1.150 raeburn 20829: for (var i=0;i<formname.elements.length;i++) {
20830: if (formname.elements[i].name == item) {
1.152 raeburn 20831: group.push(formname.elements[i].id);
1.150 raeburn 20832: }
20833: }
1.152 raeburn 20834: return group;
1.150 raeburn 20835: }
20836:
20837: // ]]>
20838: </script>
20839:
20840: END
1.152 raeburn 20841:
1.150 raeburn 20842: }
20843:
1.160.6.5 raeburn 20844: sub recaptcha_js {
20845: my %lt = &captcha_phrases();
20846: return <<"END";
20847:
20848: <script type="text/javascript">
20849: // <![CDATA[
20850:
20851: function updateCaptcha(caller,context) {
20852: var privitem;
20853: var pubitem;
20854: var privtext;
20855: var pubtext;
1.160.6.69 raeburn 20856: var versionitem;
20857: var versiontext;
1.160.6.5 raeburn 20858: if (document.getElementById(context+'_recaptchapub')) {
20859: pubitem = document.getElementById(context+'_recaptchapub');
20860: } else {
20861: return;
20862: }
20863: if (document.getElementById(context+'_recaptchapriv')) {
20864: privitem = document.getElementById(context+'_recaptchapriv');
20865: } else {
20866: return;
20867: }
20868: if (document.getElementById(context+'_recaptchapubtxt')) {
20869: pubtext = document.getElementById(context+'_recaptchapubtxt');
20870: } else {
20871: return;
20872: }
20873: if (document.getElementById(context+'_recaptchaprivtxt')) {
20874: privtext = document.getElementById(context+'_recaptchaprivtxt');
20875: } else {
20876: return;
20877: }
1.160.6.69 raeburn 20878: if (document.getElementById(context+'_recaptchaversion')) {
20879: versionitem = document.getElementById(context+'_recaptchaversion');
20880: } else {
20881: return;
20882: }
20883: if (document.getElementById(context+'_recaptchavertxt')) {
20884: versiontext = document.getElementById(context+'_recaptchavertxt');
20885: } else {
20886: return;
20887: }
1.160.6.5 raeburn 20888: if (caller.checked) {
20889: if (caller.value == 'recaptcha') {
20890: pubitem.type = 'text';
20891: privitem.type = 'text';
20892: pubitem.size = '40';
20893: privitem.size = '40';
20894: pubtext.innerHTML = "$lt{'pub'}";
20895: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 20896: versionitem.type = 'text';
20897: versionitem.size = '3';
20898: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 20899: } else {
20900: pubitem.type = 'hidden';
20901: privitem.type = 'hidden';
1.160.6.69 raeburn 20902: versionitem.type = 'hidden';
1.160.6.5 raeburn 20903: pubtext.innerHTML = '';
20904: privtext.innerHTML = '';
1.160.6.69 raeburn 20905: versiontext.innerHTML = '';
1.160.6.5 raeburn 20906: }
20907: }
20908: return;
20909: }
20910:
20911: // ]]>
20912: </script>
20913:
20914: END
20915:
20916: }
20917:
1.160.6.40 raeburn 20918: sub toggle_display_js {
1.160.6.16 raeburn 20919: return <<"END";
20920:
20921: <script type="text/javascript">
20922: // <![CDATA[
20923:
1.160.6.40 raeburn 20924: function toggleDisplay(domForm,caller) {
20925: if (document.getElementById(caller)) {
20926: var divitem = document.getElementById(caller);
20927: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 20928: var checkval = 1;
20929: var dispval = 'block';
1.160.6.93 raeburn 20930: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 20931: if (caller == 'emailoptions') {
1.160.6.118.2 14(raebu 20932:23): optionsElement = domForm.cancreate_email;
1.160.6.40 raeburn 20933: }
1.160.6.57 raeburn 20934: if (caller == 'studentsubmission') {
20935: optionsElement = domForm.postsubmit;
20936: }
1.160.6.64 raeburn 20937: if (caller == 'cloneinstcode') {
20938: optionsElement = domForm.canclone;
20939: checkval = 'instcode';
20940: }
1.160.6.93 raeburn 20941: if (selfcreateRegExp.test(caller)) {
20942: optionsElement = domForm.elements[caller];
20943: checkval = 'other';
20944: dispval = 'inline'
20945: }
1.160.6.40 raeburn 20946: if (optionsElement.length) {
1.160.6.16 raeburn 20947: var currval;
1.160.6.40 raeburn 20948: for (var i=0; i<optionsElement.length; i++) {
20949: if (optionsElement[i].checked) {
20950: currval = optionsElement[i].value;
1.160.6.16 raeburn 20951: }
20952: }
1.160.6.64 raeburn 20953: if (currval == checkval) {
20954: divitem.style.display = dispval;
1.160.6.16 raeburn 20955: } else {
1.160.6.40 raeburn 20956: divitem.style.display = 'none';
1.160.6.16 raeburn 20957: }
20958: }
20959: }
20960: return;
20961: }
20962:
20963: // ]]>
20964: </script>
20965:
20966: END
20967:
20968: }
20969:
1.160.6.5 raeburn 20970: sub captcha_phrases {
20971: return &Apache::lonlocal::texthash (
20972: priv => 'Private key',
20973: pub => 'Public key',
20974: original => 'original (CAPTCHA)',
20975: recaptcha => 'successor (ReCAPTCHA)',
20976: notused => 'unused',
1.160.6.69 raeburn 20977: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 20978: );
20979: }
20980:
1.160.6.24 raeburn 20981: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 20982: my ($dom,$cachekeys) = @_;
20983: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 20984: my %servers = &Apache::lonnet::internet_dom_servers($dom);
20985: my %thismachine;
20986: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 20987:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 20988: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
20989: 'ipaccess');
20990: my %cache_by_lonhost;
20991: if (exists($cachekeys->{'samllanding'})) {
20992: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
20993: my %landing = %{$cachekeys->{'samllanding'}};
20994: my %domservers = &Apache::lonnet::get_servers($dom);
20995: if (keys(%domservers)) {
20996: foreach my $server (keys(%domservers)) {
20997: my @cached;
20998: next if ($thismachine{$server});
20999: if ($landing{$server}) {
21000: push(@cached,&escape('samllanding').':'.&escape($server));
21001: }
21002: if (@cached) {
21003: $cache_by_lonhost{$server} = \@cached;
21004: }
21005: }
21006: }
21007: }
21008: }
1.160.6.61 raeburn 21009: if (keys(%servers)) {
1.160.6.24 raeburn 21010: foreach my $server (keys(%servers)) {
21011: next if ($thismachine{$server});
1.160.6.27 raeburn 21012: my @cached;
21013: foreach my $name (@posscached) {
21014: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 21015: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
21016: if (ref($cachekeys->{$name}) eq 'HASH') {
21017: foreach my $key (keys(%{$cachekeys->{$name}})) {
21018: push(@cached,&escape($name).':'.&escape($key));
21019: }
21020: }
21021: } else {
21022: push(@cached,&escape($name).':'.&escape($dom));
21023: }
1.160.6.27 raeburn 21024: }
21025: }
1.160.6.113 raeburn 21026: if ((exists($cache_by_lonhost{$server})) &&
21027: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
21028: push(@cached,@{$cache_by_lonhost{$server}});
21029: }
1.160.6.27 raeburn 21030: if (@cached) {
21031: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21032: }
1.160.6.24 raeburn 21033: }
21034: }
21035: return;
21036: }
21037:
1.3 raeburn 21038: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>