Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.22
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 22(raebu 4:24): # $Id: domainprefs.pm,v 1.160.6.118.2.21 2024/03/03 02:21:32 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.118.2 20(raebu 98:24): used by course owners to request creation of a course.
1.160.6.20 raeburn 99:
1.101 raeburn 100: Outputs: 1
101:
102: $datatable - HTML containing form elements which allow settings to be changed.
103:
104: In the case of course requests, radio buttons are displayed for each institutional
105: affiliate type (and also default, and _LC_adv) for each of the course types
1.160.6.118.2 14(raebu 106:23): (official, unofficial, community, textbook, and lti).
107:23): In each case the radio buttons allow the selection of one of four values:
1.101 raeburn 108:
1.104 raeburn 109: 0, approval, validate, autolimit=N (where N is blank, or a positive integer).
1.101 raeburn 110: which have the following effects:
111:
112: 0
113:
114: =over
115:
116: - course requests are not allowed for this course types/affiliation
117:
118: =back
119:
1.104 raeburn 120: approval
1.101 raeburn 121:
122: =over
123:
124: - course requests must be approved by a Doman Coordinator in the
125: course's domain
126:
127: =back
128:
129: validate
130:
131: =over
132:
133: - an institutional validation (e.g., check requestor is instructor
134: of record) needs to be passed before the course will be created. The required
135: validation is in localenroll.pm on the primary library server for the course
136: domain.
137:
138: =back
139:
140: autolimit
141:
142: =over
143:
1.143 raeburn 144: - course requests will be processed automatically up to a limit of
1.101 raeburn 145: N requests for the course type for the particular requestor.
146: If N is undefined, there is no limit to the number of course requests
147: which a course owner may submit and have processed automatically.
148:
149: =back
150:
151: =item modify_quotas()
152:
153: =back
154:
155: =cut
156:
1.1 raeburn 157: package Apache::domainprefs;
158:
159: use strict;
160: use Apache::Constants qw(:common :http);
161: use Apache::lonnet;
162: use Apache::loncommon();
163: use Apache::lonhtmlcommon();
164: use Apache::lonlocal;
1.43 raeburn 165: use Apache::lonmsg();
1.91 raeburn 166: use Apache::lonconfigsettings;
1.160.6.37 raeburn 167: use Apache::lonuserutils();
1.160.6.39 raeburn 168: use Apache::loncoursequeueadmin();
1.160.6.118.2 14(raebu 169:23): use Apache::courseprefs();
1.69 raeburn 170: use LONCAPA qw(:DEFAULT :match);
1.6 raeburn 171: use LONCAPA::Enrollment;
1.81 raeburn 172: use LONCAPA::lonauthcgi();
1.9 raeburn 173: use File::Copy;
1.43 raeburn 174: use Locale::Language;
1.62 raeburn 175: use DateTime::TimeZone;
1.68 raeburn 176: use DateTime::Locale;
1.160.6.118.2 14(raebu 177:23): use Time::HiRes qw( sleep );
1.160.6.113 raeburn 178: use Net::CIDR;
1.160.6.118.2 14(raebu 179:23): use Crypt::CBC;
1.1 raeburn 180:
1.155 raeburn 181: my $registered_cleanup;
182: my $modified_urls;
183:
1.1 raeburn 184: sub handler {
185: my $r=shift;
186: if ($r->header_only) {
187: &Apache::loncommon::content_type($r,'text/html');
188: $r->send_http_header;
189: return OK;
190: }
191:
1.91 raeburn 192: my $context = 'domain';
1.1 raeburn 193: my $dom = $env{'request.role.domain'};
1.5 albertel 194: my $domdesc = &Apache::lonnet::domain($dom,'description');
1.1 raeburn 195: if (&Apache::lonnet::allowed('mau',$dom)) {
196: &Apache::loncommon::content_type($r,'text/html');
197: $r->send_http_header;
198: } else {
199: $env{'user.error.msg'}=
200: "/adm/domainprefs:mau:0:0:Cannot modify domain settings";
201: return HTTP_NOT_ACCEPTABLE;
202: }
1.155 raeburn 203:
204: $registered_cleanup=0;
205: @{$modified_urls}=();
206:
1.1 raeburn 207: &Apache::lonhtmlcommon::clear_breadcrumbs();
208: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.58 raeburn 209: ['phase','actions']);
1.30 raeburn 210: my $phase = 'pickactions';
1.3 raeburn 211: if ( exists($env{'form.phase'}) ) {
212: $phase = $env{'form.phase'};
213: }
1.150 raeburn 214: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.3 raeburn 215: my %domconfig =
1.6 raeburn 216: &Apache::lonnet::get_dom('configuration',['login','rolecolors',
1.125 raeburn 217: 'quotas','autoenroll','autoupdate','autocreate',
218: 'directorysrch','usercreation','usermodification',
219: 'contacts','defaults','scantron','coursecategories',
1.160.6.73 raeburn 220: 'serverstatuses','requestcourses','helpsettings',
221: 'coursedefaults','usersessions','loadbalancing',
1.160.6.113 raeburn 222: 'requestauthor','selfenrollment','inststatus',
1.160.6.118.2 14(raebu 223:23): 'passwords','ltitools','toolsec','lti','ltisec',
20(raebu 224:24): 'wafproxy','ipaccess','authordefaults'],$dom);
6(raebur 225:2): my %encconfig =
14(raebu 226:23): &Apache::lonnet::get_dom('encconfig',['ltitools','lti','linkprot'],$dom,undef,1);
227:23): my ($checked_is_home,$is_home);
1(raebur 228:1): if (ref($domconfig{'ltitools'}) eq 'HASH') {
229:1): if (ref($encconfig{'ltitools'}) eq 'HASH') {
14(raebu 230:23): my $home = &Apache::lonnet::domain($dom,'primary');
231:23): unless (($home eq 'no_host') || ($home eq '')) {
232:23): my @ids=&Apache::lonnet::current_machine_ids();
233:23): if (grep(/^\Q$home\E$/,@ids)) {
234:23): $is_home = 1;
235:23): }
236:23): }
237:23): $checked_is_home = 1;
1(raebur 238:1): foreach my $id (keys(%{$domconfig{'ltitools'}})) {
14(raebu 239:23): if ((ref($domconfig{'ltitools'}{$id}) eq 'HASH') &&
240:23): (ref($encconfig{'ltitools'}{$id}) eq 'HASH')) {
241:23): $domconfig{'ltitools'}{$id}{'key'} = $encconfig{'ltitools'}{$id}{'key'};
242:23): if (($is_home) && ($phase eq 'process')) {
243:23): $domconfig{'ltitools'}{$id}{'secret'} = $encconfig{'ltitools'}{$id}{'secret'};
244:23): }
245:23): }
246:23): }
247:23): }
248:23): }
249:23): if (ref($domconfig{'lti'}) eq 'HASH') {
250:23): if (ref($encconfig{'lti'}) eq 'HASH') {
251:23): unless ($checked_is_home) {
252:23): my $home = &Apache::lonnet::domain($dom,'primary');
253:23): unless (($home eq 'no_host') || ($home eq '')) {
254:23): my @ids=&Apache::lonnet::current_machine_ids();
255:23): if (grep(/^\Q$home\E$/,@ids)) {
256:23): $is_home = 1;
257:23): }
258:23): }
259:23): $checked_is_home = 1;
260:23): }
261:23): foreach my $id (keys(%{$domconfig{'lti'}})) {
262:23): if ((ref($domconfig{'lti'}{$id}) eq 'HASH') &&
263:23): (ref($encconfig{'lti'}{$id}) eq 'HASH')) {
264:23): $domconfig{'lti'}{$id}{'key'} = $encconfig{'lti'}{$id}{'key'};
265:23): if (($is_home) && ($phase eq 'process')) {
266:23): $domconfig{'lti'}{$id}{'secret'} = $encconfig{'lti'}{$id}{'secret'};
1(raebur 267:1): }
268:1): }
269:1): }
270:1): }
271:1): }
5(raebur 272:2): if (ref($domconfig{'ltisec'}) eq 'HASH') {
273:2): if (ref($domconfig{'ltisec'}{'linkprot'}) eq 'HASH') {
274:2): if (ref($encconfig{'linkprot'}) eq 'HASH') {
275:2): foreach my $id (keys(%{$domconfig{'ltisec'}{'linkprot'}})) {
276:2): unless ($id =~ /^\d+$/) {
277:2): delete($domconfig{'ltisec'}{'linkprot'}{$id});
278:2): }
279:2): if ((ref($domconfig{'ltisec'}{'linkprot'}{$id}) eq 'HASH') &&
280:2): (ref($encconfig{'linkprot'}{$id}) eq 'HASH')) {
281:2): foreach my $item ('key','secret') {
282:2): $domconfig{'ltisec'}{'linkprot'}{$id}{$item} = $encconfig{'linkprot'}{$id}{$item};
283:2): }
284:2): }
285:2): }
286:2): }
287:2): }
288:2): }
1.160.6.113 raeburn 289: my @prefs_order = ('rolecolors','login','ipaccess','defaults','wafproxy','passwords',
290: 'quotas','autoenroll','autoupdate','autocreate','directorysrch',
291: 'contacts','usercreation','selfcreation','usermodification',
292: 'scantron','requestcourses','requestauthor','coursecategories',
1.160.6.73 raeburn 293: 'serverstatuses','helpsettings','coursedefaults',
1.160.6.118.2 20(raebu 294:24): 'authordefaults','ltitools','selfenrollment','usersessions','lti');
1.160.6.7 raeburn 295: my %existing;
296: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
297: %existing = %{$domconfig{'loadbalancing'}};
298: }
299: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.150 raeburn 300: push(@prefs_order,'loadbalancing');
301: }
1.30 raeburn 302: my %prefs = (
303: 'rolecolors' =>
304: { text => 'Default color schemes',
1.67 raeburn 305: help => 'Domain_Configuration_Color_Schemes',
1.30 raeburn 306: header => [{col1 => 'Student Settings',
307: col2 => '',},
308: {col1 => 'Coordinator Settings',
309: col2 => '',},
310: {col1 => 'Author Settings',
311: col2 => '',},
312: {col1 => 'Administrator Settings',
313: col2 => '',}],
1.160.6.37 raeburn 314: print => \&print_rolecolors,
315: modify => \&modify_rolecolors,
1.30 raeburn 316: },
1.110 raeburn 317: 'login' =>
1.30 raeburn 318: { text => 'Log-in page options',
1.67 raeburn 319: help => 'Domain_Configuration_Login_Page',
1.160.6.5 raeburn 320: header => [{col1 => 'Log-in Page Items',
321: col2 => '',},
322: {col1 => 'Log-in Help',
1.160.6.56 raeburn 323: col2 => 'Value'},
324: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 325: col2 => 'Value'},
326: {col1 => 'SSO',
327: col2 => 'Dual login: SSO and non-SSO options'},
328: ],
1.160.6.37 raeburn 329: print => \&print_login,
330: modify => \&modify_login,
1.30 raeburn 331: },
1.43 raeburn 332: 'defaults' =>
1.160.6.40 raeburn 333: { text => 'Default authentication/language/timezone/portal/types',
1.67 raeburn 334: help => 'Domain_Configuration_LangTZAuth',
1.43 raeburn 335: header => [{col1 => 'Setting',
1.160.6.40 raeburn 336: col2 => 'Value'},
337: {col1 => 'Institutional user types',
1.160.6.118.2 8(raebur 338:2): col2 => 'Name displayed'},
339:2): {col1 => 'Mapping for missing usernames via standard log-in',
340:2): col2 => 'Rules in use'}],
1.160.6.37 raeburn 341: print => \&print_defaults,
342: modify => \&modify_defaults,
1.43 raeburn 343: },
1.160.6.113 raeburn 344: 'wafproxy' =>
345: { text => 'Web Application Firewall/Reverse Proxy',
346: help => 'Domain_Configuration_WAF_Proxy',
347: header => [{col1 => 'Domain(s)',
348: col2 => 'Servers and WAF/Reverse Proxy alias(es)',
349: },
350: {col1 => 'Domain(s)',
351: col2 => 'WAF Configuration',}],
352: print => \&print_wafproxy,
353: modify => \&modify_wafproxy,
354: },
1.160.6.98 raeburn 355: 'passwords' =>
356: { text => 'Passwords (Internal authentication)',
357: help => 'Domain_Configuration_Passwords',
358: header => [{col1 => 'Resetting Forgotten Password',
359: col2 => 'Settings'},
360: {col1 => 'Encryption of Stored Passwords (Internal Auth)',
361: col2 => 'Settings'},
362: {col1 => 'Rules for LON-CAPA Passwords',
363: col2 => 'Settings'},
364: {col1 => 'Course Owner Changing Student Passwords',
365: col2 => 'Settings'}],
366: print => \&print_passwords,
367: modify => \&modify_passwords,
368: },
1.30 raeburn 369: 'quotas' =>
1.160.6.118.2 20(raebu 370:24): { text => 'Blogs, personal pages/timezones, portfolio/quotas',
1.67 raeburn 371: help => 'Domain_Configuration_Quotas',
1.77 raeburn 372: header => [{col1 => 'User affiliation',
1.72 raeburn 373: col2 => 'Available tools',
1.160.6.118.2 20(raebu 374:24): col3 => 'Portfolio quota (MB)',}],
1.160.6.37 raeburn 375: print => \&print_quotas,
376: modify => \&modify_quotas,
1.30 raeburn 377: },
378: 'autoenroll' =>
379: { text => 'Auto-enrollment settings',
1.67 raeburn 380: help => 'Domain_Configuration_Auto_Enrollment',
1.30 raeburn 381: header => [{col1 => 'Configuration setting',
382: col2 => 'Value(s)'}],
1.160.6.37 raeburn 383: print => \&print_autoenroll,
384: modify => \&modify_autoenroll,
1.30 raeburn 385: },
386: 'autoupdate' =>
387: { text => 'Auto-update settings',
1.67 raeburn 388: help => 'Domain_Configuration_Auto_Updates',
1.30 raeburn 389: header => [{col1 => 'Setting',
390: col2 => 'Value',},
1.131 raeburn 391: {col1 => 'Setting',
392: col2 => 'Affiliation'},
1.43 raeburn 393: {col1 => 'User population',
1.160.6.35 raeburn 394: col2 => 'Updatable user data'}],
1.160.6.37 raeburn 395: print => \&print_autoupdate,
396: modify => \&modify_autoupdate,
1.30 raeburn 397: },
1.125 raeburn 398: 'autocreate' =>
399: { text => 'Auto-course creation settings',
400: help => 'Domain_Configuration_Auto_Creation',
401: header => [{col1 => 'Configuration Setting',
402: col2 => 'Value',}],
1.160.6.37 raeburn 403: print => \&print_autocreate,
404: modify => \&modify_autocreate,
1.125 raeburn 405: },
1.30 raeburn 406: 'directorysrch' =>
1.160.6.72 raeburn 407: { text => 'Directory searches',
1.67 raeburn 408: help => 'Domain_Configuration_InstDirectory_Search',
1.160.6.72 raeburn 409: header => [{col1 => 'Institutional Directory Setting',
410: col2 => 'Value',},
411: {col1 => 'LON-CAPA Directory Setting',
1.30 raeburn 412: col2 => 'Value',}],
1.160.6.37 raeburn 413: print => \&print_directorysrch,
414: modify => \&modify_directorysrch,
1.30 raeburn 415: },
416: 'contacts' =>
1.160.6.78 raeburn 417: { text => 'E-mail addresses and helpform',
1.67 raeburn 418: help => 'Domain_Configuration_Contact_Info',
1.160.6.78 raeburn 419: header => [{col1 => 'Default e-mail addresses',
420: col2 => 'Value',},
421: {col1 => 'Recipient(s) for notifications',
422: col2 => 'Value',},
1.160.6.107 raeburn 423: {col1 => 'Nightly status check e-mail',
424: col2 => 'Settings',},
1.160.6.78 raeburn 425: {col1 => 'Ask helpdesk form settings',
426: col2 => 'Value',},],
1.160.6.37 raeburn 427: print => \&print_contacts,
428: modify => \&modify_contacts,
1.30 raeburn 429: },
430: 'usercreation' =>
431: { text => 'User creation',
1.67 raeburn 432: help => 'Domain_Configuration_User_Creation',
1.43 raeburn 433: header => [{col1 => 'Format rule type',
434: col2 => 'Format rules in force'},
1.34 raeburn 435: {col1 => 'User account creation',
436: col2 => 'Usernames which may be created',},
1.30 raeburn 437: {col1 => 'Context',
1.43 raeburn 438: col2 => 'Assignable authentication types'}],
1.160.6.37 raeburn 439: print => \&print_usercreation,
440: modify => \&modify_usercreation,
1.30 raeburn 441: },
1.160.6.34 raeburn 442: 'selfcreation' =>
443: { text => 'Users self-creating accounts',
444: help => 'Domain_Configuration_Self_Creation',
445: header => [{col1 => 'Self-creation with institutional username',
446: col2 => 'Enabled?'},
447: {col1 => 'Institutional user type (login/SSO self-creation)',
448: col2 => 'Information user can enter'},
1.160.6.93 raeburn 449: {col1 => 'Self-creation with e-mail verification',
1.160.6.34 raeburn 450: col2 => 'Settings'}],
1.160.6.37 raeburn 451: print => \&print_selfcreation,
452: modify => \&modify_selfcreation,
1.160.6.34 raeburn 453: },
1.69 raeburn 454: 'usermodification' =>
1.33 raeburn 455: { text => 'User modification',
1.67 raeburn 456: help => 'Domain_Configuration_User_Modification',
1.33 raeburn 457: header => [{col1 => 'Target user has role',
1.160.6.35 raeburn 458: col2 => 'User information updatable in author context'},
1.33 raeburn 459: {col1 => 'Target user has role',
1.160.6.35 raeburn 460: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 461: print => \&print_usermodification,
462: modify => \&modify_usermodification,
1.33 raeburn 463: },
1.69 raeburn 464: 'scantron' =>
1.160.6.97 raeburn 465: { text => 'Bubblesheet format',
1.67 raeburn 466: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 467: header => [ {col1 => 'Bubblesheet format file',
468: col2 => ''},
469: {col1 => 'Bubblesheet data upload formats',
470: col2 => 'Settings'}],
1.160.6.37 raeburn 471: print => \&print_scantron,
472: modify => \&modify_scantron,
1.46 raeburn 473: },
1.86 raeburn 474: 'requestcourses' =>
475: {text => 'Request creation of courses',
476: help => 'Domain_Configuration_Request_Courses',
477: header => [{col1 => 'User affiliation',
1.102 raeburn 478: col2 => 'Availability/Processing of requests',},
479: {col1 => 'Setting',
1.160.6.30 raeburn 480: col2 => 'Value'},
481: {col1 => 'Available textbooks',
1.160.6.39 raeburn 482: col2 => ''},
1.160.6.46 raeburn 483: {col1 => 'Available templates',
484: col2 => ''},
1.160.6.39 raeburn 485: {col1 => 'Validation (not official courses)',
486: col2 => 'Value'},],
1.160.6.37 raeburn 487: print => \&print_quotas,
488: modify => \&modify_quotas,
1.86 raeburn 489: },
1.160.6.5 raeburn 490: 'requestauthor' =>
1.160.6.34 raeburn 491: {text => 'Request Authoring Space',
1.160.6.5 raeburn 492: help => 'Domain_Configuration_Request_Author',
493: header => [{col1 => 'User affiliation',
494: col2 => 'Availability/Processing of requests',},
495: {col1 => 'Setting',
496: col2 => 'Value'}],
1.160.6.37 raeburn 497: print => \&print_quotas,
498: modify => \&modify_quotas,
1.160.6.5 raeburn 499: },
1.69 raeburn 500: 'coursecategories' =>
1.120 raeburn 501: { text => 'Cataloging of courses/communities',
1.67 raeburn 502: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 503: header => [{col1 => 'Catalog type/availability',
504: col2 => '',},
505: {col1 => 'Category settings for standard catalog',
1.57 raeburn 506: col2 => '',},
507: {col1 => 'Categories',
508: col2 => '',
509: }],
1.160.6.37 raeburn 510: print => \&print_coursecategories,
511: modify => \&modify_coursecategories,
1.69 raeburn 512: },
513: 'serverstatuses' =>
1.77 raeburn 514: {text => 'Access to server status pages',
1.69 raeburn 515: help => 'Domain_Configuration_Server_Status',
516: header => [{col1 => 'Status Page',
517: col2 => 'Other named users',
518: col3 => 'Specific IPs',
519: }],
1.160.6.37 raeburn 520: print => \&print_serverstatuses,
521: modify => \&modify_serverstatuses,
1.69 raeburn 522: },
1.160.6.73 raeburn 523: 'helpsettings' =>
524: {text => 'Support settings',
525: help => 'Domain_Configuration_Help_Settings',
526: header => [{col1 => 'Help Page Settings (logged-in users)',
527: col2 => 'Value'},
528: {col1 => 'Helpdesk Roles',
529: col2 => 'Settings'},],
530: print => \&print_helpsettings,
531: modify => \&modify_helpsettings,
532: },
1.160.6.39 raeburn 533: 'coursedefaults' =>
1.160.6.16 raeburn 534: {text => 'Course/Community defaults',
535: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 536: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
537: col2 => 'Value',},
538: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 539: col2 => 'Value',},],
1.160.6.37 raeburn 540: print => \&print_coursedefaults,
541: modify => \&modify_coursedefaults,
542: },
1.160.6.39 raeburn 543: 'selfenrollment' =>
1.160.6.37 raeburn 544: {text => 'Self-enrollment in Course/Community',
545: help => 'Domain_Configuration_Selfenrollment',
546: header => [{col1 => 'Configuration Rights',
547: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
548: {col1 => 'Defaults',
549: col2 => 'Value'},
550: {col1 => 'Self-enrollment validation (optional)',
551: col2 => 'Value'},],
552: print => \&print_selfenrollment,
553: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 554: },
1.141 raeburn 555: 'usersessions' =>
1.145 raeburn 556: {text => 'User session hosting/offloading',
1.137 raeburn 557: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 558: header => [{col1 => 'Domain server',
559: col2 => 'Servers to offload sessions to when busy'},
560: {col1 => 'Hosting of users from other domains',
1.137 raeburn 561: col2 => 'Rules'},
562: {col1 => "Hosting domain's own users elsewhere",
563: col2 => 'Rules'}],
1.160.6.37 raeburn 564: print => \&print_usersessions,
565: modify => \&modify_usersessions,
1.137 raeburn 566: },
1.160.6.78 raeburn 567: 'loadbalancing' =>
1.160.6.7 raeburn 568: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 569: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 570: header => [{col1 => 'Balancers',
1.150 raeburn 571: col2 => 'Default destinations',
1.160.6.13 raeburn 572: col3 => 'User affiliation',
1.150 raeburn 573: col4 => 'Overrides'},
574: ],
1.160.6.37 raeburn 575: print => \&print_loadbalancing,
576: modify => \&modify_loadbalancing,
1.150 raeburn 577: },
1.160.6.118.2 1(raebur 578:1): 'ltitools' =>
579:1): {text => 'External Tools (LTI)',
580:1): help => 'Domain_Configuration_LTI_Tools',
14(raebu 581:23): header => [{col1 => 'Encryption of shared secrets',
582:23): col2 => 'Settings'},
583:23): {col1 => 'Rules for shared secrets',
584:23): col2 => 'Settings'},
585:23): {col1 => 'Providers',
586:23): col2 => 'Settings',}],
1(raebur 587:1): print => \&print_ltitools,
588:1): modify => \&modify_ltitools,
589:1): },
14(raebu 590:23): 'lti' =>
5(raebur 591:2): {text => 'LTI Link Protection and LTI Consumers',
592:2): help => 'Domain_Configuration_LTI_Provider',
593:2): header => [{col1 => 'Encryption of shared secrets',
594:2): col2 => 'Settings'},
595:2): {col1 => 'Rules for shared secrets',
596:2): col2 => 'Settings'},
18(raebu 597:24): {col1 => 'Link Protectors in Courses',
598:24): col2 => 'Values'},
5(raebur 599:2): {col1 => 'Link Protectors',
14(raebu 600:23): col2 => 'Settings'},
601:23): {col1 => 'Consumers',
5(raebur 602:2): col2 => 'Settings'},],
603:2): print => \&print_lti,
604:2): modify => \&modify_lti,
605:2): },
14(raebu 606:23): 'ipaccess' =>
1.160.6.113 raeburn 607: {text => 'IP-based access control',
608: help => 'Domain_Configuration_IP_Access',
609: header => [{col1 => 'Setting',
610: col2 => 'Value'},],
611: print => \&print_ipaccess,
612: modify => \&modify_ipaccess,
613: },
1.160.6.118.2 20(raebu 614:24): 'authordefaults' =>
615:24): {text => 'Authoring Space defaults',
616:24): help => 'Domain_Configuration_Author_Defaults',
617:24): header => [{col1 => 'Defaults which can be overridden by Author',
618:24): col2 => 'Settings',},
619:24): {col1 => 'Defaults which can be overridden by a Dom. Coord.',
620:24): col2 => 'Settings',},],
621:24): print => \&print_authordefaults,
622:24): modify => \&modify_authordefaults,
623:24): },
1.3 raeburn 624: );
1.110 raeburn 625: if (keys(%servers) > 1) {
626: $prefs{'login'} = { text => 'Log-in page options',
627: help => 'Domain_Configuration_Login_Page',
628: header => [{col1 => 'Log-in Service',
629: col2 => 'Server Setting',},
630: {col1 => 'Log-in Page Items',
1.160.6.118.2 5(raebur 631:2): col2 => 'Settings'},
1.160.6.5 raeburn 632: {col1 => 'Log-in Help',
1.160.6.56 raeburn 633: col2 => 'Value'},
634: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 635: col2 => 'Value'},
636: {col1 => 'SSO',
637: col2 => 'Dual login: SSO and non-SSO options'},
638: ],
1.160.6.37 raeburn 639: print => \&print_login,
640: modify => \&modify_login,
1.110 raeburn 641: };
642: }
1.160.6.13 raeburn 643:
1.6 raeburn 644: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 645: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 646: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 647: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 648: text=>"Settings to display/modify"});
1.9 raeburn 649: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 650:
1.3 raeburn 651: if ($phase eq 'process') {
1.160.6.27 raeburn 652: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
653: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 654: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 655: $r->rflush();
1.160.6.27 raeburn 656: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 657: }
1.30 raeburn 658: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 659: my $js = &recaptcha_js().
1.160.6.40 raeburn 660: &toggle_display_js();
1.160.6.7 raeburn 661: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 662: my ($othertitle,$usertypes,$types) =
663: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 664: $js .= &lonbalance_targets_js($dom,$types,\%servers,
665: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 666: &new_spares_js().
667: &common_domprefs_js().
668: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 669: }
1.160.6.30 raeburn 670: if (grep(/^requestcourses$/,@actions)) {
671: my $javascript_validations;
672: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
673: $js .= <<END;
674: <script type="text/javascript">
675: $javascript_validations
676: </script>
677: $coursebrowserjs
678: END
1.160.6.113 raeburn 679: } elsif (grep(/^ipaccess$/,@actions)) {
680: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 681: }
1.160.6.93 raeburn 682: if (grep(/^selfcreation$/,@actions)) {
683: $js .= &selfcreate_javascript();
684: }
1.160.6.78 raeburn 685: if (grep(/^contacts$/,@actions)) {
686: $js .= &contacts_javascript();
687: }
1.160.6.97 raeburn 688: if (grep(/^scantron$/,@actions)) {
689: $js .= &scantron_javascript();
690: }
1.150 raeburn 691: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 692: } else {
1.160.6.11 raeburn 693: # check if domconfig user exists for the domain.
694: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 695: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 696: &config_check($dom,$confname,$servadm);
697: unless ($configuserok eq 'ok') {
698: &Apache::lonconfigsettings::print_header($r,$phase,$context);
699: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
700: $confname).
701: '<br />'
702: );
703: if ($switchserver) {
704: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
705: '<br />'.
706: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
707: '<br />'.
708: &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).
709: '<br />'.
710: &mt('To do that now, use the following link: [_1]',$switchserver)
711: );
712: } else {
713: $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.').
714: '<br />'.
715: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
716: );
717: }
718: $r->print(&Apache::loncommon::end_page());
719: return OK;
720: }
1.21 raeburn 721: if (keys(%domconfig) == 0) {
722: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 723: my @ids=&Apache::lonnet::current_machine_ids();
724: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 725: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 726: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 727: my $custom_img_count = 0;
728: foreach my $img (@loginimages) {
729: if ($designhash{$dom.'.login.'.$img} ne '') {
730: $custom_img_count ++;
731: }
732: }
733: foreach my $role (@roles) {
734: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
735: $custom_img_count ++;
736: }
737: }
738: if ($custom_img_count > 0) {
1.94 raeburn 739: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 740: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 741: $r->print(
742: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
743: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
744: &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 />'.
745: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
746: if ($switch_server) {
1.30 raeburn 747: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 748: }
1.91 raeburn 749: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 750: return OK;
751: }
752: }
753: }
1.91 raeburn 754: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 755: }
756: return OK;
757: }
758:
759: sub process_changes {
1.160.6.24 raeburn 760: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 761: my %domconfig;
762: if (ref($values) eq 'HASH') {
763: %domconfig = %{$values};
764: }
1.3 raeburn 765: my $output;
766: if ($action eq 'login') {
1.160.6.24 raeburn 767: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 768: } elsif ($action eq 'rolecolors') {
1.9 raeburn 769: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 770: $lastactref,%domconfig);
1.3 raeburn 771: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 772: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 773: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 774: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 775: } elsif ($action eq 'autoupdate') {
776: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 777: } elsif ($action eq 'autocreate') {
778: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 779: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 780: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 781: } elsif ($action eq 'usercreation') {
1.28 raeburn 782: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 783: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 784: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 785: } elsif ($action eq 'usermodification') {
786: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 787: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 788: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 789: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 790: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 791: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 792: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 793: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 794: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 795: } elsif ($action eq 'serverstatuses') {
796: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 797: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 798: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 799: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 800: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 801: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 802: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 803: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 804: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 805: } elsif ($action eq 'selfenrollment') {
806: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 807: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 808: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 809: } elsif ($action eq 'loadbalancing') {
810: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2 14(raebu 811:23): } elsif ($action eq 'ltitools') {
812:23): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
5(raebur 813:2): } elsif ($action eq 'lti') {
814:2): $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98 raeburn 815: } elsif ($action eq 'passwords') {
816: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 817: } elsif ($action eq 'wafproxy') {
818: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
819: } elsif ($action eq 'ipaccess') {
820: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.160.6.118.2 20(raebu 821:24): } elsif ($action eq 'authordefaults') {
822:24): $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 823: }
824: return $output;
825: }
826:
827: sub print_config_box {
1.9 raeburn 828: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 829: my $rowtotal = 0;
1.49 raeburn 830: my $output;
831: if ($action eq 'coursecategories') {
832: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 833: } elsif ($action eq 'defaults') {
834: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 835: } elsif ($action eq 'passwords') {
1.160.6.118.2 5(raebur 836:2): $output = &passwords_javascript($action);
1.160.6.73 raeburn 837: } elsif ($action eq 'helpsettings') {
838: my (%privs,%levelscurrent);
839: my %full=();
840: my %levels=(
841: course => {},
842: domain => {},
843: system => {},
844: );
845: my $context = 'domain';
846: my $crstype = 'Course';
847: my $formname = 'display';
848: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
849: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
850: $output =
851: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
852: \@templateroles);
1.160.6.118.2 1(raebur 853:1): } elsif ($action eq 'ltitools') {
14(raebu 854:23): $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
5(raebur 855:2): } elsif ($action eq 'lti') {
14(raebu 856:23): $output .= &passwords_javascript('ltisecrets')."\n".
5(raebur 857:2): <i_javascript($dom,$settings);
1.160.6.113 raeburn 858: } elsif ($action eq 'wafproxy') {
859: $output .= &wafproxy_javascript($dom);
860: } elsif ($action eq 'autoupdate') {
861: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 862: } elsif ($action eq 'autoenroll') {
863: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 864: } elsif ($action eq 'login') {
865: $output .= &saml_javascript();
866: } elsif ($action eq 'ipaccess') {
867: $output .= &ipaccess_javascript($settings);
1.160.6.118.2 20(raebu 868:24): } elsif ($action eq 'authordefaults') {
869:24): $output .= &authordefaults_javascript();
1.91 raeburn 870: }
1.160.6.40 raeburn 871: $output .=
1.30 raeburn 872: '<table class="LC_nested_outer">
1.3 raeburn 873: <tr>
1.160.6.113 raeburn 874: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 875: &mt($item->{text}).' '.
876: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
877: '</tr>';
1.30 raeburn 878: $rowtotal ++;
1.110 raeburn 879: my $numheaders = 1;
880: if (ref($item->{'header'}) eq 'ARRAY') {
881: $numheaders = scalar(@{$item->{'header'}});
882: }
883: if ($numheaders > 1) {
1.64 raeburn 884: my $colspan = '';
1.145 raeburn 885: my $rightcolspan = '';
1.160.6.118.2 14(raebu 886:23): my $leftnobr = '';
1.160.6.42 raeburn 887: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 888: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 889: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 890: $colspan = ' colspan="2"';
891: }
1.145 raeburn 892: if ($action eq 'usersessions') {
893: $rightcolspan = ' colspan="3"';
894: }
1.160.6.104 raeburn 895: if ($action eq 'passwords') {
896: $leftnobr = ' LC_nobreak';
897: }
1.30 raeburn 898: $output .= '
1.3 raeburn 899: <tr>
900: <td>
901: <table class="LC_nested">
902: <tr class="LC_info_row">
1.160.6.104 raeburn 903: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 904: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 905: </tr>';
1.69 raeburn 906: $rowtotal ++;
1.160.6.37 raeburn 907: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 908: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 909: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2 14(raebu 910:23): ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') ||
20(raebu 911:24): ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.160.6.37 raeburn 912: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 913: } elsif ($action eq 'passwords') {
914: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 915: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 916: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 917: } elsif ($action eq 'scantron') {
918: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 919: } elsif ($action eq 'login') {
1.160.6.113 raeburn 920: if ($numheaders == 5) {
1.160.6.5 raeburn 921: $colspan = ' colspan="2"';
922: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
923: } else {
924: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
925: }
1.160.6.37 raeburn 926: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 927: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 928: } elsif ($action eq 'rolecolors') {
1.30 raeburn 929: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 930: }
1.30 raeburn 931: $output .= '
1.6 raeburn 932: </table>
933: </td>
934: </tr>
935: <tr>
936: <td>
937: <table class="LC_nested">
938: <tr class="LC_info_row">
1.160.6.37 raeburn 939: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 940: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 941: </tr>';
942: $rowtotal ++;
1.160.6.37 raeburn 943: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
944: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 945: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2 8(raebur 946:2): ($action eq 'contacts') || ($action eq 'passwords') ||
14(raebu 947:23): ($action eq 'defaults') || ($action eq 'lti') ||
948:23): ($action eq 'ltitools')) {
1.160.6.42 raeburn 949: if ($action eq 'coursecategories') {
950: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
951: $colspan = ' colspan="2"';
1.160.6.98 raeburn 952: } elsif ($action eq 'passwords') {
953: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.118.2 18(raebu 954:24): } elsif ($action eq 'lti') {
955:24): $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
956:24): </table>
957:24): </td>
958:24): </tr>
959:24): <tr>
960:24): <td>
961:24): <table class="LC_nested">
962:24): <tr class="LC_info_row">
963:24): <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
964:24): <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
965:24): </tr>'."\n".
966:24): $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.160.6.42 raeburn 967: } else {
968: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
969: }
1.160.6.118.2 18(raebu 970:24): my $hdridx = 2;
971:24): if ($action eq 'lti') {
972:24): $hdridx = 3;
973:24): }
1.160.6.42 raeburn 974: $output .= '
1.63 raeburn 975: </table>
976: </td>
977: </tr>
978: <tr>
979: <td>
980: <table class="LC_nested">
981: <tr class="LC_info_row">
1.160.6.118.2 18(raebu 982:24): <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
983:24): <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.160.6.42 raeburn 984: </tr>'."\n";
985: if ($action eq 'coursecategories') {
986: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 987: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 988: if ($action eq 'passwords') {
989: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
990: } else {
991: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
992: }
1.160.6.118.2 18(raebu 993:24): $hdridx ++;
1.160.6.107 raeburn 994: $output .= '
1.160.6.98 raeburn 995: </tr>
996: </table>
997: </td>
998: </tr>
999: <tr>
1000: <td>
1001: <table class="LC_nested">
1002: <tr class="LC_info_row">
1.160.6.118.2 18(raebu 1003:24): <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1004:24): <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 1005: if ($action eq 'passwords') {
1006: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1007: } else {
1008: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1009: }
1010: $output .= '
1.160.6.98 raeburn 1011: </table>
1012: </td>
1013: </tr>
1014: <tr>';
1.160.6.42 raeburn 1015: } else {
1016: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1017: }
1.63 raeburn 1018: $rowtotal ++;
1.160.6.57 raeburn 1019: } elsif (($action eq 'usermodification') || ($action eq 'coursedefaults') ||
1.160.6.118.2 8(raebur 1020:2): ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
20(raebu 1021:24): ($action eq 'wafproxy') || ($action eq 'authordefaults')) {
1.160.6.37 raeburn 1022: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 1023: } elsif ($action eq 'scantron') {
1024: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1025: } elsif ($action eq 'login') {
1.160.6.113 raeburn 1026: if ($numheaders == 5) {
1.160.6.5 raeburn 1027: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1028: </table>
1029: </td>
1030: </tr>
1031: <tr>
1032: <td>
1033: <table class="LC_nested">
1034: <tr class="LC_info_row">
1035: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 1036: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 1037: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1038: $rowtotal ++;
1039: } else {
1040: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1041: }
1.160.6.56 raeburn 1042: $output .= '
1043: </table>
1044: </td>
1045: </tr>
1046: <tr>
1047: <td>
1048: <table class="LC_nested">
1049: <tr class="LC_info_row">';
1.160.6.113 raeburn 1050: if ($numheaders == 5) {
1.160.6.56 raeburn 1051: $output .= '
1052: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1053: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1054: </tr>';
1055: } else {
1056: $output .= '
1057: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1058: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1059: </tr>';
1060: }
1061: $rowtotal ++;
1.160.6.113 raeburn 1062: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1063: </table>
1064: </td>
1065: </tr>
1066: <tr>
1067: <td>
1068: <table class="LC_nested">
1069: <tr class="LC_info_row">';
1070: if ($numheaders == 5) {
1071: $output .= '
1072: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1073: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1074: </tr>';
1075: } else {
1076: $output .= '
1077: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1078: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1079: </tr>';
1080: }
1081: $rowtotal ++;
1082: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1083: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 1084: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1085: $rowtotal ++;
1086: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 1087: </table>
1088: </td>
1089: </tr>
1090: <tr>
1091: <td>
1092: <table class="LC_nested">
1093: <tr class="LC_info_row">
1094: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1095: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 1096: &textbookcourses_javascript($settings).
1097: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1098: </table>
1099: </td>
1100: </tr>
1101: <tr>
1102: <td>
1103: <table class="LC_nested">
1104: <tr class="LC_info_row">
1105: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1106: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1107: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 1108: </table>
1109: </td>
1110: </tr>
1111: <tr>
1112: <td>
1113: <table class="LC_nested">
1114: <tr class="LC_info_row">
1.160.6.46 raeburn 1115: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1116: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1117: </tr>'.
1118: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1119: } elsif ($action eq 'requestauthor') {
1120: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1121: $rowtotal ++;
1.122 jms 1122: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1123: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1124: </table>
1125: </td>
1126: </tr>
1127: <tr>
1128: <td>
1129: <table class="LC_nested">
1130: <tr class="LC_info_row">
1.69 raeburn 1131: <td class="LC_left_item"'.$colspan.' valign="top">'.
1132: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1133: <td class="LC_right_item" valign="top">'.
1134: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1135: </tr>'.
1.30 raeburn 1136: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1137: </table>
1138: </td>
1139: </tr>
1140: <tr>
1141: <td>
1142: <table class="LC_nested">
1143: <tr class="LC_info_row">
1.59 bisitz 1144: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1145: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1146: </tr>'.
1.30 raeburn 1147: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1148: $rowtotal += 2;
1.6 raeburn 1149: }
1.3 raeburn 1150: } else {
1.30 raeburn 1151: $output .= '
1.3 raeburn 1152: <tr>
1153: <td>
1154: <table class="LC_nested">
1.30 raeburn 1155: <tr class="LC_info_row">';
1.160.6.72 raeburn 1156: if ($action eq 'login') {
1.30 raeburn 1157: $output .= '
1.59 bisitz 1158: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1159: } elsif ($action eq 'serverstatuses') {
1160: $output .= '
1161: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1162: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1163:
1.6 raeburn 1164: } else {
1.30 raeburn 1165: $output .= '
1.69 raeburn 1166: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1167: }
1.72 raeburn 1168: if (defined($item->{'header'}->[0]->{'col3'})) {
1169: $output .= '<td class="LC_left_item" valign="top">'.
1170: &mt($item->{'header'}->[0]->{'col2'});
1171: if ($action eq 'serverstatuses') {
1172: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1173: }
1.69 raeburn 1174: } else {
1175: $output .= '<td class="LC_right_item" valign="top">'.
1176: &mt($item->{'header'}->[0]->{'col2'});
1177: }
1178: $output .= '</td>';
1179: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1180: if (defined($item->{'header'}->[0]->{'col4'})) {
1181: $output .= '<td class="LC_left_item" valign="top">'.
1182: &mt($item->{'header'}->[0]->{'col3'});
1183: } else {
1184: $output .= '<td class="LC_right_item" valign="top">'.
1185: &mt($item->{'header'}->[0]->{'col3'});
1186: }
1.69 raeburn 1187: if ($action eq 'serverstatuses') {
1188: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1189: }
1190: $output .= '</td>';
1.6 raeburn 1191: }
1.150 raeburn 1192: if ($item->{'header'}->[0]->{'col4'}) {
1193: $output .= '<td class="LC_right_item" valign="top">'.
1194: &mt($item->{'header'}->[0]->{'col4'});
1195: }
1.69 raeburn 1196: $output .= '</tr>';
1.48 raeburn 1197: $rowtotal ++;
1.160.6.5 raeburn 1198: if ($action eq 'quotas') {
1.86 raeburn 1199: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1200: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1201: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 14(raebu 1202:23): ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1203: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1204: }
1.3 raeburn 1205: }
1.30 raeburn 1206: $output .= '
1.3 raeburn 1207: </table>
1208: </td>
1209: </tr>
1.30 raeburn 1210: </table><br />';
1211: return ($output,$rowtotal);
1.1 raeburn 1212: }
1213:
1.3 raeburn 1214: sub print_login {
1.160.6.5 raeburn 1215: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1216: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1217: my %choices = &login_choices();
1.160.6.113 raeburn 1218: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1219: %lt = &login_file_options();
1220: $switchserver = &check_switchserver($dom,$confname);
1221: }
1.160.6.5 raeburn 1222: if ($caller eq 'service') {
1.149 raeburn 1223: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1224: my $choice = $choices{'disallowlogin'};
1225: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1226: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1227: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1228: '<th>'.$choices{'server'}.'</th>'.
1229: '<th>'.$choices{'serverpath'}.'</th>'.
1230: '<th>'.$choices{'custompath'}.'</th>'.
1231: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1232: my %disallowed;
1233: if (ref($settings) eq 'HASH') {
1234: if (ref($settings->{'loginvia'}) eq 'HASH') {
1235: %disallowed = %{$settings->{'loginvia'}};
1236: }
1237: }
1238: foreach my $lonhost (sort(keys(%servers))) {
1239: my $direct = 'selected="selected"';
1.128 raeburn 1240: if (ref($disallowed{$lonhost}) eq 'HASH') {
1241: if ($disallowed{$lonhost}{'server'} ne '') {
1242: $direct = '';
1243: }
1.110 raeburn 1244: }
1.115 raeburn 1245: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1246: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1247: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1248: '</option>';
1.160.6.13 raeburn 1249: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1250: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1251: my $selected = '';
1.128 raeburn 1252: if (ref($disallowed{$lonhost}) eq 'HASH') {
1253: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1254: $selected = 'selected="selected"';
1255: }
1.110 raeburn 1256: }
1257: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1258: $servers{$hostid}.'</option>';
1259: }
1.128 raeburn 1260: $datatable .= '</select></td>'.
1261: '<td><select name="'.$lonhost.'_serverpath">';
1262: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1263: my $pathname = $path;
1264: if ($path eq 'custom') {
1265: $pathname = &mt('Custom Path').' ->';
1266: }
1267: my $selected = '';
1268: if (ref($disallowed{$lonhost}) eq 'HASH') {
1269: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1270: $selected = 'selected="selected"';
1271: }
1272: } elsif ($path eq '') {
1273: $selected = 'selected="selected"';
1274: }
1275: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1276: }
1277: $datatable .= '</select></td>';
1278: my ($custom,$exempt);
1279: if (ref($disallowed{$lonhost}) eq 'HASH') {
1280: $custom = $disallowed{$lonhost}{'custompath'};
1281: $exempt = $disallowed{$lonhost}{'exempt'};
1282: }
1283: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1284: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1285: '</tr>';
1.110 raeburn 1286: }
1287: $datatable .= '</table></td></tr>';
1288: return $datatable;
1.160.6.5 raeburn 1289: } elsif ($caller eq 'page') {
1290: my %defaultchecked = (
1291: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1292: 'helpdesk' => 'on',
1.160.6.5 raeburn 1293: 'adminmail' => 'off',
1294: 'newuser' => 'off',
1295: );
1.160.6.14 raeburn 1296: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1297: my (%checkedon,%checkedoff);
1.42 raeburn 1298: foreach my $item (@toggles) {
1.160.6.5 raeburn 1299: if ($defaultchecked{$item} eq 'on') {
1300: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1301: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1302: } elsif ($defaultchecked{$item} eq 'off') {
1303: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1304: $checkedon{$item} = ' ';
1305: }
1.1 raeburn 1306: }
1.160.6.5 raeburn 1307: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1308:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1309: my @logintext = ('textcol','bgcol');
1310: my @bgs = ('pgbg','mainbg','sidebg');
1311: my @links = ('link','alink','vlink');
1312: my %designhash = &Apache::loncommon::get_domainconf($dom);
1313: my %defaultdesign = %Apache::loncommon::defaultdesign;
1314: my (%is_custom,%designs);
1315: my %defaults = (
1316: font => $defaultdesign{'login.font'},
1317: );
1.6 raeburn 1318: foreach my $item (@images) {
1.160.6.5 raeburn 1319: $defaults{$item} = $defaultdesign{'login.'.$item};
1320: $defaults{'showlogo'}{$item} = 1;
1321: }
1322: foreach my $item (@bgs) {
1323: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1324: }
1.41 raeburn 1325: foreach my $item (@logintext) {
1.160.6.5 raeburn 1326: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1327: }
1.160.6.5 raeburn 1328: foreach my $item (@links) {
1329: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1330: }
1.160.6.5 raeburn 1331: if (ref($settings) eq 'HASH') {
1332: foreach my $item (@toggles) {
1333: if ($settings->{$item} eq '1') {
1334: $checkedon{$item} = ' checked="checked" ';
1335: $checkedoff{$item} = ' ';
1336: } elsif ($settings->{$item} eq '0') {
1337: $checkedoff{$item} = ' checked="checked" ';
1338: $checkedon{$item} = ' ';
1339: }
1.6 raeburn 1340: }
1.160.6.5 raeburn 1341: foreach my $item (@images) {
1342: if (defined($settings->{$item})) {
1343: $designs{$item} = $settings->{$item};
1344: $is_custom{$item} = 1;
1345: }
1346: if (defined($settings->{'showlogo'}{$item})) {
1347: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1348: }
1349: }
1.160.6.118.2 2(raebur 1350:2): foreach my $item (@alttext) {
1351:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1352:2): if ($settings->{'alttext'}->{$item} ne '') {
1353:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1354:2): }
1355:2): }
1356:2): }
1.160.6.5 raeburn 1357: foreach my $item (@logintext) {
1358: if ($settings->{$item} ne '') {
1359: $designs{'logintext'}{$item} = $settings->{$item};
1360: $is_custom{$item} = 1;
1361: }
1362: }
1363: if ($settings->{'font'} ne '') {
1364: $designs{'font'} = $settings->{'font'};
1365: $is_custom{'font'} = 1;
1366: }
1367: foreach my $item (@bgs) {
1368: if ($settings->{$item} ne '') {
1369: $designs{'bgs'}{$item} = $settings->{$item};
1370: $is_custom{$item} = 1;
1371: }
1372: }
1373: foreach my $item (@links) {
1374: if ($settings->{$item} ne '') {
1375: $designs{'links'}{$item} = $settings->{$item};
1376: $is_custom{$item} = 1;
1377: }
1378: }
1379: } else {
1380: if ($designhash{$dom.'.login.font'} ne '') {
1381: $designs{'font'} = $designhash{$dom.'.login.font'};
1382: $is_custom{'font'} = 1;
1383: }
1384: foreach my $item (@images) {
1385: if ($designhash{$dom.'.login.'.$item} ne '') {
1386: $designs{$item} = $designhash{$dom.'.login.'.$item};
1387: $is_custom{$item} = 1;
1388: }
1389: }
1390: foreach my $item (@bgs) {
1391: if ($designhash{$dom.'.login.'.$item} ne '') {
1392: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1393: $is_custom{$item} = 1;
1394: }
1395: }
1396: foreach my $item (@links) {
1397: if ($designhash{$dom.'.login.'.$item} ne '') {
1398: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1399: $is_custom{$item} = 1;
1400: }
1.6 raeburn 1401: }
1402: }
1.160.6.5 raeburn 1403: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1404: logo => 'Institution Logo',
1405: domlogo => 'Domain Logo',
1406: login => 'Login box');
1407: my $itemcount = 1;
1408: foreach my $item (@toggles) {
1409: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1410: $datatable .=
1411: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1412: '</td><td>'.
1413: '<span class="LC_nobreak"><label><input type="radio" name="'.
1414: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1415: '</label> <label><input type="radio" name="'.$item.'"'.
1416: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1417: '</tr>';
1418: $itemcount ++;
1.6 raeburn 1419: }
1.160.6.5 raeburn 1420: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1421: $datatable .= '</tr></table></td></tr>';
1422: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1423: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1424: my $itemcount = 1;
1425: $defaulturl = '/adm/loginproblems.html';
1426: $defaulttype = 'default';
1427: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1428: my @currlangs;
1429: if (ref($settings) eq 'HASH') {
1430: if (ref($settings->{'helpurl'}) eq 'HASH') {
1431: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1432: next if ($settings->{'helpurl'}{$key} eq '');
1433: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1434: $type{$key} = 'custom';
1435: unless ($key eq 'nolang') {
1436: push(@currlangs,$key);
1437: }
1438: }
1439: } elsif ($settings->{'helpurl'} ne '') {
1440: $type{'nolang'} = 'custom';
1441: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1442: }
1443: }
1.160.6.5 raeburn 1444: foreach my $lang ('nolang',sort(@currlangs)) {
1445: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1446: $datatable .= '<tr'.$css_class.'>';
1447: if ($url{$lang} eq '') {
1448: $url{$lang} = $defaulturl;
1449: }
1450: if ($type{$lang} eq '') {
1451: $type{$lang} = $defaulttype;
1452: }
1453: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1454: if ($lang eq 'nolang') {
1455: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1456: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1457: } else {
1458: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1459: $langchoices{$lang},
1460: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1461: }
1462: $datatable .= '</span></td>'."\n".
1463: '<td class="LC_left_item">';
1464: if ($type{$lang} eq 'custom') {
1465: $datatable .= '<span class="LC_nobreak"><label>'.
1466: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1467: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1468: } else {
1469: $datatable .= $lt{'upl'};
1470: }
1471: $datatable .='<br />';
1472: if ($switchserver) {
1473: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1474: } else {
1475: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1476: }
1.160.6.5 raeburn 1477: $datatable .= '</td></tr>';
1478: $itemcount ++;
1.6 raeburn 1479: }
1.160.6.5 raeburn 1480: my @addlangs;
1481: foreach my $lang (sort(keys(%langchoices))) {
1482: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1483: push(@addlangs,$lang);
1484: }
1485: if (@addlangs > 0) {
1486: my %toadd;
1487: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1488: $toadd{''} = &mt('Select');
1489: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1490: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1491: &mt('Add log-in help page for a specific language:').' '.
1492: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1493: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1494: if ($switchserver) {
1495: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1496: } else {
1497: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1498: }
1.160.6.5 raeburn 1499: $datatable .= '</td></tr>';
1500: $itemcount ++;
1.6 raeburn 1501: }
1.160.6.5 raeburn 1502: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1503: } elsif ($caller eq 'headtag') {
1504: my %domservers = &Apache::lonnet::get_servers($dom);
1505: my $choice = $choices{'headtag'};
1506: $css_class = ' class="LC_odd_row"';
1507: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1508: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1509: '<th>'.$choices{'current'}.'</th>'.
1510: '<th>'.$choices{'action'}.'</th>'.
1511: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1512: my (%currurls,%currexempt);
1513: if (ref($settings) eq 'HASH') {
1514: if (ref($settings->{'headtag'}) eq 'HASH') {
1515: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1516: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1517: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1518: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1519: }
1520: }
1521: }
1522: }
1523: foreach my $lonhost (sort(keys(%domservers))) {
1524: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1525: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1526: if ($currurls{$lonhost}) {
1527: $datatable .= '<td class="LC_right_item"><a href="'.
1528: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1529: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1530: '">'.$lt{'curr'}.'</a></td>'.
1531: '<td><span class="LC_nobreak"><label>'.
1532: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1533: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1534: } else {
1535: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1536: }
1537: $datatable .='<br />';
1538: if ($switchserver) {
1539: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1540: } else {
1541: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1542: }
1.160.6.87 raeburn 1543: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1544: }
1545: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1546: } elsif ($caller eq 'saml') {
1547: my %domservers = &Apache::lonnet::get_servers($dom);
1548: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1549: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1550: '<th>'.$choices{'samllanding'}.'</th>'.
1551: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.160.6.118.2 9(raebur 1552:2): my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.160.6.113 raeburn 1553: foreach my $lonhost (keys(%domservers)) {
1554: $samlurl{$lonhost} = '/adm/sso';
1555: $styleon{$lonhost} = 'display:none';
1556: $styleoff{$lonhost} = '';
1557: }
1.160.6.118.2 11(raebu 1558:23): if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.160.6.113 raeburn 1559: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1560: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1561: $saml{$lonhost} = 1;
1562: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1563: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1564: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1565: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1566: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 1567:2): $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 1568: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1569: $styleon{$lonhost} = '';
1570: $styleoff{$lonhost} = 'display:none';
1571: } else {
1572: $styleon{$lonhost} = 'display:none';
1573: $styleoff{$lonhost} = '';
1574: }
1575: }
1576: }
1577: my $itemcount = 1;
1578: foreach my $lonhost (sort(keys(%domservers))) {
1579: my $samlon = ' ';
1580: my $samloff = ' checked="checked" ';
1581: if ($saml{$lonhost}) {
1582: $samlon = $samloff;
1583: $samloff = ' ';
1584: }
1.160.6.118.2 9(raebur 1585:2): my $samlwinon = '';
1586:2): my $samlwinoff = ' checked="checked"';
1587:2): if ($samlwindow{$lonhost}) {
1588:2): $samlwinon = $samlwinoff;
1589:2): $samlwinoff = '';
1590:2): }
1.160.6.113 raeburn 1591: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1592: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1593: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1594: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1595: &mt('No').'</label>'.(' 'x2).
1596: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1597: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1598: &mt('Yes').'</label></span></td>'.
1599: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.160.6.118.2 9(raebur 1600:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.160.6.113 raeburn 1601: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.160.6.118.2 9(raebur 1602:2): '<th>'.&mt('Alt Text').'</th></tr>'.
1603:2): '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.160.6.113 raeburn 1604: $samltext{$lonhost}.'" /></td><td>';
1605: if ($samlimg{$lonhost}) {
1606: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1607: '<span class="LC_nobreak"><label>'.
1608: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1609: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1610: } else {
1611: $datatable .= $lt{'upl'};
1612: }
1613: $datatable .='<br />';
1614: if ($switchserver) {
1615: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1616: } else {
1617: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1618: }
1619: $datatable .= '</td>'.
1.160.6.118.2 9(raebur 1620:2): '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1621:2): 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1622:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1623:2): '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1624:2): '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1625:2): '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1626:2): '<tr'.$css_class.'>'.
1627:2): '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.160.6.113 raeburn 1628: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.160.6.118.2 9(raebur 1629:2): '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.160.6.113 raeburn 1630: $samltitle{$lonhost}.'</textarea></td>'.
1.160.6.118.2 9(raebur 1631:2): '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1632:2): &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1633:2): 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1634:2): '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.160.6.113 raeburn 1635: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1636: '</table></td>'.
1637: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1638: $itemcount ++;
1639: }
1640: $datatable .= '</table></td></tr>';
1.1 raeburn 1641: }
1.6 raeburn 1642: return $datatable;
1643: }
1644:
1645: sub login_choices {
1646: my %choices =
1647: &Apache::lonlocal::texthash (
1.116 bisitz 1648: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1649: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1650: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1651: disallowlogin => "Login page requests redirected",
1652: hostid => "Server",
1.128 raeburn 1653: server => "Redirect to:",
1654: serverpath => "Path",
1655: custompath => "Custom",
1656: exempt => "Exempt IP(s)",
1.110 raeburn 1657: directlogin => "No redirect",
1658: newuser => "Link to create a user account",
1659: img => "Header",
1660: logo => "Main Logo",
1661: domlogo => "Domain Logo",
1662: login => "Log-in Header",
1663: textcol => "Text color",
1664: bgcol => "Box color",
1665: bgs => "Background colors",
1666: links => "Link colors",
1667: font => "Font color",
1668: pgbg => "Header",
1669: mainbg => "Page",
1670: sidebg => "Login box",
1671: link => "Link",
1672: alink => "Active link",
1673: vlink => "Visited link",
1.160.6.56 raeburn 1674: headtag => "Custom markup",
1675: action => "Action",
1676: current => "Current",
1.160.6.113 raeburn 1677: samllanding => "Dual login?",
1678: samloptions => "Options",
1.160.6.118.2 2(raebur 1679:2): alttext => "Alt text",
1.6 raeburn 1680: );
1681: return %choices;
1682: }
1683:
1.160.6.113 raeburn 1684: sub login_file_options {
1685: return &Apache::lonlocal::texthash(
1686: del => 'Delete?',
1687: rep => 'Replace:',
1688: upl => 'Upload:',
1689: curr => 'View contents',
1690: default => 'Default',
1691: custom => 'Custom',
1692: none => 'None',
1693: );
1694: }
1695:
1696: sub print_ipaccess {
1697: my ($dom,$settings,$rowtotal) = @_;
1698: my $css_class;
1699: my $itemcount = 0;
1700: my $datatable;
1701: my %ordered;
1702: if (ref($settings) eq 'HASH') {
1703: foreach my $item (keys(%{$settings})) {
1704: if (ref($settings->{$item}) eq 'HASH') {
1705: my $num = $settings->{$item}{'order'};
1706: if ($num eq '') {
1707: $num = scalar(keys(%{$settings}));
1708: }
1709: $ordered{$num} = $item;
1710: }
1711: }
1712: }
1713: my $maxnum = scalar(keys(%ordered));
1714: if (keys(%ordered)) {
1715: my @items = sort { $a <=> $b } keys(%ordered);
1716: for (my $i=0; $i<@items; $i++) {
1717: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1718: my $item = $ordered{$items[$i]};
1719: my ($name,$ipranges,%commblocks,%courses);
1720: if (ref($settings->{$item}) eq 'HASH') {
1721: $name = $settings->{$item}->{'name'};
1722: $ipranges = $settings->{$item}->{'ip'};
1723: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1724: %commblocks = %{$settings->{$item}->{'commblocks'}};
1725: }
1726: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1727: %courses = %{$settings->{$item}->{'courses'}};
1728: }
1729: }
1730: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1731: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1732: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1733: for (my $k=0; $k<=$maxnum; $k++) {
1734: my $vpos = $k+1;
1735: my $selstr;
1736: if ($k == $i) {
1737: $selstr = ' selected="selected" ';
1738: }
1739: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1740: }
1741: $datatable .= '</select>'.(' 'x2).
1742: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1743: &mt('Delete?').'</label></span></td>'.
1744: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1745: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1746: '</td></tr>';
1747: $itemcount ++;
1748: }
1749: }
1750: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1751: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1752: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1753: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1754: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1755: for (my $k=0; $k<$maxnum+1; $k++) {
1756: my $vpos = $k+1;
1757: my $selstr;
1758: if ($k == $maxnum) {
1759: $selstr = ' selected="selected" ';
1760: }
1761: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1762: }
1763: $datatable .= '</select> '."\n".
1764: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1765: '<td colspan="2">'.
1766: &ipaccess_options('add',$itemcount,$dom).
1767: '</td>'."\n".
1768: '</tr>'."\n";
1769: $$rowtotal ++;
1770: return $datatable;
1771: }
1772:
1773: sub ipaccess_options {
1774: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1775: my (%currblocks,%currcourses,$output);
1776: if (ref($blocksref) eq 'HASH') {
1777: %currblocks = %{$blocksref};
1778: }
1779: if (ref($coursesref) eq 'HASH') {
1780: %currcourses = %{$coursesref};
1781: }
1782: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1783: '<span class="LC_nobreak">'.&mt('Name').': '.
1784: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1785: '</span></fieldset>'.
1786: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1787: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1788: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1789: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1790: $ipranges.'</textarea></fieldset>'.
1791: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1792: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1793: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1794: '<table>';
1795: foreach my $cid (sort(keys(%currcourses))) {
1796: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1797: $output .= '<tr><td><span class="LC_nobreak">'.
1798: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1799: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1800: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1801: }
1802: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1803: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1804: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1805: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1806: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1807: '</span></td></tr></table>'."\n".
1808: '</fieldset>';
1809: return $output;
1810: }
1811:
1812: sub blocker_checkboxes {
1813: my ($num,$blocks) = @_;
1814: my ($typeorder,$types) = &commblocktype_text();
1815: my $numinrow = 6;
1816: my $output = '<table>';
1817: for (my $i=0; $i<@{$typeorder}; $i++) {
1818: my $block = $typeorder->[$i];
1819: my $blockstatus;
1820: if (ref($blocks) eq 'HASH') {
1821: if ($blocks->{$block} eq 'on') {
1822: $blockstatus = 'checked="checked"';
1823: }
1824: }
1825: my $rem = $i%($numinrow);
1826: if ($rem == 0) {
1827: if ($i > 0) {
1828: $output .= '</tr>';
1829: }
1830: $output .= '<tr>';
1831: }
1832: if ($i == scalar(@{$typeorder})-1) {
1833: my $colsleft = $numinrow-$rem;
1834: if ($colsleft > 1) {
1835: $output .= '<td colspan="'.$colsleft.'">';
1836: } else {
1837: $output .= '<td>';
1838: }
1839: } else {
1840: $output .= '<td>';
1841: }
1842: my $item = 'ipaccess_block_'.$num;
1843: if ($blockstatus) {
1844: $blockstatus = ' '.$blockstatus;
1845: }
1846: $output .= '<span class="LC_nobreak"><label>'."\n".
1847: '<input type="checkbox" name="'.$item.'"'.
1848: $blockstatus.' value="'.$block.'"'.' />'.
1849: $types->{$block}.'</label></span>'."\n".
1850: '<br /></td>';
1851: }
1852: $output .= '</tr></table>';
1853: return $output;
1854: }
1855:
1856: sub commblocktype_text {
1857: my %types = &Apache::lonlocal::texthash(
1858: 'com' => 'Messaging',
1859: 'chat' => 'Chat Room',
1860: 'boards' => 'Discussion',
1861: 'port' => 'Portfolio',
1862: 'groups' => 'Groups',
1863: 'blogs' => 'Blogs',
1864: 'about' => 'User Information',
1865: 'printout' => 'Printouts',
1866: 'passwd' => 'Change Password',
1867: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1868: 'search' => 'Course search',
1869: 'wishlist' => 'Stored links',
1870: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1871: );
1.160.6.115 raeburn 1872: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1873: return ($typeorder,\%types);
1874: }
1875:
1.6 raeburn 1876: sub print_rolecolors {
1.30 raeburn 1877: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1878: my %choices = &color_font_choices();
1879: my @bgs = ('pgbg','tabbg','sidebg');
1880: my @links = ('link','alink','vlink');
1881: my @images = ('img');
1882: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1883: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1884: my %defaultdesign = %Apache::loncommon::defaultdesign;
1885: my (%is_custom,%designs);
1.160.6.22 raeburn 1886: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1887: if (ref($settings) eq 'HASH') {
1888: if (ref($settings->{$role}) eq 'HASH') {
1889: if ($settings->{$role}->{'img'} ne '') {
1890: $designs{'img'} = $settings->{$role}->{'img'};
1891: $is_custom{'img'} = 1;
1892: }
1893: if ($settings->{$role}->{'font'} ne '') {
1894: $designs{'font'} = $settings->{$role}->{'font'};
1895: $is_custom{'font'} = 1;
1896: }
1.97 tempelho 1897: if ($settings->{$role}->{'fontmenu'} ne '') {
1898: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1899: $is_custom{'fontmenu'} = 1;
1900: }
1.6 raeburn 1901: foreach my $item (@bgs) {
1902: if ($settings->{$role}->{$item} ne '') {
1903: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1904: $is_custom{$item} = 1;
1905: }
1906: }
1907: foreach my $item (@links) {
1908: if ($settings->{$role}->{$item} ne '') {
1909: $designs{'links'}{$item} = $settings->{$role}->{$item};
1910: $is_custom{$item} = 1;
1911: }
1912: }
1913: }
1914: } else {
1915: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1916: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1917: $is_custom{'img'} = 1;
1918: }
1.97 tempelho 1919: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1920: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1921: $is_custom{'fontmenu'} = 1;
1922: }
1.6 raeburn 1923: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1924: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1925: $is_custom{'font'} = 1;
1926: }
1927: foreach my $item (@bgs) {
1928: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1929: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1930: $is_custom{$item} = 1;
1931:
1932: }
1933: }
1934: foreach my $item (@links) {
1935: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1936: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1937: $is_custom{$item} = 1;
1938: }
1939: }
1940: }
1941: my $itemcount = 1;
1.30 raeburn 1942: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1943: $datatable .= '</tr></table></td></tr>';
1944: return $datatable;
1945: }
1946:
1.160.6.22 raeburn 1947: sub role_defaults {
1948: my ($role,$bgs,$links,$images,$logintext) = @_;
1949: my %defaults;
1950: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1951: return %defaults;
1952: }
1953: my %defaultdesign = %Apache::loncommon::defaultdesign;
1954: if ($role eq 'login') {
1955: %defaults = (
1956: font => $defaultdesign{$role.'.font'},
1957: );
1958: if (ref($logintext) eq 'ARRAY') {
1959: foreach my $item (@{$logintext}) {
1960: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1961: }
1962: }
1963: foreach my $item (@{$images}) {
1964: $defaults{'showlogo'}{$item} = 1;
1965: }
1966: } else {
1967: %defaults = (
1968: img => $defaultdesign{$role.'.img'},
1969: font => $defaultdesign{$role.'.font'},
1970: fontmenu => $defaultdesign{$role.'.fontmenu'},
1971: );
1972: }
1973: foreach my $item (@{$bgs}) {
1974: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1975: }
1976: foreach my $item (@{$links}) {
1977: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1978: }
1979: foreach my $item (@{$images}) {
1980: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1981: }
1982: return %defaults;
1983: }
1984:
1.6 raeburn 1985: sub display_color_options {
1.9 raeburn 1986: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1987: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1988: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1989: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1990: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1991: '<td>'.$choices->{'font'}.'</td>';
1992: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1993: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1994: } else {
1995: $datatable .= '<td> </td>';
1996: }
1.160.6.9 raeburn 1997: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1998:
1.8 raeburn 1999: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 2000: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
2001: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 2002: ' </span></td></tr>';
1.107 raeburn 2003: unless ($role eq 'login') {
2004: $datatable .= '<tr'.$css_class.'>'.
2005: '<td>'.$choices->{'fontmenu'}.'</td>';
2006: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 2007: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2008: } else {
2009: $datatable .= '<td> </td>';
2010: }
1.160.6.22 raeburn 2011: $current_color = $designs->{'fontmenu'} ?
2012: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2013: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 2014: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 2015: .$role.'_fontmenu"'.
1.160.6.9 raeburn 2016: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 2017: ' </span></td></tr>';
1.97 tempelho 2018: }
1.9 raeburn 2019: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2020: foreach my $img (@{$images}) {
1.18 albertel 2021: $itemcount ++;
1.6 raeburn 2022: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2023: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2024: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 2025:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2026: if ($role eq 'login') {
2027: if ($img eq 'login') {
2028: $login_hdr_pick =
1.135 bisitz 2029: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2030: $logincolors =
2031: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 2032: $designs,$defaults);
1.160.6.118.2 2(raebur 2033:2): } else {
2034:2): if ($img ne 'domlogo') {
2035:2): $datatable.= &logo_display_options($img,$defaults,$designs);
2036:2): }
2037:2): if (ref($designs->{'alttext'}) eq 'HASH') {
2038:2): $alttext = $designs->{'alttext'}{$img};
2039:2): }
1.70 raeburn 2040: }
2041: }
2042: $datatable .= '</td>';
1.6 raeburn 2043: if ($designs->{$img} ne '') {
2044: $imgfile = $designs->{$img};
1.18 albertel 2045: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2046: } else {
2047: $imgfile = $defaults->{$img};
2048: }
2049: if ($imgfile) {
1.9 raeburn 2050: my ($showfile,$fullsize);
2051: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2052: my $urldir = $1;
2053: my $filename = $2;
2054: my @info = &Apache::lonnet::stat_file($designs->{$img});
2055: if (@info) {
2056: my $thumbfile = 'tn-'.$filename;
2057: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2058: if (@thumb) {
2059: $showfile = $urldir.'/'.$thumbfile;
2060: } else {
2061: $showfile = $imgfile;
2062: }
2063: } else {
2064: $showfile = '';
2065: }
2066: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2067: $showfile = $imgfile;
1.6 raeburn 2068: my $imgdir = $1;
2069: my $filename = $2;
1.159 raeburn 2070: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2071: $showfile = "/$imgdir/tn-".$filename;
2072: } else {
1.159 raeburn 2073: my $input = $londocroot.$imgfile;
2074: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2075: if (!-e $output) {
1.9 raeburn 2076: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2077: my ($fullwidth,$fullheight) = &check_dimensions($input);
2078: if ($fullwidth ne '' && $fullheight ne '') {
2079: if ($fullwidth > $width && $fullheight > $height) {
2080: my $size = $width.'x'.$height;
1.160.6.88 raeburn 2081: my @args = ('convert','-sample',$size,$input,$output);
2082: system({$args[0]} @args);
1.159 raeburn 2083: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2084: }
2085: }
1.6 raeburn 2086: }
2087: }
1.16 raeburn 2088: }
1.6 raeburn 2089: if ($showfile) {
1.40 raeburn 2090: if ($showfile =~ m{^/(adm|res)/}) {
2091: if ($showfile =~ m{^/res/}) {
2092: my $local_showfile =
2093: &Apache::lonnet::filelocation('',$showfile);
2094: &Apache::lonnet::repcopy($local_showfile);
2095: }
2096: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2097: }
2098: if ($imgfile) {
2099: if ($imgfile =~ m{^/(adm|res)/}) {
2100: if ($imgfile =~ m{^/res/}) {
2101: my $local_imgfile =
2102: &Apache::lonnet::filelocation('',$imgfile);
2103: &Apache::lonnet::repcopy($local_imgfile);
2104: }
2105: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2106: } else {
2107: $fullsize = $imgfile;
2108: }
2109: }
1.41 raeburn 2110: $datatable .= '<td>';
2111: if ($img eq 'login') {
1.135 bisitz 2112: $datatable .= $login_hdr_pick;
2113: }
1.41 raeburn 2114: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2115: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2116: } else {
1.160.6.22 raeburn 2117: $datatable .= '<td> </td><td class="LC_left_item">'.
2118: &mt('Upload:').'<br />';
1.6 raeburn 2119: }
2120: } else {
1.160.6.22 raeburn 2121: $datatable .= '<td> </td><td class="LC_left_item">'.
2122: &mt('Upload:').'<br />';
1.6 raeburn 2123: }
1.9 raeburn 2124: if ($switchserver) {
2125: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2126: } else {
1.135 bisitz 2127: if ($img ne 'login') { # suppress file selection for Log-in header
2128: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2129: }
1.9 raeburn 2130: }
1.160.6.118.2 2(raebur 2131:2): if (($role eq 'login') && ($img ne 'login')) {
2132:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2133:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2134:2): '</label></span>';
2135:2): }
1.9 raeburn 2136: $datatable .= '</td></tr>';
1.6 raeburn 2137: }
2138: $itemcount ++;
2139: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2140: $datatable .= '<tr'.$css_class.'>'.
2141: '<td>'.$choices->{'bgs'}.'</td>';
2142: my $bgs_def;
2143: foreach my $item (@{$bgs}) {
2144: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2145: $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 2146: }
2147: }
2148: if ($bgs_def) {
1.8 raeburn 2149: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2150: } else {
2151: $datatable .= '<td> </td>';
2152: }
2153: $datatable .= '<td class="LC_right_item">'.
2154: '<table border="0"><tr>';
1.160.6.13 raeburn 2155:
1.6 raeburn 2156: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2157: $datatable .= '<td align="center">'.$choices->{$item};
2158: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2159: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2160: $datatable .= ' ';
1.6 raeburn 2161: }
1.160.6.9 raeburn 2162: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2163: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2164: }
2165: $datatable .= '</tr></table></td></tr>';
2166: $itemcount ++;
2167: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2168: $datatable .= '<tr'.$css_class.'>'.
2169: '<td>'.$choices->{'links'}.'</td>';
2170: my $links_def;
2171: foreach my $item (@{$links}) {
2172: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2173: $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 2174: }
2175: }
2176: if ($links_def) {
1.8 raeburn 2177: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2178: } else {
2179: $datatable .= '<td> </td>';
2180: }
2181: $datatable .= '<td class="LC_right_item">'.
2182: '<table border="0"><tr>';
2183: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2184: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2185: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2186: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2187: $datatable.=' ';
1.6 raeburn 2188: }
1.160.6.9 raeburn 2189: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2190: '" /></td>';
2191: }
1.30 raeburn 2192: $$rowtotal += $itemcount;
1.3 raeburn 2193: return $datatable;
2194: }
2195:
1.70 raeburn 2196: sub logo_display_options {
2197: my ($img,$defaults,$designs) = @_;
2198: my $checkedon;
2199: if (ref($defaults) eq 'HASH') {
2200: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2201: if ($defaults->{'showlogo'}{$img}) {
2202: $checkedon = 'checked="checked" ';
2203: }
2204: }
2205: }
2206: if (ref($designs) eq 'HASH') {
2207: if (ref($designs->{'showlogo'}) eq 'HASH') {
2208: if (defined($designs->{'showlogo'}{$img})) {
2209: if ($designs->{'showlogo'}{$img} == 0) {
2210: $checkedon = '';
2211: } elsif ($designs->{'showlogo'}{$img} == 1) {
2212: $checkedon = 'checked="checked" ';
2213: }
2214: }
2215: }
2216: }
2217: return '<br /><label> <input type="checkbox" name="'.
2218: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2219: &mt('show').'</label>'."\n";
2220: }
2221:
1.41 raeburn 2222: sub login_header_options {
1.135 bisitz 2223: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2224: my $output = '';
1.41 raeburn 2225: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2226: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2227: if (!$is_custom->{'textcol'}) {
2228: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2229: ' ';
2230: }
2231: if (!$is_custom->{'bgcol'}) {
2232: $output .= $choices->{'bgcol'}.': '.
2233: '<span id="css_'.$role.'_font" style="background-color: '.
2234: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2235: }
2236: $output .= '<br />';
2237: }
2238: $output .='<br />';
2239: return $output;
2240: }
2241:
2242: sub login_text_colors {
1.160.6.22 raeburn 2243: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2244: my $color_menu = '<table border="0"><tr>';
2245: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2246: $color_menu .= '<td align="center">'.$choices->{$item};
2247: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2248: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2249: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2250: }
2251: $color_menu .= '</tr></table><br />';
2252: return $color_menu;
2253: }
2254:
2255: sub image_changes {
2256: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2257: my $output;
1.135 bisitz 2258: if ($img eq 'login') {
1.160.6.87 raeburn 2259: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2260: } elsif (!$is_custom) {
1.70 raeburn 2261: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2262: $output = &mt('Default image:').'<br />';
1.41 raeburn 2263: } else {
1.160.6.87 raeburn 2264: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2265: }
2266: }
1.160.6.87 raeburn 2267: if ($img ne 'login') {
1.135 bisitz 2268: if ($img_import) {
2269: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2270: }
2271: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2272: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2273: if ($is_custom) {
2274: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2275: '<input type="checkbox" name="'.
2276: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2277: '</label> '.&mt('Replace:').'</span><br />';
2278: } else {
1.160.6.22 raeburn 2279: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2280: }
1.41 raeburn 2281: }
2282: return $output;
2283: }
2284:
1.3 raeburn 2285: sub print_quotas {
1.86 raeburn 2286: my ($dom,$settings,$rowtotal,$action) = @_;
2287: my $context;
2288: if ($action eq 'quotas') {
2289: $context = 'tools';
2290: } else {
2291: $context = $action;
2292: }
1.160.6.118.2 20(raebu 2293:24): my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2294: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2295: my $typecount = 0;
1.101 raeburn 2296: my ($css_class,%titles);
1.86 raeburn 2297: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 2298:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 2299: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2300: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2301: %titles = &courserequest_titles();
1.160.6.5 raeburn 2302: } elsif ($context eq 'requestauthor') {
2303: @usertools = ('author');
2304: @options = ('norequest','approval','automatic');
2305: %titles = &authorrequest_titles();
1.86 raeburn 2306: } else {
1.160.6.118.2 20(raebu 2307:24): @usertools = ('aboutme','blog','portfolio','timezone');
1.101 raeburn 2308: %titles = &tool_titles();
1.86 raeburn 2309: }
1.26 raeburn 2310: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2311: foreach my $type (@{$types}) {
1.160.6.118.2 20(raebu 2312:24): my $currdefquota;
1.160.6.5 raeburn 2313: unless (($context eq 'requestcourses') ||
2314: ($context eq 'requestauthor')) {
1.86 raeburn 2315: if (ref($settings) eq 'HASH') {
2316: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2317: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2318: } else {
2319: $currdefquota = $settings->{$type};
2320: }
1.78 raeburn 2321: }
1.72 raeburn 2322: }
1.3 raeburn 2323: if (defined($usertypes->{$type})) {
2324: $typecount ++;
2325: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2326: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2327: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2328: '<td class="LC_left_item">';
1.101 raeburn 2329: if ($context eq 'requestcourses') {
2330: $datatable .= '<table><tr>';
2331: }
2332: my %cell;
1.72 raeburn 2333: foreach my $item (@usertools) {
1.101 raeburn 2334: if ($context eq 'requestcourses') {
2335: my ($curroption,$currlimit);
2336: if (ref($settings) eq 'HASH') {
2337: if (ref($settings->{$item}) eq 'HASH') {
2338: $curroption = $settings->{$item}->{$type};
2339: if ($curroption =~ /^autolimit=(\d*)$/) {
2340: $currlimit = $1;
2341: }
2342: }
2343: }
2344: if (!$curroption) {
2345: $curroption = 'norequest';
2346: }
2347: $datatable .= '<th>'.$titles{$item}.'</th>';
2348: foreach my $option (@options) {
2349: my $val = $option;
2350: if ($option eq 'norequest') {
2351: $val = 0;
2352: }
2353: if ($option eq 'validate') {
2354: my $canvalidate = 0;
2355: if (ref($validations{$item}) eq 'HASH') {
2356: if ($validations{$item}{$type}) {
2357: $canvalidate = 1;
2358: }
2359: }
2360: next if (!$canvalidate);
2361: }
2362: my $checked = '';
2363: if ($option eq $curroption) {
2364: $checked = ' checked="checked"';
2365: } elsif ($option eq 'autolimit') {
2366: if ($curroption =~ /^autolimit/) {
2367: $checked = ' checked="checked"';
2368: }
2369: }
2370: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2371: '<input type="radio" name="crsreq_'.$item.
2372: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2373: $titles{$option}.'</label>';
1.101 raeburn 2374: if ($option eq 'autolimit') {
1.127 raeburn 2375: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2376: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2377: 'value="'.$currlimit.'" />';
1.101 raeburn 2378: }
1.127 raeburn 2379: $cell{$item} .= '</span> ';
1.103 raeburn 2380: if ($option eq 'autolimit') {
1.127 raeburn 2381: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2382: }
1.101 raeburn 2383: }
1.160.6.5 raeburn 2384: } elsif ($context eq 'requestauthor') {
2385: my $curroption;
2386: if (ref($settings) eq 'HASH') {
2387: $curroption = $settings->{$type};
2388: }
2389: if (!$curroption) {
2390: $curroption = 'norequest';
2391: }
2392: foreach my $option (@options) {
2393: my $val = $option;
2394: if ($option eq 'norequest') {
2395: $val = 0;
2396: }
2397: my $checked = '';
2398: if ($option eq $curroption) {
2399: $checked = ' checked="checked"';
2400: }
2401: $datatable .= '<span class="LC_nobreak"><label>'.
2402: '<input type="radio" name="authorreq_'.$type.
2403: '" value="'.$val.'"'.$checked.' />'.
2404: $titles{$option}.'</label></span> ';
2405: }
1.101 raeburn 2406: } else {
2407: my $checked = 'checked="checked" ';
1.160.6.118.2 10(raebu 2408:22): if ($item eq 'timezone') {
2409:22): $checked = '';
2410:22): }
1.101 raeburn 2411: if (ref($settings) eq 'HASH') {
2412: if (ref($settings->{$item}) eq 'HASH') {
1.160.6.118.2 10(raebu 2413:22): if (!$settings->{$item}->{$type}) {
1.101 raeburn 2414: $checked = '';
2415: } elsif ($settings->{$item}->{$type} == 1) {
2416: $checked = 'checked="checked" ';
2417: }
1.78 raeburn 2418: }
1.72 raeburn 2419: }
1.101 raeburn 2420: $datatable .= '<span class="LC_nobreak"><label>'.
2421: '<input type="checkbox" name="'.$context.'_'.$item.
2422: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2423: '</label></span> ';
1.72 raeburn 2424: }
1.101 raeburn 2425: }
2426: if ($context eq 'requestcourses') {
2427: $datatable .= '</tr><tr>';
2428: foreach my $item (@usertools) {
1.106 raeburn 2429: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2430: }
2431: $datatable .= '</tr></table>';
1.72 raeburn 2432: }
1.86 raeburn 2433: $datatable .= '</td>';
1.160.6.5 raeburn 2434: unless (($context eq 'requestcourses') ||
2435: ($context eq 'requestauthor')) {
1.86 raeburn 2436: $datatable .=
1.160.6.20 raeburn 2437: '<td class="LC_right_item">'.
1.160.6.118.2 20(raebu 2438:24): '<span class="LC_nobreak">'.
1.3 raeburn 2439: '<input type="text" name="quota_'.$type.
1.72 raeburn 2440: '" value="'.$currdefquota.
1.160.6.20 raeburn 2441: '" size="5" /></span></td>';
1.86 raeburn 2442: }
2443: $datatable .= '</tr>';
1.3 raeburn 2444: }
2445: }
2446: }
1.160.6.5 raeburn 2447: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2448: $defaultquota = '20';
2449: if (ref($settings) eq 'HASH') {
2450: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2451: $defaultquota = $settings->{'defaultquota'}->{'default'};
2452: } elsif (defined($settings->{'default'})) {
2453: $defaultquota = $settings->{'default'};
2454: }
1.3 raeburn 2455: }
2456: }
2457: $typecount ++;
2458: $css_class = $typecount%2?' class="LC_odd_row"':'';
2459: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2460: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2461: '<td class="LC_left_item">';
1.101 raeburn 2462: if ($context eq 'requestcourses') {
2463: $datatable .= '<table><tr>';
2464: }
2465: my %defcell;
1.72 raeburn 2466: foreach my $item (@usertools) {
1.101 raeburn 2467: if ($context eq 'requestcourses') {
2468: my ($curroption,$currlimit);
2469: if (ref($settings) eq 'HASH') {
2470: if (ref($settings->{$item}) eq 'HASH') {
2471: $curroption = $settings->{$item}->{'default'};
2472: if ($curroption =~ /^autolimit=(\d*)$/) {
2473: $currlimit = $1;
2474: }
2475: }
2476: }
2477: if (!$curroption) {
2478: $curroption = 'norequest';
2479: }
2480: $datatable .= '<th>'.$titles{$item}.'</th>';
2481: foreach my $option (@options) {
2482: my $val = $option;
2483: if ($option eq 'norequest') {
2484: $val = 0;
2485: }
2486: if ($option eq 'validate') {
2487: my $canvalidate = 0;
2488: if (ref($validations{$item}) eq 'HASH') {
2489: if ($validations{$item}{'default'}) {
2490: $canvalidate = 1;
2491: }
2492: }
2493: next if (!$canvalidate);
2494: }
2495: my $checked = '';
2496: if ($option eq $curroption) {
2497: $checked = ' checked="checked"';
2498: } elsif ($option eq 'autolimit') {
2499: if ($curroption =~ /^autolimit/) {
2500: $checked = ' checked="checked"';
2501: }
2502: }
2503: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2504: '<input type="radio" name="crsreq_'.$item.
2505: '_default" value="'.$val.'"'.$checked.' />'.
2506: $titles{$option}.'</label>';
2507: if ($option eq 'autolimit') {
1.127 raeburn 2508: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2509: $item.'_limit_default" size="1" '.
2510: 'value="'.$currlimit.'" />';
2511: }
1.127 raeburn 2512: $defcell{$item} .= '</span> ';
1.104 raeburn 2513: if ($option eq 'autolimit') {
1.127 raeburn 2514: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2515: }
1.101 raeburn 2516: }
1.160.6.5 raeburn 2517: } elsif ($context eq 'requestauthor') {
2518: my $curroption;
2519: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2520: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2521: }
2522: if (!$curroption) {
2523: $curroption = 'norequest';
2524: }
2525: foreach my $option (@options) {
2526: my $val = $option;
2527: if ($option eq 'norequest') {
2528: $val = 0;
2529: }
2530: my $checked = '';
2531: if ($option eq $curroption) {
2532: $checked = ' checked="checked"';
2533: }
2534: $datatable .= '<span class="LC_nobreak"><label>'.
2535: '<input type="radio" name="authorreq_default"'.
2536: ' value="'.$val.'"'.$checked.' />'.
2537: $titles{$option}.'</label></span> ';
2538: }
1.101 raeburn 2539: } else {
2540: my $checked = 'checked="checked" ';
2541: if (ref($settings) eq 'HASH') {
2542: if (ref($settings->{$item}) eq 'HASH') {
2543: if ($settings->{$item}->{'default'} == 0) {
2544: $checked = '';
2545: } elsif ($settings->{$item}->{'default'} == 1) {
2546: $checked = 'checked="checked" ';
2547: }
1.78 raeburn 2548: }
1.72 raeburn 2549: }
1.101 raeburn 2550: $datatable .= '<span class="LC_nobreak"><label>'.
2551: '<input type="checkbox" name="'.$context.'_'.$item.
2552: '" value="default" '.$checked.'/>'.$titles{$item}.
2553: '</label></span> ';
2554: }
2555: }
2556: if ($context eq 'requestcourses') {
2557: $datatable .= '</tr><tr>';
2558: foreach my $item (@usertools) {
1.106 raeburn 2559: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2560: }
1.101 raeburn 2561: $datatable .= '</tr></table>';
1.72 raeburn 2562: }
1.86 raeburn 2563: $datatable .= '</td>';
1.160.6.5 raeburn 2564: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2565: $datatable .= '<td class="LC_right_item">'.
1.160.6.118.2 20(raebu 2566:24): '<span class="LC_nobreak">'.
1.86 raeburn 2567: '<input type="text" name="defaultquota" value="'.
1.160.6.118.2 20(raebu 2568:24): $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2569: }
2570: $datatable .= '</tr>';
1.72 raeburn 2571: $typecount ++;
2572: $css_class = $typecount%2?' class="LC_odd_row"':'';
2573: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2574: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2575: if ($context eq 'requestcourses') {
1.109 raeburn 2576: $datatable .= &mt('(overrides affiliation, if set)').
2577: '</td>'.
2578: '<td class="LC_left_item">'.
2579: '<table><tr>';
1.101 raeburn 2580: } else {
1.109 raeburn 2581: $datatable .= &mt('(overrides affiliation, if checked)').
2582: '</td>'.
2583: '<td class="LC_left_item" colspan="2">'.
2584: '<br />';
1.101 raeburn 2585: }
2586: my %advcell;
1.72 raeburn 2587: foreach my $item (@usertools) {
1.101 raeburn 2588: if ($context eq 'requestcourses') {
2589: my ($curroption,$currlimit);
2590: if (ref($settings) eq 'HASH') {
2591: if (ref($settings->{$item}) eq 'HASH') {
2592: $curroption = $settings->{$item}->{'_LC_adv'};
2593: if ($curroption =~ /^autolimit=(\d*)$/) {
2594: $currlimit = $1;
2595: }
2596: }
2597: }
2598: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2599: my $checked = '';
2600: if ($curroption eq '') {
2601: $checked = ' checked="checked"';
2602: }
2603: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2604: '<input type="radio" name="crsreq_'.$item.
2605: '__LC_adv" value=""'.$checked.' />'.
2606: &mt('No override set').'</label></span> ';
1.101 raeburn 2607: foreach my $option (@options) {
2608: my $val = $option;
2609: if ($option eq 'norequest') {
2610: $val = 0;
2611: }
2612: if ($option eq 'validate') {
2613: my $canvalidate = 0;
2614: if (ref($validations{$item}) eq 'HASH') {
2615: if ($validations{$item}{'_LC_adv'}) {
2616: $canvalidate = 1;
2617: }
2618: }
2619: next if (!$canvalidate);
2620: }
2621: my $checked = '';
1.104 raeburn 2622: if ($val eq $curroption) {
1.101 raeburn 2623: $checked = ' checked="checked"';
2624: } elsif ($option eq 'autolimit') {
2625: if ($curroption =~ /^autolimit/) {
2626: $checked = ' checked="checked"';
2627: }
2628: }
2629: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2630: '<input type="radio" name="crsreq_'.$item.
2631: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2632: $titles{$option}.'</label>';
2633: if ($option eq 'autolimit') {
1.127 raeburn 2634: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2635: $item.'_limit__LC_adv" size="1" '.
2636: 'value="'.$currlimit.'" />';
2637: }
1.127 raeburn 2638: $advcell{$item} .= '</span> ';
1.104 raeburn 2639: if ($option eq 'autolimit') {
1.127 raeburn 2640: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2641: }
1.101 raeburn 2642: }
1.160.6.5 raeburn 2643: } elsif ($context eq 'requestauthor') {
2644: my $curroption;
2645: if (ref($settings) eq 'HASH') {
2646: $curroption = $settings->{'_LC_adv'};
2647: }
2648: my $checked = '';
2649: if ($curroption eq '') {
2650: $checked = ' checked="checked"';
2651: }
2652: $datatable .= '<span class="LC_nobreak"><label>'.
2653: '<input type="radio" name="authorreq__LC_adv"'.
2654: ' value=""'.$checked.' />'.
2655: &mt('No override set').'</label></span> ';
2656: foreach my $option (@options) {
2657: my $val = $option;
2658: if ($option eq 'norequest') {
2659: $val = 0;
2660: }
2661: my $checked = '';
2662: if ($val eq $curroption) {
2663: $checked = ' checked="checked"';
2664: }
2665: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2666: '<input type="radio" name="authorreq__LC_adv"'.
2667: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2668: $titles{$option}.'</label></span> ';
2669: }
1.101 raeburn 2670: } else {
2671: my $checked = 'checked="checked" ';
2672: if (ref($settings) eq 'HASH') {
2673: if (ref($settings->{$item}) eq 'HASH') {
2674: if ($settings->{$item}->{'_LC_adv'} == 0) {
2675: $checked = '';
2676: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2677: $checked = 'checked="checked" ';
2678: }
1.79 raeburn 2679: }
1.72 raeburn 2680: }
1.101 raeburn 2681: $datatable .= '<span class="LC_nobreak"><label>'.
2682: '<input type="checkbox" name="'.$context.'_'.$item.
2683: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2684: '</label></span> ';
2685: }
2686: }
2687: if ($context eq 'requestcourses') {
2688: $datatable .= '</tr><tr>';
2689: foreach my $item (@usertools) {
1.106 raeburn 2690: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2691: }
1.101 raeburn 2692: $datatable .= '</tr></table>';
1.72 raeburn 2693: }
1.98 raeburn 2694: $datatable .= '</td></tr>';
1.30 raeburn 2695: $$rowtotal += $typecount;
1.3 raeburn 2696: return $datatable;
2697: }
2698:
1.160.6.5 raeburn 2699: sub print_requestmail {
1.160.6.93 raeburn 2700: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2701: my ($now,$datatable,%currapp);
1.102 raeburn 2702: $now = time;
2703: if (ref($settings) eq 'HASH') {
2704: if (ref($settings->{'notify'}) eq 'HASH') {
2705: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2706: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2707: }
2708: }
2709: }
1.160.6.16 raeburn 2710: my $numinrow = 2;
1.160.6.34 raeburn 2711: my $css_class;
1.160.6.93 raeburn 2712: if ($$rowtotal%2) {
2713: $css_class = 'LC_odd_row';
2714: }
2715: if ($customcss) {
2716: $css_class .= " $customcss";
2717: }
2718: $css_class =~ s/^\s+//;
2719: if ($css_class) {
2720: $css_class = ' class="'.$css_class.'"';
2721: }
2722: if ($rowstyle) {
2723: $css_class .= ' style="'.$rowstyle.'"';
2724: }
1.160.6.5 raeburn 2725: my $text;
2726: if ($action eq 'requestcourses') {
2727: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2728: } elsif ($action eq 'requestauthor') {
2729: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2730: } else {
1.160.6.34 raeburn 2731: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2732: }
1.160.6.34 raeburn 2733: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2734: ' <td>'.$text.'</td>'.
1.102 raeburn 2735: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2736: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2737: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2738: if ($numdc > 0) {
2739: $datatable .= $table;
1.102 raeburn 2740: } else {
2741: $datatable .= &mt('There are no active Domain Coordinators');
2742: }
2743: $datatable .='</td></tr>';
2744: return $datatable;
2745: }
2746:
1.160.6.30 raeburn 2747: sub print_studentcode {
2748: my ($settings,$rowtotal) = @_;
2749: my $rownum = 0;
2750: my ($output,%current);
1.160.6.118.2 14(raebu 2751:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.51 raeburn 2752: if (ref($settings) eq 'HASH') {
2753: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2754: foreach my $type (@crstypes) {
2755: $current{$type} = $settings->{'uniquecode'}{$type};
2756: }
1.160.6.30 raeburn 2757: }
2758: }
2759: $output .= '<tr>'.
2760: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2761: '<td class="LC_left_item">';
2762: foreach my $type (@crstypes) {
2763: my $check = ' ';
2764: if ($current{$type}) {
2765: $check = ' checked="checked" ';
2766: }
2767: $output .= '<span class="LC_nobreak"><label>'.
2768: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2769: &mt($type).'</label></span>'.(' 'x2).' ';
2770: }
2771: $output .= '</td></tr>';
2772: $$rowtotal ++;
2773: return $output;
2774: }
2775:
2776: sub print_textbookcourses {
1.160.6.46 raeburn 2777: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2778: my $rownum = 0;
2779: my $css_class;
2780: my $itemcount = 1;
2781: my $maxnum = 0;
2782: my $bookshash;
2783: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2784: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2785: }
2786: my %ordered;
2787: if (ref($bookshash) eq 'HASH') {
2788: foreach my $item (keys(%{$bookshash})) {
2789: if (ref($bookshash->{$item}) eq 'HASH') {
2790: my $num = $bookshash->{$item}{'order'};
2791: $ordered{$num} = $item;
2792: }
2793: }
2794: }
2795: my $confname = $dom.'-domainconfig';
2796: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2797: my $maxnum = scalar(keys(%ordered));
2798: my $datatable;
1.160.6.30 raeburn 2799: if (keys(%ordered)) {
2800: my @items = sort { $a <=> $b } keys(%ordered);
2801: for (my $i=0; $i<@items; $i++) {
2802: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2803: my $key = $ordered{$items[$i]};
2804: my %coursehash=&Apache::lonnet::coursedescription($key);
2805: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2806: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2807: if (ref($bookshash->{$key}) eq 'HASH') {
2808: $subject = $bookshash->{$key}->{'subject'};
2809: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2810: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2811: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2812: $author = $bookshash->{$key}->{'author'};
2813: $image = $bookshash->{$key}->{'image'};
2814: if ($image ne '') {
2815: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2816: my $imagethumb = "$path/tn-".$imagefile;
2817: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2818: }
1.160.6.30 raeburn 2819: }
2820: }
1.160.6.46 raeburn 2821: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2822: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2823: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2824: for (my $k=0; $k<=$maxnum; $k++) {
2825: my $vpos = $k+1;
2826: my $selstr;
2827: if ($k == $i) {
2828: $selstr = ' selected="selected" ';
2829: }
2830: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2831: }
2832: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2833: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2834: &mt('Delete?').'</label></span></td>'.
2835: '<td colspan="2">'.
1.160.6.46 raeburn 2836: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2837: (' 'x2).
1.160.6.46 raeburn 2838: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2839: if ($type eq 'textbooks') {
2840: $datatable .= (' 'x2).
1.160.6.47 raeburn 2841: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2842: (' 'x2).
1.160.6.46 raeburn 2843: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2844: (' 'x2).
2845: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2846: if ($image) {
1.160.6.114 raeburn 2847: $datatable .= $imgsrc.
1.160.6.46 raeburn 2848: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2849: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2850: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2851: }
2852: if ($switchserver) {
2853: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2854: } else {
2855: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2856: }
1.160.6.30 raeburn 2857: }
1.160.6.46 raeburn 2858: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2859: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2860: $coursetitle.'</span></td></tr>'."\n";
2861: $itemcount ++;
2862: }
2863: }
2864: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2865: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2866: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2867: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2868: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2869: for (my $k=0; $k<$maxnum+1; $k++) {
2870: my $vpos = $k+1;
2871: my $selstr;
2872: if ($k == $maxnum) {
2873: $selstr = ' selected="selected" ';
2874: }
2875: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2876: }
2877: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2878: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2879: '<td colspan="2">'.
1.160.6.46 raeburn 2880: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2881: (' 'x2).
1.160.6.46 raeburn 2882: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2883: (' 'x2);
2884: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2885: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2886: (' 'x2).
2887: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2888: (' 'x2).
2889: '<span class="LC_nobreak">'.&mt('Image:').' ';
2890: if ($switchserver) {
2891: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2892: } else {
2893: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2894: }
1.160.6.87 raeburn 2895: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2896: }
1.160.6.87 raeburn 2897: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2898: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2899: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2900: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2901: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2902: '</span></td>'."\n".
2903: '</tr>'."\n";
2904: $itemcount ++;
2905: return $datatable;
2906: }
2907:
2908: sub textbookcourses_javascript {
1.160.6.46 raeburn 2909: my ($settings) = @_;
2910: return unless(ref($settings) eq 'HASH');
2911: my (%ordered,%total,%jstext);
2912: foreach my $type ('textbooks','templates') {
2913: $total{$type} = 0;
2914: if (ref($settings->{$type}) eq 'HASH') {
2915: foreach my $item (keys(%{$settings->{$type}})) {
2916: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2917: my $num = $settings->{$type}->{$item}{'order'};
2918: $ordered{$type}{$num} = $item;
2919: }
2920: }
2921: $total{$type} = scalar(keys(%{$settings->{$type}}));
2922: }
2923: my @jsarray = ();
2924: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2925: push(@jsarray,$ordered{$type}{$item});
2926: }
2927: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2928: }
2929: return <<"ENDSCRIPT";
2930: <script type="text/javascript">
2931: // <![CDATA[
1.160.6.46 raeburn 2932: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2933: var changedVal;
1.160.6.46 raeburn 2934: $jstext{'textbooks'};
2935: $jstext{'templates'};
2936: var newpos;
2937: var maxh;
2938: if (caller == 'textbooks') {
2939: newpos = 'textbooks_addbook_pos';
2940: maxh = 1 + $total{'textbooks'};
2941: } else {
2942: newpos = 'templates_addbook_pos';
2943: maxh = 1 + $total{'templates'};
2944: }
1.160.6.30 raeburn 2945: var current = new Array;
2946: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2947: if (item == newpos) {
2948: changedVal = newitemVal;
2949: } else {
2950: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2951: current[newitemVal] = newpos;
2952: }
1.160.6.46 raeburn 2953: if (caller == 'textbooks') {
2954: for (var i=0; i<textbooks.length; i++) {
2955: var elementName = 'textbooks_'+textbooks[i];
2956: if (elementName != item) {
2957: if (form.elements[elementName]) {
2958: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2959: current[currVal] = elementName;
2960: }
2961: }
2962: }
2963: }
2964: if (caller == 'templates') {
2965: for (var i=0; i<templates.length; i++) {
2966: var elementName = 'templates_'+templates[i];
2967: if (elementName != item) {
2968: if (form.elements[elementName]) {
2969: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2970: current[currVal] = elementName;
2971: }
1.160.6.30 raeburn 2972: }
2973: }
2974: }
2975: var oldVal;
2976: for (var j=0; j<maxh; j++) {
2977: if (current[j] == undefined) {
2978: oldVal = j;
2979: }
2980: }
2981: if (oldVal < changedVal) {
2982: for (var k=oldVal+1; k<=changedVal ; k++) {
2983: var elementName = current[k];
2984: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2985: }
2986: } else {
2987: for (var k=changedVal; k<oldVal; k++) {
2988: var elementName = current[k];
2989: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2990: }
2991: }
2992: return;
2993: }
2994:
2995: // ]]>
2996: </script>
2997:
2998: ENDSCRIPT
2999: }
3000:
1.160.6.118.2 1(raebur 3001:1): sub ltitools_javascript {
3002:1): my ($settings) = @_;
3003:1): my $togglejs = <itools_toggle_js();
3004:1): unless (ref($settings) eq 'HASH') {
3005:1): return $togglejs;
3006:1): }
3007:1): my (%ordered,$total,%jstext);
3008:1): $total = 0;
3009:1): foreach my $item (keys(%{$settings})) {
3010:1): if (ref($settings->{$item}) eq 'HASH') {
3011:1): my $num = $settings->{$item}{'order'};
3012:1): $ordered{$num} = $item;
3013:1): }
3014:1): }
3015:1): $total = scalar(keys(%{$settings}));
3016:1): my @jsarray = ();
3017:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3018:1): push(@jsarray,$ordered{$item});
3019:1): }
3020:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3021:1): return <<"ENDSCRIPT";
3022:1): <script type="text/javascript">
3023:1): // <![CDATA[
3024:1): function reorderLTITools(form,item) {
3025:1): var changedVal;
3026:1): $jstext
3027:1): var newpos = 'ltitools_add_pos';
3028:1): var maxh = 1 + $total;
3029:1): var current = new Array;
3030:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3031:1): if (item == newpos) {
3032:1): changedVal = newitemVal;
3033:1): } else {
3034:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3035:1): current[newitemVal] = newpos;
3036:1): }
3037:1): for (var i=0; i<ltitools.length; i++) {
3038:1): var elementName = 'ltitools_'+ltitools[i];
3039:1): if (elementName != item) {
3040:1): if (form.elements[elementName]) {
3041:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3042:1): current[currVal] = elementName;
3043:1): }
3044:1): }
3045:1): }
3046:1): var oldVal;
3047:1): for (var j=0; j<maxh; j++) {
3048:1): if (current[j] == undefined) {
3049:1): oldVal = j;
3050:1): }
3051:1): }
3052:1): if (oldVal < changedVal) {
3053:1): for (var k=oldVal+1; k<=changedVal ; k++) {
3054:1): var elementName = current[k];
3055:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3056:1): }
3057:1): } else {
3058:1): for (var k=changedVal; k<oldVal; k++) {
3059:1): var elementName = current[k];
3060:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3061:1): }
3062:1): }
3063:1): return;
3064:1): }
3065:1):
3066:1): // ]]>
3067:1): </script>
3068:1):
3069:1): $togglejs
3070:1):
3071:1): ENDSCRIPT
3072:1): }
3073:1):
3074:1): sub ltitools_toggle_js {
3075:1): return <<"ENDSCRIPT";
3076:1): <script type="text/javascript">
3077:1): // <![CDATA[
3078:1):
3079:1): function toggleLTITools(form,setting,item) {
3080:1): var radioname = '';
3081:1): var divid = '';
14(raebu 3082:23): if ((setting == 'passback') || (setting == 'roster')) {
3083:23): radioname = 'ltitools_'+setting+'_'+item;
3084:23): divid = 'ltitools_'+setting+'time_'+item;
3085:23): var num = form.elements[radioname].length;
3086:23): if (num) {
3087:23): var setvis = '';
3088:23): for (var i=0; i<num; i++) {
3089:23): if (form.elements[radioname][i].checked) {
3090:23): if (form.elements[radioname][i].value == '1') {
3091:23): if (document.getElementById(divid)) {
3092:23): document.getElementById(divid).style.display = 'inline-block';
3093:23): }
3094:23): setvis = 1;
3095:23): }
3096:23): break;
3097:23): }
3098:23): }
3099:23): }
3100:23): if (!setvis) {
3101:23): if (document.getElementById(divid)) {
3102:23): document.getElementById(divid).style.display = 'none';
3103:23): }
3104:23): }
3105:23): }
1(raebur 3106:1): if (setting == 'user') {
3107:1): divid = 'ltitools_'+setting+'_div_'+item;
3108:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3109:1): if (document.getElementById(divid)) {
3110:1): if (document.getElementById(checkid)) {
3111:1): if (document.getElementById(checkid).checked) {
3112:1): document.getElementById(divid).style.display = 'inline-block';
3113:1): } else {
3114:1): document.getElementById(divid).style.display = 'none';
3115:1): }
3116:1): }
3117:1): }
3118:1): }
3119:1): return;
3120:1): }
3121:1): // ]]>
3122:1): </script>
3123:1):
3124:1): ENDSCRIPT
3125:1): }
3126:1):
1.160.6.113 raeburn 3127: sub wafproxy_javascript {
3128: my ($dom) = @_;
3129: return <<"ENDSCRIPT";
3130: <script type="text/javascript">
3131: // <![CDATA[
3132: function updateWAF() {
3133: if (document.getElementById('wafproxy_remoteip')) {
3134: var wafremote = 0;
3135: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3136: wafremote = 1;
3137: }
3138: var fields = new Array('header','trust');
3139: for (var i=0; i<fields.length; i++) {
3140: if (document.getElementById('wafproxy_'+fields[i])) {
3141: if (wafremote == 1) {
3142: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3143: }
3144: else {
3145: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3146: }
3147: }
3148: }
3149: if (document.getElementById('wafproxyranges_$dom')) {
3150: if (wafremote == 1) {
3151: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3152: } else {
3153: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3154: if (document.display.wafproxy_vpnaccess[i].checked) {
3155: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3156: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3157: }
3158: }
3159: }
3160: }
3161: }
3162: }
3163: return;
3164: }
3165:
3166: function checkWAF() {
3167: if (document.getElementById('wafproxy_remoteip')) {
3168: var wafvpn = 0;
3169: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3170: if (document.display.wafproxy_vpnaccess[i].checked) {
3171: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3172: wafvpn = 1;
3173: }
3174: break;
3175: }
3176: }
3177: var vpn = new Array('vpnint','vpnext');
3178: for (var i=0; i<vpn.length; i++) {
3179: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3180: if (wafvpn == 1) {
3181: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3182: }
3183: else {
3184: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3185: }
3186: }
3187: }
3188: if (document.getElementById('wafproxyranges_$dom')) {
3189: if (wafvpn == 1) {
3190: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3191: }
3192: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3193: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3194: }
3195: }
3196: }
3197: return;
3198: }
3199:
3200: function toggleWAF() {
3201: if (document.getElementById('wafproxy_table')) {
3202: var wafproxy = 0;
3203: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3204: if (document.display.wafproxy_${dom}[i].checked) {
3205: if (document.display.wafproxy_${dom}[i].value == 1) {
3206: wafproxy = 1;
3207: break;
3208: }
3209: }
3210: }
3211: if (wafproxy == 1) {
3212: document.getElementById('wafproxy_table').style.display='inline';
3213: }
3214: else {
3215: document.getElementById('wafproxy_table').style.display='none';
3216: }
3217: if (document.getElementById('wafproxyrow_${dom}')) {
3218: if (wafproxy == 1) {
3219: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3220: }
3221: else {
3222: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3223: }
3224: }
3225: if (document.getElementById('nowafproxyrow_$dom')) {
3226: if (wafproxy == 1) {
3227: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3228: }
3229: else {
3230: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3231: }
3232: }
3233: }
3234: return;
3235: }
3236: // ]]>
3237: </script>
3238:
3239: ENDSCRIPT
3240: }
3241:
1.160.6.118.2 5(raebur 3242:2): sub lti_javascript {
3243:2): my ($dom,$settings) = @_;
3244:2): my $togglejs = <i_toggle_js($dom);
3245:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
14(raebu 3246:23): unless (ref($settings) eq 'HASH') {
3247:23): return $togglejs.'
3248:23): <script type="text/javascript">
3249:23): // <![CDATA[
3250:23):
3251:23): '.$linkprot_js.'
3252:23):
3253:23): // ]]>
3254:23): </script>
3255:23): ';
3256:23): }
3257:23): my (%ordered,$total,%jstext);
3258:23): $total = scalar(keys(%{$settings}));
3259:23): foreach my $item (keys(%{$settings})) {
3260:23): if (ref($settings->{$item}) eq 'HASH') {
3261:23): my $num = $settings->{$item}{'order'};
3262:23): if ($num eq '') {
3263:23): $num = $total - 1;
3264:23): }
3265:23): $ordered{$num} = $item;
3266:23): }
3267:23): }
3268:23): my @jsarray = ();
3269:23): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3270:23): push(@jsarray,$ordered{$item});
3271:23): }
3272:23): my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
5(raebur 3273:2): return <<"ENDSCRIPT";
3274:2): <script type="text/javascript">
3275:2): // <![CDATA[
14(raebu 3276:23): function reorderLTI(form,item) {
3277:23): var changedVal;
3278:23): $jstext
3279:23): var newpos = 'lti_pos_add';
3280:23): var maxh = 1 + $total;
3281:23): var current = new Array;
3282:23): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3283:23): if (item == newpos) {
3284:23): changedVal = newitemVal;
3285:23): } else {
3286:23): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3287:23): current[newitemVal] = newpos;
3288:23): }
3289:23): for (var i=0; i<lti.length; i++) {
3290:23): var elementName = 'lti_pos_'+lti[i];
3291:23): if (elementName != item) {
3292:23): if (form.elements[elementName]) {
3293:23): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3294:23): current[currVal] = elementName;
3295:23): }
3296:23): }
3297:23): }
3298:23): var oldVal;
3299:23): for (var j=0; j<maxh; j++) {
3300:23): if (current[j] == undefined) {
3301:23): oldVal = j;
3302:23): }
3303:23): }
3304:23): if (oldVal < changedVal) {
3305:23): for (var k=oldVal+1; k<=changedVal ; k++) {
3306:23): var elementName = current[k];
3307:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3308:23): }
3309:23): } else {
3310:23): for (var k=changedVal; k<oldVal; k++) {
3311:23): var elementName = current[k];
3312:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3313:23): }
3314:23): }
3315:23): return;
3316:23): }
5(raebur 3317:2):
3318:2): $linkprot_js
3319:2):
3320:2): // ]]>
3321:2): </script>
3322:2):
3323:2): $togglejs
3324:2):
3325:2): ENDSCRIPT
3326:2): }
3327:2):
3328:2): sub lti_toggle_js {
3329:2): my ($dom) = @_;
14(raebu 3330:23): my %lcauthparmtext = &Apache::lonlocal::texthash (
3331:23): localauth => 'Local auth argument',
3332:23): krb => 'Kerberos domain',
3333:23): );
3334: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");
3335:23): &js_escape(\$crsincalert);
5(raebur 3336:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3337:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3338:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3339:2): return <<"ENDSCRIPT";
3340:2): <script type="text/javascript">
3341:2): // <![CDATA[
14(raebu 3342:23):
3343:23): function toggleLTI(form,setting,item) {
3344:23): if ((setting == 'requser') || (setting == 'crsinc')) {
3345:23): var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3346:23): var setvis = '';
3347:23): var radioname = 'lti_requser_'+item;
3348:23): var num = form.elements[radioname].length;
3349:23): if (num) {
3350:23): for (var i=0; i<num; i++) {
3351:23): if (form.elements[radioname][i].checked) {
3352:23): if (form.elements[radioname][i].value == '1') {
3353:23): setvis = 1;
3354:23): break;
5(raebur 3355:2): }
14(raebu 3356:23): }
3357:23): }
3358:23): }
3359:23): if (usrfieldsets.length) {
3360:23): for (var j=0; j<usrfieldsets.length; j++) {
3361:23): if (setvis) {
3362:23): usrfieldsets[j].style.display = 'block';
3363:23): } else {
3364:23): usrfieldsets[j].style.display = 'none';
3365:23): }
3366:23): }
3367:23): }
3368:23): var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3369:23): if (crsfieldsets.length) {
3370:23): radioname = 'lti_crsinc_'+item;
3371:23): var num = form.elements[radioname].length;
3372:23): if (num) {
3373:23): var crsvis = '';
3374:23): for (var i=0; i<num; i++) {
3375:23): if (form.elements[radioname][i].checked) {
3376:23): if (form.elements[radioname][i].value == '1') {
3377:23): if (setvis == '') {
3378:23): if (setting == 'crsinc'){
3379:23): alert("$crsincalert");
3380:23): form.elements[radioname][0].checked = true;
3381:23): }
3382:23): } else {
3383:23): crsvis = 1;
5(raebur 3384:2): }
14(raebu 3385:23): break;
5(raebur 3386:2): }
3387:2): }
3388:2): }
14(raebu 3389:23): setvis = crsvis;
5(raebur 3390:2): }
14(raebu 3391:23): for (var j=0; j<crsfieldsets.length; j++) {
3392:23): if (setvis) {
3393:23): crsfieldsets[j].style.display = 'block';
3394:23): } else {
3395:23): crsfieldsets[j].style.display = 'none';
5(raebur 3396:2): }
3397:2): }
3398:2): }
14(raebu 3399:23): } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
3400:23): var radioname = '';
3401:23): var divid = '';
3402:23): if (setting == 'user') {
3403:23): radioname = 'lti_mapuser_'+item;
3404:23): divid = 'lti_userfield_'+item;
3405:23): } else if (setting == 'crs') {
3406:23): radioname = 'lti_mapcrs_'+item;
3407:23): divid = 'lti_crsfield_'+item;
3408:23): } else if (setting == 'callback') {
3409:23): radioname = 'lti_callback_'+item;
3410:23): divid = 'lti_callbackfield_'+item;
3411:23): } else {
3412:23): radioname = 'lti_passback_'+item;
3413:23): divid = 'lti_passback_'+item;
3414:23): }
3415:23): var num = form.elements[radioname].length;
3416:23): if (num) {
3417:23): var setvis = '';
3418:23): for (var i=0; i<num; i++) {
3419:23): if (form.elements[radioname][i].checked) {
3420:23): if ((setting == 'passback') || (setting == 'callback')) {
3421:23): if (form.elements[radioname][i].value == '1') {
3422:23): if (document.getElementById(divid)) {
3423:23): document.getElementById(divid).style.display = 'inline-block';
3424:23): }
3425:23): setvis = 1;
3426:23): break;
3427:23): }
3428:23): } else {
3429:23): if (form.elements[radioname][i].value == 'other') {
3430:23): if (document.getElementById(divid)) {
3431:23): document.getElementById(divid).style.display = 'inline-block';
3432:23): }
3433:23): setvis = 1;
3434:23): break;
3435:23): }
3436:23): }
3437:23): }
3438:23): }
3439:23): if (!setvis) {
3440:23): if (document.getElementById(divid)) {
3441:23): document.getElementById(divid).style.display = 'none';
3442:23): }
5(raebur 3443:2): }
3444:2): }
14(raebu 3445:23): } else if ((setting == 'sec') || (setting == 'secsrc')) {
3446:23): var numsec = form.elements['lti_crssec_'+item].length;
3447:23): if (numsec) {
3448:23): var setvis = '';
3449:23): for (var i=0; i<numsec; i++) {
3450:23): if (form.elements['lti_crssec_'+item][i].checked) {
3451:23): if (form.elements['lti_crssec_'+item][i].value == '1') {
3452:23): if (document.getElementById('lti_crssecfield_'+item)) {
3453:23): document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3454:23): setvis = 1;
3455:23): var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3456:23): if (numsrcsec) {
3457:23): var setsrcvis = '';
3458:23): for (var j=0; j<numsrcsec; j++) {
3459:23): if (form.elements['lti_crssecsrc_'+item][j].checked) {
3460:23): if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3461:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3462:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3463:23): setsrcvis = 1;
3464:23): }
3465:23): }
3466:23): }
3467:23): }
3468:23): if (!setsrcvis) {
3469:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3470:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3471:23): }
3472:23): }
3473:23): }
3474:23): }
3475:23): }
3476:23): }
3477:23): }
3478:23): if (!setvis) {
3479:23): if (document.getElementById('lti_crssecfield_'+item)) {
3480:23): document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3481:23): }
3482:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3483:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3484:23): }
3485:23): }
5(raebur 3486:2): }
14(raebu 3487:23): } else if (setting == 'lcauth') {
3488:23): var numauth = form.elements['lti_lcauth_'+item].length;
3489:23): if (numauth) {
3490:23): for (var i=0; i<numauth; i++) {
3491:23): if (form.elements['lti_lcauth_'+item][i].checked) {
3492:23): if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3493:23): if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3494:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3495:23): } else {
3496:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3497:23): if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3498:23): if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3499:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3500:23): } else {
3501:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3502:23): }
3503:23): }
3504:23): }
3505:23): }
5(raebur 3506:2): }
3507:2): }
3508:2): }
14(raebu 3509:23): } else if (setting == 'lcmenu') {
3510:23): var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3511:23): var divid = 'lti_menufield_'+item;
3512:23): var setvis = '';
3513:23): for (var i=0; i<menus.length; i++) {
3514:23): var radioname = menus[i];
3515:23): var num = form.elements[radioname].length;
3516:23): if (num) {
3517:23): for (var j=0; j<num; j++) {
3518:23): if (form.elements[radioname][j].checked) {
3519:23): if (form.elements[radioname][j].value == '1') {
3520:23): if (document.getElementById(divid)) {
3521:23): document.getElementById(divid).style.display = 'inline-block';
3522:23): }
5(raebur 3523:2): setvis = 1;
14(raebu 3524:23): break;
5(raebur 3525:2): }
3526:2): }
3527:2): }
14(raebu 3528:23): }
3529:23): if (setvis == 1) {
3530:23): break;
3531:23): }
3532:23): }
3533:23): if (!setvis) {
3534:23): if (document.getElementById(divid)) {
3535:23): document.getElementById(divid).style.display = 'none';
5(raebur 3536:2): }
3537:2): }
3538:2): }
14(raebu 3539:23): return;
5(raebur 3540:2): }
3541:2):
3542:2): // ]]>
3543:2): </script>
3544:2):
3545:2): ENDSCRIPT
3546:2): }
3547:2):
1.160.6.113 raeburn 3548: sub autoupdate_javascript {
3549: return <<"ENDSCRIPT";
3550: <script type="text/javascript">
3551: // <![CDATA[
3552: function toggleLastActiveDays(form) {
3553: var radioname = 'lastactive';
3554: var divid = 'lastactive_div';
3555: var num = form.elements[radioname].length;
3556: if (num) {
3557: var setvis = '';
3558: for (var i=0; i<num; i++) {
3559: if (form.elements[radioname][i].checked) {
3560: if (form.elements[radioname][i].value == '1') {
3561: if (document.getElementById(divid)) {
3562: document.getElementById(divid).style.display = 'inline-block';
3563: }
3564: setvis = 1;
3565: }
3566: break;
3567: }
3568: }
3569: if (!setvis) {
3570: if (document.getElementById(divid)) {
3571: document.getElementById(divid).style.display = 'none';
3572: }
3573: }
3574: }
3575: return;
3576: }
3577: // ]]>
3578: </script>
3579:
3580: ENDSCRIPT
3581: }
3582:
1.160.6.116 raeburn 3583: sub autoenroll_javascript {
3584: return <<"ENDSCRIPT";
3585: <script type="text/javascript">
3586: // <![CDATA[
3587: function toggleFailsafe(form) {
3588: var radioname = 'autoenroll_failsafe';
3589: var divid = 'autoenroll_failsafe_div';
3590: var num = form.elements[radioname].length;
3591: if (num) {
3592: var setvis = '';
3593: for (var i=0; i<num; i++) {
3594: if (form.elements[radioname][i].checked) {
3595: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3596: if (document.getElementById(divid)) {
3597: document.getElementById(divid).style.display = 'inline-block';
3598: }
3599: setvis = 1;
3600: }
3601: break;
3602: }
3603: }
3604: if (!setvis) {
3605: if (document.getElementById(divid)) {
3606: document.getElementById(divid).style.display = 'none';
3607: }
3608: }
3609: }
3610: return;
3611: }
3612: // ]]>
3613: </script>
3614:
3615: ENDSCRIPT
3616: }
3617:
1.160.6.113 raeburn 3618: sub saml_javascript {
3619: return <<"ENDSCRIPT";
3620: <script type="text/javascript">
3621: // <![CDATA[
3622: function toggleSamlOptions(form,hostid) {
3623: var radioname = 'saml_'+hostid;
3624: var tablecellon = 'samloptionson_'+hostid;
3625: var tablecelloff = 'samloptionsoff_'+hostid;
3626: var num = form.elements[radioname].length;
3627: if (num) {
3628: var setvis = '';
3629: for (var i=0; i<num; i++) {
3630: if (form.elements[radioname][i].checked) {
3631: if (form.elements[radioname][i].value == '1') {
3632: if (document.getElementById(tablecellon)) {
3633: document.getElementById(tablecellon).style.display='';
3634: }
3635: if (document.getElementById(tablecelloff)) {
3636: document.getElementById(tablecelloff).style.display='none';
3637: }
3638: setvis = 1;
3639: }
3640: break;
3641: }
3642: }
3643: if (!setvis) {
3644: if (document.getElementById(tablecellon)) {
3645: document.getElementById(tablecellon).style.display='none';
3646: }
3647: if (document.getElementById(tablecelloff)) {
3648: document.getElementById(tablecelloff).style.display='';
3649: }
3650: }
3651: }
3652: return;
3653: }
3654: // ]]>
3655: </script>
3656:
3657: ENDSCRIPT
3658: }
3659:
3660: sub ipaccess_javascript {
3661: my ($settings) = @_;
3662: my (%ordered,$total,%jstext);
3663: $total = 0;
3664: if (ref($settings) eq 'HASH') {
3665: foreach my $item (keys(%{$settings})) {
3666: if (ref($settings->{$item}) eq 'HASH') {
3667: my $num = $settings->{$item}{'order'};
3668: $ordered{$num} = $item;
3669: }
3670: }
3671: $total = scalar(keys(%{$settings}));
3672: }
3673: my @jsarray = ();
3674: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3675: push(@jsarray,$ordered{$item});
3676: }
3677: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3678: return <<"ENDSCRIPT";
3679: <script type="text/javascript">
3680: // <![CDATA[
3681: function reorderIPaccess(form,item) {
3682: var changedVal;
3683: $jstext
3684: var newpos = 'ipaccess_pos_add';
3685: var maxh = 1 + $total;
3686: var current = new Array;
3687: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3688: if (item == newpos) {
3689: changedVal = newitemVal;
3690: } else {
3691: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3692: current[newitemVal] = newpos;
3693: }
3694: for (var i=0; i<ipaccess.length; i++) {
3695: var elementName = 'ipaccess_pos_'+ipaccess[i];
3696: if (elementName != item) {
3697: if (form.elements[elementName]) {
3698: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3699: current[currVal] = elementName;
3700: }
3701: }
3702: }
3703: var oldVal;
3704: for (var j=0; j<maxh; j++) {
3705: if (current[j] == undefined) {
3706: oldVal = j;
3707: }
3708: }
3709: if (oldVal < changedVal) {
3710: for (var k=oldVal+1; k<=changedVal ; k++) {
3711: var elementName = current[k];
3712: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3713: }
3714: } else {
3715: for (var k=changedVal; k<oldVal; k++) {
3716: var elementName = current[k];
3717: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3718: }
3719: }
3720: return;
3721: }
3722: // ]]>
3723: </script>
3724:
3725: ENDSCRIPT
3726: }
3727:
1.160.6.118.2 20(raebu 3728:24): sub authordefaults_javascript {
3729:24): my %alert = &Apache::lonlocal::texthash (
3730:24): reqd => 'Warning: at least one editor needs to be available.',
3731:24): rest => 'Unchecking this editor disallowed while others unchecked.',
3732:24): );
3733:24): &js_escape(\%alert);
3734:24): return <<"ENDSCRIPT";
3735:24): <script type="text/javascript">
3736:24): // <![CDATA[
3737:24):
3738:24): function checkEditors(form,checkbox,current) {
3739:24): if (form.elements[checkbox].length != undefined) {
3740:24): var count = 0;
3741:24): for (var i=0; i<form.elements[checkbox].length; i++) {
3742:24): if (form.elements[checkbox][i].checked) {
3743:24): count ++;
3744:24): }
3745:24): }
3746:24): if (count == 0) {
3747:24): if (current.type =='radio') {
3748:24): current.checked = true;
3749:24): alert('$alert{reqd}\\n$alert{rest}');
3750:24): }
3751:24): }
3752:24): }
3753:24): return;
3754:24): }
3755:24): // ]]>
3756:24): </script>
3757:24):
3758:24): ENDSCRIPT
3759:24): }
3760:24):
1.3 raeburn 3761: sub print_autoenroll {
1.30 raeburn 3762: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3763: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3764: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3765: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3766: $failsafesty = 'none';
3767: %failsafechecked = (
3768: off => ' checked="checked"',
3769: );
1.3 raeburn 3770: if (ref($settings) eq 'HASH') {
3771: if (exists($settings->{'run'})) {
3772: if ($settings->{'run'} eq '0') {
3773: $runoff = ' checked="checked" ';
3774: $runon = ' ';
3775: } else {
3776: $runon = ' checked="checked" ';
3777: $runoff = ' ';
3778: }
3779: } else {
3780: if ($autorun) {
3781: $runon = ' checked="checked" ';
3782: $runoff = ' ';
3783: } else {
3784: $runoff = ' checked="checked" ';
3785: $runon = ' ';
3786: }
3787: }
1.129 raeburn 3788: if (exists($settings->{'co-owners'})) {
3789: if ($settings->{'co-owners'} eq '0') {
3790: $coownersoff = ' checked="checked" ';
3791: $coownerson = ' ';
3792: } else {
3793: $coownerson = ' checked="checked" ';
3794: $coownersoff = ' ';
3795: }
3796: } else {
3797: $coownersoff = ' checked="checked" ';
3798: $coownerson = ' ';
3799: }
1.3 raeburn 3800: if (exists($settings->{'sender_domain'})) {
3801: $defdom = $settings->{'sender_domain'};
3802: }
1.160.6.116 raeburn 3803: if (exists($settings->{'failsafe'})) {
3804: $failsafe = $settings->{'failsafe'};
3805: if ($failsafe eq 'zero') {
3806: $failsafechecked{'zero'} = ' checked="checked"';
3807: $failsafechecked{'off'} = '';
3808: $failsafesty = 'inline-block';
3809: } elsif ($failsafe eq 'any') {
3810: $failsafechecked{'any'} = ' checked="checked"';
3811: $failsafechecked{'off'} = '';
3812: }
3813: $autofailsafe = $settings->{'autofailsafe'};
3814: } elsif (exists($settings->{'autofailsafe'})) {
3815: $autofailsafe = $settings->{'autofailsafe'};
3816: if ($autofailsafe ne '') {
3817: $failsafechecked{'zero'} = ' checked="checked"';
3818: $failsafe = 'zero';
3819: $failsafechecked{'off'} = '';
3820: }
1.160.6.68 raeburn 3821: }
1.14 raeburn 3822: } else {
3823: if ($autorun) {
3824: $runon = ' checked="checked" ';
3825: $runoff = ' ';
3826: } else {
3827: $runoff = ' checked="checked" ';
3828: $runon = ' ';
3829: }
1.3 raeburn 3830: }
3831: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3832: my $notif_sender;
3833: if (ref($settings) eq 'HASH') {
3834: $notif_sender = $settings->{'sender_uname'};
3835: }
1.3 raeburn 3836: my $datatable='<tr class="LC_odd_row">'.
3837: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3838: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3839: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3840: $runon.' value="1" />'.&mt('Yes').'</label> '.
3841: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3842: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3843: '</tr><tr>'.
3844: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3845: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3846: &mt('username').': '.
3847: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3848: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3849: ': '.$domform.'</span></td></tr>'.
3850: '<tr class="LC_odd_row">'.
3851: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3852: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3853: '<input type="radio" name="autoassign_coowners"'.
3854: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3855: '<label><input type="radio" name="autoassign_coowners"'.
3856: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3857: '</tr><tr>'.
3858: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3859: '<td class="LC_left_item"><span class="LC_nobreak">'.
3860: '<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> '.
3861: '<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 />'.
3862: '<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>'.
3863: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3864: '<span class="LC_nobreak">'.
3865: &mt('Threshold for number of students in section to drop: [_1]',
3866: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3867: '</span></div></td></tr>';
1.160.6.68 raeburn 3868: $$rowtotal += 4;
1.3 raeburn 3869: return $datatable;
3870: }
3871:
3872: sub print_autoupdate {
1.30 raeburn 3873: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3874: my ($enable,$datatable);
1.3 raeburn 3875: if ($position eq 'top') {
1.160.6.113 raeburn 3876: my %choices = &Apache::lonlocal::texthash (
3877: run => 'Auto-update active?',
3878: classlists => 'Update information in classlists?',
3879: unexpired => 'Skip updates for users without active or future roles?',
3880: lastactive => 'Skip updates for inactive users?',
3881: );
3882: my $itemcount = 0;
1.3 raeburn 3883: my $updateon = ' ';
3884: my $updateoff = ' checked="checked" ';
3885: if (ref($settings) eq 'HASH') {
3886: if ($settings->{'run'} eq '1') {
3887: $updateon = $updateoff;
3888: $updateoff = ' ';
3889: }
3890: }
1.160.6.118.2 14(raebu 3891:23): $enable = '<tr class="LC_odd_row">'.
3892:23): '<td>'.$choices{'run'}.'</td>'.
1.160.6.113 raeburn 3893: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3894: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3895: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3896: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3897: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3898: '</tr>';
1.160.6.113 raeburn 3899: my @toggles = ('classlists','unexpired');
3900: my %defaultchecked = ('classlists' => 'off',
3901: 'unexpired' => 'off'
3902: );
3903: $$rowtotal ++;
3904: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3905: \%choices,$itemcount,'','','left','no');
3906: $datatable = $enable.$datatable;
3907: $$rowtotal += $itemcount;
3908: my $lastactiveon = ' ';
3909: my $lastactiveoff = ' checked="checked" ';
3910: my $lastactivestyle = 'none';
3911: my $lastactivedays;
3912: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3913: if (ref($settings) eq 'HASH') {
3914: if ($settings->{'lastactive'} =~ /^\d+$/) {
3915: $lastactiveon = $lastactiveoff;
3916: $lastactiveoff = ' ';
3917: $lastactivestyle = 'inline-block';
3918: $lastactivedays = $settings->{'lastactive'};
3919: }
3920: }
3921: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3922: $datatable .= '<tr'.$css_class.'>'.
3923: '<td>'.$choices{'lastactive'}.'</td>'.
3924: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3925: '<input type="radio" name="lastactive"'.
3926: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3927: ' <label>'.
3928: '<input type="radio" name="lastactive"'.
3929: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3930: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3931: ': '.&mt('inactive = no activity in last [_1] days',
3932: '<input type="text" size="5" name="lastactivedays" value="'.
3933: $lastactivedays.'" />').
3934: '</span></td>'.
3935: '</tr>';
3936: $$rowtotal ++;
1.131 raeburn 3937: } elsif ($position eq 'middle') {
3938: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3939: my $numinrow = 3;
3940: my $locknamesettings;
3941: $datatable .= &insttypes_row($settings,$types,$usertypes,
3942: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3943: 'lockablenames',$rowtotal);
1.131 raeburn 3944: $$rowtotal ++;
1.3 raeburn 3945: } else {
1.44 raeburn 3946: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3947: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3948: 'permanentemail','id');
1.33 raeburn 3949: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3950: my $numrows = 0;
1.26 raeburn 3951: if (ref($types) eq 'ARRAY') {
3952: if (@{$types} > 0) {
3953: $datatable =
3954: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3955: \@fields,$types,\$numrows);
1.30 raeburn 3956: $$rowtotal += @{$types};
1.26 raeburn 3957: }
1.3 raeburn 3958: }
3959: $datatable .=
3960: &usertype_update_row($settings,{'default' => $othertitle},
3961: \%fieldtitles,\@fields,['default'],
3962: \$numrows);
1.30 raeburn 3963: $$rowtotal ++;
1.3 raeburn 3964: }
3965: return $datatable;
3966: }
3967:
1.125 raeburn 3968: sub print_autocreate {
3969: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3970: my (%createon,%createoff,%currhash);
1.125 raeburn 3971: my @types = ('xml','req');
3972: if (ref($settings) eq 'HASH') {
3973: foreach my $item (@types) {
3974: $createoff{$item} = ' checked="checked" ';
3975: $createon{$item} = ' ';
3976: if (exists($settings->{$item})) {
3977: if ($settings->{$item}) {
3978: $createon{$item} = ' checked="checked" ';
3979: $createoff{$item} = ' ';
3980: }
3981: }
3982: }
1.160.6.16 raeburn 3983: if ($settings->{'xmldc'} ne '') {
3984: $currhash{$settings->{'xmldc'}} = 1;
3985: }
1.125 raeburn 3986: } else {
3987: foreach my $item (@types) {
3988: $createoff{$item} = ' checked="checked" ';
3989: $createon{$item} = ' ';
3990: }
3991: }
3992: $$rowtotal += 2;
1.160.6.16 raeburn 3993: my $numinrow = 2;
1.125 raeburn 3994: my $datatable='<tr class="LC_odd_row">'.
3995: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3996: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3997: '<input type="radio" name="autocreate_xml"'.
3998: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3999: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4000: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4001: '</td></tr><tr>'.
4002: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4003: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4004: '<input type="radio" name="autocreate_req"'.
4005: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4006: '<label><input type="radio" name="autocreate_req"'.
4007: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 4008: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4009: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 4010: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4011: if ($numdc > 1) {
1.160.6.50 raeburn 4012: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4013: '</td><td class="LC_left_item">';
1.125 raeburn 4014: } else {
1.160.6.50 raeburn 4015: $datatable .= &mt('Course creation processed as:').
4016: '</td><td class="LC_right_item">';
1.125 raeburn 4017: }
1.160.6.50 raeburn 4018: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 4019: $$rowtotal += $rows;
1.125 raeburn 4020: return $datatable;
4021: }
4022:
1.23 raeburn 4023: sub print_directorysrch {
1.160.6.72 raeburn 4024: my ($position,$dom,$settings,$rowtotal) = @_;
4025: my $datatable;
4026: if ($position eq 'top') {
4027: my $instsrchon = ' ';
4028: my $instsrchoff = ' checked="checked" ';
4029: my ($exacton,$containson,$beginson);
4030: my $instlocalon = ' ';
4031: my $instlocaloff = ' checked="checked" ';
4032: if (ref($settings) eq 'HASH') {
4033: if ($settings->{'available'} eq '1') {
4034: $instsrchon = $instsrchoff;
4035: $instsrchoff = ' ';
4036: }
4037: if ($settings->{'localonly'} eq '1') {
4038: $instlocalon = $instlocaloff;
4039: $instlocaloff = ' ';
4040: }
4041: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4042: foreach my $type (@{$settings->{'searchtypes'}}) {
4043: if ($type eq 'exact') {
4044: $exacton = ' checked="checked" ';
4045: } elsif ($type eq 'contains') {
4046: $containson = ' checked="checked" ';
4047: } elsif ($type eq 'begins') {
4048: $beginson = ' checked="checked" ';
4049: }
4050: }
4051: } else {
4052: if ($settings->{'searchtypes'} eq 'exact') {
4053: $exacton = ' checked="checked" ';
4054: } elsif ($settings->{'searchtypes'} eq 'contains') {
4055: $containson = ' checked="checked" ';
4056: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4057: $exacton = ' checked="checked" ';
4058: $containson = ' checked="checked" ';
4059: }
4060: }
1.23 raeburn 4061: }
1.160.6.72 raeburn 4062: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4063: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 4064:
1.160.6.72 raeburn 4065: my $numinrow = 4;
4066: my $cansrchrow = 0;
4067: $datatable='<tr class="LC_odd_row">'.
4068: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4070: '<input type="radio" name="dirsrch_available"'.
4071: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4072: '<label><input type="radio" name="dirsrch_available"'.
4073: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4074: '</tr><tr>'.
4075: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4076: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4077: '<input type="radio" name="dirsrch_instlocalonly"'.
4078: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4079: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4080: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4081: '</tr>';
4082: $$rowtotal += 2;
4083: if (ref($usertypes) eq 'HASH') {
4084: if (keys(%{$usertypes}) > 0) {
4085: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 4086: $numinrow,$othertitle,'cansearch',
4087: $rowtotal);
1.160.6.72 raeburn 4088: $cansrchrow = 1;
4089: }
1.26 raeburn 4090: }
1.160.6.72 raeburn 4091: if ($cansrchrow) {
4092: $$rowtotal ++;
4093: $datatable .= '<tr>';
4094: } else {
4095: $datatable .= '<tr class="LC_odd_row">';
4096: }
4097: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4098: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4099: foreach my $title (@{$titleorder}) {
4100: if (defined($searchtitles->{$title})) {
4101: my $check = ' ';
4102: if (ref($settings) eq 'HASH') {
4103: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4104: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4105: $check = ' checked="checked" ';
4106: }
1.39 raeburn 4107: }
1.25 raeburn 4108: }
1.160.6.72 raeburn 4109: $datatable .= '<td class="LC_left_item">'.
4110: '<span class="LC_nobreak"><label>'.
4111: '<input type="checkbox" name="searchby" '.
4112: 'value="'.$title.'"'.$check.'/>'.
4113: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4114: }
4115: }
1.160.6.72 raeburn 4116: $datatable .= '</tr></table></td></tr>';
4117: $$rowtotal ++;
4118: if ($cansrchrow) {
4119: $datatable .= '<tr class="LC_odd_row">';
4120: } else {
4121: $datatable .= '<tr>';
4122: }
4123: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4124: '<td class="LC_left_item" colspan="2">'.
4125: '<span class="LC_nobreak"><label>'.
4126: '<input type="checkbox" name="searchtypes" '.
4127: $exacton.' value="exact" />'.&mt('Exact match').
4128: '</label> '.
4129: '<label><input type="checkbox" name="searchtypes" '.
4130: $beginson.' value="begins" />'.&mt('Begins with').
4131: '</label> '.
4132: '<label><input type="checkbox" name="searchtypes" '.
4133: $containson.' value="contains" />'.&mt('Contains').
4134: '</label></span></td></tr>';
4135: $$rowtotal ++;
1.26 raeburn 4136: } else {
1.160.6.72 raeburn 4137: my $domsrchon = ' checked="checked" ';
4138: my $domsrchoff = ' ';
4139: my $domlocalon = ' ';
4140: my $domlocaloff = ' checked="checked" ';
4141: if (ref($settings) eq 'HASH') {
4142: if ($settings->{'lclocalonly'} eq '1') {
4143: $domlocalon = $domlocaloff;
4144: $domlocaloff = ' ';
4145: }
4146: if ($settings->{'lcavailable'} eq '0') {
4147: $domsrchoff = $domsrchon;
4148: $domsrchon = ' ';
4149: }
4150: }
4151: $datatable='<tr class="LC_odd_row">'.
4152: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4153: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4154: '<input type="radio" name="dirsrch_domavailable"'.
4155: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4156: '<label><input type="radio" name="dirsrch_domavailable"'.
4157: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4158: '</tr><tr>'.
4159: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4160: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4161: '<input type="radio" name="dirsrch_domlocalonly"'.
4162: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4163: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4164: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4165: '</tr>';
4166: $$rowtotal += 2;
1.26 raeburn 4167: }
1.25 raeburn 4168: return $datatable;
4169: }
4170:
1.28 raeburn 4171: sub print_contacts {
1.160.6.78 raeburn 4172: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4173: my $datatable;
4174: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 4175: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 4176: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 4177: if ($position eq 'top') {
4178: if (ref($settings) eq 'HASH') {
4179: foreach my $item (@contacts) {
4180: if (exists($settings->{$item})) {
4181: $to{$item} = $settings->{$item};
4182: }
1.28 raeburn 4183: }
4184: }
1.160.6.78 raeburn 4185: } elsif ($position eq 'middle') {
4186: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 4187: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 4188: foreach my $type (@mailings) {
1.160.6.78 raeburn 4189: $otheremails{$type} = '';
4190: }
1.160.6.107 raeburn 4191: } elsif ($position eq 'lower') {
4192: if (ref($settings) eq 'HASH') {
4193: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4194: %lonstatus = %{$settings->{'lonstatus'}};
4195: }
4196: }
1.160.6.78 raeburn 4197: } else {
4198: @mailings = ('helpdeskmail','otherdomsmail');
4199: foreach my $type (@mailings) {
4200: $otheremails{$type} = '';
4201: }
4202: $bccemails{'helpdeskmail'} = '';
4203: $bccemails{'otherdomsmail'} = '';
4204: $includestr{'helpdeskmail'} = '';
4205: $includestr{'otherdomsmail'} = '';
4206: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4207: }
4208: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 4209: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4210: foreach my $type (@mailings) {
4211: if (exists($settings->{$type})) {
4212: if (ref($settings->{$type}) eq 'HASH') {
4213: foreach my $item (@contacts) {
4214: if ($settings->{$type}{$item}) {
4215: $checked{$type}{$item} = ' checked="checked" ';
4216: }
1.28 raeburn 4217: }
1.160.6.78 raeburn 4218: $otheremails{$type} = $settings->{$type}{'others'};
4219: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4220: $bccemails{$type} = $settings->{$type}{'bcc'};
4221: if ($settings->{$type}{'include'} ne '') {
4222: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4223: $includestr{$type} = &unescape($includestr{$type});
4224: }
4225: }
4226: }
4227: } elsif ($type eq 'lonstatusmail') {
4228: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4229: }
4230: }
4231: }
4232: if ($position eq 'bottom') {
4233: foreach my $type (@mailings) {
4234: $bccemails{$type} = $settings->{$type}{'bcc'};
4235: if ($settings->{$type}{'include'} ne '') {
4236: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4237: $includestr{$type} = &unescape($includestr{$type});
4238: }
4239: }
4240: if (ref($settings->{'helpform'}) eq 'HASH') {
4241: if (ref($fields) eq 'ARRAY') {
4242: foreach my $field (@{$fields}) {
4243: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4244: }
1.160.6.78 raeburn 4245: }
4246: if (exists($settings->{'helpform'}{'maxsize'})) {
4247: $maxsize = $settings->{'helpform'}{'maxsize'};
4248: } else {
4249: $maxsize = '1.0';
4250: }
4251: } else {
4252: if (ref($fields) eq 'ARRAY') {
4253: foreach my $field (@{$fields}) {
4254: $currfield{$field} = 'yes';
1.134 raeburn 4255: }
1.28 raeburn 4256: }
1.160.6.78 raeburn 4257: $maxsize = '1.0';
1.28 raeburn 4258: }
4259: }
4260: } else {
1.160.6.78 raeburn 4261: if ($position eq 'top') {
4262: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4263: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4264: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4265: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
4266: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4267: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4268: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4269: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 4270: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 4271: } elsif ($position eq 'bottom') {
4272: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4273: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4274: if (ref($fields) eq 'ARRAY') {
4275: foreach my $field (@{$fields}) {
4276: $currfield{$field} = 'yes';
4277: }
4278: }
4279: $maxsize = '1.0';
4280: }
1.28 raeburn 4281: }
4282: my ($titles,$short_titles) = &contact_titles();
4283: my $rownum = 0;
4284: my $css_class;
1.160.6.78 raeburn 4285: if ($position eq 'top') {
4286: foreach my $item (@contacts) {
4287: $css_class = $rownum%2?' class="LC_odd_row"':'';
4288: $datatable .= '<tr'.$css_class.'>'.
4289: '<td><span class="LC_nobreak">'.$titles->{$item}.
4290: '</span></td><td class="LC_right_item">'.
4291: '<input type="text" name="'.$item.'" value="'.
4292: $to{$item}.'" /></td></tr>';
4293: $rownum ++;
4294: }
1.160.6.101 raeburn 4295: } elsif ($position eq 'bottom') {
4296: $css_class = $rownum%2?' class="LC_odd_row"':'';
4297: $datatable .= '<tr'.$css_class.'>'.
4298: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4299: &mt('(e-mail, subject, and description always shown)').
4300: '</td><td class="LC_left_item">';
4301: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4302: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4303: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4304: foreach my $field (@{$fields}) {
4305: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4306: if (($field eq 'screenshot') || ($field eq 'cc')) {
4307: $datatable .= ' '.&mt('(logged-in users)');
4308: }
4309: $datatable .='</td><td>';
4310: my $clickaction;
4311: if ($field eq 'screenshot') {
4312: $clickaction = ' onclick="screenshotSize(this);"';
4313: }
4314: if (ref($possoptions->{$field}) eq 'ARRAY') {
4315: foreach my $option (@{$possoptions->{$field}}) {
4316: my $checked;
4317: if ($currfield{$field} eq $option) {
4318: $checked = ' checked="checked"';
4319: }
4320: $datatable .= '<span class="LC_nobreak"><label>'.
4321: '<input type="radio" name="helpform_'.$field.'" '.
4322: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4323: '</label></span>'.(' 'x2);
4324: }
4325: }
4326: if ($field eq 'screenshot') {
4327: my $display;
4328: if ($currfield{$field} eq 'no') {
4329: $display = ' style="display:none"';
4330: }
4331: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4332: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4333: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4334: }
4335: $datatable .= '</td></tr>';
4336: }
4337: $datatable .= '</table>';
4338: }
4339: $datatable .= '</td></tr>'."\n";
4340: $rownum ++;
4341: }
1.160.6.107 raeburn 4342: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4343: foreach my $type (@mailings) {
4344: $css_class = $rownum%2?' class="LC_odd_row"':'';
4345: $datatable .= '<tr'.$css_class.'>'.
4346: '<td><span class="LC_nobreak">'.
4347: $titles->{$type}.': </span></td>'.
4348: '<td class="LC_left_item">';
4349: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4350: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4351: }
4352: $datatable .= '<span class="LC_nobreak">';
4353: foreach my $item (@contacts) {
4354: $datatable .= '<label>'.
4355: '<input type="checkbox" name="'.$type.'"'.
4356: $checked{$type}{$item}.
4357: ' value="'.$item.'" />'.$short_titles->{$item}.
4358: '</label> ';
4359: }
4360: $datatable .= '</span><br />'.&mt('Others').': '.
4361: '<input type="text" name="'.$type.'_others" '.
4362: 'value="'.$otheremails{$type}.'" />';
4363: my %locchecked;
4364: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4365: foreach my $loc ('s','b') {
4366: if ($includeloc{$type} eq $loc) {
4367: $locchecked{$loc} = ' checked="checked"';
4368: last;
4369: }
4370: }
4371: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4372: '<input type="text" name="'.$type.'_bcc" '.
4373: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4374: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4375: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4376: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4377: '<span class="LC_nobreak">'.&mt('Location:').' '.
4378: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4379: (' 'x2).
4380: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4381: '</span></fieldset>';
4382: }
4383: $datatable .= '</td></tr>'."\n";
4384: $rownum ++;
4385: }
1.28 raeburn 4386: }
1.160.6.78 raeburn 4387: if ($position eq 'middle') {
4388: my %choices;
1.160.6.107 raeburn 4389: my $corelink = &core_link_msu();
4390: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4391: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4392: $corelink);
4393: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4394: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4395: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4396: 'reportupdates' => 'on',
4397: 'reportstatus' => 'on');
1.160.6.78 raeburn 4398: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4399: \%choices,$rownum);
4400: $datatable .= $reports;
1.160.6.107 raeburn 4401: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4402: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4403: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4404: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4405: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4406: } else {
1.160.6.109 raeburn 4407: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4408: }
4409: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4410: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4411: } else {
1.160.6.109 raeburn 4412: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4413: }
4414: if (ref($lonstatus{'weights'}) eq 'HASH') {
4415: foreach my $type ('E','W','N','U') {
4416: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4417: $weights{$type} = $lonstatus{'weights'}{$type};
4418: } else {
4419: $weights{$type} = $defaults->{$type};
4420: }
4421: }
4422: } else {
4423: foreach my $type ('E','W','N','U') {
4424: $weights{$type} = $defaults->{$type};
4425: }
4426: }
4427: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4428: if (@{$lonstatus{'excluded'}} > 0) {
4429: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4430: }
4431: }
1.160.6.109 raeburn 4432: foreach my $item ('errorthreshold','errorsysmail') {
4433: $css_class = $rownum%2?' class="LC_odd_row"':'';
4434: $datatable .= '<tr'.$css_class.'>'.
4435: '<td class="LC_left_item"><span class="LC_nobreak">'.
4436: $titles->{$item}.
4437: '</span></td><td class="LC_left_item">'.
4438: '<input type="text" name="'.$item.'" value="'.
4439: $current{$item}.'" size="5" /></td></tr>';
4440: $rownum ++;
4441: }
1.160.6.107 raeburn 4442: $css_class = $rownum%2?' class="LC_odd_row"':'';
4443: $datatable .= '<tr'.$css_class.'>'.
4444: '<td class="LC_left_item">'.
4445: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4446: '</span></td><td class="LC_left_item"><table><tr>';
4447: foreach my $type ('E','W','N','U') {
4448: $datatable .= '<td>'.$names->{$type}.'<br />'.
4449: '<input type="text" name="errorweights_'.$type.'" value="'.
4450: $weights{$type}.'" size="5" /></td>';
4451: }
4452: $datatable .= '</tr></table></tr>';
4453: $rownum ++;
4454: $css_class = $rownum%2?' class="LC_odd_row"':'';
4455: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4456: $titles->{'errorexcluded'}.'</td>'.
4457: '<td class="LC_left_item"><table>';
4458: my $numinrow = 4;
4459: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4460: for (my $i=0; $i<@ids; $i++) {
4461: my $rem = $i%($numinrow);
4462: if ($rem == 0) {
4463: if ($i > 0) {
4464: $datatable .= '</tr>';
4465: }
4466: $datatable .= '<tr>';
4467: }
4468: my $check;
4469: if ($excluded{$ids[$i]}) {
4470: $check = ' checked="checked" ';
4471: }
4472: $datatable .= '<td class="LC_left_item">'.
4473: '<span class="LC_nobreak"><label>'.
4474: '<input type="checkbox" name="errorexcluded" '.
4475: 'value="'.$ids[$i].'"'.$check.' />'.
4476: $ids[$i].'</label></span></td>';
4477: }
4478: my $colsleft = $numinrow - @ids%($numinrow);
4479: if ($colsleft > 1 ) {
4480: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4481: ' </td>';
4482: } elsif ($colsleft == 1) {
4483: $datatable .= '<td class="LC_left_item"> </td>';
4484: }
4485: $datatable .= '</tr></table></td></tr>';
4486: $rownum ++;
1.160.6.78 raeburn 4487: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4488: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4489: my (@posstypes,%usertypeshash);
4490: if (ref($types) eq 'ARRAY') {
4491: @posstypes = @{$types};
4492: }
4493: if (@posstypes) {
4494: if (ref($usertypes) eq 'HASH') {
4495: %usertypeshash = %{$usertypes};
4496: }
4497: my @overridden;
4498: my $numinrow = 4;
4499: if (ref($settings) eq 'HASH') {
4500: if (ref($settings->{'overrides'}) eq 'HASH') {
4501: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4502: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4503: push(@overridden,$key);
4504: foreach my $item (@contacts) {
4505: if ($settings->{'overrides'}{$key}{$item}) {
4506: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4507: }
4508: }
4509: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4510: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4511: $includeloc{'override_'.$key} = '';
4512: $includestr{'override_'.$key} = '';
4513: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4514: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4515: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4516: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4517: }
1.160.6.78 raeburn 4518: }
4519: }
4520: }
1.160.6.101 raeburn 4521: }
4522: my $customclass = 'LC_helpdesk_override';
4523: my $optionsprefix = 'LC_options_helpdesk_';
4524:
4525: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4526: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4527: $numinrow,$othertitle,'overrides',
4528: \$rownum,$onclicktypes,$customclass);
4529: $rownum ++;
4530: $usertypeshash{'default'} = $othertitle;
4531: foreach my $status (@posstypes) {
4532: my $css_class;
4533: if ($rownum%2) {
4534: $css_class = 'LC_odd_row ';
4535: }
4536: $css_class .= $customclass;
4537: my $rowid = $optionsprefix.$status;
4538: my $hidden = 1;
4539: my $currstyle = 'display:none';
4540: if (grep(/^\Q$status\E$/,@overridden)) {
4541: $currstyle = 'display:table-row';
4542: $hidden = 0;
4543: }
4544: my $key = 'override_'.$status;
4545: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4546: $includeloc{$key},$includestr{$key},$status,$rowid,
4547: $usertypeshash{$status},$css_class,$currstyle,
4548: \@contacts,$short_titles);
4549: unless ($hidden) {
4550: $rownum ++;
1.160.6.78 raeburn 4551: }
4552: }
1.134 raeburn 4553: }
1.28 raeburn 4554: }
1.30 raeburn 4555: $$rowtotal += $rownum;
1.28 raeburn 4556: return $datatable;
4557: }
4558:
1.160.6.107 raeburn 4559: sub core_link_msu {
4560: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4561: &mt('LON-CAPA core group - MSU'),600,500);
4562: }
4563:
1.160.6.101 raeburn 4564: sub overridden_helpdesk {
4565: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4566: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4567: my $class = 'LC_left_item';
4568: if ($css_class) {
4569: $css_class = ' class="'.$css_class.'"';
4570: }
4571: if ($rowid) {
4572: $rowid = ' id="'.$rowid.'"';
4573: }
4574: if ($rowstyle) {
4575: $rowstyle = ' style="'.$rowstyle.'"';
4576: }
4577: my ($output,$description);
4578: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4579: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4580: "<td>$description</td>\n".
4581: '<td class="'.$class.'" colspan="2">'.
4582: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4583: '<span class="LC_nobreak">';
4584: if (ref($contacts) eq 'ARRAY') {
4585: foreach my $item (@{$contacts}) {
4586: my $check;
4587: if (ref($checked) eq 'HASH') {
4588: $check = $checked->{$item};
4589: }
4590: my $title;
4591: if (ref($short_titles) eq 'HASH') {
4592: $title = $short_titles->{$item};
4593: }
4594: $output .= '<label>'.
4595: '<input type="checkbox" name="override_'.$type.'"'.$check.
4596: ' value="'.$item.'" />'.$title.'</label> ';
4597: }
4598: }
4599: $output .= '</span><br />'.&mt('Others').': '.
4600: '<input type="text" name="override_'.$type.'_others" '.
4601: 'value="'.$otheremails.'" />';
4602: my %locchecked;
4603: foreach my $loc ('s','b') {
4604: if ($includeloc eq $loc) {
4605: $locchecked{$loc} = ' checked="checked"';
4606: last;
4607: }
4608: }
4609: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4610: '<input type="text" name="override_'.$type.'_bcc" '.
4611: 'value="'.$bccemails.'" /></fieldset>'.
4612: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4613: &mt('Text automatically added to e-mail:').' '.
4614: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4615: '<span class="LC_nobreak">'.&mt('Location:').' '.
4616: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4617: (' 'x2).
4618: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4619: '</span></fieldset>'.
4620: '</td></tr>'."\n";
4621: return $output;
4622: }
4623:
1.160.6.78 raeburn 4624: sub contacts_javascript {
4625: return <<"ENDSCRIPT";
4626:
4627: <script type="text/javascript">
4628: // <![CDATA[
4629:
4630: function screenshotSize(field) {
4631: if (document.getElementById('help_screenshotsize')) {
4632: if (field.value == 'no') {
4633: document.getElementById('help_screenshotsize').style.display="none";
4634: } else {
4635: document.getElementById('help_screenshotsize').style.display="";
4636: }
4637: }
4638: return;
4639: }
4640:
1.160.6.101 raeburn 4641: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4642: if (form.elements[checkbox].length != undefined) {
4643: var count = 0;
4644: if (docount) {
4645: for (var i=0; i<form.elements[checkbox].length; i++) {
4646: if (form.elements[checkbox][i].checked) {
4647: count ++;
4648: }
4649: }
4650: }
4651: for (var i=0; i<form.elements[checkbox].length; i++) {
4652: var type = form.elements[checkbox][i].value;
4653: if (document.getElementById(prefix+type)) {
4654: if (form.elements[checkbox][i].checked) {
4655: document.getElementById(prefix+type).style.display = 'table-row';
4656: if (count % 2 == 1) {
4657: document.getElementById(prefix+type).className = target+' LC_odd_row';
4658: } else {
4659: document.getElementById(prefix+type).className = target;
4660: }
4661: count ++;
4662: } else {
4663: document.getElementById(prefix+type).style.display = 'none';
4664: }
4665: }
4666: }
4667: }
4668: return;
4669: }
4670:
1.160.6.78 raeburn 4671: // ]]>
4672: </script>
4673:
4674: ENDSCRIPT
4675: }
4676:
1.118 jms 4677: sub print_helpsettings {
1.160.6.73 raeburn 4678: my ($position,$dom,$settings,$rowtotal) = @_;
4679: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4680: my $formname = 'display';
1.160.6.5 raeburn 4681: my ($datatable,$itemcount);
1.160.6.73 raeburn 4682: if ($position eq 'top') {
4683: $itemcount = 1;
4684: my (%choices,%defaultchecked,@toggles);
4685: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4686: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4687: &mt('LON-CAPA bug tracker'),600,500));
4688: %defaultchecked = ('submitbugs' => 'on');
4689: @toggles = ('submitbugs');
4690: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4691: \%choices,$itemcount);
4692: $$rowtotal ++;
4693: } else {
4694: my $css_class;
4695: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4696: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4697: if (ref($settings) eq 'HASH') {
4698: if (ref($settings->{'adhoc'}) eq 'HASH') {
4699: %current = %{$settings->{'adhoc'}};
4700: }
1.160.6.77 raeburn 4701: }
4702: my $count = 0;
4703: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4704: if ($key=~/^rolesdef\_(\w+)$/) {
4705: my $rolename = $1;
1.160.6.77 raeburn 4706: my (%privs,$order);
1.160.6.73 raeburn 4707: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4708: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4709: if (ref($current{$rolename}) eq 'HASH') {
4710: $order = $current{$rolename}{'order'};
4711: }
4712: if ($order eq '') {
4713: $order = $count;
4714: }
4715: $ordered{$order} = $rolename;
4716: $count++;
1.160.6.73 raeburn 4717: }
4718: }
1.160.6.77 raeburn 4719: my $maxnum = scalar(keys(%ordered));
4720: my @roles_by_num = ();
4721: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4722: push(@roles_by_num,$item);
4723: }
4724: my $context = 'domprefs';
4725: my $crstype = 'Course';
4726: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4727: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4728: my ($numstatustypes,@jsarray);
4729: if (ref($types) eq 'ARRAY') {
4730: if (@{$types} > 0) {
4731: $numstatustypes = scalar(@{$types});
4732: push(@accesstypes,'status');
4733: @jsarray = ('bystatus');
4734: }
4735: }
1.160.6.86 raeburn 4736: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4737: if (keys(%domhelpdesk)) {
4738: push(@accesstypes,('inc','exc'));
4739: push(@jsarray,('notinc','notexc'));
4740: }
4741: my $hiddenstr = join("','",@jsarray);
1.160.6.73 raeburn 4742: my $context = 'domprefs';
4743: my $crstype = 'Course';
1.160.6.77 raeburn 4744: my $prefix = 'helproles_';
4745: my $add_class = 'LC_hidden';
4746: foreach my $num (@roles_by_num) {
4747: my $role = $ordered{$num};
4748: my ($desc,$access,@statuses);
4749: if (ref($current{$role}) eq 'HASH') {
4750: $desc = $current{$role}{'desc'};
4751: $access = $current{$role}{'access'};
4752: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4753: @statuses = @{$current{$role}{'insttypes'}};
4754: }
4755: }
4756: if ($desc eq '') {
4757: $desc = $role;
4758: }
4759: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4760: my %full=();
4761: my %levels= (
4762: course => {},
4763: domain => {},
4764: system => {},
4765: );
4766: my %levelscurrent=(
4767: course => {},
4768: domain => {},
4769: system => {},
4770: );
4771: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4772: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4773: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4774: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4775: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4776: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4777: for (my $k=0; $k<=$maxnum; $k++) {
4778: my $vpos = $k+1;
4779: my $selstr;
4780: if ($k == $num) {
4781: $selstr = ' selected="selected" ';
4782: }
4783: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4784: }
4785: $datatable .= '</select>'.(' 'x2).
4786: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4787: '</td>'.
4788: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4789: &mt('Name shown to users:').
4790: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4791: '</fieldset>'.
4792: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4793: $othertitle,$usertypes,$types,\%domhelpdesk).
4794: '<fieldset>'.
4795: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4796: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4797: \%levelscurrent,$identifier,
4798: 'LC_hidden',$prefix.$num.'_privs').
4799: '</fieldset></td>';
1.160.6.73 raeburn 4800: $itemcount ++;
4801: }
4802: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4803: my $newcust = 'custhelp'.$count;
4804: my (%privs,%levelscurrent);
4805: my %full=();
4806: my %levels= (
4807: course => {},
4808: domain => {},
4809: system => {},
4810: );
4811: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4812: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4813: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4814: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4815: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4816: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4817: for (my $k=0; $k<$maxnum+1; $k++) {
4818: my $vpos = $k+1;
4819: my $selstr;
4820: if ($k == $maxnum) {
4821: $selstr = ' selected="selected" ';
4822: }
4823: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4824: }
4825: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4826: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4827: '</label></span></td>'.
1.160.6.77 raeburn 4828: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4829: '<span class="LC_nobreak">'.
4830: &mt('Internal name:').
4831: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4832: '</span>'.(' 'x4).
4833: '<span class="LC_nobreak">'.
4834: &mt('Name shown to users:').
4835: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4836: '</span></fieldset>'.
4837: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4838: $usertypes,$types,\%domhelpdesk).
4839: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4840: &Apache::lonuserutils::custom_role_header($context,$crstype,
4841: \@templateroles,$newcust).
4842: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4843: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4844: '</fieldset>'.
4845: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4846: '</td></tr>';
1.160.6.73 raeburn 4847: $count ++;
4848: $$rowtotal += $count;
4849: }
1.160.6.5 raeburn 4850: return $datatable;
1.121 raeburn 4851: }
4852:
1.160.6.77 raeburn 4853: sub adhocbutton {
4854: my ($prefix,$num,$field,$visibility) = @_;
4855: my %lt = &Apache::lonlocal::texthash(
4856: show => 'Show details',
4857: hide => 'Hide details',
4858: );
4859: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4860: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4861: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4862: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4863: }
4864:
4865: sub helpsettings_javascript {
4866: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4867: return unless(ref($roles_by_num) eq 'ARRAY');
4868: my %html_js_lt = &Apache::lonlocal::texthash(
4869: show => 'Show details',
4870: hide => 'Hide details',
4871: );
4872: &html_escape(\%html_js_lt);
4873: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4874: return <<"ENDSCRIPT";
4875: <script type="text/javascript">
4876: // <![CDATA[
4877:
4878: function reorderHelpRoles(form,item) {
4879: var changedVal;
4880: $jstext
4881: var newpos = 'helproles_${total}_pos';
4882: var maxh = 1 + $total;
4883: var current = new Array();
4884: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4885: if (item == newpos) {
4886: changedVal = newitemVal;
4887: } else {
4888: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4889: current[newitemVal] = newpos;
4890: }
4891: for (var i=0; i<helproles.length; i++) {
4892: var elementName = 'helproles_'+helproles[i]+'_pos';
4893: if (elementName != item) {
4894: if (form.elements[elementName]) {
4895: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4896: current[currVal] = elementName;
4897: }
4898: }
4899: }
4900: var oldVal;
4901: for (var j=0; j<maxh; j++) {
4902: if (current[j] == undefined) {
4903: oldVal = j;
4904: }
4905: }
4906: if (oldVal < changedVal) {
4907: for (var k=oldVal+1; k<=changedVal ; k++) {
4908: var elementName = current[k];
4909: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4910: }
4911: } else {
4912: for (var k=changedVal; k<oldVal; k++) {
4913: var elementName = current[k];
4914: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4915: }
4916: }
4917: return;
4918: }
4919:
4920: function helpdeskAccess(num) {
4921: var curraccess = null;
4922: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4923: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4924: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4925: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4926: }
4927: }
4928: }
4929: var shown = Array();
4930: var hidden = Array();
4931: if (curraccess == 'none') {
4932: hidden = Array('$hiddenstr');
4933: } else {
4934: if (curraccess == 'status') {
4935: shown = Array('bystatus');
4936: hidden = Array('notinc','notexc');
4937: } else {
4938: if (curraccess == 'exc') {
4939: shown = Array('notexc');
4940: hidden = Array('notinc','bystatus');
4941: }
4942: if (curraccess == 'inc') {
4943: shown = Array('notinc');
4944: hidden = Array('notexc','bystatus');
4945: }
1.160.6.79 raeburn 4946: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4947: hidden = Array('notinc','notexc','bystatus');
4948: }
4949: }
4950: }
4951: if (hidden.length > 0) {
4952: for (var i=0; i<hidden.length; i++) {
4953: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4954: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4955: }
4956: }
4957: }
4958: if (shown.length > 0) {
4959: for (var i=0; i<shown.length; i++) {
4960: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4961: if (shown[i] == 'privs') {
4962: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4963: } else {
4964: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4965: }
4966: }
4967: }
4968: }
4969: return;
4970: }
4971:
4972: function toggleHelpdeskItem(num,field) {
4973: if (document.getElementById('helproles_'+num+'_'+field)) {
4974: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4975: document.getElementById('helproles_'+num+'_'+field).className =
4976: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4977: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4978: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4979: }
4980: } else {
4981: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4982: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4983: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4984: }
4985: }
4986: }
4987: return;
4988: }
4989:
4990: // ]]>
4991: </script>
4992:
4993: ENDSCRIPT
4994: }
4995:
4996: sub helpdeskroles_access {
4997: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4998: $usertypes,$types,$domhelpdesk) = @_;
4999: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5000: my %lt = &Apache::lonlocal::texthash(
5001: 'rou' => 'Role usage',
5002: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 5003: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5004: 'dh' => 'All with domain helpdesk role',
5005: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 5006: 'none' => 'None',
5007: 'status' => 'Determined based on institutional status',
5008: 'inc' => 'Include all, but exclude specific personnel',
5009: 'exc' => 'Exclude all, but include specific personnel',
5010: );
5011: my %usecheck = (
5012: all => ' checked="checked"',
5013: );
5014: my %displaydiv = (
5015: status => 'none',
5016: inc => 'none',
5017: exc => 'none',
5018: priv => 'block',
5019: );
5020: my $output;
5021: if (ref($current) eq 'HASH') {
5022: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5023: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5024: $usecheck{$current->{access}} = $usecheck{'all'};
5025: delete($usecheck{'all'});
5026: if ($current->{access} =~ /^(status|inc|exc)$/) {
5027: my $access = $1;
5028: $displaydiv{$access} = 'inline';
5029: } elsif ($current->{access} eq 'none') {
5030: $displaydiv{'priv'} = 'none';
5031: }
5032: }
5033: }
5034: }
5035: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5036: '<p>'.$lt{'whi'}.'</p>';
5037: foreach my $access (@{$accesstypes}) {
5038: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5039: ' onclick="helpdeskAccess('."'$num'".');" />'.
5040: $lt{$access}.'</label>';
5041: if ($access eq 'status') {
5042: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5043: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5044: $othertitle,$usertypes,$types).
5045: '</div>';
5046: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5047: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5048: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5049: '</div>';
5050: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5051: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5052: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5053: '</div>';
5054: }
5055: $output .= '</p>';
5056: }
5057: $output .= '</fieldset>';
5058: return $output;
5059: }
5060:
1.121 raeburn 5061: sub radiobutton_prefs {
1.160.6.16 raeburn 5062: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 5063: $additional,$align,$firstval) = @_;
1.121 raeburn 5064: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5065: (ref($choices) eq 'HASH'));
5066:
5067: my (%checkedon,%checkedoff,$datatable,$css_class);
5068:
5069: foreach my $item (@{$toggles}) {
5070: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5071: $checkedon{$item} = ' checked="checked" ';
5072: $checkedoff{$item} = ' ';
1.121 raeburn 5073: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5074: $checkedoff{$item} = ' checked="checked" ';
5075: $checkedon{$item} = ' ';
5076: }
5077: }
5078: if (ref($settings) eq 'HASH') {
1.121 raeburn 5079: foreach my $item (@{$toggles}) {
1.118 jms 5080: if ($settings->{$item} eq '1') {
5081: $checkedon{$item} = ' checked="checked" ';
5082: $checkedoff{$item} = ' ';
5083: } elsif ($settings->{$item} eq '0') {
5084: $checkedoff{$item} = ' checked="checked" ';
5085: $checkedon{$item} = ' ';
5086: }
5087: }
1.121 raeburn 5088: }
1.160.6.16 raeburn 5089: if ($onclick) {
5090: $onclick = ' onclick="'.$onclick.'"';
5091: }
1.121 raeburn 5092: foreach my $item (@{$toggles}) {
1.118 jms 5093: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5094: $datatable .=
1.160.6.16 raeburn 5095: '<tr'.$css_class.'><td valign="top">'.
5096: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 5097: '</span></td>';
5098: if ($align eq 'left') {
5099: $datatable .= '<td class="LC_left_item">';
5100: } else {
5101: $datatable .= '<td class="LC_right_item">';
5102: }
1.160.6.113 raeburn 5103: $datatable .= '<span class="LC_nobreak">';
5104: if ($firstval eq 'no') {
5105: $datatable .=
5106: '<label><input type="radio" name="'.
5107: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5108: '</label> <label><input type="radio" name="'.$item.'" '.
5109: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5110: } else {
5111: $datatable .=
1.160.6.118.2 14(raebu 5112:23): '<label><input type="radio" name="'.
5113:23): $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5114:23): '</label> <label><input type="radio" name="'.$item.'" '.
5115:23): $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
1.160.6.113 raeburn 5116: }
5117: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5118: $itemcount ++;
1.121 raeburn 5119: }
5120: return ($datatable,$itemcount);
5121: }
5122:
1.160.6.118.2 1(raebur 5123:1): sub print_ltitools {
14(raebu 5124:23): my ($position,$dom,$settings,$rowtotal) = @_;
5125:23): my (%rules,%encrypt,%privkeys,%linkprot);
1(raebur 5126:1): if (ref($settings) eq 'HASH') {
14(raebu 5127:23): if ($position eq 'top') {
5128:23): if (exists($settings->{'encrypt'})) {
5129:23): if (ref($settings->{'encrypt'}) eq 'HASH') {
5130:23): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5131:23): $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1(raebur 5132:1): }
5133:1): }
5134:1): }
14(raebu 5135:23): if (exists($settings->{'private'})) {
5136:23): if (ref($settings->{'private'}) eq 'HASH') {
5137:23): if (ref($settings->{'private'}) eq 'HASH') {
5138:23): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5139:23): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1(raebur 5140:1): }
5141:1): }
5142:1): }
5143:1): }
14(raebu 5144:23): } elsif ($position eq 'middle') {
5145:23): if (exists($settings->{'rules'})) {
5146:23): if (ref($settings->{'rules'}) eq 'HASH') {
5147:23): %rules = %{$settings->{'rules'}};
1(raebur 5148:1): }
5149:1): }
14(raebu 5150:23): } else {
5151:23): foreach my $key ('encrypt','private','rules') {
5152:23): if (exists($settings->{$key})) {
5153:23): delete($settings->{$key});
1(raebur 5154:1): }
5155:1): }
5156:1): }
5157:1): }
14(raebu 5158:23): my $datatable;
5159:23): my $itemcount = 1;
5160:23): if ($position eq 'top') {
5161:23): $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5162:23): } elsif ($position eq 'middle') {
5163:23): $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5164:23): $$rowtotal += $itemcount;
5165:23): } else {
5166:23): $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1(raebur 5167:1): }
5168:1): return $datatable;
5169:1): }
5170:1):
5171:1): sub ltitools_names {
5172:1): my %lt = &Apache::lonlocal::texthash(
5173:1): 'title' => 'Title',
5174:1): 'version' => 'Version',
5175:1): 'msgtype' => 'Message Type',
5176:1): 'sigmethod' => 'Signature Method',
5177:1): 'url' => 'URL',
5178:1): 'key' => 'Key',
5179:1): 'lifetime' => 'Nonce lifetime (s)',
5180:1): 'secret' => 'Secret',
5181:1): 'icon' => 'Icon',
5182:1): 'user' => 'User',
5183:1): 'fullname' => 'Full Name',
5184:1): 'firstname' => 'First Name',
5185:1): 'lastname' => 'Last Name',
5186:1): 'email' => 'E-mail',
5187:1): 'roles' => 'Role',
5188:1): 'window' => 'Window',
5189:1): 'tab' => 'Tab',
5190:1): 'iframe' => 'iFrame',
5191:1): 'height' => 'Height',
5192:1): 'width' => 'Width',
5193:1): 'linktext' => 'Default Link Text',
5194:1): 'explanation' => 'Default Explanation',
14(raebu 5195:23): 'passback' => 'Tool can return grades:',
5196:23): 'roster' => 'Tool can retrieve roster:',
1(raebur 5197:1): 'crstarget' => 'Display target',
5198:1): 'crslabel' => 'Course label',
5199:1): 'crstitle' => 'Course title',
5200:1): 'crslinktext' => 'Link Text',
5201:1): 'crsexplanation' => 'Explanation',
5202:1): 'crsappend' => 'Provider URL',
5203:1): );
5204:1): return %lt;
5205:1): }
5206:1):
14(raebu 5207:23): sub secrets_form {
5208:23): my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5209:23): my @ids=&Apache::lonnet::current_machine_ids();
5210:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
5211:23): my $primary = &Apache::lonnet::domain($dom,'primary');
5212:23): my ($css_class,$extra,$numshown,$itemcount,$output);
5213:23): $itemcount = 0;
5214:23): foreach my $hostid (sort(keys(%servers))) {
5215:23): my ($showextra,$divsty,$switch);
5216:23): if ($hostid eq $primary) {
5217:23): if ($context eq 'ltisec') {
5218:23): if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5219:23): $showextra = 1;
5220:23): }
5221:23): if ($encrypt->{'ltisec_crslinkprot'}) {
5222:23): $showextra = 1;
5223:23): }
5224:23): } else {
5225:23): if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5226:23): $showextra = 1;
5227:23): }
5228:23): }
5229:23): unless (grep(/^\Q$hostid\E$/,@ids)) {
5230:23): $switch = 1;
5231:23): }
5232:23): if ($showextra) {
5233:23): $numshown ++;
5234:23): $divsty = 'display:inline-block';
5235:23): } else {
5236:23): $divsty = 'display:none';
5237:23): }
5238:23): $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5239:23): '<legend>'.$hostid.'</legend>';
5240:23): if ($switch) {
5241:23): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5242:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5243:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5244:23): if (exists($privkeys->{$hostid})) {
5245:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5246:23): '<span class="LC_nobreak">'.
5247:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5248:23): '<span class="LC_nobreak">'.&mt('Change?').
5249:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5250:23): (' 'x2).
5251:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5252:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5253:23): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5254:23): '</span></div>';
5255:23): } else {
5256:23): $extra .= '<span class="LC_nobreak">'.
5257:23): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5258:23): '</span>'."\n";
5259:23): }
5260:23): } elsif (exists($privkeys->{$hostid})) {
5261:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5262:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5263:23): '<span class="LC_nobreak">'.&mt('Change?').
5264:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5265:23): (' 'x2).
5266:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5267:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5268:23): '<span class="LC_nobreak">'.&mt('New Key').':'.
5269:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5270: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>'.
5271:23): '</span></div>';
5272:23): } else {
5273:23): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5274:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5275: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>';
5276:23): }
5277:23): $extra .= '</fieldset>';
5278:23): }
5279:23): }
5280:23): my (%choices,@toggles,%defaultchecked);
5281:23): if ($context eq 'ltisec') {
5282:23): %choices = &Apache::lonlocal::texthash (
5283:23): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5284:23): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5285:23): ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5286:23): );
5287:23): @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5288:23): %defaultchecked = (
5289:23): 'ltisec_crslinkprot' => 'off',
5290:23): 'ltisec_domlinkprot' => 'off',
5291:23): 'ltisec_consumers' => 'off',
5292:23): );
5293:23): } else {
5294:23): %choices = &Apache::lonlocal::texthash (
5295:23): toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5296:23): toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5297:23): );
5298:23): @toggles = qw(toolsec_crs toolsec_dom);
5299:23): %defaultchecked = (
5300:23): 'toolsec_crs' => 'off',
5301:23): 'toolsec_dom' => 'off',
5302:23): );
5303:23): }
5304:23): my ($onclick,$itemcount);
5305:23): $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5306:23): ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5307:23): \%choices,$itemcount,$onclick,'','left','no');
5308:23):
5309:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5310:23): my $noprivkeysty = 'display:inline-block';
5311:23): if ($numshown) {
5312:23): $noprivkeysty = 'display:none';
5313:23): }
5314:23): $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5315:23): '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5316:23): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5317:23): $extra.
5318:23): '</td></tr>';
5319:23): $itemcount ++;
5320:23): $$rowtotal += $itemcount;
5321:23): return $output;
5322:23): }
5323:23):
5(raebur 5324:2): sub print_lti {
5325:2): my ($position,$dom,$settings,$rowtotal) = @_;
5326:2): my $itemcount = 1;
5327:2): my ($datatable,$css_class);
18(raebu 5328:24): my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
5(raebur 5329:2): if (ref($settings) eq 'HASH') {
5330:2): if ($position eq 'top') {
5331:2): if (exists($settings->{'encrypt'})) {
5332:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5333:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
14(raebu 5334:23): if ($key eq 'consumers') {
5335:23): $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5336:23): } else {
5337:23): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5338:23): }
5(raebur 5339:2): }
5340:2): }
5341:2): }
5342:2): if (exists($settings->{'private'})) {
5343:2): if (ref($settings->{'private'}) eq 'HASH') {
5344:2): if (ref($settings->{'private'}) eq 'HASH') {
5345:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5346:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5347:2): }
5348:2): }
5349:2): }
5350:2): }
18(raebu 5351:24): } elsif ($position eq 'upper') {
5(raebur 5352:2): if (exists($settings->{'rules'})) {
5353:2): if (ref($settings->{'rules'}) eq 'HASH') {
5354:2): %rules = %{$settings->{'rules'}};
5355:2): }
5356:2): }
18(raebu 5357:24): } elsif ($position eq 'middle') {
5358:24): if (exists($settings->{'suggested'})) {
5359:24): if (ref($settings->{'suggested'}) eq 'HASH') {
5360:24): %suggestions = %{$settings->{'suggested'}};
5361:24): }
5362:24): }
14(raebu 5363:23): } elsif ($position eq 'lower') {
5(raebur 5364:2): if (exists($settings->{'linkprot'})) {
5365:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5366:2): %linkprot = %{$settings->{'linkprot'}};
5367:2): if ($linkprot{'lock'}) {
5368:2): delete($linkprot{'lock'});
5369:2): }
5370:2): }
5371:2): }
14(raebu 5372:23): } else {
18(raebu 5373:24): foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
14(raebu 5374:23): if (exists($settings->{$key})) {
5375:23): delete($settings->{$key});
5376:23): }
5377:23): }
5(raebur 5378:2): }
5379:2): }
5380:2): if ($position eq 'top') {
14(raebu 5381:23): $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
18(raebu 5382:24): } elsif ($position eq 'upper') {
14(raebu 5383:23): $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5384:23): $$rowtotal += $itemcount;
18(raebu 5385:24): } elsif ($position eq 'middle') {
5386:24): $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
5387:24): $$rowtotal += $itemcount;
14(raebu 5388:23): } elsif ($position eq 'lower') {
18(raebu 5389:24): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
14(raebu 5390:23): } else {
5391:23): my ($switchserver,$switchmessage);
5392:23): $switchserver = &check_switchserver($dom);
5393:23): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5394:23): my $maxnum = 0;
5395:23): my %ordered;
5396:23): if (ref($settings) eq 'HASH') {
5397:23): foreach my $item (keys(%{$settings})) {
5398:23): if (ref($settings->{$item}) eq 'HASH') {
5399:23): my $num = $settings->{$item}{'order'};
5400:23): if ($num eq '') {
5401:23): $num = scalar(keys(%{$settings}));
5402:23): }
5403:23): $ordered{$num} = $item;
5(raebur 5404:2): }
5405:2): }
14(raebu 5406:23): }
5407:23): $maxnum = scalar(keys(%ordered));
5408:23): my %lt = <i_names();
5409:23): if (keys(%ordered)) {
5410:23): my @items = sort { $a <=> $b } keys(%ordered);
5411:23): for (my $i=0; $i<@items; $i++) {
5412:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5413:23): my $item = $ordered{$items[$i]};
5414:23): my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5415:23): if (ref($settings->{$item}) eq 'HASH') {
5416:23): $key = $settings->{$item}->{'key'};
5417:23): $usable = $settings->{$item}->{'usable'};
5418:23): $lifetime = $settings->{$item}->{'lifetime'};
5419:23): $consumer = $settings->{$item}->{'consumer'};
5420:23): $requser = $settings->{$item}->{'requser'};
5421:23): $crsinc = $settings->{$item}->{'crsinc'};
5422:23): $current = $settings->{$item};
5423:23): }
5424:23): my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5425:23): my %checkedrequser = (
5426:23): yes => ' checked="checked"',
5427:23): no => '',
5428:23): );
5429:23): if (!$requser) {
5430:23): $checkedrequser{'no'} = $checkedrequser{'yes'};
5431:23): $checkedrequser{'yes'} = '';
5432:23): }
5433:23): my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5434:23): my %checkedcrsinc = (
5435:23): yes => ' checked="checked"',
5436:23): no => '',
5437:23): );
5438:23): if (!$crsinc) {
5439:23): $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5440:23): $checkedcrsinc{'yes'} = '';
5441:23): }
5442:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5443:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5444:23): .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5445:23): for (my $k=0; $k<=$maxnum; $k++) {
5446:23): my $vpos = $k+1;
5447:23): my $selstr;
5448:23): if ($k == $i) {
5449:23): $selstr = ' selected="selected" ';
5450:23): }
5451:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5452:23): }
5453:23): $datatable .= '</select>'.(' 'x2).
5454:23): '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5455:23): &mt('Delete?').'</label></span></td>'.
5456:23): '<td colspan="2">'.
5457:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5458:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5459:23): ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5460:23): (' 'x2).
5461:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5462:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5463:23): (' 'x2).
5464:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5465:23): 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5466:23): if ($key ne '') {
5467:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5468:23): if ($switchserver) {
5469:23): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5470:23): } else {
5471:23): $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5472:23): }
5473:23): $datatable .= '</span> '.(' 'x2);
5474:23): } elsif (!$switchserver) {
5475:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5476:23): '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5477:23): '</span> '.(' 'x2);
5478:23): }
5479:23): if ($switchserver) {
5480:23): if ($usable ne '') {
5481:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5482:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5483:23): '<span class="LC_nobreak">'.&mt('Change secret?').
5484:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5485:23): (' 'x2).
5486:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5487:23): '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5488:23): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5489:23): '</div>';
5490:23): } elsif ($key eq '') {
5491:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5492:23): } else {
5493:23): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5494:23): }
5495:23): } else {
5496:23): if ($usable ne '') {
5497:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5498:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5499:23): '<span class="LC_nobreak">'.&mt('Change?').
5500:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5501:23): (' 'x2).
5502:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5503:23): '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5504:23): '<span class="LC_nobreak">'.&mt('New Secret').':'.
5505:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5506: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>';
5507:23): } else {
5508:23): $datatable .=
5509:23): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5510:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5511: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>';
5512:23): }
5513:23): }
5514:23): $datatable .= '<br /><br />'.
5515:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5516:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5517:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5518:23): '<br /><br />'.
5519:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5520:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5521:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5522:23): (' 'x4).
5523:23): '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5524:23): '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5525:23): $itemcount ++;
5(raebur 5526:2): }
14(raebu 5527:23): }
5528:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5529:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5530:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5531:23): '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5532:23): '<select name="lti_pos_add"'.$chgstr.'>';
5533:23): for (my $k=0; $k<$maxnum+1; $k++) {
5534:23): my $vpos = $k+1;
5535:23): my $selstr;
5536:23): if ($k == $maxnum) {
5537:23): $selstr = ' selected="selected" ';
5(raebur 5538:2): }
14(raebu 5539:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5540:23): }
5541:23): $datatable .= '</select> '."\n".
5542:23): '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5543:23): '<td colspan="2">'.
5544:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5545:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5546:23): ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5547:23): (' 'x2).
5548:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5549:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5550:23): (' 'x2).
5551:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5552:23): if ($switchserver) {
5553:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5554:23): } else {
5555:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5556:23): (' 'x2).
5557:23): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5558: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";
5559:23): }
5560:23): $datatable .= '<br /><br />'.
5561:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5562:23): '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5563:23): '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5564:23): '<br /><br />'.
5565:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5566:23): '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5567:23): '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5568:23): '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5569:23): '</td>'."\n".
5570:23): '</tr>'."\n";
5571:23): $itemcount ++;
5572:23): }
5573:23): $$rowtotal += $itemcount;
5574:23): return $datatable;
5575:23): }
5576:23):
5577:23): sub lti_names {
5578:23): my %lt = &Apache::lonlocal::texthash(
5579:23): 'version' => 'LTI Version',
5580:23): 'url' => 'URL',
5581:23): 'key' => 'Key',
5582:23): 'lifetime' => 'Nonce lifetime (s)',
5583:23): 'consumer' => 'Consumer',
5584:23): 'secret' => 'Secret',
5585:23): 'requser' => "User's identity sent",
5586:23): 'crsinc' => "Course's identity sent",
5587:23): 'email' => 'Email address',
5588:23): 'sourcedid' => 'User ID',
5589:23): 'other' => 'Other',
5590:23): 'passback' => 'Can return grades to Consumer:',
5591:23): 'roster' => 'Can retrieve roster from Consumer:',
5592:23): 'topmenu' => 'Display LON-CAPA page header',
5593:23): 'inlinemenu'=> 'Display LON-CAPA inline menu',
5594:23): );
5595:23): return %lt;
5596:23): }
5597:23):
5598:23): sub lti_options {
5599:23): my ($num,$current,$itemcount,%lt) = @_;
5600:23): my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5601:23): $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5602:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5603:23): $checked{'storecrs'}{'Y'} = ' checked="checked"';
5604:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5605:23): $checked{'mapcrstype'} = {};
5606:23): $checked{'makeuser'} = {};
5607:23): $checked{'selfenroll'} = {};
5608:23): $checked{'crssec'} = {};
5609:23): $checked{'crssecsrc'} = {};
5610:23): $checked{'lcauth'} = {};
5611:23): $checked{'menuitem'} = {};
5612:23): if ($num eq 'add') {
5613:23): $checked{'lcauth'}{'lti'} = ' checked="checked"';
5614:23): }
5615:23): my $userfieldsty = 'none';
5616:23): my $crsfieldsty = 'none';
5617:23): my $crssecfieldsty = 'none';
5618:23): my $secsrcfieldsty = 'none';
5619:23): my $callbacksty = 'none';
5620:23): my $passbacksty = 'none';
5621:23): my $optionsty = 'block';
5622:23): my $crssty = 'block';
5623:23): my $lcauthparm;
5624:23): my $lcauthparmstyle = 'display:none';
5625:23): my $lcauthparmtext;
5626:23): my $menusty;
5627:23): my $numinrow = 4;
5628:23): my %menutitles = <imenu_titles();
5629:23):
5630:23): if (ref($current) eq 'HASH') {
5631:23): if (!$current->{'requser'}) {
5632:23): $optionsty = 'none';
5633:23): $crssty = 'none';
5634:23): } elsif (!$current->{'crsinc'}) {
5635:23): $crssty = 'none';
5636:23): }
5637:23): if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5638:23): $checked{'mapuser'}{'sourcedid'} = '';
5639:23): if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5640:23): $checked{'mapuser'}{'email'} = ' checked="checked"';
5(raebur 5641:2): } else {
14(raebu 5642:23): $checked{'mapuser'}{'other'} = ' checked="checked"';
5643:23): $userfield = $current->{'mapuser'};
5644:23): $userfieldsty = 'inline-block';
5(raebur 5645:2): }
14(raebu 5646:23): }
5647:23): if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5648:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5649:23): if ($current->{'mapcrs'} eq 'context_id') {
5650:23): $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5651:23): } else {
5652:23): $checked{'mapcrs'}{'other'} = ' checked="checked"';
5653:23): $cidfield = $current->{'mapcrs'};
5654:23): $crsfieldsty = 'inline-block';
5655:23): }
5656:23): }
5657:23): if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5658:23): foreach my $type (@{$current->{'mapcrstype'}}) {
5659:23): $checked{'mapcrstype'}{$type} = ' checked="checked"';
5660:23): }
5661:23): }
5662:23): if (!$current->{'storecrs'}) {
5663:23): $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5664:23): $checked{'storecrs'}{'Y'} = '';
5665:23): }
5666:23): if ($current->{'makecrs'}) {
5667:23): $checked{'makecrs'}{'Y'} = ' checked="checked"';
5668:23): }
5669:23): if (ref($current->{'makeuser'}) eq 'ARRAY') {
5670:23): foreach my $role (@{$current->{'makeuser'}}) {
5671:23): $checked{'makeuser'}{$role} = ' checked="checked"';
5672:23): }
5673:23): }
5674:23): if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5675:23): $checked{'lcauth'}{$1} = ' checked="checked"';
5676:23): unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5677:23): $lcauthparm = $current->{'lcauthparm'};
5678:23): $lcauthparmstyle = 'display:table-row';
5679:23): if ($current->{'lcauth'} eq 'localauth') {
5680:23): $lcauthparmtext = &mt('Local auth argument');
5(raebur 5681:2): } else {
14(raebu 5682:23): $lcauthparmtext = &mt('Kerberos domain');
5(raebur 5683:2): }
14(raebu 5684:23): }
5685:23): }
5686:23): if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5687:23): foreach my $role (@{$current->{'selfenroll'}}) {
5688:23): $checked{'selfenroll'}{$role} = ' checked="checked"';
5689:23): }
5690:23): }
5691:23): if (ref($current->{'maproles'}) eq 'HASH') {
5692:23): %rolemaps = %{$current->{'maproles'}};
5693:23): }
5694:23): if ($current->{'section'} ne '') {
5695:23): $checked{'crssec'}{'Y'} = ' checked="checked"';
5696:23): $crssecfieldsty = 'inline-block';
5697:23): if ($current->{'section'} eq 'course_section_sourcedid') {
5698:23): $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5(raebur 5699:2): } else {
14(raebu 5700:23): $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5701:23): $crssecsrc = $current->{'section'};
5702:23): $secsrcfieldsty = 'inline-block';
5(raebur 5703:2): }
14(raebu 5704:23): } else {
5705:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5(raebur 5706:2): }
14(raebu 5707:23): if ($current->{'callback'} ne '') {
5708:23): $callback = $current->{'callback'};
5709:23): $checked{'callback'}{'Y'} = ' checked="checked"';
5710:23): $callbacksty = 'inline-block';
5711:23): } else {
5712:23): $checked{'callback'}{'N'} = ' checked="checked"';
5713:23): }
5714:23): if ($current->{'topmenu'}) {
5715:23): $checked{'topmenu'}{'Y'} = ' checked="checked"';
5716:23): } else {
5717:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5718:23): }
5719:23): if ($current->{'inlinemenu'}) {
5720:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5721:23): } else {
5722:23): $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5723:23): }
5724:23): if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5725:23): $menusty = 'inline-block';
5726:23): if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5727:23): foreach my $item (@{$current->{'lcmenu'}}) {
5728:23): if (exists($menutitles{$item})) {
5729:23): $checked{'menuitem'}{$item} = ' checked="checked"';
5730:23): }
5731:23): }
5732:23): }
5733:23): } else {
5734:23): $menusty = 'none';
5735:23): }
5736:23): } else {
5737:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5738:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5739:23): $checked{'callback'}{'N'} = ' checked="checked"';
5740:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5741:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5742:23): $checked{'menuitem'}{'grades'} = ' checked="checked"';
5743:23): $menusty = 'inline-block';
5(raebur 5744:2): }
14(raebu 5745:23): my @coursetypes = ('official','unofficial','community','textbook','lti');
5746:23): my %coursetypetitles = &Apache::lonlocal::texthash (
5747:23): official => 'Official',
5748:23): unofficial => 'Unofficial',
5749:23): community => 'Community',
5750:23): textbook => 'Textbook',
5751:23): lti => 'LTI Provider',
5752:23): );
5753:23): my @authtypes = ('internal','krb4','krb5','localauth');
5754:23): my %shortauth = (
5755:23): internal => 'int',
5756:23): krb4 => 'krb4',
5757:23): krb5 => 'krb5',
5758:23): localauth => 'loc'
5759:23): );
5760:23): my %authnames = &authtype_names();
5761:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5762:23): my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5763:23): my @courseroles = ('cc','in','ta','ep','st');
5764:23): my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5765:23): my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5766:23): my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5767:23): my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5768:23): my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5769:23): my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5770:23): my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5771:23): my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5772:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5773:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5774:23): $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5775:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5776:23): $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5777:23): '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5778:23): '<span class="LC_nobreak">'.&mt('Parameter').': '.
5779:23): '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5780:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5781:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5782:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5783:23): foreach my $option ('sourcedid','email','other') {
5784:23): $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5785:23): $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5786:23): ($option eq 'other' ? '' : (' 'x2) );
5787:23): }
5788:23): $output .= '</span></div>'.
5789:23): '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5790:23): '<input type="text" name="lti_customuser_'.$num.'" '.
5791:23): 'value="'.$userfield.'" /></div></fieldset>'.
5792:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5793:23): foreach my $ltirole (@ltiroles) {
5794:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5795:23): $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5796:23): }
5797:23): $output .= '</fieldset>'.
5798:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5799:23): '<table>'.
5800:23): &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5801:23): '</table>'.
5802:23): '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5803:23): '<td class="LC_left_item">';
5804:23): foreach my $auth ('lti',@authtypes) {
5805:23): my $authtext;
5806:23): if ($auth eq 'lti') {
5807:23): $authtext = &mt('None');
5808:23): } else {
5809:23): $authtext = $authnames{$shortauth{$auth}};
5810:23): }
5811:23): $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5812:23): '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5813:23): $authtext.'</label></span> ';
5814:23): }
5815:23): $output .= '</td></tr>'.
5816:23): '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5817:23): '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5818:23): '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5819:23): '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5820:23): '</table></fieldset>'.
5821:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5822:23): &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5823:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5824:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5825:23): $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5826:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5827:23): $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5828:23): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5829:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5830:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5831:23): $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5832:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5833:23): $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5834:23): $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5835:23): '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5836:23): '<span class="LC_nobreak">'.&mt('Menu items').': ';
5837:23): foreach my $type ('fullname','coursetitle','role','logout','grades') {
5838:23): $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5839:23): $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5840:23): (' 'x2);
5841:23): }
5842:23): $output .= '</span></div></fieldset>'.
5843:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5844:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.
5845:23): &mt('Unique course identifier').': ';
5846:23): foreach my $option ('course_offering_sourcedid','context_id','other') {
5847:23): $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5848:23): $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5849:23): ($option eq 'other' ? '' : (' 'x2) );
5850:23): }
5851:23): $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5852:23): '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5853:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5854:23): '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5855:23): foreach my $type (@coursetypes) {
5856:23): $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5857:23): $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5858:23): (' 'x2);
5859:23): }
5860:23): $output .= '</span><br /><br />'.
5861:23): '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5862:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5863:23): $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5864:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5865:23): $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5866:23): '</fieldset>'.
5867:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5868:23): foreach my $ltirole (@lticourseroles) {
5869:23): my ($selected,$selectnone);
5870:23): if ($rolemaps{$ltirole} eq '') {
5871:23): $selectnone = ' selected="selected"';
5872:23): }
5873:23): $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5874:23): '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5875:23): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5876:23): foreach my $role (@courseroles) {
5877:23): unless ($selectnone) {
5878:23): if ($rolemaps{$ltirole} eq $role) {
5879:23): $selected = ' selected="selected"';
5880:23): } else {
5881:23): $selected = '';
5882:23): }
5883:23): }
5884:23): $output .= '<option value="'.$role.'"'.$selected.'>'.
5885:23): &Apache::lonnet::plaintext($role,'Course').
5886:23): '</option>';
5887:23): }
5888:23): $output .= '</select></td>';
5889:23): }
5890:23): $output .= '</tr></table></fieldset>'.
5891:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5892:23): '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5893:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5894:23): $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5895:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5896:23): $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5897:23): '</fieldset>'.
5898:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5899:23): foreach my $lticrsrole (@lticourseroles) {
5900:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5901:23): $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5902:23): }
5903:23): $output .= '</fieldset>'.
5904:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5905:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5906:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5907:23): $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5908:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5909:23): $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5910:23): '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5911:23): '<span class="LC_nobreak">'.&mt('From').':<label>'.
5912:23): '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5913:23): $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5914:23): &mt('Standard field').'</label>'.(' 'x2).
5915:23): '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5916:23): $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5917:23): '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5918:23): '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5919:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5920:23): my ($pb1p1chk,$pb1p0chk,$onclickpb);
5921:23): foreach my $extra ('roster','passback') {
5922:23): my $checkedon = '';
5923:23): my $checkedoff = ' checked="checked"';
5924:23): if ($extra eq 'passback') {
5925:23): $pb1p1chk = ' checked="checked"';
5926:23): $pb1p0chk = '';
5927:23): $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5928:23): } else {
5929:23): $onclickpb = '';
5930:23): }
5931:23): if (ref($current) eq 'HASH') {
5932:23): if (($current->{$extra})) {
5933:23): $checkedon = $checkedoff;
5934:23): $checkedoff = '';
5935:23): if ($extra eq 'passback') {
5936:23): $passbacksty = 'inline-block';
5937:23): }
5938:23): if ($current->{'passbackformat'} eq '1.0') {
5939:23): $pb1p0chk = ' checked="checked"';
5940:23): $pb1p1chk = '';
5941:23): }
5942:23): }
5943:23): }
5944:23): $output .= $lt{$extra}.' '.
5945:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5946:23): &mt('No').'</label>'.(' 'x2).
5947:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5948:23): &mt('Yes').'</label><br />';
5949:23): }
5950:23): $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5951:23): '<span class="LC_nobreak">'.&mt('Grade format').
5952:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5953:23): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5954:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5955:23): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5956:23): '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5957:23): $output .= '</span></div></fieldset>';
5958:23): # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5959:23): #
5960:23): # $output .= '</fieldset>'.
5961:23): # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5962:23): return $output;
5963:23): }
5964:23):
5965:23): sub ltimenu_titles {
5966:23): return &Apache::lonlocal::texthash(
5967:23): fullname => 'Full name',
5968:23): coursetitle => 'Course title',
5969:23): role => 'Role',
5970:23): logout => 'Logout',
5971:23): grades => 'Grades',
5972:23): );
5(raebur 5973:2): }
5974:2):
18(raebu 5975:24): sub linkprot_suggestions {
5976:24): my ($suggested,$itemcount) = @_;
5977:24): my $count = 0;
5978:24): my $next = 1;
5979:24): my %lt = &Apache::lonlocal::texthash(
5980:24): 'name' => 'Suggested Launcher',
5981:24): 'info' => 'Recommendations',
5982:24): );
5983:24): my ($datatable,$css_class,$dest);
5984:24): if (ref($suggested) eq 'HASH') {
5985:24): my @current = sort { $a <=> $b } keys(%{$suggested});
5986:24): $next += $current[-1];
5987:24): for (my $i=0; $i<@current; $i++) {
5988:24): my $num = $current[$i];
5989:24): my %values;
5990:24): if (ref($suggested->{$num}) eq 'HASH') {
5991:24): %values = %{$suggested->{$num}};
5992:24): } else {
5993:24): next;
5994:24): }
5995:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5996:24): $datatable .=
5997:24): '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5998:24): '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
5999:24): &mt('Delete?').'</label></span></td><td>'."\n".
6000:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6001:24): '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6002:24): '</fieldset></div>'.
6003:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6004:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6005:24): '</fieldset></div>'.
6006:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6007:24): '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6008:24): $$itemcount ++;
6009:24): }
6010:24): }
6011:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6012:24): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6013:24): '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6014:24): '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6015:24): '<td>'."\n".
6016:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6017:24): '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6018:24): '</fieldset></div>'.
6019:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6020:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6021:24): '</fieldset></div>'.
6022:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6023:24): '</td></tr>'."\n";
6024:24): return $datatable;
6025:24): }
14(raebu 6026:23):
1.121 raeburn 6027: sub print_coursedefaults {
1.139 raeburn 6028: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 6029: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6030: my $itemcount = 1;
1.160.6.16 raeburn 6031: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 6032: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.118.2 20(raebu 6033:24): coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.160.6.16 raeburn 6034: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6035: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 6036: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6037: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 6038: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 6039: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 6040: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 6041: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 6042: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 6043:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
14(raebu 6044:23): domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6045:23): exttool => 'External Tools can be defined and configured in courses/communities (by type)',
22(raebu 6046:24): crseditors => 'Available editors for web pages and/or problems created in a course/community',
7(raebur 6047:2): );
1.160.6.21 raeburn 6048: my %staticdefaults = (
6049: anonsurvey_threshold => 10,
6050: uploadquota => 500,
1.160.6.118.2 15(raebu 6051:23): coursequota => 20,
1.160.6.57 raeburn 6052: postsubmit => 60,
1.160.6.70 raeburn 6053: mysqltables => 172800,
1.160.6.118.2 14(raebu 6054:23): domexttool => 1,
6055:23): exttool => 0,
22(raebu 6056:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 6057: );
1.139 raeburn 6058: if ($position eq 'top') {
1.160.6.57 raeburn 6059: %defaultchecked = (
6060: 'uselcmath' => 'on',
6061: 'usejsme' => 'on',
1.160.6.115 raeburn 6062: 'inline_chem' => 'on',
1.160.6.64 raeburn 6063: 'canclone' => 'none',
1.160.6.57 raeburn 6064: );
1.160.6.115 raeburn 6065: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 6066: my $deftex = $Apache::lonnet::deftex;
6067: if (ref($settings) eq 'HASH') {
6068: if ($settings->{'texengine'}) {
6069: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6070: $deftex = $settings->{'texengine'};
6071: }
6072: }
6073: }
6074: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6075: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6076: '<span class="LC_nobreak">'.$choices{'texengine'}.
6077: '</span></td><td class="LC_right_item">'.
6078: '<select name="texengine">'."\n";
6079: my %texoptions = (
6080: MathJax => 'MathJax',
6081: mimetex => &mt('Convert to Images'),
6082: tth => &mt('TeX to HTML'),
6083: );
6084: foreach my $renderer ('MathJax','mimetex','tth') {
6085: my $selected = '';
6086: if ($renderer eq $deftex) {
6087: $selected = ' selected="selected"';
6088: }
6089: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6090: }
6091: $mathdisp .= '</select></td></tr>'."\n";
6092: $itemcount ++;
1.139 raeburn 6093: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6094: \%choices,$itemcount);
1.160.6.90 raeburn 6095: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 6096: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6097: $datatable .=
6098: '<tr'.$css_class.'><td valign="top">'.
6099: '<span class="LC_nobreak">'.$choices{'canclone'}.
6100: '</span></td><td class="LC_left_item">';
6101: my $currcanclone = 'none';
6102: my $onclick;
6103: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 6104: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 6105: none => 'No additional course requesters',
6106: domain => "Any course requester in course's domain",
6107: instcode => 'Course requests for official courses ...',
6108: );
6109: my (%codedefaults,@code_order,@posscodes);
6110: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6111: \@code_order) eq 'ok') {
6112: if (@code_order > 0) {
6113: push(@cloneoptions,'instcode');
6114: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6115: }
6116: }
6117: if (ref($settings) eq 'HASH') {
6118: if ($settings->{'canclone'}) {
6119: if (ref($settings->{'canclone'}) eq 'HASH') {
6120: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6121: if (@code_order > 0) {
6122: $currcanclone = 'instcode';
6123: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6124: }
6125: }
6126: } elsif ($settings->{'canclone'} eq 'domain') {
6127: $currcanclone = $settings->{'canclone'};
6128: }
6129: }
6130: }
6131: foreach my $option (@cloneoptions) {
6132: my ($checked,$additional);
6133: if ($currcanclone eq $option) {
6134: $checked = ' checked="checked"';
6135: }
6136: if ($option eq 'instcode') {
6137: if (@code_order) {
6138: my $show = 'none';
6139: if ($checked) {
6140: $show = 'block';
6141: }
1.160.6.118.2 14(raebu 6142:23): $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.160.6.64 raeburn 6143: &mt('Institutional codes for new and cloned course have identical:').
6144: '<br />';
6145: foreach my $item (@code_order) {
6146: my $codechk;
6147: if ($checked) {
6148: if (grep(/^\Q$item\E$/,@posscodes)) {
6149: $codechk = ' checked="checked"';
6150: }
6151: }
6152: $additional .= '<label>'.
6153: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6154: $item.'</label>';
6155: }
6156: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6157: }
6158: }
6159: $datatable .=
6160: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6161: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6162: '</label> '.$additional.'</span><br />';
6163: }
6164: $datatable .= '</td>'.
6165: '</tr>';
6166: $itemcount ++;
1.139 raeburn 6167: } else {
6168: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.118.2 15(raebu 6169:23): my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6170:23): %deftimeout,%currmysql);
1.160.6.16 raeburn 6171: my $currusecredits = 0;
1.160.6.57 raeburn 6172: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 6173:2): my $ltiauth = 0;
14(raebu 6174:23): my %domexttool;
6175:23): my %exttool;
22(raebu 6176:24): my %crseditors;
1.160.6.30 raeburn 6177: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 6178: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 6179:2): if ($settings->{'ltiauth'}) {
6180:2): $ltiauth = 1;
6181:2): }
14(raebu 6182:23): if (ref($settings->{'domexttool'}) eq 'HASH') {
6183:23): foreach my $type (@types) {
6184:23): if ($settings->{'domexttool'}->{$type}) {
6185:23): $domexttool{$type} = ' checked="checked"';
6186:23): }
6187:23): }
6188:23): } else {
6189:23): foreach my $type (@types) {
6190:23): if ($staticdefaults{'domexttool'}) {
6191:23): $domexttool{$type} = ' checked="checked"';
6192:23): }
6193:23): }
6194:23): }
6195:23): if (ref($settings->{'exttool'}) eq 'HASH') {
6196:23): foreach my $type (@types) {
6197:23): if ($settings->{'exttool'}->{$type}) {
6198:23): $exttool{$type} = ' checked="checked"';
6199:23): }
6200:23): }
6201:23): }
22(raebu 6202:24): if (ref($settings->{'crseditors'}) eq 'ARRAY') {
6203:24): foreach my $editor (@{$settings->{'crseditors'}}) {
6204:24): $crseditors{$editor} = ' checked="checked"';
6205:24): }
6206:24): } else {
6207:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6208:24): $crseditors{$editor} = ' checked="checked"';
6209:24): }
6210:24): }
1.139 raeburn 6211: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 6212: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6213: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6214: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6215: }
6216: }
1.160.6.118.2 15(raebu 6217:23): if (ref($settings->{'coursequota'}) eq 'HASH') {
6218:23): foreach my $type (keys(%{$settings->{'coursequota'}})) {
6219:23): $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6220:23): }
6221:23): }
1.160.6.16 raeburn 6222: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 6223: foreach my $type (@types) {
6224: next if ($type eq 'community');
6225: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6226: if ($defcredits{$type} ne '') {
6227: $currusecredits = 1;
6228: }
6229: }
6230: }
6231: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6232: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6233: $postsubmitclient = 0;
6234: foreach my $type (@types) {
6235: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6236: }
6237: } else {
6238: foreach my $type (@types) {
6239: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6240: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6241: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6242: } else {
6243: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6244: }
6245: } else {
6246: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6247: }
6248: }
6249: }
6250: } else {
6251: foreach my $type (@types) {
6252: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 6253: }
6254: }
1.160.6.70 raeburn 6255: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6256: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6257: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6258: }
6259: } else {
6260: foreach my $type (@types) {
6261: $currmysql{$type} = $staticdefaults{'mysqltables'};
6262: }
6263: }
1.160.6.58 raeburn 6264: } else {
6265: foreach my $type (@types) {
6266: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.118.2 14(raebu 6267:23): if ($staticdefaults{'domexttool'}) {
6268:23): $domexttool{$type} = ' checked="checked"';
6269:23): }
1.160.6.58 raeburn 6270: }
1.160.6.118.2 22(raebu 6271:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6272:24): $crseditors{$editor} = ' checked="checked"';
6273:24): }
1.139 raeburn 6274: }
6275: if (!$currdefresponder) {
1.160.6.21 raeburn 6276: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6277: } elsif ($currdefresponder < 1) {
6278: $currdefresponder = 1;
6279: }
1.160.6.21 raeburn 6280: foreach my $type (@types) {
6281: if ($curruploadquota{$type} eq '') {
6282: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6283: }
1.160.6.118.2 15(raebu 6284:23): if ($currcoursequota{$type} eq '') {
6285:23): $currcoursequota{$type} = $staticdefaults{'coursequota'};
6286:23): }
1.160.6.21 raeburn 6287: }
1.139 raeburn 6288: $datatable .=
1.160.6.16 raeburn 6289: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6290: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6291: '</span></td>'.
6292: '<td class="LC_right_item"><span class="LC_nobreak">'.
6293: '<input type="text" name="anonsurvey_threshold"'.
6294: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 6295: '</td></tr>'."\n";
6296: $itemcount ++;
6297: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6298: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6299: $choices{'uploadquota'}.
6300: '</span></td>'.
6301: '<td align="right" class="LC_right_item">'.
6302: '<table><tr>';
1.160.6.21 raeburn 6303: foreach my $type (@types) {
6304: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6305: '<input type="text" name="uploadquota_'.$type.'"'.
6306: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6307: }
6308: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 6309: $itemcount ++;
1.160.6.118.2 15(raebu 6310:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6311:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6312:23): $choices{'coursequota'}.
6313:23): '</span></td>'.
6314:23): '<td style="text-align: right" class="LC_right_item">'.
6315:23): '<table><tr>';
6316:23): foreach my $type (@types) {
6317:23): $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6318:23): '<input type="text" name="coursequota_'.$type.'"'.
6319:23): ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6320:23): }
6321:23): $datatable .= '</tr></table></td></tr>'."\n";
6322:23): $itemcount ++;
1.160.6.40 raeburn 6323: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 6324: my $display = 'none';
6325: if ($currusecredits) {
6326: $display = 'block';
6327: }
6328: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 6329: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6330: foreach my $type (@types) {
6331: next if ($type eq 'community');
6332: $additional .= '<td align="center">'.&mt($type).'<br />'.
6333: '<input type="text" name="'.$type.'_credits"'.
6334: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6335: }
6336: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 6337: %defaultchecked = ('coursecredits' => 'off');
6338: @toggles = ('coursecredits');
6339: my $current = {
6340: 'coursecredits' => $currusecredits,
6341: };
6342: (my $table,$itemcount) =
6343: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6344: \%choices,$itemcount,$onclick,$additional,'left');
6345: $datatable .= $table;
6346: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6347: my $display = 'none';
6348: if ($postsubmitclient) {
6349: $display = 'block';
6350: }
6351: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 6352: &mt('Number of seconds submit is disabled').'<br />'.
6353: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6354: '<table><tr>';
1.160.6.57 raeburn 6355: foreach my $type (@types) {
6356: $additional .= '<td align="center">'.&mt($type).'<br />'.
6357: '<input type="text" name="'.$type.'_timeout" value="'.
6358: $deftimeout{$type}.'" size="5" /></td>';
6359: }
6360: $additional .= '</tr></table></div>'."\n";
6361: %defaultchecked = ('postsubmit' => 'on');
6362: @toggles = ('postsubmit');
1.160.6.70 raeburn 6363: $current = {
6364: 'postsubmit' => $postsubmitclient,
6365: };
1.160.6.57 raeburn 6366: ($table,$itemcount) =
6367: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6368: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 6369: $datatable .= $table;
1.160.6.70 raeburn 6370: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6371: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6372: $choices{'mysqltables'}.
6373: '</span></td>'.
6374: '<td align="right" class="LC_right_item">'.
6375: '<table><tr>';
6376: foreach my $type (@types) {
6377: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6378: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 6379: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 6380: }
6381: $datatable .= '</tr></table></td></tr>'."\n";
6382: $itemcount ++;
1.160.6.118.2 4(raebur 6383:2): %defaultchecked = ('ltiauth' => 'off');
6384:2): @toggles = ('ltiauth');
6385:2): $current = {
6386:2): 'ltiauth' => $ltiauth,
6387:2): };
6388:2): ($table,$itemcount) =
6389:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6390:2): \%choices,$itemcount,undef,undef,'left');
6391:2): $datatable .= $table;
14(raebu 6392:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6393:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6394:23): $choices{'domexttool'}.
6395:23): '</span></td>'.
6396:23): '<td style="text-align: right" class="LC_right_item">'.
6397:23): '<table><tr>';
6398:23): foreach my $type (@types) {
6399:23): $datatable .= '<td style="text-align: left">'.
6400:23): '<span class="LC_nobreak">'.
22(raebu 6401:24): '<label><input type="checkbox" name="domexttool"'.
14(raebu 6402:23): ' value="'.$type.'"'.$domexttool{$type}.' />'.
22(raebu 6403:24): &mt($type).'</label></span></td>'."\n";
14(raebu 6404:23): }
6405:23): $datatable .= '</tr></table></td></tr>'."\n";
4(raebur 6406:2): $itemcount ++;
14(raebu 6407:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6408:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6409:23): $choices{'exttool'}.
6410:23): '</span></td>'.
6411:23): '<td style="text-align: right" class="LC_right_item">'.
6412:23): '<table><tr>';
6413:23): foreach my $type (@types) {
6414:23): $datatable .= '<td style="text-align: left">'.
6415:23): '<span class="LC_nobreak">'.
22(raebu 6416:24): '<label><input type="checkbox" name="exttool"'.
14(raebu 6417:23): ' value="'.$type.'"'.$exttool{$type}.' />'.
22(raebu 6418:24): &mt($type).'</label></span></td>'."\n";
6419:24): }
6420:24): $datatable .= '</tr></table></td></tr>'."\n";
6421:24): $itemcount ++;
6422:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6423:24): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6424:24): $choices{'crseditors'}.
6425:24): '</span></td>'.
6426:24): '<td style="text-align: right" class="LC_right_item">'.
6427:24): '<table><tr>';
6428:24): my @editors = ('edit','xml','daxe');
6429:24): my %editornames = &crseditor_titles();
6430:24): foreach my $editor (@editors) {
6431:24): $datatable .= '<td style="text-align: left">'.
6432:24): '<span class="LC_nobreak">'.
6433:24): '<label><input type="checkbox" name="crseditors"'.
6434:24): ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
6435:24): $editornames{$editor}.'</label></span></td>'."\n";
14(raebu 6436:23): }
6437:23): $datatable .= '</tr></table></td></tr>'."\n";
6438:23): }
6439:23): $$rowtotal += $itemcount;
6440:23): return $datatable;
6441:23): }
6442:23):
22(raebu 6443:24): sub crseditor_titles {
6444:24): return &Apache::lonlocal::texthash(
6445:24): edit => 'Standard editor (Edit)',
6446:24): xml => 'Text editor (EditXML)',
6447:24): daxe => 'Daxe editor (Daxe)',
6448:24): );
6449:24): }
6450:24):
20(raebu 6451:24): sub print_authordefaults {
6452:24): my ($position,$dom,$settings,$rowtotal) = @_;
6453:24): my ($css_class,$datatable,%checkedon,%checkedoff);
6454:24): my $itemcount = 1;
6455:24): my %titles = &authordefaults_titles();
6456:24): if ($position eq 'top') {
6457:24): my %defaultchecked = (
6458:24): 'nocodemirror' => 'off',
21(raebu 6459:24): 'daxecollapse' => 'off',
20(raebu 6460:24): 'domcoordacc' => 'on',
6461:24): );
21(raebu 6462:24): my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
20(raebu 6463:24): ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
6464:24): \%titles,$itemcount);
6465:24): my %staticdefaults = (
6466:24): 'copyright' => 'default',
6467:24): 'sourceavail' => 'closed',
6468:24): );
6469:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6470:24): my %currrights;
6471:24): foreach my $item ('copyright','sourceavail') {
6472:24): $currrights{$item} = $staticdefaults{$item};
6473:24): if (ref($settings) eq 'HASH') {
6474:24): if (exists($settings->{$item})) {
6475:24): $currrights{$item} = $settings->{$item};
6476:24): }
6477:24): }
6478:24): }
6479:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6480:24): '<span class="LC_nobreak">'.$titles{'copyright'}.
6481:24): '</span></td><td class="LC_right_item">'.
6482:24): &selectbox('copyright',$currrights{'copyright'},'',
6483:24): \&Apache::loncommon::copyrightdescription,
6484:24): (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
6485:24): '</td></tr>'."\n";
6486:24): $itemcount ++;
6487:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6488:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6489:24): '<span class="LC_nobreak">'.$titles{'sourceavail'}.
6490:24): '</span></td><td class="LC_right_item">'.
6491:24): &selectbox('sourceavail',$currrights{'sourceavail'},'',
6492:24): \&Apache::loncommon::source_copyrightdescription,
6493:24): (&Apache::loncommon::source_copyrightids)).
6494:24): '</td></tr>'."\n";
6495:24): } else {
6496:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6497:24): my $curreditors;
6498:24): my %staticdefaults = (
6499:24): editors => ['edit','xml'],
6500:24): authorquota => 500,
6501:24): webdav => 0,
6502:24): );
6503:24): my $curreditors = $staticdefaults{'editors'};
6504:24): if ((ref($settings) eq 'HASH') &&
6505:24): (ref($settings->{'editors'}) eq 'ARRAY')) {
6506:24): $curreditors = $settings->{'editors'};
6507:24): } else {
6508:24): $curreditors = $staticdefaults{'editors'};
6509:24): }
6510:24): my @editors = ('edit','xml','daxe');
6511:24): $datatable = '<tr'.$css_class.'>'."\n".
6512:24): '<td>'.$titles{'editors'}.'</td>'."\n".
6513:24): '<td class="LC_left_item">'."\n".
6514:24): '<span class="LC_nobreak">';
6515:24): foreach my $editor (@editors) {
6516:24): my $checked;
6517:24): if (grep(/^\Q$editor\E$/,@{$curreditors})) {
6518:24): $checked = ' checked="checked"';
6519:24): }
6520:24): $datatable .= '<label>'.
6521:24): '<input type="checkbox" name="author_editors" '.
6522:24): $checked.' value="'.$editor.'" '.
6523:24): 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
6524:24): $titles{$editor}.'</label> ';
6525:24): }
6526:24): $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
6527:24): $itemcount ++;
6528:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6529:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6530:24): my @insttypes;
6531:24): if (ref($types) eq 'ARRAY') {
6532:24): @insttypes = @{$types};
6533:24): }
6534:24): my $typecount = 0;
6535:24): my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
6536:24): my @items = ('webdav','authorquota');
6537:24): my %quotas;
6538:24): if (ref($domconf{'quotas'}) eq 'HASH') {
6539:24): %quotas = %{$domconf{'quotas'}};
6540:24): foreach my $item (@items) {
6541:24): if (ref($quotas{$item}) eq 'HASH') {
6542:24): foreach my $type (@insttypes,'default') {
6543:24): if ($item eq 'authorquota') {
6544:24): if ($quotas{$item}{$type} !~ /^\d+$/) {
6545:24): $quotas{$item}{$type} = $staticdefaults{$item};
6546:24): }
6547:24): } elsif ($item eq 'webdav') {
6548:24): if ($quotas{$item}{$type} !~ /^(0|1)$/) {
6549:24): $quotas{$item}{$type} = $staticdefaults{$item};
6550:24): }
6551:24): }
6552:24): }
6553:24): } else {
6554:24): foreach my $type (@insttypes,'default') {
6555:24): $quotas{$item}{$type} = $staticdefaults{$item};
6556:24): }
6557:24): }
6558:24): }
6559:24): } else {
6560:24): foreach my $item (@items) {
6561:24): foreach my $type (@insttypes,'default') {
6562:24): $quotas{$item}{$type} = $staticdefaults{$item};
6563:24): }
6564:24): }
6565:24): }
6566:24): if (ref($usertypes) eq 'HASH') {
6567:24): my $numinrow = 4;
6568:24): my $onclick = '';
6569:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6570:24): $numinrow,$othertitle,'authorquota',
6571:24): \$itemcount,$onclick);
6572:24): $itemcount ++;
6573:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6574:24): $numinrow,$othertitle,'webdav',
6575:24): \$itemcount);
6576:24): $itemcount ++;
6577:24): }
6578:24): my $checkedno = ' checked="checked"';
6579:24): my ($checkedon,$checkedoff);
6580:24): if (ref($quotas{'webdav'}) eq 'HASH') {
6581:24): if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
6582:24): if ($quotas{'webdav'}{'_LC_adv'}) {
6583:24): $checkedon = $checkedno;
6584:24): } else {
6585:24): $checkedoff = $checkedno;
6586:24): }
6587:24): undef($checkedno);
6588:24): }
6589:24): }
6590:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6591:24): $datatable .= '<tr'.$css_class.'>'.
6592:24): '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
6593:24): $titles{'webdav_LC_adv_over'}.
6594:24): '</td>'.
6595:24): '<td class="LC_left_item">';
6596:24): foreach my $option ('none','off','on') {
6597:24): my ($text,$val,$checked);
6598:24): if ($option eq 'none') {
6599:24): $text = $titles{'none'};
6600:24): $val = '';
6601:24): $checked = $checkedno;
6602:24): } elsif ($option eq 'off') {
6603:24): $text = $titles{'overoff'};
6604:24): $val = 0;
6605:24): $checked = $checkedoff;
6606:24): } elsif ($option eq 'on') {
6607:24): $text = $titles{'overon'};
6608:24): $val = 1;
6609:24): $checked = $checkedon;
6610:24): }
6611:24): $datatable .= '<span class="LC_nobreak"><label>'.
6612:24): '<input type="radio" name="webdav_LC_adv"'.
6613:24): ' value="'.$val.'"'.$checked.' />'.
6614:24): $text.'</label></span> ';
6615:24): }
6616:24): $datatable .= '</td></tr>';
6617:24): $itemcount ++;
22(raebu 6618:24): my %defchecked = (
6619:24): 'archive' => 'off',
6620:24): );
6621:24): my @toggles = ('archive');
6622:24): (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
6623:24): {'archive' => 'off'},
6624:24): \%titles,$itemcount);
6625:24): $datatable .= $archive."\n";
6626:24): $itemcount ++;
20(raebu 6627:24): }
6628:24): $$rowtotal += $itemcount;
6629:24): return $datatable;
6630:24): }
6631:24):
6632:24): sub authordefaults_titles {
6633:24): return &Apache::lonlocal::texthash(
6634:24): copyright => 'Copyright/Distribution',
6635:24): sourceavail => ' Source Available',
6636:24): editors => 'Available Editors',
6637:24): webdav => 'WebDAV',
6638:24): authorquota => 'Authoring Space quotas (MB)',
6639:24): nocodemirror => 'Deactivate CodeMirror for EditXML editor',
21(raebu 6640:24): daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
20(raebu 6641:24): domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
6642:24): edit => 'Standard editor (Edit)',
6643:24): xml => 'Text editor (EditXML)',
6644:24): daxe => 'Daxe editor (Daxe)',
6645:24): webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
6646:24): webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
6647:24): none => 'No override set',
6648:24): overon => 'Override -- webDAV on',
6649:24): overoff => 'Override -- webDAV off',
22(raebu 6650:24): archive => 'Authors can download tar.gz file of Authoring Space',
20(raebu 6651:24): );
6652:24): }
6653:24):
6654:24): sub selectbox {
6655:24): my ($name,$value,$readonly,$functionref,@idlist)=@_;
6656:24): my $selout = '<select name="'.$name.'">';
6657:24): foreach my $id (@idlist) {
6658:24): $selout.='<option value="'.$id.'"';
6659:24): if ($id eq $value) {
6660:24): $selout.=' selected="selected"';
6661:24): }
6662:24): if ($readonly) {
6663:24): $selout .= ' disabled="disabled"';
6664:24): }
6665:24): $selout.='>'.&{$functionref}($id).'</option>';
6666:24): }
6667:24): $selout.='</select>';
6668:24): return $selout;
6669:24): }
6670:24):
14(raebu 6671:23): sub print_selfenrollment {
1.160.6.37 raeburn 6672: my ($position,$dom,$settings,$rowtotal) = @_;
6673: my ($css_class,$datatable);
6674: my $itemcount = 1;
6675: my @types = ('official','unofficial','community','textbook');
6676: if (($position eq 'top') || ($position eq 'middle')) {
6677: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6678: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6679: my @rows;
6680: my $key;
6681: if ($position eq 'top') {
6682: $key = 'admin';
6683: if (ref($rowsref) eq 'ARRAY') {
6684: @rows = @{$rowsref};
6685: }
6686: } elsif ($position eq 'middle') {
6687: $key = 'default';
6688: @rows = ('types','registered','approval','limit');
6689: }
6690: foreach my $row (@rows) {
6691: if (defined($titlesref->{$row})) {
6692: $itemcount ++;
6693: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6694: $datatable .= '<tr'.$css_class.'>'.
6695: '<td>'.$titlesref->{$row}.'</td>'.
6696: '<td class="LC_left_item">'.
6697: '<table><tr>';
6698: my (%current,%currentcap);
6699: if (ref($settings) eq 'HASH') {
6700: if (ref($settings->{$key}) eq 'HASH') {
6701: foreach my $type (@types) {
6702: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6703: $current{$type} = $settings->{$key}->{$type}->{$row};
6704: }
6705: if (($row eq 'limit') && ($key eq 'default')) {
6706: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6707: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6708: }
6709: }
6710: }
6711: }
6712: }
6713: my %roles = (
6714: '0' => &Apache::lonnet::plaintext('dc'),
6715: );
6716:
6717: foreach my $type (@types) {
6718: unless (($row eq 'registered') && ($key eq 'default')) {
6719: $datatable .= '<th>'.&mt($type).'</th>';
6720: }
6721: }
6722: unless (($row eq 'registered') && ($key eq 'default')) {
6723: $datatable .= '</tr><tr>';
6724: }
6725: foreach my $type (@types) {
6726: if ($type eq 'community') {
6727: $roles{'1'} = &mt('Community personnel');
6728: } else {
6729: $roles{'1'} = &mt('Course personnel');
6730: }
6731: $datatable .= '<td style="vertical-align: top">';
6732: if ($position eq 'top') {
6733: my %checked;
6734: if ($current{$type} eq '0') {
6735: $checked{'0'} = ' checked="checked"';
6736: } else {
6737: $checked{'1'} = ' checked="checked"';
6738: }
6739: foreach my $role ('1','0') {
6740: $datatable .= '<span class="LC_nobreak"><label>'.
6741: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6742: 'value="'.$role.'"'.$checked{$role}.' />'.
6743: $roles{$role}.'</label></span> ';
6744: }
6745: } else {
6746: if ($row eq 'types') {
6747: my %checked;
6748: if ($current{$type} =~ /^(all|dom)$/) {
6749: $checked{$1} = ' checked="checked"';
6750: } else {
6751: $checked{''} = ' checked="checked"';
6752: }
6753: foreach my $val ('','dom','all') {
6754: $datatable .= '<span class="LC_nobreak"><label>'.
6755: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6756: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6757: }
6758: } elsif ($row eq 'registered') {
6759: my %checked;
6760: if ($current{$type} eq '1') {
6761: $checked{'1'} = ' checked="checked"';
6762: } else {
6763: $checked{'0'} = ' checked="checked"';
6764: }
6765: foreach my $val ('0','1') {
6766: $datatable .= '<span class="LC_nobreak"><label>'.
6767: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6768: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6769: }
6770: } elsif ($row eq 'approval') {
6771: my %checked;
6772: if ($current{$type} =~ /^([12])$/) {
6773: $checked{$1} = ' checked="checked"';
6774: } else {
6775: $checked{'0'} = ' checked="checked"';
6776: }
6777: for my $val (0..2) {
6778: $datatable .= '<span class="LC_nobreak"><label>'.
6779: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6780: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6781: }
6782: } elsif ($row eq 'limit') {
6783: my %checked;
6784: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6785: $checked{$1} = ' checked="checked"';
6786: } else {
6787: $checked{'none'} = ' checked="checked"';
6788: }
6789: my $cap;
6790: if ($currentcap{$type} =~ /^\d+$/) {
6791: $cap = $currentcap{$type};
6792: }
6793: foreach my $val ('none','allstudents','selfenrolled') {
6794: $datatable .= '<span class="LC_nobreak"><label>'.
6795: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6796: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6797: }
6798: $datatable .= '<br />'.
6799: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6800: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6801: '</span>';
6802: }
6803: }
6804: $datatable .= '</td>';
6805: }
6806: $datatable .= '</tr>';
6807: }
6808: $datatable .= '</table></td></tr>';
6809: }
6810: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 6811: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6812: }
6813: $$rowtotal += $itemcount;
6814: return $datatable;
6815: }
6816:
6817: sub print_validation_rows {
6818: my ($caller,$dom,$settings,$rowtotal) = @_;
6819: my ($itemsref,$namesref,$fieldsref);
6820: if ($caller eq 'selfenroll') {
6821: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6822: } elsif ($caller eq 'requestcourses') {
6823: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6824: }
6825: my %currvalidation;
6826: if (ref($settings) eq 'HASH') {
6827: if (ref($settings->{'validation'}) eq 'HASH') {
6828: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 6829: }
1.160.6.39 raeburn 6830: }
6831: my $datatable;
6832: my $itemcount = 0;
6833: foreach my $item (@{$itemsref}) {
6834: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6835: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6836: $namesref->{$item}.
6837: '</span></td>'.
6838: '<td class="LC_left_item">';
6839: if (($item eq 'url') || ($item eq 'button')) {
6840: $datatable .= '<span class="LC_nobreak">'.
6841: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6842: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6843: } elsif ($item eq 'fields') {
6844: my @currfields;
6845: if (ref($currvalidation{$item}) eq 'ARRAY') {
6846: @currfields = @{$currvalidation{$item}};
6847: }
6848: foreach my $field (@{$fieldsref}) {
6849: my $check = '';
6850: if (grep(/^\Q$field\E$/,@currfields)) {
6851: $check = ' checked="checked"';
6852: }
6853: $datatable .= '<span class="LC_nobreak"><label>'.
6854: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6855: ' value="'.$field.'"'.$check.' />'.$field.
6856: '</label></span> ';
6857: }
6858: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 6859: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 6860: $currvalidation{$item}.
1.160.6.37 raeburn 6861: '</textarea>';
1.160.6.39 raeburn 6862: }
6863: $datatable .= '</td></tr>'."\n";
6864: if (ref($rowtotal)) {
1.160.6.37 raeburn 6865: $itemcount ++;
6866: }
1.139 raeburn 6867: }
1.160.6.39 raeburn 6868: if ($caller eq 'requestcourses') {
6869: my %currhash;
1.160.6.51 raeburn 6870: if (ref($settings) eq 'HASH') {
6871: if (ref($settings->{'validation'}) eq 'HASH') {
6872: if ($settings->{'validation'}{'dc'} ne '') {
6873: $currhash{$settings->{'validation'}{'dc'}} = 1;
6874: }
1.160.6.39 raeburn 6875: }
6876: }
6877: my $numinrow = 2;
6878: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6879: 'validationdc',%currhash);
1.160.6.50 raeburn 6880: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 6881: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 6882: if ($numdc > 1) {
1.160.6.50 raeburn 6883: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 6884: } else {
1.160.6.50 raeburn 6885: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 6886: }
1.160.6.50 raeburn 6887: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 6888: $itemcount ++;
6889: }
6890: if (ref($rowtotal)) {
6891: $$rowtotal += $itemcount;
6892: }
1.121 raeburn 6893: return $datatable;
1.118 jms 6894: }
6895:
1.160.6.98 raeburn 6896: sub print_passwords {
6897: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6898: my ($datatable,$css_class);
6899: my $itemcount = 0;
6900: my %titles = &Apache::lonlocal::texthash (
6901: captcha => '"Forgot Password" CAPTCHA validation',
6902: link => 'Reset link expiration (hours)',
6903: case => 'Case-sensitive usernames/e-mail',
6904: prelink => 'Information required (form 1)',
6905: postlink => 'Information required (form 2)',
6906: emailsrc => 'LON-CAPA e-mail address type(s)',
6907: customtext => 'Domain specific text (HTML)',
6908: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6909: intauth_check => 'Check bcrypt cost if authenticated',
6910: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6911: permanent => 'Permanent e-mail address',
6912: critical => 'Critical notification address',
6913: notify => 'Notification address',
6914: min => 'Minimum password length',
6915: max => 'Maximum password length',
6916: chars => 'Required characters',
6917: numsaved => 'Number of previous passwords to save and disallow reuse',
6918: );
6919: if ($position eq 'top') {
6920: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6921: my $shownlinklife = 2;
6922: my $prelink = 'both';
6923: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6924: if (ref($settings) eq 'HASH') {
6925: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6926: $shownlinklife = $settings->{resetlink};
6927: }
6928: if (ref($settings->{resetcase}) eq 'ARRAY') {
6929: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6930: }
6931: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6932: $prelink = $settings->{resetprelink};
6933: }
6934: if (ref($settings->{resetpostlink}) eq 'HASH') {
6935: %postlink = %{$settings->{resetpostlink}};
6936: }
6937: if (ref($settings->{resetemail}) eq 'ARRAY') {
6938: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6939: }
6940: if ($settings->{resetremove}) {
6941: $nostdtext = 1;
6942: }
6943: if ($settings->{resetcustom}) {
6944: $customurl = $settings->{resetcustom};
6945: }
6946: } else {
6947: if (ref($types) eq 'ARRAY') {
6948: foreach my $item (@{$types}) {
6949: $casesens{$item} = 1;
6950: $postlink{$item} = ['username','email'];
6951: }
6952: }
6953: $casesens{'default'} = 1;
6954: $postlink{'default'} = ['username','email'];
6955: $prelink = 'both';
6956: %emailsrc = (
6957: permanent => 1,
6958: critical => 1,
6959: notify => 1,
6960: );
6961: }
6962: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6963: $itemcount ++;
6964: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6965: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6966: '<td class="LC_left_item">'.
6967: '<input type="textbox" value="'.$shownlinklife.'" '.
6968: 'name="passwords_link" size="3" /></td></tr>';
6969: $itemcount ++;
6970: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6971: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6972: '<td class="LC_left_item">';
6973: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6974: foreach my $item (@{$types}) {
6975: my $checkedcase;
6976: if ($casesens{$item}) {
6977: $checkedcase = ' checked="checked"';
6978: }
6979: $datatable .= '<span class="LC_nobreak"><label>'.
6980: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6981: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 6982: '</span> ';
1.160.6.98 raeburn 6983: }
6984: }
6985: my $checkedcase;
6986: if ($casesens{'default'}) {
6987: $checkedcase = ' checked="checked"';
6988: }
6989: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6990: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6991: $othertitle.'</label></span></td>';
6992: $itemcount ++;
6993: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6994: my %checkedpre = (
6995: both => ' checked="checked"',
6996: either => '',
6997: );
6998: if ($prelink eq 'either') {
6999: $checkedpre{either} = ' checked="checked"';
7000: $checkedpre{both} = '';
7001: }
7002: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7003: '<td class="LC_left_item"><span class="LC_nobreak">'.
7004: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7005: &mt('Both username and e-mail address').'</label></span> '.
7006: '<span class="LC_nobreak"><label>'.
7007: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7008: &mt('Either username or e-mail address').'</label></span></td></tr>';
7009: $itemcount ++;
7010: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7011: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7012: '<td class="LC_left_item">';
7013: my %postlinked;
7014: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7015: foreach my $item (@{$types}) {
7016: undef(%postlinked);
7017: $datatable .= '<fieldset style="display: inline-block;">'.
7018: '<legend>'.$usertypes->{$item}.'</legend>';
7019: if (ref($postlink{$item}) eq 'ARRAY') {
7020: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7021: }
7022: foreach my $field ('email','username') {
7023: my $checked;
7024: if ($postlinked{$field}) {
7025: $checked = ' checked="checked"';
7026: }
7027: $datatable .= '<span class="LC_nobreak"><label>'.
7028: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7029: $field.'"'.$checked.' />'.$field.'</label>'.
7030: '<span> ';
7031: }
7032: $datatable .= '</fieldset>';
7033: }
7034: }
7035: if (ref($postlink{'default'}) eq 'ARRAY') {
7036: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7037: }
7038: $datatable .= '<fieldset style="display: inline-block;">'.
7039: '<legend>'.$othertitle.'</legend>';
7040: foreach my $field ('email','username') {
7041: my $checked;
7042: if ($postlinked{$field}) {
7043: $checked = ' checked="checked"';
7044: }
7045: $datatable .= '<span class="LC_nobreak"><label>'.
7046: '<input type="checkbox" name="passwords_postlink_default" value="'.
7047: $field.'"'.$checked.' />'.$field.'</label>'.
7048: '<span> ';
7049: }
7050: $datatable .= '</fieldset></td></tr>';
7051: $itemcount ++;
7052: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7053: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7054: '<td class="LC_left_item">';
7055: foreach my $type ('permanent','critical','notify') {
7056: my $checkedemail;
7057: if ($emailsrc{$type}) {
7058: $checkedemail = ' checked="checked"';
7059: }
7060: $datatable .= '<span class="LC_nobreak"><label>'.
7061: '<input type="checkbox" name="passwords_emailsrc" value="'.
7062: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7063: '<span> ';
7064: }
7065: $datatable .= '</td></tr>';
7066: $itemcount ++;
7067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7068: my $switchserver = &check_switchserver($dom,$confname);
7069: my ($showstd,$noshowstd);
7070: if ($nostdtext) {
7071: $noshowstd = ' checked="checked"';
7072: } else {
7073: $showstd = ' checked="checked"';
7074: }
7075: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7076: '<td class="LC_left_item"><span class="LC_nobreak">'.
7077: &mt('Retain standard text:').
7078: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7079: &mt('Yes').'</label>'.' '.
7080: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7081: &mt('No').'</label></span><br />'.
7082: '<span class="LC_fontsize_small">'.
7083: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7084: &mt('Include custom text:');
7085: if ($customurl) {
1.160.6.104 raeburn 7086: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 7087: undef,undef,undef,undef,'background-color:#ffffff');
7088: $datatable .= '<span class="LC_nobreak"> '.$link.
7089: '<label><input type="checkbox" name="passwords_custom_del"'.
7090: ' value="1" />'.&mt('Delete?').'</label></span>'.
7091: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7092: }
7093: if ($switchserver) {
7094: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7095: } else {
7096: $datatable .='<span class="LC_nobreak"> '.
7097: '<input type="file" name="passwords_customfile" /></span>';
7098: }
7099: $datatable .= '</td></tr>';
7100: } elsif ($position eq 'middle') {
7101: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7102: my @items = ('intauth_cost','intauth_check','intauth_switch');
7103: my %defaults;
7104: if (ref($domconf{'defaults'}) eq 'HASH') {
7105: %defaults = %{$domconf{'defaults'}};
7106: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7107: $defaults{'intauth_cost'} = 10;
7108: }
7109: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7110: $defaults{'intauth_check'} = 0;
7111: }
7112: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7113: $defaults{'intauth_switch'} = 0;
7114: }
7115: } else {
7116: %defaults = (
7117: 'intauth_cost' => 10,
7118: 'intauth_check' => 0,
7119: 'intauth_switch' => 0,
7120: );
7121: }
7122: foreach my $item (@items) {
7123: if ($itemcount%2) {
7124: $css_class = '';
7125: } else {
7126: $css_class = ' class="LC_odd_row" ';
7127: }
7128: $datatable .= '<tr'.$css_class.'>'.
7129: '<td><span class="LC_nobreak">'.$titles{$item}.
7130: '</span></td><td class="LC_left_item" colspan="3">';
7131: if ($item eq 'intauth_switch') {
7132: my @options = (0,1,2);
7133: my %optiondesc = &Apache::lonlocal::texthash (
7134: 0 => 'No',
7135: 1 => 'Yes',
7136: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7137: );
7138: $datatable .= '<table width="100%">';
7139: foreach my $option (@options) {
7140: my $checked = ' ';
7141: if ($defaults{$item} eq $option) {
7142: $checked = ' checked="checked"';
7143: }
7144: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7145: '<label><input type="radio" name="'.$item.
7146: '" value="'.$option.'"'.$checked.' />'.
7147: $optiondesc{$option}.'</label></span></td></tr>';
7148: }
7149: $datatable .= '</table>';
7150: } elsif ($item eq 'intauth_check') {
7151: my @options = (0,1,2);
7152: my %optiondesc = &Apache::lonlocal::texthash (
7153: 0 => 'No',
7154: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7155: 2 => 'Yes, disallow login if stored cost is less than domain default',
7156: );
7157: $datatable .= '<table width="100%">';
7158: foreach my $option (@options) {
7159: my $checked = ' ';
7160: my $onclick;
7161: if ($defaults{$item} eq $option) {
7162: $checked = ' checked="checked"';
7163: }
7164: if ($option == 2) {
7165: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7166: }
7167: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7168: '<label><input type="radio" name="'.$item.
7169: '" value="'.$option.'"'.$checked.$onclick.' />'.
7170: $optiondesc{$option}.'</label></span></td></tr>';
7171: }
7172: $datatable .= '</table>';
7173: } else {
7174: $datatable .= '<input type="text" name="'.$item.'" value="'.
7175: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7176: }
7177: $datatable .= '</td></tr>';
7178: $itemcount ++;
7179: }
7180: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 7181:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 7182: } else {
7183: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7184: my %ownerchg = (
7185: by => {},
7186: for => {},
7187: );
7188: my %ownertitles = &Apache::lonlocal::texthash (
7189: by => 'Course owner status(es) allowed',
7190: for => 'Student status(es) allowed',
7191: );
7192: if (ref($settings) eq 'HASH') {
7193: if (ref($settings->{crsownerchg}) eq 'HASH') {
7194: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7195: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7196: }
7197: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7198: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7199: }
7200: }
7201: }
7202: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7203: $datatable .= '<tr '.$css_class.'>'.
7204: '<td>'.
7205: &mt('Requirements').'<ul>'.
7206: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
7207: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7208: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
7209: '<li>'.&mt('User, course, and student share same domain').'</li>'.
7210: '</ul>'.
7211: '</td>'.
7212: '<td class="LC_left_item">';
7213: foreach my $item ('by','for') {
7214: $datatable .= '<fieldset style="display: inline-block;">'.
7215: '<legend>'.$ownertitles{$item}.'</legend>';
7216: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7217: foreach my $type (@{$types}) {
7218: my $checked;
7219: if ($ownerchg{$item}{$type}) {
7220: $checked = ' checked="checked"';
7221: }
7222: $datatable .= '<span class="LC_nobreak"><label>'.
7223: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7224: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 7225: '</span> ';
1.160.6.98 raeburn 7226: }
7227: }
7228: my $checked;
7229: if ($ownerchg{$item}{'default'}) {
7230: $checked = ' checked="checked"';
7231: }
7232: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7233: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7234: $othertitle.'</label></span></fieldset>';
7235: }
7236: $datatable .= '</td></tr>';
7237: }
7238: return $datatable;
7239: }
7240:
1.160.6.118.2 5(raebur 7241:2): sub password_rules {
7242:2): my ($prefix,$itemcountref,$settings) = @_;
7243:2): my ($min,$max,%chars,$numsaved,$numinrow);
7244:2): my %titles;
7245:2): if ($prefix eq 'passwords') {
7246:2): %titles = &Apache::lonlocal::texthash (
7247:2): min => 'Minimum password length',
7248:2): max => 'Maximum password length',
7249:2): chars => 'Required characters',
7250:2): );
14(raebu 7251:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 7252:2): %titles = &Apache::lonlocal::texthash (
7253:2): min => 'Minimum secret length',
7254:2): max => 'Maximum secret length',
7255:2): chars => 'Required characters',
7256:2): );
7257:2): }
7258:2): $min = $Apache::lonnet::passwdmin;
7259:2): my $datatable;
7260:2): my $itemcount;
7261:2): if (ref($itemcountref)) {
7262:2): $itemcount = $$itemcountref;
7263:2): }
7264:2): if (ref($settings) eq 'HASH') {
7265:2): if ($settings->{min}) {
7266:2): $min = $settings->{min};
7267:2): }
7268:2): if ($settings->{max}) {
7269:2): $max = $settings->{max};
7270:2): }
7271:2): if (ref($settings->{chars}) eq 'ARRAY') {
7272:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
7273:2): }
7274:2): if ($prefix eq 'passwords') {
7275:2): if ($settings->{numsaved}) {
7276:2): $numsaved = $settings->{numsaved};
7277:2): }
7278:2): }
7279:2): }
7280:2): my %rulenames = &Apache::lonlocal::texthash(
7281:2): uc => 'At least one upper case letter',
7282:2): lc => 'At least one lower case letter',
7283:2): num => 'At least one number',
7284:2): spec => 'At least one non-alphanumeric',
7285:2): );
7286:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7287:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7288:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7289:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7290:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7291:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7292:2): '</span></td></tr>';
7293:2): $itemcount ++;
7294:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7295:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7296:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7297:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7298:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7299:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7300:2): '</span></td></tr>';
7301:2): $itemcount ++;
7302:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7303:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7304:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7305:2): '</span></td>';
7306:2): my $numinrow = 2;
7307:2): my @possrules = ('uc','lc','num','spec');
7308:2): $datatable .= '<td class="LC_left_item"><table>';
7309:2): for (my $i=0; $i<@possrules; $i++) {
7310:2): my ($rem,$checked);
7311:2): if ($chars{$possrules[$i]}) {
7312:2): $checked = ' checked="checked"';
7313:2): }
7314:2): $rem = $i%($numinrow);
7315:2): if ($rem == 0) {
7316:2): if ($i > 0) {
7317:2): $datatable .= '</tr>';
7318:2): }
7319:2): $datatable .= '<tr>';
7320:2): }
7321:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
7322:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7323:2): $rulenames{$possrules[$i]}.'</label></span></td>';
7324:2): }
7325:2): my $rem = @possrules%($numinrow);
7326:2): my $colsleft = $numinrow - $rem;
7327:2): if ($colsleft > 1 ) {
7328:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7329:2): ' </td>';
7330:2): } elsif ($colsleft == 1) {
7331:2): $datatable .= '<td class="LC_left_item"> </td>';
7332:2): }
7333:2): $datatable .='</table></td></tr>';
7334:2): $itemcount ++;
7335:2): if ($prefix eq 'passwords') {
7336:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7337:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7338:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7339:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7340:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7341:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7342:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7343:2): '</span></td></tr>';
7344:2): $itemcount ++;
7345:2): }
7346:2): if (ref($itemcountref)) {
7347:2): $$itemcountref += $itemcount;
7348:2): }
7349:2): return $datatable;
7350:2): }
7351:2):
1.160.6.113 raeburn 7352: sub print_wafproxy {
7353: my ($position,$dom,$settings,$rowtotal) = @_;
7354: my $css_class;
7355: my $itemcount = 0;
7356: my $datatable;
7357: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7358: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
7359: my %lt = &wafproxy_titles();
7360: foreach my $server (sort(keys(%servers))) {
7361: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7362: next if ($serverhome eq '');
7363: my $serverdom;
7364: if ($serverhome ne $server) {
7365: $serverdom = &Apache::lonnet::host_domain($serverhome);
7366: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7367: $othercontrol{$server} = $serverdom;
7368: }
7369: } else {
7370: $serverdom = &Apache::lonnet::host_domain($server);
7371: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7372: if ($serverdom ne $dom) {
7373: $othercontrol{$server} = $serverdom;
7374: } else {
7375: $setdom = 1;
7376: if (ref($settings) eq 'HASH') {
7377: if (ref($settings->{'alias'}) eq 'HASH') {
7378: $aliases{$dom} = $settings->{'alias'};
7379: if ($aliases{$dom} ne '') {
7380: $showdom = 1;
7381: }
7382: }
7383: if (ref($settings->{'saml'}) eq 'HASH') {
7384: $saml{$dom} = $settings->{'saml'};
7385: }
7386: }
7387: }
7388: }
7389: }
7390: if ($setdom) {
7391: %{$values{$dom}} = ();
7392: if (ref($settings) eq 'HASH') {
7393: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7394: $values{$dom}{$item} = $settings->{$item};
7395: }
7396: }
7397: }
7398: if (keys(%othercontrol)) {
7399: %otherdoms = reverse(%othercontrol);
7400: foreach my $domain (keys(%otherdoms)) {
7401: %{$values{$domain}} = ();
7402: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7403: if (ref($config{'wafproxy'}) eq 'HASH') {
7404: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7405: if (exists($config{'wafproxy'}{'saml'})) {
7406: $saml{$domain} = $config{'wafproxy'}{'saml'};
7407: }
7408: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7409: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7410: }
7411: }
7412: }
7413: }
7414: if ($position eq 'top') {
7415: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7416: my %aliasinfo;
7417: foreach my $server (sort(keys(%servers))) {
7418: $itemcount ++;
7419: my $dom_in_effect;
7420: my $aliasrows = '<tr>'.
7421: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.118.2 17(raebu 7422:24): &mt('Hostname').': '.
16(raebu 7423:24): '<span class="LC_nobreak LC_cusr_emph">'.
7424:24): &Apache::lonnet::hostname($server).'</span></td><td> </td>';
1.160.6.113 raeburn 7425: if ($othercontrol{$server}) {
7426: $dom_in_effect = $othercontrol{$server};
7427: my ($current,$forsaml);
7428: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7429: $current = $aliases{$dom_in_effect}{$server};
7430: }
7431: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7432: if ($saml{$dom_in_effect}{$server}) {
7433: $forsaml = 1;
7434: }
7435: }
7436: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7437: &mt('Alias').': ';
7438: if ($current) {
7439: $aliasrows .= $current;
7440: if ($forsaml) {
7441: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7442: }
7443: } else {
7444: $aliasrows .= &mt('None');
7445: }
7446: $aliasrows .= ' <span class="LC_small">('.
7447: &mt('controlled by domain: [_1]',
7448: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7449: } else {
7450: $dom_in_effect = $dom;
7451: my ($current,$samlon,$samloff);
7452: $samloff = ' checked="checked"';
7453: if (ref($aliases{$dom}) eq 'HASH') {
7454: if ($aliases{$dom}{$server}) {
7455: $current = $aliases{$dom}{$server};
7456: }
7457: }
7458: if (ref($saml{$dom}) eq 'HASH') {
7459: if ($saml{$dom}{$server}) {
7460: $samlon = $samloff;
7461: undef($samloff);
7462: }
7463: }
7464: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7465: &mt('Alias').': '.
7466: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7467: 'value="'.$current.'" size="30" />'.
7468: (' 'x2).'<span class="LC_nobreak">'.
7469: &mt('Alias used for SSO Auth').': <label>'.
7470: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7471: &mt('No').'</label> <label>'.
7472: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7473: &mt('Yes').'</label></span>'.
7474: '</td>';
7475: }
7476: $aliasrows .= '</tr>';
7477: $aliasinfo{$dom_in_effect} .= $aliasrows;
7478: }
7479: if ($aliasinfo{$dom}) {
7480: my ($onclick,$wafon,$wafoff,$showtable);
7481: $onclick = ' onclick="javascript:toggleWAF();"';
7482: $wafoff = ' checked="checked"';
7483: $showtable = ' style="display:none";';
7484: if ($showdom) {
7485: $wafon = $wafoff;
7486: $wafoff = '';
7487: $showtable = ' style="display:inline;"';
7488: }
7489: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7490: $datatable = '<tr'.$css_class.'>'.
7491: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7492: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7493: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7494: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7495: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7496: &mt('No').'</label></span></td>'.
7497: '<td class="LC_left_item">'.
7498: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7499: '</table></td></tr>';
7500: $itemcount++;
7501: }
7502: if (keys(%otherdoms)) {
7503: foreach my $key (sort(keys(%otherdoms))) {
7504: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7505: $datatable .= '<tr'.$css_class.'>'.
7506: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7507: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7508: '</table></td></tr>';
7509: $itemcount++;
7510: }
7511: }
7512: } else {
7513: my %ip_methods = &remoteip_methods();
7514: if ($setdom) {
7515: $itemcount ++;
7516: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7517: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7518: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7519: $wafstyle = ' style="display:none;"';
7520: $nowafstyle = ' style="display:table-row;"';
7521: $currwafdisplay = ' style="display: none"';
7522: $wafrangestyle = ' style="display: none"';
7523: $curr_remotip = 'n';
7524: $ssltossl = ' checked="checked"';
7525: if ($showdom) {
7526: $wafstyle = ' style="display:table-row;"';
7527: $nowafstyle = ' style="display:none;"';
7528: if (keys(%{$values{$dom}})) {
7529: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7530: $curr_remotip = $values{$dom}{remoteip};
7531: }
7532: if ($curr_remotip eq 'h') {
7533: $currwafdisplay = ' style="display:table-row"';
7534: $wafrangestyle = ' style="display:inline-block;"';
7535: }
7536: if ($values{$dom}{'sslopt'}) {
7537: $alltossl = ' checked="checked"';
7538: $ssltossl = '';
7539: }
7540: }
7541: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7542: $vpndircheck = ' checked="checked"';
7543: $currwafvpn = ' style="display:table-row;"';
7544: $wafrangestyle = ' style="display:inline-block;"';
7545: } else {
7546: $vpnaliascheck = ' checked="checked"';
7547: $currwafvpn = ' style="display:none;"';
7548: }
7549: }
7550: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7551: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7552: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7553: '</tr>'.
7554: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7555: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7556: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7557: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7558: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7559: '<td class="LC_left_item"><table>'.
7560: '<tr>'.
7561: '<td valign="top">'.$lt{'remoteip'}.': '.
7562: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7563: foreach my $option ('m','h','n') {
7564: my $sel;
1.160.6.114 raeburn 7565: if ($option eq $curr_remotip) {
7566: $sel = ' selected="selected"';
7567: }
7568: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7569: $ip_methods{$option}.'</option>';
7570: }
7571: $datatable .= '</select></td></tr>'."\n".
7572: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7573: $lt{'ipheader'}.': '.
7574: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7575: 'name="wafproxy_ipheader" />'.
7576: '</td></tr>'."\n".
7577: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7578: $lt{'trusted'}.':<br />'.
7579: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7580: $values{$dom}{'trusted'}.'</textarea>'.
7581: '</td></tr>'."\n".
7582: '<tr><td><hr /></td></tr>'."\n".
7583: '<tr>'.
1.160.6.113 raeburn 7584: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7585: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7586: $lt{'vpndirect'}.'</label>'.(' 'x2).
7587: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7588: $lt{'vpnaliased'}.'</label></span></td></tr>';
7589: foreach my $item ('vpnint','vpnext') {
7590: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7591: '<td valign="top">'.$lt{$item}.':<br />'.
7592: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7593: $values{$dom}{$item}.'</textarea>'.
7594: '</td></tr>'."\n";
7595: }
7596: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7597: '<tr>'.
7598: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7599: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7600: $lt{'alltossl'}.'</label>'.(' 'x2).
7601: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7602: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7603: '</table></td></tr>';
7604: }
7605: if (keys(%otherdoms)) {
7606: foreach my $domain (sort(keys(%otherdoms))) {
7607: $itemcount ++;
7608: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7609: $datatable .= '<tr'.$css_class.'>'.
7610: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7611: '<td class="LC_left_item"><table>';
7612: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7613: my $showval = &mt('None');
7614: if ($item eq 'ssl') {
7615: $showval = $lt{'ssltossl'};
7616: }
7617: if ($values{$domain}{$item}) {
7618: $showval = $values{$domain}{$item};
7619: if ($item eq 'ssl') {
7620: $showval = $lt{'alltossl'};
7621: } elsif ($item eq 'remoteip') {
7622: $showval = $ip_methods{$values{$domain}{$item}};
7623: }
7624: }
7625: $datatable .= '<tr>'.
7626: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7627: }
7628: $datatable .= '</table></td></tr>';
7629: }
7630: }
7631: }
7632: $$rowtotal += $itemcount;
7633: return $datatable;
7634: }
7635:
7636: sub wafproxy_titles {
7637: return &Apache::lonlocal::texthash(
7638: remoteip => "Method for determining user's IP",
7639: ipheader => 'Request header containing remote IP',
7640: trusted => 'Trusted IP range(s)',
7641: vpnaccess => 'Access from institutional VPN',
7642: vpndirect => 'via regular hostname (no WAF)',
7643: vpnaliased => 'via aliased hostname (WAF)',
7644: vpnint => 'Internal IP Range(s) for VPN sessions',
7645: vpnext => 'IP Range(s) for backend WAF connections',
7646: sslopt => 'Forwarding http/https',
7647: alltossl => 'WAF forwards both http and https requests to https',
7648: ssltossl => 'WAF forwards http requests to http and https to https',
7649: );
7650: }
7651:
7652: sub remoteip_methods {
7653: return &Apache::lonlocal::texthash(
7654: m => 'Use Apache mod_remoteip',
7655: h => 'Use headers parsed by LON-CAPA',
7656: n => 'Not in use',
7657: );
7658: }
7659:
1.137 raeburn 7660: sub print_usersessions {
7661: my ($position,$dom,$settings,$rowtotal) = @_;
7662: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 7663: my (%by_ip,%by_location,@intdoms);
7664: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 7665:
7666: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7667: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7668: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7669: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7670: my $itemcount = 1;
7671: if ($position eq 'top') {
1.152 raeburn 7672: if (keys(%serverhomes) > 1) {
1.145 raeburn 7673: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 7674: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 7675: if (ref($settings) eq 'HASH') {
7676: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7677: $curroffloadnow = $settings->{'offloadnow'};
7678: }
1.160.6.105 raeburn 7679: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7680: $curroffloadoth = $settings->{'offloadoth'};
7681: }
1.160.6.61 raeburn 7682: }
1.160.6.105 raeburn 7683: my $other_insts = scalar(keys(%by_location));
7684: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7685: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7686: } else {
1.140 raeburn 7687: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7688:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7689:23): '</td></tr>';
1.140 raeburn 7690: }
1.137 raeburn 7691: } else {
1.145 raeburn 7692: if (keys(%by_location) == 0) {
7693: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7694:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7695:23): '</td></tr>';
1.145 raeburn 7696: } else {
7697: my %lt = &usersession_titles();
7698: my $numinrow = 5;
7699: my $prefix;
7700: my @types;
7701: if ($position eq 'bottom') {
7702: $prefix = 'remote';
7703: @types = ('version','excludedomain','includedomain');
7704: } else {
7705: $prefix = 'hosted';
7706: @types = ('excludedomain','includedomain');
7707: }
7708: my (%current,%checkedon,%checkedoff);
7709: my @lcversions = &Apache::lonnet::all_loncaparevs();
7710: my @locations = sort(keys(%by_location));
7711: foreach my $type (@types) {
7712: $checkedon{$type} = '';
7713: $checkedoff{$type} = ' checked="checked"';
7714: }
7715: if (ref($settings) eq 'HASH') {
7716: if (ref($settings->{$prefix}) eq 'HASH') {
7717: foreach my $key (keys(%{$settings->{$prefix}})) {
7718: $current{$key} = $settings->{$prefix}{$key};
7719: if ($key eq 'version') {
7720: if ($current{$key} ne '') {
7721: $checkedon{$key} = ' checked="checked"';
7722: $checkedoff{$key} = '';
7723: }
7724: } elsif (ref($current{$key}) eq 'ARRAY') {
7725: $checkedon{$key} = ' checked="checked"';
7726: $checkedoff{$key} = '';
7727: }
1.137 raeburn 7728: }
7729: }
7730: }
1.145 raeburn 7731: foreach my $type (@types) {
7732: next if ($type ne 'version' && !@locations);
7733: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7734: $datatable .= '<tr'.$css_class.'>
7735: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7736: <span class="LC_nobreak">
7737: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7738: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7739: if ($type eq 'version') {
7740: my $selector = '<select name="'.$prefix.'_version">';
7741: foreach my $version (@lcversions) {
7742: my $selected = '';
7743: if ($current{'version'} eq $version) {
7744: $selected = ' selected="selected"';
7745: }
7746: $selector .= ' <option value="'.$version.'"'.
7747: $selected.'>'.$version.'</option>';
7748: }
7749: $selector .= '</select> ';
7750: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7751: } else {
7752: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7753: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7754: ' />'.(' 'x2).
7755: '<input type="button" value="'.&mt('uncheck all').'" '.
7756: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7757: "\n".
7758: '</div><div><table>';
7759: my $rem;
7760: for (my $i=0; $i<@locations; $i++) {
7761: my ($showloc,$value,$checkedtype);
7762: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7763: my $ip = $by_location{$locations[$i]}->[0];
7764: if (ref($by_ip{$ip}) eq 'ARRAY') {
7765: $value = join(':',@{$by_ip{$ip}});
7766: $showloc = join(', ',@{$by_ip{$ip}});
7767: if (ref($current{$type}) eq 'ARRAY') {
7768: foreach my $loc (@{$by_ip{$ip}}) {
7769: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7770: $checkedtype = ' checked="checked"';
7771: last;
7772: }
7773: }
1.138 raeburn 7774: }
7775: }
7776: }
1.145 raeburn 7777: $rem = $i%($numinrow);
7778: if ($rem == 0) {
7779: if ($i > 0) {
7780: $datatable .= '</tr>';
7781: }
7782: $datatable .= '<tr>';
7783: }
7784: $datatable .= '<td class="LC_left_item">'.
7785: '<span class="LC_nobreak"><label>'.
7786: '<input type="checkbox" name="'.$prefix.'_'.$type.
7787: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7788: '</label></span></td>';
1.137 raeburn 7789: }
1.145 raeburn 7790: $rem = @locations%($numinrow);
7791: my $colsleft = $numinrow - $rem;
7792: if ($colsleft > 1 ) {
7793: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7794: ' </td>';
7795: } elsif ($colsleft == 1) {
7796: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7797: }
1.145 raeburn 7798: $datatable .= '</tr></table>';
1.137 raeburn 7799: }
1.145 raeburn 7800: $datatable .= '</td></tr>';
7801: $itemcount ++;
1.137 raeburn 7802: }
7803: }
7804: }
7805: $$rowtotal += $itemcount;
7806: return $datatable;
7807: }
7808:
1.138 raeburn 7809: sub build_location_hashes {
7810: my ($intdoms,$by_ip,$by_location) = @_;
7811: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7812: (ref($by_location) eq 'HASH'));
7813: my %iphost = &Apache::lonnet::get_iphost();
7814: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7815: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7816: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7817: foreach my $id (@{$iphost{$primary_ip}}) {
7818: my $intdom = &Apache::lonnet::internet_dom($id);
7819: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7820: push(@{$intdoms},$intdom);
7821: }
7822: }
7823: }
7824: foreach my $ip (keys(%iphost)) {
7825: if (ref($iphost{$ip}) eq 'ARRAY') {
7826: foreach my $id (@{$iphost{$ip}}) {
7827: my $location = &Apache::lonnet::internet_dom($id);
7828: if ($location) {
7829: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7830: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7831: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7832: push(@{$by_ip->{$ip}},$location);
7833: }
7834: } else {
7835: $by_ip->{$ip} = [$location];
7836: }
7837: }
7838: }
7839: }
7840: }
7841: foreach my $ip (sort(keys(%{$by_ip}))) {
7842: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7843: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7844: my $first = $by_ip->{$ip}->[0];
7845: if (ref($by_location->{$first}) eq 'ARRAY') {
7846: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7847: push(@{$by_location->{$first}},$ip);
7848: }
7849: } else {
7850: $by_location->{$first} = [$ip];
7851: }
7852: }
7853: }
7854: return;
7855: }
7856:
1.145 raeburn 7857: sub current_offloads_to {
7858: my ($dom,$settings,$servers) = @_;
7859: my (%spareid,%otherdomconfigs);
1.152 raeburn 7860: if (ref($servers) eq 'HASH') {
1.145 raeburn 7861: foreach my $lonhost (sort(keys(%{$servers}))) {
7862: my $gotspares;
1.152 raeburn 7863: if (ref($settings) eq 'HASH') {
7864: if (ref($settings->{'spares'}) eq 'HASH') {
7865: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7866: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7867: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7868: $gotspares = 1;
7869: }
1.145 raeburn 7870: }
7871: }
7872: unless ($gotspares) {
7873: my $gotspares;
7874: my $serverhomeID =
7875: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7876: my $serverhomedom =
7877: &Apache::lonnet::host_domain($serverhomeID);
7878: if ($serverhomedom ne $dom) {
7879: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7880: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7881: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7882: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7883: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7884: $gotspares = 1;
7885: }
7886: }
7887: } else {
7888: $otherdomconfigs{$serverhomedom} =
7889: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7890: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7891: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7892: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7893: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7894: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7895: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7896: $gotspares = 1;
7897: }
7898: }
7899: }
7900: }
7901: }
7902: }
7903: }
7904: unless ($gotspares) {
7905: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7906: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7907: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7908: } else {
7909: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7910: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7911: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7912: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7913: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7914: } else {
1.150 raeburn 7915: my %what = (
7916: spareid => 1,
7917: );
7918: my ($result,$returnhash) =
7919: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7920: if ($result eq 'ok') {
7921: if (ref($returnhash) eq 'HASH') {
7922: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7923: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7924: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7925: }
7926: }
1.145 raeburn 7927: }
7928: }
7929: }
7930: }
7931: }
7932: }
7933: return %spareid;
7934: }
7935:
7936: sub spares_row {
1.160.6.105 raeburn 7937: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7938: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7939: my $css_class;
7940: my $numinrow = 4;
7941: my $itemcount = 1;
7942: my $datatable;
1.152 raeburn 7943: my %typetitles = &sparestype_titles();
7944: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7945: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7946: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7947: my ($othercontrol,$serverdom);
7948: if ($serverhome ne $server) {
7949: $serverdom = &Apache::lonnet::host_domain($serverhome);
7950: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7951: } else {
7952: $serverdom = &Apache::lonnet::host_domain($server);
7953: if ($serverdom ne $dom) {
7954: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7955: }
7956: }
7957: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 7958: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 7959: if (ref($curroffloadnow) eq 'HASH') {
7960: if ($curroffloadnow->{$server}) {
7961: $checkednow = ' checked="checked"';
7962: }
7963: }
1.160.6.105 raeburn 7964: if (ref($curroffloadoth) eq 'HASH') {
7965: if ($curroffloadoth->{$server}) {
7966: $checkedoth = ' checked="checked"';
7967: }
7968: }
1.145 raeburn 7969: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7970: $datatable .= '<tr'.$css_class.'>
7971: <td rowspan="2">
1.160.6.13 raeburn 7972: <span class="LC_nobreak">'.
7973: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 7974: ,'<b>'.$server.'</b>').'</span><br />'.
7975: '<span class="LC_nobreak">'."\n".
7976: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 7977: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 7978: "\n";
1.160.6.105 raeburn 7979: if ($other_insts) {
7980: $datatable .= '<br />'.
7981: '<span class="LC_nobreak">'."\n".
7982: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7983: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7984: "\n";
7985: }
1.145 raeburn 7986: my (%current,%canselect);
1.152 raeburn 7987: my @choices =
7988: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7989: foreach my $type ('primary','default') {
7990: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7991: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7992: my @spares = @{$spareid->{$server}{$type}};
7993: if (@spares > 0) {
1.152 raeburn 7994: if ($othercontrol) {
7995: $current{$type} = join(', ',@spares);
7996: } else {
7997: $current{$type} .= '<table>';
7998: my $numspares = scalar(@spares);
7999: for (my $i=0; $i<@spares; $i++) {
8000: my $rem = $i%($numinrow);
8001: if ($rem == 0) {
8002: if ($i > 0) {
8003: $current{$type} .= '</tr>';
8004: }
8005: $current{$type} .= '<tr>';
1.145 raeburn 8006: }
1.152 raeburn 8007: $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'".');" /> '.
8008: $spareid->{$server}{$type}[$i].
8009: '</label></td>'."\n";
8010: }
8011: my $rem = @spares%($numinrow);
8012: my $colsleft = $numinrow - $rem;
8013: if ($colsleft > 1 ) {
8014: $current{$type} .= '<td colspan="'.$colsleft.
8015: '" class="LC_left_item">'.
8016: ' </td>';
8017: } elsif ($colsleft == 1) {
8018: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8019: }
1.152 raeburn 8020: $current{$type} .= '</tr></table>';
1.150 raeburn 8021: }
1.145 raeburn 8022: }
8023: }
8024: if ($current{$type} eq '') {
8025: $current{$type} = &mt('None specified');
8026: }
1.152 raeburn 8027: if ($othercontrol) {
8028: if ($type eq 'primary') {
8029: $canselect{$type} = $othercontrol;
8030: }
8031: } else {
8032: $canselect{$type} =
8033: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8034: '<select name="newspare_'.$type.'_'.$server.'" '.
8035: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8036: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8037: if (@choices > 0) {
8038: foreach my $lonhost (@choices) {
8039: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8040: }
8041: }
8042: $canselect{$type} .= '</select>'."\n";
8043: }
8044: } else {
8045: $current{$type} = &mt('Could not be determined');
8046: if ($type eq 'primary') {
8047: $canselect{$type} = $othercontrol;
8048: }
1.145 raeburn 8049: }
1.152 raeburn 8050: if ($type eq 'default') {
8051: $datatable .= '<tr'.$css_class.'>';
8052: }
8053: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8054: '<td>'.$current{$type}.'</td>'."\n".
8055: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8056: }
8057: $itemcount ++;
8058: }
8059: }
8060: $$rowtotal += $itemcount;
8061: return $datatable;
8062: }
8063:
1.152 raeburn 8064: sub possible_newspares {
8065: my ($server,$currspares,$serverhomes,$altids) = @_;
8066: my $serverhostname = &Apache::lonnet::hostname($server);
8067: my %excluded;
8068: if ($serverhostname ne '') {
8069: %excluded = (
8070: $serverhostname => 1,
8071: );
8072: }
8073: if (ref($currspares) eq 'HASH') {
8074: foreach my $type (keys(%{$currspares})) {
8075: if (ref($currspares->{$type}) eq 'ARRAY') {
8076: if (@{$currspares->{$type}} > 0) {
8077: foreach my $curr (@{$currspares->{$type}}) {
8078: my $hostname = &Apache::lonnet::hostname($curr);
8079: $excluded{$hostname} = 1;
8080: }
8081: }
8082: }
8083: }
8084: }
8085: my @choices;
8086: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8087: if (keys(%{$serverhomes}) > 1) {
8088: foreach my $name (sort(keys(%{$serverhomes}))) {
8089: unless ($excluded{$name}) {
8090: if (exists($altids->{$serverhomes->{$name}})) {
8091: push(@choices,$altids->{$serverhomes->{$name}});
8092: } else {
8093: push(@choices,$serverhomes->{$name});
1.145 raeburn 8094: }
8095: }
8096: }
8097: }
8098: }
1.152 raeburn 8099: return sort(@choices);
1.145 raeburn 8100: }
8101:
1.150 raeburn 8102: sub print_loadbalancing {
8103: my ($dom,$settings,$rowtotal) = @_;
8104: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8105: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8106: my $numinrow = 1;
8107: my $datatable;
8108: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 8109: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 8110: if (ref($settings) eq 'HASH') {
8111: %existing = %{$settings};
8112: }
8113: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8114: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 8115: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8116: } else {
8117: return;
8118: }
8119: my ($othertitle,$usertypes,$types) =
8120: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 8121: my $rownum = 8;
1.150 raeburn 8122: if (ref($types) eq 'ARRAY') {
8123: $rownum += scalar(@{$types});
8124: }
1.160.6.7 raeburn 8125: my @css_class = ('LC_odd_row','LC_even_row');
8126: my $balnum = 0;
8127: my $islast;
8128: my (@toshow,$disabledtext);
8129: if (keys(%currbalancer) > 0) {
8130: @toshow = sort(keys(%currbalancer));
8131: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8132: push(@toshow,'');
8133: }
8134: } else {
8135: @toshow = ('');
8136: $disabledtext = &mt('No existing load balancer');
8137: }
8138: foreach my $lonhost (@toshow) {
8139: if ($balnum == scalar(@toshow)-1) {
8140: $islast = 1;
8141: } else {
8142: $islast = 0;
8143: }
8144: my $cssidx = $balnum%2;
8145: my $targets_div_style = 'display: none';
8146: my $disabled_div_style = 'display: block';
8147: my $homedom_div_style = 'display: none';
8148: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
8149: '<td rowspan="'.$rownum.'" valign="top">'.
8150: '<p>';
8151: if ($lonhost eq '') {
8152: $datatable .= '<span class="LC_nobreak">';
8153: if (keys(%currbalancer) > 0) {
8154: $datatable .= &mt('Add balancer:');
8155: } else {
8156: $datatable .= &mt('Enable balancer:');
8157: }
8158: $datatable .= ' '.
8159: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8160: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8161: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8162: '<option value="" selected="selected">'.&mt('None').
8163: '</option>'."\n";
8164: foreach my $server (sort(keys(%servers))) {
8165: next if ($currbalancer{$server});
8166: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8167: }
8168: $datatable .=
8169: '</select>'."\n".
8170: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8171: } else {
8172: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8173: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8174: &mt('Stop balancing').'</label>'.
8175: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8176: $targets_div_style = 'display: block';
8177: $disabled_div_style = 'display: none';
8178: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8179: $homedom_div_style = 'display: block';
8180: }
8181: }
8182: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
8183: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8184: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8185: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8186: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8187: my @sparestypes = ('primary','default');
8188: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 8189: my %hostherechecked = (
8190: no => ' checked="checked"',
8191: );
1.160.6.94 raeburn 8192: my %balcookiechecked = (
8193: no => ' checked="checked"',
8194: );
1.160.6.7 raeburn 8195: foreach my $sparetype (@sparestypes) {
8196: my $targettable;
8197: for (my $i=0; $i<$numspares; $i++) {
8198: my $checked;
8199: if (ref($currtargets{$lonhost}) eq 'HASH') {
8200: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8201: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8202: $checked = ' checked="checked"';
8203: }
8204: }
8205: }
8206: my ($chkboxval,$disabled);
8207: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8208: $chkboxval = $spares[$i];
8209: }
8210: if (exists($currbalancer{$spares[$i]})) {
8211: $disabled = ' disabled="disabled"';
8212: }
8213: $targettable .=
1.160.6.55 raeburn 8214: '<td><span class="LC_nobreak"><label>'.
8215: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 8216: $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 8217: '</span></label></span></td>';
1.160.6.7 raeburn 8218: my $rem = $i%($numinrow);
8219: if ($rem == 0) {
8220: if (($i > 0) && ($i < $numspares-1)) {
8221: $targettable .= '</tr>';
8222: }
8223: if ($i < $numspares-1) {
8224: $targettable .= '<tr>';
1.150 raeburn 8225: }
8226: }
8227: }
1.160.6.7 raeburn 8228: if ($targettable ne '') {
8229: my $rem = $numspares%($numinrow);
8230: my $colsleft = $numinrow - $rem;
8231: if ($colsleft > 1 ) {
8232: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8233: ' </td>';
8234: } elsif ($colsleft == 1) {
8235: $targettable .= '<td class="LC_left_item"> </td>';
8236: }
8237: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8238: '<table><tr>'.$targettable.'</tr></table><br />';
8239: }
1.160.6.76 raeburn 8240: $hostherechecked{$sparetype} = '';
8241: if (ref($currtargets{$lonhost}) eq 'HASH') {
8242: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8243: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8244: $hostherechecked{$sparetype} = ' checked="checked"';
8245: $hostherechecked{'no'} = '';
8246: }
8247: }
8248: }
8249: }
1.160.6.94 raeburn 8250: if ($currcookies{$lonhost}) {
8251: %balcookiechecked = (
8252: yes => ' checked="checked"',
8253: );
8254: }
1.160.6.76 raeburn 8255: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8256: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8257: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8258: foreach my $sparetype (@sparestypes) {
8259: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8260: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8261: '</i></label><br />';
1.160.6.7 raeburn 8262: }
1.160.6.94 raeburn 8263: $datatable .= &mt('Use balancer cookie').'<br />'.
8264: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8265: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8266: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8267: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8268: '</div></td></tr>'.
1.160.6.7 raeburn 8269: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8270: $othertitle,$usertypes,$types,\%servers,
8271: \%currbalancer,$lonhost,
8272: $targets_div_style,$homedom_div_style,
8273: $css_class[$cssidx],$balnum,$islast);
8274: $$rowtotal += $rownum;
8275: $balnum ++;
8276: }
8277: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8278: return $datatable;
8279: }
8280:
8281: sub get_loadbalancers_config {
1.160.6.94 raeburn 8282: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 8283: return unless ((ref($servers) eq 'HASH') &&
8284: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 8285: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8286: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 8287: if (keys(%{$existing}) > 0) {
8288: my $oldlonhost;
8289: foreach my $key (sort(keys(%{$existing}))) {
8290: if ($key eq 'lonhost') {
8291: $oldlonhost = $existing->{'lonhost'};
8292: $currbalancer->{$oldlonhost} = 1;
8293: } elsif ($key eq 'targets') {
8294: if ($oldlonhost) {
8295: $currtargets->{$oldlonhost} = $existing->{'targets'};
8296: }
8297: } elsif ($key eq 'rules') {
8298: if ($oldlonhost) {
8299: $currrules->{$oldlonhost} = $existing->{'rules'};
8300: }
8301: } elsif (ref($existing->{$key}) eq 'HASH') {
8302: $currbalancer->{$key} = 1;
8303: $currtargets->{$key} = $existing->{$key}{'targets'};
8304: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 8305: if ($existing->{$key}{'cookie'}) {
8306: $currcookies->{$key} = 1;
8307: }
1.150 raeburn 8308: }
8309: }
1.160.6.7 raeburn 8310: } else {
8311: my ($balancerref,$targetsref) =
8312: &Apache::lonnet::get_lonbalancer_config($servers);
8313: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8314: foreach my $server (sort(keys(%{$balancerref}))) {
8315: $currbalancer->{$server} = 1;
8316: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8317: }
8318: }
8319: }
1.160.6.7 raeburn 8320: return;
1.150 raeburn 8321: }
8322:
8323: sub loadbalancing_rules {
8324: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 8325: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8326: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8327: my $output;
1.160.6.7 raeburn 8328: my $num = 0;
8329: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8330: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8331: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8332: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 8333: $num ++;
1.150 raeburn 8334: my $current;
8335: if (ref($currrules) eq 'HASH') {
8336: $current = $currrules->{$type};
8337: }
1.160.6.55 raeburn 8338: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 8339: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8340: $current = '';
8341: }
8342: }
8343: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 8344: $servers,$currbalancer,$lonhost,$dom,
8345: $targets_div_style,$homedom_div_style,
8346: $css_class,$balnum,$num,$islast);
1.150 raeburn 8347: }
8348: }
8349: return $output;
8350: }
8351:
8352: sub loadbalancing_titles {
8353: my ($dom,$intdom,$usertypes,$types) = @_;
8354: my %othertypes = (
8355: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8356: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8357: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8358: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 8359: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8360: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8361: );
1.160.6.26 raeburn 8362: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 8363: my @available;
1.150 raeburn 8364: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8365: @available = @{$types};
1.150 raeburn 8366: }
1.160.6.89 raeburn 8367: unless (grep(/^default$/,@available)) {
8368: push(@available,'default');
8369: }
8370: unshift(@alltypes,@available);
1.150 raeburn 8371: my %titles;
8372: foreach my $type (@alltypes) {
8373: if ($type =~ /^_LC_/) {
8374: $titles{$type} = $othertypes{$type};
8375: } elsif ($type eq 'default') {
8376: $titles{$type} = &mt('All users from [_1]',$dom);
8377: if (ref($types) eq 'ARRAY') {
8378: if (@{$types} > 0) {
8379: $titles{$type} = &mt('Other users from [_1]',$dom);
8380: }
8381: }
8382: } elsif (ref($usertypes) eq 'HASH') {
8383: $titles{$type} = $usertypes->{$type};
8384: }
8385: }
8386: return (\@alltypes,\%othertypes,\%titles);
8387: }
8388:
8389: sub loadbalance_rule_row {
1.160.6.7 raeburn 8390: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8391: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 8392: my @rulenames;
1.150 raeburn 8393: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 8394: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 8395: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8396: } else {
1.160.6.26 raeburn 8397: @rulenames = ('default','homeserver');
8398: if ($type eq '_LC_external') {
8399: push(@rulenames,'externalbalancer');
8400: } else {
8401: push(@rulenames,'specific');
8402: }
8403: push(@rulenames,'none');
1.150 raeburn 8404: }
8405: my $style = $targets_div_style;
1.160.6.55 raeburn 8406: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8407: $style = $homedom_div_style;
8408: }
1.160.6.7 raeburn 8409: my $space;
8410: if ($islast && $num == 1) {
1.160.6.118.2 14(raebu 8411:23): $space = '<div style="display:inline-block;"> </div>';
1.160.6.7 raeburn 8412: }
8413: my $output =
8414: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8415: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8416: '<td valaign="top">'.$space.
8417: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8418: for (my $i=0; $i<@rulenames; $i++) {
8419: my $rule = $rulenames[$i];
8420: my ($checked,$extra);
8421: if ($rulenames[$i] eq 'default') {
8422: $rule = '';
8423: }
8424: if ($rulenames[$i] eq 'specific') {
8425: if (ref($servers) eq 'HASH') {
8426: my $default;
8427: if (($current ne '') && (exists($servers->{$current}))) {
8428: $checked = ' checked="checked"';
8429: }
8430: unless ($checked) {
8431: $default = ' selected="selected"';
8432: }
1.160.6.7 raeburn 8433: $extra =
8434: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8435: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8436: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8437: '<option value=""'.$default.'></option>'."\n";
8438: foreach my $server (sort(keys(%{$servers}))) {
8439: if (ref($currbalancer) eq 'HASH') {
8440: next if (exists($currbalancer->{$server}));
8441: }
1.150 raeburn 8442: my $selected;
1.160.6.7 raeburn 8443: if ($server eq $current) {
1.150 raeburn 8444: $selected = ' selected="selected"';
8445: }
1.160.6.7 raeburn 8446: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8447: }
8448: $extra .= '</select>';
8449: }
8450: } elsif ($rule eq $current) {
8451: $checked = ' checked="checked"';
8452: }
8453: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 8454: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8455: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8456: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 8457: ')"'.$checked.' /> ';
1.160.6.56 raeburn 8458: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 8459: $output .= $ruletitles{'particular'};
8460: } else {
8461: $output .= $ruletitles{$rulenames[$i]};
8462: }
8463: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8464: }
8465: $output .= '</div></td></tr>'."\n";
8466: return $output;
8467: }
8468:
8469: sub offloadtype_text {
8470: my %ruletitles = &Apache::lonlocal::texthash (
8471: 'default' => 'Offloads to default destinations',
8472: 'homeserver' => "Offloads to user's home server",
8473: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8474: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 8475: 'none' => 'No offload',
1.160.6.26 raeburn 8476: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8477: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 8478: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8479: );
8480: return %ruletitles;
8481: }
8482:
8483: sub sparestype_titles {
8484: my %typestitles = &Apache::lonlocal::texthash (
8485: 'primary' => 'primary',
8486: 'default' => 'default',
8487: );
8488: return %typestitles;
8489: }
8490:
1.28 raeburn 8491: sub contact_titles {
8492: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 8493: 'supportemail' => 'Support E-mail address',
8494: 'adminemail' => 'Default Server Admin E-mail address',
8495: 'errormail' => 'Error reports to be e-mailed to',
8496: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 8497: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8498: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 8499: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8500: 'requestsmail' => 'E-mail from course requests requiring approval',
8501: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 8502: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 8503: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 8504: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8505: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 8506: 'errorweights' => 'Weights used to compute error count',
8507: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8508: );
8509: my %short_titles = &Apache::lonlocal::texthash (
8510: adminemail => 'Admin E-mail address',
8511: supportemail => 'Support E-mail',
8512: );
8513: return (\%titles,\%short_titles);
8514: }
8515:
1.160.6.78 raeburn 8516: sub helpform_fields {
8517: my %titles = &Apache::lonlocal::texthash (
8518: 'username' => 'Name',
8519: 'user' => 'Username/domain',
8520: 'phone' => 'Phone',
8521: 'cc' => 'Cc e-mail',
8522: 'course' => 'Course Details',
8523: 'section' => 'Sections',
8524: 'screenshot' => 'File upload',
8525: );
8526: my @fields = ('username','phone','user','course','section','cc','screenshot');
8527: my %possoptions = (
8528: username => ['yes','no','req'],
8529: phone => ['yes','no','req'],
8530: user => ['yes','no'],
8531: cc => ['yes','no'],
8532: course => ['yes','no'],
8533: section => ['yes','no'],
8534: screenshot => ['yes','no'],
8535: );
8536: my %fieldoptions = &Apache::lonlocal::texthash (
8537: 'yes' => 'Optional',
8538: 'req' => 'Required',
8539: 'no' => "Not shown",
8540: );
8541: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8542: }
8543:
1.72 raeburn 8544: sub tool_titles {
8545: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 8546: aboutme => 'Personal web page',
1.86 raeburn 8547: blog => 'Blog',
8548: portfolio => 'Portfolio',
1.160.6.118.2 10(raebu 8549:22): timezone => 'Can set time zone',
1.88 bisitz 8550: official => 'Official courses (with institutional codes)',
8551: unofficial => 'Unofficial courses',
1.98 raeburn 8552: community => 'Communities',
1.160.6.30 raeburn 8553: textbook => 'Textbook courses',
1.86 raeburn 8554: );
1.72 raeburn 8555: return %titles;
8556: }
8557:
1.101 raeburn 8558: sub courserequest_titles {
8559: my %titles = &Apache::lonlocal::texthash (
8560: official => 'Official',
8561: unofficial => 'Unofficial',
8562: community => 'Communities',
1.160.6.30 raeburn 8563: textbook => 'Textbook',
1.160.6.118.2 14(raebu 8564:23): lti => 'LTI Provider',
1.101 raeburn 8565: norequest => 'Not allowed',
1.104 raeburn 8566: approval => 'Approval by Dom. Coord.',
1.101 raeburn 8567: validate => 'With validation',
8568: autolimit => 'Numerical limit',
1.103 raeburn 8569: unlimited => '(blank for unlimited)',
1.101 raeburn 8570: );
8571: return %titles;
8572: }
8573:
1.160.6.5 raeburn 8574: sub authorrequest_titles {
8575: my %titles = &Apache::lonlocal::texthash (
8576: norequest => 'Not allowed',
8577: approval => 'Approval by Dom. Coord.',
8578: automatic => 'Automatic approval',
8579: );
8580: return %titles;
8581: }
8582:
1.101 raeburn 8583: sub courserequest_conditions {
8584: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8585: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 8586: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8587: );
8588: return %conditions;
8589: }
8590:
8591:
1.27 raeburn 8592: sub print_usercreation {
1.30 raeburn 8593: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8594: my $numinrow = 4;
1.28 raeburn 8595: my $datatable;
8596: if ($position eq 'top') {
1.30 raeburn 8597: $$rowtotal ++;
1.34 raeburn 8598: my $rowcount = 0;
1.32 raeburn 8599: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8600: if (ref($rules) eq 'HASH') {
8601: if (keys(%{$rules}) > 0) {
1.32 raeburn 8602: $datatable .= &user_formats_row('username',$settings,$rules,
8603: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8604: $$rowtotal ++;
1.32 raeburn 8605: $rowcount ++;
8606: }
8607: }
8608: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8609: if (ref($idrules) eq 'HASH') {
8610: if (keys(%{$idrules}) > 0) {
8611: $datatable .= &user_formats_row('id',$settings,$idrules,
8612: $idruleorder,$numinrow,$rowcount);
8613: $$rowtotal ++;
8614: $rowcount ++;
1.28 raeburn 8615: }
8616: }
1.39 raeburn 8617: if ($rowcount == 0) {
8618: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8619: $$rowtotal ++;
8620: $rowcount ++;
8621: }
1.34 raeburn 8622: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 8623: my @creators = ('author','course','requestcrs');
1.37 raeburn 8624: my ($rules,$ruleorder) =
8625: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8626: my %lt = &usercreation_types();
8627: my %checked;
8628: if (ref($settings) eq 'HASH') {
8629: if (ref($settings->{'cancreate'}) eq 'HASH') {
8630: foreach my $item (@creators) {
8631: $checked{$item} = $settings->{'cancreate'}{$item};
8632: }
8633: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8634: foreach my $item (@creators) {
8635: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8636: $checked{$item} = 'none';
8637: }
8638: }
8639: }
8640: }
8641: my $rownum = 0;
8642: foreach my $item (@creators) {
8643: $rownum ++;
1.160.6.34 raeburn 8644: if ($checked{$item} eq '') {
8645: $checked{$item} = 'any';
1.34 raeburn 8646: }
8647: my $css_class;
8648: if ($rownum%2) {
8649: $css_class = '';
8650: } else {
8651: $css_class = ' class="LC_odd_row" ';
8652: }
8653: $datatable .= '<tr'.$css_class.'>'.
8654: '<td><span class="LC_nobreak">'.$lt{$item}.
8655: '</span></td><td align="right">';
1.160.6.34 raeburn 8656: my @options = ('any');
8657: if (ref($rules) eq 'HASH') {
8658: if (keys(%{$rules}) > 0) {
8659: push(@options,('official','unofficial'));
1.37 raeburn 8660: }
8661: }
1.160.6.34 raeburn 8662: push(@options,'none');
1.37 raeburn 8663: foreach my $option (@options) {
1.50 raeburn 8664: my $type = 'radio';
1.34 raeburn 8665: my $check = ' ';
1.160.6.34 raeburn 8666: if ($checked{$item} eq $option) {
8667: $check = ' checked="checked" ';
1.34 raeburn 8668: }
8669: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8670: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8671: $item.'" value="'.$option.'"'.$check.'/> '.
8672: $lt{$option}.'</label> </span>';
8673: }
8674: $datatable .= '</td></tr>';
8675: }
1.28 raeburn 8676: } else {
8677: my @contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 8678:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8679: my %checked;
8680: if (ref($settings) eq 'HASH') {
8681: if (ref($settings->{'authtypes'}) eq 'HASH') {
8682: foreach my $item (@contexts) {
8683: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8684: foreach my $auth (@authtypes) {
8685: if ($settings->{'authtypes'}{$item}{$auth}) {
8686: $checked{$item}{$auth} = ' checked="checked" ';
8687: }
8688: }
8689: }
8690: }
1.27 raeburn 8691: }
1.35 raeburn 8692: } else {
8693: foreach my $item (@contexts) {
1.36 raeburn 8694: foreach my $auth (@authtypes) {
1.35 raeburn 8695: $checked{$item}{$auth} = ' checked="checked" ';
8696: }
8697: }
1.27 raeburn 8698: }
1.28 raeburn 8699: my %title = &context_names();
8700: my %authname = &authtype_names();
8701: my $rownum = 0;
8702: my $css_class;
8703: foreach my $item (@contexts) {
8704: if ($rownum%2) {
8705: $css_class = '';
8706: } else {
8707: $css_class = ' class="LC_odd_row" ';
8708: }
1.30 raeburn 8709: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8710: '<td>'.$title{$item}.
8711: '</td><td class="LC_left_item">'.
8712: '<span class="LC_nobreak">';
8713: foreach my $auth (@authtypes) {
8714: $datatable .= '<label>'.
8715: '<input type="checkbox" name="'.$item.'_auth" '.
8716: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8717: $authname{$auth}.'</label> ';
8718: }
8719: $datatable .= '</span></td></tr>';
8720: $rownum ++;
1.27 raeburn 8721: }
1.30 raeburn 8722: $$rowtotal += $rownum;
1.27 raeburn 8723: }
8724: return $datatable;
8725: }
8726:
1.160.6.34 raeburn 8727: sub print_selfcreation {
8728: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 8729: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8730: $emaildomain,$datatable);
1.160.6.34 raeburn 8731: if (ref($settings) eq 'HASH') {
8732: if (ref($settings->{'cancreate'}) eq 'HASH') {
8733: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 8734: if (ref($createsettings) eq 'HASH') {
8735: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8736: @selfcreate = @{$createsettings->{'selfcreate'}};
8737: } elsif ($createsettings->{'selfcreate'} ne '') {
8738: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8739: @selfcreate = ('email','login','sso');
8740: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8741: @selfcreate = ($createsettings->{'selfcreate'});
8742: }
8743: }
8744: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8745: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 8746: }
1.160.6.93 raeburn 8747: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8748: $emailoptions = $createsettings->{'emailoptions'};
8749: }
8750: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8751: $emailverified = $createsettings->{'emailverified'};
8752: }
8753: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8754: $emaildomain = $createsettings->{'emaildomain'};
8755: }
1.160.6.34 raeburn 8756: }
8757: }
8758: }
8759: my %radiohash;
8760: my $numinrow = 4;
8761: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 8762: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 8763: if ($position eq 'top') {
8764: my %choices = &Apache::lonlocal::texthash (
8765: cancreate_login => 'Institutional Login',
8766: cancreate_sso => 'Institutional Single Sign On',
8767: );
8768: my @toggles = sort(keys(%choices));
8769: my %defaultchecked = (
8770: 'cancreate_login' => 'off',
8771: 'cancreate_sso' => 'off',
8772: );
1.160.6.35 raeburn 8773: my ($onclick,$itemcount);
1.160.6.34 raeburn 8774: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8775: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 8776: $$rowtotal += $itemcount;
1.160.6.34 raeburn 8777:
8778: if (ref($usertypes) eq 'HASH') {
8779: if (keys(%{$usertypes}) > 0) {
8780: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8781: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 8782: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 8783: $$rowtotal ++;
8784: }
8785: }
1.160.6.44 raeburn 8786: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8787: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8788: $fieldtitles{'inststatus'} = &mt('Institutional status');
8789: my $rem;
8790: my $numperrow = 2;
8791: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8792: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 8793: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 8794: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 8795: '<table>'."\n";
1.160.6.44 raeburn 8796: for (my $i=0; $i<@fields; $i++) {
8797: $rem = $i%($numperrow);
8798: if ($rem == 0) {
8799: if ($i > 0) {
8800: $datatable .= '</tr>';
8801: }
8802: $datatable .= '<tr>';
8803: }
8804: my $currval;
1.160.6.51 raeburn 8805: if (ref($createsettings) eq 'HASH') {
8806: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8807: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8808: }
1.160.6.44 raeburn 8809: }
8810: $datatable .= '<td class="LC_left_item">'.
8811: '<span class="LC_nobreak">'.
8812: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8813: 'value="'.$currval.'" size="10" /> '.
8814: $fieldtitles{$fields[$i]}.'</span></td>';
8815: }
8816: my $colsleft = $numperrow - $rem;
8817: if ($colsleft > 1 ) {
8818: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8819: ' </td>';
8820: } elsif ($colsleft == 1) {
8821: $datatable .= '<td class="LC_left_item"> </td>';
8822: }
8823: $datatable .= '</tr></table></td></tr>';
8824: $$rowtotal ++;
1.160.6.34 raeburn 8825: } elsif ($position eq 'middle') {
8826: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 8827: my @posstypes;
1.160.6.34 raeburn 8828: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8829: @posstypes = @{$types};
8830: }
8831: unless (grep(/^default$/,@posstypes)) {
8832: push(@posstypes,'default');
8833: }
8834: my %usertypeshash;
8835: if (ref($usertypes) eq 'HASH') {
8836: %usertypeshash = %{$usertypes};
8837: }
8838: $usertypeshash{'default'} = $othertitle;
8839: foreach my $status (@posstypes) {
8840: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8841: $numinrow,$$rowtotal,\%usertypeshash);
8842: $$rowtotal ++;
1.160.6.34 raeburn 8843: }
8844: } else {
1.160.6.40 raeburn 8845: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 8846: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 8847: );
8848: my @toggles = sort(keys(%choices));
8849: my %defaultchecked = (
8850: 'cancreate_email' => 'off',
8851: );
1.160.6.93 raeburn 8852: my $customclass = 'LC_selfcreate_email';
8853: my $classprefix = 'LC_canmodify_emailusername_';
8854: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 8855: my $display = 'none';
1.160.6.93 raeburn 8856: my $rowstyle = 'display:none';
1.160.6.40 raeburn 8857: if (grep(/^\Qemail\E$/,@selfcreate)) {
8858: $display = 'block';
1.160.6.93 raeburn 8859: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 8860: }
1.160.6.93 raeburn 8861: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8862: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8863: \%choices,$$rowtotal,$onclick);
8864: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8865: $rowstyle);
8866: $$rowtotal ++;
8867: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8868: $rowstyle);
8869: $$rowtotal ++;
8870: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 8871: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 8872: my ($emailrules,$emailruleorder) =
8873: &Apache::lonnet::inst_userrules($dom,'email');
8874: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8875: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8876: if (ref($types) eq 'ARRAY') {
8877: @posstypes = @{$types};
8878: }
8879: if (@posstypes) {
8880: unless (grep(/^default$/,@posstypes)) {
8881: push(@posstypes,'default');
1.160.6.89 raeburn 8882: }
8883: if (ref($usertypes) eq 'HASH') {
8884: %usertypeshash = %{$usertypes};
8885: }
1.160.6.93 raeburn 8886: my $currassign;
8887: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8888: $currassign = {
8889: selfassign => $domdefaults{'inststatusguest'},
8890: };
8891: @ordered = @{$domdefaults{'inststatusguest'}};
8892: } else {
8893: $currassign = { selfassign => [] };
8894: }
8895: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8896: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8897: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8898: $numinrow,$othertitle,'selfassign',
8899: $rowtotal,$onclicktypes,$customclass,
8900: $rowstyle);
8901: $$rowtotal ++;
1.160.6.89 raeburn 8902: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8903: foreach my $status (@posstypes) {
8904: my $css_class;
8905: if ($$rowtotal%2) {
8906: $css_class = 'LC_odd_row ';
8907: }
8908: $css_class .= $customclass;
8909: my $rowid = $optionsprefix.$status;
8910: my $hidden = 1;
8911: my $currstyle = 'display:none';
8912: if (grep(/^\Q$status\E$/,@ordered)) {
8913: $currstyle = $rowstyle;
8914: $hidden = 0;
8915: }
8916: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8917: $emailrules,$emailruleorder,$settings,$status,$rowid,
8918: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8919: unless ($hidden) {
8920: $$rowtotal ++;
8921: }
1.160.6.89 raeburn 8922: }
8923: } else {
1.160.6.93 raeburn 8924: my $css_class;
8925: if ($$rowtotal%2) {
8926: $css_class = 'LC_odd_row ';
8927: }
8928: $css_class .= $customclass;
1.160.6.89 raeburn 8929: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8930: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8931: $emailrules,$emailruleorder,$settings,'default','',
8932: $othertitle,$css_class,$rowstyle,$intdom);
8933: $$rowtotal ++;
1.160.6.34 raeburn 8934: }
1.160.6.35 raeburn 8935: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8936: $numinrow = 1;
1.160.6.93 raeburn 8937: if (@posstypes) {
8938: foreach my $status (@posstypes) {
8939: my $rowid = $classprefix.$status;
8940: my $datarowstyle = 'display:none';
8941: if (grep(/^\Q$status\E$/,@ordered)) {
8942: $datarowstyle = $rowstyle;
8943: }
8944: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8945: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8946: $infotitles,$rowid,$customclass,$datarowstyle);
8947: unless ($datarowstyle eq 'display:none') {
8948: $$rowtotal ++;
8949: }
1.160.6.34 raeburn 8950: }
1.160.6.93 raeburn 8951: } else {
8952: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8953: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8954: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 8955: }
8956: }
8957: return $datatable;
8958: }
8959:
1.160.6.93 raeburn 8960: sub selfcreate_javascript {
8961: return <<"ENDSCRIPT";
8962:
8963: <script type="text/javascript">
8964: // <![CDATA[
8965:
8966: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8967: var x = document.getElementsByClassName(target);
8968: var insttypes = 0;
8969: var insttypeRegExp = new RegExp(prefix);
8970: if ((x.length != undefined) && (x.length > 0)) {
8971: if (form.elements[radio].length != undefined) {
8972: for (var i=0; i<form.elements[radio].length; i++) {
8973: if (form.elements[radio][i].checked) {
8974: if (form.elements[radio][i].value == 1) {
8975: for (var j=0; j<x.length; j++) {
8976: if (x[j].id == 'undefined') {
8977: x[j].style.display = 'table-row';
8978: } else if (insttypeRegExp.test(x[j].id)) {
8979: insttypes ++;
8980: } else {
8981: x[j].style.display = 'table-row';
8982: }
8983: }
8984: } else {
8985: for (var j=0; j<x.length; j++) {
8986: x[j].style.display = 'none';
8987: }
1.160.6.40 raeburn 8988: }
1.160.6.93 raeburn 8989: break;
8990: }
8991: }
8992: if (insttypes > 0) {
8993: toggleDataRow(form,checkbox,target,altprefix);
8994: toggleDataRow(form,checkbox,target,prefix,1);
8995: }
8996: }
8997: }
8998: return;
8999: }
9000:
9001: function toggleDataRow(form,checkbox,target,prefix,docount) {
9002: if (form.elements[checkbox].length != undefined) {
9003: var count = 0;
9004: if (docount) {
9005: for (var i=0; i<form.elements[checkbox].length; i++) {
9006: if (form.elements[checkbox][i].checked) {
9007: count ++;
9008: }
9009: }
9010: }
9011: for (var i=0; i<form.elements[checkbox].length; i++) {
9012: var type = form.elements[checkbox][i].value;
9013: if (document.getElementById(prefix+type)) {
9014: if (form.elements[checkbox][i].checked) {
9015: document.getElementById(prefix+type).style.display = 'table-row';
9016: if (count % 2 == 1) {
9017: document.getElementById(prefix+type).className = target+' LC_odd_row';
9018: } else {
9019: document.getElementById(prefix+type).className = target;
9020: }
9021: count ++;
1.160.6.40 raeburn 9022: } else {
1.160.6.93 raeburn 9023: document.getElementById(prefix+type).style.display = 'none';
9024: }
9025: }
9026: }
9027: }
9028: return;
9029: }
9030:
9031: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9032: var caller = radio+'_'+status;
9033: if (form.elements[caller].length != undefined) {
9034: for (var i=0; i<form.elements[caller].length; i++) {
9035: if (form.elements[caller][i].checked) {
9036: if (document.getElementById(altprefix+'_inst_'+status)) {
9037: var curr = form.elements[caller][i].value;
9038: if (prefix) {
9039: document.getElementById(prefix+'_'+status).style.display = 'none';
9040: }
9041: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9042: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9043: if (curr == 'custom') {
9044: if (prefix) {
9045: document.getElementById(prefix+'_'+status).style.display = 'inline';
9046: }
9047: } else if (curr == 'inst') {
9048: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9049: } else if (curr == 'noninst') {
9050: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 9051: }
1.160.6.93 raeburn 9052: break;
1.160.6.40 raeburn 9053: }
1.160.6.93 raeburn 9054: }
9055: }
9056: }
9057: }
9058:
9059: // ]]>
9060: </script>
9061:
9062: ENDSCRIPT
9063: }
9064:
9065: sub noninst_users {
9066: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9067: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9068: my $class = 'LC_left_item';
9069: if ($css_class) {
9070: $css_class = ' class="'.$css_class.'"';
9071: }
9072: if ($rowid) {
9073: $rowid = ' id="'.$rowid.'"';
9074: }
9075: if ($rowstyle) {
9076: $rowstyle = ' style="'.$rowstyle.'"';
9077: }
9078: my ($output,$description);
9079: if ($type eq 'default') {
9080: $description = &mt('Requests for: [_1]',$typetitle);
9081: } else {
9082: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9083: }
9084: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9085: "<td>$description</td>\n".
9086: '<td class="'.$class.'" colspan="2">'.
9087: '<table><tr>';
9088: my %headers = &Apache::lonlocal::texthash(
9089: approve => 'Processing',
9090: email => 'E-mail',
9091: username => 'Username',
9092: );
9093: foreach my $item ('approve','email','username') {
9094: $output .= '<th>'.$headers{$item}.'</th>';
9095: }
9096: $output .= '</tr><tr>';
9097: foreach my $item ('approve','email','username') {
9098: $output .= '<td valign="top">';
9099: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9100: if ($item eq 'approve') {
9101: %choices = &Apache::lonlocal::texthash (
9102: automatic => 'Automatically approved',
9103: approval => 'Queued for approval',
9104: );
9105: @options = ('automatic','approval');
9106: $hashref = $processing;
9107: $defoption = 'automatic';
9108: $name = 'cancreate_emailprocess_'.$type;
9109: } elsif ($item eq 'email') {
9110: %choices = &Apache::lonlocal::texthash (
9111: any => 'Any e-mail',
9112: inst => 'Institutional only',
9113: noninst => 'Non-institutional only',
9114: custom => 'Custom restrictions',
9115: );
9116: @options = ('any','inst','noninst');
9117: my $showcustom;
9118: if (ref($emailrules) eq 'HASH') {
9119: if (keys(%{$emailrules}) > 0) {
9120: push(@options,'custom');
9121: $showcustom = 'cancreate_emailrule';
9122: if (ref($settings) eq 'HASH') {
9123: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9124: foreach my $rule (@{$settings->{'email_rule'}}) {
9125: if (exists($emailrules->{$rule})) {
9126: $hascustom ++;
9127: }
9128: }
9129: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9130: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9131: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9132: if (exists($emailrules->{$rule})) {
9133: $hascustom ++;
9134: }
9135: }
9136: }
9137: }
9138: }
9139: }
9140: }
9141: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9142: "'cancreate_emaildomain','$type'".');"';
9143: $hashref = $emailoptions;
9144: $defoption = 'any';
9145: $name = 'cancreate_emailoptions_'.$type;
9146: } elsif ($item eq 'username') {
9147: %choices = &Apache::lonlocal::texthash (
9148: all => 'Same as e-mail',
9149: first => 'Omit @domain',
9150: free => 'Free to choose',
9151: );
9152: @options = ('all','first','free');
9153: $hashref = $emailverified;
9154: $defoption = 'all';
9155: $name = 'cancreate_usernameoptions_'.$type;
9156: }
9157: foreach my $option (@options) {
9158: my $checked;
9159: if (ref($hashref) eq 'HASH') {
9160: if ($type eq '') {
9161: if (!exists($hashref->{'default'})) {
9162: if ($option eq $defoption) {
9163: $checked = ' checked="checked"';
9164: }
9165: } else {
9166: if ($hashref->{'default'} eq $option) {
9167: $checked = ' checked="checked"';
9168: }
1.160.6.40 raeburn 9169: }
9170: } else {
1.160.6.93 raeburn 9171: if (!exists($hashref->{$type})) {
9172: if ($option eq $defoption) {
9173: $checked = ' checked="checked"';
9174: }
9175: } else {
9176: if ($hashref->{$type} eq $option) {
9177: $checked = ' checked="checked"';
9178: }
1.160.6.40 raeburn 9179: }
9180: }
1.160.6.93 raeburn 9181: } elsif (($item eq 'email') && ($hascustom)) {
9182: if ($option eq 'custom') {
9183: $checked = ' checked="checked"';
9184: }
9185: } elsif ($option eq $defoption) {
9186: $checked = ' checked="checked"';
9187: }
9188: $output .= '<span class="LC_nobreak"><label>'.
9189: '<input type="radio" name="'.$name.'"'.
9190: $checked.' value="'.$option.'"'.$onclick.' />'.
9191: $choices{$option}.'</label></span><br />';
9192: if ($item eq 'email') {
9193: if ($option eq 'custom') {
9194: my $id = 'cancreate_emailrule_'.$type;
9195: my $display = 'none';
9196: if ($checked) {
9197: $display = 'inline';
9198: }
9199: my $numinrow = 2;
9200: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9201: '<legend>'.&mt('Disallow').'</legend><table>'.
9202: &user_formats_row('email',$settings,$emailrules,
9203: $emailruleorder,$numinrow,'',$type);
9204: '</table></fieldset>';
9205: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9206: my %text = &Apache::lonlocal::texthash (
9207: inst => 'must end:',
9208: noninst => 'cannot end:',
9209: );
9210: my $value;
9211: if (ref($emaildomain) eq 'HASH') {
9212: if (ref($emaildomain->{$type}) eq 'HASH') {
9213: $value = $emaildomain->{$type}->{$option};
9214: }
9215: }
9216: if ($value eq '') {
9217: $value = '@'.$intdom;
9218: }
9219: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9220: my $display = 'none';
9221: if ($checked) {
9222: $display = 'inline';
9223: }
9224: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9225: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9226: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9227: '</div>';
9228: }
1.160.6.40 raeburn 9229: }
9230: }
1.160.6.93 raeburn 9231: $output .= '</td>'."\n";
1.160.6.40 raeburn 9232: }
1.160.6.93 raeburn 9233: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 9234: return $output;
9235: }
9236:
1.160.6.5 raeburn 9237: sub captcha_choice {
1.160.6.93 raeburn 9238: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 9239: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
1.160.6.118.2 14(raebu 9240:23): $vertext,$currver);
1.160.6.5 raeburn 9241: my %lt = &captcha_phrases();
9242: $keyentry = 'hidden';
1.160.6.98 raeburn 9243: my $colspan=2;
1.160.6.5 raeburn 9244: if ($context eq 'cancreate') {
1.160.6.34 raeburn 9245: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 9246: } elsif ($context eq 'login') {
9247: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 9248: } elsif ($context eq 'passwords') {
9249: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9250: $colspan=1;
1.160.6.5 raeburn 9251: }
9252: if (ref($settings) eq 'HASH') {
9253: if ($settings->{'captcha'}) {
9254: $checked{$settings->{'captcha'}} = ' checked="checked"';
9255: } else {
9256: $checked{'original'} = ' checked="checked"';
9257: }
9258: if ($settings->{'captcha'} eq 'recaptcha') {
9259: $pubtext = $lt{'pub'};
9260: $privtext = $lt{'priv'};
9261: $keyentry = 'text';
1.160.6.69 raeburn 9262: $vertext = $lt{'ver'};
9263: $currver = $settings->{'recaptchaversion'};
9264: if ($currver ne '2') {
9265: $currver = 1;
9266: }
1.160.6.5 raeburn 9267: }
9268: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9269: $currpub = $settings->{'recaptchakeys'}{'public'};
9270: $currpriv = $settings->{'recaptchakeys'}{'private'};
9271: }
9272: } else {
9273: $checked{'original'} = ' checked="checked"';
9274: }
1.160.6.93 raeburn 9275: my $css_class;
9276: if ($itemcount%2) {
9277: $css_class = 'LC_odd_row';
9278: }
9279: if ($customcss) {
9280: $css_class .= " $customcss";
9281: }
9282: $css_class =~ s/^\s+//;
9283: if ($css_class) {
9284: $css_class = ' class="'.$css_class.'"';
9285: }
9286: if ($rowstyle) {
9287: $css_class .= ' style="'.$rowstyle.'"';
9288: }
1.160.6.5 raeburn 9289: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 9290: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 9291: '<table><tr><td>'."\n";
9292: foreach my $option ('original','recaptcha','notused') {
9293: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9294: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9295: $lt{$option}.'</label></span>';
9296: unless ($option eq 'notused') {
9297: $output .= (' 'x2)."\n";
9298: }
9299: }
9300: #
9301: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9302: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
9303: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
9304: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
9305: #
9306: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 9307: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 9308: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9309: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9310: $currpub.'" size="40" /></span><br />'."\n".
9311: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9312: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 9313: $currpriv.'" size="40" /></span><br />'.
9314: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9315: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9316: $currver.'" size="3" /></span><br />'.
9317: '</td></tr></table>'."\n".
1.160.6.5 raeburn 9318: '</td></tr>';
9319: return $output;
9320: }
9321:
1.32 raeburn 9322: sub user_formats_row {
1.160.6.93 raeburn 9323: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9324: my $output;
9325: my %text = (
9326: 'username' => 'new usernames',
9327: 'id' => 'IDs',
9328: );
1.160.6.118.2 8(raebur 9329:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 9330: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9331: $output = '<tr '.$css_class.'>'.
9332: '<td><span class="LC_nobreak">'.
9333: &mt("Format rules to check for $text{$type}: ").
9334: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9335: }
1.27 raeburn 9336: my $rem;
9337: if (ref($ruleorder) eq 'ARRAY') {
9338: for (my $i=0; $i<@{$ruleorder}; $i++) {
9339: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9340: my $rem = $i%($numinrow);
9341: if ($rem == 0) {
9342: if ($i > 0) {
9343: $output .= '</tr>';
9344: }
9345: $output .= '<tr>';
9346: }
9347: my $check = ' ';
1.39 raeburn 9348: if (ref($settings) eq 'HASH') {
9349: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9350: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9351: $check = ' checked="checked" ';
9352: }
1.160.6.93 raeburn 9353: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9354: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9355: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9356: $check = ' checked="checked" ';
9357: }
9358: }
1.27 raeburn 9359: }
9360: }
1.160.6.93 raeburn 9361: my $name = $type.'_rule';
9362: if ($type eq 'email') {
9363: $name .= '_'.$status;
9364: }
1.27 raeburn 9365: $output .= '<td class="LC_left_item">'.
9366: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 9367: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9368: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9369: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9370: }
9371: }
9372: $rem = @{$ruleorder}%($numinrow);
9373: }
1.160.6.93 raeburn 9374: my $colsleft;
9375: if ($rem) {
9376: $colsleft = $numinrow - $rem;
9377: }
1.27 raeburn 9378: if ($colsleft > 1 ) {
9379: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9380: ' </td>';
9381: } elsif ($colsleft == 1) {
9382: $output .= '<td class="LC_left_item"> </td>';
9383: }
1.160.6.118.2 8(raebur 9384:2): $output .= '</tr>';
9385:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
9386:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 9387: }
1.27 raeburn 9388: return $output;
9389: }
9390:
1.34 raeburn 9391: sub usercreation_types {
9392: my %lt = &Apache::lonlocal::texthash (
9393: author => 'When adding a co-author',
9394: course => 'When adding a user to a course',
1.100 raeburn 9395: requestcrs => 'When requesting a course',
1.34 raeburn 9396: any => 'Any',
9397: official => 'Institutional only ',
9398: unofficial => 'Non-institutional only',
9399: none => 'None',
9400: );
9401: return %lt;
1.48 raeburn 9402: }
1.34 raeburn 9403:
1.160.6.34 raeburn 9404: sub selfcreation_types {
9405: my %lt = &Apache::lonlocal::texthash (
9406: selfcreate => 'User creates own account',
9407: any => 'Any',
9408: official => 'Institutional only ',
9409: unofficial => 'Non-institutional only',
9410: email => 'E-mail address',
9411: login => 'Institutional Login',
9412: sso => 'SSO',
9413: );
9414: }
9415:
1.28 raeburn 9416: sub authtype_names {
9417: my %lt = &Apache::lonlocal::texthash(
9418: int => 'Internal',
9419: krb4 => 'Kerberos 4',
9420: krb5 => 'Kerberos 5',
9421: loc => 'Local',
1.160.6.118.2 14(raebu 9422:23): lti => 'LTI',
1.28 raeburn 9423: );
9424: return %lt;
9425: }
9426:
9427: sub context_names {
9428: my %context_title = &Apache::lonlocal::texthash(
9429: author => 'Creating users when an Author',
9430: course => 'Creating users when in a course',
9431: domain => 'Creating users when a Domain Coordinator',
9432: );
9433: return %context_title;
9434: }
9435:
1.33 raeburn 9436: sub print_usermodification {
9437: my ($position,$dom,$settings,$rowtotal) = @_;
9438: my $numinrow = 4;
9439: my ($context,$datatable,$rowcount);
9440: if ($position eq 'top') {
9441: $rowcount = 0;
9442: $context = 'author';
9443: foreach my $role ('ca','aa') {
9444: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9445: $numinrow,$rowcount);
9446: $$rowtotal ++;
9447: $rowcount ++;
9448: }
1.160.6.37 raeburn 9449: } elsif ($position eq 'bottom') {
1.33 raeburn 9450: $context = 'course';
9451: $rowcount = 0;
9452: foreach my $role ('st','ep','ta','in','cr') {
9453: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9454: $numinrow,$rowcount);
9455: $$rowtotal ++;
9456: $rowcount ++;
9457: }
9458: }
9459: return $datatable;
9460: }
9461:
1.43 raeburn 9462: sub print_defaults {
1.160.6.40 raeburn 9463: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9464: my $rownum = 0;
1.160.6.80 raeburn 9465: my ($datatable,$css_class,$titles);
9466: unless ($position eq 'bottom') {
9467: $titles = &defaults_titles($dom);
9468: }
1.160.6.40 raeburn 9469: if ($position eq 'top') {
9470: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9471: 'datelocale_def','portal_def');
9472: my %defaults;
9473: if (ref($settings) eq 'HASH') {
9474: %defaults = %{$settings};
1.43 raeburn 9475: } else {
1.160.6.40 raeburn 9476: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9477: foreach my $item (@items) {
9478: $defaults{$item} = $domdefaults{$item};
9479: }
1.43 raeburn 9480: }
1.160.6.40 raeburn 9481: foreach my $item (@items) {
9482: if ($rownum%2) {
9483: $css_class = '';
9484: } else {
9485: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 9486: }
1.160.6.40 raeburn 9487: $datatable .= '<tr'.$css_class.'>'.
9488: '<td><span class="LC_nobreak">'.$titles->{$item}.
9489: '</span></td><td class="LC_right_item" colspan="3">';
9490: if ($item eq 'auth_def') {
1.160.6.118.2 14(raebu 9491:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.160.6.40 raeburn 9492: my %shortauth = (
9493: internal => 'int',
9494: krb4 => 'krb4',
9495: krb5 => 'krb5',
1.160.6.118.2 14(raebu 9496:23): localauth => 'loc',
9497:23): lti => 'lti',
1.160.6.40 raeburn 9498: );
9499: my %authnames = &authtype_names();
9500: foreach my $auth (@authtypes) {
9501: my $checked = ' ';
9502: if ($defaults{$item} eq $auth) {
9503: $checked = ' checked="checked" ';
9504: }
9505: $datatable .= '<label><input type="radio" name="'.$item.
9506: '" value="'.$auth.'"'.$checked.'/>'.
9507: $authnames{$shortauth{$auth}}.'</label> ';
9508: }
9509: } elsif ($item eq 'timezone_def') {
9510: my $includeempty = 1;
9511: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9512: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 9513: my $includeempty = 1;
9514: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9515: } elsif ($item eq 'lang_def') {
9516: my $includeempty = 1;
9517: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 9518:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 9519: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 9520:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9521:23): my $portalsty = 'none';
9522:23): if ($defaults{$item}) {
9523:23): $portalsty = 'block';
9524:23): }
9525:23): foreach my $field ('email','web') {
9526:23): my $checkedoff = ' checked="checked"';
9527:23): my $checkedon;
9528:23): if ($defaults{$item.'_'.$field}) {
9529:23): $checkedon = $checkedoff;
9530:23): $checkedoff = '';
9531:23): }
9532:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9533:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
9534:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9535:23): (' 'x2).
9536:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9537:23): '</div>';
9538:23): }
9539:23): } else {
9540:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 9541: }
9542: $datatable .= '</td></tr>';
9543: $rownum ++;
9544: }
1.160.6.118.2 8(raebur 9545:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 9546: my %defaults;
1.160.6.40 raeburn 9547: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 9548: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 9549: my $maxnum = @{$settings->{'inststatusorder'}};
9550: for (my $i=0; $i<$maxnum; $i++) {
9551: $css_class = $rownum%2?' class="LC_odd_row"':'';
9552: my $item = $settings->{'inststatusorder'}->[$i];
9553: my $title = $settings->{'inststatustypes'}->{$item};
9554: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9555: $datatable .= '<tr'.$css_class.'>'.
9556: '<td><span class="LC_nobreak">'.
9557: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9558: for (my $k=0; $k<=$maxnum; $k++) {
9559: my $vpos = $k+1;
9560: my $selstr;
9561: if ($k == $i) {
9562: $selstr = ' selected="selected" ';
9563: }
9564: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9565: }
9566: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9567: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9568: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 9569: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 9570: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 9571: '</span></td></tr>';
1.160.6.40 raeburn 9572: }
9573: $css_class = $rownum%2?' class="LC_odd_row"':'';
9574: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9575: $datatable .= '<tr '.$css_class.'>'.
9576: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9577: for (my $k=0; $k<=$maxnum; $k++) {
9578: my $vpos = $k+1;
9579: my $selstr;
9580: if ($k == $maxnum) {
9581: $selstr = ' selected="selected" ';
9582: }
9583: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9584: }
9585: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 9586: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 9587: ' '.&mt('(new)').
9588: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 9589: &mt('Name displayed').':'.
1.160.6.40 raeburn 9590: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9591: '</tr>'."\n";
9592: $rownum ++;
1.141 raeburn 9593: }
1.43 raeburn 9594: }
1.160.6.118.2 8(raebur 9595:2): } else {
9596:2): my ($unamemaprules,$ruleorder) =
9597:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
9598:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
9599:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9600:2): my $numinrow = 2;
9601:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9602:2): &user_formats_row('unamemap',$settings,$unamemaprules,
9603:2): $ruleorder,$numinrow).
9604:2): '</table></td></tr>';
9605:2): }
9606:2): if ($datatable eq '') {
9607:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9608:2): &mt('No rules set for domain in customized localenroll.pm').
9609:2): '</td></tr>';
9610:2): }
1.43 raeburn 9611: }
9612: $$rowtotal += $rownum;
9613: return $datatable;
9614: }
9615:
1.160.6.5 raeburn 9616: sub get_languages_hash {
9617: my %langchoices;
9618: foreach my $id (&Apache::loncommon::languageids()) {
9619: my $code = &Apache::loncommon::supportedlanguagecode($id);
9620: if ($code ne '') {
9621: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9622: }
9623: }
9624: return %langchoices;
9625: }
9626:
1.43 raeburn 9627: sub defaults_titles {
1.141 raeburn 9628: my ($dom) = @_;
1.43 raeburn 9629: my %titles = &Apache::lonlocal::texthash (
9630: 'auth_def' => 'Default authentication type',
9631: 'auth_arg_def' => 'Default authentication argument',
9632: 'lang_def' => 'Default language',
1.54 raeburn 9633: 'timezone_def' => 'Default timezone',
1.68 raeburn 9634: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9635: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 9636:23): 'email' => 'Email links use portal URL',
9637:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 9638: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9639: 'intauth_check' => 'Check bcrypt cost if authenticated',
9640: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9641: );
1.141 raeburn 9642: if ($dom) {
9643: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9644: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9645: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9646: $protocol = 'http' if ($protocol ne 'https');
9647: if ($uint_dom) {
9648: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9649: $uint_dom);
9650: }
9651: }
1.43 raeburn 9652: return (\%titles);
9653: }
9654:
1.160.6.97 raeburn 9655: sub print_scantron {
9656: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9657: if ($position eq 'top') {
9658: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9659: } else {
9660: return &print_scantronconfig($dom,$settings,\$rowtotal);
9661: }
9662: }
9663:
9664: sub scantron_javascript {
9665: return <<"ENDSCRIPT";
9666:
9667: <script type="text/javascript">
9668: // <![CDATA[
9669:
9670: function toggleScantron(form) {
9671: var csvfieldset = new Array();
9672: if (document.getElementById('scantroncsv_cols')) {
9673: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9674: }
9675: if (document.getElementById('scantroncsv_options')) {
9676: csvfieldset.push(document.getElementById('scantroncsv_options'));
9677: }
9678: if (csvfieldset.length) {
9679: if (document.getElementById('scantronconfcsv')) {
9680: var scantroncsv = document.getElementById('scantronconfcsv');
9681: if (scantroncsv.checked) {
9682: for (var i=0; i<csvfieldset.length; i++) {
9683: csvfieldset[i].style.display = 'block';
9684: }
9685: } else {
9686: for (var i=0; i<csvfieldset.length; i++) {
9687: csvfieldset[i].style.display = 'none';
9688: }
9689: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9690: if (csvselects.length) {
9691: for (var j=0; j<csvselects.length; j++) {
9692: csvselects[j].selectedIndex = 0;
9693: }
9694: }
9695: }
9696: }
9697: }
9698: return;
9699: }
9700: // ]]>
9701: </script>
9702:
9703: ENDSCRIPT
9704:
9705: }
9706:
1.46 raeburn 9707: sub print_scantronformat {
9708: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9709: my $itemcount = 1;
1.60 raeburn 9710: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9711: %confhash);
1.46 raeburn 9712: my $switchserver = &check_switchserver($dom,$confname);
9713: my %lt = &Apache::lonlocal::texthash (
1.95 www 9714: default => 'Default bubblesheet format file error',
9715: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9716: );
9717: my %scantronfiles = (
9718: default => 'default.tab',
9719: custom => 'custom.tab',
9720: );
9721: foreach my $key (keys(%scantronfiles)) {
9722: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9723: .$scantronfiles{$key};
9724: }
9725: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9726: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9727: if (!$switchserver) {
9728: my $servadm = $r->dir_config('lonAdmEMail');
9729: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9730: if ($configuserok eq 'ok') {
9731: if ($author_ok eq 'ok') {
9732: my %legacyfile = (
1.160.6.97 raeburn 9733: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9734: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9735: );
9736: my %md5chk;
9737: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9738: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9739: chomp($md5chk{$type});
1.46 raeburn 9740: }
9741: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9742: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 9743: ($scantronurls{$type},my $error) =
1.46 raeburn 9744: &legacy_scantronformat($r,$dom,$confname,
9745: $type,$legacyfile{$type},
9746: $scantronurls{$type},
9747: $scantronfiles{$type});
1.60 raeburn 9748: if ($error ne '') {
9749: $error{$type} = $error;
9750: }
9751: }
9752: if (keys(%error) == 0) {
9753: $is_custom = 1;
1.160.6.97 raeburn 9754: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9755: $scantronurls{'custom'};
1.160.6.97 raeburn 9756: my $putresult =
1.60 raeburn 9757: &Apache::lonnet::put_dom('configuration',
9758: \%confhash,$dom);
9759: if ($putresult ne 'ok') {
1.160.6.97 raeburn 9760: $error{'custom'} =
1.60 raeburn 9761: '<span class="LC_error">'.
9762: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9763: }
1.46 raeburn 9764: }
9765: } else {
1.60 raeburn 9766: ($scantronurls{'default'},my $error) =
1.46 raeburn 9767: &legacy_scantronformat($r,$dom,$confname,
9768: 'default',$legacyfile{'default'},
9769: $scantronurls{'default'},
9770: $scantronfiles{'default'});
1.60 raeburn 9771: if ($error eq '') {
9772: $confhash{'scantron'}{'scantronformat'} = '';
9773: my $putresult =
9774: &Apache::lonnet::put_dom('configuration',
9775: \%confhash,$dom);
9776: if ($putresult ne 'ok') {
9777: $error{'default'} =
9778: '<span class="LC_error">'.
9779: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9780: }
9781: } else {
9782: $error{'default'} = $error;
9783: }
1.46 raeburn 9784: }
9785: }
9786: }
9787: } else {
1.95 www 9788: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9789: }
9790: }
9791: if (ref($settings) eq 'HASH') {
9792: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9793: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9794: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9795: $scantronurl = '';
9796: } else {
9797: $scantronurl = $settings->{'scantronformat'};
9798: }
9799: $is_custom = 1;
9800: } else {
9801: $scantronurl = $scantronurls{'default'};
9802: }
9803: } else {
1.60 raeburn 9804: if ($is_custom) {
9805: $scantronurl = $scantronurls{'custom'};
9806: } else {
9807: $scantronurl = $scantronurls{'default'};
9808: }
1.46 raeburn 9809: }
9810: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9811: $datatable .= '<tr'.$css_class.'>';
9812: if (!$is_custom) {
1.65 raeburn 9813: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9814: '<span class="LC_nobreak">';
1.46 raeburn 9815: if ($scantronurl) {
1.160.6.21 raeburn 9816: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9817: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9818: } else {
9819: $datatable = &mt('File unavailable for display');
9820: }
1.65 raeburn 9821: $datatable .= '</span></td>';
1.60 raeburn 9822: if (keys(%error) == 0) {
9823: $datatable .= '<td valign="bottom">';
9824: if (!$switchserver) {
9825: $datatable .= &mt('Upload:').'<br />';
9826: }
9827: } else {
9828: my $errorstr;
9829: foreach my $key (sort(keys(%error))) {
9830: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9831: }
9832: $datatable .= '<td>'.$errorstr;
9833: }
1.46 raeburn 9834: } else {
9835: if (keys(%error) > 0) {
9836: my $errorstr;
9837: foreach my $key (sort(keys(%error))) {
9838: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9839: }
1.60 raeburn 9840: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9841: } elsif ($scantronurl) {
1.160.6.26 raeburn 9842: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 9843: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9844: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 9845: $link.
9846: '<label><input type="checkbox" name="scantronformat_del"'.
9847: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9848: '<td><span class="LC_nobreak"> '.
9849: &mt('Replace:').'</span><br />';
1.46 raeburn 9850: }
9851: }
9852: if (keys(%error) == 0) {
9853: if ($switchserver) {
9854: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9855: } else {
1.65 raeburn 9856: $datatable .='<span class="LC_nobreak"> '.
9857: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9858: }
9859: }
9860: $datatable .= '</td></tr>';
9861: $$rowtotal ++;
9862: return $datatable;
9863: }
9864:
9865: sub legacy_scantronformat {
9866: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9867: my ($url,$error);
9868: my @statinfo = &Apache::lonnet::stat_file($newurl);
9869: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.160.6.118.2 14(raebu 9870:23): my $modified = [];
1.46 raeburn 9871: (my $result,$url) =
1.160.6.118.2 14(raebu 9872:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9873:23): 'scantron','','',$newfile,$modified);
9874:23): if ($result eq 'ok') {
9875:23): &update_modify_urls($r,$modified);
9876:23): } else {
1.130 raeburn 9877: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9878: }
9879: }
9880: return ($url,$error);
9881: }
1.43 raeburn 9882:
1.160.6.97 raeburn 9883: sub print_scantronconfig {
9884: my ($dom,$settings,$rowtotal) = @_;
9885: my $itemcount = 2;
9886: my $is_checked = ' checked="checked"';
9887: my %optionson = (
9888: hdr => ' checked="checked"',
9889: pad => ' checked="checked"',
9890: rem => ' checked="checked"',
9891: );
9892: my %optionsoff = (
9893: hdr => '',
9894: pad => '',
9895: rem => '',
9896: );
9897: my $currcsvsty = 'none';
9898: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9899: my @fields = &scantroncsv_fields();
9900: my %titles = &scantronconfig_titles();
9901: if (ref($settings) eq 'HASH') {
9902: if (ref($settings->{config}) eq 'HASH') {
9903: if ($settings->{config}->{dat}) {
9904: $checked{'dat'} = $is_checked;
9905: }
9906: if (ref($settings->{config}->{csv}) eq 'HASH') {
9907: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9908: %csvfields = %{$settings->{config}->{csv}->{fields}};
9909: if (keys(%csvfields) > 0) {
9910: $checked{'csv'} = $is_checked;
9911: $currcsvsty = 'block';
9912: }
9913: }
9914: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9915: %csvoptions = %{$settings->{config}->{csv}->{options}};
9916: foreach my $option (keys(%optionson)) {
9917: unless ($csvoptions{$option}) {
9918: $optionsoff{$option} = $optionson{$option};
9919: $optionson{$option} = '';
9920: }
9921: }
9922: }
9923: }
9924: } else {
9925: $checked{'dat'} = $is_checked;
9926: }
9927: } else {
9928: $checked{'dat'} = $is_checked;
9929: }
9930: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9931: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9932: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9933: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9934: foreach my $item ('dat','csv') {
9935: my $id;
9936: if ($item eq 'csv') {
9937: $id = 'id="scantronconfcsv" ';
9938: }
9939: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9940: $titles{$item}.'</label>'.(' 'x3);
9941: if ($item eq 'csv') {
9942: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9943: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9944: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9945: foreach my $col (@fields) {
9946: my $selnone;
9947: if ($csvfields{$col} eq '') {
9948: $selnone = ' selected="selected"';
9949: }
9950: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9951: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9952: '<option value=""'.$selnone.'></option>';
9953: for (my $i=0; $i<20; $i++) {
9954: my $shown = $i+1;
9955: my $sel;
9956: unless ($selnone) {
9957: if (exists($csvfields{$col})) {
9958: if ($csvfields{$col} == $i) {
9959: $sel = ' selected="selected"';
9960: }
9961: }
9962: }
9963: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9964: }
9965: $datatable .= '</select></td></tr>';
9966: }
9967: $datatable .= '</table></fieldset>'.
9968: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9969: '<legend>'.&mt('CSV Options').'</legend>';
9970: foreach my $option ('hdr','pad','rem') {
9971: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9972: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9973: &mt('Yes').'</label>'.(' 'x2)."\n".
9974: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9975: }
9976: $datatable .= '</fieldset>';
9977: $itemcount ++;
9978: }
9979: }
9980: $datatable .= '</td></tr>';
9981: $$rowtotal ++;
9982: return $datatable;
9983: }
9984:
9985: sub scantronconfig_titles {
9986: return &Apache::lonlocal::texthash(
9987: dat => 'Standard format (.dat)',
9988: csv => 'Comma separated values (.csv)',
9989: hdr => 'Remove first line in file (contains column titles)',
9990: pad => 'Prepend 0s to PaperID',
9991: rem => 'Remove leading spaces (except Question Response columns)',
9992: CODE => 'CODE',
9993: ID => 'Student ID',
9994: PaperID => 'Paper ID',
9995: FirstName => 'First Name',
9996: LastName => 'Last Name',
9997: FirstQuestion => 'First Question Response',
9998: Section => 'Section',
9999: );
10000: }
10001:
10002: sub scantroncsv_fields {
10003: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10004: }
10005:
1.49 raeburn 10006: sub print_coursecategories {
1.57 raeburn 10007: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10008: my $datatable;
10009: if ($position eq 'top') {
1.160.6.42 raeburn 10010: my (%checked);
10011: my @catitems = ('unauth','auth');
10012: my @cattypes = ('std','domonly','codesrch','none');
10013: $checked{'unauth'} = 'std';
10014: $checked{'auth'} = 'std';
10015: if (ref($settings) eq 'HASH') {
10016: foreach my $type (@cattypes) {
10017: if ($type eq $settings->{'unauth'}) {
10018: $checked{'unauth'} = $type;
10019: }
10020: if ($type eq $settings->{'auth'}) {
10021: $checked{'auth'} = $type;
10022: }
10023: }
10024: }
10025: my %lt = &Apache::lonlocal::texthash (
10026: unauth => 'Catalog type for unauthenticated users',
10027: auth => 'Catalog type for authenticated users',
10028: none => 'No catalog',
10029: std => 'Standard catalog',
10030: domonly => 'Domain-only catalog',
10031: codesrch => "Code search form",
10032: );
10033: my $itemcount = 0;
10034: foreach my $item (@catitems) {
10035: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10036: $datatable .= '<tr '.$css_class.'>'.
10037: '<td>'.$lt{$item}.'</td>'.
10038: '<td class="LC_right_item"><span class="LC_nobreak">';
10039: foreach my $type (@cattypes) {
10040: my $ischecked;
10041: if ($checked{$item} eq $type) {
10042: $ischecked=' checked="checked"';
10043: }
10044: $datatable .= '<label>'.
10045: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10046: ' />'.$lt{$type}.'</label> ';
10047: }
1.160.6.87 raeburn 10048: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 10049: $itemcount ++;
10050: }
10051: $$rowtotal += $itemcount;
10052: } elsif ($position eq 'middle') {
1.57 raeburn 10053: my $toggle_cats_crs = ' ';
10054: my $toggle_cats_dom = ' checked="checked" ';
10055: my $can_cat_crs = ' ';
10056: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10057: my $toggle_catscomm_comm = ' ';
10058: my $toggle_catscomm_dom = ' checked="checked" ';
10059: my $can_catcomm_comm = ' ';
10060: my $can_catcomm_dom = ' checked="checked" ';
10061:
1.57 raeburn 10062: if (ref($settings) eq 'HASH') {
10063: if ($settings->{'togglecats'} eq 'crs') {
10064: $toggle_cats_crs = $toggle_cats_dom;
10065: $toggle_cats_dom = ' ';
10066: }
10067: if ($settings->{'categorize'} eq 'crs') {
10068: $can_cat_crs = $can_cat_dom;
10069: $can_cat_dom = ' ';
10070: }
1.120 raeburn 10071: if ($settings->{'togglecatscomm'} eq 'comm') {
10072: $toggle_catscomm_comm = $toggle_catscomm_dom;
10073: $toggle_catscomm_dom = ' ';
10074: }
10075: if ($settings->{'categorizecomm'} eq 'comm') {
10076: $can_catcomm_comm = $can_catcomm_dom;
10077: $can_catcomm_dom = ' ';
10078: }
1.57 raeburn 10079: }
10080: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 10081: togglecats => 'Show/Hide a course in catalog',
10082: togglecatscomm => 'Show/Hide a community in catalog',
10083: categorize => 'Assign a category to a course',
10084: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10085: );
10086: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 10087: dom => 'Set in Domain',
10088: crs => 'Set in Course',
10089: comm => 'Set in Community',
1.57 raeburn 10090: );
10091: $datatable = '<tr class="LC_odd_row">'.
10092: '<td>'.$title{'togglecats'}.'</td>'.
10093: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10094: '<input type="radio" name="togglecats"'.
10095: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10096: '<label><input type="radio" name="togglecats"'.
10097: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10098: '</tr><tr>'.
10099: '<td>'.$title{'categorize'}.'</td>'.
10100: '<td class="LC_right_item"><span class="LC_nobreak">'.
10101: '<label><input type="radio" name="categorize"'.
10102: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10103: '<label><input type="radio" name="categorize"'.
10104: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10105: '</tr><tr class="LC_odd_row">'.
10106: '<td>'.$title{'togglecatscomm'}.'</td>'.
10107: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10108: '<input type="radio" name="togglecatscomm"'.
10109: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10110: '<label><input type="radio" name="togglecatscomm"'.
10111: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10112: '</tr><tr>'.
10113: '<td>'.$title{'categorizecomm'}.'</td>'.
10114: '<td class="LC_right_item"><span class="LC_nobreak">'.
10115: '<label><input type="radio" name="categorizecomm"'.
10116: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10117: '<label><input type="radio" name="categorizecomm"'.
10118: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 10119: '</tr>';
1.120 raeburn 10120: $$rowtotal += 4;
1.57 raeburn 10121: } else {
10122: my $css_class;
10123: my $itemcount = 1;
10124: my $cathash;
10125: if (ref($settings) eq 'HASH') {
10126: $cathash = $settings->{'cats'};
10127: }
10128: if (ref($cathash) eq 'HASH') {
10129: my (@cats,@trails,%allitems,%idx,@jsarray);
10130: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10131: \%allitems,\%idx,\@jsarray);
10132: my $maxdepth = scalar(@cats);
10133: my $colattrib = '';
10134: if ($maxdepth > 2) {
10135: $colattrib = ' colspan="2" ';
10136: }
10137: my @path;
10138: if (@cats > 0) {
10139: if (ref($cats[0]) eq 'ARRAY') {
10140: my $numtop = @{$cats[0]};
10141: my $maxnum = $numtop;
1.120 raeburn 10142: my %default_names = (
10143: instcode => &mt('Official courses'),
10144: communities => &mt('Communities'),
10145: );
10146:
10147: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10148: ($cathash->{'instcode::0'} eq '') ||
10149: (!grep(/^communities$/,@{$cats[0]})) ||
10150: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 10151: $maxnum ++;
10152: }
10153: my $lastidx;
10154: for (my $i=0; $i<$numtop; $i++) {
10155: my $parent = $cats[0][$i];
10156: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10157: my $item = &escape($parent).'::0';
10158: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10159: $lastidx = $idx{$item};
10160: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10161: .'<select name="'.$item.'"'.$chgstr.'>';
10162: for (my $k=0; $k<=$maxnum; $k++) {
10163: my $vpos = $k+1;
10164: my $selstr;
10165: if ($k == $i) {
10166: $selstr = ' selected="selected" ';
10167: }
10168: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10169: }
1.160.6.29 raeburn 10170: $datatable .= '</select></span></td><td>';
1.120 raeburn 10171: if ($parent eq 'instcode' || $parent eq 'communities') {
10172: $datatable .= '<span class="LC_nobreak">'
10173: .$default_names{$parent}.'</span>';
10174: if ($parent eq 'instcode') {
10175: $datatable .= '<br /><span class="LC_nobreak">('
10176: .&mt('with institutional codes')
10177: .')</span></td><td'.$colattrib.'>';
10178: } else {
10179: $datatable .= '<table><tr><td>';
10180: }
10181: $datatable .= '<span class="LC_nobreak">'
10182: .'<label><input type="radio" name="'
10183: .$parent.'" value="1" checked="checked" />'
10184: .&mt('Display').'</label>';
10185: if ($parent eq 'instcode') {
10186: $datatable .= ' ';
10187: } else {
10188: $datatable .= '</span></td></tr><tr><td>'
10189: .'<span class="LC_nobreak">';
10190: }
10191: $datatable .= '<label><input type="radio" name="'
10192: .$parent.'" value="0" />'
10193: .&mt('Do not display').'</label></span>';
10194: if ($parent eq 'communities') {
10195: $datatable .= '</td></tr></table>';
10196: }
10197: $datatable .= '</td>';
1.57 raeburn 10198: } else {
10199: $datatable .= $parent
1.160.6.29 raeburn 10200: .' <span class="LC_nobreak"><label>'
10201: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10202: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10203: }
10204: my $depth = 1;
10205: push(@path,$parent);
10206: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10207: pop(@path);
10208: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10209: $itemcount ++;
10210: }
1.48 raeburn 10211: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10212: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10213: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10214: for (my $k=0; $k<=$maxnum; $k++) {
10215: my $vpos = $k+1;
10216: my $selstr;
1.57 raeburn 10217: if ($k == $numtop) {
1.48 raeburn 10218: $selstr = ' selected="selected" ';
10219: }
10220: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10221: }
1.59 bisitz 10222: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10223: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10224: .'</tr>'."\n";
1.48 raeburn 10225: $itemcount ++;
1.120 raeburn 10226: foreach my $default ('instcode','communities') {
10227: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10228: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10229: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10230: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10231: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10232: for (my $k=0; $k<=$maxnum; $k++) {
10233: my $vpos = $k+1;
10234: my $selstr;
10235: if ($k == $maxnum) {
10236: $selstr = ' selected="selected" ';
10237: }
10238: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10239: }
1.120 raeburn 10240: $datatable .= '</select></span></td>'.
10241: '<td><span class="LC_nobreak">'.
10242: $default_names{$default}.'</span>';
10243: if ($default eq 'instcode') {
10244: $datatable .= '<br /><span class="LC_nobreak">('
10245: .&mt('with institutional codes').')</span>';
10246: }
10247: $datatable .= '</td>'
10248: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10249: .&mt('Display').'</label> '
10250: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10251: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10252: }
10253: }
10254: }
1.57 raeburn 10255: } else {
10256: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10257: }
10258: } else {
1.160.6.87 raeburn 10259: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10260: .&initialize_categories($itemcount);
1.48 raeburn 10261: }
1.57 raeburn 10262: $$rowtotal += $itemcount;
1.48 raeburn 10263: }
10264: return $datatable;
10265: }
10266:
1.69 raeburn 10267: sub print_serverstatuses {
10268: my ($dom,$settings,$rowtotal) = @_;
10269: my $datatable;
10270: my @pages = &serverstatus_pages();
10271: my (%namedaccess,%machineaccess);
10272: foreach my $type (@pages) {
10273: $namedaccess{$type} = '';
10274: $machineaccess{$type}= '';
10275: }
10276: if (ref($settings) eq 'HASH') {
10277: foreach my $type (@pages) {
10278: if (exists($settings->{$type})) {
10279: if (ref($settings->{$type}) eq 'HASH') {
10280: foreach my $key (keys(%{$settings->{$type}})) {
10281: if ($key eq 'namedusers') {
10282: $namedaccess{$type} = $settings->{$type}->{$key};
10283: } elsif ($key eq 'machines') {
10284: $machineaccess{$type} = $settings->{$type}->{$key};
10285: }
10286: }
10287: }
10288: }
10289: }
10290: }
1.81 raeburn 10291: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10292: my $rownum = 0;
10293: my $css_class;
10294: foreach my $type (@pages) {
10295: $rownum ++;
10296: $css_class = $rownum%2?' class="LC_odd_row"':'';
10297: $datatable .= '<tr'.$css_class.'>'.
10298: '<td><span class="LC_nobreak">'.
10299: $titles->{$type}.'</span></td>'.
10300: '<td class="LC_left_item">'.
10301: '<input type="text" name="'.$type.'_namedusers" '.
10302: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10303: '<td class="LC_right_item">'.
10304: '<span class="LC_nobreak">'.
10305: '<input type="text" name="'.$type.'_machines" '.
10306: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 10307: '</span></td></tr>'."\n";
1.69 raeburn 10308: }
10309: $$rowtotal += $rownum;
10310: return $datatable;
10311: }
10312:
10313: sub serverstatus_pages {
10314: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 10315: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 10316: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 10317: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10318: }
10319:
1.160.6.40 raeburn 10320: sub defaults_javascript {
10321: my ($settings) = @_;
1.160.6.98 raeburn 10322: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 10323:23): my $portal_js = <<"ENDPORTAL";
10324:23):
10325:23): function portalExtras(caller) {
10326:23): var x = caller.value;
10327:23): var y = new Array('email','web');
10328:23): for (var i=0; i<y.length; i++) {
10329:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
10330:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
10331:23): if (x.length > 0) {
10332:23): z.style.display = 'block';
10333:23): } else {
10334:23): z.style.display = 'none';
10335:23): }
10336:23): }
10337:23): }
10338:23): }
10339:23): ENDPORTAL
1.160.6.40 raeburn 10340: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10341: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10342: if ($maxnum eq '') {
10343: $maxnum = 0;
10344: }
10345: $maxnum ++;
1.160.6.51 raeburn 10346: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 10347: return <<"ENDSCRIPT";
10348: <script type="text/javascript">
10349: // <![CDATA[
10350: function reorderTypes(form,caller) {
10351: var changedVal;
10352: $jstext
10353: var newpos = 'addinststatus_pos';
10354: var current = new Array;
10355: var maxh = $maxnum;
10356: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10357: var oldVal;
10358: if (caller == newpos) {
10359: changedVal = newitemVal;
10360: } else {
10361: var curritem = 'inststatus_pos_'+caller;
10362: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10363: current[newitemVal] = newpos;
10364: }
10365: for (var i=0; i<inststatuses.length; i++) {
10366: if (inststatuses[i] != caller) {
10367: var elementName = 'inststatus_pos_'+inststatuses[i];
10368: if (form.elements[elementName]) {
10369: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10370: current[currVal] = elementName;
10371: }
10372: }
10373: }
10374: for (var j=0; j<maxh; j++) {
10375: if (current[j] == undefined) {
10376: oldVal = j;
10377: }
10378: }
10379: if (oldVal < changedVal) {
10380: for (var k=oldVal+1; k<=changedVal ; k++) {
10381: var elementName = current[k];
10382: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10383: }
10384: } else {
10385: for (var k=changedVal; k<oldVal; k++) {
10386: var elementName = current[k];
10387: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10388: }
10389: }
10390: return;
10391: }
10392:
1.160.6.118.2 12(raebu 10393:23): $portal_js
10394:23):
10395:23): // ]]>
10396:23): </script>
10397:23):
10398:23): ENDSCRIPT
10399:23): } else {
10400:23): return <<"ENDSCRIPT";
10401:23): <script type="text/javascript">
10402:23): // <![CDATA[
10403:23): $portal_js
1.160.6.40 raeburn 10404: // ]]>
10405: </script>
10406:
10407: ENDSCRIPT
10408: }
1.160.6.118.2 14(raebu 10409:23): return;
1.160.6.40 raeburn 10410: }
10411:
1.160.6.98 raeburn 10412: sub passwords_javascript {
1.160.6.118.2 5(raebur 10413:2): my ($prefix) = @_;
10414:2): my %intalert;
10415:2): if ($prefix eq 'passwords') {
10416:2): %intalert = &Apache::lonlocal::texthash (
10417: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.',
10418:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10419:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10420:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10421:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10422:2): );
14(raebu 10423:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 10424:2): %intalert = &Apache::lonlocal::texthash (
10425:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10426:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10427:2): );
10428:2): }
1.160.6.99 raeburn 10429: &js_escape(\%intalert);
10430: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 10431:2): my $intauthjs;
10432:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 10433:
10434: function warnIntAuth(field) {
10435: if (field.name == 'intauth_check') {
10436: if (field.value == '2') {
1.160.6.99 raeburn 10437: alert('$intalert{authcheck}');
1.160.6.98 raeburn 10438: }
10439: }
10440: if (field.name == 'intauth_cost') {
10441: field.value.replace(/\s/g,'');
10442: if (field.value != '') {
10443: var regexdigit=/^\\d+\$/;
10444: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 10445: alert('$intalert{authcost}');
10446: }
10447: }
10448: }
10449: return;
10450: }
10451:
1.160.6.118.2 5(raebur 10452:2): ENDSCRIPT
10453:2):
10454:2): }
10455:2):
10456:2): $intauthjs .= <<"ENDSCRIPT";
10457:2):
10458:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 10459: field.value.replace(/^\s+/,'');
10460: field.value.replace(/\s+\$/,'');
10461: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 10462:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 10463: if (field.value == '') {
10464: alert('$intalert{passmin}');
10465: field.value = '$defmin';
10466: } else {
10467: if (!regexdigit.test(field.value)) {
10468: alert('$intalert{passmin}');
10469: field.value = '$defmin';
10470: }
10471: var minval = parseInt(field.value,10);
10472: if (minval < $defmin) {
10473: alert('$intalert{passmin}');
10474: field.value = '$defmin';
10475: }
10476: }
10477: } else {
10478: if (field.value == '0') {
10479: field.value = '';
10480: }
10481: if (field.value != '') {
1.160.6.118.2 5(raebur 10482:2): if (!regexdigit.test(field.value)) {
10483:2): if (field.name == '${prefix}_max') {
10484:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 10485: } else {
1.160.6.118.2 5(raebur 10486:2): if (field.name == '${prefix}_numsaved') {
10487:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 10488: }
10489: }
1.160.6.118.2 5(raebur 10490:2): field.value = '';
1.160.6.98 raeburn 10491: }
10492: }
10493: }
10494: return;
10495: }
10496:
10497: ENDSCRIPT
10498: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10499: }
10500:
1.49 raeburn 10501: sub coursecategories_javascript {
10502: my ($settings) = @_;
1.57 raeburn 10503: my ($output,$jstext,$cathash);
1.49 raeburn 10504: if (ref($settings) eq 'HASH') {
1.57 raeburn 10505: $cathash = $settings->{'cats'};
10506: }
10507: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10508: my (@cats,@jsarray,%idx);
1.57 raeburn 10509: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10510: if (@jsarray > 0) {
10511: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10512: for (my $i=0; $i<@jsarray; $i++) {
10513: if (ref($jsarray[$i]) eq 'ARRAY') {
10514: my $catstr = join('","',@{$jsarray[$i]});
10515: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10516: }
10517: }
10518: }
10519: } else {
10520: $jstext = ' var categories = Array(1);'."\n".
10521: ' categories[0] = Array("instcode_pos");'."\n";
10522: }
1.160.6.42 raeburn 10523: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10524: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 10525: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10526: &js_escape(\$instcode_reserved);
10527: &js_escape(\$communities_reserved);
10528: &js_escape(\$choose_again);
1.49 raeburn 10529: $output = <<"ENDSCRIPT";
10530: <script type="text/javascript">
1.109 raeburn 10531: // <![CDATA[
1.49 raeburn 10532: function reorderCats(form,parent,item,idx) {
10533: var changedVal;
10534: $jstext
10535: var newpos = 'addcategory_pos';
10536: if (parent == '') {
10537: var has_instcode = 0;
10538: var maxtop = categories[idx].length;
10539: for (var j=0; j<maxtop; j++) {
10540: if (categories[idx][j] == 'instcode::0') {
10541: has_instcode == 1;
10542: }
10543: }
10544: if (has_instcode == 0) {
10545: categories[idx][maxtop] = 'instcode_pos';
10546: }
10547: } else {
10548: newpos += '_'+parent;
10549: }
10550: var maxh = 1 + categories[idx].length;
10551: var current = new Array;
10552: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10553: if (item == newpos) {
10554: changedVal = newitemVal;
10555: } else {
10556: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10557: current[newitemVal] = newpos;
10558: }
10559: for (var i=0; i<categories[idx].length; i++) {
10560: var elementName = categories[idx][i];
10561: if (elementName != item) {
10562: if (form.elements[elementName]) {
10563: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10564: current[currVal] = elementName;
10565: }
10566: }
10567: }
10568: var oldVal;
10569: for (var j=0; j<maxh; j++) {
10570: if (current[j] == undefined) {
10571: oldVal = j;
10572: }
10573: }
10574: if (oldVal < changedVal) {
10575: for (var k=oldVal+1; k<=changedVal ; k++) {
10576: var elementName = current[k];
10577: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10578: }
10579: } else {
10580: for (var k=changedVal; k<oldVal; k++) {
10581: var elementName = current[k];
10582: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10583: }
10584: }
10585: return;
10586: }
1.120 raeburn 10587:
10588: function categoryCheck(form) {
10589: if (form.elements['addcategory_name'].value == 'instcode') {
10590: alert('$instcode_reserved\\n$choose_again');
10591: return false;
10592: }
10593: if (form.elements['addcategory_name'].value == 'communities') {
10594: alert('$communities_reserved\\n$choose_again');
10595: return false;
10596: }
10597: return true;
10598: }
10599:
1.109 raeburn 10600: // ]]>
1.49 raeburn 10601: </script>
10602:
10603: ENDSCRIPT
10604: return $output;
10605: }
10606:
1.48 raeburn 10607: sub initialize_categories {
10608: my ($itemcount) = @_;
1.120 raeburn 10609: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 10610: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10611: instcode => 'Official courses (with institutional codes)',
10612: communities => 'Communities',
10613: );
10614: my $select0 = ' selected="selected"';
10615: my $select1 = '';
10616: foreach my $default ('instcode','communities') {
10617: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 10618: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 10619: if ($default eq 'communities') {
10620: $select1 = $select0;
10621: $select0 = '';
10622: }
10623: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10624: .'<select name="'.$default.'_pos">'
10625: .'<option value="0"'.$select0.'>1</option>'
10626: .'<option value="1"'.$select1.'>2</option>'
10627: .'<option value="2">3</option></select> '
10628: .$default_names{$default}
10629: .'</span></td><td><span class="LC_nobreak">'
10630: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10631: .&mt('Display').'</label> <label>'
10632: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10633: .'</label></span></td></tr>';
1.120 raeburn 10634: $itemcount ++;
10635: }
1.48 raeburn 10636: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10637: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10638: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10639: .'<select name="addcategory_pos"'.$chgstr.'>'
10640: .'<option value="0">1</option>'
10641: .'<option value="1">2</option>'
10642: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 10643: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 10644: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10645: .'</td></tr>';
1.48 raeburn 10646: return $datatable;
10647: }
10648:
10649: sub build_category_rows {
1.49 raeburn 10650: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10651: my ($text,$name,$item,$chgstr);
1.48 raeburn 10652: if (ref($cats) eq 'ARRAY') {
10653: my $maxdepth = scalar(@{$cats});
10654: if (ref($cats->[$depth]) eq 'HASH') {
10655: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10656: my $numchildren = @{$cats->[$depth]{$parent}};
10657: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 10658: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10659: my ($idxnum,$parent_name,$parent_item);
10660: my $higher = $depth - 1;
10661: if ($higher == 0) {
10662: $parent_name = &escape($parent).'::'.$higher;
10663: } else {
10664: if (ref($path) eq 'ARRAY') {
10665: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10666: }
10667: }
10668: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10669: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10670: if ($j < $numchildren) {
1.48 raeburn 10671: $name = $cats->[$depth]{$parent}[$j];
10672: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10673: $idxnum = $idx->{$item};
10674: } else {
10675: $name = $parent_name;
10676: $item = $parent_item;
1.48 raeburn 10677: }
1.49 raeburn 10678: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10679: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10680: for (my $i=0; $i<=$numchildren; $i++) {
10681: my $vpos = $i+1;
10682: my $selstr;
10683: if ($j == $i) {
10684: $selstr = ' selected="selected" ';
10685: }
10686: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10687: }
10688: $text .= '</select> ';
10689: if ($j < $numchildren) {
10690: my $deeper = $depth+1;
10691: $text .= $name.' '
10692: .'<label><input type="checkbox" name="deletecategory" value="'
10693: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10694: if(ref($path) eq 'ARRAY') {
10695: push(@{$path},$name);
1.49 raeburn 10696: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10697: pop(@{$path});
10698: }
10699: } else {
1.160.6.87 raeburn 10700: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10701: if ($j == $numchildren) {
10702: $text .= $name;
10703: } else {
10704: $text .= $item;
10705: }
10706: $text .= '" value="" />';
10707: }
10708: $text .= '</td></tr>';
10709: }
10710: $text .= '</table></td>';
10711: } else {
10712: my $higher = $depth-1;
10713: if ($higher == 0) {
10714: $name = &escape($parent).'::'.$higher;
10715: } else {
10716: if (ref($path) eq 'ARRAY') {
10717: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10718: }
10719: }
10720: my $colspan;
10721: if ($parent ne 'instcode') {
10722: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 10723: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10724: }
10725: }
10726: }
10727: }
10728: return $text;
10729: }
10730:
1.33 raeburn 10731: sub modifiable_userdata_row {
1.160.6.93 raeburn 10732: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.160.6.118.2 14(raebu 10733:23): $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.160.6.35 raeburn 10734: my ($role,$rolename,$statustype);
10735: $role = $item;
1.160.6.34 raeburn 10736: if ($context eq 'cancreate') {
1.160.6.93 raeburn 10737: if ($item =~ /^(emailusername)_(.+)$/) {
10738: $role = $1;
10739: $statustype = $2;
1.160.6.35 raeburn 10740: if (ref($usertypes) eq 'HASH') {
10741: if ($usertypes->{$statustype}) {
10742: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10743: } else {
10744: $rolename = &mt('Data provided by user');
10745: }
10746: }
1.160.6.34 raeburn 10747: }
10748: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10749: if (ref($usertypes) eq 'HASH') {
10750: $rolename = $usertypes->{$role};
10751: } else {
10752: $rolename = $role;
10753: }
1.160.6.118.2 14(raebu 10754:23): } elsif ($context eq 'lti') {
10755:23): $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 10756: } else {
1.63 raeburn 10757: if ($role eq 'cr') {
10758: $rolename = &mt('Custom role');
10759: } else {
10760: $rolename = &Apache::lonnet::plaintext($role);
10761: }
1.33 raeburn 10762: }
1.160.6.34 raeburn 10763: my (@fields,%fieldtitles);
10764: if (ref($fieldsref) eq 'ARRAY') {
10765: @fields = @{$fieldsref};
10766: } else {
10767: @fields = ('lastname','firstname','middlename','generation',
10768: 'permanentemail','id');
10769: }
10770: if ((ref($titlesref) eq 'HASH')) {
10771: %fieldtitles = %{$titlesref};
10772: } else {
10773: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10774: }
1.33 raeburn 10775: my $output;
1.160.6.93 raeburn 10776: my $css_class;
10777: if ($rowcount%2) {
10778: $css_class = 'LC_odd_row';
10779: }
10780: if ($customcss) {
10781: $css_class .= " $customcss";
10782: }
10783: $css_class =~ s/^\s+//;
10784: if ($css_class) {
10785: $css_class = ' class="'.$css_class.'"';
10786: }
10787: if ($rowstyle) {
10788: $css_class .= ' style="'.$rowstyle.'"';
10789: }
10790: if ($rowid) {
10791: $rowid = ' id="'.$rowid.'"';
10792: }
10793: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10794: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10795: '<td class="LC_left_item" colspan="2"><table>';
10796: my $rem;
10797: my %checks;
10798: if (ref($settings) eq 'HASH') {
1.160.6.118.2 14(raebu 10799:23): my $hashref;
10800:23): if ($context eq 'lti') {
10801:23): if (ref($settings) eq 'HASH') {
10802:23): $hashref = $settings->{'instdata'};
10803:23): }
10804:23): } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10805: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.118.2 14(raebu 10806:23): $hashref = $settings->{'lti_instdata'};
10807:23): }
10808:23): if ($role eq 'emailusername') {
10809:23): if ($statustype) {
10810:23): if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10811:23): $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.35 raeburn 10812: }
1.160.6.118.2 14(raebu 10813:23): }
10814:23): }
10815:23): }
10816:23): if (ref($hashref) eq 'HASH') {
10817:23): foreach my $field (@fields) {
10818:23): if ($hashref->{$field}) {
10819:23): if ($role eq 'emailusername') {
10820:23): $checks{$field} = $hashref->{$field};
10821:23): } else {
10822:23): $checks{$field} = ' checked="checked" ';
1.33 raeburn 10823: }
10824: }
10825: }
10826: }
10827: }
1.160.6.93 raeburn 10828: my $total = scalar(@fields);
10829: for (my $i=0; $i<$total; $i++) {
10830: $rem = $i%($numinrow);
1.33 raeburn 10831: if ($rem == 0) {
10832: if ($i > 0) {
10833: $output .= '</tr>';
10834: }
10835: $output .= '<tr>';
10836: }
10837: my $check = ' ';
1.160.6.35 raeburn 10838: unless ($role eq 'emailusername') {
10839: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 10840: $check = $checks{$fields[$i]};
1.160.6.118.2 14(raebu 10841:23): } elsif ($context ne 'lti') {
1.160.6.35 raeburn 10842: if ($role eq 'st') {
10843: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 10844: $check = ' checked="checked" ';
1.160.6.35 raeburn 10845: }
1.33 raeburn 10846: }
10847: }
10848: }
10849: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 10850: '<span class="LC_nobreak">';
1.160.6.118.2 14(raebu 10851:23): my $prefix = 'canmodify';
1.160.6.35 raeburn 10852: if ($role eq 'emailusername') {
10853: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10854: $checks{$fields[$i]} = 'omit';
10855: }
10856: foreach my $option ('required','optional','omit') {
10857: my $checked='';
10858: if ($checks{$fields[$i]} eq $option) {
10859: $checked='checked="checked" ';
10860: }
10861: $output .= '<label>'.
1.160.6.118.2 14(raebu 10862:23): '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.160.6.35 raeburn 10863: &mt($option).'</label>'.(' ' x2);
10864: }
10865: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10866: } else {
1.160.6.118.2 14(raebu 10867:23): if ($context eq 'lti') {
10868:23): $prefix = 'lti';
10869:23): }
1.160.6.35 raeburn 10870: $output .= '<label>'.
1.160.6.118.2 14(raebu 10871:23): '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.160.6.35 raeburn 10872: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10873: '</label>';
10874: }
10875: $output .= '</span></td>';
1.33 raeburn 10876: }
1.160.6.93 raeburn 10877: $rem = $total%$numinrow;
10878: my $colsleft;
10879: if ($rem) {
10880: $colsleft = $numinrow - $rem;
10881: }
10882: if ($colsleft > 1) {
1.33 raeburn 10883: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10884: ' </td>';
10885: } elsif ($colsleft == 1) {
10886: $output .= '<td class="LC_left_item"> </td>';
10887: }
10888: $output .= '</tr></table></td></tr>';
10889: return $output;
10890: }
1.28 raeburn 10891:
1.93 raeburn 10892: sub insttypes_row {
1.160.6.93 raeburn 10893: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10894: $customcss,$rowstyle) = @_;
1.93 raeburn 10895: my %lt = &Apache::lonlocal::texthash (
1.160.6.118.2 20(raebu 10896:24): cansearch => 'Users allowed to search',
1.93 raeburn 10897: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.160.6.118.2 20(raebu 10898:24): lockablenames => 'User preference to lock name',
10899:24): selfassign => 'Self-reportable affiliations',
10900:24): overrides => "Override domain's helpdesk settings based on requester's affiliation",
10901:24): webdav => 'WebDAV access available',
10902:24): authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 10903: );
1.160.6.118.2 20(raebu 10904:24): my ($showdom,$defaultquota);
1.93 raeburn 10905: if ($context eq 'cansearch') {
10906: $showdom = ' ('.$dom.')';
1.160.6.118.2 20(raebu 10907:24): } elsif ($context eq 'authorquota') {
10908:24): $defaultquota = 500;
1.93 raeburn 10909: }
1.160.6.5 raeburn 10910: my $class = 'LC_left_item';
10911: if ($context eq 'statustocreate') {
10912: $class = 'LC_right_item';
10913: }
1.160.6.93 raeburn 10914: my $css_class;
10915: if ($$rowtotal%2) {
10916: $css_class = 'LC_odd_row';
10917: }
10918: if ($customcss) {
10919: $css_class .= ' '.$customcss;
10920: }
10921: $css_class =~ s/^\s+//;
10922: if ($css_class) {
10923: $css_class = ' class="'.$css_class.'"';
10924: }
10925: if ($rowstyle) {
10926: $css_class .= ' style="'.$rowstyle.'"';
10927: }
10928: if ($onclick) {
10929: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 10930: }
10931: my $output = '<tr'.$css_class.'>'.
10932: '<td>'.$lt{$context}.$showdom.
10933: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10934: my $rem;
10935: if (ref($types) eq 'ARRAY') {
10936: for (my $i=0; $i<@{$types}; $i++) {
10937: if (defined($usertypes->{$types->[$i]})) {
10938: my $rem = $i%($numinrow);
10939: if ($rem == 0) {
10940: if ($i > 0) {
10941: $output .= '</tr>';
10942: }
10943: $output .= '<tr>';
1.23 raeburn 10944: }
1.160.6.118.2 20(raebu 10945:24): if ($context eq 'authorquota') {
10946:24): my $currquota;
10947:24): if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
10948:24): $currquota = $settings->{$context}->{$types->[$i]};
10949:24): } else {
10950:24): $currquota = $defaultquota;
10951:24): }
10952:24): $output .= '<td class="LC_left_item">'."\n".
10953:24): '<label><span class="LC_nobreak">'."\n".
10954:24): $usertypes->{$types->[$i]}.'</span><br />'."\n".
10955:24): '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
10956:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
10957:24): '</label></td>';
10958:24): } else {
10959:24): my $check = ' ';
10960:24): if (ref($settings) eq 'HASH') {
10961:24): if (ref($settings->{$context}) eq 'ARRAY') {
10962:24): if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10963:24): $check = ' checked="checked" ';
10964:24): }
10965:24): } elsif (ref($settings->{$context}) eq 'HASH') {
10966:24): if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10967:24): $check = ' checked="checked" ';
10968:24): } elsif ($context eq 'webdav') {
10969:24): if ($settings->{$context}->{$types->[$i]}) {
10970:24): $check = ' checked="checked" ';
10971:24): }
10972:24): }
10973:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 10974: $check = ' checked="checked" ';
10975: }
1.26 raeburn 10976: }
1.160.6.118.2 20(raebu 10977:24): $output .= '<td class="LC_left_item">'.
10978:24): '<span class="LC_nobreak"><label>'.
10979:24): '<input type="checkbox" name="'.$context.'" '.
10980:24): 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
10981:24): $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10982: }
10983: }
10984: }
1.26 raeburn 10985: $rem = @{$types}%($numinrow);
1.23 raeburn 10986: }
10987: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 10988: if ($context eq 'overrides') {
10989: if ($colsleft > 1) {
10990: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10991: } else {
10992: $output .= '<td class="LC_left_item">';
10993: }
10994: $output .= ' ';
1.23 raeburn 10995: } else {
1.160.6.101 raeburn 10996: if ($rem == 0) {
10997: $output .= '<tr>';
10998: }
10999: if ($colsleft > 1) {
11000: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11001: } else {
11002: $output .= '<td class="LC_left_item">';
11003: }
1.160.6.118.2 20(raebu 11004:24): if ($context eq 'authorquota') {
11005:24): my $currquota = 500;
11006:24): if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
11007:24): if ($settings->{$context}{'default'} =~ /^\d+$/) {
11008:24): $currquota = $settings->{$context}{'default'};
11009:24): }
11010:24): }
11011:24): $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
11012:24): '<input type="text" name="'.$context.'_default" '.
11013:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
11014:24): '</label>';
11015:24): } else {
11016:24): my $defcheck = ' ';
11017:24): if (ref($settings) eq 'HASH') {
11018:24): if (ref($settings->{$context}) eq 'ARRAY') {
11019:24): if (grep(/^default$/,@{$settings->{$context}})) {
11020:24): $defcheck = ' checked="checked" ';
11021:24): }
11022:24): } elsif (ref($settings->{$context}) eq 'HASH') {
11023:24): if (ref($settings->{$context}->{'default'}) eq 'HASH') {
11024:24): $defcheck = ' checked="checked" ';
11025:24): } elsif ($context eq 'webdav') {
11026:24): if ($settings->{$context}->{'default'}) {
11027:24): $defcheck = ' checked="checked" ';
11028:24): }
11029:24): }
11030:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 11031: $defcheck = ' checked="checked" ';
11032: }
1.99 raeburn 11033: }
1.160.6.118.2 20(raebu 11034:24): $output .= '<span class="LC_nobreak"><label>'.
11035:24): '<input type="checkbox" name="'.$context.'" '.
11036:24): 'value="default"'.$defcheck.$onclick.'/>'.
11037:24): $othertitle.'</label></span>';
1.26 raeburn 11038: }
1.23 raeburn 11039: }
1.160.6.101 raeburn 11040: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11041: return $output;
1.23 raeburn 11042: }
11043:
11044: sub sorted_searchtitles {
11045: my %searchtitles = &Apache::lonlocal::texthash(
11046: 'uname' => 'username',
11047: 'lastname' => 'last name',
11048: 'lastfirst' => 'last name, first name',
11049: );
11050: my @titleorder = ('uname','lastname','lastfirst');
11051: return (\%searchtitles,\@titleorder);
11052: }
11053:
1.25 raeburn 11054: sub sorted_searchtypes {
11055: my %srchtypes_desc = (
11056: exact => 'is exact match',
11057: contains => 'contains ..',
11058: begins => 'begins with ..',
11059: );
11060: my @srchtypeorder = ('exact','begins','contains');
11061: return (\%srchtypes_desc,\@srchtypeorder);
11062: }
11063:
1.3 raeburn 11064: sub usertype_update_row {
11065: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11066: my $datatable;
11067: my $numinrow = 4;
11068: foreach my $type (@{$types}) {
11069: if (defined($usertypes->{$type})) {
11070: $$rownums ++;
11071: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11072: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11073: '</td><td class="LC_left_item"><table>';
11074: for (my $i=0; $i<@{$fields}; $i++) {
11075: my $rem = $i%($numinrow);
11076: if ($rem == 0) {
11077: if ($i > 0) {
11078: $datatable .= '</tr>';
11079: }
11080: $datatable .= '<tr>';
11081: }
11082: my $check = ' ';
1.39 raeburn 11083: if (ref($settings) eq 'HASH') {
11084: if (ref($settings->{'fields'}) eq 'HASH') {
11085: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11086: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11087: $check = ' checked="checked" ';
11088: }
1.3 raeburn 11089: }
11090: }
11091: }
11092:
11093: if ($i == @{$fields}-1) {
11094: my $colsleft = $numinrow - $rem;
11095: if ($colsleft > 1) {
11096: $datatable .= '<td colspan="'.$colsleft.'">';
11097: } else {
11098: $datatable .= '<td>';
11099: }
11100: } else {
11101: $datatable .= '<td>';
11102: }
1.8 raeburn 11103: $datatable .= '<span class="LC_nobreak"><label>'.
11104: '<input type="checkbox" name="updateable_'.$type.
11105: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11106: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11107: }
11108: $datatable .= '</tr></table></td></tr>';
11109: }
11110: }
11111: return $datatable;
1.1 raeburn 11112: }
11113:
11114: sub modify_login {
1.160.6.24 raeburn 11115: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11116: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 11117: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 11118:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 11119: %title = ( coursecatalog => 'Display course catalog',
11120: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 11121: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 11122: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 11123: loginheader => 'Log-in box header',
11124: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 11125: @offon = ('off','on');
1.112 raeburn 11126: if (ref($domconfig{login}) eq 'HASH') {
11127: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11128: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11129: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11130: }
11131: }
1.160.6.113 raeburn 11132: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11133: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11134: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11135: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11136: $saml{$lonhost} = 1;
11137: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11138: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11139: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11140: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11141: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 11142:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 11143: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11144: }
11145: }
11146: }
1.112 raeburn 11147: }
1.9 raeburn 11148: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11149: \%domconfig,\%loginhash);
1.160.6.14 raeburn 11150: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11151: foreach my $item (@toggles) {
11152: $loginhash{login}{$item} = $env{'form.'.$item};
11153: }
1.41 raeburn 11154: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11155: if (ref($colchanges{'login'}) eq 'HASH') {
11156: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11157: \%loginhash);
11158: }
1.110 raeburn 11159:
1.149 raeburn 11160: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 11161: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11162: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11163: if (keys(%servers) > 1) {
11164: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11165: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11166: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11167: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11168: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11169: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11170: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11171: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11172: $changes{'loginvia'}{$lonhost} = 1;
11173: } else {
11174: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11175: $changes{'loginvia'}{$lonhost} = 1;
11176: }
11177: } else {
11178: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11179: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11180: $changes{'loginvia'}{$lonhost} = 1;
11181: }
11182: }
11183: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11184: foreach my $item (@loginvia_attribs) {
11185: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11186: }
11187: } else {
11188: foreach my $item (@loginvia_attribs) {
11189: my $new = $env{'form.'.$lonhost.'_'.$item};
11190: if (($item eq 'serverpath') && ($new eq 'custom')) {
11191: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11192: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11193: $new = '/';
11194: }
11195: }
11196: if (($item eq 'custompath') &&
11197: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11198: $new = '';
11199: }
11200: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11201: $changes{'loginvia'}{$lonhost} = 1;
11202: }
11203: if ($item eq 'exempt') {
1.160.6.56 raeburn 11204: $new = &check_exempt_addresses($new);
1.128 raeburn 11205: }
11206: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11207: }
11208: }
1.112 raeburn 11209: } else {
1.128 raeburn 11210: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11211: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11212: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11213: foreach my $item (@loginvia_attribs) {
11214: my $new = $env{'form.'.$lonhost.'_'.$item};
11215: if (($item eq 'serverpath') && ($new eq 'custom')) {
11216: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11217: $new = '/';
11218: }
11219: }
11220: if (($item eq 'custompath') &&
11221: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11222: $new = '';
11223: }
11224: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11225: }
1.110 raeburn 11226: }
11227: }
11228: }
11229: }
1.119 raeburn 11230:
1.160.6.5 raeburn 11231: my $servadm = $r->dir_config('lonAdmEMail');
11232: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11233: if (ref($domconfig{'login'}) eq 'HASH') {
11234: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11235: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11236: if ($lang eq 'nolang') {
11237: push(@currlangs,$lang);
11238: } elsif (defined($langchoices{$lang})) {
11239: push(@currlangs,$lang);
11240: } else {
11241: next;
11242: }
11243: }
11244: }
11245: }
11246: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11247: if (@currlangs > 0) {
11248: foreach my $lang (@currlangs) {
11249: if (grep(/^\Q$lang\E$/,@delurls)) {
11250: $changes{'helpurl'}{$lang} = 1;
11251: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11252: $changes{'helpurl'}{$lang} = 1;
11253: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11254: push(@newlangs,$lang);
11255: } else {
11256: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11257: }
11258: }
11259: }
11260: unless (grep(/^nolang$/,@currlangs)) {
11261: if ($env{'form.loginhelpurl_nolang.filename'}) {
11262: $changes{'helpurl'}{'nolang'} = 1;
11263: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11264: push(@newlangs,'nolang');
11265: }
11266: }
11267: if ($env{'form.loginhelpurl_add_lang'}) {
11268: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11269: ($env{'form.loginhelpurl_add_file.filename'})) {
11270: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11271: $addedfile = $env{'form.loginhelpurl_add_lang'};
11272: }
11273: }
11274: if ((@newlangs > 0) || ($addedfile)) {
11275: my $error;
11276: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11277: if ($configuserok eq 'ok') {
11278: if ($switchserver) {
11279: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11280: } elsif ($author_ok eq 'ok') {
11281: my @allnew = @newlangs;
11282: if ($addedfile ne '') {
11283: push(@allnew,$addedfile);
11284: }
1.160.6.118.2 14(raebu 11285:23): my $modified = [];
1.160.6.5 raeburn 11286: foreach my $lang (@allnew) {
11287: my $formelem = 'loginhelpurl_'.$lang;
11288: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11289: $formelem = 'loginhelpurl_add_file';
11290: }
1.160.6.118.2 14(raebu 11291:23): (my $result,$newurl{$lang}) =
11292:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11293:23): "help/$lang",'','',$newfile{$lang},
11294:23): $modified);
1.160.6.5 raeburn 11295: if ($result eq 'ok') {
11296: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11297: $changes{'helpurl'}{$lang} = 1;
11298: } else {
11299: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11300: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11301: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
11302: (!grep(/^\Q$lang\E$/,@delurls))) {
11303: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11304: }
11305: }
11306: }
1.160.6.118.2 14(raebu 11307:23): &update_modify_urls($r,$modified);
1.160.6.5 raeburn 11308: } else {
11309: $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);
11310: }
11311: } else {
11312: $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);
11313: }
11314: if ($error) {
11315: &Apache::lonnet::logthis($error);
11316: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11317: }
11318: }
1.160.6.56 raeburn 11319:
11320: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11321: if (ref($domconfig{'login'}) eq 'HASH') {
11322: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11323: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11324: if ($domservers{$lonhost}) {
11325: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11326: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 11327: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 11328: }
11329: }
11330: }
11331: }
11332: }
11333: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11334: foreach my $lonhost (sort(keys(%domservers))) {
11335: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11336: $changes{'headtag'}{$lonhost} = 1;
11337: } else {
11338: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11339: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11340: }
11341: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11342: push(@newhosts,$lonhost);
11343: } elsif ($currheadtagurls{$lonhost}) {
11344: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11345: if ($currexempt{$lonhost}) {
11346: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
11347: $changes{'headtag'}{$lonhost} = 1;
11348: }
11349: } elsif ($possexempt{$lonhost}) {
11350: $changes{'headtag'}{$lonhost} = 1;
11351: }
11352: if ($possexempt{$lonhost}) {
11353: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11354: }
11355: }
11356: }
11357: }
11358: if (@newhosts) {
11359: my $error;
11360: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11361: if ($configuserok eq 'ok') {
11362: if ($switchserver) {
11363: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11364: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11365:23): my $modified = [];
1.160.6.56 raeburn 11366: foreach my $lonhost (@newhosts) {
11367: my $formelem = 'loginheadtag_'.$lonhost;
1.160.6.118.2 14(raebu 11368:23): (my $result,$newheadtagurls{$lonhost}) =
11369:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11370:23): "login/headtag/$lonhost",'','',
11371:23): $env{'form.loginheadtag_'.$lonhost.'.filename'},
11372:23): $modified);
1.160.6.56 raeburn 11373: if ($result eq 'ok') {
1.160.6.113 raeburn 11374: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11375: $changes{'headtag'}{$lonhost} = 1;
11376: if ($possexempt{$lonhost}) {
11377: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11378: }
11379: } else {
11380: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11381: $newheadtagurls{$lonhost},$result);
11382: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11383: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11384: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11385: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11386: }
11387: }
11388: }
1.160.6.118.2 14(raebu 11389:23): &update_modify_urls($r,$modified);
1.160.6.113 raeburn 11390: } else {
11391: $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);
11392: }
11393: } else {
11394: $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);
11395: }
11396: if ($error) {
11397: &Apache::lonnet::logthis($error);
11398: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11399: }
11400: }
11401: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11402: my @newsamlimgs;
11403: foreach my $lonhost (keys(%domservers)) {
11404: if ($env{'form.saml_'.$lonhost}) {
11405: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11406: push(@newsamlimgs,$lonhost);
11407: }
1.160.6.118.2 9(raebur 11408:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11409: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11410: }
11411: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 11412:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
11413:2): $env{'form.saml_window_'.$lonhost} = '';
11414:2): }
1.160.6.113 raeburn 11415: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11416: #FIXME Need to obsolete published image
11417: delete($currsaml{$lonhost}{'img'});
11418: $changes{'saml'}{$lonhost} = 1;
11419: }
11420: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11421: $changes{'saml'}{$lonhost} = 1;
11422: }
11423: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11424: $changes{'saml'}{$lonhost} = 1;
11425: }
11426: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11427: $changes{'saml'}{$lonhost} = 1;
11428: }
11429: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11430: $changes{'saml'}{$lonhost} = 1;
11431: }
1.160.6.118.2 9(raebur 11432:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11433:2): $changes{'saml'}{$lonhost} = 1;
11434:2): }
1.160.6.113 raeburn 11435: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11436: $changes{'saml'}{$lonhost} = 1;
11437: }
11438: } else {
11439: $changes{'saml'}{$lonhost} = 1;
11440: }
1.160.6.118.2 9(raebur 11441:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11442: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11443: }
11444: } else {
11445: if ($saml{$lonhost}) {
11446: $changes{'saml'}{$lonhost} = 1;
11447: delete($currsaml{$lonhost});
11448: }
11449: }
11450: }
11451: foreach my $posshost (keys(%currsaml)) {
11452: unless (exists($domservers{$posshost})) {
11453: delete($currsaml{$posshost});
11454: }
11455: }
11456: %{$loginhash{'login'}{'saml'}} = %currsaml;
11457: if (@newsamlimgs) {
11458: my $error;
11459: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11460: if ($configuserok eq 'ok') {
11461: if ($switchserver) {
11462: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11463: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11464:23): my $modified = [];
1.160.6.113 raeburn 11465: foreach my $lonhost (@newsamlimgs) {
11466: my $formelem = 'saml_img_'.$lonhost;
1.160.6.118.2 14(raebu 11467:23): my ($result,$imgurl) =
11468:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11469:23): "login/saml/$lonhost",'','',
11470:23): $env{'form.saml_img_'.$lonhost.'.filename'},
11471:23): $modified);
1.160.6.113 raeburn 11472: if ($result eq 'ok') {
11473: $currsaml{$lonhost}{'img'} = $imgurl;
11474: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11475: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 11476: } else {
1.160.6.113 raeburn 11477: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11478: $lonhost,$result);
1.160.6.56 raeburn 11479: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11480: }
11481: }
1.160.6.118.2 14(raebu 11482:23): &update_modify_urls($r,$modified);
1.160.6.56 raeburn 11483: } else {
1.160.6.113 raeburn 11484: $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 11485: }
11486: } else {
1.160.6.113 raeburn 11487: $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 11488: }
11489: if ($error) {
11490: &Apache::lonnet::logthis($error);
11491: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11492: }
11493: }
1.160.6.5 raeburn 11494: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11495:
11496: my $defaulthelpfile = '/adm/loginproblems.html';
11497: my $defaulttext = &mt('Default in use');
11498:
1.1 raeburn 11499: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11500: $dom);
11501: if ($putresult eq 'ok') {
1.160.6.14 raeburn 11502: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11503: my %defaultchecked = (
11504: 'coursecatalog' => 'on',
1.160.6.14 raeburn 11505: 'helpdesk' => 'on',
1.42 raeburn 11506: 'adminmail' => 'off',
1.43 raeburn 11507: 'newuser' => 'off',
1.42 raeburn 11508: );
1.55 raeburn 11509: if (ref($domconfig{'login'}) eq 'HASH') {
11510: foreach my $item (@toggles) {
11511: if ($defaultchecked{$item} eq 'on') {
11512: if (($domconfig{'login'}{$item} eq '0') &&
11513: ($env{'form.'.$item} eq '1')) {
11514: $changes{$item} = 1;
11515: } elsif (($domconfig{'login'}{$item} eq '' ||
11516: $domconfig{'login'}{$item} eq '1') &&
11517: ($env{'form.'.$item} eq '0')) {
11518: $changes{$item} = 1;
11519: }
11520: } elsif ($defaultchecked{$item} eq 'off') {
11521: if (($domconfig{'login'}{$item} eq '1') &&
11522: ($env{'form.'.$item} eq '0')) {
11523: $changes{$item} = 1;
11524: } elsif (($domconfig{'login'}{$item} eq '' ||
11525: $domconfig{'login'}{$item} eq '0') &&
11526: ($env{'form.'.$item} eq '1')) {
11527: $changes{$item} = 1;
11528: }
1.42 raeburn 11529: }
11530: }
1.41 raeburn 11531: }
1.6 raeburn 11532: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11533: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 11534: if (exists($changes{'saml'})) {
11535: my $hostid_in_use;
11536: my @hosts = &Apache::lonnet::current_machine_ids();
11537: if (@hosts > 1) {
11538: foreach my $hostid (@hosts) {
11539: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11540: $hostid_in_use = $hostid;
11541: last;
11542: }
11543: }
11544: } else {
11545: $hostid_in_use = $r->dir_config('lonHostID');
11546: }
11547: if (($hostid_in_use) &&
11548: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11549: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11550: }
11551: if (ref($lastactref) eq 'HASH') {
11552: if (ref($changes{'saml'}) eq 'HASH') {
11553: my %updates;
11554: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11555: $lastactref->{'samllanding'} = \%updates;
11556: }
11557: }
11558: }
1.160.6.27 raeburn 11559: if (ref($lastactref) eq 'HASH') {
11560: $lastactref->{'domainconfig'} = 1;
11561: }
1.1 raeburn 11562: $resulttext = &mt('Changes made:').'<ul>';
11563: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11564: if ($item eq 'loginvia') {
1.112 raeburn 11565: if (ref($changes{$item}) eq 'HASH') {
11566: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11567: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11568: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11569: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11570: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11571: $protocol = 'http' if ($protocol ne 'https');
11572: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11573:
11574: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11575: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11576: } else {
11577: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11578: }
11579: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11580: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11581: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11582: }
11583: $resulttext .= '</li>';
11584: } else {
11585: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11586: }
1.112 raeburn 11587: } else {
1.128 raeburn 11588: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11589: }
11590: }
1.128 raeburn 11591: $resulttext .= '</ul></li>';
1.112 raeburn 11592: }
1.160.6.5 raeburn 11593: } elsif ($item eq 'helpurl') {
11594: if (ref($changes{$item}) eq 'HASH') {
11595: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11596: if (grep(/^\Q$lang\E$/,@delurls)) {
11597: my ($chg,$link);
11598: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11599: if ($lang eq 'nolang') {
11600: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11601: } else {
11602: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11603: }
11604: $resulttext .= '<li>'.$chg.'</li>';
11605: } else {
11606: my $chg;
11607: if ($lang eq 'nolang') {
11608: $chg = &mt('custom log-in help file for no preferred language');
11609: } else {
11610: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11611: }
11612: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11613: $loginhash{'login'}{'helpurl'}{$lang}.
11614: '?inhibitmenu=yes',$chg,600,500).
11615: '</li>';
11616: }
11617: }
11618: }
1.160.6.56 raeburn 11619: } elsif ($item eq 'headtag') {
11620: if (ref($changes{$item}) eq 'HASH') {
11621: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11622: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11623: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11624: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11625: $resulttext .= '<li><a href="'.
11626: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11627: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11628: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11629: if ($possexempt{$lonhost}) {
11630: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11631: } else {
11632: $resulttext .= &mt('included for any client IP');
11633: }
11634: $resulttext .= '</li>';
11635: }
11636: }
11637: }
1.160.6.113 raeburn 11638: } elsif ($item eq 'saml') {
11639: if (ref($changes{$item}) eq 'HASH') {
11640: my %notlt = (
11641: text => 'Text for log-in by SSO',
11642: img => 'SSO button image',
11643: alt => 'Alt text for button image',
11644: url => 'SSO URL',
11645: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 11646:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 11647: notsso => 'Text for non-SSO log-in',
11648: );
11649: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11650: if (ref($currsaml{$lonhost}) eq 'HASH') {
11651: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11652: '<ul>';
1.160.6.118.2 9(raebur 11653:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11654: if ($currsaml{$lonhost}{$key} eq '') {
11655: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11656: } else {
11657: my $value = "'$currsaml{$lonhost}{$key}'";
11658: if ($key eq 'img') {
11659: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 11660:2): } elsif ($key eq 'window') {
11661:2): $value = 'On';
1.160.6.113 raeburn 11662: }
11663: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11664: $value).'</li>';
11665: }
11666: }
11667: $resulttext .= '</ul></li>';
11668: } else {
11669: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11670: }
11671: }
11672: }
1.160.6.5 raeburn 11673: } elsif ($item eq 'captcha') {
11674: if (ref($loginhash{'login'}) eq 'HASH') {
11675: my $chgtxt;
11676: if ($loginhash{'login'}{$item} eq 'notused') {
11677: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11678: } else {
11679: my %captchas = &captcha_phrases();
11680: if ($captchas{$loginhash{'login'}{$item}}) {
11681: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11682: } else {
11683: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11684: }
11685: }
11686: $resulttext .= '<li>'.$chgtxt.'</li>';
11687: }
11688: } elsif ($item eq 'recaptchakeys') {
11689: if (ref($loginhash{'login'}) eq 'HASH') {
11690: my ($privkey,$pubkey);
11691: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11692: $pubkey = $loginhash{'login'}{$item}{'public'};
11693: $privkey = $loginhash{'login'}{$item}{'private'};
11694: }
11695: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11696: if (!$pubkey) {
11697: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11698: } else {
11699: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11700: }
11701: if (!$privkey) {
11702: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11703: } else {
1.160.6.53 raeburn 11704: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 11705: }
11706: $chgtxt .= '</ul>';
11707: $resulttext .= '<li>'.$chgtxt.'</li>';
11708: }
1.160.6.69 raeburn 11709: } elsif ($item eq 'recaptchaversion') {
11710: if (ref($loginhash{'login'}) eq 'HASH') {
11711: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11712: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11713: '</li>';
11714: }
11715: }
1.41 raeburn 11716: } else {
11717: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11718: }
1.1 raeburn 11719: }
1.6 raeburn 11720: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11721: } else {
11722: $resulttext = &mt('No changes made to log-in page settings');
11723: }
11724: } else {
1.11 albertel 11725: $resulttext = '<span class="LC_error">'.
11726: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11727: }
1.6 raeburn 11728: if ($errors) {
1.9 raeburn 11729: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11730: $errors.'</ul>';
11731: }
11732: return $resulttext;
11733: }
11734:
1.160.6.56 raeburn 11735: sub check_exempt_addresses {
11736: my ($iplist) = @_;
11737: $iplist =~ s/^\s+//;
11738: $iplist =~ s/\s+$//;
11739: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11740: my (@okips,$new);
11741: foreach my $ip (@poss_ips) {
11742: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11743: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11744: push(@okips,$ip);
11745: }
11746: }
11747: }
11748: if (@okips > 0) {
11749: $new = join(',',@okips);
11750: } else {
11751: $new = '';
11752: }
11753: return $new;
11754: }
11755:
1.6 raeburn 11756: sub color_font_choices {
11757: my %choices =
11758: &Apache::lonlocal::texthash (
11759: img => "Header",
11760: bgs => "Background colors",
11761: links => "Link colors",
1.55 raeburn 11762: images => "Images",
1.6 raeburn 11763: font => "Font color",
1.160.6.22 raeburn 11764: fontmenu => "Font menu",
1.76 raeburn 11765: pgbg => "Page",
1.6 raeburn 11766: tabbg => "Header",
11767: sidebg => "Border",
11768: link => "Link",
11769: alink => "Active link",
11770: vlink => "Visited link",
11771: );
11772: return %choices;
11773: }
11774:
1.160.6.113 raeburn 11775: sub modify_ipaccess {
11776: my ($dom,$lastactref,%domconfig) = @_;
11777: my (@allpos,%changes,%confhash,$errors,$resulttext);
11778: my (@items,%deletions,%itemids,@warnings);
11779: my ($typeorder,$types) = &commblocktype_text();
11780: if ($env{'form.ipaccess_add'}) {
11781: my $name = $env{'form.ipaccess_name_add'};
11782: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11783: if ($newid) {
11784: $itemids{'add'} = $newid;
11785: push(@items,'add');
11786: $changes{$newid} = 1;
11787: } else {
11788: $error = &mt('Failed to acquire unique ID for new IP access control item');
11789: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11790: }
11791: }
11792: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11793: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11794: if (@todelete) {
11795: map { $deletions{$_} = 1; } @todelete;
11796: }
11797: my $maxnum = $env{'form.ipaccess_maxnum'};
11798: for (my $i=0; $i<$maxnum; $i++) {
11799: my $itemid = $env{'form.ipaccess_id_'.$i};
11800: $itemid =~ s/\D+//g;
11801: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11802: if ($deletions{$itemid}) {
11803: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11804: } else {
11805: push(@items,$i);
11806: $itemids{$i} = $itemid;
11807: }
11808: }
11809: }
11810: }
11811: foreach my $idx (@items) {
11812: my $itemid = $itemids{$idx};
11813: next unless ($itemid);
11814: my %current;
11815: unless ($idx eq 'add') {
11816: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11817: %current = %{$domconfig{'ipaccess'}{$itemid}};
11818: }
11819: }
11820: my $position = $env{'form.ipaccess_pos_'.$itemid};
11821: $position =~ s/\D+//g;
11822: if ($position ne '') {
11823: $allpos[$position] = $itemid;
11824: }
11825: my $name = $env{'form.ipaccess_name_'.$idx};
11826: $name =~ s/^\s+|\s+$//g;
11827: $confhash{$itemid}{'name'} = $name;
11828: my $possrange = $env{'form.ipaccess_range_'.$idx};
11829: $possrange =~ s/^\s+|\s+$//g;
11830: unless ($possrange eq '') {
11831: $possrange =~ s/[\r\n]+/\s/g;
11832: $possrange =~ s/\s*-\s*/-/g;
11833: $possrange =~ s/\s+/,/g;
11834: $possrange =~ s/,+/,/g;
11835: if ($possrange ne '') {
11836: my (@ok,$count);
11837: $count = 0;
11838: foreach my $poss (split(/\,/,$possrange)) {
11839: $count ++;
11840: $poss = &validate_ip_pattern($poss);
11841: if ($poss ne '') {
11842: push(@ok,$poss);
11843: }
11844: }
11845: my $diff = $count - scalar(@ok);
11846: if ($diff) {
11847: $errors .= '<li><span class="LC_error">'.
11848: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11849: $diff,$name).
11850: '</span></li>';
11851: }
11852: if (@ok) {
11853: my @cidr_list;
11854: foreach my $item (@ok) {
11855: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11856: }
11857: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11858: }
11859: }
11860: }
11861: foreach my $field ('name','ip') {
11862: unless (($idx eq 'add') || ($changes{$itemid})) {
11863: if ($current{$field} ne $confhash{$itemid}{$field}) {
11864: $changes{$itemid} = 1;
11865: last;
11866: }
11867: }
11868: }
11869: $confhash{$itemid}{'commblocks'} = {};
11870:
11871: my %commblocks;
11872: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11873: foreach my $type (@{$typeorder}) {
11874: if ($commblocks{$type}) {
11875: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11876: }
11877: unless (($idx eq 'add') || ($changes{$itemid})) {
11878: if (ref($current{'commblocks'}) eq 'HASH') {
11879: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11880: $changes{$itemid} = 1;
11881: }
11882: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11883: $changes{$itemid} = 1;
11884: }
11885: }
11886: }
11887: $confhash{$itemid}{'courses'} = {};
11888: my %crsdeletions;
11889: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11890: if (@delcrs) {
11891: map { $crsdeletions{$_} = 1; } @delcrs;
11892: }
11893: if (ref($current{'courses'}) eq 'HASH') {
11894: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11895: if ($crsdeletions{$cid}) {
11896: $changes{$itemid} = 1;
11897: } else {
11898: $confhash{$itemid}{'courses'}{$cid} = 1;
11899: }
11900: }
11901: }
11902: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11903: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11904: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11905: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11906: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11907: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11908: $errors .= '<li><span class="LC_error">'.
11909: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11910: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11911: '</span></li>';
11912: } else {
11913: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11914: $changes{$itemid} = 1;
11915: }
11916: }
11917: }
11918: if (@allpos > 0) {
11919: my $idx = 0;
11920: foreach my $itemid (@allpos) {
11921: if ($itemid ne '') {
11922: $confhash{$itemid}{'order'} = $idx;
11923: unless ($changes{$itemid}) {
11924: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11925: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11926: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11927: $changes{$itemid} = 1;
11928: }
11929: }
11930: }
11931: }
11932: $idx ++;
11933: }
11934: }
11935: }
11936: if (keys(%changes)) {
11937: my %defaultshash = (
11938: ipaccess => \%confhash,
11939: );
11940: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11941: $dom);
11942: if ($putresult eq 'ok') {
11943: my $cachetime = 1800;
11944: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11945: if (ref($lastactref) eq 'HASH') {
11946: $lastactref->{'ipaccess'} = 1;
11947: }
11948: $resulttext = &mt('Changes made:').'<ul>';
11949: my %bynum;
11950: foreach my $itemid (sort(keys(%changes))) {
11951: if (ref($confhash{$itemid}) eq 'HASH') {
11952: my $position = $confhash{$itemid}{'order'};
11953: if ($position =~ /^\d+$/) {
11954: $bynum{$position} = $itemid;
11955: }
11956: }
11957: }
11958: if (keys(%deletions)) {
11959: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11960: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11961: }
11962: }
11963: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11964: my $itemid = $bynum{$pos};
11965: if (ref($confhash{$itemid}) eq 'HASH') {
11966: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11967: my $position = $pos + 1;
11968: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11969: if ($confhash{$itemid}{'ip'} eq '') {
11970: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11971: } else {
11972: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11973: }
11974: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11975: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11976: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11977: '</li>';
11978: } else {
11979: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11980: }
11981: if (keys(%{$confhash{$itemid}{'courses'}})) {
11982: my @courses;
11983: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11984: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11985: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
11986: }
11987: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
11988: join('</li><li>',@courses).'</li></ul>';
11989: } else {
11990: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
11991: }
11992: $resulttext .= '</ul></li>';
11993: }
11994: }
11995: $resulttext .= '</ul>';
11996: } else {
11997: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11998: }
11999: } else {
12000: $resulttext = &mt('No changes made');
12001: }
12002: if ($errors) {
12003: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12004: $errors.'</ul></p>';
12005: }
12006: return $resulttext;
12007: }
12008:
12009: sub get_ipaccess_id {
12010: my ($domain,$location) = @_;
12011: # get lock on ipaccess db
12012: my $lockhash = {
12013: lock => $env{'user.name'}.
12014: ':'.$env{'user.domain'},
12015: };
12016: my $tries = 0;
12017: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12018: my ($id,$error);
12019:
12020: while (($gotlock ne 'ok') && ($tries<10)) {
12021: $tries ++;
12022: sleep (0.1);
12023: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12024: }
12025: if ($gotlock eq 'ok') {
12026: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12027: if ($currids{'lock'}) {
12028: delete($currids{'lock'});
12029: if (keys(%currids)) {
12030: my @curr = sort { $a <=> $b } keys(%currids);
12031: if ($curr[-1] =~ /^\d+$/) {
12032: $id = 1 + $curr[-1];
12033: }
12034: } else {
12035: $id = 1;
12036: }
12037: if ($id) {
12038: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12039: $error = 'nostore';
12040: }
12041: } else {
12042: $error = 'nonumber';
12043: }
12044: }
12045: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12046: } else {
12047: $error = 'nolock';
12048: }
12049: return ($id,$error);
12050: }
12051:
1.160.6.118.2 20(raebu 12052:24): sub modify_authordefaults {
12053:24): my ($dom,$lastactref,%domconfig) = @_;
12054:24): #
12055:24): # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
12056:24): #
12057:24): my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
12058:24): if (ref($domconfig{'quotas'}) eq 'HASH') {
12059:24): foreach my $key (keys(%{$domconfig{'quotas'}})) {
12060:24): if ($key =~ /^webdav|authorquota$/) {
12061:24): $curr_quotas{$key} = $domconfig{'quotas'}{$key};
12062:24): } else {
12063:24): $save_quotas{$key} = $domconfig{'quotas'}{$key};
12064:24): }
12065:24): }
12066:24): }
12067:24): my %staticdefaults = (
12068:24): 'copyright' => 'default',
12069:24): 'sourceavail' => 'closed',
12070:24): 'nocodemirror' => 'off',
21(raebu 12071:24): 'daxecollapse' => 'off',
20(raebu 12072:24): 'domcoordacc' => 'on',
22(raebu 12073:24): 'editors' => ['edit','xml'],
20(raebu 12074:24): 'authorquota' => 500,
12075:24): 'webdav' => 0,
22(raebu 12076:24): 'archive' => 'off',
20(raebu 12077:24): );
12078:24): my %titles = &authordefaults_titles();
22(raebu 12079:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12080:24): if ($env{'form.'.$item} =~ /^(0|1)$/) {
12081:24): $confhash{$item} = $env{'form.'.$item};
12082:24): }
12083:24): }
12084:24): if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
12085:24): $confhash{'copyright'} = $1;
12086:24): }
12087:24): if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
12088:24): $confhash{'sourceavail'} = $1;
12089:24): }
12090:24): my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
12091:24): my @okeditors = ('edit','xml','daxe');
12092:24): my @editors;
12093:24): foreach my $item (@posseditors) {
12094:24): if (grep(/^\Q$item\E$/,@okeditors)) {
12095:24): push(@editors,$item);
12096:24): }
12097:24): }
12098:24): $confhash{'editors'} = \@editors;
12099:24):
12100:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12101:24): my @insttypes;
12102:24): if (ref($types) eq 'ARRAY') {
12103:24): @insttypes = @{$types};
12104:24): }
12105:24): my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
12106:24): my %webdav;
12107:24): map { $webdav{$_} = 1; } @webdavon;
12108:24): foreach my $type (@insttypes,'default') {
12109:24): my $possquota = $env{'form.authorquota_'.$type};
12110:24): if ($possquota =~ /^\d+$/) {
12111:24): $save_quotas{'authorquota'}{$type} = $possquota;
12112:24): }
12113:24): if ($webdav{$type}) {
12114:24): $save_quotas{'webdav'}{$type} = 1;
12115:24): } else {
12116:24): $save_quotas{'webdav'}{$type} = 0;
12117:24): }
12118:24): }
12119:24): if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
12120:24): $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
12121:24): }
12122:24): if (ref($domconfig{'authordefaults'}) eq 'HASH') {
22(raebu 12123:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
20(raebu 12124:24): if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
12125:24): $changes{$item} = 1;
12126:24): }
12127:24): }
12128:24): if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
12129:24): my @diffs =
12130:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12131:24): $domconfig{'authordefaults'}{'editors'});
12132:24): unless (@diffs == 0) {
12133:24): $changes{'editors'} = 1;
12134:24): }
12135:24): } else {
12136:24): my @diffs =
12137:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12138:24): $staticdefaults{'editors'});
12139:24): unless (@diffs == 0) {
12140:24): $changes{'editors'} = 1;
12141:24): }
12142:24): }
12143:24): } else {
12144:24): my @offon = ('off','on');
22(raebu 12145:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12146:24): if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
12147:24): $changes{$item} = 1;
12148:24): }
12149:24): }
12150:24): foreach my $item ('copyright','sourceavail') {
12151:24): if ($confhash{$item} ne $staticdefaults{$item}) {
12152:24): $changes{$item} = 1;
12153:24): }
12154:24): }
22(raebu 12155:24): my @diffs =
12156:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12157:24): $staticdefaults{'editors'});
12158:24): unless (@diffs == 0) {
12159:24): $changes{'editors'} = 1;
12160:24): }
20(raebu 12161:24): }
12162:24): foreach my $key ('authorquota','webdav') {
12163:24): if (ref($curr_quotas{$key}) eq 'HASH') {
12164:24): foreach my $type (@insttypes,'default') {
12165:24): if (exists($save_quotas{$key}{$type})) {
12166:24): if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
12167:24): $changes{$key}{$type} = 1;
12168:24): }
12169:24): } elsif (exists($curr_quotas{$key}{$type})) {
12170:24): $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
12171:24): } else {
12172:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12173:24): }
12174:24): }
12175:24): } else {
12176:24): foreach my $type (@insttypes,'default') {
12177:24): if (exists($save_quotas{$key}{$type})) {
12178:24): unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
12179:24): $changes{$key}{$type} = 1;
12180:24): }
12181:24): } else {
12182:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12183:24): }
12184:24): }
12185:24): }
12186:24): }
12187:24): if (ref($curr_quotas{'webdav'}) eq 'HASH') {
12188:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12189:24): if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
12190:24): $changes{'webdav_LC_adv'} = 1;
12191:24): }
12192:24): } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
12193:24): $changes{'webdav_LC_adv'} = 1;
12194:24): }
12195:24): } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12196:24): $changes{'webdav_LC_adv'} = 1;
12197:24): }
12198:24): my %confighash = (
12199:24): quotas => \%save_quotas,
12200:24): authordefaults => \%confhash,
12201:24): );
12202:24): my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
12203:24): $dom);
12204:24): my $resulttext;
12205:24): if ($putresult eq 'ok') {
12206:24): if (keys(%changes)) {
12207:24): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12208:24): if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
12209:24): ($changes{'webdav_LC_adv'})) {
12210:24): if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
12211:24): $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
12212:24): }
12213:24): if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
12214:24): (ref($save_quotas{'webdav'}) eq 'HASH')) {
12215:24): $domdefaults{'webdav'} = $save_quotas{'webdav'};
12216:24): }
12217:24): }
12218:24): $resulttext = &mt('Changes made:').'<ul>';
12219:24): my $authoroverride;
21(raebu 12220:24): foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
20(raebu 12221:24): if (exists($changes{$key})) {
12222:24): $domdefaults{$key} = $confhash{$key};
12223:24): my $shown;
12224:24): unless ($authoroverride) {
12225:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
12226:24): $authoroverride = 1;
12227:24): }
21(raebu 12228:24): if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
20(raebu 12229:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
12230:24): } elsif ($key eq 'copyright') {
12231:24): $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
12232:24): } elsif ($key eq 'sourceavail') {
12233:24): $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
12234:24): }
12235:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12236:24): }
12237:24): }
12238:24): if ($authoroverride) {
12239:24): $resulttext .= '</ul></li>';
12240:24): }
12241:24): my $domcoordoverride;
22(raebu 12242:24): foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
20(raebu 12243:24): if (exists($changes{$key})) {
12244:24): my $shown;
12245:24): unless ($domcoordoverride) {
12246:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
12247:24): $domcoordoverride = 1;
12248:24): }
12249:24): if ($key eq 'editors') {
12250:24): if (ref($confhash{'editors'}) eq 'ARRAY') {
12251:24): $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
12252:24): if (@{$confhash{'editors'}}) {
12253:24): $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
12254:24): } else {
12255:24): $shown = &mt('None');
12256:24): }
12257:24): }
12258:24): } elsif ($key eq 'authorquota') {
12259:24): foreach my $type (@insttypes) {
12260:24): $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
12261:24): }
12262:24): $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
12263:24): } elsif ($key eq 'webdav') {
12264:24): foreach my $type (@insttypes) {
12265:24): $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
12266:24): }
12267:24): $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
12268:24): } elsif ($key eq 'webdav_LC_adv') {
12269:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12270:24): $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
12271:24): } else {
12272:24): $shown = $titles{'none'};
12273:24): }
22(raebu 12274:24): } elsif ($key eq 'archive') {
12275:24): $domdefaults{$key} = $confhash{$key};
12276:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
20(raebu 12277:24): }
12278:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12279:24): }
12280:24): }
12281:24): if ($domcoordoverride) {
12282:24): $resulttext .= '</ul></li>';
12283:24): }
22(raebu 12284:24): $resulttext .= '</ul>';
20(raebu 12285:24): my $cachetime = 24*60*60;
12286:24): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12287:24): if (ref($lastactref) eq 'HASH') {
12288:24): $lastactref->{'domdefaults'} = 1;
12289:24): }
12290:24): } else {
12291:24): $resulttext = &mt('No changes made to Authoring Space defaults');
12292:24): }
12293:24): }
12294:24): return $resulttext;
12295:24): }
12296:24):
1.6 raeburn 12297: sub modify_rolecolors {
1.160.6.24 raeburn 12298: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12299: my ($resulttext,%rolehash);
12300: $rolehash{'rolecolors'} = {};
1.55 raeburn 12301: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12302: if ($domconfig{'rolecolors'} eq '') {
12303: $domconfig{'rolecolors'} = {};
12304: }
12305: }
1.9 raeburn 12306: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12307: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12308: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12309: $dom);
12310: if ($putresult eq 'ok') {
12311: if (keys(%changes) > 0) {
1.41 raeburn 12312: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12313: if (ref($lastactref) eq 'HASH') {
12314: $lastactref->{'domainconfig'} = 1;
12315: }
1.6 raeburn 12316: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12317: $rolehash{'rolecolors'});
12318: } else {
12319: $resulttext = &mt('No changes made to default color schemes');
12320: }
12321: } else {
1.11 albertel 12322: $resulttext = '<span class="LC_error">'.
12323: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12324: }
12325: if ($errors) {
12326: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12327: $errors.'</ul>';
12328: }
12329: return $resulttext;
12330: }
12331:
12332: sub modify_colors {
1.9 raeburn 12333: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12334: my (%changes,%choices);
1.51 raeburn 12335: my @bgs;
1.6 raeburn 12336: my @links = ('link','alink','vlink');
1.41 raeburn 12337: my @logintext;
1.6 raeburn 12338: my @images;
12339: my $servadm = $r->dir_config('lonAdmEMail');
12340: my $errors;
1.160.6.22 raeburn 12341: my %defaults;
1.6 raeburn 12342: foreach my $role (@{$roles}) {
12343: if ($role eq 'login') {
1.12 raeburn 12344: %choices = &login_choices();
1.41 raeburn 12345: @logintext = ('textcol','bgcol');
1.12 raeburn 12346: } else {
12347: %choices = &color_font_choices();
12348: }
12349: if ($role eq 'login') {
1.41 raeburn 12350: @images = ('img','logo','domlogo','login');
1.51 raeburn 12351: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12352: } else {
12353: @images = ('img');
1.160.6.22 raeburn 12354: @bgs = ('pgbg','tabbg','sidebg');
12355: }
12356: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12357: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12358: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12359: }
12360: if ($role eq 'login') {
12361: foreach my $item (@logintext) {
1.160.6.39 raeburn 12362: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12363: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12364: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12365: }
12366: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 12367: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12368: }
12369: }
12370: } else {
1.160.6.39 raeburn 12371: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12372: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12373: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12374: }
12375: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 12376: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12377: }
1.6 raeburn 12378: }
1.160.6.22 raeburn 12379: foreach my $item (@bgs) {
1.160.6.39 raeburn 12380: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12381: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12382: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12383: }
12384: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 12385: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12386: }
12387: }
12388: foreach my $item (@links) {
1.160.6.39 raeburn 12389: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12390: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12391: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12392: }
12393: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 12394: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12395: }
1.6 raeburn 12396: }
1.46 raeburn 12397: my ($configuserok,$author_ok,$switchserver) =
12398: &config_check($dom,$confname,$servadm);
1.9 raeburn 12399: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12400: if (ref($domconfig->{$role}) ne 'HASH') {
12401: $domconfig->{$role} = {};
12402: }
1.8 raeburn 12403: foreach my $img (@images) {
1.160.6.118.2 2(raebur 12404:2): if ($role eq 'login') {
12405:2): if (($img eq 'img') || ($img eq 'logo')) {
12406:2): if (defined($env{'form.login_showlogo_'.$img})) {
12407:2): $confhash->{$role}{'showlogo'}{$img} = 1;
12408:2): } else {
12409:2): $confhash->{$role}{'showlogo'}{$img} = 0;
12410:2): }
1.70 raeburn 12411: }
1.160.6.118.2 2(raebur 12412:2): if ($env{'form.login_alt_'.$img} ne '') {
12413:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
12414:2): }
12415:2): }
1.18 albertel 12416: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12417: && !defined($domconfig->{$role}{$img})
12418: && !$env{'form.'.$role.'_del_'.$img}
12419: && $env{'form.'.$role.'_import_'.$img}) {
12420: # import the old configured image from the .tab setting
12421: # if they haven't provided a new one
12422: $domconfig->{$role}{$img} =
12423: $env{'form.'.$role.'_import_'.$img};
12424: }
1.6 raeburn 12425: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12426: my $error;
1.6 raeburn 12427: if ($configuserok eq 'ok') {
1.9 raeburn 12428: if ($switchserver) {
1.12 raeburn 12429: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12430: } else {
12431: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12432:23): my $modified = [];
1.9 raeburn 12433: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12434:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
12435:23): $dom,$confname,$img,$width,$height,
12436:23): '',$modified);
1.9 raeburn 12437: if ($result eq 'ok') {
12438: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12439: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12440:23): &update_modify_urls($r,$modified);
1.9 raeburn 12441: } else {
1.12 raeburn 12442: $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 12443: }
12444: } else {
1.46 raeburn 12445: $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 12446: }
12447: }
12448: } else {
1.46 raeburn 12449: $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 12450: }
12451: if ($error) {
1.8 raeburn 12452: &Apache::lonnet::logthis($error);
1.11 albertel 12453: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12454: }
12455: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12456: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12457: my $error;
12458: if ($configuserok eq 'ok') {
12459: # is confname an author?
12460: if ($switchserver eq '') {
12461: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12462:23): my $modified = [];
1.9 raeburn 12463: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12464:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
12465:23): $dom,$confname,$img,$width,$height,
12466:23): '',$modified);
1.9 raeburn 12467: if ($result eq 'ok') {
12468: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12469: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12470:23): &update_modify_urls($r,$modified);
1.9 raeburn 12471: }
12472: }
12473: }
12474: }
1.6 raeburn 12475: }
12476: }
12477: }
12478: if (ref($domconfig) eq 'HASH') {
12479: if (ref($domconfig->{$role}) eq 'HASH') {
12480: foreach my $img (@images) {
12481: if ($domconfig->{$role}{$img} ne '') {
12482: if ($env{'form.'.$role.'_del_'.$img}) {
12483: $confhash->{$role}{$img} = '';
1.12 raeburn 12484: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12485: } else {
1.9 raeburn 12486: if ($confhash->{$role}{$img} eq '') {
12487: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12488: }
1.6 raeburn 12489: }
12490: } else {
12491: if ($env{'form.'.$role.'_del_'.$img}) {
12492: $confhash->{$role}{$img} = '';
1.12 raeburn 12493: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12494: }
12495: }
1.160.6.118.2 2(raebur 12496:2): if ($role eq 'login') {
12497:2): if (($img eq 'logo') || ($img eq 'img')) {
12498:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12499:2): if ($confhash->{$role}{'showlogo'}{$img} ne
12500:2): $domconfig->{$role}{'showlogo'}{$img}) {
12501:2): $changes{$role}{'showlogo'}{$img} = 1;
12502:2): }
12503:2): } else {
12504:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12505:2): $changes{$role}{'showlogo'}{$img} = 1;
12506:2): }
1.70 raeburn 12507: }
1.160.6.118.2 2(raebur 12508:2): }
12509:2): if ($img ne 'login') {
12510:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
12511:2): if ($confhash->{$role}{'alttext'}{$img} ne
12512:2): $domconfig->{$role}{'alttext'}{$img}) {
12513:2): $changes{$role}{'alttext'}{$img} = 1;
12514:2): }
12515:2): } else {
12516:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12517:2): $changes{$role}{'alttext'}{$img} = 1;
12518:2): }
1.70 raeburn 12519: }
12520: }
12521: }
12522: }
1.6 raeburn 12523: if ($domconfig->{$role}{'font'} ne '') {
12524: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12525: $changes{$role}{'font'} = 1;
12526: }
12527: } else {
12528: if ($confhash->{$role}{'font'}) {
12529: $changes{$role}{'font'} = 1;
12530: }
12531: }
1.107 raeburn 12532: if ($role ne 'login') {
12533: if ($domconfig->{$role}{'fontmenu'} ne '') {
12534: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12535: $changes{$role}{'fontmenu'} = 1;
12536: }
12537: } else {
12538: if ($confhash->{$role}{'fontmenu'}) {
12539: $changes{$role}{'fontmenu'} = 1;
12540: }
1.97 tempelho 12541: }
12542: }
1.6 raeburn 12543: foreach my $item (@bgs) {
12544: if ($domconfig->{$role}{$item} ne '') {
12545: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12546: $changes{$role}{'bgs'}{$item} = 1;
12547: }
12548: } else {
12549: if ($confhash->{$role}{$item}) {
12550: $changes{$role}{'bgs'}{$item} = 1;
12551: }
12552: }
12553: }
12554: foreach my $item (@links) {
12555: if ($domconfig->{$role}{$item} ne '') {
12556: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12557: $changes{$role}{'links'}{$item} = 1;
12558: }
12559: } else {
12560: if ($confhash->{$role}{$item}) {
12561: $changes{$role}{'links'}{$item} = 1;
12562: }
12563: }
12564: }
1.41 raeburn 12565: foreach my $item (@logintext) {
12566: if ($domconfig->{$role}{$item} ne '') {
12567: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12568: $changes{$role}{'logintext'}{$item} = 1;
12569: }
12570: } else {
12571: if ($confhash->{$role}{$item}) {
12572: $changes{$role}{'logintext'}{$item} = 1;
12573: }
12574: }
12575: }
1.6 raeburn 12576: } else {
12577: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12578: \@logintext,$confhash,\%changes);
1.6 raeburn 12579: }
12580: } else {
12581: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12582: \@logintext,$confhash,\%changes);
1.6 raeburn 12583: }
12584: }
12585: return ($errors,%changes);
12586: }
12587:
1.46 raeburn 12588: sub config_check {
12589: my ($dom,$confname,$servadm) = @_;
12590: my ($configuserok,$author_ok,$switchserver,%currroles);
12591: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12592: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12593: $confname,$servadm);
12594: if ($configuserok eq 'ok') {
12595: $switchserver = &check_switchserver($dom,$confname);
12596: if ($switchserver eq '') {
12597: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12598: }
12599: }
12600: return ($configuserok,$author_ok,$switchserver);
12601: }
12602:
1.6 raeburn 12603: sub default_change_checker {
1.41 raeburn 12604: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12605: foreach my $item (@{$links}) {
12606: if ($confhash->{$role}{$item}) {
12607: $changes->{$role}{'links'}{$item} = 1;
12608: }
12609: }
12610: foreach my $item (@{$bgs}) {
12611: if ($confhash->{$role}{$item}) {
12612: $changes->{$role}{'bgs'}{$item} = 1;
12613: }
12614: }
1.41 raeburn 12615: foreach my $item (@{$logintext}) {
12616: if ($confhash->{$role}{$item}) {
12617: $changes->{$role}{'logintext'}{$item} = 1;
12618: }
12619: }
1.6 raeburn 12620: foreach my $img (@{$images}) {
12621: if ($env{'form.'.$role.'_del_'.$img}) {
12622: $confhash->{$role}{$img} = '';
1.12 raeburn 12623: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12624: }
1.70 raeburn 12625: if ($role eq 'login') {
12626: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12627: $changes->{$role}{'showlogo'}{$img} = 1;
12628: }
1.160.6.118.2 2(raebur 12629:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
12630:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12631:2): $changes->{$role}{'alttext'}{$img} = 1;
12632:2): }
12633:2): }
1.70 raeburn 12634: }
1.6 raeburn 12635: }
12636: if ($confhash->{$role}{'font'}) {
12637: $changes->{$role}{'font'} = 1;
12638: }
1.48 raeburn 12639: }
1.6 raeburn 12640:
12641: sub display_colorchgs {
12642: my ($dom,$changes,$roles,$confhash) = @_;
12643: my (%choices,$resulttext);
12644: if (!grep(/^login$/,@{$roles})) {
12645: $resulttext = &mt('Changes made:').'<br />';
12646: }
12647: foreach my $role (@{$roles}) {
12648: if ($role eq 'login') {
12649: %choices = &login_choices();
12650: } else {
12651: %choices = &color_font_choices();
12652: }
12653: if (ref($changes->{$role}) eq 'HASH') {
12654: if ($role ne 'login') {
12655: $resulttext .= '<h4>'.&mt($role).'</h4>';
12656: }
12657: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12658: if ($role ne 'login') {
12659: $resulttext .= '<ul>';
12660: }
12661: if (ref($changes->{$role}{$key}) eq 'HASH') {
12662: if ($role ne 'login') {
12663: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12664: }
12665: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12666: if (($role eq 'login') && ($key eq 'showlogo')) {
12667: if ($confhash->{$role}{$key}{$item}) {
12668: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12669: } else {
12670: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12671: }
1.160.6.118.2 2(raebur 12672:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
12673:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 12674:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 12675:2): $confhash->{$role}{$key}{$item}).'</li>';
12676:2): } else {
12677:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12678:2): }
1.70 raeburn 12679: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12680: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12681: } else {
1.12 raeburn 12682: my $newitem = $confhash->{$role}{$item};
12683: if ($key eq 'images') {
12684: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12685: }
12686: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12687: }
12688: }
12689: if ($role ne 'login') {
12690: $resulttext .= '</ul></li>';
12691: }
12692: } else {
12693: if ($confhash->{$role}{$key} eq '') {
12694: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12695: } else {
12696: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12697: }
12698: }
12699: if ($role ne 'login') {
12700: $resulttext .= '</ul>';
12701: }
12702: }
12703: }
12704: }
1.3 raeburn 12705: return $resulttext;
1.1 raeburn 12706: }
12707:
1.9 raeburn 12708: sub thumb_dimensions {
12709: return ('200','50');
12710: }
12711:
1.16 raeburn 12712: sub check_dimensions {
12713: my ($inputfile) = @_;
12714: my ($fullwidth,$fullheight);
12715: if ($inputfile =~ m|^[/\w.\-]+$|) {
12716: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12717: my $imageinfo = <PIPE>;
12718: if (!close(PIPE)) {
12719: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12720: }
12721: chomp($imageinfo);
12722: my ($fullsize) =
1.21 raeburn 12723: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12724: if ($fullsize) {
12725: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12726: }
12727: }
12728: }
12729: return ($fullwidth,$fullheight);
12730: }
12731:
1.9 raeburn 12732: sub check_configuser {
12733: my ($uhome,$dom,$confname,$servadm) = @_;
12734: my ($configuserok,%currroles);
12735: if ($uhome eq 'no_host') {
12736: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 12737: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12738: $configuserok =
12739: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12740: $configpass,'','','','','',undef,$servadm);
12741: } else {
12742: $configuserok = 'ok';
12743: %currroles =
12744: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12745: }
12746: return ($configuserok,%currroles);
12747: }
12748:
12749: sub check_authorstatus {
12750: my ($dom,$confname,%currroles) = @_;
12751: my $author_ok;
1.40 raeburn 12752: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12753: my $start = time;
12754: my $end = 0;
12755: $author_ok =
12756: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12757: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12758: } else {
12759: $author_ok = 'ok';
12760: }
12761: return $author_ok;
12762: }
12763:
1.160.6.118.2 14(raebu 12764:23): sub update_modify_urls {
12765:23): my ($r,$modified) = @_;
12766:23): if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12767:23): push(@{$modified_urls},$modified);
12768:23): unless ($registered_cleanup) {
12769:23): my $handlers = $r->get_handlers('PerlCleanupHandler');
12770:23): $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12771:23): $registered_cleanup=1;
1.9 raeburn 12772: }
12773: }
1.155 raeburn 12774: }
12775:
12776: sub notifysubscribed {
12777: foreach my $targetsource (@{$modified_urls}){
12778: next unless (ref($targetsource) eq 'ARRAY');
12779: my ($target,$source)=@{$targetsource};
12780: if ($source ne '') {
1.160.6.88 raeburn 12781: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12782: print $logfh "\nCleanup phase: Notifications\n";
12783: my @subscribed=&subscribed_hosts($target);
12784: foreach my $subhost (@subscribed) {
12785: print $logfh "\nNotifying host ".$subhost.':';
12786: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12787: print $logfh $reply;
12788: }
12789: my @subscribedmeta=&subscribed_hosts("$target.meta");
12790: foreach my $subhost (@subscribedmeta) {
12791: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12792: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12793: $subhost);
12794: print $logfh $reply;
12795: }
12796: print $logfh "\n============ Done ============\n";
1.160 raeburn 12797: close($logfh);
1.155 raeburn 12798: }
12799: }
12800: }
12801: return OK;
12802: }
12803:
12804: sub subscribed_hosts {
12805: my ($target) = @_;
12806: my @subscribed;
1.160.6.88 raeburn 12807: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12808: while (my $subline=<$fh>) {
12809: if ($subline =~ /^($match_lonid):/) {
12810: my $host = $1;
12811: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12812: unless (grep(/^\Q$host\E$/,@subscribed)) {
12813: push(@subscribed,$host);
12814: }
12815: }
12816: }
12817: }
12818: }
12819: return @subscribed;
1.9 raeburn 12820: }
12821:
12822: sub check_switchserver {
12823: my ($dom,$confname) = @_;
1.160.6.118.2 14(raebu 12824:23): my ($allowed,$switchserver,$home);
12825:23): if ($confname eq '') {
1.9 raeburn 12826: $home = &Apache::lonnet::domain($dom,'primary');
1.160.6.118.2 14(raebu 12827:23): } else {
12828:23): $home = &Apache::lonnet::homeserver($confname,$dom);
12829:23): if ($home eq 'no_host') {
12830:23): $home = &Apache::lonnet::domain($dom,'primary');
12831:23): }
1.9 raeburn 12832: }
12833: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12834: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12835: if (!$allowed) {
1.160.6.118.2 14(raebu 12836:23): $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12837:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12838:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12839: }
12840: return $switchserver;
12841: }
12842:
1.1 raeburn 12843: sub modify_quotas {
1.160.6.30 raeburn 12844: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12845: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 12846: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 12847: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12848: $validationfieldsref);
1.86 raeburn 12849: if ($action eq 'quotas') {
1.160.6.118.2 20(raebu 12850:24): $context = 'tools';
1.160.6.26 raeburn 12851: } else {
1.86 raeburn 12852: $context = $action;
12853: }
12854: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 12855:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 12856: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12857: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12858: %titles = &courserequest_titles();
12859: $toolregexp = join('|',@usertools);
12860: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 12861: $confname = $dom.'-domainconfig';
12862: my $servadm = $r->dir_config('lonAdmEMail');
12863: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 12864: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12865: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 12866: } elsif ($context eq 'requestauthor') {
12867: @usertools = ('author');
12868: %titles = &authorrequest_titles();
1.86 raeburn 12869: } else {
1.160.6.118.2 20(raebu 12870:24): @usertools = ('aboutme','blog','portfolio','timezone');
1.101 raeburn 12871: %titles = &tool_titles();
1.86 raeburn 12872: }
1.160.6.27 raeburn 12873: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12874: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12875: foreach my $key (keys(%env)) {
1.101 raeburn 12876: if ($context eq 'requestcourses') {
12877: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12878: my $item = $1;
12879: my $type = $2;
12880: if ($type =~ /^limit_(.+)/) {
12881: $limithash{$item}{$1} = $env{$key};
12882: } else {
12883: $confhash{$item}{$type} = $env{$key};
12884: }
12885: }
1.160.6.5 raeburn 12886: } elsif ($context eq 'requestauthor') {
12887: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12888: $confhash{$1} = $env{$key};
12889: }
1.101 raeburn 12890: } else {
1.86 raeburn 12891: if ($key =~ /^form\.quota_(.+)$/) {
12892: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 12893: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12894: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12895: }
1.72 raeburn 12896: }
12897: }
1.160.6.5 raeburn 12898: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 12899: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12900: @approvalnotify = sort(@approvalnotify);
12901: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.118.2 14(raebu 12902:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.30 raeburn 12903: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12904: foreach my $type (@hasuniquecode) {
12905: if (grep(/^\Q$type\E$/,@crstypes)) {
12906: $confhash{'uniquecode'}{$type} = 1;
12907: }
12908: }
1.160.6.46 raeburn 12909: my (%newbook,%allpos);
1.160.6.30 raeburn 12910: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12911: foreach my $type ('textbooks','templates') {
12912: @{$allpos{$type}} = ();
12913: my $invalid;
12914: if ($type eq 'textbooks') {
12915: $invalid = &mt('Invalid LON-CAPA course for textbook');
12916: } else {
12917: $invalid = &mt('Invalid LON-CAPA course for template');
12918: }
12919: if ($env{'form.'.$type.'_addbook'}) {
12920: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12921: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12922: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12923: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12924: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12925: } else {
12926: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12927: my $position = $env{'form.'.$type.'_addbook_pos'};
12928: $position =~ s/\D+//g;
12929: if ($position ne '') {
12930: $allpos{$type}[$position] = $newbook{$type};
12931: }
1.160.6.30 raeburn 12932: }
1.160.6.46 raeburn 12933: } else {
12934: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 12935: }
12936: }
1.160.6.46 raeburn 12937: }
1.160.6.30 raeburn 12938: }
1.102 raeburn 12939: if (ref($domconfig{$action}) eq 'HASH') {
12940: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12941: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12942: $changes{'notify'}{'approval'} = 1;
12943: }
12944: } else {
1.144 raeburn 12945: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12946: $changes{'notify'}{'approval'} = 1;
12947: }
12948: }
1.160.6.30 raeburn 12949: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12950: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12951: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12952: unless ($confhash{'uniquecode'}{$crstype}) {
12953: $changes{'uniquecode'} = 1;
12954: }
12955: }
12956: unless ($changes{'uniquecode'}) {
12957: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12958: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12959: $changes{'uniquecode'} = 1;
12960: }
12961: }
12962: }
12963: } else {
12964: $changes{'uniquecode'} = 1;
12965: }
12966: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12967: $changes{'uniquecode'} = 1;
12968: }
12969: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12970: foreach my $type ('textbooks','templates') {
12971: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12972: my %deletions;
12973: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12974: if (@todelete) {
12975: map { $deletions{$_} = 1; } @todelete;
12976: }
12977: my %imgdeletions;
12978: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12979: if (@todeleteimages) {
12980: map { $imgdeletions{$_} = 1; } @todeleteimages;
12981: }
12982: my $maxnum = $env{'form.'.$type.'_maxnum'};
12983: for (my $i=0; $i<=$maxnum; $i++) {
12984: my $itemid = $env{'form.'.$type.'_id_'.$i};
12985: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12986: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12987: if ($deletions{$key}) {
12988: if ($domconfig{$action}{$type}{$key}{'image'}) {
12989: #FIXME need to obsolete item in RES space
12990: }
12991: next;
12992: } else {
12993: my $newpos = $env{'form.'.$itemid};
12994: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 12995: foreach my $item ('subject','title','publisher','author') {
12996: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12997: ($type eq 'templates'));
1.160.6.46 raeburn 12998: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12999: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13000: $changes{$type}{$key} = 1;
13001: }
13002: }
13003: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 13004: }
1.160.6.46 raeburn 13005: if ($imgdeletions{$key}) {
13006: $changes{$type}{$key} = 1;
13007: #FIXME need to obsolete item in RES space
13008: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13009: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 13010: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13011: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13012: } else {
13013: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13014: $cdom,$cnum,$type,$configuserok,
13015: $switchserver,$author_ok);
13016: if ($imgurl) {
13017: $confhash{$type}{$key}{'image'} = $imgurl;
13018: $changes{$type}{$key} = 1;
13019: }
13020: if ($error) {
13021: &Apache::lonnet::logthis($error);
13022: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13023: }
1.160.6.118.2 14(raebu 13024:23): }
1.160.6.46 raeburn 13025: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13026: $confhash{$type}{$key}{'image'} =
13027: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 13028: }
13029: }
13030: }
13031: }
13032: }
13033: }
1.102 raeburn 13034: } else {
1.144 raeburn 13035: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13036: $changes{'notify'}{'approval'} = 1;
13037: }
1.160.6.30 raeburn 13038: if (ref($confhash{'uniquecode'} eq 'HASH')) {
13039: $changes{'uniquecode'} = 1;
13040: }
13041: }
13042: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 13043: foreach my $type ('textbooks','templates') {
13044: if ($newbook{$type}) {
13045: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 13046: foreach my $item ('subject','title','publisher','author') {
13047: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13048: ($type eq 'template'));
1.160.6.46 raeburn 13049: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13050: if ($env{'form.'.$type.'_addbook_'.$item}) {
13051: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13052: }
13053: }
13054: if ($type eq 'textbooks') {
13055: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13056: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 13057: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13058: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13059: } else {
13060: my ($imageurl,$error) =
13061: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13062: $configuserok,$switchserver,$author_ok);
13063: if ($imageurl) {
13064: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13065: }
13066: if ($error) {
13067: &Apache::lonnet::logthis($error);
13068: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13069: }
1.160.6.46 raeburn 13070: }
13071: }
1.160.6.30 raeburn 13072: }
13073: }
1.160.6.46 raeburn 13074: if (@{$allpos{$type}} > 0) {
13075: my $idx = 0;
13076: foreach my $item (@{$allpos{$type}}) {
13077: if ($item ne '') {
13078: $confhash{$type}{$item}{'order'} = $idx;
13079: if (ref($domconfig{$action}) eq 'HASH') {
13080: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13081: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13082: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13083: $changes{$type}{$item} = 1;
13084: }
1.160.6.30 raeburn 13085: }
13086: }
13087: }
1.160.6.46 raeburn 13088: $idx ++;
1.160.6.30 raeburn 13089: }
13090: }
13091: }
13092: }
1.160.6.39 raeburn 13093: if (ref($validationitemsref) eq 'ARRAY') {
13094: foreach my $item (@{$validationitemsref}) {
13095: if ($item eq 'fields') {
13096: my @changed;
13097: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13098: if (@{$confhash{'validation'}{$item}} > 0) {
13099: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13100: }
1.160.6.65 raeburn 13101: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13102: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13103: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13104: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13105: $domconfig{'requestcourses'}{'validation'}{$item});
13106: } else {
13107: @changed = @{$confhash{'validation'}{$item}};
13108: }
1.160.6.39 raeburn 13109: } else {
13110: @changed = @{$confhash{'validation'}{$item}};
13111: }
13112: } else {
13113: @changed = @{$confhash{'validation'}{$item}};
13114: }
13115: if (@changed) {
13116: if ($confhash{'validation'}{$item}) {
13117: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13118: } else {
13119: $changes{'validation'}{$item} = &mt('None');
13120: }
13121: }
13122: } else {
13123: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13124: if ($item eq 'markup') {
13125: if ($env{'form.requestcourses_validation_'.$item}) {
13126: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13127: }
13128: }
1.160.6.65 raeburn 13129: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13130: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13131: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13132: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13133: }
13134: } else {
13135: if ($confhash{'validation'}{$item} ne '') {
13136: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13137: }
1.160.6.39 raeburn 13138: }
13139: } else {
13140: if ($confhash{'validation'}{$item} ne '') {
13141: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13142: }
13143: }
13144: }
13145: }
13146: }
13147: if ($env{'form.validationdc'}) {
13148: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 13149: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 13150: if (exists($domcoords{$newval})) {
13151: $confhash{'validation'}{'dc'} = $newval;
13152: }
13153: }
13154: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 13155: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13156: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13157: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13158: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13159: if ($confhash{'validation'}{'dc'} eq '') {
13160: $changes{'validation'}{'dc'} = &mt('None');
13161: } else {
13162: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13163: }
1.160.6.39 raeburn 13164: }
1.160.6.65 raeburn 13165: } elsif ($confhash{'validation'}{'dc'} ne '') {
13166: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 13167: }
13168: } elsif ($confhash{'validation'}{'dc'} ne '') {
13169: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13170: }
13171: } elsif ($confhash{'validation'}{'dc'} ne '') {
13172: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13173: }
1.160.6.65 raeburn 13174: } else {
13175: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13176: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13177: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13178: $changes{'validation'}{'dc'} = &mt('None');
13179: }
13180: }
1.160.6.39 raeburn 13181: }
13182: }
1.102 raeburn 13183: }
13184: } else {
1.86 raeburn 13185: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
13186: }
1.72 raeburn 13187: foreach my $item (@usertools) {
13188: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13189: my $unset;
1.101 raeburn 13190: if ($context eq 'requestcourses') {
1.104 raeburn 13191: $unset = '0';
13192: if ($type eq '_LC_adv') {
13193: $unset = '';
13194: }
1.101 raeburn 13195: if ($confhash{$item}{$type} eq 'autolimit') {
13196: $confhash{$item}{$type} .= '=';
13197: unless ($limithash{$item}{$type} =~ /\D/) {
13198: $confhash{$item}{$type} .= $limithash{$item}{$type};
13199: }
13200: }
1.160.6.5 raeburn 13201: } elsif ($context eq 'requestauthor') {
13202: $unset = '0';
13203: if ($type eq '_LC_adv') {
13204: $unset = '';
13205: }
1.72 raeburn 13206: } else {
1.101 raeburn 13207: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13208: $confhash{$item}{$type} = 1;
13209: } else {
13210: $confhash{$item}{$type} = 0;
13211: }
1.72 raeburn 13212: }
1.86 raeburn 13213: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 13214: if ($action eq 'requestauthor') {
13215: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13216: $changes{$type} = 1;
13217: }
13218: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13219: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13220: $changes{$item}{$type} = 1;
13221: }
13222: } else {
13223: if ($context eq 'requestcourses') {
1.104 raeburn 13224: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13225: $changes{$item}{$type} = 1;
13226: }
13227: } else {
13228: if (!$confhash{$item}{$type}) {
13229: $changes{$item}{$type} = 1;
13230: }
13231: }
13232: }
13233: } else {
13234: if ($context eq 'requestcourses') {
1.104 raeburn 13235: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13236: $changes{$item}{$type} = 1;
13237: }
1.160.6.5 raeburn 13238: } elsif ($context eq 'requestauthor') {
13239: if ($confhash{$type} ne $unset) {
13240: $changes{$type} = 1;
13241: }
1.72 raeburn 13242: } else {
13243: if (!$confhash{$item}{$type}) {
13244: $changes{$item}{$type} = 1;
13245: }
13246: }
13247: }
1.1 raeburn 13248: }
13249: }
1.160.6.5 raeburn 13250: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13251: if (ref($domconfig{'quotas'}) eq 'HASH') {
13252: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13253: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13254: if (exists($confhash{'defaultquota'}{$key})) {
13255: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13256: $changes{'defaultquota'}{$key} = 1;
13257: }
13258: } else {
13259: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13260: }
13261: }
1.86 raeburn 13262: } else {
13263: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13264: if (exists($confhash{'defaultquota'}{$key})) {
13265: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13266: $changes{'defaultquota'}{$key} = 1;
13267: }
13268: } else {
13269: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13270: }
1.1 raeburn 13271: }
13272: }
1.160.6.20 raeburn 13273: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.160.6.118.2 20(raebu 13274:24): $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
13275:24): }
13276:24): if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
13277:24): $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.160.6.20 raeburn 13278: }
1.1 raeburn 13279: }
1.86 raeburn 13280: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13281: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13282: if (ref($domconfig{'quotas'}) eq 'HASH') {
13283: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13284: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13285: $changes{'defaultquota'}{$key} = 1;
13286: }
13287: } else {
13288: if (!exists($domconfig{'quotas'}{$key})) {
13289: $changes{'defaultquota'}{$key} = 1;
13290: }
1.72 raeburn 13291: }
13292: } else {
1.86 raeburn 13293: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13294: }
1.1 raeburn 13295: }
13296: }
13297: }
1.72 raeburn 13298:
1.160.6.5 raeburn 13299: if ($context eq 'requestauthor') {
13300: $domdefaults{'requestauthor'} = \%confhash;
13301: } else {
13302: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 13303: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 13304: $domdefaults{$key} = $confhash{$key};
13305: }
1.160.6.5 raeburn 13306: }
1.72 raeburn 13307: }
1.160.6.5 raeburn 13308:
1.1 raeburn 13309: my %quotahash = (
1.86 raeburn 13310: $action => { %confhash }
1.1 raeburn 13311: );
13312: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13313: $dom);
13314: if ($putresult eq 'ok') {
13315: if (keys(%changes) > 0) {
1.72 raeburn 13316: my $cachetime = 24*60*60;
13317: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13318: if (ref($lastactref) eq 'HASH') {
13319: $lastactref->{'domdefaults'} = 1;
13320: }
1.1 raeburn 13321: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 13322: unless (($context eq 'requestcourses') ||
13323: ($context eq 'requestauthor')) {
1.86 raeburn 13324: if (ref($changes{'defaultquota'}) eq 'HASH') {
13325: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13326: foreach my $type (@{$types},'default') {
13327: if (defined($changes{'defaultquota'}{$type})) {
13328: my $typetitle = $usertypes->{$type};
13329: if ($type eq 'default') {
13330: $typetitle = $othertitle;
13331: }
1.160.6.28 raeburn 13332: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13333: }
13334: }
1.86 raeburn 13335: $resulttext .= '</ul></li>';
1.72 raeburn 13336: }
13337: }
1.80 raeburn 13338: my %newenv;
1.72 raeburn 13339: foreach my $item (@usertools) {
1.160.6.5 raeburn 13340: my (%haschgs,%inconf);
13341: if ($context eq 'requestauthor') {
13342: %haschgs = %changes;
13343: %inconf = %confhash;
13344: } else {
13345: if (ref($changes{$item}) eq 'HASH') {
13346: %haschgs = %{$changes{$item}};
13347: }
13348: if (ref($confhash{$item}) eq 'HASH') {
13349: %inconf = %{$confhash{$item}};
13350: }
13351: }
13352: if (keys(%haschgs) > 0) {
1.80 raeburn 13353: my $newacc =
13354: &Apache::lonnet::usertools_access($env{'user.name'},
13355: $env{'user.domain'},
1.86 raeburn 13356: $item,'reload',$context);
1.160.6.5 raeburn 13357: if (($context eq 'requestcourses') ||
13358: ($context eq 'requestauthor')) {
1.108 raeburn 13359: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13360: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13361: }
13362: } else {
13363: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13364: $newenv{'environment.availabletools.'.$item} = $newacc;
13365: }
1.80 raeburn 13366: }
1.160.6.5 raeburn 13367: unless ($context eq 'requestauthor') {
13368: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13369: }
1.72 raeburn 13370: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 13371: if ($haschgs{$type}) {
1.72 raeburn 13372: my $typetitle = $usertypes->{$type};
13373: if ($type eq 'default') {
13374: $typetitle = $othertitle;
13375: } elsif ($type eq '_LC_adv') {
13376: $typetitle = 'LON-CAPA Advanced Users';
13377: }
1.160.6.5 raeburn 13378: if ($inconf{$type}) {
1.101 raeburn 13379: if ($context eq 'requestcourses') {
13380: my $cond;
1.160.6.5 raeburn 13381: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13382: if ($1 eq '') {
13383: $cond = &mt('(Automatic processing of any request).');
13384: } else {
13385: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13386: }
13387: } else {
1.160.6.5 raeburn 13388: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13389: }
13390: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 13391: } elsif ($context eq 'requestauthor') {
13392: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13393: $titles{$inconf{$type}},$typetitle);
13394:
1.101 raeburn 13395: } else {
13396: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13397: }
1.72 raeburn 13398: } else {
1.104 raeburn 13399: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 13400: if ($inconf{$type} eq '0') {
1.104 raeburn 13401: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13402: } else {
13403: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13404: }
13405: } else {
13406: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13407: }
1.72 raeburn 13408: }
13409: }
1.26 raeburn 13410: }
1.160.6.5 raeburn 13411: unless ($context eq 'requestauthor') {
13412: $resulttext .= '</ul></li>';
13413: }
1.26 raeburn 13414: }
1.1 raeburn 13415: }
1.160.6.5 raeburn 13416: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13417: if (ref($changes{'notify'}) eq 'HASH') {
13418: if ($changes{'notify'}{'approval'}) {
13419: if (ref($confhash{'notify'}) eq 'HASH') {
13420: if ($confhash{'notify'}{'approval'}) {
13421: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13422: } else {
1.160.6.5 raeburn 13423: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13424: }
13425: }
13426: }
13427: }
13428: }
1.160.6.30 raeburn 13429: if ($action eq 'requestcourses') {
13430: my @offon = ('off','on');
13431: if ($changes{'uniquecode'}) {
13432: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13433: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13434: $resulttext .= '<li>'.
13435: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13436: '</li>';
13437: } else {
13438: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13439: '</li>';
13440: }
13441: }
1.160.6.46 raeburn 13442: foreach my $type ('textbooks','templates') {
13443: if (ref($changes{$type}) eq 'HASH') {
13444: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13445: foreach my $key (sort(keys(%{$changes{$type}}))) {
13446: my %coursehash = &Apache::lonnet::coursedescription($key);
13447: my $coursetitle = $coursehash{'description'};
13448: my $position = $confhash{$type}{$key}{'order'} + 1;
13449: $resulttext .= '<li>';
1.160.6.47 raeburn 13450: foreach my $item ('subject','title','publisher','author') {
13451: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13452: ($type eq 'templates'));
1.160.6.46 raeburn 13453: my $name = $item.':';
13454: $name =~ s/^(\w)/\U$1/;
13455: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13456: }
13457: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13458: if ($type eq 'textbooks') {
13459: if ($confhash{$type}{$key}{'image'}) {
13460: $resulttext .= ' '.&mt('Image: [_1]',
13461: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13462: ' alt="Textbook cover" />').'<br />';
13463: }
13464: }
13465: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 13466: }
1.160.6.46 raeburn 13467: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 13468: }
13469: }
1.160.6.39 raeburn 13470: if (ref($changes{'validation'}) eq 'HASH') {
13471: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13472: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13473: foreach my $item (@{$validationitemsref}) {
13474: if (exists($changes{'validation'}{$item})) {
13475: if ($item eq 'markup') {
13476: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13477: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13478: } else {
13479: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13480: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13481: }
13482: }
13483: }
13484: if (exists($changes{'validation'}{'dc'})) {
13485: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13486: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13487: }
1.160.6.118.2 22(raebu 13488:24): resulttext .= '</ul></li>';
1.160.6.39 raeburn 13489: }
13490: }
1.160.6.30 raeburn 13491: }
1.1 raeburn 13492: $resulttext .= '</ul>';
1.80 raeburn 13493: if (keys(%newenv)) {
13494: &Apache::lonnet::appenv(\%newenv);
13495: }
1.1 raeburn 13496: } else {
1.86 raeburn 13497: if ($context eq 'requestcourses') {
13498: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 13499: } elsif ($context eq 'requestauthor') {
13500: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13501: } else {
1.90 weissno 13502: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13503: }
1.1 raeburn 13504: }
13505: } else {
1.11 albertel 13506: $resulttext = '<span class="LC_error">'.
13507: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13508: }
1.160.6.30 raeburn 13509: if ($errors) {
13510: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13511: '<ul>'.$errors.'</ul></p>';
13512: }
1.3 raeburn 13513: return $resulttext;
1.1 raeburn 13514: }
13515:
1.160.6.30 raeburn 13516: sub process_textbook_image {
1.160.6.46 raeburn 13517: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 13518: my $filename = $env{'form.'.$caller.'.filename'};
13519: my ($error,$url);
13520: my ($width,$height) = (50,50);
13521: if ($configuserok eq 'ok') {
13522: if ($switchserver) {
13523: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13524: $switchserver);
13525: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 13526:23): my $modified = [];
1.160.6.30 raeburn 13527: my ($result,$imageurl) =
1.160.6.118.2 14(raebu 13528:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
13529:23): "$type/$cdom/$cnum/cover",$width,$height,
13530:23): '',$modified);
1.160.6.30 raeburn 13531: if ($result eq 'ok') {
13532: $url = $imageurl;
1.160.6.118.2 14(raebu 13533:23): &update_modify_urls($r,$modified);
1.160.6.30 raeburn 13534: } else {
13535: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13536: }
13537: } else {
13538: $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);
13539: }
13540: } else {
13541: $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);
13542: }
13543: return ($url,$error);
13544: }
13545:
1.160.6.118.2 1(raebur 13546:1): sub modify_ltitools {
13547:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14(raebu 13548:23): my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
13549:23): &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
13550:23):
1(raebur 13551:1): my $confname = $dom.'-domainconfig';
13552:1): my $servadm = $r->dir_config('lonAdmEMail');
13553:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14(raebu 13554:23):
13555:23): my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
13556:23): my $toolserror =
13557:23): &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
13558:23): $lastactref,$configuserok,$switchserver,$author_ok);
13559:23):
13560:23): my $home = &Apache::lonnet::domain($dom,'primary');
13561:23): unless (($home eq 'no_host') || ($home eq '')) {
13562:23): my @ids=&Apache::lonnet::current_machine_ids();
13563:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
13564:23): }
13565:23):
13566:23): if (keys(%ltitoolschg)) {
13567:23): foreach my $id (keys(%ltitoolschg)) {
13568:23): if (ref($ltitoolschg{$id}) eq 'HASH') {
13569:23): foreach my $inner (keys(%{$ltitoolschg{$id}})) {
13570:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13571:23): if ($is_home) {
13572:23): $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
13573:23): }
13574:23): }
1(raebur 13575:1): }
14(raebu 13576:23): }
13577:23): }
13578:23): $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
13579:23): if (keys(%ltitoolschg)) {
13580:23): %newltitools = %ltitoolschg;
13581:23): }
13582:23): }
13583:23): if (ref($domconfig{'ltitools'}) eq 'HASH') {
13584:23): foreach my $id (%{$domconfig{'ltitools'}}) {
13585:23): next if ($id !~ /^\d+$/);
13586:23): unless (exists($ltitoolschg{$id})) {
13587:23): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
13588:23): foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
13589:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13590:23): if ($is_home) {
13591:23): $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13592:23): }
13593:23): } else {
13594:23): $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13595:23): }
1(raebur 13596:1): }
14(raebu 13597:23): } else {
13598:23): $newltitools{$id} = $domconfig{'ltitools'}{$id};
1(raebur 13599:1): }
13600:1): }
14(raebu 13601:23): }
13602:23): }
13603:23): if ($toolserror) {
13604:23): $errors = '<li>'.$toolserror.'</li>';
13605:23): }
13606:23): if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
13607:23): $resulttext = &mt('No changes made.');
13608:23): if ($errors) {
13609:23): $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13610:23): $errors.'</ul>';
13611:23): }
13612:23): return $resulttext;
13613:23): }
13614:23): my %ltitoolshash = (
13615:23): $action => { %newltitools }
13616:23): );
13617:23): if (keys(%secchanges)) {
13618:23): $ltitoolshash{'toolsec'} = \%newtoolsec;
13619:23): }
13620:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
13621:23): if ($putresult eq 'ok') {
13622:23): my %keystore;
13623:23): if ($is_home) {
13624:23): my %toolsenchash = (
13625:23): $action => { %newtoolsenc }
13626:23): );
13627:23): &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13628:23): my $cachetime = 24*60*60;
13629:23): &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13630:23): &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13631:23): }
13632:23): $resulttext = &mt('Changes made:').'<ul>';
13633:23): if (keys(%secchanges) > 0) {
13634:23): $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13635:23): }
13636:23): if (keys(%ltitoolschg) > 0) {
13637:23): $resulttext .= $ltitoolsoutput;
13638:23): }
13639:23): my $cachetime = 24*60*60;
13640:23): &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13641:23): if (ref($lastactref) eq 'HASH') {
13642:23): $lastactref->{'ltitools'} = 1;
13643:23): }
13644:23): } else {
13645:23): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13646:23): }
13647:23): if ($errors) {
13648:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13649:23): $errors.'</ul></p>';
13650:23): }
13651:23): return $resulttext;
13652:23): }
13653:23):
13654:23): sub fetch_secrets {
13655:23): my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13656:23): my %keyset;
13657:23): %{$currsec} = ();
13658:23): $newsec->{'private'}{'keys'} = [];
13659:23): $newsec->{'encrypt'} = {};
13660:23): $newsec->{'rules'} = {};
13661:23): if ($context eq 'ltisec') {
13662:23): $newsec->{'linkprot'} = {};
13663:23): }
13664:23): if (ref($domconfig->{$context}) eq 'HASH') {
13665:23): %{$currsec} = %{$domconfig->{$context}};
13666:23): if ($context eq 'ltisec') {
13667:23): if (ref($currsec->{'linkprot'}) eq 'HASH') {
13668:23): foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13669:23): unless ($id =~ /^\d+$/) {
13670:23): delete($currsec->{'linkprot'}{$id});
13671:23): }
13672:23): }
1(raebur 13673:1): }
14(raebu 13674:23): }
13675:23): if (ref($currsec->{'private'}) eq 'HASH') {
13676:23): if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13677:23): $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13678:23): map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1(raebur 13679:1): }
14(raebu 13680:23): }
13681:23): }
13682:23): my @items= ('crs','dom');
13683:23): if ($context eq 'ltisec') {
13684:23): push(@items,'consumers');
13685:23): }
13686:23): foreach my $item (@items) {
13687:23): my $formelement;
13688:23): if (($context eq 'toolsec') || ($item eq 'consumers')) {
13689:23): $formelement = 'form.'.$context.'_'.$item;
13690:23): } else {
13691:23): $formelement = 'form.'.$context.'_'.$item.'linkprot';
13692:23): }
13693:23): if ($env{$formelement}) {
13694:23): $newsec->{'encrypt'}{$item} = 1;
13695:23): if (ref($currsec->{'encrypt'}) eq 'HASH') {
13696:23): unless ($currsec->{'encrypt'}{$item}) {
13697:23): $secchanges->{'encrypt'} = 1;
13698:23): }
1(raebur 13699:1): } else {
14(raebu 13700:23): $secchanges->{'encrypt'} = 1;
13701:23): }
13702:23): } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13703:23): if ($currsec->{'encrypt'}{$item}) {
13704:23): $secchanges->{'encrypt'} = 1;
1(raebur 13705:1): }
14(raebu 13706:23): }
13707:23): }
13708:23): my $secrets;
13709:23): if ($context eq 'ltisec') {
13710:23): $secrets = 'ltisecrets';
13711:23): } else {
13712:23): $secrets = 'toolsecrets';
13713:23): }
13714:23): unless (exists($currsec->{'rules'})) {
13715:23): $currsec->{'rules'} = {};
13716:23): }
13717:23): &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13718:23):
13719:23): my @ids=&Apache::lonnet::current_machine_ids();
13720:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
13721:23):
13722:23): foreach my $hostid (keys(%servers)) {
13723:23): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13724:23): my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13725:23): if (exists($env{$keyitem})) {
13726:23): $env{$keyitem} =~ s/(`)/'/g;
13727:23): if ($keyset{$hostid}) {
13728:23): if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13729:23): if ($env{$keyitem} ne '') {
13730:23): $secchanges->{'private'} = 1;
13731:23): $newkeyset->{$hostid} = $env{$keyitem};
13732:23): }
1(raebur 13733:1): }
14(raebu 13734:23): } elsif ($env{$keyitem} ne '') {
13735:23): unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13736:23): push(@{$newsec->{'private'}{'keys'}},$hostid);
1(raebur 13737:1): }
14(raebu 13738:23): $secchanges->{'private'} = 1;
13739:23): $newkeyset->{$hostid} = $env{$keyitem};
1(raebur 13740:1): }
13741:1): }
14(raebu 13742:23): }
13743:23): }
13744:23): }
13745:23):
13746:23): sub store_security {
13747:23): my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13748:23): return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13749:23): (ref($keystore) eq 'HASH'));
13750:23): if (keys(%{$secchanges})) {
13751:23): if ($secchanges->{'private'}) {
13752:23): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13753:23): foreach my $hostid (keys(%{$newkeyset})) {
13754:23): my $storehash = {
13755:23): key => $newkeyset->{$hostid},
13756:23): who => $env{'user.name'}.':'.$env{'user.domain'},
13757:23): };
13758:23): $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13759:23): $dom,$hostid);
13760:23): }
13761:23): }
13762:23): }
13763:23): }
13764:23):
13765:23): sub lti_security_results {
13766:23): my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13767:23): my $output;
13768:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13769:23): my $needs_update;
13770:23): foreach my $item (keys(%{$secchanges})) {
13771:23): if ($item eq 'encrypt') {
13772:23): $needs_update = 1;
13773:23): my %encrypted;
13774:23): if ($context eq 'lti') {
13775:23): %encrypted = (
13776:23): crs => {
13777:23): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13778:23): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13779:23): },
13780:23): dom => {
13781:23): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13782:23): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13783:23): },
13784:23): consumers => {
13785:23): on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13786:23): off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13787:23): },
13788:23): );
1(raebur 13789:1): } else {
14(raebu 13790:23): %encrypted = (
13791:23): crs => {
13792:23): on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13793:23): off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13794:23): },
13795:23): dom => {
13796:23): on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13797:23): off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13798:23): },
13799:23): );
1(raebur 13800:1): }
14(raebu 13801:23): my @types= ('crs','dom');
13802:23): if ($context eq 'lti') {
13803:23): foreach my $type (@types) {
13804:23): undef($domdefaults{'linkprotenc_'.$type});
1(raebur 13805:1): }
14(raebu 13806:23): push(@types,'consumers');
13807:23): undef($domdefaults{'ltienc_consumers'});
13808:23): } elsif ($context eq 'ltitools') {
13809:23): foreach my $type (@types) {
13810:23): undef($domdefaults{'toolenc_'.$type});
1(raebur 13811:1): }
13812:1): }
14(raebu 13813:23): foreach my $type (@types) {
13814:23): my $shown = $encrypted{$type}{'off'};
13815:23): if (ref($newsec->{$item}) eq 'HASH') {
13816:23): if ($newsec->{$item}{$type}) {
13817:23): if ($context eq 'lti') {
13818:23): if ($type eq 'consumers') {
13819:23): $domdefaults{'ltienc_consumers'} = 1;
13820:23): } else {
13821:23): $domdefaults{'linkprotenc_'.$type} = 1;
1(raebur 13822:1): }
14(raebu 13823:23): } elsif ($context eq 'ltitools') {
13824:23): $domdefaults{'toolenc_'.$type} = 1;
1(raebur 13825:1): }
14(raebu 13826:23): $shown = $encrypted{$type}{'on'};
1(raebur 13827:1): }
13828:1): }
14(raebu 13829:23): $output .= '<li>'.$shown.'</li>';
13830:23): }
13831:23): } elsif ($item eq 'rules') {
13832:23): my %titles = &Apache::lonlocal::texthash(
13833:23): min => 'Minimum password length',
13834:23): max => 'Maximum password length',
13835:23): chars => 'Required characters',
13836:23): );
13837:23): foreach my $rule ('min','max') {
13838:23): if ($newsec->{rules}{$rule} eq '') {
13839:23): if ($rule eq 'min') {
13840:23): $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13841:23): ' '.&mt('Default of [_1] will be used',
13842:23): $Apache::lonnet::passwdmin).'</li>';
13843:23): } else {
13844:23): $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13845:23): }
13846:23): } else {
13847:23): $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13848:23): }
13849:23): }
13850:23): if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13851:23): if (@{$newsec->{'rules'}{'chars'}} > 0) {
13852:23): my %rulenames = &Apache::lonlocal::texthash(
13853:23): uc => 'At least one upper case letter',
13854:23): lc => 'At least one lower case letter',
13855:23): num => 'At least one number',
13856:23): spec => 'At least one non-alphanumeric',
13857:23): );
13858:23): my $needed = '<ul><li>'.
13859:23): join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13860:23): '</li></ul>';
13861:23): $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13862:23): } else {
13863:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13864:23): }
13865:23): } else {
13866:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1(raebur 13867:1): }
14(raebu 13868:23): } elsif ($item eq 'private') {
13869:23): $needs_update = 1;
13870:23): if ($context eq 'lti') {
13871:23): undef($domdefaults{'ltiprivhosts'});
13872:23): } elsif ($context eq 'ltitools') {
13873:23): undef($domdefaults{'toolprivhosts'});
13874:23): }
13875:23): if (keys(%{$newkeyset})) {
13876:23): my @privhosts;
13877:23): foreach my $hostid (sort(keys(%{$newkeyset}))) {
13878:23): if ($keystore->{$hostid} eq 'ok') {
13879:23): $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13880:23): unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13881:23): push(@privhosts,$hostid);
13882:23): }
13883:23): }
13884:23): }
13885:23): if (@privhosts) {
13886:23): if ($context eq 'lti') {
13887:23): $domdefaults{'ltiprivhosts'} = \@privhosts;
13888:23): } elsif ($context eq 'ltitools') {
13889:23): $domdefaults{'toolprivhosts'} = \@privhosts;
1(raebur 13890:1): }
13891:1): }
13892:1): }
14(raebu 13893:23): } elsif ($item eq 'linkprot') {
13894:23): next;
18(raebu 13895:24): } elsif ($item eq 'suggested') {
13896:24): if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
13897:24): (ref($newsec->{'suggested'}) eq 'HASH')) {
13898:24): my $suggestions;
13899:24): foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
13900:24): if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
13901:24): my $name = $newsec->{'suggested'}->{$id}->{'name'};
13902:24): my $info = $newsec->{'suggested'}->{$id}->{'info'};
13903:24): $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
13904:24): &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
13905:24): '</li>';
13906:24): } else {
13907:24): $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
13908:24): $newsec->{'suggested'}->{$id}).'</li>';
13909:24): }
13910:24): }
13911:24): if ($suggestions) {
13912:24): $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
13913:24): '<ul>'.$suggestions.'</ul>'.
13914:24): '</li>';
13915:24): }
13916:24): }
14(raebu 13917:23): }
13918:23): }
13919:23): if ($needs_update) {
13920:23): my $cachetime = 24*60*60;
13921:23): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13922:23): }
13923:23): return $output;
13924:23): }
13925:23):
13926:23): sub modify_lti {
13927:23): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13928:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13929:23): my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13930:23): my (%posslti,%posslticrs,%posscrstype);
13931:23): my @courseroles = ('cc','in','ta','ep','st');
13932:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13933:23): my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13934:23): my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13935:23): my %coursetypetitles = &Apache::lonlocal::texthash (
13936:23): official => 'Official',
13937:23): unofficial => 'Unofficial',
13938:23): community => 'Community',
13939:23): textbook => 'Textbook',
13940:23): placement => 'Placement Test',
13941:23): lti => 'LTI Provider',
13942:23): );
13943:23): my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13944:23): my %lt = <i_names();
13945:23): map { $posslti{$_} = 1; } @ltiroles;
13946:23): map { $posslticrs{$_} = 1; } @lticourseroles;
13947:23): map { $posscrstype{$_} = 1; } @coursetypes;
13948:23):
13949:23): my %menutitles = <imenu_titles();
13950:23): my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13951:23):
13952:23): &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13953:23):
13954:23): my (%linkprotchg,$linkprotoutput,$is_home);
13955:23): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13956:23): \%linkprotchg,'domain');
13957:23): my $home = &Apache::lonnet::domain($dom,'primary');
13958:23): unless (($home eq 'no_host') || ($home eq '')) {
13959:23): my @ids=&Apache::lonnet::current_machine_ids();
13960:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13961:23): }
13962:23):
13963:23): if (keys(%linkprotchg)) {
13964:23): $secchanges{'linkprot'} = 1;
13965:23): my %oldlinkprot;
13966:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13967:23): %oldlinkprot = %{$currltisec{'linkprot'}};
13968:23): }
13969:23): foreach my $id (keys(%linkprotchg)) {
13970:23): if (ref($linkprotchg{$id}) eq 'HASH') {
13971:23): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13972:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13973:23): if ($is_home) {
13974:23): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13975:23): }
13976:23): }
13977:23): }
13978:23): } else {
13979:23): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
1(raebur 13980:1): }
14(raebu 13981:23): }
13982:23): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13983:23): if (keys(%linkprotchg)) {
13984:23): %{$newltisec{'linkprot'}} = %linkprotchg;
13985:23): }
13986:23): }
13987:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
18(raebu 13988:24): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
14(raebu 13989:23): next if ($id !~ /^\d+$/);
13990:23): unless (exists($linkprotchg{$id})) {
13991:23): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13992:23): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13993:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13994:23): if ($is_home) {
13995:23): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13996:23): }
13997:23): } else {
13998:23): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13999:23): }
14000:23): }
14001:23): } else {
14002:23): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
14003:23): }
1(raebur 14004:1): }
14(raebu 14005:23): }
14006:23): }
14007:23): if ($proterror) {
14008:23): $errors .= '<li>'.$proterror.'</li>';
14009:23): }
18(raebu 14010:24):
14011:24): my (%delsuggested,%suggids,@suggested);;
14012:24): if (ref($currltisec{'suggested'}) eq 'HASH') {
14013:24): my $maxnum = $env{'form.linkprot_suggested_maxnum'};
14014:24): my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
14015:24): for (my $i=0; $i<$maxnum; $i++) {
14016:24): my $itemid = $env{'form.linkprot_suggested_id_'.$i};
14017:24): $itemid =~ s/\D+//g;
14018:24): if ($itemid) {
14019:24): if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
14020:24): push(@suggested,$i);
14021:24): $suggids{$i} = $itemid;
14022:24): if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
14023:24): if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
14024:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14025:24): }
14026:24): } else {
14027:24): if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
14028:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14029:24): } else {
14030:24): $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
14031:24): $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
14032:24): $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
14033:24): $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
14034:24): if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
14035:24): ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
14036:24): $secchanges{'suggested'}{$itemid} = 1;
14037:24): }
14038:24): }
14039:24): }
14040:24): }
14041:24): }
14042:24): }
14043:24): }
14044:24): foreach my $key (keys(%delsuggested)) {
14045:24): $newltisec{'suggested'}{$key} = $delsuggested{$key};
14046:24): $secchanges{'suggested'}{$key} = 1;
14047:24): }
14048:24): if (($env{'form.linkprot_suggested_add'}) &&
14049:24): ($env{'form.linkprot_suggested_name_add'} ne '')) {
14050:24): $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
14051:24): $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
14052:24): my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
14053:24): if ($newsuggid) {
14054:24): $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
14055:24): $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
14056:24): $secchanges{'suggested'}{$newsuggid} = 1;
14057:24): } else {
14058:24): my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
14059:24): if ($errormsg) {
14060:24): $error .= ' ('.$errormsg.')';
14061:24): }
14062:24): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14063:24): }
14064:24): }
14(raebu 14065:23): my (@items,%deletions,%itemids);
14066:23): if ($env{'form.lti_add'}) {
14067:23): my $consumer = $env{'form.lti_consumer_add'};
14068:23): $consumer =~ s/(`)/'/g;
19(raebu 14069:24): ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
14(raebu 14070:23): if ($newid) {
14071:23): $itemids{'add'} = $newid;
14072:23): push(@items,'add');
14073:23): $changes{$newid} = 1;
1(raebur 14074:1): } else {
14(raebu 14075:23): my $error = &mt('Failed to acquire unique ID for new LTI configuration');
18(raebu 14076:24): if ($errormsg) {
14077:24): $error .= ' ('.$errormsg.')';
14078:24): }
1(raebur 14079:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14080:1): }
14081:1): }
14082:1): if (ref($domconfig{$action}) eq 'HASH') {
14(raebu 14083:23): my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
1(raebur 14084:1): if (@todelete) {
14085:1): map { $deletions{$_} = 1; } @todelete;
14086:1): }
14(raebu 14087:23): my $maxnum = $env{'form.lti_maxnum'};
14088:23): for (my $i=0; $i<$maxnum; $i++) {
14089:23): my $itemid = $env{'form.lti_id_'.$i};
1(raebur 14090:1): $itemid =~ s/\D+//g;
14091:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14092:1): if ($deletions{$itemid}) {
14(raebu 14093:23): $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
1(raebur 14094:1): } else {
14(raebu 14095:23): push(@items,$i);
14096:23): $itemids{$i} = $itemid;
14097:23): }
14098:23): }
14099:23): }
14100:23): }
14101:23): my (%keystore,$secstored);
14102:23): if ($is_home) {
14103:23): &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
14104:23): }
14105:23):
14106:23): my ($cipher,$privnum);
14107:23): if ((@items > 0) && ($is_home)) {
14108:23): ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
14109:23): $newltisec{'encrypt'},$keystore{$home});
14110:23): }
14111:23): foreach my $idx (@items) {
14112:23): my $itemid = $itemids{$idx};
14113:23): next unless ($itemid);
14114:23): my %currlti;
14115:23): unless ($idx eq 'add') {
14116:23): if (ref($domconfig{$action}) eq 'HASH') {
14117:23): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14118:23): %currlti = %{$domconfig{$action}{$itemid}};
14119:23): }
14120:23): }
14121:23): }
14122:23): my $position = $env{'form.lti_pos_'.$itemid};
14123:23): $position =~ s/\D+//g;
14124:23): if ($position ne '') {
14125:23): $allpos[$position] = $itemid;
14126:23): }
14127:23): foreach my $item ('consumer','lifetime','requser','crsinc') {
14128:23): my $formitem = 'form.lti_'.$item.'_'.$idx;
14129:23): $env{$formitem} =~ s/(`)/'/g;
14130:23): if ($item eq 'lifetime') {
14131:23): $env{$formitem} =~ s/[^\d.]//g;
14132:23): }
14133:23): if ($env{$formitem} ne '') {
14134:23): $confhash{$itemid}{$item} = $env{$formitem};
14135:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14136:23): if ($currlti{$item} ne $confhash{$itemid}{$item}) {
14137:23): $changes{$itemid} = 1;
14138:23): }
14139:23): }
14140:23): }
14141:23): }
14142:23): if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14143:23): $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14144:23): }
14145:23): if ($confhash{$itemid}{'requser'}) {
14146:23): if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14147:23): $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14148:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14149:23): $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14150:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14151:23): my $mapuser = $env{'form.lti_customuser_'.$idx};
14152:23): $mapuser =~ s/(`)/'/g;
14153:23): $mapuser =~ s/^\s+|\s+$//g;
14154:23): $confhash{$itemid}{'mapuser'} = $mapuser;
14155:23): }
14156:23): my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14157:23): my @makeuser;
14158:23): foreach my $ltirole (sort(@possmakeuser)) {
14159:23): if ($posslti{$ltirole}) {
14160:23): push(@makeuser,$ltirole);
14161:23): }
14162:23): }
14163:23): $confhash{$itemid}{'makeuser'} = \@makeuser;
14164:23): if (@makeuser) {
14165:23): my $lcauth = $env{'form.lti_lcauth_'.$idx};
14166:23): if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14167:23): $confhash{$itemid}{'lcauth'} = $lcauth;
14168:23): if ($lcauth ne 'internal') {
14169:23): my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14170:23): $lcauthparm =~ s/^(\s+|\s+)$//g;
14171:23): $lcauthparm =~ s/`//g;
14172:23): if ($lcauthparm ne '') {
14173:23): $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
1(raebur 14174:1): }
14175:1): }
14(raebu 14176:23): } else {
14177:23): $confhash{$itemid}{'lcauth'} = 'lti';
14178:23): }
14179:23): }
14180:23): my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14181:23): if (@possinstdata) {
14182:23): foreach my $field (@possinstdata) {
14183:23): if (exists($fieldtitles{$field})) {
14184:23): push(@{$confhash{$itemid}{'instdata'}});
14185:23): }
14186:23): }
14187:23): }
14188:23): if ($env{'form.lti_callback_'.$idx}) {
14189:23): if ($env{'form.lti_callbackparam_'.$idx}) {
14190:23): my $callback = $env{'form.lti_callbackparam_'.$idx};
14191:23): $callback =~ s/^\s+|\s+$//g;
14192:23): $confhash{$itemid}{'callback'} = $callback;
14193:23): }
14194:23): }
14195:23): foreach my $field ('topmenu','inlinemenu') {
14196:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14197:23): $confhash{$itemid}{$field} = 1;
14198:23): }
14199:23): }
14200:23): if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14201:23): $confhash{$itemid}{lcmenu} = [];
14202:23): my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14203:23): foreach my $field (@possmenu) {
14204:23): if (exists($menutitles{$field})) {
14205:23): if ($field eq 'grades') {
14206:23): next unless ($env{'form.lti_inlinemenu_'.$idx});
1(raebur 14207:1): }
14(raebu 14208:23): push(@{$confhash{$itemid}{lcmenu}},$field);
14209:23): }
14210:23): }
14211:23): }
14212:23): if ($confhash{$itemid}{'crsinc'}) {
14213:23): if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14214:23): ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14215:23): $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14216:23): } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14217:23): my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14218:23): $mapcrs =~ s/(`)/'/g;
14219:23): $mapcrs =~ s/^\s+|\s+$//g;
14220:23): $confhash{$itemid}{'mapcrs'} = $mapcrs;
14221:23): }
14222:23): my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14223:23): my @crstypes;
14224:23): foreach my $type (sort(@posstypes)) {
14225:23): if ($posscrstype{$type}) {
14226:23): push(@crstypes,$type);
14227:23): }
14228:23): }
14229:23): $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14230:23): if ($env{'form.lti_storecrs_'.$idx}) {
14231:23): $confhash{$itemid}{'storecrs'} = 1;
14232:23): }
14233:23): if ($env{'form.lti_makecrs_'.$idx}) {
14234:23): $confhash{$itemid}{'makecrs'} = 1;
14235:23): }
14236:23): foreach my $ltirole (@lticourseroles) {
14237:23): my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14238:23): if (grep(/^\Q$possrole\E$/,@courseroles)) {
14239:23): $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
1(raebur 14240:1): }
14(raebu 14241:23): }
14242:23): my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14243:23): my @selfenroll;
14244:23): foreach my $type (sort(@possenroll)) {
14245:23): if ($posslticrs{$type}) {
14246:23): push(@selfenroll,$type);
14247:23): }
14248:23): }
14249:23): $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14250:23): if ($env{'form.lti_crssec_'.$idx}) {
14251:23): if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14252:23): $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14253:23): } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14254:23): my $section = $env{'form.lti_customsection_'.$idx};
14255:23): $section =~ s/(`)/'/g;
14256:23): $section =~ s/^\s+|\s+$//g;
14257:23): if ($section ne '') {
14258:23): $confhash{$itemid}{'section'} = $section;
14259:23): }
1(raebur 14260:1): }
14(raebu 14261:23): }
14262:23): foreach my $field ('passback','roster') {
14263:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14264:23): $confhash{$itemid}{$field} = 1;
1(raebur 14265:1): }
14(raebu 14266:23): }
14267:23): if ($env{'form.lti_passback_'.$idx}) {
14268:23): if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14269:23): $confhash{$itemid}{'passbackformat'} = '1.0';
1(raebur 14270:1): } else {
14(raebu 14271:23): $confhash{$itemid}{'passbackformat'} = '1.1';
1(raebur 14272:1): }
14(raebu 14273:23): }
14274:23): }
14275:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14276:23): if ($confhash{$itemid}{'crsinc'}) {
14277:23): foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
14278:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1(raebur 14279:1): $changes{$itemid} = 1;
14280:1): }
14281:1): }
14(raebu 14282:23): unless ($changes{$itemid}) {
14283:23): if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
14284:23): if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1(raebur 14285:1): $changes{$itemid} = 1;
14286:1): }
14287:1): }
14288:1): }
14(raebu 14289:23): foreach my $field ('mapcrstype','selfenroll') {
14290:23): unless ($changes{$itemid}) {
14291:23): if (ref($currlti{$field}) eq 'ARRAY') {
14292:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14293:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14294:23): $confhash{$itemid}{$field});
14295:23): if (@diffs) {
14296:23): $changes{$itemid} = 1;
14297:23): }
14298:23): } elsif (@{$currlti{$field}} > 0) {
1(raebur 14299:1): $changes{$itemid} = 1;
14300:1): }
14(raebu 14301:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14302:23): if (@{$confhash{$itemid}{$field}} > 0) {
1(raebur 14303:1): $changes{$itemid} = 1;
14304:1): }
14305:1): }
14306:1): }
14307:1): }
14(raebu 14308:23): unless ($changes{$itemid}) {
14309:23): if (ref($currlti{'maproles'}) eq 'HASH') {
14310:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14311:23): foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
14312:23): if ($currlti{'maproles'}{$ltirole} ne
14313:23): $confhash{$itemid}{'maproles'}{$ltirole}) {
14314:23): $changes{$itemid} = 1;
14315:23): last;
1(raebur 14316:1): }
14(raebu 14317:23): }
14318:23): unless ($changes{$itemid}) {
14319:23): foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14320:23): if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14321:23): $currlti{'maproles'}{$ltirole}) {
1(raebur 14322:1): $changes{$itemid} = 1;
14(raebu 14323:23): last;
1(raebur 14324:1): }
14325:1): }
14326:1): }
14(raebu 14327:23): } elsif (keys(%{$currlti{'maproles'}}) > 0) {
14328:23): $changes{$itemid} = 1;
14329:23): }
14330:23): } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14331:23): unless ($changes{$itemid}) {
14332:23): if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
1(raebur 14333:1): $changes{$itemid} = 1;
14334:1): }
14335:1): }
14336:1): }
14337:1): }
14(raebu 14338:23): }
14339:23): unless ($changes{$itemid}) {
14340:23): foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
14341:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
14342:23): $changes{$itemid} = 1;
14343:23): }
14344:23): }
14345:23): unless ($changes{$itemid}) {
14346:23): foreach my $field ('makeuser','lcmenu') {
14347:23): if (ref($currlti{$field}) eq 'ARRAY') {
14348:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14349:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14350:23): $confhash{$itemid}{$field});
14351:23): if (@diffs) {
14352:23): $changes{$itemid} = 1;
14353:23): }
14354:23): } elsif (@{$currlti{$field}} > 0) {
14355:23): $changes{$itemid} = 1;
14356:23): }
14357:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14358:23): if (@{$confhash{$itemid}{$field}} > 0) {
14359:23): $changes{$itemid} = 1;
14360:23): }
1(raebur 14361:1): }
14362:1): }
14363:1): }
14364:1): }
14(raebu 14365:23): }
14366:23): }
14367:23): if ($is_home) {
14368:23): my $keyitem = 'form.lti_key_'.$idx;
14369:23): $env{$keyitem} =~ s/(`)/'/g;
14370:23): if ($env{$keyitem} ne '') {
14371:23): $ltienc{$itemid}{'key'} = $env{$keyitem};
14372:23): unless ($changes{$itemid}) {
14373:23): if ($currlti{'key'} ne $env{$keyitem}) {
1(raebur 14374:1): $changes{$itemid} = 1;
14375:1): }
14(raebu 14376:23): }
14377:23): }
14378:23): my $secretitem = 'form.lti_secret_'.$idx;
14379:23): $env{$secretitem} =~ s/(`)/'/g;
14380:23): if ($currlti{'usable'}) {
14381:23): if ($env{'form.lti_changesecret_'.$idx}) {
14382:23): if ($env{$secretitem} ne '') {
14383:23): if ($privnum && $cipher) {
14384:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14385:23): $confhash{$itemid}{'cipher'} = $privnum;
14386:23): } else {
14387:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14388:23): }
1(raebur 14389:1): $changes{$itemid} = 1;
14390:1): }
14(raebu 14391:23): } else {
14392:23): $ltienc{$itemid}{'secret'} = $currlti{'secret'};
14393:23): $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
1(raebur 14394:1): }
14(raebu 14395:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14396:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
14397:23): $confhash{$itemid}{'usable'} = 1;
14398:23): }
1(raebur 14399:1): }
14(raebu 14400:23): } elsif ($env{$secretitem} ne '') {
14401:23): if ($privnum && $cipher) {
14402:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14403:23): $confhash{$itemid}{'cipher'} = $privnum;
14404:23): } else {
14405:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14406:23): }
14407:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14408:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
14409:23): $confhash{$itemid}{'usable'} = 1;
1(raebur 14410:1): }
14411:1): }
14(raebu 14412:23): $changes{$itemid} = 1;
14413:23): }
14414:23): }
14415:23): unless ($changes{$itemid}) {
14416:23): foreach my $key (keys(%currlti)) {
14417:23): if (ref($currlti{$key}) eq 'HASH') {
14418:23): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
14419:23): foreach my $innerkey (keys(%{$currlti{$key}})) {
14420:23): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
1(raebur 14421:1): $changes{$itemid} = 1;
14(raebu 14422:23): last;
1(raebur 14423:1): }
14424:1): }
14(raebu 14425:23): } elsif (keys(%{$currlti{$key}}) > 0) {
14426:23): $changes{$itemid} = 1;
1(raebur 14427:1): }
14428:1): }
14(raebu 14429:23): last if ($changes{$itemid});
1(raebur 14430:1): }
14431:1): }
14432:1): }
14433:1): if (@allpos > 0) {
14434:1): my $idx = 0;
14435:1): foreach my $itemid (@allpos) {
14436:1): if ($itemid ne '') {
14437:1): $confhash{$itemid}{'order'} = $idx;
14438:1): if (ref($domconfig{$action}) eq 'HASH') {
14439:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14440:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14441:1): $changes{$itemid} = 1;
14442:1): }
14443:1): }
14444:1): }
14445:1): $idx ++;
14446:1): }
14447:1): }
14448:1): }
14(raebu 14449:23):
14450:23): if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
14451:23): return &mt('No changes made.');
14452:23): }
14453:23):
14454:23): my %ltihash = (
14455:23): $action => { %confhash }
14456:23): );
14457:23): my %ltienchash;
14458:23):
14459:23): if ($is_home) {
14460:23): %ltienchash = (
14461:23): $action => { %ltienc }
14462:23): );
14463:23): }
14464:23): if (keys(%secchanges)) {
14465:23): $ltihash{'ltisec'} = \%newltisec;
14466:23): if ($secchanges{'linkprot'}) {
14467:23): if ($is_home) {
14468:23): $ltienchash{'linkprot'} = \%newltienc;
14469:23): }
14470:23): }
14471:23): }
14472:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1(raebur 14473:1): if ($putresult eq 'ok') {
14(raebu 14474:23): if (keys(%ltienchash)) {
14475:23): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
14476:23): }
14477:23): $resulttext = &mt('Changes made:').'<ul>';
14478:23): if (keys(%secchanges) > 0) {
14479:23): $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
14480:23): if (exists($secchanges{'linkprot'})) {
14481:23): $resulttext .= $linkprotoutput;
14482:23): }
14483:23): }
1(raebur 14484:1): if (keys(%changes) > 0) {
14485:1): my $cachetime = 24*60*60;
14(raebu 14486:23): &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1(raebur 14487:1): if (ref($lastactref) eq 'HASH') {
14(raebu 14488:23): $lastactref->{'lti'} = 1;
1(raebur 14489:1): }
14490:1): my %bynum;
14491:1): foreach my $itemid (sort(keys(%changes))) {
14(raebu 14492:23): if (ref($confhash{$itemid}) eq 'HASH') {
14493:23): my $position = $confhash{$itemid}{'order'};
14494:23): $bynum{$position} = $itemid;
14495:23): }
1(raebur 14496:1): }
14497:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14498:1): my $itemid = $bynum{$pos};
14(raebu 14499:23): if (ref($confhash{$itemid}) eq 'HASH') {
14500:23): $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1(raebur 14501:1): my $position = $pos + 1;
14502:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14(raebu 14503:23): foreach my $item ('version','lifetime') {
1(raebur 14504:1): if ($confhash{$itemid}{$item} ne '') {
14505:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14506:1): }
14507:1): }
14(raebu 14508:23): if ($ltienc{$itemid}{'key'} ne '') {
14509:23): $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
14510:23): }
14511:23): if ($ltienc{$itemid}{'secret'} ne '') {
14512:23): $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1(raebur 14513:1): }
14(raebu 14514:23): if ($confhash{$itemid}{'requser'}) {
14515:23): if ($confhash{$itemid}{'callback'}) {
14516:23): $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14517:23): } else {
14518:23): $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
14519:23): }
14520:23): if ($confhash{$itemid}{'mapuser'}) {
14521:23): my $shownmapuser;
14522:23): if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14523:23): $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14524:23): } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14525:23): $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14526:23): } else {
14527:23): $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
14528:23): }
14529:23): $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
14530:23): }
14531:23): if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14532:23): if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14533:23): $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14534:23): join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14535:23): if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14536:23): $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14537:23): } else {
14538:23): $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14539:23): $confhash{$itemid}{'lcauth'});
14540:23): if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14541:23): $resulttext .= '; '.&mt('a randomly generated password will be created');
14542:23): } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14543:23): if ($confhash{$itemid}{'lcauthparm'} ne '') {
14544:23): $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14545:23): }
14546:23): } else {
14547:23): $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14548:23): }
14549:23): }
14550:23): $resulttext .= '</li>';
14551:23): } else {
14552:23): $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
1(raebur 14553:1): }
14554:1): }
14(raebu 14555:23): if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14556:23): if (@{$confhash{$itemid}{'instdata'}} > 0) {
14557:23): $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14558:23): join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
14559:23): } else {
14560:23): $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1(raebur 14561:1): }
14562:1): }
14(raebu 14563:23): foreach my $item ('topmenu','inlinemenu') {
14564:23): $resulttext .= '<li>'.$lt{$item}.': ';
14565:23): if ($confhash{$itemid}{$item}) {
14566:23): $resulttext .= &mt('Yes');
14567:23): } else {
14568:23): $resulttext .= &mt('No');
1(raebur 14569:1): }
14(raebu 14570:23): $resulttext .= '</li>';
1(raebur 14571:1): }
14(raebu 14572:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14573:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14574:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14575:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14576:23): } else {
14577:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
1(raebur 14578:1): }
14579:1): }
14(raebu 14580:23): if ($confhash{$itemid}{'crsinc'}) {
14581:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14582:23): my $rolemaps;
14583:23): foreach my $role (@ltiroles) {
14584:23): if ($confhash{$itemid}{'maproles'}{$role}) {
14585:23): $rolemaps .= (' 'x2).$role.'='.
14586:23): &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14587:23): 'Course').',';
14588:23): }
14589:23): }
14590:23): if ($rolemaps) {
14591:23): $rolemaps =~ s/,$//;
14592:23): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14593:23): }
14594:23): }
14595:23): if ($confhash{$itemid}{'mapcrs'}) {
14596:23): $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14597:23): }
14598:23): if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14599:23): if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14600:23): $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14601:23): join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14602:23): '</li>';
1(raebur 14603:1): } else {
14(raebu 14604:23): $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
1(raebur 14605:1): }
14606:1): }
14(raebu 14607:23): if ($confhash{$itemid}{'storecrs'}) {
14608:23): $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
1(raebur 14609:1): }
14(raebu 14610:23): if ($confhash{$itemid}{'makecrs'}) {
14611:23): $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
14612:23): } else {
14613:23): $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
14614:23): }
14615:23): if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14616:23): if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14617:23): $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14618:23): join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14619:23): '</li>';
14620:23): } else {
14621:23): $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14622:23): }
14623:23): }
14624:23): if ($confhash{$itemid}{'section'}) {
14625:23): if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14626:23): $resulttext .= '<li>'.&mt('User section from standard field:').
14627:23): ' (course_section_sourcedid)'.'</li>';
14628:23): } else {
14629:23): $resulttext .= '<li>'.&mt('User section from:').' '.
14630:23): $confhash{$itemid}{'section'}.'</li>';
14631:23): }
14632:23): } else {
14633:23): $resulttext .= '<li>'.&mt('No section assignment').'</li>';
14634:23): }
14635:23): foreach my $item ('passback','roster','topmenu','inlinemenu') {
14636:23): $resulttext .= '<li>'.$lt{$item}.': ';
14637:23): if ($confhash{$itemid}{$item}) {
14638:23): $resulttext .= &mt('Yes');
14639:23): if ($item eq 'passback') {
14640:23): if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14641:23): $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14642:23): } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14643:23): $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14644:23): }
14645:23): }
14646:23): } else {
14647:23): $resulttext .= &mt('No');
14648:23): }
14649:23): $resulttext .= '</li>';
14650:23): }
14651:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14652:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14653:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14654:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14655:23): } else {
14656:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14657:23): }
1(raebur 14658:1): }
14659:1): }
14660:1): }
14661:1): $resulttext .= '</ul></li>';
14662:1): }
14663:1): }
14(raebu 14664:23): if (keys(%deletions)) {
14665:23): foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
14666:23): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14667:23): }
14668:23): }
14669:23): }
14670:23): $resulttext .= '</ul>';
14671:23): if (ref($lastactref) eq 'HASH') {
18(raebu 14672:24): if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
14673:24): &Apache::lonnet::get_domain_defaults($dom,1);
14(raebu 14674:23): $lastactref->{'domdefaults'} = 1;
14675:23): }
1(raebur 14676:1): }
14677:1): } else {
14678:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14679:1): }
14680:1): if ($errors) {
14681:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14682:1): $errors.'</ul>';
14683:1): }
14684:1): return $resulttext;
14685:1): }
14686:1):
14(raebu 14687:23): sub get_priv_creds {
14688:23): my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
14689:23): my ($needenc,$cipher,$privnum);
14690:23): my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
14691:23): if (($encchg) && (ref($encrypt) eq 'HASH')) {
14692:23): $needenc = $encrypt->{'consumers'}
14693:23): } else {
14694:23): $needenc = $domdefs{'ltienc_consumers'};
14695:23): }
14696:23): if ($needenc) {
14697:23): if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
14698:23): (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
14699:23): my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
14700:23): my $privkey = $privhash{'key'};
14701:23): $privnum = $privhash{'version'};
14702:23): if (($privnum) && ($privkey ne '')) {
14703:23): $cipher = Crypt::CBC->new({'key' => $privkey,
14704:23): 'cipher' => 'DES'});
1(raebur 14705:1): }
14706:1): }
14707:1): }
14(raebu 14708:23): return ($cipher,$privnum);
1(raebur 14709:1): }
14710:1):
14(raebu 14711:23): sub get_lti_id {
18(raebu 14712:24): my ($domain,$consumer,$dbname) = @_;
14713:24): unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
14714:24): return ('','invalid db');
14715:24): }
14716:24): # get lock on db
1(raebur 14717:1): my $lockhash = {
14718:1): lock => $env{'user.name'}.
14719:1): ':'.$env{'user.domain'},
14720:1): };
14721:1): my $tries = 0;
18(raebu 14722:24): my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14723:1): my ($id,$error);
14724:1):
14725:1): while (($gotlock ne 'ok') && ($tries<10)) {
14726:1): $tries ++;
14727:1): sleep (0.1);
18(raebu 14728:24): $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14729:1): }
14730:1): if ($gotlock eq 'ok') {
18(raebu 14731:24): my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1(raebur 14732:1): if ($currids{'lock'}) {
14733:1): delete($currids{'lock'});
14734:1): if (keys(%currids)) {
14735:1): my @curr = sort { $a <=> $b } keys(%currids);
14736:1): if ($curr[-1] =~ /^\d+$/) {
14737:1): $id = 1 + $curr[-1];
14738:1): }
14739:1): } else {
14740:1): $id = 1;
14741:1): }
14742:1): if ($id) {
18(raebu 14743:24): unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1(raebur 14744:1): $error = 'nostore';
14745:1): }
14746:1): } else {
14747:1): $error = 'nonumber';
14748:1): }
14749:1): }
18(raebu 14750:24): my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1(raebur 14751:1): } else {
14752:1): $error = 'nolock';
14753:1): }
14754:1): return ($id,$error);
14755:1): }
14756:1):
1.3 raeburn 14757: sub modify_autoenroll {
1.160.6.24 raeburn 14758: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14759: my ($resulttext,%changes);
14760: my %currautoenroll;
14761: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14762: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14763: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14764: }
14765: }
14766: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14767: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14768: sender => 'Sender for notification messages',
1.160.6.68 raeburn 14769: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 14770: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14771: my @offon = ('off','on');
1.17 raeburn 14772: my $sender_uname = $env{'form.sender_uname'};
14773: my $sender_domain = $env{'form.sender_domain'};
14774: if ($sender_domain eq '') {
14775: $sender_uname = '';
14776: } elsif ($sender_uname eq '') {
14777: $sender_domain = '';
14778: }
1.129 raeburn 14779: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 14780: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14781: $autofailsafe =~ s{^\s+|\s+$}{}g;
14782: if ($autofailsafe =~ /\D/) {
14783: undef($autofailsafe);
14784: }
1.160.6.68 raeburn 14785: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 14786: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14787: $failsafe = 'off';
14788: undef($autofailsafe);
1.160.6.68 raeburn 14789: }
1.1 raeburn 14790: my %autoenrollhash = (
1.129 raeburn 14791: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14792: 'sender_uname' => $sender_uname,
14793: 'sender_domain' => $sender_domain,
14794: 'co-owners' => $coowners,
1.160.6.116 raeburn 14795: 'autofailsafe' => $autofailsafe,
14796: 'failsafe' => $failsafe,
1.1 raeburn 14797: }
14798: );
1.4 raeburn 14799: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14800: $dom);
1.1 raeburn 14801: if ($putresult eq 'ok') {
14802: if (exists($currautoenroll{'run'})) {
14803: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14804: $changes{'run'} = 1;
14805: }
14806: } elsif ($autorun) {
14807: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14808: $changes{'run'} = 1;
1.1 raeburn 14809: }
14810: }
1.17 raeburn 14811: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14812: $changes{'sender'} = 1;
14813: }
1.17 raeburn 14814: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14815: $changes{'sender'} = 1;
14816: }
1.129 raeburn 14817: if ($currautoenroll{'co-owners'} ne '') {
14818: if ($currautoenroll{'co-owners'} ne $coowners) {
14819: $changes{'coowners'} = 1;
14820: }
14821: } elsif ($coowners) {
14822: $changes{'coowners'} = 1;
1.160.6.68 raeburn 14823: }
1.160.6.116 raeburn 14824: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 14825: $changes{'autofailsafe'} = 1;
14826: }
1.160.6.116 raeburn 14827: if ($currautoenroll{'failsafe'} ne $failsafe) {
14828: $changes{'failsafe'} = 1;
14829: }
1.1 raeburn 14830: if (keys(%changes) > 0) {
14831: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14832: if ($changes{'run'}) {
1.1 raeburn 14833: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14834: }
14835: if ($changes{'sender'}) {
1.17 raeburn 14836: if ($sender_uname eq '' || $sender_domain eq '') {
14837: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14838: } else {
14839: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14840: }
1.1 raeburn 14841: }
1.129 raeburn 14842: if ($changes{'coowners'}) {
14843: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14844: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14845: if (ref($lastactref) eq 'HASH') {
14846: $lastactref->{'domainconfig'} = 1;
14847: }
1.129 raeburn 14848: }
1.160.6.68 raeburn 14849: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 14850: if ($autofailsafe ne '') {
14851: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 14852: } else {
1.160.6.116 raeburn 14853: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 14854: }
1.160.6.116 raeburn 14855: }
14856: if ($changes{'failsafe'}) {
14857: if ($failsafe eq 'off') {
14858: unless ($changes{'autofailsafe'}) {
14859: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14860: }
14861: } elsif ($failsafe eq 'zero') {
14862: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14863: } else {
14864: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14865: }
14866: }
14867: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 14868: &Apache::lonnet::get_domain_defaults($dom,1);
14869: if (ref($lastactref) eq 'HASH') {
14870: $lastactref->{'domdefaults'} = 1;
14871: }
14872: }
1.1 raeburn 14873: $resulttext .= '</ul>';
14874: } else {
14875: $resulttext = &mt('No changes made to auto-enrollment settings');
14876: }
14877: } else {
1.11 albertel 14878: $resulttext = '<span class="LC_error">'.
14879: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14880: }
1.3 raeburn 14881: return $resulttext;
1.1 raeburn 14882: }
14883:
14884: sub modify_autoupdate {
1.3 raeburn 14885: my ($dom,%domconfig) = @_;
1.1 raeburn 14886: my ($resulttext,%currautoupdate,%fields,%changes);
14887: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14888: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14889: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14890: }
14891: }
14892: my @offon = ('off','on');
14893: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 14894: run => 'Auto-update:',
14895: classlists => 'Updates to user information in classlists?',
14896: unexpired => 'Skip updates for users without active or future roles?',
14897: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 14898: );
1.44 raeburn 14899: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14900: my %fieldtitles = &Apache::lonlocal::texthash (
14901: id => 'Student/Employee ID',
1.20 raeburn 14902: permanentemail => 'E-mail address',
1.1 raeburn 14903: lastname => 'Last Name',
14904: firstname => 'First Name',
14905: middlename => 'Middle Name',
1.132 raeburn 14906: generation => 'Generation',
1.1 raeburn 14907: );
1.142 raeburn 14908: $othertitle = &mt('All users');
1.1 raeburn 14909: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14910: $othertitle = &mt('Other users');
1.1 raeburn 14911: }
14912: foreach my $key (keys(%env)) {
14913: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14914: my ($usertype,$item) = ($1,$2);
14915: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14916: if ($usertype eq 'default') {
14917: push(@{$fields{$1}},$2);
14918: } elsif (ref($types) eq 'ARRAY') {
14919: if (grep(/^\Q$usertype\E$/,@{$types})) {
14920: push(@{$fields{$1}},$2);
14921: }
14922: }
14923: }
1.1 raeburn 14924: }
14925: }
1.131 raeburn 14926: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14927: @lockablenames = sort(@lockablenames);
14928: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14929: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14930: if (@changed) {
14931: $changes{'lockablenames'} = 1;
14932: }
14933: } else {
14934: if (@lockablenames) {
14935: $changes{'lockablenames'} = 1;
14936: }
14937: }
1.1 raeburn 14938: my %updatehash = (
14939: autoupdate => { run => $env{'form.autoupdate_run'},
14940: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 14941: unexpired => $env{'form.unexpired'},
1.1 raeburn 14942: fields => {%fields},
1.131 raeburn 14943: lockablenames => \@lockablenames,
1.1 raeburn 14944: }
14945: );
1.160.6.113 raeburn 14946: my $lastactivedays;
14947: if ($env{'form.lastactive'}) {
14948: $lastactivedays = $env{'form.lastactivedays'};
14949: $lastactivedays =~ s/^\s+|\s+$//g;
14950: unless ($lastactivedays =~ /^\d+$/) {
14951: undef($lastactivedays);
14952: $env{'form.lastactive'} = 0;
14953: }
14954: }
14955: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 14956: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 14957: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 14958: if (exists($updatehash{autoupdate}{$key})) {
14959: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14960: $changes{$key} = 1;
14961: }
14962: }
14963: } elsif ($key eq 'fields') {
14964: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14965: foreach my $item (@{$types},'default') {
1.1 raeburn 14966: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14967: my $change = 0;
14968: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14969: if (!exists($fields{$item})) {
14970: $change = 1;
1.132 raeburn 14971: last;
1.1 raeburn 14972: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14973: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14974: $change = 1;
1.132 raeburn 14975: last;
1.1 raeburn 14976: }
14977: }
14978: }
14979: if ($change) {
14980: push(@{$changes{$key}},$item);
14981: }
1.26 raeburn 14982: }
1.1 raeburn 14983: }
14984: }
1.131 raeburn 14985: } elsif ($key eq 'lockablenames') {
14986: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14987: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14988: if (@changed) {
14989: $changes{'lockablenames'} = 1;
14990: }
14991: } else {
14992: if (@lockablenames) {
14993: $changes{'lockablenames'} = 1;
14994: }
14995: }
14996: }
14997: }
14998: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14999: if (@lockablenames) {
15000: $changes{'lockablenames'} = 1;
1.1 raeburn 15001: }
15002: }
1.160.6.113 raeburn 15003: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15004: if ($updatehash{'autoupdate'}{'unexpired'}) {
15005: $changes{'unexpired'} = 1;
15006: }
15007: }
15008: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15009: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15010: $changes{'lastactive'} = 1;
15011: }
15012: }
1.26 raeburn 15013: foreach my $item (@{$types},'default') {
15014: if (defined($fields{$item})) {
15015: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15016: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15017: my $change = 0;
15018: if (ref($fields{$item}) eq 'ARRAY') {
15019: foreach my $type (@{$fields{$item}}) {
15020: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15021: $change = 1;
15022: last;
15023: }
15024: }
15025: }
15026: if ($change) {
15027: push(@{$changes{'fields'}},$item);
15028: }
15029: } else {
1.26 raeburn 15030: push(@{$changes{'fields'}},$item);
15031: }
15032: } else {
15033: push(@{$changes{'fields'}},$item);
1.1 raeburn 15034: }
15035: }
15036: }
15037: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15038: $dom);
15039: if ($putresult eq 'ok') {
15040: if (keys(%changes) > 0) {
15041: $resulttext = &mt('Changes made:').'<ul>';
15042: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15043: if ($key eq 'lockablenames') {
15044: $resulttext .= '<li>';
15045: if (@lockablenames) {
15046: $usertypes->{'default'} = $othertitle;
15047: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15048: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15049: } else {
15050: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15051: }
15052: $resulttext .= '</li>';
15053: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15054: foreach my $item (@{$changes{$key}}) {
15055: my @newvalues;
15056: foreach my $type (@{$fields{$item}}) {
15057: push(@newvalues,$fieldtitles{$type});
15058: }
1.3 raeburn 15059: my $newvaluestr;
15060: if (@newvalues > 0) {
15061: $newvaluestr = join(', ',@newvalues);
15062: } else {
15063: $newvaluestr = &mt('none');
1.6 raeburn 15064: }
1.1 raeburn 15065: if ($item eq 'default') {
1.26 raeburn 15066: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15067: } else {
1.26 raeburn 15068: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15069: }
15070: }
15071: } else {
15072: my $newvalue;
15073: if ($key eq 'run') {
15074: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 15075: } elsif ($key eq 'lastactive') {
15076: $newvalue = $offon[$env{'form.lastactive'}];
15077: unless ($lastactivedays eq '') {
15078: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15079: }
1.1 raeburn 15080: } else {
15081: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15082: }
1.1 raeburn 15083: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15084: }
15085: }
15086: $resulttext .= '</ul>';
15087: } else {
1.3 raeburn 15088: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15089: }
15090: } else {
1.11 albertel 15091: $resulttext = '<span class="LC_error">'.
15092: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15093: }
1.3 raeburn 15094: return $resulttext;
1.1 raeburn 15095: }
15096:
1.125 raeburn 15097: sub modify_autocreate {
15098: my ($dom,%domconfig) = @_;
15099: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15100: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15101: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15102: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15103: }
15104: }
15105: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15106: req => 'Auto-creation of validated requests for official courses',
15107: xmldc => 'Identity of course creator of courses from XML files',
15108: );
15109: my @types = ('xml','req');
15110: foreach my $item (@types) {
15111: $newvals{$item} = $env{'form.autocreate_'.$item};
15112: $newvals{$item} =~ s/\D//g;
15113: $newvals{$item} = 0 if ($newvals{$item} eq '');
15114: }
15115: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 15116: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15117: unless (exists($domcoords{$newvals{'xmldc'}})) {
15118: $newvals{'xmldc'} = '';
15119: }
15120: %autocreatehash = (
15121: autocreate => { xml => $newvals{'xml'},
15122: req => $newvals{'req'},
15123: }
15124: );
15125: if ($newvals{'xmldc'} ne '') {
15126: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15127: }
15128: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15129: $dom);
15130: if ($putresult eq 'ok') {
15131: my @items = @types;
15132: if ($newvals{'xml'}) {
15133: push(@items,'xmldc');
15134: }
15135: foreach my $item (@items) {
15136: if (exists($currautocreate{$item})) {
15137: if ($currautocreate{$item} ne $newvals{$item}) {
15138: $changes{$item} = 1;
15139: }
15140: } elsif ($newvals{$item}) {
15141: $changes{$item} = 1;
15142: }
15143: }
15144: if (keys(%changes) > 0) {
15145: my @offon = ('off','on');
15146: $resulttext = &mt('Changes made:').'<ul>';
15147: foreach my $item (@types) {
15148: if ($changes{$item}) {
15149: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 15150: $resulttext .= '<li>'.
15151: &mt("$title{$item} set to [_1]$newtxt [_2]",
15152: '<b>','</b>').
15153: '</li>';
1.125 raeburn 15154: }
15155: }
15156: if ($changes{'xmldc'}) {
15157: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15158: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 15159: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15160: }
15161: $resulttext .= '</ul>';
15162: } else {
15163: $resulttext = &mt('No changes made to auto-creation settings');
15164: }
15165: } else {
15166: $resulttext = '<span class="LC_error">'.
15167: &mt('An error occurred: [_1]',$putresult).'</span>';
15168: }
15169: return $resulttext;
15170: }
15171:
1.23 raeburn 15172: sub modify_directorysrch {
1.160.6.81 raeburn 15173: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15174: my ($resulttext,%changes);
15175: my %currdirsrch;
15176: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15177: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15178: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15179: }
15180: }
1.160.6.72 raeburn 15181: my %title = ( available => 'Institutional directory search available',
15182: localonly => 'Other domains can search institution',
15183: lcavailable => 'LON-CAPA directory search available',
15184: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15185: searchby => 'Search types',
15186: searchtypes => 'Search latitude');
15187: my @offon = ('off','on');
1.24 raeburn 15188: my @otherdoms = ('Yes','No');
1.23 raeburn 15189:
1.25 raeburn 15190: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15191: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15192: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15193:
1.44 raeburn 15194: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15195: if (keys(%{$usertypes}) == 0) {
15196: @cansearch = ('default');
15197: } else {
15198: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15199: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15200: if (!grep(/^\Q$type\E$/,@cansearch)) {
15201: push(@{$changes{'cansearch'}},$type);
15202: }
1.23 raeburn 15203: }
1.26 raeburn 15204: foreach my $type (@cansearch) {
15205: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15206: push(@{$changes{'cansearch'}},$type);
15207: }
1.23 raeburn 15208: }
1.26 raeburn 15209: } else {
15210: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15211: }
15212: }
15213:
15214: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15215: foreach my $by (@{$currdirsrch{'searchby'}}) {
15216: if (!grep(/^\Q$by\E$/,@searchby)) {
15217: push(@{$changes{'searchby'}},$by);
15218: }
15219: }
15220: foreach my $by (@searchby) {
15221: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15222: push(@{$changes{'searchby'}},$by);
15223: }
15224: }
15225: } else {
15226: push(@{$changes{'searchby'}},@searchby);
15227: }
1.25 raeburn 15228:
15229: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15230: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15231: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15232: push(@{$changes{'searchtypes'}},$type);
15233: }
15234: }
15235: foreach my $type (@searchtypes) {
15236: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15237: push(@{$changes{'searchtypes'}},$type);
15238: }
15239: }
15240: } else {
15241: if (exists($currdirsrch{'searchtypes'})) {
15242: foreach my $type (@searchtypes) {
15243: if ($type ne $currdirsrch{'searchtypes'}) {
15244: push(@{$changes{'searchtypes'}},$type);
15245: }
15246: }
15247: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15248: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15249: }
15250: } else {
15251: push(@{$changes{'searchtypes'}},@searchtypes);
15252: }
15253: }
15254:
1.23 raeburn 15255: my %dirsrch_hash = (
15256: directorysrch => { available => $env{'form.dirsrch_available'},
15257: cansearch => \@cansearch,
1.160.6.72 raeburn 15258: localonly => $env{'form.dirsrch_instlocalonly'},
15259: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15260: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15261: searchby => \@searchby,
1.25 raeburn 15262: searchtypes => \@searchtypes,
1.23 raeburn 15263: }
15264: );
15265: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15266: $dom);
15267: if ($putresult eq 'ok') {
15268: if (exists($currdirsrch{'available'})) {
15269: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15270: $changes{'available'} = 1;
15271: }
15272: } else {
15273: if ($env{'form.dirsrch_available'} eq '1') {
15274: $changes{'available'} = 1;
15275: }
15276: }
1.160.6.72 raeburn 15277: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 15278: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15279: $changes{'lcavailable'} = 1;
15280: }
1.24 raeburn 15281: } else {
1.160.6.72 raeburn 15282: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15283: $changes{'lcavailable'} = 1;
15284: }
15285: }
15286: if (exists($currdirsrch{'localonly'})) {
15287: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 15288: $changes{'localonly'} = 1;
15289: }
1.160.6.72 raeburn 15290: } else {
15291: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
15292: $changes{'localonly'} = 1;
15293: }
15294: }
15295: if (exists($currdirsrch{'lclocalonly'})) {
15296: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15297: $changes{'lclocalonly'} = 1;
15298: }
15299: } else {
15300: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15301: $changes{'lclocalonly'} = 1;
15302: }
1.24 raeburn 15303: }
1.23 raeburn 15304: if (keys(%changes) > 0) {
15305: $resulttext = &mt('Changes made:').'<ul>';
15306: if ($changes{'available'}) {
15307: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15308: }
1.160.6.72 raeburn 15309: if ($changes{'lcavailable'}) {
15310: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15311: }
1.24 raeburn 15312: if ($changes{'localonly'}) {
1.160.6.72 raeburn 15313: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
15314: }
15315: if ($changes{'lclocalonly'}) {
15316: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 15317: }
1.23 raeburn 15318: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15319: my $chgtext;
1.26 raeburn 15320: if (ref($usertypes) eq 'HASH') {
15321: if (keys(%{$usertypes}) > 0) {
15322: foreach my $type (@{$types}) {
15323: if (grep(/^\Q$type\E$/,@cansearch)) {
15324: $chgtext .= $usertypes->{$type}.'; ';
15325: }
15326: }
15327: if (grep(/^default$/,@cansearch)) {
15328: $chgtext .= $othertitle;
15329: } else {
15330: $chgtext =~ s/\; $//;
15331: }
1.160.6.13 raeburn 15332: $resulttext .=
15333: '<li>'.
15334: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15335: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15336: '</li>';
1.23 raeburn 15337: }
15338: }
15339: }
15340: if (ref($changes{'searchby'}) eq 'ARRAY') {
15341: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15342: my $chgtext;
15343: foreach my $type (@{$titleorder}) {
15344: if (grep(/^\Q$type\E$/,@searchby)) {
15345: if (defined($searchtitles->{$type})) {
15346: $chgtext .= $searchtitles->{$type}.'; ';
15347: }
15348: }
15349: }
15350: $chgtext =~ s/\; $//;
15351: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15352: }
1.25 raeburn 15353: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15354: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15355: my $chgtext;
15356: foreach my $type (@{$srchtypeorder}) {
15357: if (grep(/^\Q$type\E$/,@searchtypes)) {
15358: if (defined($srchtypes_desc->{$type})) {
15359: $chgtext .= $srchtypes_desc->{$type}.'; ';
15360: }
15361: }
15362: }
15363: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 15364: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15365: }
15366: $resulttext .= '</ul>';
1.160.6.81 raeburn 15367: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15368: if (ref($lastactref) eq 'HASH') {
15369: $lastactref->{'directorysrch'} = 1;
15370: }
1.23 raeburn 15371: } else {
1.160.6.72 raeburn 15372: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15373: }
15374: } else {
15375: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15376: &mt('An error occurred: [_1]',$putresult).'</span>';
15377: }
15378: return $resulttext;
15379: }
15380:
1.28 raeburn 15381: sub modify_contacts {
1.160.6.24 raeburn 15382: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15383: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15384: if (ref($domconfig{'contacts'}) eq 'HASH') {
15385: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15386: $currsetting{$key} = $domconfig{'contacts'}{$key};
15387: }
15388: }
1.160.6.78 raeburn 15389: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15390: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 15391: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 15392: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 15393: my @toggles = ('reporterrors','reportupdates','reportstatus');
15394: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 15395: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15396: foreach my $type (@mailings) {
15397: @{$newsetting{$type}} =
15398: &Apache::loncommon::get_env_multiple('form.'.$type);
15399: foreach my $item (@contacts) {
15400: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15401: $contacts_hash{contacts}{$type}{$item} = 1;
15402: } else {
15403: $contacts_hash{contacts}{$type}{$item} = 0;
15404: }
1.160.6.78 raeburn 15405: }
1.28 raeburn 15406: $others{$type} = $env{'form.'.$type.'_others'};
15407: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 15408: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15409: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15410: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 15411: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15412: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15413: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15414: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15415: }
1.134 raeburn 15416: }
1.28 raeburn 15417: }
15418: foreach my $item (@contacts) {
15419: $to{$item} = $env{'form.'.$item};
15420: $contacts_hash{'contacts'}{$item} = $to{$item};
15421: }
1.160.6.23 raeburn 15422: foreach my $item (@toggles) {
15423: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15424: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15425: }
15426: }
1.160.6.107 raeburn 15427: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15428: foreach my $item (@lonstatus) {
15429: if ($item eq 'excluded') {
15430: my (%serverhomes,@excluded);
15431: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15432: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15433: if (@possexcluded) {
15434: foreach my $id (sort(@possexcluded)) {
15435: if ($serverhomes{$id}) {
15436: push(@excluded,$id);
15437: }
15438: }
15439: }
15440: if (@excluded) {
15441: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15442: }
15443: } elsif ($item eq 'weights') {
15444: foreach my $type ('E','W','N','U') {
15445: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15446: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15447: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15448: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15449: $env{'form.error'.$item.'_'.$type};
15450: }
15451: }
15452: }
15453: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15454: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15455: if ($env{'form.error'.$item} =~ /^\d+$/) {
15456: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15457: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15458: }
15459: }
15460: }
15461: }
1.160.6.78 raeburn 15462: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15463: foreach my $field (@{$fields}) {
15464: if (ref($possoptions->{$field}) eq 'ARRAY') {
15465: my $value = $env{'form.helpform_'.$field};
15466: $value =~ s/^\s+|\s+$//g;
15467: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 15468: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 15469: if ($field eq 'screenshot') {
15470: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15471: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 15472: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 15473: }
15474: }
15475: }
15476: }
15477: }
15478: }
1.160.6.101 raeburn 15479: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15480: my (@statuses,%usertypeshash,@overrides);
15481: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15482: @statuses = @{$types};
15483: if (ref($usertypes) eq 'HASH') {
15484: %usertypeshash = %{$usertypes};
15485: }
15486: }
15487: if (@statuses) {
15488: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15489: foreach my $type (@possoverrides) {
15490: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15491: push(@overrides,$type);
15492: }
15493: }
15494: if (@overrides) {
15495: foreach my $type (@overrides) {
15496: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15497: foreach my $item (@contacts) {
15498: if (grep(/^\Q$item\E$/,@standard)) {
15499: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15500: $newsetting{'override_'.$type}{$item} = 1;
15501: } else {
15502: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15503: $newsetting{'override_'.$type}{$item} = 0;
15504: }
15505: }
15506: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15507: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15508: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15509: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15510: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15511: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15512: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15513: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15514: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15515: }
1.160.6.118.2 14(raebu 15516:23): }
1.160.6.101 raeburn 15517: }
15518: }
1.28 raeburn 15519: if (keys(%currsetting) > 0) {
15520: foreach my $item (@contacts) {
15521: if ($to{$item} ne $currsetting{$item}) {
15522: $changes{$item} = 1;
15523: }
15524: }
15525: foreach my $type (@mailings) {
15526: foreach my $item (@contacts) {
15527: if (ref($currsetting{$type}) eq 'HASH') {
15528: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15529: push(@{$changes{$type}},$item);
15530: }
15531: } else {
15532: push(@{$changes{$type}},@{$newsetting{$type}});
15533: }
15534: }
15535: if ($others{$type} ne $currsetting{$type}{'others'}) {
15536: push(@{$changes{$type}},'others');
15537: }
1.160.6.78 raeburn 15538: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15539: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15540: push(@{$changes{$type}},'bcc');
15541: }
1.160.6.78 raeburn 15542: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15543: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15544: push(@{$changes{$type}},'include');
15545: }
15546: }
15547: }
15548: if (ref($fields) eq 'ARRAY') {
15549: if (ref($currsetting{'helpform'}) eq 'HASH') {
15550: foreach my $field (@{$fields}) {
15551: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15552: push(@{$changes{'helpform'}},$field);
15553: }
15554: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15555: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15556: push(@{$changes{'helpform'}},'maxsize');
15557: }
15558: }
15559: }
15560: } else {
15561: foreach my $field (@{$fields}) {
15562: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15563: push(@{$changes{'helpform'}},$field);
15564: }
15565: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15566: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15567: push(@{$changes{'helpform'}},'maxsize');
15568: }
15569: }
15570: }
1.134 raeburn 15571: }
1.28 raeburn 15572: }
1.160.6.101 raeburn 15573: if (@statuses) {
15574: if (ref($currsetting{'overrides'}) eq 'HASH') {
15575: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15576: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15577: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15578: foreach my $item (@contacts,'bcc','others','include') {
15579: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15580: push(@{$changes{'overrides'}},$key);
15581: last;
15582: }
15583: }
15584: } else {
15585: push(@{$changes{'overrides'}},$key);
15586: }
15587: }
15588: }
15589: foreach my $key (@overrides) {
15590: unless (exists($currsetting{'overrides'}{$key})) {
15591: push(@{$changes{'overrides'}},$key);
15592: }
15593: }
15594: } else {
15595: foreach my $key (@overrides) {
15596: push(@{$changes{'overrides'}},$key);
15597: }
15598: }
15599: }
1.160.6.107 raeburn 15600: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15601: foreach my $key ('excluded','weights','threshold','sysmail') {
15602: if ($key eq 'excluded') {
15603: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15604: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15605: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15606: (@{$currsetting{'lonstatus'}{$key}})) {
15607: my @diffs =
15608: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15609: $currsetting{'lonstatus'}{$key});
15610: if (@diffs) {
15611: push(@{$changes{'lonstatus'}},$key);
15612: }
15613: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15614: push(@{$changes{'lonstatus'}},$key);
15615: }
15616: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15617: (@{$currsetting{'lonstatus'}{$key}})) {
15618: push(@{$changes{'lonstatus'}},$key);
15619: }
15620: } elsif ($key eq 'weights') {
15621: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15622: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15623: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15624: foreach my $type ('E','W','N','U') {
15625: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15626: $currsetting{'lonstatus'}{$key}{$type}) {
15627: push(@{$changes{'lonstatus'}},$key);
15628: last;
15629: }
15630: }
15631: } else {
15632: foreach my $type ('E','W','N','U') {
15633: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15634: push(@{$changes{'lonstatus'}},$key);
15635: last;
15636: }
15637: }
15638: }
15639: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15640: foreach my $type ('E','W','N','U') {
15641: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15642: push(@{$changes{'lonstatus'}},$key);
15643: last;
15644: }
15645: }
15646: }
15647: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15648: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15649: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15650: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15651: push(@{$changes{'lonstatus'}},$key);
15652: }
15653: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15654: push(@{$changes{'lonstatus'}},$key);
15655: }
15656: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15657: push(@{$changes{'lonstatus'}},$key);
15658: }
15659: }
15660: }
15661: } else {
15662: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15663: foreach my $key ('excluded','weights','threshold','sysmail') {
15664: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15665: push(@{$changes{'lonstatus'}},$key);
15666: }
15667: }
15668: }
15669: }
1.28 raeburn 15670: } else {
15671: my %default;
15672: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15673: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15674: $default{'errormail'} = 'adminemail';
15675: $default{'packagesmail'} = 'adminemail';
15676: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 15677: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15678: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15679: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 15680: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 15681: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15682: foreach my $item (@contacts) {
15683: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 15684: $changes{$item} = 1;
1.160.6.23 raeburn 15685: }
1.28 raeburn 15686: }
15687: foreach my $type (@mailings) {
15688: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15689: push(@{$changes{$type}},@{$newsetting{$type}});
15690: }
15691: if ($others{$type} ne '') {
15692: push(@{$changes{$type}},'others');
1.134 raeburn 15693: }
1.160.6.78 raeburn 15694: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15695: if ($bcc{$type} ne '') {
15696: push(@{$changes{$type}},'bcc');
15697: }
1.160.6.78 raeburn 15698: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15699: push(@{$changes{$type}},'include');
15700: }
15701: }
15702: }
15703: if (ref($fields) eq 'ARRAY') {
15704: foreach my $field (@{$fields}) {
15705: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15706: push(@{$changes{'helpform'}},$field);
15707: }
15708: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15709: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15710: push(@{$changes{'helpform'}},'maxsize');
15711: }
15712: }
1.134 raeburn 15713: }
1.28 raeburn 15714: }
1.160.6.107 raeburn 15715: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15716: foreach my $key ('excluded','weights','threshold','sysmail') {
15717: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15718: push(@{$changes{'lonstatus'}},$key);
15719: }
15720: }
15721: }
1.28 raeburn 15722: }
1.160.6.23 raeburn 15723: foreach my $item (@toggles) {
15724: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15725: $changes{$item} = 1;
15726: } elsif ((!$env{'form.'.$item}) &&
15727: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15728: $changes{$item} = 1;
15729: }
15730: }
1.28 raeburn 15731: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15732: $dom);
15733: if ($putresult eq 'ok') {
15734: if (keys(%changes) > 0) {
1.160.6.24 raeburn 15735: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 15736: if (ref($lastactref) eq 'HASH') {
15737: $lastactref->{'domainconfig'} = 1;
15738: }
1.28 raeburn 15739: my ($titles,$short_titles) = &contact_titles();
15740: $resulttext = &mt('Changes made:').'<ul>';
15741: foreach my $item (@contacts) {
15742: if ($changes{$item}) {
15743: $resulttext .= '<li>'.$titles->{$item}.
15744: &mt(' set to: ').
15745: '<span class="LC_cusr_emph">'.
15746: $to{$item}.'</span></li>';
15747: }
15748: }
15749: foreach my $type (@mailings) {
15750: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 15751: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15752: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15753: } else {
15754: $resulttext .= '<li>'.$titles->{$type}.': ';
15755: }
1.28 raeburn 15756: my @text;
15757: foreach my $item (@{$newsetting{$type}}) {
15758: push(@text,$short_titles->{$item});
15759: }
15760: if ($others{$type} ne '') {
15761: push(@text,$others{$type});
15762: }
1.160.6.78 raeburn 15763: if (@text) {
15764: $resulttext .= '<span class="LC_cusr_emph">'.
15765: join(', ',@text).'</span>';
15766: }
15767: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15768: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 15769: my $bcctext;
15770: if (@text) {
15771: $bcctext = ' '.&mt('with Bcc to');
15772: } else {
15773: $bcctext = '(Bcc)';
15774: }
15775: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15776: } elsif (!@text) {
15777: $resulttext .= &mt('No one');
1.134 raeburn 15778: }
1.160.6.78 raeburn 15779: if ($includestr{$type} ne '') {
15780: if ($includeloc{$type} eq 'b') {
15781: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15782: } elsif ($includeloc{$type} eq 's') {
15783: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15784: }
15785: }
15786: } elsif (!@text) {
15787: $resulttext .= &mt('No recipients');
1.134 raeburn 15788: }
15789: $resulttext .= '</li>';
1.28 raeburn 15790: }
15791: }
1.160.6.101 raeburn 15792: if (ref($changes{'overrides'}) eq 'ARRAY') {
15793: my @deletions;
15794: foreach my $type (@{$changes{'overrides'}}) {
15795: if ($usertypeshash{$type}) {
15796: if (grep(/^\Q$type\E/,@overrides)) {
15797: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15798: $usertypeshash{$type}).'<ul><li>';
15799: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15800: my @text;
15801: foreach my $item (@contacts) {
15802: if ($newsetting{'override_'.$type}{$item}) {
15803: push(@text,$short_titles->{$item});
15804: }
15805: }
15806: if ($newsetting{'override_'.$type}{'others'} ne '') {
15807: push(@text,$newsetting{'override_'.$type}{'others'});
15808: }
15809:
15810: if (@text) {
15811: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15812: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15813: }
15814: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15815: my $bcctext;
15816: if (@text) {
15817: $bcctext = ' '.&mt('with Bcc to');
15818: } else {
15819: $bcctext = '(Bcc)';
15820: }
15821: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15822: } elsif (!@text) {
15823: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15824: }
15825: $resulttext .= '</li>';
15826: if ($newsetting{'override_'.$type}{'include'} ne '') {
15827: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15828: if ($loc eq 'b') {
15829: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15830: } elsif ($loc eq 's') {
15831: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15832: }
15833: }
15834: }
15835: $resulttext .= '</li></ul></li>';
15836: } else {
15837: push(@deletions,$usertypeshash{$type});
15838: }
15839: }
15840: }
15841: if (@deletions) {
15842: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15843: join(', ',@deletions)).'</li>';
15844: }
15845: }
1.160.6.23 raeburn 15846: my @offon = ('off','on');
1.160.6.107 raeburn 15847: my $corelink = &core_link_msu();
1.160.6.23 raeburn 15848: if ($changes{'reporterrors'}) {
15849: $resulttext .= '<li>'.
15850: &mt('E-mail error reports to [_1] set to "'.
15851: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 15852: $corelink).
1.160.6.23 raeburn 15853: '</li>';
15854: }
15855: if ($changes{'reportupdates'}) {
15856: $resulttext .= '<li>'.
15857: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15858: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 15859: $corelink).
1.160.6.23 raeburn 15860: '</li>';
15861: }
1.160.6.107 raeburn 15862: if ($changes{'reportstatus'}) {
15863: $resulttext .= '<li>'.
15864: &mt('E-mail status if errors above threshold to [_1] set to "'.
15865: $offon[$env{'form.reportstatus'}].'".',
15866: $corelink).
15867: '</li>';
15868: }
15869: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15870: $resulttext .= '<li>'.
15871: &mt('Nightly status check e-mail settings').':<ul>';
15872: my (%defval,%use_def,%shown);
15873: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15874: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15875: $defval{'weights'} =
15876: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15877: $defval{'excluded'} = &mt('None');
15878: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15879: foreach my $item ('threshold','sysmail','weights','excluded') {
15880: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15881: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15882: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15883: } elsif ($item eq 'weights') {
15884: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15885: foreach my $type ('E','W','N','U') {
15886: $shown{$item} .= $lonstatus_names->{$type}.'=';
15887: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15888: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15889: } else {
15890: $shown{$item} .= $lonstatus_defs->{$type};
15891: }
15892: $shown{$item} .= ', ';
15893: }
15894: $shown{$item} =~ s/, $//;
15895: } else {
15896: $shown{$item} = $defval{$item};
15897: }
15898: } elsif ($item eq 'excluded') {
15899: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15900: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15901: } else {
15902: $shown{$item} = $defval{$item};
15903: }
15904: }
15905: } else {
15906: $shown{$item} = $defval{$item};
15907: }
15908: }
15909: } else {
15910: foreach my $item ('threshold','weights','excluded','sysmail') {
15911: $shown{$item} = $defval{$item};
15912: }
15913: }
15914: foreach my $item ('threshold','weights','excluded','sysmail') {
15915: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15916: $shown{$item}).'</li>';
15917: }
15918: $resulttext .= '</ul></li>';
15919: }
1.160.6.78 raeburn 15920: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15921: my (@optional,@required,@unused,$maxsizechg);
15922: foreach my $field (@{$changes{'helpform'}}) {
15923: if ($field eq 'maxsize') {
15924: $maxsizechg = 1;
15925: next;
15926: }
15927: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15928: push(@optional,$field);
15929: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15930: push(@unused,$field);
15931: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15932: push(@required,$field);
15933: }
15934: }
15935: if (@optional) {
15936: $resulttext .= '<li>'.
15937: &mt('Help form fields changed to "Optional": [_1].',
15938: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15939: '</li>';
15940: }
15941: if (@required) {
15942: $resulttext .= '<li>'.
15943: &mt('Help form fields changed to "Required": [_1].',
15944: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15945: '</li>';
15946: }
15947: if (@unused) {
15948: $resulttext .= '<li>'.
15949: &mt('Help form fields changed to "Not shown": [_1].',
15950: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15951: '</li>';
15952: }
15953: if ($maxsizechg) {
15954: $resulttext .= '<li>'.
15955: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15956: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15957: '</li>';
15958: }
15959: }
1.28 raeburn 15960: $resulttext .= '</ul>';
15961: } else {
1.160.6.78 raeburn 15962: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15963: }
15964: } else {
15965: $resulttext = '<span class="LC_error">'.
1.160.6.118.2 14(raebu 15966:23): &mt('An error occurred: [_1]',$putresult).'</span>';
1.28 raeburn 15967: }
15968: return $resulttext;
15969: }
15970:
1.160.6.98 raeburn 15971: sub modify_passwords {
15972: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15973: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15974: $updatedefaults,$updateconf);
15975: my $customfn = 'resetpw.html';
15976: if (ref($domconfig{'passwords'}) eq 'HASH') {
15977: %current = %{$domconfig{'passwords'}};
15978: }
15979: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15980: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15981: if (ref($types) eq 'ARRAY') {
15982: @oktypes = @{$types};
15983: }
15984: push(@oktypes,'default');
15985:
15986: my %titles = &Apache::lonlocal::texthash (
15987: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15988: intauth_check => 'Check bcrypt cost if authenticated',
15989: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15990: permanent => 'Permanent e-mail address',
15991: critical => 'Critical notification address',
15992: notify => 'Notification address',
15993: min => 'Minimum password length',
15994: max => 'Maximum password length',
15995: chars => 'Required characters',
15996: numsaved => 'Number of previous passwords to save',
15997: reset => 'Resetting Forgotten Password',
15998: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15999: rules => 'Rules for LON-CAPA Passwords',
16000: crsownerchg => 'Course Owner Changing Student Passwords',
16001: username => 'Username',
16002: email => 'E-mail address',
16003: );
16004:
16005: #
16006: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16007: #
16008: my (%curr_defaults,%save_defaults);
16009: if (ref($domconfig{'defaults'}) eq 'HASH') {
16010: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16011: if ($key =~ /^intauth_(cost|check|switch)$/) {
16012: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16013: } else {
16014: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16015: }
16016: }
16017: }
16018: my %staticdefaults = (
16019: 'resetlink' => 2,
16020: 'resetcase' => \@oktypes,
16021: 'resetprelink' => 'both',
16022: 'resetemail' => ['critical','notify','permanent'],
16023: 'intauth_cost' => 10,
16024: 'intauth_check' => 0,
16025: 'intauth_switch' => 0,
16026: );
1.160.6.99 raeburn 16027: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 16028: foreach my $type (@oktypes) {
16029: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16030: }
16031: my $linklife = $env{'form.passwords_link'};
16032: $linklife =~ s/^\s+|\s+$//g;
16033: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16034: $newvalues{'resetlink'} = $linklife;
16035: if ($current{'resetlink'}) {
16036: if ($current{'resetlink'} ne $linklife) {
16037: $changes{'reset'} = 1;
16038: }
1.160.6.102 raeburn 16039: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16040: if ($staticdefaults{'resetlink'} ne $linklife) {
16041: $changes{'reset'} = 1;
16042: }
16043: }
16044: } elsif ($current{'resetlink'}) {
16045: $changes{'reset'} = 1;
16046: }
16047: my @casesens;
16048: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16049: foreach my $case (sort(@posscase)) {
16050: if (grep(/^\Q$case\E$/,@oktypes)) {
16051: push(@casesens,$case);
16052: }
16053: }
16054: $newvalues{'resetcase'} = \@casesens;
16055: if (ref($current{'resetcase'}) eq 'ARRAY') {
16056: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16057: if (@diffs > 0) {
16058: $changes{'reset'} = 1;
16059: }
1.160.6.102 raeburn 16060: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16061: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16062: if (@diffs > 0) {
16063: $changes{'reset'} = 1;
16064: }
16065: }
16066: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16067: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16068: if (exists($current{'resetprelink'})) {
16069: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16070: $changes{'reset'} = 1;
16071: }
1.160.6.102 raeburn 16072: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16073: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16074: $changes{'reset'} = 1;
16075: }
16076: }
16077: } elsif ($current{'resetprelink'}) {
16078: $changes{'reset'} = 1;
16079: }
16080: foreach my $type (@oktypes) {
16081: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16082: my @postlink;
16083: foreach my $item (sort(@possplink)) {
16084: if ($item =~ /^(email|username)$/) {
16085: push(@postlink,$item);
16086: }
16087: }
16088: $newvalues{'resetpostlink'}{$type} = \@postlink;
16089: unless ($changes{'reset'}) {
16090: if (ref($current{'resetpostlink'}) eq 'HASH') {
16091: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16092: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16093: if (@diffs > 0) {
16094: $changes{'reset'} = 1;
16095: }
16096: } else {
16097: $changes{'reset'} = 1;
16098: }
1.160.6.102 raeburn 16099: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16100: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16101: if (@diffs > 0) {
16102: $changes{'reset'} = 1;
16103: }
16104: }
16105: }
16106: }
16107: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16108: my @resetemail;
16109: foreach my $item (sort(@possemailsrc)) {
16110: if ($item =~ /^(permanent|critical|notify)$/) {
16111: push(@resetemail,$item);
16112: }
16113: }
16114: $newvalues{'resetemail'} = \@resetemail;
16115: unless ($changes{'reset'}) {
16116: if (ref($current{'resetemail'}) eq 'ARRAY') {
16117: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16118: if (@diffs > 0) {
16119: $changes{'reset'} = 1;
16120: }
1.160.6.102 raeburn 16121: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16122: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16123: if (@diffs > 0) {
16124: $changes{'reset'} = 1;
16125: }
16126: }
16127: }
16128: if ($env{'form.passwords_stdtext'} == 0) {
16129: $newvalues{'resetremove'} = 1;
16130: unless ($current{'resetremove'}) {
16131: $changes{'reset'} = 1;
16132: }
16133: } elsif ($current{'resetremove'}) {
16134: $changes{'reset'} = 1;
16135: }
16136: if ($env{'form.passwords_customfile.filename'} ne '') {
16137: my $servadm = $r->dir_config('lonAdmEMail');
16138: my ($configuserok,$author_ok,$switchserver) =
16139: &config_check($dom,$confname,$servadm);
16140: my $error;
16141: if ($configuserok eq 'ok') {
16142: if ($switchserver) {
16143: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16144: } else {
16145: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 16146:23): my $modified = [];
1.160.6.98 raeburn 16147: my ($result,$customurl) =
1.160.6.118.2 14(raebu 16148:23): &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
16149:23): $confname,'customtext/resetpw','','',$customfn,
16150:23): $modified);
1.160.6.98 raeburn 16151: if ($result eq 'ok') {
16152: $newvalues{'resetcustom'} = $customurl;
16153: $changes{'reset'} = 1;
1.160.6.118.2 14(raebu 16154:23): &update_modify_urls($r,$modified);
1.160.6.98 raeburn 16155: } else {
16156: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16157: }
16158: } else {
16159: $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);
16160: }
16161: }
16162: } else {
16163: $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);
16164: }
16165: if ($error) {
16166: &Apache::lonnet::logthis($error);
16167: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16168: }
16169: } elsif ($current{'resetcustom'}) {
16170: if ($env{'form.passwords_custom_del'}) {
16171: $changes{'reset'} = 1;
16172: } else {
16173: $newvalues{'resetcustom'} = $current{'resetcustom'};
16174: }
16175: }
16176: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16177: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16178: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16179: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16180: $changes{'intauth'} = 1;
16181: }
16182: } else {
16183: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16184: }
16185: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16186: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16187: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16188: $changes{'intauth'} = 1;
16189: }
16190: } else {
16191: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16192: }
16193: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16194: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16195: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16196: $changes{'intauth'} = 1;
16197: }
16198: } else {
16199: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16200: }
16201: foreach my $item ('cost','check','switch') {
16202: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16203: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16204: $updatedefaults = 1;
16205: }
16206: }
1.160.6.118.2 5(raebur 16207:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 16208: my %crsownerchg = (
16209: by => [],
16210: for => [],
16211: );
16212: foreach my $item ('by','for') {
16213: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16214: foreach my $type (sort(@posstypes)) {
16215: if (grep(/^\Q$type\E$/,@oktypes)) {
16216: push(@{$crsownerchg{$item}},$type);
16217: }
16218: }
16219: }
16220: $newvalues{'crsownerchg'} = \%crsownerchg;
16221: if (ref($current{'crsownerchg'}) eq 'HASH') {
16222: foreach my $item ('by','for') {
16223: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16224: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16225: if (@diffs > 0) {
16226: $changes{'crsownerchg'} = 1;
16227: last;
16228: }
16229: }
16230: }
1.160.6.102 raeburn 16231: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 16232: foreach my $item ('by','for') {
16233: if (@{$crsownerchg{$item}} > 0) {
16234: $changes{'crsownerchg'} = 1;
16235: last;
16236: }
16237: }
16238: }
16239:
16240: my %confighash = (
16241: defaults => \%save_defaults,
16242: passwords => \%newvalues,
16243: );
16244: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16245:
16246: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16247: if ($putresult eq 'ok') {
16248: if (keys(%changes) > 0) {
16249: $resulttext = &mt('Changes made: ').'<ul>';
16250: foreach my $key ('reset','intauth','rules','crsownerchg') {
16251: if ($changes{$key}) {
16252: unless ($key eq 'intauth') {
16253: $updateconf = 1;
16254: }
16255: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16256: if ($key eq 'reset') {
16257: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16258: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16259: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16260: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 16261: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16262: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16263: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16264: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16265: }
1.160.6.98 raeburn 16266: } else {
16267: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16268: }
16269: if ($confighash{'passwords'}{'resetlink'}) {
16270: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16271: } else {
16272: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16273: &mt('Will default to 2 hours').'</li>';
16274: }
16275: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16276: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16277: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16278: } else {
16279: my $casesens;
16280: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16281: if ($type eq 'default') {
16282: $casesens .= $othertitle.', ';
16283: } elsif ($usertypes->{$type} ne '') {
16284: $casesens .= $usertypes->{$type}.', ';
16285: }
16286: }
16287: $casesens =~ s/\Q, \E$//;
16288: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16289: }
16290: } else {
16291: $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>';
16292: }
16293: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16294: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16295: } else {
16296: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16297: }
16298: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16299: my $output;
16300: if (ref($types) eq 'ARRAY') {
16301: foreach my $type (@{$types}) {
16302: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16303: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16304: $output .= $usertypes->{$type}.' -- '.&mt('none');
16305: } else {
16306: $output .= $usertypes->{$type}.' -- '.
16307: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16308: }
16309: }
16310: }
16311: }
16312: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16313: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16314: $output .= $othertitle.' -- '.&mt('none');
16315: } else {
16316: $output .= $othertitle.' -- '.
16317: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16318: }
16319: }
16320: if ($output) {
16321: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16322: } else {
16323: $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>';
16324: }
16325: } else {
16326: $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>';
16327: }
16328: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16329: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16330: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16331: } else {
16332: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16333: }
16334: } else {
1.160.6.110 raeburn 16335: $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 16336: }
16337: if ($confighash{'passwords'}{'resetremove'}) {
16338: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16339: } else {
16340: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16341: }
16342: if ($confighash{'passwords'}{'resetcustom'}) {
16343: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 16344: &mt('custom text'),600,500,undef,undef,
16345: undef,undef,'background-color:#ffffff');
16346: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 16347: } else {
16348: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16349: }
16350: } elsif ($key eq 'intauth') {
16351: foreach my $item ('cost','switch','check') {
16352: my $value = $save_defaults{$key.'_'.$item};
16353: if ($item eq 'switch') {
16354: my %optiondesc = &Apache::lonlocal::texthash (
16355: 0 => 'No',
16356: 1 => 'Yes',
16357: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16358: );
16359: if ($value =~ /^(0|1|2)$/) {
16360: $value = $optiondesc{$value};
16361: } else {
16362: $value = &mt('none -- defaults to No');
16363: }
16364: } elsif ($item eq 'check') {
16365: my %optiondesc = &Apache::lonlocal::texthash (
16366: 0 => 'No',
16367: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16368: 2 => 'Yes, disallow login if stored cost is less than domain default',
16369: );
16370: if ($value =~ /^(0|1|2)$/) {
16371: $value = $optiondesc{$value};
16372: } else {
16373: $value = &mt('none -- defaults to No');
16374: }
16375: }
16376: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16377: }
16378: } elsif ($key eq 'rules') {
16379: foreach my $rule ('min','max','numsaved') {
16380: if ($confighash{'passwords'}{$rule} eq '') {
16381: if ($rule eq 'min') {
16382: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 16383: ' '.&mt('Default of [_1] will be used',
16384: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 16385: } else {
16386: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
16387: }
16388: } else {
16389: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16390: }
16391: }
1.160.6.104 raeburn 16392: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16393: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16394: my %rulenames = &Apache::lonlocal::texthash(
16395: uc => 'At least one upper case letter',
16396: lc => 'At least one lower case letter',
16397: num => 'At least one number',
16398: spec => 'At least one non-alphanumeric',
16399: );
16400: my $needed = '<ul><li>'.
16401: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16402: '</li></ul>';
16403: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16404: } else {
16405: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16406: }
16407: } else {
16408: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16409: }
1.160.6.98 raeburn 16410: } elsif ($key eq 'crsownerchg') {
16411: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16412: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16413: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16414: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16415: } else {
16416: my %crsownerstr;
16417: foreach my $item ('by','for') {
16418: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16419: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16420: if ($type eq 'default') {
16421: $crsownerstr{$item} .= $othertitle.', ';
16422: } elsif ($usertypes->{$type} ne '') {
16423: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16424: }
16425: }
16426: $crsownerstr{$item} =~ s/\Q, \E$//;
16427: }
16428: }
16429: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16430: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16431: }
16432: } else {
16433: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16434: }
16435: }
16436: $resulttext .= '</ul></li>';
16437: }
16438: }
16439: $resulttext .= '</ul>';
16440: } else {
16441: $resulttext = &mt('No changes made to password settings');
16442: }
16443: my $cachetime = 24*60*60;
16444: if ($updatedefaults) {
16445: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16446: if (ref($lastactref) eq 'HASH') {
16447: $lastactref->{'domdefaults'} = 1;
16448: }
16449: }
16450: if ($updateconf) {
16451: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16452: if (ref($lastactref) eq 'HASH') {
16453: $lastactref->{'passwdconf'} = 1;
16454: }
16455: }
16456: } else {
16457: $resulttext = '<span class="LC_error">'.
16458: &mt('An error occurred: [_1]',$putresult).'</span>';
16459: }
16460: if ($errors) {
16461: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16462: $errors.'</ul></p>';
16463: }
16464: return $resulttext;
16465: }
16466:
1.160.6.118.2 5(raebur 16467:2): sub password_rule_changes {
16468:2): my ($prefix,$newvalues,$current,$changes) = @_;
16469:2): return unless ((ref($newvalues) eq 'HASH') &&
16470:2): (ref($current) eq 'HASH') &&
16471:2): (ref($changes) eq 'HASH'));
16472:2): my (@rules,%staticdefaults);
16473:2): if ($prefix eq 'passwords') {
16474:2): @rules = ('min','max','numsaved');
14(raebu 16475:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 16476:2): @rules = ('min','max');
16477:2): }
16478:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
16479:2): foreach my $rule (@rules) {
16480:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
16481:2): my $ruleok;
16482:2): if ($rule eq 'min') {
16483:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
16484:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
16485:2): $ruleok = 1;
16486:2): }
16487:2): }
16488:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
16489:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
16490:2): $ruleok = 1;
16491:2): }
16492:2): if ($ruleok) {
16493:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
16494:2): if (exists($current->{$rule})) {
16495:2): if ($newvalues->{$rule} ne $current->{$rule}) {
16496:2): $changes->{'rules'} = 1;
16497:2): }
16498:2): } elsif ($rule eq 'min') {
16499:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
16500:2): $changes->{'rules'} = 1;
16501:2): }
16502:2): } else {
16503:2): $changes->{'rules'} = 1;
16504:2): }
16505:2): } elsif (exists($current->{$rule})) {
16506:2): $changes->{'rules'} = 1;
16507:2): }
16508:2): }
16509:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
16510:2): my @chars;
16511:2): foreach my $item (sort(@posschars)) {
16512:2): if ($item =~ /^(uc|lc|num|spec)$/) {
16513:2): push(@chars,$item);
16514:2): }
16515:2): }
16516:2): $newvalues->{'chars'} = \@chars;
16517:2): unless ($changes->{'rules'}) {
16518:2): if (ref($current->{'chars'}) eq 'ARRAY') {
16519:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
16520:2): if (@diffs > 0) {
16521:2): $changes->{'rules'} = 1;
16522:2): }
16523:2): } else {
16524:2): if (@chars > 0) {
16525:2): $changes->{'rules'} = 1;
16526:2): }
16527:2): }
16528:2): }
16529:2): return;
16530:2): }
16531:2):
1.28 raeburn 16532: sub modify_usercreation {
1.27 raeburn 16533: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16534: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16535: my $warningmsg;
1.27 raeburn 16536: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16537: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 16538: if ($key eq 'cancreate') {
16539: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16540: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 16541: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 16542: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 16543: } else {
16544: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 16545: }
1.50 raeburn 16546: }
1.43 raeburn 16547: }
1.160.6.34 raeburn 16548: } elsif ($key eq 'email_rule') {
16549: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16550: } else {
16551: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 16552: }
16553: }
1.34 raeburn 16554: }
1.160.6.34 raeburn 16555: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
16556: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
16557: my @contexts = ('author','course','requestcrs');
16558: foreach my $item(@contexts) {
16559: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16560: }
1.34 raeburn 16561: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16562: foreach my $item (@contexts) {
1.160.6.34 raeburn 16563: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16564: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16565: }
1.27 raeburn 16566: }
1.34 raeburn 16567: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16568: foreach my $item (@contexts) {
1.43 raeburn 16569: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16570: if ($cancreate{$item} ne 'any') {
16571: push(@{$changes{'cancreate'}},$item);
16572: }
16573: } else {
16574: if ($cancreate{$item} ne 'none') {
16575: push(@{$changes{'cancreate'}},$item);
16576: }
1.27 raeburn 16577: }
16578: }
16579: } else {
1.43 raeburn 16580: foreach my $item (@contexts) {
1.34 raeburn 16581: push(@{$changes{'cancreate'}},$item);
16582: }
1.27 raeburn 16583: }
1.34 raeburn 16584:
1.27 raeburn 16585: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16586: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16587: if (!grep(/^\Q$type\E$/,@username_rule)) {
16588: push(@{$changes{'username_rule'}},$type);
16589: }
16590: }
16591: foreach my $type (@username_rule) {
16592: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16593: push(@{$changes{'username_rule'}},$type);
16594: }
16595: }
16596: } else {
16597: push(@{$changes{'username_rule'}},@username_rule);
16598: }
16599:
1.32 raeburn 16600: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16601: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16602: if (!grep(/^\Q$type\E$/,@id_rule)) {
16603: push(@{$changes{'id_rule'}},$type);
16604: }
16605: }
16606: foreach my $type (@id_rule) {
16607: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16608: push(@{$changes{'id_rule'}},$type);
16609: }
16610: }
16611: } else {
16612: push(@{$changes{'id_rule'}},@id_rule);
16613: }
16614:
1.43 raeburn 16615: my @authen_contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 16616:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16617: my %authhash;
1.43 raeburn 16618: foreach my $item (@authen_contexts) {
1.28 raeburn 16619: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16620: foreach my $auth (@authtypes) {
16621: if (grep(/^\Q$auth\E$/,@authallowed)) {
16622: $authhash{$item}{$auth} = 1;
16623: } else {
16624: $authhash{$item}{$auth} = 0;
16625: }
16626: }
16627: }
16628: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16629: foreach my $item (@authen_contexts) {
1.28 raeburn 16630: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16631: foreach my $auth (@authtypes) {
16632: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16633: push(@{$changes{'authtypes'}},$item);
16634: last;
16635: }
16636: }
16637: }
16638: }
16639: } else {
1.43 raeburn 16640: foreach my $item (@authen_contexts) {
1.28 raeburn 16641: push(@{$changes{'authtypes'}},$item);
16642: }
16643: }
16644:
1.160.6.34 raeburn 16645: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16646: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16647: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16648: $save_usercreate{'id_rule'} = \@id_rule;
16649: $save_usercreate{'username_rule'} = \@username_rule,
16650: $save_usercreate{'authtypes'} = \%authhash;
16651:
1.27 raeburn 16652: my %usercreation_hash = (
1.160.6.34 raeburn 16653: usercreation => \%save_usercreate,
16654: );
1.27 raeburn 16655:
16656: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16657: $dom);
1.50 raeburn 16658:
1.160.6.34 raeburn 16659: if ($putresult eq 'ok') {
16660: if (keys(%changes) > 0) {
16661: $resulttext = &mt('Changes made:').'<ul>';
16662: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16663: my %lt = &usercreation_types();
16664: foreach my $type (@{$changes{'cancreate'}}) {
16665: my $chgtext = $lt{$type}.', ';
16666: if ($cancreate{$type} eq 'none') {
16667: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16668: } elsif ($cancreate{$type} eq 'any') {
16669: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16670: } elsif ($cancreate{$type} eq 'official') {
16671: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16672: } elsif ($cancreate{$type} eq 'unofficial') {
16673: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16674: }
16675: $resulttext .= '<li>'.$chgtext.'</li>';
16676: }
16677: }
16678: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16679: my ($rules,$ruleorder) =
16680: &Apache::lonnet::inst_userrules($dom,'username');
16681: my $chgtext = '<ul>';
16682: foreach my $type (@username_rule) {
16683: if (ref($rules->{$type}) eq 'HASH') {
16684: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16685: }
16686: }
16687: $chgtext .= '</ul>';
16688: if (@username_rule > 0) {
16689: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16690: } else {
16691: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16692: }
16693: }
16694: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16695: my ($idrules,$idruleorder) =
16696: &Apache::lonnet::inst_userrules($dom,'id');
16697: my $chgtext = '<ul>';
16698: foreach my $type (@id_rule) {
16699: if (ref($idrules->{$type}) eq 'HASH') {
16700: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16701: }
16702: }
16703: $chgtext .= '</ul>';
16704: if (@id_rule > 0) {
16705: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16706: } else {
16707: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16708: }
16709: }
16710: my %authname = &authtype_names();
16711: my %context_title = &context_names();
16712: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16713: my $chgtext = '<ul>';
16714: foreach my $type (@{$changes{'authtypes'}}) {
16715: my @allowed;
16716: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16717: foreach my $auth (@authtypes) {
16718: if ($authhash{$type}{$auth}) {
16719: push(@allowed,$authname{$auth});
16720: }
16721: }
16722: if (@allowed > 0) {
16723: $chgtext .= join(', ',@allowed).'</li>';
16724: } else {
16725: $chgtext .= &mt('none').'</li>';
16726: }
16727: }
16728: $chgtext .= '</ul>';
16729: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16730: $resulttext .= '</li>';
16731: }
16732: $resulttext .= '</ul>';
16733: } else {
16734: $resulttext = &mt('No changes made to user creation settings');
16735: }
16736: } else {
16737: $resulttext = '<span class="LC_error">'.
16738: &mt('An error occurred: [_1]',$putresult).'</span>';
16739: }
16740: if ($warningmsg ne '') {
16741: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16742: }
16743: return $resulttext;
16744: }
16745:
16746: sub modify_selfcreation {
1.160.6.93 raeburn 16747: my ($dom,$lastactref,%domconfig) = @_;
16748: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16749: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16750: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16751: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16752: if (ref($typesref) eq 'ARRAY') {
16753: @types = @{$typesref};
16754: }
16755: if (ref($usertypesref) eq 'HASH') {
16756: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 16757: }
1.160.6.93 raeburn 16758: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 16759: #
16760: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16761: #
16762: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16763: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16764: if ($key eq 'cancreate') {
16765: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16766: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16767: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 16768: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16769: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16770: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16771: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16772: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 16773: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16774: } else {
16775: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16776: }
16777: }
16778: }
16779: } elsif ($key eq 'email_rule') {
16780: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16781: } else {
16782: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16783: }
16784: }
16785: }
16786: #
16787: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16788: #
16789: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16790: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16791: if ($key eq 'selfcreate') {
16792: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16793: } else {
16794: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16795: }
16796: }
16797: }
1.160.6.93 raeburn 16798: #
16799: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16800: #
16801: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16802: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16803: if ($key eq 'inststatusguest') {
16804: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16805: } else {
16806: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16807: }
16808: }
16809: }
1.160.6.34 raeburn 16810:
16811: my @contexts = ('selfcreate');
16812: @{$cancreate{'selfcreate'}} = ();
16813: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 16814: if (@types) {
16815: @{$cancreate{'statustocreate'}} = ();
16816: }
1.160.6.40 raeburn 16817: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 16818: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 16819: %{$cancreate{'emailverified'}} = ();
16820: %{$cancreate{'emailoptions'}} = ();
16821: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16822: my %selfcreatetypes = (
16823: sso => 'users authenticated by institutional single sign on',
16824: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 16825: email => 'users verified by e-mail',
1.50 raeburn 16826: );
1.160.6.34 raeburn 16827: #
16828: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16829: # is permitted.
16830: #
1.160.6.93 raeburn 16831: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 16832:
1.160.6.93 raeburn 16833: my (@statuses,%email_rule);
1.160.6.35 raeburn 16834: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 16835: if ($item eq 'email') {
1.160.6.40 raeburn 16836: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 16837: if (@types) {
16838: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16839: foreach my $status (@poss_statuses) {
16840: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16841: push(@statuses,$status);
16842: }
16843: }
16844: $save_inststatus{'inststatusguest'} = \@statuses;
16845: } else {
16846: push(@statuses,'default');
16847: }
16848: if (@statuses) {
16849: my %curr_rule;
16850: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16851: foreach my $type (@statuses) {
16852: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16853: }
16854: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16855: foreach my $type (@statuses) {
16856: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16857: }
16858: }
16859: push(@{$cancreate{'selfcreate'}},'email');
16860: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16861: my %curremaildom;
16862: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16863: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16864: }
16865: foreach my $type (@statuses) {
16866: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16867: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16868: }
16869: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16870: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16871: }
16872: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16873: #
16874: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16875: #
16876: my $chosen = $1;
16877: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16878: my $emaildom;
16879: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16880: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16881: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16882: if (ref($curremaildom{$type}) eq 'HASH') {
16883: if (exists($curremaildom{$type}{$chosen})) {
16884: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16885: push(@{$changes{'cancreate'}},'emaildomain');
16886: }
16887: } elsif ($emaildom ne '') {
16888: push(@{$changes{'cancreate'}},'emaildomain');
16889: }
16890: } elsif ($emaildom ne '') {
16891: push(@{$changes{'cancreate'}},'emaildomain');
16892: }
16893: }
16894: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16895: } elsif ($chosen eq 'custom') {
16896: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16897: $email_rule{$type} = [];
16898: if (ref($emailrules) eq 'HASH') {
16899: foreach my $rule (@possemail_rules) {
16900: if (exists($emailrules->{$rule})) {
16901: push(@{$email_rule{$type}},$rule);
16902: }
16903: }
16904: }
16905: if (@{$email_rule{$type}}) {
16906: $cancreate{'emailoptions'}{$type} = 'custom';
16907: if (ref($curr_rule{$type}) eq 'ARRAY') {
16908: if (@{$curr_rule{$type}} > 0) {
16909: foreach my $rule (@{$curr_rule{$type}}) {
16910: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16911: push(@{$changes{'email_rule'}},$type);
16912: }
16913: }
16914: }
16915: foreach my $type (@{$email_rule{$type}}) {
16916: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16917: push(@{$changes{'email_rule'}},$type);
16918: }
16919: }
16920: } else {
16921: push(@{$changes{'email_rule'}},$type);
16922: }
16923: }
16924: } else {
16925: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16926: }
16927: }
16928: }
16929: if (@types) {
16930: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16931: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16932: if (@changed) {
16933: push(@{$changes{'inststatus'}},'inststatusguest');
16934: }
16935: } else {
16936: push(@{$changes{'inststatus'}},'inststatusguest');
16937: }
16938: }
16939: } else {
16940: delete($env{'form.cancreate_email'});
16941: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16942: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16943: push(@{$changes{'inststatus'}},'inststatusguest');
16944: }
16945: }
16946: }
16947: } else {
16948: $save_inststatus{'inststatusguest'} = [];
16949: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16950: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16951: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 16952: }
16953: }
1.160.6.34 raeburn 16954: }
16955: } else {
16956: if ($env{'form.cancreate_'.$item}) {
16957: push(@{$cancreate{'selfcreate'}},$item);
16958: }
16959: }
16960: }
1.160.6.93 raeburn 16961: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 16962: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16963: #
1.160.6.35 raeburn 16964: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16965: # 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 16966: #
1.160.6.40 raeburn 16967:
1.160.6.48 raeburn 16968: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 16969: push(@contexts,'emailusername');
1.160.6.93 raeburn 16970: if (@statuses) {
16971: foreach my $type (@statuses) {
1.160.6.35 raeburn 16972: if (ref($infofields) eq 'ARRAY') {
16973: foreach my $field (@{$infofields}) {
16974: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16975: $cancreate{'emailusername'}{$type}{$field} = $1;
16976: }
16977: }
1.160.6.34 raeburn 16978: }
16979: }
16980: }
16981: #
16982: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 16983: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 16984: #
16985:
16986: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16987: @approvalnotify = sort(@approvalnotify);
16988: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16989: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16990: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16991: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16992: push(@{$changes{'cancreate'}},'notify');
16993: }
16994: } else {
16995: if ($cancreate{'notify'}{'approval'}) {
16996: push(@{$changes{'cancreate'}},'notify');
16997: }
16998: }
16999: } elsif ($cancreate{'notify'}{'approval'}) {
17000: push(@{$changes{'cancreate'}},'notify');
17001: }
17002:
17003: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17004: }
17005: #
1.160.6.40 raeburn 17006: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 17007: # institutional log-in.
17008: #
17009: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17010: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17011: ($domdefaults{'auth_def'} eq 'localauth'))) {
17012: $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.').' '.
17013: &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.');
17014: }
17015: }
17016: my @fields = ('lastname','firstname','middlename','generation',
17017: 'permanentemail','id');
1.160.6.44 raeburn 17018: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 17019: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17020: #
17021: # Where usernames may created for institutional log-in and/or institutional single sign on:
17022: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17023: # may self-create accounts
17024: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17025: # which the user may supply, if institutional data is unavailable.
17026: #
17027: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 17028: if (@types) {
17029: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17030: push(@contexts,'statustocreate');
17031: foreach my $type (@types) {
1.160.6.34 raeburn 17032: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17033: foreach my $field (@fields) {
17034: if (grep(/^\Q$field\E$/,@modifiable)) {
17035: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17036: } else {
17037: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17038: }
17039: }
17040: }
17041: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 17042: foreach my $type (@types) {
1.160.6.34 raeburn 17043: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17044: foreach my $field (@fields) {
17045: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17046: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17047: push(@{$changes{'selfcreate'}},$type);
17048: last;
17049: }
17050: }
17051: }
17052: }
17053: } else {
1.160.6.93 raeburn 17054: foreach my $type (@types) {
1.160.6.34 raeburn 17055: push(@{$changes{'selfcreate'}},$type);
17056: }
17057: }
17058: }
1.160.6.44 raeburn 17059: foreach my $field (@shibfields) {
17060: if ($env{'form.shibenv_'.$field} ne '') {
17061: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17062: }
17063: }
17064: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17065: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17066: foreach my $field (@shibfields) {
17067: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17068: push(@{$changes{'cancreate'}},'shibenv');
17069: }
17070: }
17071: } else {
17072: foreach my $field (@shibfields) {
17073: if ($env{'form.shibenv_'.$field}) {
17074: push(@{$changes{'cancreate'}},'shibenv');
17075: last;
17076: }
17077: }
17078: }
17079: }
1.160.6.34 raeburn 17080: }
17081: foreach my $item (@contexts) {
17082: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17083: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17084: if (ref($cancreate{$item}) eq 'ARRAY') {
17085: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17086: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17087: push(@{$changes{'cancreate'}},$item);
17088: }
17089: }
17090: }
17091: }
17092: if (ref($cancreate{$item}) eq 'ARRAY') {
17093: foreach my $type (@{$cancreate{$item}}) {
17094: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17095: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17096: push(@{$changes{'cancreate'}},$item);
17097: }
17098: }
17099: }
17100: }
17101: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17102: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 17103: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17104: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17105: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17106: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17107: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17108: push(@{$changes{'cancreate'}},$item);
17109: }
17110: }
17111: }
1.160.6.93 raeburn 17112: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17113: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17114: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17115: push(@{$changes{'cancreate'}},$item);
17116: }
1.160.6.34 raeburn 17117: }
17118: }
17119: }
1.160.6.93 raeburn 17120: foreach my $type (keys(%{$cancreate{$item}})) {
17121: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17122: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17123: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17124: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17125: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17126: push(@{$changes{'cancreate'}},$item);
17127: }
17128: }
17129: } else {
17130: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17131: push(@{$changes{'cancreate'}},$item);
17132: }
17133: }
17134: }
1.160.6.93 raeburn 17135: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17136: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17137: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17138: push(@{$changes{'cancreate'}},$item);
17139: }
1.160.6.34 raeburn 17140: }
17141: }
17142: }
17143: }
17144: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17145: if (ref($cancreate{$item}) eq 'ARRAY') {
17146: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17147: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17148: push(@{$changes{'cancreate'}},$item);
17149: }
17150: }
1.160.6.93 raeburn 17151: }
17152: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17153: if (ref($cancreate{$item}) eq 'HASH') {
17154: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17155: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 17156: }
17157: }
17158: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 17159: if (ref($cancreate{$item}) eq 'HASH') {
17160: foreach my $type (keys(%{$cancreate{$item}})) {
17161: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17162: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17163: if ($cancreate{$item}{$type}{$field}) {
17164: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17165: push(@{$changes{'cancreate'}},$item);
17166: }
17167: last;
17168: }
17169: }
17170: }
17171: }
1.160.6.34 raeburn 17172: }
17173: }
17174: }
17175: #
17176: # Populate %save_usercreate hash with updates to self-creation configuration.
17177: #
17178: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17179: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 17180: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 17181: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17182: if (ref($cancreate{'notify'}) eq 'HASH') {
17183: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17184: }
1.160.6.40 raeburn 17185: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17186: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17187: }
1.160.6.93 raeburn 17188: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17189: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17190: }
17191: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17192: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17193: }
17194: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17195: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17196: }
1.160.6.34 raeburn 17197: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17198: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17199: }
1.160.6.44 raeburn 17200: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17201: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17202: }
1.160.6.34 raeburn 17203: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 17204: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 17205:
17206: my %userconfig_hash = (
17207: usercreation => \%save_usercreate,
17208: usermodification => \%save_usermodify,
1.160.6.93 raeburn 17209: inststatus => \%save_inststatus,
1.160.6.34 raeburn 17210: );
1.160.6.93 raeburn 17211:
1.160.6.34 raeburn 17212: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17213: $dom);
17214: #
1.160.6.93 raeburn 17215: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 17216: #
1.27 raeburn 17217: if ($putresult eq 'ok') {
17218: if (keys(%changes) > 0) {
17219: $resulttext = &mt('Changes made:').'<ul>';
17220: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 17221: my %lt = &selfcreation_types();
1.34 raeburn 17222: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 17223: my $chgtext = '';
1.45 raeburn 17224: if ($type eq 'selfcreate') {
1.50 raeburn 17225: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 17226: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17227: } else {
1.160.6.34 raeburn 17228: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17229: '<ul>';
1.50 raeburn 17230: foreach my $case (@{$cancreate{$type}}) {
17231: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17232: }
17233: $chgtext .= '</ul>';
1.100 raeburn 17234: if (ref($cancreate{$type}) eq 'ARRAY') {
17235: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17236: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17237: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 17238: $chgtext .= '<span class="LC_warning">'.
17239: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17240: '</span><br />';
1.100 raeburn 17241: }
17242: }
17243: }
1.160.6.93 raeburn 17244: if (grep(/^email$/,@{$cancreate{$type}})) {
17245: if (!@statuses) {
17246: $chgtext .= '<span class="LC_warning">'.
17247: &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.").
17248: '</span><br />';
17249:
17250: }
17251: }
1.100 raeburn 17252: }
1.43 raeburn 17253: }
1.160.6.44 raeburn 17254: } elsif ($type eq 'shibenv') {
17255: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 17256: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 17257: } else {
17258: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17259: '<ul>';
17260: foreach my $field (@shibfields) {
17261: next if ($cancreate{$type}{$field} eq '');
17262: if ($field eq 'inststatus') {
17263: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17264: } else {
17265: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17266: }
17267: }
17268: $chgtext .= '</ul>';
1.160.6.93 raeburn 17269: }
1.93 raeburn 17270: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17271: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17272: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17273: if (@{$cancreate{'selfcreate'}} > 0) {
17274: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17275: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17276: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 17277: $chgtext .= '<br />'.
17278: '<span class="LC_warning">'.
17279: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17280: '</span>';
17281: }
1.160.6.93 raeburn 17282: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17283: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17284: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17285: } else {
17286: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17287: }
17288: $chgtext .= '<ul>';
17289: foreach my $case (@{$cancreate{$type}}) {
17290: if ($case eq 'default') {
17291: $chgtext .= '<li>'.$othertitle.'</li>';
17292: } else {
1.160.6.93 raeburn 17293: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17294: }
17295: }
1.100 raeburn 17296: $chgtext .= '</ul>';
17297: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 17298: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 17299: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17300: '</span>';
1.100 raeburn 17301: }
17302: }
17303: } else {
17304: if (@{$cancreate{$type}} == 0) {
17305: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17306: } else {
17307: $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 17308: }
17309: }
1.160.6.93 raeburn 17310: $chgtext .= '<br />';
1.93 raeburn 17311: }
1.160.6.40 raeburn 17312: } elsif ($type eq 'selfcreateprocessing') {
17313: my %choices = &Apache::lonlocal::texthash (
17314: automatic => 'Automatic approval',
17315: approval => 'Queued for approval',
17316: );
1.160.6.93 raeburn 17317: if (@types) {
17318: if (@statuses) {
17319: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
17320: '<ul>';
17321: foreach my $status (@statuses) {
17322: if ($status eq 'default') {
17323: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17324: } else {
17325: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17326: }
17327: }
17328: $chgtext .= '</ul>';
17329: }
17330: } else {
17331: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17332: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17333: }
17334: } elsif ($type eq 'emailverified') {
17335: my %options = &Apache::lonlocal::texthash (
17336: all => 'Same as e-mail',
17337: first => 'Omit @domain',
17338: free => 'Free to choose',
17339: );
17340: if (@types) {
17341: if (@statuses) {
17342: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17343: '<ul>';
17344: foreach my $status (@statuses) {
17345: if ($status eq 'default') {
17346: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17347: } else {
17348: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17349: }
17350: }
17351: $chgtext .= '</ul>';
17352: }
1.160.6.40 raeburn 17353: } else {
1.160.6.93 raeburn 17354: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
17355: $options{$cancreate{'emailverified'}{'default'}});
17356: }
17357: } elsif ($type eq 'emailoptions') {
17358: my %options = &Apache::lonlocal::texthash (
17359: any => 'Any e-mail',
17360: inst => 'Institutional only',
17361: noninst => 'Non-institutional only',
17362: custom => 'Custom restrictions',
17363: );
17364: if (@types) {
17365: if (@statuses) {
17366: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17367: '<ul>';
17368: foreach my $status (@statuses) {
17369: if ($type eq 'default') {
17370: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17371: } else {
17372: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17373: }
17374: }
17375: $chgtext .= '</ul>';
17376: }
17377: } else {
17378: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17379: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17380: } else {
17381: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17382: $options{$cancreate{'emailoptions'}{'default'}});
17383: }
17384: }
17385: } elsif ($type eq 'emaildomain') {
17386: my $output;
17387: if (@statuses) {
17388: foreach my $type (@statuses) {
17389: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17390: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17391: if ($type eq 'default') {
17392: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17393: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17394: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17395: } else {
17396: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17397: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17398: }
17399: } else {
17400: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17401: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17402: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17403: } else {
17404: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17405: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17406: }
17407: }
17408: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17409: if ($type eq 'default') {
17410: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17411: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17412: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17413: } else {
17414: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17415: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17416: }
17417: } else {
17418: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17419: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17420: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17421: } else {
17422: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17423: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17424: }
17425: }
17426: }
17427: }
17428: }
17429: }
17430: if ($output ne '') {
17431: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17432: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 17433: }
1.160.6.5 raeburn 17434: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 17435: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 17436: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17437: } else {
17438: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 17439: if ($captchas{$savecaptcha{$type}}) {
17440: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 17441: } else {
17442: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
17443: }
17444: }
17445: } elsif ($type eq 'recaptchakeys') {
17446: my ($privkey,$pubkey);
1.160.6.34 raeburn 17447: if (ref($savecaptcha{$type}) eq 'HASH') {
17448: $pubkey = $savecaptcha{$type}{'public'};
17449: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 17450: }
17451: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17452: if (!$pubkey) {
17453: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17454: } else {
17455: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17456: }
17457: if (!$privkey) {
17458: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17459: } else {
17460: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17461: }
17462: $chgtext .= '</ul>';
1.160.6.69 raeburn 17463: } elsif ($type eq 'recaptchaversion') {
17464: if ($savecaptcha{'captcha'} eq 'recaptcha') {
17465: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
17466: }
1.160.6.34 raeburn 17467: } elsif ($type eq 'emailusername') {
17468: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 17469: if (@statuses) {
17470: foreach my $type (@statuses) {
1.160.6.35 raeburn 17471: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17472: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 17473: $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 17474: '<ul>';
17475: foreach my $field (@{$infofields}) {
17476: if ($cancreate{'emailusername'}{$type}{$field}) {
17477: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17478: }
17479: }
1.160.6.50 raeburn 17480: $chgtext .= '</ul>';
17481: } else {
1.160.6.93 raeburn 17482: $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 17483: }
17484: } else {
1.160.6.93 raeburn 17485: $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 17486: }
17487: }
17488: }
17489: }
17490: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 17491: my $numapprove = 0;
1.160.6.34 raeburn 17492: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17493: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17494: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 17495: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17496: $numapprove ++;
1.160.6.34 raeburn 17497: }
17498: }
1.43 raeburn 17499: }
1.160.6.93 raeburn 17500: unless ($numapprove) {
17501: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17502: }
1.34 raeburn 17503: }
1.160.6.34 raeburn 17504: if ($chgtext) {
17505: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17506: }
17507: }
17508: }
1.160.6.93 raeburn 17509: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17510: my ($emailrules,$emailruleorder) =
17511: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 17512: foreach my $type (@{$changes{'email_rule'}}) {
17513: if (ref($email_rule{$type}) eq 'ARRAY') {
17514: my $chgtext = '<ul>';
17515: foreach my $rule (@{$email_rule{$type}}) {
17516: if (ref($emailrules->{$rule}) eq 'HASH') {
17517: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17518: }
17519: }
17520: $chgtext .= '</ul>';
17521: my $typename;
17522: if (@types) {
17523: if ($type eq 'default') {
17524: $typename = $othertitle;
17525: } else {
17526: $typename = $usertypes{$type};
17527: }
17528: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17529: }
17530: if (@{$email_rule{$type}} > 0) {
17531: $resulttext .= '<li>'.
17532: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17533: $usertypes{$type}).
17534: $chgtext.
17535: '</li>';
17536: } else {
17537: $resulttext .= '<li>'.
17538: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
17539: '</li>'.
17540: &mt('(Affiliation: [_1])',$typename);
17541: }
1.43 raeburn 17542: }
17543: }
1.160.6.93 raeburn 17544: }
17545: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17546: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17547: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17548: my $chgtext = '<ul>';
17549: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17550: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17551: }
17552: $chgtext .= '</ul>';
17553: $resulttext .= '<li>'.
17554: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17555: $chgtext.
17556: '</li>';
17557: } else {
17558: $resulttext .= '<li>'.
17559: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17560: '</li>';
17561: }
1.43 raeburn 17562: }
17563: }
1.160.6.34 raeburn 17564: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17565: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17566: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17567: foreach my $type (@{$changes{'selfcreate'}}) {
17568: my $typename = $type;
1.160.6.93 raeburn 17569: if (keys(%usertypes) > 0) {
17570: if ($usertypes{$type} ne '') {
17571: $typename = $usertypes{$type};
1.28 raeburn 17572: }
17573: }
1.160.6.34 raeburn 17574: my @modifiable;
17575: $resulttext .= '<li>'.
17576: &mt('Self-creation of account by users with status: [_1]',
17577: '<span class="LC_cusr_emph">'.$typename.'</span>').
17578: ' - '.&mt('modifiable fields (if institutional data blank): ');
17579: foreach my $field (@fields) {
17580: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17581: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
17582: }
17583: }
17584: if (@modifiable > 0) {
17585: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17586: } else {
1.160.6.34 raeburn 17587: $resulttext .= &mt('none');
1.43 raeburn 17588: }
1.160.6.34 raeburn 17589: $resulttext .= '</li>';
1.28 raeburn 17590: }
1.160.6.34 raeburn 17591: $resulttext .= '</ul></li>';
1.28 raeburn 17592: }
1.27 raeburn 17593: $resulttext .= '</ul>';
1.160.6.93 raeburn 17594: my $cachetime = 24*60*60;
17595: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17596: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17597: if (ref($lastactref) eq 'HASH') {
17598: $lastactref->{'domdefaults'} = 1;
17599: }
1.27 raeburn 17600: } else {
1.160.6.34 raeburn 17601: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17602: }
17603: } else {
17604: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17605: &mt('An error occurred: [_1]',$putresult).'</span>';
17606: }
1.43 raeburn 17607: if ($warningmsg ne '') {
17608: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17609: }
1.23 raeburn 17610: return $resulttext;
17611: }
17612:
1.160.6.5 raeburn 17613: sub process_captcha {
1.160.6.104 raeburn 17614: my ($container,$changes,$newsettings,$currsettings) = @_;
17615: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 17616: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17617: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17618: $newsettings->{'captcha'} = 'original';
17619: }
1.160.6.104 raeburn 17620: my %current;
17621: if (ref($currsettings) eq 'HASH') {
17622: %current = %{$currsettings};
17623: }
17624: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 17625: if ($container eq 'cancreate') {
17626: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17627: push(@{$changes->{'cancreate'}},'captcha');
17628: } elsif (!defined($changes->{'cancreate'})) {
17629: $changes->{'cancreate'} = ['captcha'];
17630: }
1.160.6.102 raeburn 17631: } elsif ($container eq 'passwords') {
17632: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17633: } else {
17634: $changes->{'captcha'} = 1;
17635: }
17636: }
1.160.6.69 raeburn 17637: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 17638: if ($newsettings->{'captcha'} eq 'recaptcha') {
17639: $newpub = $env{'form.'.$container.'_recaptchapub'};
17640: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 17641: $newpub =~ s/[^\w\-]//g;
17642: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 17643: $newsettings->{'recaptchakeys'} = {
17644: public => $newpub,
17645: private => $newpriv,
17646: };
1.160.6.69 raeburn 17647: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17648: $newversion =~ s/\D//g;
17649: if ($newversion ne '2') {
17650: $newversion = 1;
17651: }
17652: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 17653: }
1.160.6.104 raeburn 17654: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17655: $currpub = $current{'recaptchakeys'}{'public'};
17656: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 17657: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17658: $newsettings->{'recaptchakeys'} = {
17659: public => '',
17660: private => '',
17661: }
17662: }
1.160.6.5 raeburn 17663: }
1.160.6.104 raeburn 17664: if ($current{'captcha'} eq 'recaptcha') {
17665: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 17666: if ($currversion ne '2') {
17667: $currversion = 1;
17668: }
17669: }
17670: if ($currversion ne $newversion) {
17671: if ($container eq 'cancreate') {
17672: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17673: push(@{$changes->{'cancreate'}},'recaptchaversion');
17674: } elsif (!defined($changes->{'cancreate'})) {
17675: $changes->{'cancreate'} = ['recaptchaversion'];
17676: }
1.160.6.102 raeburn 17677: } elsif ($container eq 'passwords') {
17678: $changes->{'reset'} = 1;
1.160.6.69 raeburn 17679: } else {
17680: $changes->{'recaptchaversion'} = 1;
17681: }
17682: }
1.160.6.5 raeburn 17683: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
17684: if ($container eq 'cancreate') {
17685: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17686: push(@{$changes->{'cancreate'}},'recaptchakeys');
17687: } elsif (!defined($changes->{'cancreate'})) {
17688: $changes->{'cancreate'} = ['recaptchakeys'];
17689: }
1.160.6.102 raeburn 17690: } elsif ($container eq 'passwords') {
17691: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17692: } else {
17693: $changes->{'recaptchakeys'} = 1;
17694: }
17695: }
17696: return;
17697: }
17698:
1.33 raeburn 17699: sub modify_usermodification {
17700: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 17701: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17702: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17703: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 17704: if ($key eq 'selfcreate') {
17705: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17706: } else {
17707: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17708: }
1.33 raeburn 17709: }
17710: }
1.160.6.34 raeburn 17711: my @contexts = ('author','course');
1.33 raeburn 17712: my %context_title = (
17713: author => 'In author context',
17714: course => 'In course context',
17715: );
17716: my @fields = ('lastname','firstname','middlename','generation',
17717: 'permanentemail','id');
17718: my %roles = (
17719: author => ['ca','aa'],
17720: course => ['st','ep','ta','in','cr'],
17721: );
17722: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17723: foreach my $context (@contexts) {
17724: foreach my $role (@{$roles{$context}}) {
17725: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$role);
17726: foreach my $item (@fields) {
17727: if (grep(/^\Q$item\E$/,@modifiable)) {
17728: $modifyhash{$context}{$role}{$item} = 1;
17729: } else {
17730: $modifyhash{$context}{$role}{$item} = 0;
17731: }
17732: }
17733: }
17734: if (ref($curr_usermodification{$context}) eq 'HASH') {
17735: foreach my $role (@{$roles{$context}}) {
17736: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17737: foreach my $field (@fields) {
17738: if ($modifyhash{$context}{$role}{$field} ne
17739: $curr_usermodification{$context}{$role}{$field}) {
17740: push(@{$changes{$context}},$role);
17741: last;
17742: }
17743: }
17744: }
17745: }
17746: } else {
17747: foreach my $context (@contexts) {
17748: foreach my $role (@{$roles{$context}}) {
17749: push(@{$changes{$context}},$role);
17750: }
17751: }
17752: }
17753: }
17754: my %usermodification_hash = (
17755: usermodification => \%modifyhash,
17756: );
17757: my $putresult = &Apache::lonnet::put_dom('configuration',
17758: \%usermodification_hash,$dom);
17759: if ($putresult eq 'ok') {
17760: if (keys(%changes) > 0) {
17761: $resulttext = &mt('Changes made: ').'<ul>';
17762: foreach my $context (@contexts) {
17763: if (ref($changes{$context}) eq 'ARRAY') {
17764: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17765: if (ref($changes{$context}) eq 'ARRAY') {
17766: foreach my $role (@{$changes{$context}}) {
17767: my $rolename;
1.160.6.34 raeburn 17768: if ($role eq 'cr') {
17769: $rolename = &mt('Custom');
1.33 raeburn 17770: } else {
1.160.6.34 raeburn 17771: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17772: }
17773: my @modifiable;
1.160.6.34 raeburn 17774: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17775: foreach my $field (@fields) {
17776: if ($modifyhash{$context}{$role}{$field}) {
17777: push(@modifiable,$fieldtitles{$field});
17778: }
17779: }
17780: if (@modifiable > 0) {
17781: $resulttext .= join(', ',@modifiable);
17782: } else {
17783: $resulttext .= &mt('none');
17784: }
17785: $resulttext .= '</li>';
17786: }
17787: $resulttext .= '</ul></li>';
17788: }
17789: }
17790: }
17791: $resulttext .= '</ul>';
17792: } else {
17793: $resulttext = &mt('No changes made to user modification settings');
17794: }
17795: } else {
17796: $resulttext = '<span class="LC_error">'.
17797: &mt('An error occurred: [_1]',$putresult).'</span>';
17798: }
17799: return $resulttext;
17800: }
17801:
1.43 raeburn 17802: sub modify_defaults {
1.160.6.27 raeburn 17803: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17804: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 17805: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 17806: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 17807: 'portal_def');
1.160.6.118.2 14(raebu 17808:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17809: foreach my $item (@items) {
17810: $newvalues{$item} = $env{'form.'.$item};
17811: if ($item eq 'auth_def') {
17812: if ($newvalues{$item} ne '') {
17813: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17814: push(@errors,$item);
17815: }
17816: }
17817: } elsif ($item eq 'lang_def') {
17818: if ($newvalues{$item} ne '') {
17819: if ($newvalues{$item} =~ /^(\w+)/) {
17820: my $langcode = $1;
1.103 raeburn 17821: if ($langcode ne 'x_chef') {
17822: if (code2language($langcode) eq '') {
17823: push(@errors,$item);
17824: }
1.43 raeburn 17825: }
17826: } else {
17827: push(@errors,$item);
17828: }
17829: }
1.54 raeburn 17830: } elsif ($item eq 'timezone_def') {
17831: if ($newvalues{$item} ne '') {
1.62 raeburn 17832: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17833: push(@errors,$item);
17834: }
17835: }
1.68 raeburn 17836: } elsif ($item eq 'datelocale_def') {
17837: if ($newvalues{$item} ne '') {
17838: my @datelocale_ids = DateTime::Locale->ids();
17839: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17840: push(@errors,$item);
17841: }
17842: }
1.141 raeburn 17843: } elsif ($item eq 'portal_def') {
17844: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 17845: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])\/?$/) {
17846:23): foreach my $field ('email','web') {
17847:23): if ($env{'form.'.$item.'_'.$field}) {
17848:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17849:23): }
17850:23): }
17851:23): } else {
1.141 raeburn 17852: push(@errors,$item);
17853: }
17854: }
1.43 raeburn 17855: }
17856: if (grep(/^\Q$item\E$/,@errors)) {
17857: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 17858:23): if ($item eq 'portal_def') {
17859:23): if ($domdefaults{$item}) {
17860:23): foreach my $field ('email','web') {
17861:23): if (exists($domdefaults{$item.'_'.$field})) {
17862:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17863:23): }
17864:23): }
17865:23): }
17866:23): }
1.43 raeburn 17867: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17868: $changes{$item} = 1;
17869: }
1.160.6.118.2 12(raebu 17870:23): if ($item eq 'portal_def') {
17871:23): unless (grep(/^\Q$item\E$/,@errors)) {
17872:23): if ($newvalues{$item} eq '') {
17873:23): foreach my $field ('email','web') {
17874:23): if (exists($domdefaults{$item.'_'.$field})) {
17875:23): delete($domdefaults{$item.'_'.$field});
17876:23): }
17877:23): }
17878:23): } else {
17879:23): unless ($changes{$item}) {
17880:23): foreach my $field ('email','web') {
17881:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17882:23): $changes{$item} = 1;
17883:23): last;
17884:23): }
17885:23): }
17886:23): }
17887:23): foreach my $field ('email','web') {
17888:23): if ($newvalues{$item.'_'.$field}) {
17889:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17890:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
17891:23): delete($domdefaults{$item.'_'.$field});
17892:23): }
17893:23): }
17894:23): }
17895:23): }
17896:23): }
1.72 raeburn 17897: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17898: }
1.160.6.98 raeburn 17899: my %staticdefaults = (
17900: 'intauth_cost' => 10,
17901: 'intauth_check' => 0,
17902: 'intauth_switch' => 0,
17903: );
17904: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17905: if (exists($domdefaults{$item})) {
17906: $newvalues{$item} = $domdefaults{$item};
17907: } else {
17908: $newvalues{$item} = $staticdefaults{$item};
17909: }
17910: }
1.160.6.118.2 8(raebur 17911:2): my ($unamemaprules,$ruleorder);
17912:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17913:2): if (@possunamemaprules) {
17914:2): ($unamemaprules,$ruleorder) =
17915:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
17916:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17917:2): if (@{$ruleorder} > 0) {
17918:2): my %possrules;
17919:2): map { $possrules{$_} = 1; } @possunamemaprules;
17920:2): foreach my $rule (@{$ruleorder}) {
17921:2): if ($possrules{$rule}) {
17922:2): push(@{$newvalues{'unamemap_rule'}},$rule);
17923:2): }
17924:2): }
17925:2): }
17926:2): }
17927:2): }
17928:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17929:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17930:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17931:2): $newvalues{'unamemap_rule'});
17932:2): if (@rulediffs) {
17933:2): $changes{'unamemap_rule'} = 1;
17934:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17935:2): }
17936:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17937:2): $changes{'unamemap_rule'} = 1;
17938:2): delete($domdefaults{'unamemap_rule'});
17939:2): }
17940:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17941:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
17942:2): $changes{'unamemap_rule'} = 1;
17943:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17944:2): }
17945:2): }
1.43 raeburn 17946: my %defaults_hash = (
1.72 raeburn 17947: defaults => \%newvalues,
17948: );
1.43 raeburn 17949: my $title = &defaults_titles();
1.160.6.40 raeburn 17950:
17951: my $currinststatus;
17952: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17953: $currinststatus = $domconfig{'inststatus'};
17954: } else {
17955: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17956: $currinststatus = {
17957: inststatustypes => $usertypes,
17958: inststatusorder => $types,
17959: inststatusguest => [],
17960: };
17961: }
17962: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17963: my @allpos;
17964: my %alltypes;
1.160.6.93 raeburn 17965: my @inststatusguest;
17966: if (ref($currinststatus) eq 'HASH') {
17967: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17968: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17969: unless (grep(/^\Q$type\E$/,@todelete)) {
17970: push(@inststatusguest,$type);
17971: }
17972: }
17973: }
17974: }
17975: my ($currtitles,$currorder);
1.160.6.40 raeburn 17976: if (ref($currinststatus) eq 'HASH') {
17977: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17978: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17979: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17980: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17981: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17982: }
17983: }
17984: unless (grep(/^\Q$type\E$/,@todelete)) {
17985: my $position = $env{'form.inststatus_pos_'.$type};
17986: $position =~ s/\D+//g;
17987: $allpos[$position] = $type;
17988: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17989: $alltypes{$type} =~ s/`//g;
17990: }
17991: }
17992: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17993: $currtitles =~ s/,$//;
17994: }
17995: }
17996: if ($env{'form.addinststatus'}) {
17997: my $newtype = $env{'form.addinststatus'};
17998: $newtype =~ s/\W//g;
17999: unless (exists($alltypes{$newtype})) {
18000: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18001: $alltypes{$newtype} =~ s/`//g;
18002: my $position = $env{'form.addinststatus_pos'};
18003: $position =~ s/\D+//g;
18004: if ($position ne '') {
18005: $allpos[$position] = $newtype;
18006: }
18007: }
18008: }
1.160.6.93 raeburn 18009: my @orderedstatus;
1.160.6.40 raeburn 18010: foreach my $type (@allpos) {
18011: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18012: push(@orderedstatus,$type);
18013: }
18014: }
18015: foreach my $type (keys(%alltypes)) {
18016: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18017: delete($alltypes{$type});
18018: }
18019: }
18020: $defaults_hash{'inststatus'} = {
18021: inststatustypes => \%alltypes,
18022: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 18023: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 18024: };
18025: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18026: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18027: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18028: }
18029: }
18030: if ($currorder ne join(',',@orderedstatus)) {
18031: $changes{'inststatus'}{'inststatusorder'} = 1;
18032: }
18033: my $newtitles;
18034: foreach my $item (@orderedstatus) {
18035: $newtitles .= $alltypes{$item}.',';
18036: }
18037: $newtitles =~ s/,$//;
18038: if ($currtitles ne $newtitles) {
18039: $changes{'inststatus'}{'inststatustypes'} = 1;
18040: }
1.43 raeburn 18041: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18042: $dom);
18043: if ($putresult eq 'ok') {
18044: if (keys(%changes) > 0) {
18045: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 18046: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18047: 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";
18048: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 18049: if ($item eq 'inststatus') {
18050: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 18051: if (@orderedstatus) {
1.160.6.40 raeburn 18052: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18053: foreach my $type (@orderedstatus) {
18054: $resulttext .= $alltypes{$type}.', ';
18055: }
18056: $resulttext =~ s/, $//;
18057: $resulttext .= '</li>';
1.160.6.93 raeburn 18058: } else {
18059: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 18060: }
18061: }
1.160.6.118.2 8(raebur 18062:2): } elsif ($item eq 'unamemap_rule') {
18063:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
18064:2): my @rulenames;
18065:2): if (ref($unamemaprules) eq 'HASH') {
18066:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
18067:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
18068:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
18069:2): }
18070:2): }
18071:2): }
18072:2): if (@rulenames) {
18073:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
18074:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
18075:2): '</li>';
18076:2): } else {
14(raebu 18077:23): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
18078:23): }
8(raebur 18079:2): } else {
18080:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
18081:2): }
1.160.6.40 raeburn 18082: } else {
18083: my $value = $env{'form.'.$item};
18084: if ($value eq '') {
18085: $value = &mt('none');
18086: } elsif ($item eq 'auth_def') {
18087: my %authnames = &authtype_names();
18088: my %shortauth = (
18089: internal => 'int',
18090: krb4 => 'krb4',
18091: krb5 => 'krb5',
18092: localauth => 'loc',
1.160.6.118.2 14(raebu 18093:23): lti => 'lti',
1.160.6.40 raeburn 18094: );
18095: $value = $authnames{$shortauth{$value}};
18096: }
18097: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 18098:23): $mailmsgtext .= "$title->{$item} set to $value\n";
18099:23): if ($item eq 'portal_def') {
18100:23): if ($env{'form.'.$item} ne '') {
18101:23): foreach my $field ('email','web') {
18102:23): $value = $env{'form.'.$item.'_'.$field};
18103:23): if ($value) {
18104:23): $value = &mt('Yes');
18105:23): } else {
18106:23): $value = &mt('No');
18107:23): }
18108:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
18109:23): }
18110:23): }
18111:23): }
1.43 raeburn 18112: }
18113: }
18114: $resulttext .= '</ul>';
18115: $mailmsgtext .= "\n";
18116: my $cachetime = 24*60*60;
1.72 raeburn 18117: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 18118: if (ref($lastactref) eq 'HASH') {
18119: $lastactref->{'domdefaults'} = 1;
18120: }
1.68 raeburn 18121: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 18122: my $notify = 1;
18123: if (ref($domconfig{'contacts'}) eq 'HASH') {
18124: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18125: $notify = 0;
18126: }
18127: }
18128: if ($notify) {
18129: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18130: "LON-CAPA Domain Settings Change - $dom",
18131: $mailmsgtext);
18132: }
1.54 raeburn 18133: }
1.43 raeburn 18134: } else {
1.54 raeburn 18135: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18136: }
18137: } else {
18138: $resulttext = '<span class="LC_error">'.
18139: &mt('An error occurred: [_1]',$putresult).'</span>';
18140: }
18141: if (@errors > 0) {
18142: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18143: foreach my $item (@errors) {
18144: $resulttext .= ' "'.$title->{$item}.'",';
18145: }
18146: $resulttext =~ s/,$//;
18147: }
18148: return $resulttext;
18149: }
18150:
1.46 raeburn 18151: sub modify_scantron {
1.160.6.24 raeburn 18152: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18153: my ($resulttext,%confhash,%changes,$errors);
18154: my $custom = 'custom.tab';
18155: my $default = 'default.tab';
18156: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 18157: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18158: &config_check($dom,$confname,$servadm);
18159: if ($env{'form.scantronformat.filename'} ne '') {
18160: my $error;
18161: if ($configuserok eq 'ok') {
18162: if ($switchserver) {
1.130 raeburn 18163: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18164: } else {
18165: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 18166:23): my $modified = [];
1.46 raeburn 18167: my ($result,$scantronurl) =
1.160.6.118.2 14(raebu 18168:23): &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
18169:23): $confname,'scantron','','',$custom,
18170:23): $modified);
1.46 raeburn 18171: if ($result eq 'ok') {
18172: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18173: $changes{'scantronformat'} = 1;
1.160.6.118.2 14(raebu 18174:23): &update_modify_urls($r,$modified);
1.46 raeburn 18175: } else {
18176: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18177: }
18178: } else {
18179: $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);
18180: }
18181: }
18182: } else {
18183: $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);
18184: }
18185: if ($error) {
18186: &Apache::lonnet::logthis($error);
18187: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18188: }
18189: }
1.48 raeburn 18190: if (ref($domconfig{'scantron'}) eq 'HASH') {
18191: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18192: if ($env{'form.scantronformat_del'}) {
18193: $confhash{'scantron'}{'scantronformat'} = '';
18194: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 18195: } else {
18196: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
18197: }
18198: }
18199: }
18200: my @options = ('hdr','pad','rem');
18201: my @fields = &scantroncsv_fields();
18202: my %titles = &scantronconfig_titles();
18203: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
18204: my ($newdat,$currdat,%newcol,%currcol);
18205: if (grep(/^dat$/,@formats)) {
18206: $confhash{'scantron'}{config}{dat} = 1;
18207: $newdat = 1;
18208: } else {
18209: $newdat = 0;
18210: }
18211: if (grep(/^csv$/,@formats)) {
18212: my %bynum;
18213: foreach my $field (@fields) {
18214: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18215: my $posscol = $1;
18216: if (($posscol < 20) && (!$bynum{$posscol})) {
18217: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
18218: $bynum{$posscol} = $field;
18219: $newcol{$field} = $posscol;
18220: }
18221: }
18222: }
18223: if (keys(%newcol)) {
18224: foreach my $option (@options) {
18225: if ($env{'form.scantroncsv_'.$option}) {
18226: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18227: }
18228: }
18229: }
18230: }
18231: $currdat = 1;
18232: if (ref($domconfig{'scantron'}) eq 'HASH') {
18233: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
18234: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
18235: $currdat = 0;
18236: }
18237: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18238: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18239: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18240: }
18241: }
18242: }
18243: }
18244: if ($currdat != $newdat) {
18245: $changes{'config'} = 1;
18246: } else {
18247: foreach my $field (@fields) {
18248: if ($currcol{$field} ne '') {
18249: if ($currcol{$field} ne $newcol{$field}) {
18250: $changes{'config'} = 1;
18251: last;
18252: }
18253: } elsif ($newcol{$field} ne '') {
18254: $changes{'config'} = 1;
18255: last;
1.46 raeburn 18256: }
18257: }
18258: }
18259: if (keys(%confhash) > 0) {
18260: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18261: $dom);
18262: if ($putresult eq 'ok') {
18263: if (keys(%changes) > 0) {
1.48 raeburn 18264: if (ref($confhash{'scantron'}) eq 'HASH') {
18265: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 18266: if ($changes{'scantronformat'}) {
18267: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18268: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18269: } else {
18270: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18271: }
18272: }
18273: if ($changes{'config'}) {
18274: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18275: if ($confhash{'scantron'}{'config'}{'dat'}) {
18276: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18277: }
18278: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18279: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18280: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18281: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18282: foreach my $field (@fields) {
18283: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18284: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18285: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18286: }
18287: }
18288: $resulttext .= '</ul></li>';
18289: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18290: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18291: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18292: foreach my $option (@options) {
18293: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18294: $resulttext .= '<li>'.$titles{$option}.'</li>';
18295: }
18296: }
18297: $resulttext .= '</ul></li>';
18298: }
18299: }
18300: }
18301: }
18302: }
18303: } else {
18304: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18305: }
1.46 raeburn 18306: }
1.48 raeburn 18307: $resulttext .= '</ul>';
18308: } else {
1.130 raeburn 18309: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18310: }
18311: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 18312: if (ref($lastactref) eq 'HASH') {
18313: $lastactref->{'domainconfig'} = 1;
18314: }
1.46 raeburn 18315: } else {
1.160.6.97 raeburn 18316: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18317: }
18318: } else {
18319: $resulttext = '<span class="LC_error">'.
18320: &mt('An error occurred: [_1]',$putresult).'</span>';
18321: }
18322: } else {
1.160.6.97 raeburn 18323: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18324: }
18325: if ($errors) {
1.160.6.118.2 14(raebu 18326:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18327:23): $errors.'</ul></p>';
1.46 raeburn 18328: }
18329: return $resulttext;
18330: }
18331:
1.48 raeburn 18332: sub modify_coursecategories {
1.160.6.43 raeburn 18333: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18334: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18335: $cathash);
1.48 raeburn 18336: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 18337: my @catitems = ('unauth','auth');
18338: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18339: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18340: $cathash = $domconfig{'coursecategories'}{'cats'};
18341: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18342: $changes{'togglecats'} = 1;
18343: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18344: }
18345: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18346: $changes{'categorize'} = 1;
18347: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18348: }
1.120 raeburn 18349: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18350: $changes{'togglecatscomm'} = 1;
18351: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18352: }
18353: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18354: $changes{'categorizecomm'} = 1;
18355: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
18356: }
1.160.6.42 raeburn 18357: foreach my $item (@catitems) {
18358: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18359: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18360: $changes{$item} = 1;
18361: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18362: }
18363: }
18364: }
1.57 raeburn 18365: } else {
18366: $changes{'togglecats'} = 1;
18367: $changes{'categorize'} = 1;
1.124 raeburn 18368: $changes{'togglecatscomm'} = 1;
18369: $changes{'categorizecomm'} = 1;
1.87 raeburn 18370: $domconfig{'coursecategories'} = {
18371: togglecats => $env{'form.togglecats'},
18372: categorize => $env{'form.categorize'},
1.124 raeburn 18373: togglecatscomm => $env{'form.togglecatscomm'},
18374: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 18375: };
1.160.6.42 raeburn 18376: foreach my $item (@catitems) {
18377: if ($env{'form.coursecat_'.$item} ne 'std') {
18378: $changes{$item} = 1;
18379: }
18380: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18381: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18382: }
18383: }
1.57 raeburn 18384: }
18385: if (ref($cathash) eq 'HASH') {
18386: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18387: push (@deletecategory,'instcode::0');
18388: }
1.120 raeburn 18389: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18390: push(@deletecategory,'communities::0');
18391: }
1.48 raeburn 18392: }
1.57 raeburn 18393: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18394: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18395: if (@deletecategory > 0) {
18396: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18397: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18398: foreach my $item (@deletecategory) {
1.57 raeburn 18399: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18400: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18401: $deletions{$item} = 1;
1.57 raeburn 18402: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18403: }
18404: }
18405: }
1.57 raeburn 18406: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18407: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18408: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18409: $reorderings{$item} = 1;
1.57 raeburn 18410: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18411: }
18412: if ($env{'form.addcategory_name_'.$item} ne '') {
18413: my $newcat = $env{'form.addcategory_name_'.$item};
18414: my $newdepth = $depth+1;
18415: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18416: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18417: $adds{$newitem} = 1;
18418: }
18419: if ($env{'form.subcat_'.$item} ne '') {
18420: my $newcat = $env{'form.subcat_'.$item};
18421: my $newdepth = $depth+1;
18422: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18423: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18424: $adds{$newitem} = 1;
18425: }
18426: }
18427: }
18428: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18429: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18430: my $newitem = 'instcode::0';
1.57 raeburn 18431: if ($cathash->{$newitem} eq '') {
18432: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18433: $adds{$newitem} = 1;
18434: }
18435: } else {
18436: my $newitem = 'instcode::0';
1.57 raeburn 18437: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18438: $adds{$newitem} = 1;
18439: }
18440: }
1.120 raeburn 18441: if ($env{'form.communities'} eq '1') {
18442: if (ref($cathash) eq 'HASH') {
18443: my $newitem = 'communities::0';
18444: if ($cathash->{$newitem} eq '') {
18445: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18446: $adds{$newitem} = 1;
18447: }
18448: } else {
18449: my $newitem = 'communities::0';
18450: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18451: $adds{$newitem} = 1;
18452: }
18453: }
1.48 raeburn 18454: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18455: if (($env{'form.addcategory_name'} ne 'instcode') &&
18456: ($env{'form.addcategory_name'} ne 'communities')) {
18457: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18458: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18459: $adds{$newitem} = 1;
18460: }
1.48 raeburn 18461: }
1.57 raeburn 18462: my $putresult;
1.48 raeburn 18463: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18464: if (keys(%deletions) > 0) {
18465: foreach my $key (keys(%deletions)) {
18466: if ($predelallitems{$key} ne '') {
18467: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18468: }
18469: }
18470: }
18471: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18472: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18473: if (ref($chkcats[0]) eq 'ARRAY') {
18474: my $depth = 0;
18475: my $chg = 0;
18476: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18477: my $name = $chkcats[0][$i];
18478: my $item;
18479: if ($name eq '') {
18480: $chg ++;
18481: } else {
18482: $item = &escape($name).'::0';
18483: if ($chg) {
1.57 raeburn 18484: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18485: }
18486: $depth ++;
1.57 raeburn 18487: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18488: $depth --;
18489: }
18490: }
18491: }
1.57 raeburn 18492: }
18493: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18494: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18495: if ($putresult eq 'ok') {
1.57 raeburn 18496: my %title = (
1.120 raeburn 18497: togglecats => 'Show/Hide a course in catalog',
18498: categorize => 'Assign a category to a course',
18499: togglecatscomm => 'Show/Hide a community in catalog',
18500: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18501: );
18502: my %level = (
1.120 raeburn 18503: dom => 'set in Domain ("Modify Course/Community")',
18504: crs => 'set in Course ("Course Configuration")',
18505: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 18506: none => 'No catalog',
18507: std => 'Standard catalog',
18508: domonly => 'Domain-only catalog',
18509: codesrch => 'Code search form',
1.57 raeburn 18510: );
1.48 raeburn 18511: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18512: if ($changes{'togglecats'}) {
18513: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18514: }
18515: if ($changes{'categorize'}) {
18516: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18517: }
1.120 raeburn 18518: if ($changes{'togglecatscomm'}) {
18519: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18520: }
18521: if ($changes{'categorizecomm'}) {
18522: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18523: }
1.160.6.42 raeburn 18524: if ($changes{'unauth'}) {
18525: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18526: }
18527: if ($changes{'auth'}) {
18528: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18529: }
1.57 raeburn 18530: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18531: my $cathash;
18532: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18533: $cathash = $domconfig{'coursecategories'}{'cats'};
18534: } else {
18535: $cathash = {};
18536: }
18537: my (@cats,@trails,%allitems);
18538: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18539: if (keys(%deletions) > 0) {
18540: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18541: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18542: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18543: }
18544: $resulttext .= '</ul></li>';
18545: }
18546: if (keys(%reorderings) > 0) {
18547: my %sort_by_trail;
18548: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18549: foreach my $key (keys(%reorderings)) {
18550: if ($allitems{$key} ne '') {
18551: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18552: }
1.48 raeburn 18553: }
1.57 raeburn 18554: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18555: $resulttext .= '<li>'.$trails[$trail].'</li>';
18556: }
18557: $resulttext .= '</ul></li>';
1.48 raeburn 18558: }
1.57 raeburn 18559: if (keys(%adds) > 0) {
18560: my %sort_by_trail;
18561: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18562: foreach my $key (keys(%adds)) {
18563: if ($allitems{$key} ne '') {
18564: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18565: }
18566: }
18567: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18568: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18569: }
1.57 raeburn 18570: $resulttext .= '</ul></li>';
1.48 raeburn 18571: }
1.160.6.92 raeburn 18572: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18573: if (ref($lastactref) eq 'HASH') {
18574: $lastactref->{'cats'} = 1;
18575: }
1.48 raeburn 18576: }
18577: $resulttext .= '</ul>';
1.160.6.43 raeburn 18578: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 18579: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18580: if ($changes{'auth'}) {
18581: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18582: }
18583: if ($changes{'unauth'}) {
18584: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18585: }
18586: my $cachetime = 24*60*60;
18587: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 18588: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 18589: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 18590: }
18591: }
1.48 raeburn 18592: } else {
18593: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18594: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18595: }
18596: } else {
1.120 raeburn 18597: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18598: }
18599: return $resulttext;
18600: }
18601:
1.69 raeburn 18602: sub modify_serverstatuses {
18603: my ($dom,%domconfig) = @_;
18604: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18605: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18606: %currserverstatus = %{$domconfig{'serverstatuses'}};
18607: }
18608: my @pages = &serverstatus_pages();
18609: foreach my $type (@pages) {
18610: $newserverstatus{$type}{'namedusers'} = '';
18611: $newserverstatus{$type}{'machines'} = '';
18612: if (defined($env{'form.'.$type.'_namedusers'})) {
18613: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18614: my @okusers;
18615: foreach my $user (@users) {
18616: my ($uname,$udom) = split(/:/,$user);
18617: if (($udom =~ /^$match_domain$/) &&
18618: (&Apache::lonnet::domain($udom)) &&
18619: ($uname =~ /^$match_username$/)) {
18620: if (!grep(/^\Q$user\E/,@okusers)) {
18621: push(@okusers,$user);
18622: }
18623: }
18624: }
18625: if (@okusers > 0) {
18626: @okusers = sort(@okusers);
18627: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18628: }
18629: }
18630: if (defined($env{'form.'.$type.'_machines'})) {
18631: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18632: my @okmachines;
18633: foreach my $ip (@machines) {
18634: my @parts = split(/\./,$ip);
18635: next if (@parts < 4);
18636: my $badip = 0;
18637: for (my $i=0; $i<4; $i++) {
18638: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18639: $badip = 1;
18640: last;
18641: }
18642: }
18643: if (!$badip) {
18644: push(@okmachines,$ip);
18645: }
18646: }
18647: @okmachines = sort(@okmachines);
18648: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18649: }
18650: }
18651: my %serverstatushash = (
18652: serverstatuses => \%newserverstatus,
18653: );
18654: foreach my $type (@pages) {
1.83 raeburn 18655: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18656: my (@current,@new);
1.83 raeburn 18657: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18658: if ($currserverstatus{$type}{$setting} ne '') {
18659: @current = split(/,/,$currserverstatus{$type}{$setting});
18660: }
18661: }
18662: if ($newserverstatus{$type}{$setting} ne '') {
18663: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18664: }
18665: if (@current > 0) {
18666: if (@new > 0) {
18667: foreach my $item (@current) {
18668: if (!grep(/^\Q$item\E$/,@new)) {
18669: $changes{$type}{$setting} = 1;
1.82 raeburn 18670: last;
18671: }
18672: }
1.84 raeburn 18673: foreach my $item (@new) {
18674: if (!grep(/^\Q$item\E$/,@current)) {
18675: $changes{$type}{$setting} = 1;
18676: last;
1.82 raeburn 18677: }
18678: }
18679: } else {
1.83 raeburn 18680: $changes{$type}{$setting} = 1;
1.69 raeburn 18681: }
1.83 raeburn 18682: } elsif (@new > 0) {
18683: $changes{$type}{$setting} = 1;
1.69 raeburn 18684: }
18685: }
18686: }
18687: if (keys(%changes) > 0) {
1.81 raeburn 18688: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18689: my $putresult = &Apache::lonnet::put_dom('configuration',
18690: \%serverstatushash,$dom);
18691: if ($putresult eq 'ok') {
18692: $resulttext .= &mt('Changes made:').'<ul>';
18693: foreach my $type (@pages) {
1.84 raeburn 18694: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18695: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18696: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18697: if ($newserverstatus{$type}{'namedusers'} eq '') {
18698: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18699: } else {
18700: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18701: }
1.84 raeburn 18702: }
18703: if ($changes{$type}{'machines'}) {
1.69 raeburn 18704: if ($newserverstatus{$type}{'machines'} eq '') {
18705: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18706: } else {
18707: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18708: }
18709:
18710: }
18711: $resulttext .= '</ul></li>';
18712: }
18713: }
18714: $resulttext .= '</ul>';
18715: } else {
18716: $resulttext = '<span class="LC_error">'.
18717: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18718:
18719: }
18720: } else {
18721: $resulttext = &mt('No changes made to access to server status pages');
18722: }
18723: return $resulttext;
18724: }
18725:
1.118 jms 18726: sub modify_helpsettings {
1.160.6.77 raeburn 18727: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 18728: my ($resulttext,$errors,%changes,%helphash);
18729: my %defaultchecked = ('submitbugs' => 'on');
18730: my @offon = ('off','on');
1.118 jms 18731: my @toggles = ('submitbugs');
1.160.6.77 raeburn 18732: my %current = ('submitbugs' => '',
18733: 'adhoc' => {},
18734: );
1.118 jms 18735: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 18736: %current = %{$domconfig{'helpsettings'}};
18737: }
1.160.6.77 raeburn 18738: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 18739: foreach my $item (@toggles) {
18740: if ($defaultchecked{$item} eq 'on') {
18741: if ($current{$item} eq '') {
18742: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 18743: $changes{$item} = 1;
18744: }
1.160.6.73 raeburn 18745: } elsif ($current{$item} ne $env{'form.'.$item}) {
18746: $changes{$item} = 1;
18747: }
18748: } elsif ($defaultchecked{$item} eq 'off') {
18749: if ($current{$item} eq '') {
18750: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 18751: $changes{$item} = 1;
18752: }
1.160.6.73 raeburn 18753: } elsif ($current{$item} ne $env{'form.'.$item}) {
18754: $changes{$item} = 1;
18755: }
18756: }
18757: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18758: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18759: }
18760: }
1.160.6.77 raeburn 18761: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 18762: my $confname = $dom.'-domainconfig';
18763: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 18764: my (@allpos,%newsettings,%changedprivs,$newrole);
18765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 18766: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18767: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 18768: my %lt = &Apache::lonlocal::texthash(
18769: s => 'system',
18770: d => 'domain',
18771: order => 'Display order',
18772: access => 'Role usage',
1.160.6.79 raeburn 18773: all => 'All with domain helpdesk or helpdesk assistant role',
18774: dh => 'All with domain helpdesk role',
18775: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 18776: none => 'None',
18777: status => 'Determined based on institutional status',
18778: inc => 'Include all, but exclude specific personnel',
18779: exc => 'Exclude all, but include specific personnel',
18780: );
18781: for (my $num=0; $num<=$maxnum; $num++) {
18782: my ($prefix,$identifier,$rolename,%curr);
18783: if ($num == $maxnum) {
18784: next unless ($env{'form.newcusthelp'} == $maxnum);
18785: $identifier = 'custhelp'.$num;
18786: $prefix = 'helproles_'.$num;
18787: $rolename = $env{'form.custhelpname'.$num};
18788: $rolename=~s/[^A-Za-z0-9]//gs;
18789: next if ($rolename eq '');
18790: next if (exists($existing{'rolesdef_'.$rolename}));
18791: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18792: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18793: $newprivs{'c'},$confname,$dom);
18794: if ($result ne 'ok') {
18795: $errors .= '<li><span class="LC_error">'.
18796: &mt('An error occurred storing the new custom role: [_1]',
18797: $result).'</span></li>';
18798: next;
18799: } else {
18800: $changedprivs{$rolename} = \%newprivs;
18801: $newrole = $rolename;
18802: }
18803: } else {
18804: $prefix = 'helproles_'.$num;
18805: $rolename = $env{'form.'.$prefix};
18806: next if ($rolename eq '');
18807: next unless (exists($existing{'rolesdef_'.$rolename}));
18808: $identifier = 'custhelp'.$num;
18809: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18810: my %currprivs;
18811: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18812: split(/\_/,$existing{'rolesdef_'.$rolename});
18813: foreach my $level ('c','d','s') {
18814: if ($newprivs{$level} ne $currprivs{$level}) {
18815: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18816: $newprivs{'c'},$confname,$dom);
18817: if ($result ne 'ok') {
18818: $errors .= '<li><span class="LC_error">'.
18819: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18820: $rolename,$result).'</span></li>';
18821: } else {
18822: $changedprivs{$rolename} = \%newprivs;
18823: }
18824: last;
18825: }
18826: }
18827: if (ref($current{'adhoc'}) eq 'HASH') {
18828: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18829: %curr = %{$current{'adhoc'}{$rolename}};
18830: }
18831: }
18832: }
18833: my $newpos = $env{'form.'.$prefix.'_pos'};
18834: $newpos =~ s/\D+//g;
18835: $allpos[$newpos] = $rolename;
18836: my $newdesc = $env{'form.'.$prefix.'_desc'};
18837: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18838: if ($curr{'desc'}) {
18839: if ($curr{'desc'} ne $newdesc) {
18840: $changes{'customrole'}{$rolename}{'desc'} = 1;
18841: $newsettings{$rolename}{'desc'} = $newdesc;
18842: }
18843: } elsif ($newdesc ne '') {
18844: $changes{'customrole'}{$rolename}{'desc'} = 1;
18845: $newsettings{$rolename}{'desc'} = $newdesc;
18846: }
18847: my $access = $env{'form.'.$prefix.'_access'};
18848: if (grep(/^\Q$access\E$/,@accesstypes)) {
18849: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18850: if ($access eq 'status') {
18851: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18852: if (scalar(@statuses) == 0) {
18853: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18854: } else {
18855: my (@shownstatus,$numtypes);
18856: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18857: if (ref($types) eq 'ARRAY') {
18858: $numtypes = scalar(@{$types});
18859: foreach my $type (sort(@statuses)) {
18860: if ($type eq 'default') {
18861: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18862: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18863: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18864: push(@shownstatus,$usertypes->{$type});
18865: }
1.160.6.73 raeburn 18866: }
18867: }
1.160.6.77 raeburn 18868: if (grep(/^default$/,@statuses)) {
18869: push(@shownstatus,$othertitle);
18870: }
18871: if (scalar(@shownstatus) == 1+$numtypes) {
18872: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18873: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18874: } else {
18875: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18876: if (ref($curr{'status'}) eq 'ARRAY') {
18877: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18878: if (@diffs) {
18879: $changes{'customrole'}{$rolename}{$access} = 1;
18880: }
18881: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18882: $changes{'customrole'}{$rolename}{$access} = 1;
18883: }
18884: }
18885: }
18886: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18887: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18888: my @newspecstaff;
18889: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18890: foreach my $person (sort(@personnel)) {
18891: if ($domhelpdesk{$person}) {
18892: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18893: }
18894: }
18895: if (ref($curr{$access}) eq 'ARRAY') {
18896: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18897: if (@diffs) {
18898: $changes{'customrole'}{$rolename}{$access} = 1;
18899: }
18900: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18901: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 18902: }
1.160.6.77 raeburn 18903: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18904: my ($uname,$udom) = split(/:/,$person);
18905: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18906: }
18907: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 18908: }
1.160.6.77 raeburn 18909: } else {
18910: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18911: }
18912: unless ($curr{'access'} eq $access) {
18913: $changes{'customrole'}{$rolename}{'access'} = 1;
18914: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 18915: }
18916: }
1.160.6.77 raeburn 18917: if (@allpos > 0) {
18918: my $idx = 0;
18919: foreach my $rolename (@allpos) {
18920: if ($rolename ne '') {
18921: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18922: if (ref($current{'adhoc'}) eq 'HASH') {
18923: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18924: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18925: $changes{'customrole'}{$rolename}{'order'} = 1;
18926: $newsettings{$rolename}{'order'} = $idx+1;
18927: }
18928: }
1.160.6.73 raeburn 18929: }
1.160.6.77 raeburn 18930: $idx ++;
1.122 jms 18931: }
18932: }
1.118 jms 18933: }
1.123 jms 18934: my $putresult;
18935: if (keys(%changes) > 0) {
1.160.6.5 raeburn 18936: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18937: if ($putresult eq 'ok') {
1.160.6.77 raeburn 18938: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18939: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18940: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18941: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18942: }
18943: }
18944: my $cachetime = 24*60*60;
18945: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18946: if (ref($lastactref) eq 'HASH') {
18947: $lastactref->{'domdefaults'} = 1;
18948: }
18949: } else {
18950: $errors .= '<li><span class="LC_error">'.
18951: &mt('An error occurred storing the settings: [_1]',
18952: $putresult).'</span></li>';
18953: }
18954: }
18955: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18956: $resulttext = &mt('Changes made:').'<ul>';
18957: my (%shownprivs,@levelorder);
18958: @levelorder = ('c','d','s');
18959: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 18960: foreach my $item (sort(keys(%changes))) {
18961: if ($item eq 'submitbugs') {
18962: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18963: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18964: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 18965: } elsif ($item eq 'customrole') {
18966: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 18967: my @keyorder = ('order','desc','access','status','exc','inc');
18968: my %keytext = &Apache::lonlocal::texthash(
18969: order => 'Order',
18970: desc => 'Role description',
18971: access => 'Role usage',
1.160.6.83 raeburn 18972: status => 'Allowed institutional types',
1.160.6.77 raeburn 18973: exc => 'Allowed personnel',
18974: inc => 'Disallowed personnel',
18975: );
1.160.6.73 raeburn 18976: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 18977: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18978: if ($role eq $newrole) {
18979: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18980: $role).'<ul>';
18981: } else {
18982: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18983: $role).'<ul>';
18984: }
18985: foreach my $key (@keyorder) {
18986: if ($changes{'customrole'}{$role}{$key}) {
18987: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18988: $keytext{$key},$newsettings{$role}{$key}).
18989: '</li>';
18990: }
18991: }
18992: if (ref($changedprivs{$role}) eq 'HASH') {
18993: $shownprivs{$role} = 1;
18994: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18995: foreach my $level (@levelorder) {
18996: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18997: next if ($item eq '');
18998: my ($priv) = split(/\&/,$item,2);
18999: if (&Apache::lonnet::plaintext($priv)) {
19000: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19001: unless ($level eq 'c') {
19002: $resulttext .= ' ('.$lt{$level}.')';
19003: }
19004: $resulttext .= '</li>';
19005: }
19006: }
19007: }
19008: $resulttext .= '</ul>';
19009: }
19010: $resulttext .= '</ul></li>';
19011: }
1.160.6.73 raeburn 19012: }
19013: }
1.160.6.5 raeburn 19014: }
19015: }
19016: }
1.160.6.77 raeburn 19017: if (keys(%changedprivs)) {
19018: foreach my $role (sort(keys(%changedprivs))) {
19019: unless ($shownprivs{$role}) {
19020: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19021: $role).'<ul>'.
19022: '<li>'.&mt('Privileges set to :').'<ul>';
19023: foreach my $level (@levelorder) {
19024: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19025: next if ($item eq '');
19026: my ($priv) = split(/\&/,$item,2);
19027: if (&Apache::lonnet::plaintext($priv)) {
19028: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19029: unless ($level eq 'c') {
19030: $resulttext .= ' ('.$lt{$level}.')';
19031: }
19032: $resulttext .= '</li>';
19033: }
19034: }
19035: }
19036: $resulttext .= '</ul></li></ul></li>';
19037: }
19038: }
19039: }
19040: $resulttext .= '</ul>';
19041: } else {
19042: $resulttext = &mt('No changes made to help settings');
1.118 jms 19043: }
19044: if ($errors) {
1.160.6.5 raeburn 19045: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 19046: $errors.'</ul>';
1.118 jms 19047: }
19048: return $resulttext;
19049: }
19050:
1.121 raeburn 19051: sub modify_coursedefaults {
1.160.6.27 raeburn 19052: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19053: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 19054: my %defaultchecked = (
19055: 'uselcmath' => 'on',
1.160.6.115 raeburn 19056: 'usejsme' => 'on',
19057: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 19058:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 19059: );
1.160.6.118.2 4(raebur 19060:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 19061: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.118.2 15(raebu 19062:23): 'uploadquota_community','uploadquota_textbook','coursequota_official',
19063:23): 'coursequota_unofficial','coursequota_community','coursequota_textbook',
19064:23): 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19065:23): 'mysqltables_textbook');
1.160.6.30 raeburn 19066: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 19067: my %staticdefaults = (
19068: anonsurvey_threshold => 10,
19069: uploadquota => 500,
1.160.6.118.2 15(raebu 19070:23): coursequota => 20,
1.160.6.57 raeburn 19071: postsubmit => 60,
1.160.6.70 raeburn 19072: mysqltables => 172800,
1.160.6.118.2 14(raebu 19073:23): domexttool => 1,
22(raebu 19074:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 19075: );
1.160.6.90 raeburn 19076: my %texoptions = (
19077: MathJax => 'MathJax',
19078: mimetex => &mt('Convert to Images'),
19079: tth => &mt('TeX to HTML'),
19080: );
1.160.6.118.2 22(raebu 19081:24):
19082:24): my @editors = ('edit','xml','daxe');
19083:24): my %editornames = &crseditor_titles();
19084:24):
1.121 raeburn 19085: $defaultshash{'coursedefaults'} = {};
19086:
19087: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19088: if ($domconfig{'coursedefaults'} eq '') {
19089: $domconfig{'coursedefaults'} = {};
19090: }
19091: }
19092:
19093: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19094: foreach my $item (@toggles) {
19095: if ($defaultchecked{$item} eq 'on') {
19096: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19097: ($env{'form.'.$item} eq '0')) {
19098: $changes{$item} = 1;
1.160.6.16 raeburn 19099: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19100: $changes{$item} = 1;
19101: }
19102: } elsif ($defaultchecked{$item} eq 'off') {
19103: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19104: ($env{'form.'.$item} eq '1')) {
19105: $changes{$item} = 1;
19106: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19107: $changes{$item} = 1;
19108: }
19109: }
19110: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19111: }
1.160.6.21 raeburn 19112: foreach my $item (@numbers) {
19113: my ($currdef,$newdef);
1.160.6.26 raeburn 19114: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 19115: if ($item eq 'anonsurvey_threshold') {
19116: $currdef = $domconfig{'coursedefaults'}{$item};
19117: $newdef =~ s/\D//g;
19118: if ($newdef eq '' || $newdef < 1) {
19119: $newdef = 1;
19120: }
19121: $defaultshash{'coursedefaults'}{$item} = $newdef;
19122: } else {
1.160.6.118.2 15(raebu 19123:23): my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.160.6.70 raeburn 19124: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19125: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 19126: }
19127: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 19128: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 19129: }
19130: if ($currdef ne $newdef) {
19131: if ($item eq 'anonsurvey_threshold') {
19132: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19133: $changes{$item} = 1;
19134: }
1.160.6.118.2 15(raebu 19135:23): } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.160.6.70 raeburn 19136: my $setting = $1;
19137: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19138: $changes{$setting} = 1;
1.160.6.21 raeburn 19139: }
19140: }
1.139 raeburn 19141: }
19142: }
1.160.6.90 raeburn 19143: my $texengine;
19144: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19145: $texengine = $env{'form.texengine'};
19146: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19147: if ($currdef eq '') {
19148: unless ($texengine eq $Apache::lonnet::deftex) {
19149: $changes{'texengine'} = 1;
19150: }
19151: } elsif ($currdef ne $texengine) {
19152: $changes{'texengine'} = 1;
19153: }
19154: }
19155: if ($texengine ne '') {
19156: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19157: }
1.160.6.64 raeburn 19158: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19159: my @currclonecode;
19160: if (ref($currclone) eq 'HASH') {
19161: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19162: @currclonecode = @{$currclone->{'instcode'}};
19163: }
19164: }
19165: my $newclone;
19166: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
19167: $newclone = $env{'form.canclone'};
19168: }
19169: if ($newclone eq 'instcode') {
19170: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19171: my (%codedefaults,@code_order,@clonecode);
19172: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19173: \@code_order);
19174: foreach my $item (@code_order) {
19175: if (grep(/^\Q$item\E$/,@newcodes)) {
19176: push(@clonecode,$item);
19177: }
19178: }
19179: if (@clonecode) {
19180: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19181: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19182: if (@diffs) {
19183: $changes{'canclone'} = 1;
19184: }
19185: } else {
19186: $newclone eq '';
19187: }
19188: } elsif ($newclone ne '') {
19189: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19190: }
19191: if ($newclone ne $currclone) {
19192: $changes{'canclone'} = 1;
19193: }
1.160.6.57 raeburn 19194: my %credits;
19195: foreach my $type (@types) {
19196: unless ($type eq 'community') {
19197: $credits{$type} = $env{'form.'.$type.'_credits'};
19198: $credits{$type} =~ s/[^\d.]+//g;
19199: }
19200: }
19201: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19202: ($env{'form.coursecredits'} eq '1')) {
19203: $changes{'coursecredits'} = 1;
19204: foreach my $type (keys(%credits)) {
19205: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19206: }
19207: } else {
19208: if ($env{'form.coursecredits'} eq '1') {
19209: foreach my $type (@types) {
19210: unless ($type eq 'community') {
19211: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
19212: $changes{'coursecredits'} = 1;
19213: }
19214: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19215: }
19216: }
19217: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19218: foreach my $type (@types) {
19219: unless ($type eq 'community') {
19220: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19221: $changes{'coursecredits'} = 1;
19222: last;
19223: }
19224: }
19225: }
19226: }
19227: }
19228: if ($env{'form.postsubmit'} eq '1') {
19229: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19230: my %currtimeout;
19231: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19232: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19233: $changes{'postsubmit'} = 1;
19234: }
19235: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19236: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19237: }
19238: } else {
19239: $changes{'postsubmit'} = 1;
19240: }
19241: foreach my $type (@types) {
19242: my $timeout = $env{'form.'.$type.'_timeout'};
19243: $timeout =~ s/\D//g;
19244: if ($timeout == $staticdefaults{'postsubmit'}) {
19245: $timeout = '';
19246: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19247: $timeout = '0';
19248: }
19249: unless ($timeout eq '') {
19250: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19251: }
19252: if (exists($currtimeout{$type})) {
19253: if ($timeout ne $currtimeout{$type}) {
19254: $changes{'postsubmit'} = 1;
19255: }
19256: } elsif ($timeout ne '') {
19257: $changes{'postsubmit'} = 1;
19258: }
19259: }
19260: } else {
19261: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19262: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19263: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19264: $changes{'postsubmit'} = 1;
19265: }
19266: } else {
19267: $changes{'postsubmit'} = 1;
19268: }
1.160.6.16 raeburn 19269: }
1.160.6.118.2 22(raebu 19270:24): my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool,%posscrseditors);
14(raebu 19271:23): map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
19272:23): map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
22(raebu 19273:24): map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
14(raebu 19274:23): if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19275:23): %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
19276:23): } else {
19277:23): foreach my $type (@types) {
19278:23): if ($staticdefaults{'domexttool'}) {
19279:23): $olddomexttool{$type} = 1;
19280:23): } else {
19281:23): $olddomexttool{$type} = 0;
19282:23): }
19283:23): }
19284:23): }
19285:23): if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
19286:23): %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
19287:23): } else {
19288:23): foreach my $type (@types) {
19289:23): if ($staticdefaults{'exttool'}) {
19290:23): $oldexttool{$type} = 1;
19291:23): } else {
19292:23): $oldexttool{$type} = 0;
19293:23): }
19294:23): }
19295:23): }
22(raebu 19296:24): my @newcrseditors = ();
19297:24): foreach my $editor (@editors) {
19298:24): if ($posscrseditors{$editor}) {
19299:24): push(@newcrseditors,$editor);
19300:24): }
19301:24): }
19302:24): if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19303:24): my @diffs =
19304:24): &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
19305:24): \@newcrseditors);
19306:24): if (@diffs) {
19307:24): $changes{'crseditors'} = 1;
19308:24): }
19309:24): } else {
19310:24): my @diffs =
19311:24): &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
19312:24): \@newcrseditors);
19313:24): unless (@diffs == 0) {
19314:24): $changes{'crseditors'} = 1;
19315:24): }
19316:24): }
14(raebu 19317:23): foreach my $type (@types) {
19318:23): unless ($newdomexttool{$type}) {
19319:23): $newdomexttool{$type} = 0;
19320:23): }
19321:23): unless ($newexttool{$type}) {
19322:23): $newexttool{$type} = 0;
19323:23): }
19324:23): if ($newdomexttool{$type} != $olddomexttool{$type}) {
19325:23): $changes{'domexttool'} = 1;
19326:23): }
19327:23): if ($newexttool{$type} != $oldexttool{$type}) {
19328:23): $changes{'exttool'} = 1;
19329:23): }
19330:23): }
19331:23): $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
19332:23): $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
22(raebu 19333:24): $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 19334: }
19335: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19336: $dom);
19337: if ($putresult eq 'ok') {
19338: if (keys(%changes) > 0) {
1.160.6.27 raeburn 19339: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 19340: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 19341: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 19342: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 14(raebu 19343:23): ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
15(raebu 19344:23): ($changes{'exttool'}) || ($changes{'coursequota'})) {
4(raebur 19345:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 19346: if ($changes{$item}) {
19347: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19348: }
1.160.6.16 raeburn 19349: }
19350: if ($changes{'coursecredits'}) {
19351: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 19352: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19353: $domdefaults{$type.'credits'} =
19354: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19355: }
19356: }
19357: }
19358: if ($changes{'postsubmit'}) {
19359: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19360: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19361: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19362: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19363: $domdefaults{$type.'postsubtimeout'} =
19364: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19365: }
19366: }
1.160.6.16 raeburn 19367: }
19368: }
1.160.6.21 raeburn 19369: if ($changes{'uploadquota'}) {
19370: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19371: foreach my $type (@types) {
19372: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19373: }
19374: }
19375: }
1.160.6.118.2 15(raebu 19376:23): if ($changes{'coursequota'}) {
19377:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19378:23): foreach my $type (@types) {
19379:23): $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
19380:23): }
19381:23): }
19382:23): }
1.160.6.64 raeburn 19383: if ($changes{'canclone'}) {
19384: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19385: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19386: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19387: if (@clonecodes) {
19388: $domdefaults{'canclone'} = join('+',@clonecodes);
19389: }
19390: }
19391: } else {
19392: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19393: }
19394: }
1.160.6.118.2 14(raebu 19395:23): if ($changes{'domexttool'}) {
19396:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19397:23): foreach my $type (@types) {
19398:23): $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
19399:23): }
19400:23): }
19401:23): }
19402:23): if ($changes{'exttool'}) {
19403:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19404:23): foreach my $type (@types) {
19405:23): $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
19406:23): }
19407:23): }
19408:23): }
22(raebu 19409:24): if ($changes{'crseditors'}) {
19410:24): if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19411:24): $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
19412:24): }
19413:24): }
1.121 raeburn 19414: my $cachetime = 24*60*60;
19415: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 19416: if (ref($lastactref) eq 'HASH') {
19417: $lastactref->{'domdefaults'} = 1;
19418: }
1.121 raeburn 19419: }
19420: $resulttext = &mt('Changes made:').'<ul>';
19421: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 19422: if ($item eq 'uselcmath') {
1.121 raeburn 19423: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 19424: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 19425: } else {
1.160.6.57 raeburn 19426: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19427: }
19428: } elsif ($item eq 'usejsme') {
19429: if ($env{'form.'.$item} eq '1') {
19430: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19431: } else {
19432: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 19433: }
1.160.6.115 raeburn 19434: } elsif ($item eq 'inline_chem') {
19435: if ($env{'form.'.$item} eq '1') {
19436: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
19437: } else {
19438: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
19439: }
1.160.6.90 raeburn 19440: } elsif ($item eq 'texengine') {
19441: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19442: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19443: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19444: }
1.139 raeburn 19445: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 19446: $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 19447: } elsif ($item eq 'uploadquota') {
19448: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19449: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19450: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19451: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 19452: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.160.6.21 raeburn 19453: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19454: '</ul>'.
19455: '</li>';
19456: } else {
19457: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19458: }
1.160.6.118.2 15(raebu 19459:23): } elsif ($item eq 'coursequota') {
19460:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19461:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
19462:23): '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
19463:23): '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
19464:23): '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
19465:23): '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
19466:23): '</ul>'.
19467:23): '</li>';
19468:23): } else {
19469:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
19470:23): }
1.160.6.70 raeburn 19471: } elsif ($item eq 'mysqltables') {
19472: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19473: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19474: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19475: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19476: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19477: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19478: '</ul>'.
19479: '</li>';
19480: } else {
19481: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19482: }
1.160.6.57 raeburn 19483: } elsif ($item eq 'postsubmit') {
19484: if ($domdefaults{'postsubmit'} eq 'off') {
19485: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19486: } else {
19487: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
19488: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19489: $resulttext .= &mt('durations:').'<ul>';
19490: foreach my $type (@types) {
19491: $resulttext .= '<li>';
19492: my $timeout;
19493: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19494: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19495: }
19496: my $display;
19497: if ($timeout eq '0') {
19498: $display = &mt('unlimited');
19499: } elsif ($timeout eq '') {
19500: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19501: } else {
19502: $display = &mt('[quant,_1,second]',$timeout);
19503: }
19504: if ($type eq 'community') {
19505: $resulttext .= &mt('Communities');
19506: } elsif ($type eq 'official') {
19507: $resulttext .= &mt('Official courses');
19508: } elsif ($type eq 'unofficial') {
19509: $resulttext .= &mt('Unofficial courses');
19510: } elsif ($type eq 'textbook') {
19511: $resulttext .= &mt('Textbook courses');
19512: }
19513: $resulttext .= ' -- '.$display.'</li>';
19514: }
19515: $resulttext .= '</ul>';
19516: }
19517: $resulttext .= '</li>';
19518: }
1.160.6.16 raeburn 19519: } elsif ($item eq 'coursecredits') {
19520: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19521: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 19522: ($domdefaults{'unofficialcredits'} eq '') &&
19523: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 19524: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19525: } else {
19526: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19527: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19528: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 19529: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 19530: '</ul>'.
19531: '</li>';
19532: }
19533: } else {
19534: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19535: }
1.160.6.64 raeburn 19536: } elsif ($item eq 'canclone') {
19537: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19538: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19539: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19540: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19541: }
19542: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19543: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19544: } else {
19545: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
19546: }
1.160.6.118.2 4(raebur 19547:2): } elsif ($item eq 'ltiauth') {
19548:2): if ($env{'form.'.$item} eq '1') {
19549:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
19550:2): } else {
19551:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
19552:2): }
14(raebu 19553:23): } elsif ($item eq 'domexttool') {
19554:23): my @noyes = (&mt('no'),&mt('yes'));
19555:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19556:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
19557:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
19558:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
19559:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
19560:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
19561:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
19562:23): '</ul>'.
19563:23): '</li>';
19564:23): } else {
19565:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
19566:23): }
19567:23): } elsif ($item eq 'exttool') {
19568:23): my @noyes = (&mt('no'),&mt('yes'));
19569:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19570:23): $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
19571:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
19572:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
19573:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
19574:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
19575:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
19576:23): '</ul>'.
19577:23): '</li>';
19578:23): } else {
19579:23): $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
19580:23): }
22(raebu 19581:24): } elsif ($item eq 'crseditors') {
19582:24): if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
19583:24): my $shown;
19584:24): if (@{$defaultshash{'coursedefaults'}{$item}}) {
19585:24): $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
19586:24): } else {
19587:24): $shown = &mt('None');
19588:24): }
19589:24): $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
19590:24): }
1.140 raeburn 19591: }
1.121 raeburn 19592: }
19593: $resulttext .= '</ul>';
19594: } else {
19595: $resulttext = &mt('No changes made to course defaults');
19596: }
19597: } else {
19598: $resulttext = '<span class="LC_error">'.
19599: &mt('An error occurred: [_1]',$putresult).'</span>';
19600: }
19601: return $resulttext;
19602: }
19603:
1.160.6.37 raeburn 19604: sub modify_selfenrollment {
19605: my ($dom,$lastactref,%domconfig) = @_;
19606: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
19607: my @types = ('official','unofficial','community','textbook');
19608: my %titles = &tool_titles();
19609: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19610: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
19611: $ordered{'default'} = ['types','registered','approval','limit'];
19612:
19613: my (%roles,%shown,%toplevel);
19614: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19615:
19616: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19617: if ($domconfig{'selfenrollment'} eq '') {
19618: $domconfig{'selfenrollment'} = {};
19619: }
19620: }
19621: %toplevel = (
19622: admin => 'Configuration Rights',
19623: default => 'Default settings',
19624: validation => 'Validation of self-enrollment requests',
19625: );
19626: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
19627:
19628: if (ref($ordered{'admin'}) eq 'ARRAY') {
19629: foreach my $item (@{$ordered{'admin'}}) {
19630: foreach my $type (@types) {
19631: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19632: $selfenrollhash{'admin'}{$type}{$item} = 1;
19633: } else {
19634: $selfenrollhash{'admin'}{$type}{$item} = 0;
19635: }
19636: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19637: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19638: if ($selfenrollhash{'admin'}{$type}{$item} ne
19639: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19640: push(@{$changes{'admin'}{$type}},$item);
19641: }
19642: } else {
19643: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19644: push(@{$changes{'admin'}{$type}},$item);
19645: }
19646: }
19647: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19648: push(@{$changes{'admin'}{$type}},$item);
19649: }
19650: }
19651: }
19652: }
19653:
19654: foreach my $item (@{$ordered{'default'}}) {
19655: foreach my $type (@types) {
19656: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19657: if ($item eq 'types') {
19658: unless (($value eq 'all') || ($value eq 'dom')) {
19659: $value = '';
19660: }
19661: } elsif ($item eq 'registered') {
19662: unless ($value eq '1') {
19663: $value = 0;
19664: }
19665: } elsif ($item eq 'approval') {
19666: unless ($value =~ /^[012]$/) {
19667: $value = 0;
19668: }
19669: } else {
19670: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19671: $value = 'none';
19672: }
19673: }
19674: $selfenrollhash{'default'}{$type}{$item} = $value;
19675: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19676: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19677: if ($selfenrollhash{'default'}{$type}{$item} ne
19678: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19679: push(@{$changes{'default'}{$type}},$item);
19680: }
19681: } else {
19682: push(@{$changes{'default'}{$type}},$item);
19683: }
19684: } else {
19685: push(@{$changes{'default'}{$type}},$item);
19686: }
19687: if ($item eq 'limit') {
19688: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19689: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19690: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19691: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19692: }
19693: } else {
19694: $selfenrollhash{'default'}{$type}{'cap'} = '';
19695: }
19696: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19697: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19698: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19699: push(@{$changes{'default'}{$type}},'cap');
19700: }
19701: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19702: push(@{$changes{'default'}{$type}},'cap');
19703: }
19704: }
19705: }
19706: }
19707:
19708: foreach my $item (@{$itemsref}) {
19709: if ($item eq 'fields') {
19710: my @changed;
19711: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19712: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19713: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19714: }
19715: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19716: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19717: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19718: $domconfig{'selfenrollment'}{'validation'}{$item});
19719: } else {
19720: @changed = @{$selfenrollhash{'validation'}{$item}};
19721: }
19722: } else {
19723: @changed = @{$selfenrollhash{'validation'}{$item}};
19724: }
19725: if (@changed) {
19726: if ($selfenrollhash{'validation'}{$item}) {
19727: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19728: } else {
19729: $changes{'validation'}{$item} = &mt('None');
19730: }
19731: }
19732: } else {
19733: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19734: if ($item eq 'markup') {
19735: if ($env{'form.selfenroll_validation_'.$item}) {
19736: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19737: }
19738: }
19739: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19740: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19741: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19742: }
19743: }
19744: }
19745: }
19746:
19747: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19748: $dom);
19749: if ($putresult eq 'ok') {
19750: if (keys(%changes) > 0) {
19751: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19752: $resulttext = &mt('Changes made:').'<ul>';
19753: foreach my $key ('admin','default','validation') {
19754: if (ref($changes{$key}) eq 'HASH') {
19755: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19756: if ($key eq 'validation') {
19757: foreach my $item (@{$itemsref}) {
19758: if (exists($changes{$key}{$item})) {
19759: if ($item eq 'markup') {
19760: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19761: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19762: } else {
19763: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19764: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19765: }
19766: }
19767: }
19768: } else {
19769: foreach my $type (@types) {
19770: if ($type eq 'community') {
19771: $roles{'1'} = &mt('Community personnel');
19772: } else {
19773: $roles{'1'} = &mt('Course personnel');
19774: }
19775: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19776: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19777: if ($key eq 'admin') {
19778: my @mgrdc = ();
19779: if (ref($ordered{$key}) eq 'ARRAY') {
19780: foreach my $item (@{$ordered{'admin'}}) {
19781: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19782: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19783: push(@mgrdc,$item);
19784: }
19785: }
19786: }
19787: if (@mgrdc) {
19788: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19789: } else {
19790: delete($domdefaults{$type.'selfenrolladmdc'});
19791: }
19792: }
19793: } else {
19794: if (ref($ordered{$key}) eq 'ARRAY') {
19795: foreach my $item (@{$ordered{$key}}) {
19796: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19797: $domdefaults{$type.'selfenroll'.$item} =
19798: $selfenrollhash{$key}{$type}{$item};
19799: }
19800: }
19801: }
19802: }
19803: }
19804: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19805: foreach my $item (@{$ordered{$key}}) {
19806: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19807: $resulttext .= '<li>';
19808: if ($key eq 'admin') {
19809: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19810: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19811: } else {
19812: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19813: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19814: }
19815: $resulttext .= '</li>';
19816: }
19817: }
19818: $resulttext .= '</ul></li>';
19819: }
19820: }
19821: $resulttext .= '</ul></li>';
19822: }
19823: }
1.160.6.93 raeburn 19824: }
19825: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19826: my $cachetime = 24*60*60;
19827: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19828: if (ref($lastactref) eq 'HASH') {
19829: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 19830: }
19831: }
19832: $resulttext .= '</ul>';
19833: } else {
19834: $resulttext = &mt('No changes made to self-enrollment settings');
19835: }
19836: } else {
19837: $resulttext = '<span class="LC_error">'.
19838: &mt('An error occurred: [_1]',$putresult).'</span>';
19839: }
19840: return $resulttext;
19841: }
19842:
1.160.6.113 raeburn 19843: sub modify_wafproxy {
19844: my ($dom,$action,$lastactref,%domconfig) = @_;
19845: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19846: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19847: %wafproxy,%changes,%expirecache,%expiresaml);
19848: foreach my $server (sort(keys(%servers))) {
19849: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19850: if ($serverhome eq $server) {
19851: my $serverdom = &Apache::lonnet::host_domain($server);
19852: if ($serverdom eq $dom) {
19853: $canset{$server} = 1;
19854: }
19855: }
19856: }
19857: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19858: %{$values{$dom}} = ();
19859: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19860: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19861: }
19862: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19863: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19864: }
19865: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19866: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19867: }
19868: }
19869: my $output;
19870: if (keys(%canset)) {
19871: %{$wafproxy{'alias'}} = ();
19872: %{$wafproxy{'saml'}} = ();
19873: foreach my $key (sort(keys(%canset))) {
19874: if ($env{'form.wafproxy_'.$dom}) {
19875: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19876: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19877: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19878: $changes{'alias'} = 1;
19879: }
19880: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19881: $wafproxy{'saml'}{$key} = 1;
19882: }
19883: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19884: $changes{'saml'} = 1;
19885: }
19886: } else {
19887: $wafproxy{'alias'}{$key} = '';
19888: $wafproxy{'saml'}{$key} = '';
19889: if ($curralias{$key}) {
19890: $changes{'alias'} = 1;
19891: }
19892: if ($currsaml{$key}) {
19893: $changes{'saml'} = 1;
19894: }
19895: }
19896: if ($wafproxy{'alias'}{$key} eq '') {
19897: if ($curralias{$key}) {
19898: $expirecache{$key} = 1;
19899: }
19900: delete($wafproxy{'alias'}{$key});
19901: }
19902: if ($wafproxy{'saml'}{$key} eq '') {
19903: if ($currsaml{$key}) {
19904: $expiresaml{$key} = 1;
19905: }
19906: delete($wafproxy{'saml'}{$key});
19907: }
19908: }
19909: unless (keys(%{$wafproxy{'alias'}})) {
19910: delete($wafproxy{'alias'});
19911: }
19912: unless (keys(%{$wafproxy{'saml'}})) {
19913: delete($wafproxy{'saml'});
19914: }
19915: # Localization for values in %warn occurs in &mt() calls separately.
19916: my %warn = (
19917: trusted => 'trusted IP range(s)',
19918: vpnint => 'internal IP range(s) for VPN sessions(s)',
19919: vpnext => 'IP range(s) for backend WAF connections',
19920: );
19921: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19922: my $possible = $env{'form.wafproxy_'.$item};
19923: $possible =~ s/^\s+|\s+$//g;
19924: if ($possible ne '') {
19925: if ($item eq 'remoteip') {
19926: if ($possible =~ /^[mhn]$/) {
19927: $wafproxy{$item} = $possible;
19928: }
19929: } elsif ($item eq 'ipheader') {
19930: if ($wafproxy{'remoteip'} eq 'h') {
19931: $wafproxy{$item} = $possible;
19932: }
19933: } elsif ($item eq 'sslopt') {
19934: if ($possible =~ /^0|1$/) {
19935: $wafproxy{$item} = $possible;
19936: }
19937: } else {
19938: my (@ok,$count);
19939: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19940: unless ($env{'form.wafproxy_vpnaccess'}) {
19941: $possible = '';
19942: }
19943: } elsif ($item eq 'trusted') {
19944: unless ($wafproxy{'remoteip'} eq 'h') {
19945: $possible = '';
19946: }
19947: }
19948: unless ($possible eq '') {
19949: $possible =~ s/[\r\n]+/\s/g;
19950: $possible =~ s/\s*-\s*/-/g;
19951: $possible =~ s/\s+/,/g;
19952: $possible =~ s/,+/,/g;
19953: }
19954: $count = 0;
19955: if ($possible ne '') {
19956: foreach my $poss (split(/\,/,$possible)) {
19957: $count ++;
19958: $poss = &validate_ip_pattern($poss);
19959: if ($poss ne '') {
19960: push(@ok,$poss);
19961: }
19962: }
19963: my $diff = $count - scalar(@ok);
19964: if ($diff) {
19965: push(@warnings,'<li>'.
19966: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19967: $diff,$warn{$item}).
19968: '</li>');
19969: }
19970: if (@ok) {
19971: my @cidr_list;
19972: foreach my $item (@ok) {
19973: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19974: }
19975: $wafproxy{$item} = join(',',@cidr_list);
19976: }
19977: }
19978: }
19979: if ($wafproxy{$item} ne $currvalue{$item}) {
19980: $changes{$item} = 1;
19981: }
19982: } elsif ($currvalue{$item}) {
19983: $changes{$item} = 1;
19984: }
19985: }
19986: } else {
19987: if (keys(%curralias)) {
19988: $changes{'alias'} = 1;
19989: }
19990: if (keys(%currsaml)) {
19991: $changes{'saml'} = 1;
19992: }
19993: if (keys(%currvalue)) {
19994: foreach my $key (keys(%currvalue)) {
19995: $changes{$key} = 1;
19996: }
19997: }
19998: }
19999: if (keys(%changes)) {
20000: my %defaultshash = (
20001: wafproxy => \%wafproxy,
20002: );
20003: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20004: $dom);
20005: if ($putresult eq 'ok') {
20006: my $cachetime = 24*60*60;
20007: my (%domdefaults,$updatedomdefs);
20008: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
20009: if ($changes{$item}) {
20010: unless ($updatedomdefs) {
20011: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20012: $updatedomdefs = 1;
20013: }
20014: if ($wafproxy{$item}) {
20015: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20016: } elsif (exists($domdefaults{'waf_'.$item})) {
20017: delete($domdefaults{'waf_'.$item});
20018: }
20019: }
20020: }
20021: if ($updatedomdefs) {
20022: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20023: if (ref($lastactref) eq 'HASH') {
20024: $lastactref->{'domdefaults'} = 1;
20025: }
20026: }
20027: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20028: my %updates = %expirecache;
20029: foreach my $key (keys(%expirecache)) {
20030: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20031: }
20032: if (ref($wafproxy{'alias'}) eq 'HASH') {
20033: my $cachetime = 24*60*60;
20034: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20035: $updates{$key} = 1;
20036: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20037: $cachetime);
20038: }
20039: }
20040: if (ref($lastactref) eq 'HASH') {
20041: $lastactref->{'proxyalias'} = \%updates;
20042: }
20043: }
20044: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20045: my %samlupdates = %expiresaml;
20046: foreach my $key (keys(%expiresaml)) {
20047: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20048: }
20049: if (ref($wafproxy{'saml'}) eq 'HASH') {
20050: my $cachetime = 24*60*60;
20051: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20052: $samlupdates{$key} = 1;
20053: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20054: $cachetime);
20055: }
20056: }
20057: if (ref($lastactref) eq 'HASH') {
20058: $lastactref->{'proxysaml'} = \%samlupdates;
20059: }
20060: }
20061: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 20062: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 20063: if ($changes{$item}) {
20064: if ($item eq 'alias') {
20065: my $numaliased = 0;
20066: if (ref($wafproxy{'alias'}) eq 'HASH') {
20067: my $shown;
20068: if (keys(%{$wafproxy{'alias'}})) {
20069: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20070: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20071: &Apache::lonnet::hostname($server),
20072: $wafproxy{'alias'}{$server}).'</li>';
20073: $numaliased ++;
20074: }
20075: if ($numaliased) {
20076: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20077: '<ul>'.$shown.'</ul>').'</li>';
20078: }
20079: }
20080: }
20081: unless ($numaliased) {
20082: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20083: }
20084: } elsif ($item eq 'saml') {
20085: my $shown;
20086: if (ref($wafproxy{'saml'}) eq 'HASH') {
20087: if (keys(%{$wafproxy{'saml'}})) {
20088: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20089: }
20090: }
20091: if ($shown) {
20092: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
20093: $shown).'</li>';
20094: } else {
20095: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
20096: }
20097: } else {
20098: if ($item eq 'remoteip') {
20099: my %ip_methods = &remoteip_methods();
20100: if ($wafproxy{$item} =~ /^[mh]$/) {
20101: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20102: $ip_methods{$wafproxy{$item}}).'</li>';
20103: } else {
20104: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20105: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20106: '</li>';
20107: } else {
20108: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20109: }
20110: }
20111: } elsif ($item eq 'ipheader') {
20112: if ($wafproxy{$item}) {
20113: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
20114: $wafproxy{$item}).'</li>';
20115: } else {
20116: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
20117: }
20118: } elsif ($item eq 'trusted') {
20119: if ($wafproxy{$item}) {
20120: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
20121: $wafproxy{$item}).'</li>';
20122: } else {
20123: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20124: }
20125: } elsif ($item eq 'vpnint') {
20126: if ($wafproxy{$item}) {
20127: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20128: $wafproxy{$item}).'</li>';
20129: } else {
20130: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20131: }
20132: } elsif ($item eq 'vpnext') {
20133: if ($wafproxy{$item}) {
20134: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
20135: $wafproxy{$item}).'</li>';
20136: } else {
20137: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
20138: }
20139: } elsif ($item eq 'sslopt') {
20140: if ($wafproxy{$item}) {
20141: $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>';
20142: } else {
20143: $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>';
20144: }
20145: }
20146: }
20147: }
20148: }
1.160.6.118.2 14(raebu 20149:23): $output .= '</ul>';
1.160.6.113 raeburn 20150: } else {
20151: $output = '<span class="LC_error">'.
20152: &mt('An error occurred: [_1]',$putresult).'</span>';
20153: }
20154: } elsif (keys(%canset)) {
20155: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20156: }
20157: if (@warnings) {
20158: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20159: join("\n",@warnings).'</ul>';
20160: }
20161: return $output;
20162: }
20163:
20164: sub validate_ip_pattern {
20165: my ($pattern) = @_;
20166: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20167: my ($start,$end) = ($1,$2);
20168: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20169: if (($start !~ m{/}) && ($end !~ m{/})) {
20170: return $start.'-'.$end;
20171: }
20172: }
20173: } elsif ($pattern ne '') {
20174: $pattern = &Net::CIDR::cidrvalidate($pattern);
20175: if ($pattern ne '') {
20176: return $pattern;
20177: }
20178: }
20179: return;
20180: }
20181:
1.137 raeburn 20182: sub modify_usersessions {
1.160.6.27 raeburn 20183: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20184: my @hostingtypes = ('version','excludedomain','includedomain');
20185: my @offloadtypes = ('primary','default');
20186: my %types = (
20187: remote => \@hostingtypes,
20188: hosted => \@hostingtypes,
20189: spares => \@offloadtypes,
20190: );
20191: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20192: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 20193: my (%by_ip,%by_location,@intdoms);
20194: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
20195: my @locations = sort(keys(%by_location));
1.137 raeburn 20196: my (%defaultshash,%changes);
20197: foreach my $prefix (@prefixes) {
20198: $defaultshash{'usersessions'}{$prefix} = {};
20199: }
1.160.6.27 raeburn 20200: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20201: my $resulttext;
1.138 raeburn 20202: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20203: foreach my $prefix (@prefixes) {
1.145 raeburn 20204: next if ($prefix eq 'spares');
20205: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20206: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20207: if ($type eq 'version') {
20208: my $value = $env{'form.'.$prefix.'_'.$type};
20209: my $okvalue;
20210: if ($value ne '') {
20211: if (grep(/^\Q$value\E$/,@lcversions)) {
20212: $okvalue = $value;
20213: }
20214: }
20215: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20216: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20217: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20218: if ($inuse == 0) {
20219: $changes{$prefix}{$type} = 1;
20220: } else {
20221: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20222: $changes{$prefix}{$type} = 1;
20223: }
20224: if ($okvalue ne '') {
20225: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20226: }
20227: }
20228: } else {
20229: if (($inuse == 1) && ($okvalue ne '')) {
20230: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20231: $changes{$prefix}{$type} = 1;
20232: }
20233: }
20234: } else {
20235: if (($inuse == 1) && ($okvalue ne '')) {
20236: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20237: $changes{$prefix}{$type} = 1;
20238: }
20239: }
20240: } else {
20241: if (($inuse == 1) && ($okvalue ne '')) {
20242: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20243: $changes{$prefix}{$type} = 1;
20244: }
20245: }
20246: } else {
20247: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20248: my @okvals;
20249: foreach my $val (@vals) {
1.138 raeburn 20250: if ($val =~ /:/) {
20251: my @items = split(/:/,$val);
20252: foreach my $item (@items) {
20253: if (ref($by_location{$item}) eq 'ARRAY') {
20254: push(@okvals,$item);
20255: }
20256: }
20257: } else {
20258: if (ref($by_location{$val}) eq 'ARRAY') {
20259: push(@okvals,$val);
20260: }
1.137 raeburn 20261: }
20262: }
20263: @okvals = sort(@okvals);
20264: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20265: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20266: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20267: if ($inuse == 0) {
20268: $changes{$prefix}{$type} = 1;
20269: } else {
20270: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20271: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20272: if (@changed > 0) {
20273: $changes{$prefix}{$type} = 1;
20274: }
20275: }
20276: } else {
20277: if ($inuse == 1) {
20278: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20279: $changes{$prefix}{$type} = 1;
20280: }
20281: }
20282: } else {
20283: if ($inuse == 1) {
20284: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20285: $changes{$prefix}{$type} = 1;
20286: }
20287: }
20288: } else {
20289: if ($inuse == 1) {
20290: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20291: $changes{$prefix}{$type} = 1;
20292: }
20293: }
20294: }
20295: }
20296: }
1.145 raeburn 20297:
20298: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20299: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20300: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20301: my $savespares;
20302:
20303: foreach my $lonhost (sort(keys(%servers))) {
20304: my $serverhomeID =
20305: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20306: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20307: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20308: my %spareschg;
20309: foreach my $type (@{$types{'spares'}}) {
20310: my @okspares;
20311: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20312: foreach my $server (@checked) {
1.152 raeburn 20313: if (&Apache::lonnet::hostname($server) ne '') {
20314: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20315: unless (grep(/^\Q$server\E$/,@okspares)) {
20316: push(@okspares,$server);
20317: }
1.145 raeburn 20318: }
20319: }
20320: }
20321: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20322: my $newspare;
1.152 raeburn 20323: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20324: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20325: $newspare = $new;
20326: }
20327: }
1.152 raeburn 20328: my @spares;
20329: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20330: @spares = sort(@okspares,$newspare);
20331: } else {
20332: @spares = sort(@okspares);
20333: }
20334: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20335: if (ref($spareid{$lonhost}) eq 'HASH') {
20336: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20337: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20338: if (@diffs > 0) {
20339: $spareschg{$type} = 1;
20340: }
20341: }
20342: }
20343: }
20344: if (keys(%spareschg) > 0) {
20345: $changes{'spares'}{$lonhost} = \%spareschg;
20346: }
20347: }
1.160.6.61 raeburn 20348: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 20349: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 20350: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20351: my @okoffload;
20352: if (@offloadnow) {
20353: foreach my $server (@offloadnow) {
20354: if (&Apache::lonnet::hostname($server) ne '') {
20355: unless (grep(/^\Q$server\E$/,@okoffload)) {
20356: push(@okoffload,$server);
20357: }
20358: }
20359: }
20360: if (@okoffload) {
20361: foreach my $lonhost (@okoffload) {
20362: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20363: }
20364: }
20365: }
1.160.6.105 raeburn 20366: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20367: my @okoffloadoth;
20368: if (@offloadoth) {
20369: foreach my $server (@offloadoth) {
20370: if (&Apache::lonnet::hostname($server) ne '') {
20371: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20372: push(@okoffloadoth,$server);
20373: }
20374: }
20375: }
20376: if (@okoffloadoth) {
20377: foreach my $lonhost (@okoffloadoth) {
20378: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20379: }
20380: }
20381: }
1.145 raeburn 20382: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20383: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20384: if (ref($changes{'spares'}) eq 'HASH') {
20385: if (keys(%{$changes{'spares'}}) > 0) {
20386: $savespares = 1;
20387: }
20388: }
20389: } else {
20390: $savespares = 1;
20391: }
1.160.6.105 raeburn 20392: foreach my $offload ('offloadnow','offloadoth') {
20393: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20394: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20395: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20396: $changes{$offload} = 1;
1.160.6.61 raeburn 20397: last;
20398: }
20399: }
1.160.6.105 raeburn 20400: unless ($changes{$offload}) {
20401: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20402: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20403: $changes{$offload} = 1;
20404: last;
20405: }
20406: }
20407: }
20408: } else {
20409: if (($offload eq 'offloadnow') && (@okoffload)) {
20410: $changes{'offloadnow'} = 1;
20411: }
20412: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20413: $changes{'offloadoth'} = 1;
20414: }
1.160.6.61 raeburn 20415: }
1.160.6.105 raeburn 20416: }
20417: } else {
20418: if (@okoffload) {
1.160.6.61 raeburn 20419: $changes{'offloadnow'} = 1;
20420: }
1.160.6.105 raeburn 20421: if (@okoffloadoth) {
20422: $changes{'offloadoth'} = 1;
20423: }
1.145 raeburn 20424: }
1.147 raeburn 20425: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20426: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20427: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20428: $dom);
20429: if ($putresult eq 'ok') {
20430: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20431: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20432: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20433: }
20434: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20435: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20436: }
1.160.6.61 raeburn 20437: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20438: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20439: }
1.160.6.105 raeburn 20440: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20441: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20442: }
1.137 raeburn 20443: }
20444: my $cachetime = 24*60*60;
20445: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 20446: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 20447: if (ref($lastactref) eq 'HASH') {
20448: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 20449: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 20450: }
1.147 raeburn 20451: if (keys(%changes) > 0) {
20452: my %lt = &usersession_titles();
20453: $resulttext = &mt('Changes made:').'<ul>';
20454: foreach my $prefix (@prefixes) {
20455: if (ref($changes{$prefix}) eq 'HASH') {
20456: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20457: if ($prefix eq 'spares') {
20458: if (ref($changes{$prefix}) eq 'HASH') {
20459: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20460: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20461: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 20462: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20463: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20464: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20465: foreach my $type (@{$types{$prefix}}) {
20466: if ($changes{$prefix}{$lonhost}{$type}) {
20467: my $offloadto = &mt('None');
20468: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20469: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20470: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20471: }
1.145 raeburn 20472: }
1.147 raeburn 20473: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20474: }
1.137 raeburn 20475: }
20476: }
1.147 raeburn 20477: $resulttext .= '</li>';
1.137 raeburn 20478: }
20479: }
1.147 raeburn 20480: } else {
20481: foreach my $type (@{$types{$prefix}}) {
20482: if (defined($changes{$prefix}{$type})) {
20483: my $newvalue;
20484: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20485: if (ref($defaultshash{'usersessions'}{$prefix})) {
20486: if ($type eq 'version') {
20487: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
20488: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20489: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20490: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20491: }
1.145 raeburn 20492: }
20493: }
20494: }
1.147 raeburn 20495: if ($newvalue eq '') {
20496: if ($type eq 'version') {
20497: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
20498: } else {
20499: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20500: }
1.145 raeburn 20501: } else {
1.147 raeburn 20502: if ($type eq 'version') {
1.160.6.118.2 14(raebu 20503:23): $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20504: }
20505: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20506: }
1.137 raeburn 20507: }
20508: }
20509: }
1.147 raeburn 20510: $resulttext .= '</ul>';
1.137 raeburn 20511: }
20512: }
1.160.6.61 raeburn 20513: if ($changes{'offloadnow'}) {
20514: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20515: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 20516: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 20517: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20518: $resulttext .= '<li>'.$lonhost.'</li>';
20519: }
20520: $resulttext .= '</ul>';
20521: } else {
1.160.6.105 raeburn 20522: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20523: }
20524: } else {
20525: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20526: }
20527: }
20528: if ($changes{'offloadoth'}) {
20529: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20530: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20531: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20532: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20533: $resulttext .= '<li>'.$lonhost.'</li>';
20534: }
20535: $resulttext .= '</ul>';
20536: } else {
20537: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 20538: }
20539: } else {
1.160.6.105 raeburn 20540: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 20541: }
20542: }
1.147 raeburn 20543: $resulttext .= '</ul>';
20544: } else {
20545: $resulttext = $nochgmsg;
1.137 raeburn 20546: }
20547: } else {
20548: $resulttext = '<span class="LC_error">'.
20549: &mt('An error occurred: [_1]',$putresult).'</span>';
20550: }
20551: } else {
1.147 raeburn 20552: $resulttext = $nochgmsg;
1.137 raeburn 20553: }
20554: return $resulttext;
20555: }
20556:
1.150 raeburn 20557: sub modify_loadbalancing {
20558: my ($dom,%domconfig) = @_;
20559: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20560: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20561: my ($othertitle,$usertypes,$types) =
20562: &Apache::loncommon::sorted_inst_types($dom);
20563: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 20564: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20565: my @sparestypes = ('primary','default');
20566: my %typetitles = &sparestype_titles();
20567: my $resulttext;
1.160.6.94 raeburn 20568: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 20569: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20570: %existing = %{$domconfig{'loadbalancing'}};
20571: }
20572: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 20573: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 20574: my ($saveloadbalancing,%defaultshash,%changes);
20575: my ($alltypes,$othertypes,$titles) =
20576: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20577: my %ruletitles = &offloadtype_text();
20578: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20579: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20580: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20581: if ($balancer eq '') {
20582: next;
20583: }
20584: if (!exists($servers{$balancer})) {
20585: if (exists($currbalancer{$balancer})) {
20586: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20587: }
1.160.6.7 raeburn 20588: next;
20589: }
20590: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20591: push(@{$changes{'delete'}},$balancer);
20592: next;
20593: }
20594: if (!exists($currbalancer{$balancer})) {
20595: push(@{$changes{'add'}},$balancer);
20596: }
20597: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20598: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20599: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20600: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20601: $saveloadbalancing = 1;
20602: }
20603: foreach my $sparetype (@sparestypes) {
20604: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20605: my @offloadto;
20606: foreach my $target (@targets) {
20607: if (($servers{$target}) && ($target ne $balancer)) {
20608: if ($sparetype eq 'default') {
20609: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20610: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20611: }
20612: }
1.160.6.7 raeburn 20613: unless(grep(/^\Q$target\E$/,@offloadto)) {
20614: push(@offloadto,$target);
20615: }
1.150 raeburn 20616: }
20617: }
1.160.6.76 raeburn 20618: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20619: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20620: push(@offloadto,$balancer);
20621: }
20622: }
20623: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20624: }
1.160.6.94 raeburn 20625: if ($env{'form.loadbalancing_cookie_'.$i}) {
20626: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20627: if (exists($currbalancer{$balancer})) {
20628: unless ($currcookies{$balancer}) {
20629: $changes{'curr'}{$balancer}{'cookie'} = 1;
20630: }
20631: }
20632: } elsif (exists($currbalancer{$balancer})) {
20633: if ($currcookies{$balancer}) {
20634: $changes{'curr'}{$balancer}{'cookie'} = 1;
20635: }
20636: }
1.160.6.7 raeburn 20637: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20638: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 20639: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20640: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20641: if (@targetdiffs > 0) {
1.160.6.7 raeburn 20642: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20643: }
1.160.6.7 raeburn 20644: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20645: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20646: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20647: }
20648: }
20649: }
20650: } else {
1.160.6.7 raeburn 20651: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
20652: foreach my $sparetype (@sparestypes) {
20653: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20654: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20655: $changes{'curr'}{$balancer}{'targets'} = 1;
20656: }
1.150 raeburn 20657: }
20658: }
1.160.6.7 raeburn 20659: }
1.150 raeburn 20660: }
20661: my $ishomedom;
1.160.6.7 raeburn 20662: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20663: $ishomedom = 1;
1.150 raeburn 20664: }
20665: if (ref($alltypes) eq 'ARRAY') {
20666: foreach my $type (@{$alltypes}) {
20667: my $rule;
1.160.6.7 raeburn 20668: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20669: (!$ishomedom)) {
1.160.6.7 raeburn 20670: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20671: }
20672: if ($rule eq 'specific') {
1.160.6.55 raeburn 20673: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
20674: if (exists($servers{$specifiedhost})) {
20675: $rule = $specifiedhost;
20676: }
1.150 raeburn 20677: }
1.160.6.7 raeburn 20678: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20679: if (ref($currrules{$balancer}) eq 'HASH') {
20680: if ($rule ne $currrules{$balancer}{$type}) {
20681: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20682: }
20683: } elsif ($rule ne '') {
1.160.6.7 raeburn 20684: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20685: }
20686: }
20687: }
1.160.6.7 raeburn 20688: }
20689: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20690: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20691: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20692: $defaultshash{'loadbalancing'} = {};
20693: }
20694: my $putresult = &Apache::lonnet::put_dom('configuration',
20695: \%defaultshash,$dom);
20696: if ($putresult eq 'ok') {
20697: if (keys(%changes) > 0) {
1.160.6.54 raeburn 20698: my %toupdate;
1.160.6.7 raeburn 20699: if (ref($changes{'delete'}) eq 'ARRAY') {
20700: foreach my $balancer (sort(@{$changes{'delete'}})) {
20701: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 20702: $toupdate{$balancer} = 1;
1.150 raeburn 20703: }
1.160.6.7 raeburn 20704: }
20705: if (ref($changes{'add'}) eq 'ARRAY') {
20706: foreach my $balancer (sort(@{$changes{'add'}})) {
20707: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 20708: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20709: }
20710: }
20711: if (ref($changes{'curr'}) eq 'HASH') {
20712: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 20713: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20714: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20715: if ($changes{'curr'}{$balancer}{'targets'}) {
20716: my %offloadstr;
20717: foreach my $sparetype (@sparestypes) {
20718: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20719: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20720: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20721: }
20722: }
1.150 raeburn 20723: }
1.160.6.7 raeburn 20724: if (keys(%offloadstr) == 0) {
20725: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20726: } else {
1.160.6.7 raeburn 20727: my $showoffload;
20728: foreach my $sparetype (@sparestypes) {
20729: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20730: if (defined($offloadstr{$sparetype})) {
20731: $showoffload .= $offloadstr{$sparetype};
20732: } else {
20733: $showoffload .= &mt('None');
20734: }
20735: $showoffload .= (' 'x3);
20736: }
20737: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20738: }
20739: }
20740: }
1.160.6.7 raeburn 20741: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20742: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20743: foreach my $type (@{$alltypes}) {
20744: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20745: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20746: my $balancetext;
20747: if ($rule eq '') {
20748: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 20749: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 20750: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20751: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 20752: foreach my $sparetype (@sparestypes) {
20753: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20754: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20755: }
20756: }
1.160.6.55 raeburn 20757: foreach my $item (@{$alltypes}) {
20758: next if ($item =~ /^_LC_ipchange/);
20759: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20760: if ($hasrule eq 'homeserver') {
20761: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20762: } else {
20763: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20764: if ($servers{$hasrule}) {
20765: $toupdate{$hasrule} = 1;
20766: }
20767: }
20768: }
20769: }
20770: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20771: $balancetext = $ruletitles{$rule};
20772: } else {
20773: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20774: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20775: if ($receiver) {
20776: $toupdate{$receiver};
20777: }
20778: }
20779: } else {
20780: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 20781: }
1.160.6.7 raeburn 20782: } else {
20783: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20784: }
1.160.6.26 raeburn 20785: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20786: }
20787: }
20788: }
20789: }
1.160.6.94 raeburn 20790: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 20791: if ($currcookies{$balancer}) {
20792: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20793: $balancer).'</li>';
20794: } else {
20795: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20796: $balancer).'</li>';
20797: }
1.160.6.94 raeburn 20798: }
1.160.6.106 raeburn 20799: }
20800: }
20801: if (keys(%toupdate)) {
20802: my %thismachine;
20803: my $updatedhere;
20804: my $cachetime = 60*60*24;
20805: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20806: foreach my $lonhost (keys(%toupdate)) {
20807: if ($thismachine{$lonhost}) {
20808: unless ($updatedhere) {
20809: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20810: $defaultshash{'loadbalancing'},
20811: $cachetime);
20812: $updatedhere = 1;
1.160.6.54 raeburn 20813: }
1.160.6.106 raeburn 20814: } else {
20815: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20816: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 20817: }
1.150 raeburn 20818: }
1.160.6.7 raeburn 20819: }
20820: if ($resulttext ne '') {
20821: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20822: } else {
20823: $resulttext = $nochgmsg;
20824: }
20825: } else {
1.160.6.7 raeburn 20826: $resulttext = $nochgmsg;
1.150 raeburn 20827: }
20828: } else {
1.160.6.7 raeburn 20829: $resulttext = '<span class="LC_error">'.
20830: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20831: }
20832: } else {
1.160.6.7 raeburn 20833: $resulttext = $nochgmsg;
1.150 raeburn 20834: }
20835: return $resulttext;
20836: }
20837:
1.48 raeburn 20838: sub recurse_check {
20839: my ($chkcats,$categories,$depth,$name) = @_;
20840: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20841: my $chg = 0;
20842: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20843: my $category = $chkcats->[$depth]{$name}[$j];
20844: my $item;
20845: if ($category eq '') {
20846: $chg ++;
20847: } else {
20848: my $deeper = $depth + 1;
20849: $item = &escape($category).':'.&escape($name).':'.$depth;
20850: if ($chg) {
20851: $categories->{$item} -= $chg;
20852: }
20853: &recurse_check($chkcats,$categories,$deeper,$category);
20854: $deeper --;
20855: }
20856: }
20857: }
20858: return;
20859: }
20860:
20861: sub recurse_cat_deletes {
20862: my ($item,$coursecategories,$deletions) = @_;
20863: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20864: my $subdepth = $depth + 1;
20865: if (ref($coursecategories) eq 'HASH') {
20866: foreach my $subitem (keys(%{$coursecategories})) {
20867: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20868: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20869: delete($coursecategories->{$subitem});
20870: $deletions->{$subitem} = 1;
20871: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 20872: }
1.48 raeburn 20873: }
20874: }
20875: return;
20876: }
20877:
1.125 raeburn 20878: sub active_dc_picker {
1.160.6.16 raeburn 20879: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 20880: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 20881: my @domcoord = keys(%domcoords);
20882: if (keys(%currhash)) {
20883: foreach my $dc (keys(%currhash)) {
20884: unless (exists($domcoords{$dc})) {
20885: push(@domcoord,$dc);
20886: }
20887: }
20888: }
20889: @domcoord = sort(@domcoord);
20890: my $numdcs = scalar(@domcoord);
20891: my $rows = 0;
20892: my $table;
1.125 raeburn 20893: if ($numdcs > 1) {
1.160.6.16 raeburn 20894: $table = '<table>';
20895: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20896: my $rem = $i%($numinrow);
20897: if ($rem == 0) {
20898: if ($i > 0) {
1.160.6.16 raeburn 20899: $table .= '</tr>';
1.125 raeburn 20900: }
1.160.6.16 raeburn 20901: $table .= '<tr>';
20902: $rows ++;
1.125 raeburn 20903: }
1.160.6.16 raeburn 20904: my $check = '';
20905: if ($inputtype eq 'radio') {
20906: if (keys(%currhash) == 0) {
20907: if (!$i) {
20908: $check = ' checked="checked"';
20909: }
20910: } elsif (exists($currhash{$domcoord[$i]})) {
20911: $check = ' checked="checked"';
20912: }
20913: } else {
20914: if (exists($currhash{$domcoord[$i]})) {
20915: $check = ' checked="checked"';
1.125 raeburn 20916: }
20917: }
1.160.6.16 raeburn 20918: if ($i == @domcoord - 1) {
1.125 raeburn 20919: my $colsleft = $numinrow - $rem;
20920: if ($colsleft > 1) {
1.160.6.16 raeburn 20921: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20922: } else {
1.160.6.16 raeburn 20923: $table .= '<td class="LC_left_item">';
1.125 raeburn 20924: }
20925: } else {
1.160.6.16 raeburn 20926: $table .= '<td class="LC_left_item">';
20927: }
20928: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20929: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20930: $table .= '<span class="LC_nobreak"><label>'.
20931: '<input type="'.$inputtype.'" name="'.$name.'"'.
20932: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20933: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 20934: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 20935: }
1.160.6.33 raeburn 20936: $table .= '</label></span></td>';
1.125 raeburn 20937: }
1.160.6.16 raeburn 20938: $table .= '</tr></table>';
20939: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 20940: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20941: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 20942: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 20943: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 20944: if ($user ne $dcname.':'.$dcdom) {
20945: $table .= ' ('.$dcname.':'.$dcdom.')';
20946: }
1.160.6.16 raeburn 20947: } else {
20948: my $check;
20949: if (exists($currhash{$domcoord[0]})) {
20950: $check = ' checked="checked"';
20951: }
1.160.6.50 raeburn 20952: $table = '<span class="LC_nobreak"><label>'.
20953: '<input type="checkbox" name="'.$name.'" '.
20954: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 20955: if ($user ne $dcname.':'.$dcdom) {
20956: $table .= ' ('.$dcname.':'.$dcdom.')';
20957: }
20958: $table .= '</label></span>';
1.160.6.16 raeburn 20959: $rows ++;
20960: }
1.125 raeburn 20961: }
1.160.6.16 raeburn 20962: return ($numdcs,$table,$rows);
1.125 raeburn 20963: }
20964:
1.137 raeburn 20965: sub usersession_titles {
20966: return &Apache::lonlocal::texthash(
20967: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20968: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20969: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20970: version => 'LON-CAPA version requirement',
1.138 raeburn 20971: excludedomain => 'Allow all, but exclude specific domains',
20972: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20973: primary => 'Primary (checked first)',
1.154 raeburn 20974: default => 'Default',
1.137 raeburn 20975: );
20976: }
20977:
1.152 raeburn 20978: sub id_for_thisdom {
20979: my (%servers) = @_;
20980: my %altids;
20981: foreach my $server (keys(%servers)) {
20982: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20983: if ($serverhome ne $server) {
20984: $altids{$serverhome} = $server;
20985: }
20986: }
20987: return %altids;
20988: }
20989:
1.150 raeburn 20990: sub count_servers {
20991: my ($currbalancer,%servers) = @_;
20992: my (@spares,$numspares);
20993: foreach my $lonhost (sort(keys(%servers))) {
20994: next if ($currbalancer eq $lonhost);
20995: push(@spares,$lonhost);
20996: }
20997: if ($currbalancer) {
20998: $numspares = scalar(@spares);
20999: } else {
21000: $numspares = scalar(@spares) - 1;
21001: }
21002: return ($numspares,@spares);
21003: }
21004:
21005: sub lonbalance_targets_js {
1.160.6.7 raeburn 21006: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21007: my $select = &mt('Select');
21008: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21009: if (ref($servers) eq 'HASH') {
21010: $alltargets = join("','",sort(keys(%{$servers})));
21011: my @homedoms;
21012: foreach my $server (sort(keys(%{$servers}))) {
21013: if (&Apache::lonnet::host_domain($server) eq $dom) {
21014: push(@homedoms,'1');
21015: } else {
21016: push(@homedoms,'0');
21017: }
21018: }
21019: $allishome = join("','",@homedoms);
21020: }
21021: if (ref($types) eq 'ARRAY') {
21022: if (@{$types} > 0) {
21023: @alltypes = @{$types};
21024: }
21025: }
21026: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21027: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 21028: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 21029: if (ref($settings) eq 'HASH') {
21030: %existing = %{$settings};
21031: }
21032: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 21033: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 21034: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21035: return <<"END";
21036:
21037: <script type="text/javascript">
21038: // <![CDATA[
21039:
1.160.6.7 raeburn 21040: currBalancers = new Array('$balancers');
21041:
21042: function toggleTargets(balnum) {
21043: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21044: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21045: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21046: var prevbalancer = prevhostitem.value;
21047: var baltotal = document.getElementById('loadbalancing_total').value;
21048: prevhostitem.value = balancer;
21049: if (prevbalancer != '') {
21050: var prevIdx = currBalancers.indexOf(prevbalancer);
21051: if (prevIdx != -1) {
21052: currBalancers.splice(prevIdx,1);
21053: }
21054: }
1.150 raeburn 21055: if (balancer == '') {
1.160.6.7 raeburn 21056: hideSpares(balnum);
1.150 raeburn 21057: } else {
1.160.6.7 raeburn 21058: var currIdx = currBalancers.indexOf(balancer);
21059: if (currIdx == -1) {
21060: currBalancers.push(balancer);
21061: }
1.150 raeburn 21062: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 21063: var ishomedom = homedoms[lonhostitem.selectedIndex];
21064: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21065: }
1.160.6.7 raeburn 21066: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21067: return;
21068: }
21069:
1.160.6.7 raeburn 21070: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21071: var alltargets = new Array('$alltargets');
21072: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21073: var offloadtypes = new Array('primary','default');
21074:
1.160.6.7 raeburn 21075: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21076: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21077:
1.151 raeburn 21078: for (var i=0; i<offloadtypes.length; i++) {
21079: var count = 0;
21080: for (var j=0; j<alltargets.length; j++) {
21081: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 21082: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21083: item.value = alltargets[j];
21084: item.style.textAlign='left';
21085: item.style.textFace='normal';
21086: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21087: if (currBalancers.indexOf(alltargets[j]) == -1) {
21088: item.disabled = '';
21089: } else {
21090: item.disabled = 'disabled';
21091: item.checked = false;
21092: }
1.151 raeburn 21093: count ++;
21094: }
1.150 raeburn 21095: }
21096: }
1.151 raeburn 21097: for (var k=0; k<insttypes.length; k++) {
21098: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21099: if (ishomedom == 1) {
1.160.6.7 raeburn 21100: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21101: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21102: } else {
1.160.6.7 raeburn 21103: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21104: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21105: }
21106: } else {
1.160.6.7 raeburn 21107: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21108: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21109: }
1.151 raeburn 21110: if ((insttypes[k] != '_LC_external') &&
21111: ((insttypes[k] != '_LC_internetdom') ||
21112: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 21113: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21114: item.options.length = 0;
21115: item.options[0] = new Option("","",true,true);
21116: var idx = 0;
1.151 raeburn 21117: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 21118: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21119: idx ++;
21120: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21121: }
21122: }
21123: }
21124: }
21125: return;
21126: }
21127:
1.160.6.7 raeburn 21128: function hideSpares(balnum) {
1.150 raeburn 21129: var alltargets = new Array('$alltargets');
21130: var insttypes = new Array('$allinsttypes');
21131: var offloadtypes = new Array('primary','default');
21132:
1.160.6.7 raeburn 21133: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21134: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21135:
21136: var total = alltargets.length - 1;
21137: for (var i=0; i<offloadtypes; i++) {
21138: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 21139: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21140: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21141: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21142: }
1.150 raeburn 21143: }
21144: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 21145: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21146: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21147: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 21148: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21149: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21150: }
21151: }
21152: return;
21153: }
21154:
1.160.6.7 raeburn 21155: function checkOffloads(item,balnum,type) {
1.150 raeburn 21156: var alltargets = new Array('$alltargets');
21157: var offloadtypes = new Array('primary','default');
21158: if (item.checked) {
21159: var total = alltargets.length - 1;
21160: var other;
21161: if (type == offloadtypes[0]) {
1.151 raeburn 21162: other = offloadtypes[1];
1.150 raeburn 21163: } else {
1.151 raeburn 21164: other = offloadtypes[0];
1.150 raeburn 21165: }
21166: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 21167: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21168: if (server == item.value) {
1.160.6.7 raeburn 21169: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21170: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21171: }
21172: }
21173: }
21174: }
21175: return;
21176: }
21177:
1.160.6.7 raeburn 21178: function singleServerToggle(balnum,type) {
21179: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21180: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 21181: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21182: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21183:
21184: } else {
1.160.6.7 raeburn 21185: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21186: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21187: }
21188: return;
21189: }
21190:
1.160.6.7 raeburn 21191: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21192: if (type == '_LC_external') {
1.160.6.26 raeburn 21193: return;
1.150 raeburn 21194: }
1.160.6.7 raeburn 21195: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21196: for (var i=0; i<typesRules.length; i++) {
21197: if (formname.elements[typesRules[i]].checked) {
21198: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 21199: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21200: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21201: } else {
1.160.6.7 raeburn 21202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21203: }
21204: }
21205: }
21206: return;
21207: }
21208:
21209: function balancerDeleteChange(balnum) {
21210: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21211: var baltotal = document.getElementById('loadbalancing_total').value;
21212: var addtarget;
21213: var removetarget;
21214: var action = 'delete';
21215: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21216: var lonhost = hostitem.value;
21217: var currIdx = currBalancers.indexOf(lonhost);
21218: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21219: if (currIdx != -1) {
21220: currBalancers.splice(currIdx,1);
21221: }
21222: addtarget = lonhost;
21223: } else {
21224: if (currIdx == -1) {
21225: currBalancers.push(lonhost);
21226: }
21227: removetarget = lonhost;
21228: action = 'undelete';
21229: }
21230: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21231: }
21232: return;
21233: }
21234:
21235: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21236: if (baltotal > 1) {
21237: var offloadtypes = new Array('primary','default');
21238: var alltargets = new Array('$alltargets');
21239: var insttypes = new Array('$allinsttypes');
21240: for (var i=0; i<baltotal; i++) {
21241: if (i != balnum) {
21242: for (var j=0; j<offloadtypes.length; j++) {
21243: var total = alltargets.length - 1;
21244: for (var k=0; k<total; k++) {
21245: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21246: var server = serveritem.value;
21247: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21248: if (server == addtarget) {
21249: serveritem.disabled = '';
21250: }
21251: }
21252: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21253: if (server == removetarget) {
21254: serveritem.disabled = 'disabled';
21255: serveritem.checked = false;
21256: }
21257: }
21258: }
21259: }
21260: for (var j=0; j<insttypes.length; j++) {
21261: if (insttypes[j] != '_LC_external') {
21262: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21263: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21264: var currSel = singleserver.selectedIndex;
21265: var currVal = singleserver.options[currSel].value;
21266: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21267: var numoptions = singleserver.options.length;
21268: var needsnew = 1;
21269: for (var k=0; k<numoptions; k++) {
21270: if (singleserver.options[k] == addtarget) {
21271: needsnew = 0;
21272: break;
21273: }
21274: }
21275: if (needsnew == 1) {
21276: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21277: }
21278: }
21279: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21280: singleserver.options.length = 0;
21281: if ((currVal) && (currVal != removetarget)) {
21282: singleserver.options[0] = new Option("","",false,false);
21283: } else {
21284: singleserver.options[0] = new Option("","",true,true);
21285: }
21286: var idx = 0;
21287: for (var m=0; m<alltargets.length; m++) {
21288: if (currBalancers.indexOf(alltargets[m]) == -1) {
21289: idx ++;
21290: if (currVal == alltargets[m]) {
21291: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21292: } else {
21293: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21294: }
21295: }
21296: }
21297: }
21298: }
21299: }
21300: }
1.150 raeburn 21301: }
21302: }
21303: }
21304: return;
21305: }
21306:
1.152 raeburn 21307: // ]]>
21308: </script>
21309:
21310: END
21311: }
21312:
21313: sub new_spares_js {
21314: my @sparestypes = ('primary','default');
21315: my $types = join("','",@sparestypes);
21316: my $select = &mt('Select');
21317: return <<"END";
21318:
21319: <script type="text/javascript">
21320: // <![CDATA[
21321:
21322: function updateNewSpares(formname,lonhost) {
21323: var types = new Array('$types');
21324: var include = new Array();
21325: var exclude = new Array();
21326: for (var i=0; i<types.length; i++) {
21327: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21328: for (var j=0; j<spareboxes.length; j++) {
21329: if (formname.elements[spareboxes[j]].checked) {
21330: exclude.push(formname.elements[spareboxes[j]].value);
21331: } else {
21332: include.push(formname.elements[spareboxes[j]].value);
21333: }
21334: }
21335: }
21336: for (var i=0; i<types.length; i++) {
21337: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21338: var selIdx = newSpare.selectedIndex;
21339: var currnew = newSpare.options[selIdx].value;
21340: var okSpares = new Array();
21341: for (var j=0; j<newSpare.options.length; j++) {
21342: var possible = newSpare.options[j].value;
21343: if (possible != '') {
21344: if (exclude.indexOf(possible) == -1) {
21345: okSpares.push(possible);
21346: } else {
21347: if (currnew == possible) {
21348: selIdx = 0;
21349: }
21350: }
21351: }
21352: }
21353: for (var k=0; k<include.length; k++) {
21354: if (okSpares.indexOf(include[k]) == -1) {
21355: okSpares.push(include[k]);
21356: }
21357: }
21358: okSpares.sort();
21359: newSpare.options.length = 0;
21360: if (selIdx == 0) {
21361: newSpare.options[0] = new Option("$select","",true,true);
21362: } else {
21363: newSpare.options[0] = new Option("$select","",false,false);
21364: }
21365: for (var m=0; m<okSpares.length; m++) {
21366: var idx = m+1;
21367: var selThis = 0;
21368: if (selIdx != 0) {
21369: if (okSpares[m] == currnew) {
21370: selThis = 1;
21371: }
21372: }
21373: if (selThis == 1) {
21374: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21375: } else {
21376: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21377: }
21378: }
21379: }
21380: return;
21381: }
21382:
21383: function checkNewSpares(lonhost,type) {
21384: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21385: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.160.6.118.2 14(raebu 21386:23): if (chosen != '') {
1.152 raeburn 21387: var othertype;
21388: var othernewSpare;
21389: if (type == 'primary') {
21390: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21391: }
21392: if (type == 'default') {
21393: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21394: }
21395: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21396: othernewSpare.selectedIndex = 0;
21397: }
21398: }
21399: return;
21400: }
21401:
21402: // ]]>
21403: </script>
21404:
21405: END
21406:
21407: }
21408:
21409: sub common_domprefs_js {
21410: return <<"END";
21411:
21412: <script type="text/javascript">
21413: // <![CDATA[
21414:
1.150 raeburn 21415: function getIndicesByName(formname,item) {
1.152 raeburn 21416: var group = new Array();
1.150 raeburn 21417: for (var i=0;i<formname.elements.length;i++) {
21418: if (formname.elements[i].name == item) {
1.152 raeburn 21419: group.push(formname.elements[i].id);
1.150 raeburn 21420: }
21421: }
1.152 raeburn 21422: return group;
1.150 raeburn 21423: }
21424:
21425: // ]]>
21426: </script>
21427:
21428: END
1.152 raeburn 21429:
1.150 raeburn 21430: }
21431:
1.160.6.5 raeburn 21432: sub recaptcha_js {
21433: my %lt = &captcha_phrases();
21434: return <<"END";
21435:
21436: <script type="text/javascript">
21437: // <![CDATA[
21438:
21439: function updateCaptcha(caller,context) {
21440: var privitem;
21441: var pubitem;
21442: var privtext;
21443: var pubtext;
1.160.6.69 raeburn 21444: var versionitem;
21445: var versiontext;
1.160.6.5 raeburn 21446: if (document.getElementById(context+'_recaptchapub')) {
21447: pubitem = document.getElementById(context+'_recaptchapub');
21448: } else {
21449: return;
21450: }
21451: if (document.getElementById(context+'_recaptchapriv')) {
21452: privitem = document.getElementById(context+'_recaptchapriv');
21453: } else {
21454: return;
21455: }
21456: if (document.getElementById(context+'_recaptchapubtxt')) {
21457: pubtext = document.getElementById(context+'_recaptchapubtxt');
21458: } else {
21459: return;
21460: }
21461: if (document.getElementById(context+'_recaptchaprivtxt')) {
21462: privtext = document.getElementById(context+'_recaptchaprivtxt');
21463: } else {
21464: return;
21465: }
1.160.6.69 raeburn 21466: if (document.getElementById(context+'_recaptchaversion')) {
21467: versionitem = document.getElementById(context+'_recaptchaversion');
21468: } else {
21469: return;
21470: }
21471: if (document.getElementById(context+'_recaptchavertxt')) {
21472: versiontext = document.getElementById(context+'_recaptchavertxt');
21473: } else {
21474: return;
21475: }
1.160.6.5 raeburn 21476: if (caller.checked) {
21477: if (caller.value == 'recaptcha') {
21478: pubitem.type = 'text';
21479: privitem.type = 'text';
21480: pubitem.size = '40';
21481: privitem.size = '40';
21482: pubtext.innerHTML = "$lt{'pub'}";
21483: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 21484: versionitem.type = 'text';
21485: versionitem.size = '3';
21486: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 21487: } else {
21488: pubitem.type = 'hidden';
21489: privitem.type = 'hidden';
1.160.6.69 raeburn 21490: versionitem.type = 'hidden';
1.160.6.5 raeburn 21491: pubtext.innerHTML = '';
21492: privtext.innerHTML = '';
1.160.6.69 raeburn 21493: versiontext.innerHTML = '';
1.160.6.5 raeburn 21494: }
21495: }
21496: return;
21497: }
21498:
21499: // ]]>
21500: </script>
21501:
21502: END
21503:
21504: }
21505:
1.160.6.40 raeburn 21506: sub toggle_display_js {
1.160.6.16 raeburn 21507: return <<"END";
21508:
21509: <script type="text/javascript">
21510: // <![CDATA[
21511:
1.160.6.40 raeburn 21512: function toggleDisplay(domForm,caller) {
21513: if (document.getElementById(caller)) {
21514: var divitem = document.getElementById(caller);
21515: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 21516: var checkval = 1;
21517: var dispval = 'block';
1.160.6.93 raeburn 21518: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 21519: if (caller == 'emailoptions') {
1.160.6.118.2 14(raebu 21520:23): optionsElement = domForm.cancreate_email;
1.160.6.40 raeburn 21521: }
1.160.6.57 raeburn 21522: if (caller == 'studentsubmission') {
21523: optionsElement = domForm.postsubmit;
21524: }
1.160.6.64 raeburn 21525: if (caller == 'cloneinstcode') {
21526: optionsElement = domForm.canclone;
21527: checkval = 'instcode';
21528: }
1.160.6.93 raeburn 21529: if (selfcreateRegExp.test(caller)) {
21530: optionsElement = domForm.elements[caller];
21531: checkval = 'other';
21532: dispval = 'inline'
21533: }
1.160.6.40 raeburn 21534: if (optionsElement.length) {
1.160.6.16 raeburn 21535: var currval;
1.160.6.40 raeburn 21536: for (var i=0; i<optionsElement.length; i++) {
21537: if (optionsElement[i].checked) {
21538: currval = optionsElement[i].value;
1.160.6.16 raeburn 21539: }
21540: }
1.160.6.64 raeburn 21541: if (currval == checkval) {
21542: divitem.style.display = dispval;
1.160.6.16 raeburn 21543: } else {
1.160.6.40 raeburn 21544: divitem.style.display = 'none';
1.160.6.16 raeburn 21545: }
21546: }
21547: }
21548: return;
21549: }
21550:
21551: // ]]>
21552: </script>
21553:
21554: END
21555:
21556: }
21557:
1.160.6.5 raeburn 21558: sub captcha_phrases {
21559: return &Apache::lonlocal::texthash (
21560: priv => 'Private key',
21561: pub => 'Public key',
21562: original => 'original (CAPTCHA)',
21563: recaptcha => 'successor (ReCAPTCHA)',
21564: notused => 'unused',
1.160.6.69 raeburn 21565: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 21566: );
21567: }
21568:
1.160.6.24 raeburn 21569: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 21570: my ($dom,$cachekeys) = @_;
21571: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 21572: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21573: my %thismachine;
21574: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 21575:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 21576: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
21577: 'ipaccess');
21578: my %cache_by_lonhost;
21579: if (exists($cachekeys->{'samllanding'})) {
21580: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
21581: my %landing = %{$cachekeys->{'samllanding'}};
21582: my %domservers = &Apache::lonnet::get_servers($dom);
21583: if (keys(%domservers)) {
21584: foreach my $server (keys(%domservers)) {
21585: my @cached;
21586: next if ($thismachine{$server});
21587: if ($landing{$server}) {
21588: push(@cached,&escape('samllanding').':'.&escape($server));
21589: }
21590: if (@cached) {
21591: $cache_by_lonhost{$server} = \@cached;
21592: }
21593: }
21594: }
21595: }
21596: }
1.160.6.61 raeburn 21597: if (keys(%servers)) {
1.160.6.24 raeburn 21598: foreach my $server (keys(%servers)) {
21599: next if ($thismachine{$server});
1.160.6.27 raeburn 21600: my @cached;
21601: foreach my $name (@posscached) {
21602: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 21603: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
21604: if (ref($cachekeys->{$name}) eq 'HASH') {
21605: foreach my $key (keys(%{$cachekeys->{$name}})) {
21606: push(@cached,&escape($name).':'.&escape($key));
21607: }
21608: }
21609: } else {
21610: push(@cached,&escape($name).':'.&escape($dom));
21611: }
1.160.6.27 raeburn 21612: }
21613: }
1.160.6.113 raeburn 21614: if ((exists($cache_by_lonhost{$server})) &&
21615: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
21616: push(@cached,@{$cache_by_lonhost{$server}});
21617: }
1.160.6.27 raeburn 21618: if (@cached) {
21619: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21620: }
1.160.6.24 raeburn 21621: }
21622: }
21623: return;
21624: }
21625:
1.3 raeburn 21626: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>