Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.26
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 26(raebu 4:25): # $Id: domainprefs.pm,v 1.160.6.118.2.25 2024/09/01 02:45:08 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.118.2 25(raebu 460:24): col2 => 'User information updatable by co-author manager'},
461:24): {col1 => 'Target user has role',
1.160.6.35 raeburn 462: col2 => 'User information updatable in course context'}],
1.160.6.37 raeburn 463: print => \&print_usermodification,
464: modify => \&modify_usermodification,
1.33 raeburn 465: },
1.69 raeburn 466: 'scantron' =>
1.160.6.97 raeburn 467: { text => 'Bubblesheet format',
1.67 raeburn 468: help => 'Domain_Configuration_Scantron_Format',
1.160.6.97 raeburn 469: header => [ {col1 => 'Bubblesheet format file',
470: col2 => ''},
471: {col1 => 'Bubblesheet data upload formats',
472: col2 => 'Settings'}],
1.160.6.37 raeburn 473: print => \&print_scantron,
474: modify => \&modify_scantron,
1.46 raeburn 475: },
1.86 raeburn 476: 'requestcourses' =>
477: {text => 'Request creation of courses',
478: help => 'Domain_Configuration_Request_Courses',
479: header => [{col1 => 'User affiliation',
1.102 raeburn 480: col2 => 'Availability/Processing of requests',},
481: {col1 => 'Setting',
1.160.6.30 raeburn 482: col2 => 'Value'},
483: {col1 => 'Available textbooks',
1.160.6.39 raeburn 484: col2 => ''},
1.160.6.46 raeburn 485: {col1 => 'Available templates',
486: col2 => ''},
1.160.6.39 raeburn 487: {col1 => 'Validation (not official courses)',
488: col2 => 'Value'},],
1.160.6.37 raeburn 489: print => \&print_quotas,
490: modify => \&modify_quotas,
1.86 raeburn 491: },
1.160.6.5 raeburn 492: 'requestauthor' =>
1.160.6.34 raeburn 493: {text => 'Request Authoring Space',
1.160.6.5 raeburn 494: help => 'Domain_Configuration_Request_Author',
495: header => [{col1 => 'User affiliation',
496: col2 => 'Availability/Processing of requests',},
497: {col1 => 'Setting',
498: col2 => 'Value'}],
1.160.6.37 raeburn 499: print => \&print_quotas,
500: modify => \&modify_quotas,
1.160.6.5 raeburn 501: },
1.69 raeburn 502: 'coursecategories' =>
1.120 raeburn 503: { text => 'Cataloging of courses/communities',
1.67 raeburn 504: help => 'Domain_Configuration_Cataloging_Courses',
1.160.6.42 raeburn 505: header => [{col1 => 'Catalog type/availability',
506: col2 => '',},
507: {col1 => 'Category settings for standard catalog',
1.57 raeburn 508: col2 => '',},
509: {col1 => 'Categories',
510: col2 => '',
511: }],
1.160.6.37 raeburn 512: print => \&print_coursecategories,
513: modify => \&modify_coursecategories,
1.69 raeburn 514: },
515: 'serverstatuses' =>
1.77 raeburn 516: {text => 'Access to server status pages',
1.69 raeburn 517: help => 'Domain_Configuration_Server_Status',
518: header => [{col1 => 'Status Page',
519: col2 => 'Other named users',
520: col3 => 'Specific IPs',
521: }],
1.160.6.37 raeburn 522: print => \&print_serverstatuses,
523: modify => \&modify_serverstatuses,
1.69 raeburn 524: },
1.160.6.73 raeburn 525: 'helpsettings' =>
526: {text => 'Support settings',
527: help => 'Domain_Configuration_Help_Settings',
528: header => [{col1 => 'Help Page Settings (logged-in users)',
529: col2 => 'Value'},
530: {col1 => 'Helpdesk Roles',
531: col2 => 'Settings'},],
532: print => \&print_helpsettings,
533: modify => \&modify_helpsettings,
534: },
1.160.6.39 raeburn 535: 'coursedefaults' =>
1.160.6.16 raeburn 536: {text => 'Course/Community defaults',
537: help => 'Domain_Configuration_Course_Defaults',
1.160.6.57 raeburn 538: header => [{col1 => 'Defaults which can be overridden in each course by a CC',
539: col2 => 'Value',},
540: {col1 => 'Defaults which can be overridden for each course by a DC',
1.160.6.16 raeburn 541: col2 => 'Value',},],
1.160.6.37 raeburn 542: print => \&print_coursedefaults,
543: modify => \&modify_coursedefaults,
544: },
1.160.6.39 raeburn 545: 'selfenrollment' =>
1.160.6.37 raeburn 546: {text => 'Self-enrollment in Course/Community',
547: help => 'Domain_Configuration_Selfenrollment',
548: header => [{col1 => 'Configuration Rights',
549: col2 => 'Configured by Course Personnel or Domain Coordinator?'},
550: {col1 => 'Defaults',
551: col2 => 'Value'},
552: {col1 => 'Self-enrollment validation (optional)',
553: col2 => 'Value'},],
554: print => \&print_selfenrollment,
555: modify => \&modify_selfenrollment,
1.160.6.16 raeburn 556: },
1.141 raeburn 557: 'usersessions' =>
1.145 raeburn 558: {text => 'User session hosting/offloading',
1.137 raeburn 559: help => 'Domain_Configuration_User_Sessions',
1.145 raeburn 560: header => [{col1 => 'Domain server',
561: col2 => 'Servers to offload sessions to when busy'},
562: {col1 => 'Hosting of users from other domains',
1.137 raeburn 563: col2 => 'Rules'},
564: {col1 => "Hosting domain's own users elsewhere",
565: col2 => 'Rules'}],
1.160.6.37 raeburn 566: print => \&print_usersessions,
567: modify => \&modify_usersessions,
1.137 raeburn 568: },
1.160.6.78 raeburn 569: 'loadbalancing' =>
1.160.6.7 raeburn 570: {text => 'Dedicated Load Balancer(s)',
1.150 raeburn 571: help => 'Domain_Configuration_Load_Balancing',
1.160.6.7 raeburn 572: header => [{col1 => 'Balancers',
1.150 raeburn 573: col2 => 'Default destinations',
1.160.6.13 raeburn 574: col3 => 'User affiliation',
1.150 raeburn 575: col4 => 'Overrides'},
576: ],
1.160.6.37 raeburn 577: print => \&print_loadbalancing,
578: modify => \&modify_loadbalancing,
1.150 raeburn 579: },
1.160.6.118.2 1(raebur 580:1): 'ltitools' =>
581:1): {text => 'External Tools (LTI)',
582:1): help => 'Domain_Configuration_LTI_Tools',
14(raebu 583:23): header => [{col1 => 'Encryption of shared secrets',
584:23): col2 => 'Settings'},
585:23): {col1 => 'Rules for shared secrets',
586:23): col2 => 'Settings'},
587:23): {col1 => 'Providers',
588:23): col2 => 'Settings',}],
1(raebur 589:1): print => \&print_ltitools,
590:1): modify => \&modify_ltitools,
591:1): },
14(raebu 592:23): 'lti' =>
5(raebur 593:2): {text => 'LTI Link Protection and LTI Consumers',
594:2): help => 'Domain_Configuration_LTI_Provider',
595:2): header => [{col1 => 'Encryption of shared secrets',
596:2): col2 => 'Settings'},
597:2): {col1 => 'Rules for shared secrets',
598:2): col2 => 'Settings'},
18(raebu 599:24): {col1 => 'Link Protectors in Courses',
600:24): col2 => 'Values'},
5(raebur 601:2): {col1 => 'Link Protectors',
14(raebu 602:23): col2 => 'Settings'},
603:23): {col1 => 'Consumers',
5(raebur 604:2): col2 => 'Settings'},],
605:2): print => \&print_lti,
606:2): modify => \&modify_lti,
607:2): },
14(raebu 608:23): 'ipaccess' =>
1.160.6.113 raeburn 609: {text => 'IP-based access control',
610: help => 'Domain_Configuration_IP_Access',
611: header => [{col1 => 'Setting',
612: col2 => 'Value'},],
613: print => \&print_ipaccess,
614: modify => \&modify_ipaccess,
615: },
1.160.6.118.2 20(raebu 616:24): 'authordefaults' =>
617:24): {text => 'Authoring Space defaults',
618:24): help => 'Domain_Configuration_Author_Defaults',
619:24): header => [{col1 => 'Defaults which can be overridden by Author',
620:24): col2 => 'Settings',},
621:24): {col1 => 'Defaults which can be overridden by a Dom. Coord.',
622:24): col2 => 'Settings',},],
623:24): print => \&print_authordefaults,
624:24): modify => \&modify_authordefaults,
625:24): },
1.3 raeburn 626: );
1.110 raeburn 627: if (keys(%servers) > 1) {
628: $prefs{'login'} = { text => 'Log-in page options',
629: help => 'Domain_Configuration_Login_Page',
630: header => [{col1 => 'Log-in Service',
631: col2 => 'Server Setting',},
632: {col1 => 'Log-in Page Items',
1.160.6.118.2 5(raebur 633:2): col2 => 'Settings'},
1.160.6.5 raeburn 634: {col1 => 'Log-in Help',
1.160.6.56 raeburn 635: col2 => 'Value'},
636: {col1 => 'Custom HTML in document head',
1.160.6.113 raeburn 637: col2 => 'Value'},
638: {col1 => 'SSO',
639: col2 => 'Dual login: SSO and non-SSO options'},
640: ],
1.160.6.37 raeburn 641: print => \&print_login,
642: modify => \&modify_login,
1.110 raeburn 643: };
644: }
1.160.6.13 raeburn 645:
1.6 raeburn 646: my @roles = ('student','coordinator','author','admin');
1.30 raeburn 647: my @actions = &Apache::loncommon::get_env_multiple('form.actions');
1.3 raeburn 648: &Apache::lonhtmlcommon::add_breadcrumb
1.30 raeburn 649: ({href=>"javascript:changePage(document.$phase,'pickactions')",
1.133 raeburn 650: text=>"Settings to display/modify"});
1.9 raeburn 651: my $confname = $dom.'-domainconfig';
1.160.6.13 raeburn 652:
1.3 raeburn 653: if ($phase eq 'process') {
1.160.6.27 raeburn 654: my $result = &Apache::lonconfigsettings::make_changes($r,$dom,$phase,$context,\@prefs_order,
655: \%prefs,\%domconfig,$confname,\@roles);
1.160.6.33 raeburn 656: if ((ref($result) eq 'HASH') && (keys(%{$result}))) {
1.160.6.24 raeburn 657: $r->rflush();
1.160.6.27 raeburn 658: &devalidate_remote_domconfs($dom,$result);
1.160.6.24 raeburn 659: }
1.30 raeburn 660: } elsif ($phase eq 'display') {
1.160.6.16 raeburn 661: my $js = &recaptcha_js().
1.160.6.40 raeburn 662: &toggle_display_js();
1.160.6.7 raeburn 663: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
1.152 raeburn 664: my ($othertitle,$usertypes,$types) =
665: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.7 raeburn 666: $js .= &lonbalance_targets_js($dom,$types,\%servers,
667: $domconfig{'loadbalancing'}).
1.160.6.6 raeburn 668: &new_spares_js().
669: &common_domprefs_js().
670: &Apache::loncommon::javascript_array_indexof();
1.152 raeburn 671: }
1.160.6.30 raeburn 672: if (grep(/^requestcourses$/,@actions)) {
673: my $javascript_validations;
674: my $coursebrowserjs=&Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
675: $js .= <<END;
676: <script type="text/javascript">
677: $javascript_validations
678: </script>
679: $coursebrowserjs
680: END
1.160.6.113 raeburn 681: } elsif (grep(/^ipaccess$/,@actions)) {
682: $js .= &Apache::loncommon::coursebrowser_javascript($env{'request.role.domain'});
1.160.6.30 raeburn 683: }
1.160.6.93 raeburn 684: if (grep(/^selfcreation$/,@actions)) {
685: $js .= &selfcreate_javascript();
686: }
1.160.6.78 raeburn 687: if (grep(/^contacts$/,@actions)) {
688: $js .= &contacts_javascript();
689: }
1.160.6.97 raeburn 690: if (grep(/^scantron$/,@actions)) {
691: $js .= &scantron_javascript();
692: }
1.150 raeburn 693: &Apache::lonconfigsettings::display_settings($r,$dom,$phase,$context,\@prefs_order,\%prefs,\%domconfig,$confname,$js);
1.1 raeburn 694: } else {
1.160.6.11 raeburn 695: # check if domconfig user exists for the domain.
696: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.26 raeburn 697: my ($configuserok,$author_ok,$switchserver) =
1.160.6.11 raeburn 698: &config_check($dom,$confname,$servadm);
699: unless ($configuserok eq 'ok') {
700: &Apache::lonconfigsettings::print_header($r,$phase,$context);
701: $r->print(&mt('The domain configuration user "[_1]" has yet to be created.',
702: $confname).
703: '<br />'
704: );
705: if ($switchserver) {
706: $r->print(&mt('Ordinarily, that domain configuration user is created when the ./UPDATE script is run to install LON-CAPA for the first time.').
707: '<br />'.
708: &mt('However, that does not apply when new domains are added to a multi-domain server, and ./UPDATE has not been run recently.').
709: '<br />'.
710: &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).
711: '<br />'.
712: &mt('To do that now, use the following link: [_1]',$switchserver)
713: );
714: } else {
715: $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.').
716: '<br />'.
717: &mt('Once that is done, you will be able to use the web-based "Set domain configuration" to configure the domain')
718: );
719: }
720: $r->print(&Apache::loncommon::end_page());
721: return OK;
722: }
1.21 raeburn 723: if (keys(%domconfig) == 0) {
724: my $primarylibserv = &Apache::lonnet::domain($dom,'primary');
1.29 raeburn 725: my @ids=&Apache::lonnet::current_machine_ids();
726: if (!grep(/^\Q$primarylibserv\E$/,@ids)) {
1.21 raeburn 727: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.41 raeburn 728: my @loginimages = ('img','logo','domlogo','login');
1.21 raeburn 729: my $custom_img_count = 0;
730: foreach my $img (@loginimages) {
731: if ($designhash{$dom.'.login.'.$img} ne '') {
732: $custom_img_count ++;
733: }
734: }
735: foreach my $role (@roles) {
736: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
737: $custom_img_count ++;
738: }
739: }
740: if ($custom_img_count > 0) {
1.94 raeburn 741: &Apache::lonconfigsettings::print_header($r,$phase,$context);
1.21 raeburn 742: my $switch_server = &check_switchserver($dom,$confname);
1.29 raeburn 743: $r->print(
744: &mt('Domain configuration settings have yet to be saved for this domain via the web-based domain preferences interface.').'<br />'.
745: &mt("While this remains so, you must switch to the domain's primary library server in order to update settings.").'<br /><br />'.
746: &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 />'.
747: &mt("However, you will still need to switch to the domain's primary library server to upload new images or logos.").'<br /><br />');
748: if ($switch_server) {
1.30 raeburn 749: $r->print($switch_server.' '.&mt('to primary library server for domain: [_1]',$dom));
1.29 raeburn 750: }
1.91 raeburn 751: $r->print(&Apache::loncommon::end_page());
1.21 raeburn 752: return OK;
753: }
754: }
755: }
1.91 raeburn 756: &Apache::lonconfigsettings::display_choices($r,$phase,$context,\@prefs_order,\%prefs);
1.3 raeburn 757: }
758: return OK;
759: }
760:
761: sub process_changes {
1.160.6.24 raeburn 762: my ($r,$dom,$confname,$action,$roles,$values,$lastactref) = @_;
1.92 raeburn 763: my %domconfig;
764: if (ref($values) eq 'HASH') {
765: %domconfig = %{$values};
766: }
1.3 raeburn 767: my $output;
768: if ($action eq 'login') {
1.160.6.24 raeburn 769: $output = &modify_login($r,$dom,$confname,$lastactref,%domconfig);
1.6 raeburn 770: } elsif ($action eq 'rolecolors') {
1.9 raeburn 771: $output = &modify_rolecolors($r,$dom,$confname,$roles,
1.160.6.24 raeburn 772: $lastactref,%domconfig);
1.3 raeburn 773: } elsif ($action eq 'quotas') {
1.160.6.30 raeburn 774: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.3 raeburn 775: } elsif ($action eq 'autoenroll') {
1.160.6.24 raeburn 776: $output = &modify_autoenroll($dom,$lastactref,%domconfig);
1.3 raeburn 777: } elsif ($action eq 'autoupdate') {
778: $output = &modify_autoupdate($dom,%domconfig);
1.125 raeburn 779: } elsif ($action eq 'autocreate') {
780: $output = &modify_autocreate($dom,%domconfig);
1.23 raeburn 781: } elsif ($action eq 'directorysrch') {
1.160.6.81 raeburn 782: $output = &modify_directorysrch($dom,$lastactref,%domconfig);
1.27 raeburn 783: } elsif ($action eq 'usercreation') {
1.28 raeburn 784: $output = &modify_usercreation($dom,%domconfig);
1.160.6.34 raeburn 785: } elsif ($action eq 'selfcreation') {
1.160.6.93 raeburn 786: $output = &modify_selfcreation($dom,$lastactref,%domconfig);
1.33 raeburn 787: } elsif ($action eq 'usermodification') {
788: $output = &modify_usermodification($dom,%domconfig);
1.28 raeburn 789: } elsif ($action eq 'contacts') {
1.160.6.24 raeburn 790: $output = &modify_contacts($dom,$lastactref,%domconfig);
1.43 raeburn 791: } elsif ($action eq 'defaults') {
1.160.6.27 raeburn 792: $output = &modify_defaults($dom,$lastactref,%domconfig);
1.46 raeburn 793: } elsif ($action eq 'scantron') {
1.160.6.24 raeburn 794: $output = &modify_scantron($r,$dom,$confname,$lastactref,%domconfig);
1.48 raeburn 795: } elsif ($action eq 'coursecategories') {
1.160.6.43 raeburn 796: $output = &modify_coursecategories($dom,$lastactref,%domconfig);
1.69 raeburn 797: } elsif ($action eq 'serverstatuses') {
798: $output = &modify_serverstatuses($dom,%domconfig);
1.86 raeburn 799: } elsif ($action eq 'requestcourses') {
1.160.6.30 raeburn 800: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.5 raeburn 801: } elsif ($action eq 'requestauthor') {
1.160.6.30 raeburn 802: $output = &modify_quotas($r,$dom,$action,$lastactref,%domconfig);
1.160.6.73 raeburn 803: } elsif ($action eq 'helpsettings') {
1.160.6.77 raeburn 804: $output = &modify_helpsettings($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.16 raeburn 805: } elsif ($action eq 'coursedefaults') {
1.160.6.27 raeburn 806: $output = &modify_coursedefaults($dom,$lastactref,%domconfig);
1.160.6.37 raeburn 807: } elsif ($action eq 'selfenrollment') {
808: $output = &modify_selfenrollment($dom,$lastactref,%domconfig)
1.137 raeburn 809: } elsif ($action eq 'usersessions') {
1.160.6.27 raeburn 810: $output = &modify_usersessions($dom,$lastactref,%domconfig);
1.150 raeburn 811: } elsif ($action eq 'loadbalancing') {
812: $output = &modify_loadbalancing($dom,%domconfig);
1.160.6.118.2 14(raebu 813:23): } elsif ($action eq 'ltitools') {
814:23): $output = &modify_ltitools($r,$dom,$action,$lastactref,%domconfig);
5(raebur 815:2): } elsif ($action eq 'lti') {
816:2): $output = &modify_lti($r,$dom,$action,$lastactref,%domconfig);
1.160.6.98 raeburn 817: } elsif ($action eq 'passwords') {
818: $output = &modify_passwords($r,$dom,$confname,$lastactref,%domconfig);
1.160.6.113 raeburn 819: } elsif ($action eq 'wafproxy') {
820: $output = &modify_wafproxy($dom,$action,$lastactref,%domconfig);
821: } elsif ($action eq 'ipaccess') {
822: $output = &modify_ipaccess($dom,$lastactref,%domconfig);
1.160.6.118.2 20(raebu 823:24): } elsif ($action eq 'authordefaults') {
824:24): $output = &modify_authordefaults($dom,$lastactref,%domconfig);
1.3 raeburn 825: }
826: return $output;
827: }
828:
829: sub print_config_box {
1.9 raeburn 830: my ($r,$dom,$confname,$phase,$action,$item,$settings) = @_;
1.30 raeburn 831: my $rowtotal = 0;
1.49 raeburn 832: my $output;
833: if ($action eq 'coursecategories') {
834: $output = &coursecategories_javascript($settings);
1.160.6.40 raeburn 835: } elsif ($action eq 'defaults') {
836: $output = &defaults_javascript($settings);
1.160.6.98 raeburn 837: } elsif ($action eq 'passwords') {
1.160.6.118.2 5(raebur 838:2): $output = &passwords_javascript($action);
1.160.6.73 raeburn 839: } elsif ($action eq 'helpsettings') {
840: my (%privs,%levelscurrent);
841: my %full=();
842: my %levels=(
843: course => {},
844: domain => {},
845: system => {},
846: );
847: my $context = 'domain';
848: my $crstype = 'Course';
849: my $formname = 'display';
850: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
851: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
852: $output =
853: &Apache::lonuserutils::custom_roledefs_js($context,$crstype,$formname,\%full,
854: \@templateroles);
1.160.6.118.2 1(raebur 855:1): } elsif ($action eq 'ltitools') {
14(raebu 856:23): $output .= &Apache::lonconfigsettings::ltitools_javascript($settings);
5(raebur 857:2): } elsif ($action eq 'lti') {
14(raebu 858:23): $output .= &passwords_javascript('ltisecrets')."\n".
5(raebur 859:2): <i_javascript($dom,$settings);
1.160.6.113 raeburn 860: } elsif ($action eq 'wafproxy') {
861: $output .= &wafproxy_javascript($dom);
862: } elsif ($action eq 'autoupdate') {
863: $output .= &autoupdate_javascript();
1.160.6.116 raeburn 864: } elsif ($action eq 'autoenroll') {
865: $output .= &autoenroll_javascript();
1.160.6.113 raeburn 866: } elsif ($action eq 'login') {
867: $output .= &saml_javascript();
868: } elsif ($action eq 'ipaccess') {
869: $output .= &ipaccess_javascript($settings);
1.160.6.118.2 20(raebu 870:24): } elsif ($action eq 'authordefaults') {
871:24): $output .= &authordefaults_javascript();
1.91 raeburn 872: }
1.160.6.40 raeburn 873: $output .=
1.30 raeburn 874: '<table class="LC_nested_outer">
1.3 raeburn 875: <tr>
1.160.6.113 raeburn 876: <th class="LC_left_item LC_middle"><span class="LC_nobreak">'.
1.66 raeburn 877: &mt($item->{text}).' '.
878: &Apache::loncommon::help_open_topic($item->{'help'}).'</span></th>'."\n".
879: '</tr>';
1.30 raeburn 880: $rowtotal ++;
1.110 raeburn 881: my $numheaders = 1;
882: if (ref($item->{'header'}) eq 'ARRAY') {
883: $numheaders = scalar(@{$item->{'header'}});
884: }
885: if ($numheaders > 1) {
1.64 raeburn 886: my $colspan = '';
1.145 raeburn 887: my $rightcolspan = '';
1.160.6.118.2 14(raebu 888:23): my $leftnobr = '';
1.160.6.42 raeburn 889: if (($action eq 'rolecolors') || ($action eq 'defaults') ||
1.160.6.72 raeburn 890: ($action eq 'directorysrch') ||
1.160.6.113 raeburn 891: (($action eq 'login') && ($numheaders < 5))) {
1.64 raeburn 892: $colspan = ' colspan="2"';
893: }
1.145 raeburn 894: if ($action eq 'usersessions') {
895: $rightcolspan = ' colspan="3"';
896: }
1.160.6.104 raeburn 897: if ($action eq 'passwords') {
898: $leftnobr = ' LC_nobreak';
899: }
1.30 raeburn 900: $output .= '
1.3 raeburn 901: <tr>
902: <td>
903: <table class="LC_nested">
904: <tr class="LC_info_row">
1.160.6.104 raeburn 905: <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[0]->{'col1'}).'</td>
1.145 raeburn 906: <td class="LC_right_item"'.$rightcolspan.'>'.&mt($item->{'header'}->[0]->{'col2'}).'</td>
1.30 raeburn 907: </tr>';
1.69 raeburn 908: $rowtotal ++;
1.160.6.37 raeburn 909: if (($action eq 'autoupdate') || ($action eq 'usercreation') || ($action eq 'selfcreation') ||
1.160.6.57 raeburn 910: ($action eq 'usermodification') || ($action eq 'defaults') || ($action eq 'coursedefaults') ||
1.160.6.73 raeburn 911: ($action eq 'selfenrollment') || ($action eq 'usersessions') || ($action eq 'directorysrch') ||
1.160.6.118.2 14(raebu 912:23): ($action eq 'helpsettings') || ($action eq 'contacts') || ($action eq 'wafproxy') ||
20(raebu 913:24): ($action eq 'lti') || ($action eq 'ltitools') || ($action eq 'authordefaults')) {
1.160.6.37 raeburn 914: $output .= $item->{'print'}->('top',$dom,$settings,\$rowtotal);
1.160.6.98 raeburn 915: } elsif ($action eq 'passwords') {
916: $output .= $item->{'print'}->('top',$dom,$confname,$settings,\$rowtotal);
1.57 raeburn 917: } elsif ($action eq 'coursecategories') {
1.160.6.37 raeburn 918: $output .= $item->{'print'}->('top',$dom,$item,$settings,\$rowtotal);
1.160.6.97 raeburn 919: } elsif ($action eq 'scantron') {
920: $output .= $item->{'print'}->($r,'top',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 921: } elsif ($action eq 'login') {
1.160.6.113 raeburn 922: if ($numheaders == 5) {
1.160.6.5 raeburn 923: $colspan = ' colspan="2"';
924: $output .= &print_login('service',$dom,$confname,$phase,$settings,\$rowtotal);
925: } else {
926: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal);
927: }
1.160.6.37 raeburn 928: } elsif (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 929: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.122 jms 930: } elsif ($action eq 'rolecolors') {
1.30 raeburn 931: $output .= &print_rolecolors($phase,'student',$dom,$confname,$settings,\$rowtotal);
1.160.6.2 raeburn 932: }
1.30 raeburn 933: $output .= '
1.6 raeburn 934: </table>
935: </td>
936: </tr>
937: <tr>
938: <td>
939: <table class="LC_nested">
940: <tr class="LC_info_row">
1.160.6.37 raeburn 941: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col1'}).'</td>
1.59 bisitz 942: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[1]->{'col2'}).'</td>
1.30 raeburn 943: </tr>';
944: $rowtotal ++;
1.160.6.37 raeburn 945: if (($action eq 'autoupdate') || ($action eq 'usercreation') ||
946: ($action eq 'selfcreation') || ($action eq 'selfenrollment') ||
1.160.6.78 raeburn 947: ($action eq 'usersessions') || ($action eq 'coursecategories') ||
1.160.6.118.2 8(raebur 948:2): ($action eq 'contacts') || ($action eq 'passwords') ||
14(raebu 949:23): ($action eq 'defaults') || ($action eq 'lti') ||
25(raebu 950:24): ($action eq 'ltitools') || ($action eq 'usermodification')) {
1.160.6.42 raeburn 951: if ($action eq 'coursecategories') {
952: $output .= &print_coursecategories('middle',$dom,$item,$settings,\$rowtotal);
953: $colspan = ' colspan="2"';
1.160.6.98 raeburn 954: } elsif ($action eq 'passwords') {
955: $output .= $item->{'print'}->('middle',$dom,$confname,$settings,\$rowtotal);
1.160.6.118.2 18(raebu 956:24): } elsif ($action eq 'lti') {
957:24): $output .= $item->{'print'}->('upper',$dom,$settings,\$rowtotal).'
958:24): </table>
959:24): </td>
960:24): </tr>
961:24): <tr>
962:24): <td>
963:24): <table class="LC_nested">
964:24): <tr class="LC_info_row">
965:24): <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
966:24): <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
967:24): </tr>'."\n".
968:24): $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
1.160.6.42 raeburn 969: } else {
970: $output .= $item->{'print'}->('middle',$dom,$settings,\$rowtotal);
971: }
1.160.6.118.2 18(raebu 972:24): my $hdridx = 2;
973:24): if ($action eq 'lti') {
974:24): $hdridx = 3;
975:24): }
1.160.6.42 raeburn 976: $output .= '
1.63 raeburn 977: </table>
978: </td>
979: </tr>
980: <tr>
981: <td>
982: <table class="LC_nested">
983: <tr class="LC_info_row">
1.160.6.118.2 18(raebu 984:24): <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
985:24): <td class="LC_right_item">'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td>
1.160.6.42 raeburn 986: </tr>'."\n";
987: if ($action eq 'coursecategories') {
988: $output .= &print_coursecategories('bottom',$dom,$item,$settings,\$rowtotal);
1.160.6.108 raeburn 989: } elsif (($action eq 'contacts') || ($action eq 'passwords')) {
1.160.6.107 raeburn 990: if ($action eq 'passwords') {
991: $output .= $item->{'print'}->('lower',$dom,$confname,$settings,\$rowtotal);
992: } else {
993: $output .= $item->{'print'}->('lower',$dom,$settings,\$rowtotal);
994: }
1.160.6.118.2 18(raebu 995:24): $hdridx ++;
1.160.6.107 raeburn 996: $output .= '
1.160.6.98 raeburn 997: </tr>
998: </table>
999: </td>
1000: </tr>
1001: <tr>
1002: <td>
1003: <table class="LC_nested">
1004: <tr class="LC_info_row">
1.160.6.118.2 18(raebu 1005:24): <td class="LC_left_item'.$leftnobr.'"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col1'}).'</td>
1006:24): <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[$hdridx]->{'col2'}).'</td></tr>'."\n";
1.160.6.108 raeburn 1007: if ($action eq 'passwords') {
1008: $output .= $item->{'print'}->('bottom',$dom,$confname,$settings,\$rowtotal);
1009: } else {
1010: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1011: }
1012: $output .= '
1.160.6.98 raeburn 1013: </table>
1014: </td>
1015: </tr>
1016: <tr>';
1.160.6.42 raeburn 1017: } else {
1018: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1019: }
1.63 raeburn 1020: $rowtotal ++;
1.160.6.118.2 25(raebu 1021:24): } elsif (($action eq 'coursedefaults') || ($action eq 'authordefaults') ||
8(raebur 1022:2): ($action eq 'directorysrch') || ($action eq 'helpsettings') ||
25(raebu 1023:24): ($action eq 'wafproxy')) {
1.160.6.37 raeburn 1024: $output .= $item->{'print'}->('bottom',$dom,$settings,\$rowtotal);
1.160.6.97 raeburn 1025: } elsif ($action eq 'scantron') {
1026: $output .= $item->{'print'}->($r,'bottom',$dom,$confname,$settings,\$rowtotal);
1.110 raeburn 1027: } elsif ($action eq 'login') {
1.160.6.113 raeburn 1028: if ($numheaders == 5) {
1.160.6.5 raeburn 1029: $output .= &print_login('page',$dom,$confname,$phase,$settings,\$rowtotal).'
1030: </table>
1031: </td>
1032: </tr>
1033: <tr>
1034: <td>
1035: <table class="LC_nested">
1036: <tr class="LC_info_row">
1037: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1.160.6.30 raeburn 1038: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td></tr>'.
1.160.6.5 raeburn 1039: &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1040: $rowtotal ++;
1041: } else {
1042: $output .= &print_login('help',$dom,$confname,$phase,$settings,\$rowtotal);
1043: }
1.160.6.56 raeburn 1044: $output .= '
1045: </table>
1046: </td>
1047: </tr>
1048: <tr>
1049: <td>
1050: <table class="LC_nested">
1051: <tr class="LC_info_row">';
1.160.6.113 raeburn 1052: if ($numheaders == 5) {
1.160.6.56 raeburn 1053: $output .= '
1054: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1055: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1056: </tr>';
1057: } else {
1058: $output .= '
1059: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1060: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col2'}).'</td>
1061: </tr>';
1062: }
1063: $rowtotal ++;
1.160.6.113 raeburn 1064: $output .= &print_login('headtag',$dom,$confname,$phase,$settings,\$rowtotal).'
1065: </table>
1066: </td>
1067: </tr>
1068: <tr>
1069: <td>
1070: <table class="LC_nested">
1071: <tr class="LC_info_row">';
1072: if ($numheaders == 5) {
1073: $output .= '
1074: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1075: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1076: </tr>';
1077: } else {
1078: $output .= '
1079: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1080: <td class="LC_right_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1081: </tr>';
1082: }
1083: $rowtotal ++;
1084: $output .= &print_login('saml',$dom,$confname,$phase,$settings,\$rowtotal);
1.102 raeburn 1085: } elsif ($action eq 'requestcourses') {
1.160.6.50 raeburn 1086: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1087: $rowtotal ++;
1088: $output .= &print_studentcode($settings,\$rowtotal).'
1.160.6.30 raeburn 1089: </table>
1090: </td>
1091: </tr>
1092: <tr>
1093: <td>
1094: <table class="LC_nested">
1095: <tr class="LC_info_row">
1096: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[2]->{'col1'}).'</td>
1097: <td class="LC_right_item">'.&mt($item->{'header'}->[2]->{'col2'}).'</td> </tr>'.
1.160.6.46 raeburn 1098: &textbookcourses_javascript($settings).
1099: &print_textbookcourses($dom,'textbooks',$settings,\$rowtotal).'
1100: </table>
1101: </td>
1102: </tr>
1103: <tr>
1104: <td>
1105: <table class="LC_nested">
1106: <tr class="LC_info_row">
1107: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1108: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td> </tr>'.
1109: &print_textbookcourses($dom,'templates',$settings,\$rowtotal).'
1.160.6.39 raeburn 1110: </table>
1111: </td>
1112: </tr>
1113: <tr>
1114: <td>
1115: <table class="LC_nested">
1116: <tr class="LC_info_row">
1.160.6.46 raeburn 1117: <td class="LC_left_item"'.$colspan.' valign="top">'.&mt($item->{'header'}->[4]->{'col1'}).'</td>
1118: <td class="LC_right_item" valign="top">'.&mt($item->{'header'}->[4]->{'col2'}).'</td>
1.160.6.39 raeburn 1119: </tr>'.
1120: &print_validation_rows('requestcourses',$dom,$settings,\$rowtotal);
1.160.6.5 raeburn 1121: } elsif ($action eq 'requestauthor') {
1122: $output .= &print_requestmail($dom,$action,$settings,\$rowtotal);
1.160.6.50 raeburn 1123: $rowtotal ++;
1.122 jms 1124: } elsif ($action eq 'rolecolors') {
1.30 raeburn 1125: $output .= &print_rolecolors($phase,'coordinator',$dom,$confname,$settings,\$rowtotal).'
1.6 raeburn 1126: </table>
1127: </td>
1128: </tr>
1129: <tr>
1130: <td>
1131: <table class="LC_nested">
1132: <tr class="LC_info_row">
1.69 raeburn 1133: <td class="LC_left_item"'.$colspan.' valign="top">'.
1134: &mt($item->{'header'}->[2]->{'col1'}).'</td>
1135: <td class="LC_right_item" valign="top">'.
1136: &mt($item->{'header'}->[2]->{'col2'}).'</td>
1.3 raeburn 1137: </tr>'.
1.30 raeburn 1138: &print_rolecolors($phase,'author',$dom,$confname,$settings,\$rowtotal).'
1.3 raeburn 1139: </table>
1140: </td>
1141: </tr>
1142: <tr>
1143: <td>
1144: <table class="LC_nested">
1145: <tr class="LC_info_row">
1.59 bisitz 1146: <td class="LC_left_item"'.$colspan.'>'.&mt($item->{'header'}->[3]->{'col1'}).'</td>
1147: <td class="LC_right_item">'.&mt($item->{'header'}->[3]->{'col2'}).'</td>
1.3 raeburn 1148: </tr>'.
1.30 raeburn 1149: &print_rolecolors($phase,'admin',$dom,$confname,$settings,\$rowtotal);
1150: $rowtotal += 2;
1.6 raeburn 1151: }
1.3 raeburn 1152: } else {
1.30 raeburn 1153: $output .= '
1.3 raeburn 1154: <tr>
1155: <td>
1156: <table class="LC_nested">
1.30 raeburn 1157: <tr class="LC_info_row">';
1.160.6.72 raeburn 1158: if ($action eq 'login') {
1.30 raeburn 1159: $output .= '
1.59 bisitz 1160: <td class="LC_left_item" colspan="2">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1.69 raeburn 1161: } elsif ($action eq 'serverstatuses') {
1162: $output .= '
1163: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).
1164: '<br />('.&mt('Automatic access for Dom. Coords.').')</td>';
1165:
1.6 raeburn 1166: } else {
1.30 raeburn 1167: $output .= '
1.69 raeburn 1168: <td class="LC_left_item" valign="top">'.&mt($item->{'header'}->[0]->{'col1'}).'</td>';
1169: }
1.72 raeburn 1170: if (defined($item->{'header'}->[0]->{'col3'})) {
1171: $output .= '<td class="LC_left_item" valign="top">'.
1172: &mt($item->{'header'}->[0]->{'col2'});
1173: if ($action eq 'serverstatuses') {
1174: $output .= '<br />(<tt>'.&mt('user1:domain1,user2:domain2 etc.').'</tt>)';
1175: }
1.69 raeburn 1176: } else {
1177: $output .= '<td class="LC_right_item" valign="top">'.
1178: &mt($item->{'header'}->[0]->{'col2'});
1179: }
1180: $output .= '</td>';
1181: if ($item->{'header'}->[0]->{'col3'}) {
1.150 raeburn 1182: if (defined($item->{'header'}->[0]->{'col4'})) {
1183: $output .= '<td class="LC_left_item" valign="top">'.
1184: &mt($item->{'header'}->[0]->{'col3'});
1185: } else {
1186: $output .= '<td class="LC_right_item" valign="top">'.
1187: &mt($item->{'header'}->[0]->{'col3'});
1188: }
1.69 raeburn 1189: if ($action eq 'serverstatuses') {
1190: $output .= '<br />(<tt>'.&mt('IP1,IP2 etc.').'</tt>)';
1191: }
1192: $output .= '</td>';
1.6 raeburn 1193: }
1.150 raeburn 1194: if ($item->{'header'}->[0]->{'col4'}) {
1195: $output .= '<td class="LC_right_item" valign="top">'.
1196: &mt($item->{'header'}->[0]->{'col4'});
1197: }
1.69 raeburn 1198: $output .= '</tr>';
1.48 raeburn 1199: $rowtotal ++;
1.160.6.5 raeburn 1200: if ($action eq 'quotas') {
1.86 raeburn 1201: $output .= &print_quotas($dom,$settings,\$rowtotal,$action);
1.160.6.72 raeburn 1202: } elsif (($action eq 'autoenroll') || ($action eq 'autocreate') ||
1.160.6.113 raeburn 1203: ($action eq 'serverstatuses') || ($action eq 'loadbalancing') ||
1.160.6.118.2 14(raebu 1204:23): ($action eq 'ipaccess')) {
1.160.6.37 raeburn 1205: $output .= $item->{'print'}->($dom,$settings,\$rowtotal);
1.121 raeburn 1206: }
1.3 raeburn 1207: }
1.30 raeburn 1208: $output .= '
1.3 raeburn 1209: </table>
1210: </td>
1211: </tr>
1.30 raeburn 1212: </table><br />';
1213: return ($output,$rowtotal);
1.1 raeburn 1214: }
1215:
1.3 raeburn 1216: sub print_login {
1.160.6.5 raeburn 1217: my ($caller,$dom,$confname,$phase,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 1218: my ($css_class,$datatable,$switchserver,%lt);
1.6 raeburn 1219: my %choices = &login_choices();
1.160.6.113 raeburn 1220: if (($caller eq 'help') || ($caller eq 'headtag') || ($caller eq 'saml')) {
1221: %lt = &login_file_options();
1222: $switchserver = &check_switchserver($dom,$confname);
1223: }
1.160.6.5 raeburn 1224: if ($caller eq 'service') {
1.149 raeburn 1225: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.110 raeburn 1226: my $choice = $choices{'disallowlogin'};
1227: $css_class = ' class="LC_odd_row"';
1.128 raeburn 1228: $datatable .= '<tr'.$css_class.'><td>'.$choice.'</td>'.
1.110 raeburn 1229: '<td align="right"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1.128 raeburn 1230: '<th>'.$choices{'server'}.'</th>'.
1231: '<th>'.$choices{'serverpath'}.'</th>'.
1232: '<th>'.$choices{'custompath'}.'</th>'.
1233: '<th><span class="LC_nobreak">'.$choices{'exempt'}.'</span></th></tr>'."\n";
1.110 raeburn 1234: my %disallowed;
1235: if (ref($settings) eq 'HASH') {
1236: if (ref($settings->{'loginvia'}) eq 'HASH') {
1237: %disallowed = %{$settings->{'loginvia'}};
1238: }
1239: }
1240: foreach my $lonhost (sort(keys(%servers))) {
1241: my $direct = 'selected="selected"';
1.128 raeburn 1242: if (ref($disallowed{$lonhost}) eq 'HASH') {
1243: if ($disallowed{$lonhost}{'server'} ne '') {
1244: $direct = '';
1245: }
1.110 raeburn 1246: }
1.115 raeburn 1247: $datatable .= '<tr><td>'.$servers{$lonhost}.'</td>'.
1.128 raeburn 1248: '<td><select name="'.$lonhost.'_server">'.
1.110 raeburn 1249: '<option value=""'.$direct.'>'.$choices{'directlogin'}.
1250: '</option>';
1.160.6.13 raeburn 1251: foreach my $hostid (sort(keys(%servers))) {
1.115 raeburn 1252: next if ($servers{$hostid} eq $servers{$lonhost});
1.110 raeburn 1253: my $selected = '';
1.128 raeburn 1254: if (ref($disallowed{$lonhost}) eq 'HASH') {
1255: if ($hostid eq $disallowed{$lonhost}{'server'}) {
1256: $selected = 'selected="selected"';
1257: }
1.110 raeburn 1258: }
1259: $datatable .= '<option value="'.$hostid.'"'.$selected.'>'.
1260: $servers{$hostid}.'</option>';
1261: }
1.128 raeburn 1262: $datatable .= '</select></td>'.
1263: '<td><select name="'.$lonhost.'_serverpath">';
1264: foreach my $path ('','/','/adm/login','/adm/roles','custom') {
1265: my $pathname = $path;
1266: if ($path eq 'custom') {
1267: $pathname = &mt('Custom Path').' ->';
1268: }
1269: my $selected = '';
1270: if (ref($disallowed{$lonhost}) eq 'HASH') {
1271: if ($path eq $disallowed{$lonhost}{'serverpath'}) {
1272: $selected = 'selected="selected"';
1273: }
1274: } elsif ($path eq '') {
1275: $selected = 'selected="selected"';
1276: }
1277: $datatable .= '<option value="'.$path.'"'.$selected.'>'.$pathname.'</option>';
1278: }
1279: $datatable .= '</select></td>';
1280: my ($custom,$exempt);
1281: if (ref($disallowed{$lonhost}) eq 'HASH') {
1282: $custom = $disallowed{$lonhost}{'custompath'};
1283: $exempt = $disallowed{$lonhost}{'exempt'};
1284: }
1285: $datatable .= '<td><input type="text" name="'.$lonhost.'_custompath" size="6" value="'.$custom.'" /></td>'.
1286: '<td><input type="text" name="'.$lonhost.'_exempt" size="8" value="'.$exempt.'" /></td>'.
1287: '</tr>';
1.110 raeburn 1288: }
1289: $datatable .= '</table></td></tr>';
1290: return $datatable;
1.160.6.5 raeburn 1291: } elsif ($caller eq 'page') {
1292: my %defaultchecked = (
1293: 'coursecatalog' => 'on',
1.160.6.14 raeburn 1294: 'helpdesk' => 'on',
1.160.6.5 raeburn 1295: 'adminmail' => 'off',
1296: 'newuser' => 'off',
1297: );
1.160.6.14 raeburn 1298: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.160.6.5 raeburn 1299: my (%checkedon,%checkedoff);
1.42 raeburn 1300: foreach my $item (@toggles) {
1.160.6.5 raeburn 1301: if ($defaultchecked{$item} eq 'on') {
1302: $checkedon{$item} = ' checked="checked" ';
1.42 raeburn 1303: $checkedoff{$item} = ' ';
1.160.6.5 raeburn 1304: } elsif ($defaultchecked{$item} eq 'off') {
1305: $checkedoff{$item} = ' checked="checked" ';
1.42 raeburn 1306: $checkedon{$item} = ' ';
1307: }
1.1 raeburn 1308: }
1.160.6.5 raeburn 1309: my @images = ('img','logo','domlogo','login');
1.160.6.118.2 2(raebur 1310:2): my @alttext = ('img','logo','domlogo');
1.160.6.5 raeburn 1311: my @logintext = ('textcol','bgcol');
1312: my @bgs = ('pgbg','mainbg','sidebg');
1313: my @links = ('link','alink','vlink');
1314: my %designhash = &Apache::loncommon::get_domainconf($dom);
1315: my %defaultdesign = %Apache::loncommon::defaultdesign;
1316: my (%is_custom,%designs);
1317: my %defaults = (
1318: font => $defaultdesign{'login.font'},
1319: );
1.6 raeburn 1320: foreach my $item (@images) {
1.160.6.5 raeburn 1321: $defaults{$item} = $defaultdesign{'login.'.$item};
1322: $defaults{'showlogo'}{$item} = 1;
1323: }
1324: foreach my $item (@bgs) {
1325: $defaults{'bgs'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1326: }
1.41 raeburn 1327: foreach my $item (@logintext) {
1.160.6.5 raeburn 1328: $defaults{'logintext'}{$item} = $defaultdesign{'login.'.$item};
1.41 raeburn 1329: }
1.160.6.5 raeburn 1330: foreach my $item (@links) {
1331: $defaults{'links'}{$item} = $defaultdesign{'login.'.$item};
1.6 raeburn 1332: }
1.160.6.5 raeburn 1333: if (ref($settings) eq 'HASH') {
1334: foreach my $item (@toggles) {
1335: if ($settings->{$item} eq '1') {
1336: $checkedon{$item} = ' checked="checked" ';
1337: $checkedoff{$item} = ' ';
1338: } elsif ($settings->{$item} eq '0') {
1339: $checkedoff{$item} = ' checked="checked" ';
1340: $checkedon{$item} = ' ';
1341: }
1.6 raeburn 1342: }
1.160.6.5 raeburn 1343: foreach my $item (@images) {
1344: if (defined($settings->{$item})) {
1345: $designs{$item} = $settings->{$item};
1346: $is_custom{$item} = 1;
1347: }
1348: if (defined($settings->{'showlogo'}{$item})) {
1349: $designs{'showlogo'}{$item} = $settings->{'showlogo'}{$item};
1350: }
1351: }
1.160.6.118.2 2(raebur 1352:2): foreach my $item (@alttext) {
1353:2): if (ref($settings->{'alttext'}) eq 'HASH') {
1354:2): if ($settings->{'alttext'}->{$item} ne '') {
1355:2): $designs{'alttext'}{$item} = $settings->{'alttext'}{$item};
1356:2): }
1357:2): }
1358:2): }
1.160.6.5 raeburn 1359: foreach my $item (@logintext) {
1360: if ($settings->{$item} ne '') {
1361: $designs{'logintext'}{$item} = $settings->{$item};
1362: $is_custom{$item} = 1;
1363: }
1364: }
1365: if ($settings->{'font'} ne '') {
1366: $designs{'font'} = $settings->{'font'};
1367: $is_custom{'font'} = 1;
1368: }
1369: foreach my $item (@bgs) {
1370: if ($settings->{$item} ne '') {
1371: $designs{'bgs'}{$item} = $settings->{$item};
1372: $is_custom{$item} = 1;
1373: }
1374: }
1375: foreach my $item (@links) {
1376: if ($settings->{$item} ne '') {
1377: $designs{'links'}{$item} = $settings->{$item};
1378: $is_custom{$item} = 1;
1379: }
1380: }
1381: } else {
1382: if ($designhash{$dom.'.login.font'} ne '') {
1383: $designs{'font'} = $designhash{$dom.'.login.font'};
1384: $is_custom{'font'} = 1;
1385: }
1386: foreach my $item (@images) {
1387: if ($designhash{$dom.'.login.'.$item} ne '') {
1388: $designs{$item} = $designhash{$dom.'.login.'.$item};
1389: $is_custom{$item} = 1;
1390: }
1391: }
1392: foreach my $item (@bgs) {
1393: if ($designhash{$dom.'.login.'.$item} ne '') {
1394: $designs{'bgs'}{$item} = $designhash{$dom.'.login.'.$item};
1395: $is_custom{$item} = 1;
1396: }
1397: }
1398: foreach my $item (@links) {
1399: if ($designhash{$dom.'.login.'.$item} ne '') {
1400: $designs{'links'}{$item} = $designhash{$dom.'.login.'.$item};
1401: $is_custom{$item} = 1;
1402: }
1.6 raeburn 1403: }
1404: }
1.160.6.5 raeburn 1405: my %alt_text = &Apache::lonlocal::texthash ( img => 'Log-in banner',
1406: logo => 'Institution Logo',
1407: domlogo => 'Domain Logo',
1408: login => 'Login box');
1409: my $itemcount = 1;
1410: foreach my $item (@toggles) {
1411: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1412: $datatable .=
1413: '<tr'.$css_class.'><td colspan="2">'.$choices{$item}.
1414: '</td><td>'.
1415: '<span class="LC_nobreak"><label><input type="radio" name="'.
1416: $item.'"'.$checkedon{$item}.' value="1" />'.&mt('Yes').
1417: '</label> <label><input type="radio" name="'.$item.'"'.
1418: $checkedoff{$item}.' value="0" />'.&mt('No').'</label></span></td>'.
1419: '</tr>';
1420: $itemcount ++;
1.6 raeburn 1421: }
1.160.6.5 raeburn 1422: $datatable .= &display_color_options($dom,$confname,$phase,'login',$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal,\@logintext);
1423: $datatable .= '</tr></table></td></tr>';
1424: } elsif ($caller eq 'help') {
1.160.6.113 raeburn 1425: my ($defaulturl,$defaulttype,%url,%type,%langchoices);
1.160.6.5 raeburn 1426: my $itemcount = 1;
1427: $defaulturl = '/adm/loginproblems.html';
1428: $defaulttype = 'default';
1429: %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
1430: my @currlangs;
1431: if (ref($settings) eq 'HASH') {
1432: if (ref($settings->{'helpurl'}) eq 'HASH') {
1433: foreach my $key (sort(keys(%{$settings->{'helpurl'}}))) {
1434: next if ($settings->{'helpurl'}{$key} eq '');
1435: $url{$key} = $settings->{'helpurl'}{$key}.'?inhibitmenu=yes';
1436: $type{$key} = 'custom';
1437: unless ($key eq 'nolang') {
1438: push(@currlangs,$key);
1439: }
1440: }
1441: } elsif ($settings->{'helpurl'} ne '') {
1442: $type{'nolang'} = 'custom';
1443: $url{'nolang'} = $settings->{'helpurl'}.'?inhibitmenu=yes';
1.8 raeburn 1444: }
1445: }
1.160.6.5 raeburn 1446: foreach my $lang ('nolang',sort(@currlangs)) {
1447: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1448: $datatable .= '<tr'.$css_class.'>';
1449: if ($url{$lang} eq '') {
1450: $url{$lang} = $defaulturl;
1451: }
1452: if ($type{$lang} eq '') {
1453: $type{$lang} = $defaulttype;
1454: }
1455: $datatable .= '<td colspan="2"><span class="LC_nobreak">';
1456: if ($lang eq 'nolang') {
1457: $datatable .= &mt('Log-in help page if no specific language file: [_1]',
1458: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1459: } else {
1460: $datatable .= &mt('Log-in help page for language: [_1] is [_2]',
1461: $langchoices{$lang},
1462: &Apache::loncommon::modal_link($url{$lang},$lt{$type{$lang}},600,500));
1463: }
1464: $datatable .= '</span></td>'."\n".
1465: '<td class="LC_left_item">';
1466: if ($type{$lang} eq 'custom') {
1467: $datatable .= '<span class="LC_nobreak"><label>'.
1468: '<input type="checkbox" name="loginhelpurl_del" value="'.$lang.'" />'.
1469: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1470: } else {
1471: $datatable .= $lt{'upl'};
1472: }
1473: $datatable .='<br />';
1474: if ($switchserver) {
1475: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1476: } else {
1477: $datatable .= '<input type="file" name="loginhelpurl_'.$lang.'" />';
1.6 raeburn 1478: }
1.160.6.5 raeburn 1479: $datatable .= '</td></tr>';
1480: $itemcount ++;
1.6 raeburn 1481: }
1.160.6.5 raeburn 1482: my @addlangs;
1483: foreach my $lang (sort(keys(%langchoices))) {
1484: next if ((grep(/^\Q$lang\E$/,@currlangs)) || ($lang eq 'x_chef'));
1485: push(@addlangs,$lang);
1486: }
1487: if (@addlangs > 0) {
1488: my %toadd;
1489: map { $toadd{$_} = $langchoices{$_} ; } @addlangs;
1490: $toadd{''} = &mt('Select');
1491: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1492: $datatable .= '<tr'.$css_class.'><td class="LC_left_item" colspan="2">'.
1493: &mt('Add log-in help page for a specific language:').' '.
1494: &Apache::loncommon::select_form('','loginhelpurl_add_lang',\%toadd).
1495: '</td><td class="LC_left_item">'.$lt{'upl'}.'<br />';
1496: if ($switchserver) {
1497: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1498: } else {
1499: $datatable .= '<input type="file" name="loginhelpurl_add_file" />';
1.6 raeburn 1500: }
1.160.6.5 raeburn 1501: $datatable .= '</td></tr>';
1502: $itemcount ++;
1.6 raeburn 1503: }
1.160.6.5 raeburn 1504: $datatable .= &captcha_choice('login',$settings,$itemcount);
1.160.6.56 raeburn 1505: } elsif ($caller eq 'headtag') {
1506: my %domservers = &Apache::lonnet::get_servers($dom);
1507: my $choice = $choices{'headtag'};
1508: $css_class = ' class="LC_odd_row"';
1509: $datatable .= '<tr'.$css_class.'><td colspan="2">'.$choice.'</td>'.
1510: '<td align="left"><table><tr><th>'.$choices{'hostid'}.'</th>'.
1511: '<th>'.$choices{'current'}.'</th>'.
1512: '<th>'.$choices{'action'}.'</th>'.
1513: '<th>'.$choices{'exempt'}.'</th></tr>'."\n";
1514: my (%currurls,%currexempt);
1515: if (ref($settings) eq 'HASH') {
1516: if (ref($settings->{'headtag'}) eq 'HASH') {
1517: foreach my $lonhost (keys(%{$settings->{'headtag'}})) {
1518: if (ref($settings->{'headtag'}{$lonhost}) eq 'HASH') {
1519: $currurls{$lonhost} = $settings->{'headtag'}{$lonhost}{'url'};
1520: $currexempt{$lonhost} = $settings->{'headtag'}{$lonhost}{'exempt'};
1521: }
1522: }
1523: }
1524: }
1525: foreach my $lonhost (sort(keys(%domservers))) {
1526: my $exempt = &check_exempt_addresses($currexempt{$lonhost});
1527: $datatable .= '<tr><td>'.$domservers{$lonhost}.'</td>';
1528: if ($currurls{$lonhost}) {
1529: $datatable .= '<td class="LC_right_item"><a href="'.
1530: "javascript:void(open('$currurls{$lonhost}?inhibitmenu=yes','Custom_HeadTag',
1531: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
1532: '">'.$lt{'curr'}.'</a></td>'.
1533: '<td><span class="LC_nobreak"><label>'.
1534: '<input type="checkbox" name="loginheadtag_del" value="'.$lonhost.'" />'.
1535: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1536: } else {
1537: $datatable .= '<td class="LC_right_item">'.$lt{'none'}.'</td><td>'.$lt{'upl'};
1538: }
1539: $datatable .='<br />';
1540: if ($switchserver) {
1541: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1542: } else {
1543: $datatable .= '<input type="file" name="loginheadtag_'.$lonhost.'" />';
1544: }
1.160.6.87 raeburn 1545: $datatable .= '</td><td><input type="text" name="loginheadtagexempt_'.$lonhost.'" value="'.$exempt.'" /></td></tr>';
1.160.6.56 raeburn 1546: }
1547: $datatable .= '</table></td></tr>';
1.160.6.113 raeburn 1548: } elsif ($caller eq 'saml') {
1549: my %domservers = &Apache::lonnet::get_servers($dom);
1550: $datatable .= '<tr><td colspan="3" style="text-align: left">'.
1551: '<table><tr><th>'.$choices{'hostid'}.'</th>'.
1552: '<th>'.$choices{'samllanding'}.'</th>'.
1553: '<th>'.$choices{'samloptions'}.'</th></tr>'."\n";
1.160.6.118.2 9(raebur 1554:2): my (%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso,%styleon,%styleoff);
1.160.6.113 raeburn 1555: foreach my $lonhost (keys(%domservers)) {
1556: $samlurl{$lonhost} = '/adm/sso';
1557: $styleon{$lonhost} = 'display:none';
1558: $styleoff{$lonhost} = '';
1559: }
1.160.6.118.2 11(raebu 1560:23): if ((ref($settings) eq 'HASH') && (ref($settings->{'saml'}) eq 'HASH')) {
1.160.6.113 raeburn 1561: foreach my $lonhost (keys(%{$settings->{'saml'}})) {
1562: if (ref($settings->{'saml'}{$lonhost}) eq 'HASH') {
1563: $saml{$lonhost} = 1;
1564: $samltext{$lonhost} = $settings->{'saml'}{$lonhost}{'text'};
1565: $samlimg{$lonhost} = $settings->{'saml'}{$lonhost}{'img'};
1566: $samlalt{$lonhost} = $settings->{'saml'}{$lonhost}{'alt'};
1567: $samlurl{$lonhost} = $settings->{'saml'}{$lonhost}{'url'};
1568: $samltitle{$lonhost} = $settings->{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 1569:2): $samlwindow{$lonhost} = $settings->{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 1570: $samlnotsso{$lonhost} = $settings->{'saml'}{$lonhost}{'notsso'};
1571: $styleon{$lonhost} = '';
1572: $styleoff{$lonhost} = 'display:none';
1573: } else {
1574: $styleon{$lonhost} = 'display:none';
1575: $styleoff{$lonhost} = '';
1576: }
1577: }
1578: }
1579: my $itemcount = 1;
1580: foreach my $lonhost (sort(keys(%domservers))) {
1581: my $samlon = ' ';
1582: my $samloff = ' checked="checked" ';
1583: if ($saml{$lonhost}) {
1584: $samlon = $samloff;
1585: $samloff = ' ';
1586: }
1.160.6.118.2 9(raebur 1587:2): my $samlwinon = '';
1588:2): my $samlwinoff = ' checked="checked"';
1589:2): if ($samlwindow{$lonhost}) {
1590:2): $samlwinon = $samlwinoff;
1591:2): $samlwinoff = '';
1592:2): }
1.160.6.113 raeburn 1593: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1594: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.$domservers{$lonhost}.'</span></td>'.
1595: '<td><span class="LC_nobreak"><label><input type="radio" name="saml_'.$lonhost.'"'.$samloff.
1596: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="0" />'.
1597: &mt('No').'</label>'.(' 'x2).
1598: '<label><input type="radio" name="saml_'.$lonhost.'"'.$samlon.
1599: 'onclick="toggleSamlOptions(this.form,'."'$lonhost'".');" value="1" />'.
1600: &mt('Yes').'</label></span></td>'.
1601: '<td id="samloptionson_'.$lonhost.'" style="'.$styleon{$lonhost}.'" width="100%">'.
1.160.6.118.2 9(raebur 1602:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th></tr>'.
1.160.6.113 raeburn 1603: '<tr><th>'.&mt('Text').'</th><th>'.&mt('Image').'</th>'.
1.160.6.118.2 9(raebur 1604:2): '<th>'.&mt('Alt Text').'</th></tr>'.
1605:2): '<tr'.$css_class.'><td><input type="text" name="saml_text_'.$lonhost.'" size="20" value="'.
1.160.6.113 raeburn 1606: $samltext{$lonhost}.'" /></td><td>';
1607: if ($samlimg{$lonhost}) {
1608: $datatable .= '<img src="'.$samlimg{$lonhost}.'" /><br />'.
1609: '<span class="LC_nobreak"><label>'.
1610: '<input type="checkbox" name="saml_img_del" value="'.$lonhost.'" />'.
1611: $lt{'del'}.'</label> '.$lt{'rep'}.'</span>';
1612: } else {
1613: $datatable .= $lt{'upl'};
1614: }
1615: $datatable .='<br />';
1616: if ($switchserver) {
1617: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
1618: } else {
1619: $datatable .= '<input type="file" name="saml_img_'.$lonhost.'" />';
1620: }
1621: $datatable .= '</td>'.
1.160.6.118.2 9(raebur 1622:2): '<td><input type="text" name="saml_alt_'.$lonhost.'" size="25" '.
1623:2): 'value="'.$samlalt{$lonhost}.'" /></td></tr></table><br />'.
1624:2): '<table width="100%"><tr><th colspan="3" align="center">'.&mt('SSO').'</th><th align="center">'.
1625:2): '<span class="LC_nobreak">'.&mt('Non-SSO').'</span></th></tr>'.
1626:2): '<tr><th>'.&mt('URL').'</th><th>'.&mt('Tool Tip').'</th>'.
1627:2): '<th>'.&mt('Pop-up if iframe').'</th><th>'.&mt('Text').'</th></tr>'.
1628:2): '<tr'.$css_class.'>'.
1629:2): '<td><input type="text" name="saml_url_'.$lonhost.'" size="30" '.
1.160.6.113 raeburn 1630: 'value="'.$samlurl{$lonhost}.'" /></td>'.
1.160.6.118.2 9(raebur 1631:2): '<td><textarea name="saml_title_'.$lonhost.'" rows="3" cols="20">'.
1.160.6.113 raeburn 1632: $samltitle{$lonhost}.'</textarea></td>'.
1.160.6.118.2 9(raebur 1633:2): '<td><label><input type="radio" name="saml_window_'.$lonhost.'" value=""'.$samlwinoff.'>'.
1634:2): &mt('No').'</label>'.(' 'x2).'<label><input type="radio" '.
1635:2): 'name="saml_window_'.$lonhost.'" value="1"'.$samlwinon.'>'.&mt('Yes').'</label></td>'.
1636:2): '<td><input type="text" name="saml_notsso_'.$lonhost.'" size="12" '.
1.160.6.113 raeburn 1637: 'value="'.$samlnotsso{$lonhost}.'" /></td></tr>'.
1638: '</table></td>'.
1639: '<td id="samloptionsoff_'.$lonhost.'" style="'.$styleoff{$lonhost}.'" width="100%"> </td></tr>';
1640: $itemcount ++;
1641: }
1642: $datatable .= '</table></td></tr>';
1.1 raeburn 1643: }
1.6 raeburn 1644: return $datatable;
1645: }
1646:
1647: sub login_choices {
1648: my %choices =
1649: &Apache::lonlocal::texthash (
1.116 bisitz 1650: coursecatalog => 'Display Course/Community Catalog link?',
1.110 raeburn 1651: adminmail => "Display Administrator's E-mail Address?",
1.160.6.14 raeburn 1652: helpdesk => 'Display "Contact Helpdesk" link',
1.110 raeburn 1653: disallowlogin => "Login page requests redirected",
1654: hostid => "Server",
1.128 raeburn 1655: server => "Redirect to:",
1656: serverpath => "Path",
1657: custompath => "Custom",
1658: exempt => "Exempt IP(s)",
1.110 raeburn 1659: directlogin => "No redirect",
1660: newuser => "Link to create a user account",
1661: img => "Header",
1662: logo => "Main Logo",
1663: domlogo => "Domain Logo",
1664: login => "Log-in Header",
1665: textcol => "Text color",
1666: bgcol => "Box color",
1667: bgs => "Background colors",
1668: links => "Link colors",
1669: font => "Font color",
1670: pgbg => "Header",
1671: mainbg => "Page",
1672: sidebg => "Login box",
1673: link => "Link",
1674: alink => "Active link",
1675: vlink => "Visited link",
1.160.6.56 raeburn 1676: headtag => "Custom markup",
1677: action => "Action",
1678: current => "Current",
1.160.6.113 raeburn 1679: samllanding => "Dual login?",
1680: samloptions => "Options",
1.160.6.118.2 2(raebur 1681:2): alttext => "Alt text",
1.6 raeburn 1682: );
1683: return %choices;
1684: }
1685:
1.160.6.113 raeburn 1686: sub login_file_options {
1687: return &Apache::lonlocal::texthash(
1688: del => 'Delete?',
1689: rep => 'Replace:',
1690: upl => 'Upload:',
1691: curr => 'View contents',
1692: default => 'Default',
1693: custom => 'Custom',
1694: none => 'None',
1695: );
1696: }
1697:
1698: sub print_ipaccess {
1699: my ($dom,$settings,$rowtotal) = @_;
1700: my $css_class;
1701: my $itemcount = 0;
1702: my $datatable;
1703: my %ordered;
1704: if (ref($settings) eq 'HASH') {
1705: foreach my $item (keys(%{$settings})) {
1706: if (ref($settings->{$item}) eq 'HASH') {
1707: my $num = $settings->{$item}{'order'};
1708: if ($num eq '') {
1709: $num = scalar(keys(%{$settings}));
1710: }
1711: $ordered{$num} = $item;
1712: }
1713: }
1714: }
1715: my $maxnum = scalar(keys(%ordered));
1716: if (keys(%ordered)) {
1717: my @items = sort { $a <=> $b } keys(%ordered);
1718: for (my $i=0; $i<@items; $i++) {
1719: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1720: my $item = $ordered{$items[$i]};
1721: my ($name,$ipranges,%commblocks,%courses);
1722: if (ref($settings->{$item}) eq 'HASH') {
1723: $name = $settings->{$item}->{'name'};
1724: $ipranges = $settings->{$item}->{'ip'};
1725: if (ref($settings->{$item}->{'commblocks'}) eq 'HASH') {
1726: %commblocks = %{$settings->{$item}->{'commblocks'}};
1727: }
1728: if (ref($settings->{$item}->{'courses'}) eq 'HASH') {
1729: %courses = %{$settings->{$item}->{'courses'}};
1730: }
1731: }
1732: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_".$item."'".');"';
1733: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1734: .'<select name="ipaccess_pos_'.$item.'"'.$chgstr.'>';
1735: for (my $k=0; $k<=$maxnum; $k++) {
1736: my $vpos = $k+1;
1737: my $selstr;
1738: if ($k == $i) {
1739: $selstr = ' selected="selected" ';
1740: }
1741: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1742: }
1743: $datatable .= '</select>'.(' 'x2).
1744: '<label><input type="checkbox" name="ipaccess_del" value="'.$item.'" />'.
1745: &mt('Delete?').'</label></span></td>'.
1746: '<td colspan="2"><input type="hidden" name="ipaccess_id_'.$i.'" value="'.$item.'" />'.
1747: &ipaccess_options($i,$itemcount,$dom,$name,$ipranges,\%commblocks,\%courses).
1748: '</td></tr>';
1749: $itemcount ++;
1750: }
1751: }
1752: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1753: my $chgstr = ' onchange="javascript:reorderIPaccess(this.form,'."'ipaccess_pos_add'".');"';
1754: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1755: '<input type="hidden" name="ipaccess_maxnum" value="'.$maxnum.'" />'."\n".
1756: '<select name="ipaccess_pos_add"'.$chgstr.'>';
1757: for (my $k=0; $k<$maxnum+1; $k++) {
1758: my $vpos = $k+1;
1759: my $selstr;
1760: if ($k == $maxnum) {
1761: $selstr = ' selected="selected" ';
1762: }
1763: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1764: }
1765: $datatable .= '</select> '."\n".
1766: '<input type="checkbox" name="ipaccess_add" value="1" />'.&mt('Add').'</span></td>'."\n".
1767: '<td colspan="2">'.
1768: &ipaccess_options('add',$itemcount,$dom).
1769: '</td>'."\n".
1770: '</tr>'."\n";
1771: $$rowtotal ++;
1772: return $datatable;
1773: }
1774:
1775: sub ipaccess_options {
1776: my ($num,$itemcount,$dom,$name,$ipranges,$blocksref,$coursesref) = @_;
1777: my (%currblocks,%currcourses,$output);
1778: if (ref($blocksref) eq 'HASH') {
1779: %currblocks = %{$blocksref};
1780: }
1781: if (ref($coursesref) eq 'HASH') {
1782: %currcourses = %{$coursesref};
1783: }
1784: $output = '<fieldset><legend>'.&mt('Location(s)').'</legend>'.
1785: '<span class="LC_nobreak">'.&mt('Name').': '.
1786: '<input type="text" name="ipaccess_name_'.$num.'" value="'.$name.'" />'.
1787: '</span></fieldset>'.
1788: '<fieldset><legend>'.&mt('IP Range(s)').'</legend>'.
1789: &mt('Format for each IP range').': '.&mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
1790: &mt('Range(s) will be stored as IP netblock(s) in CIDR notation (comma separated)').'<br />'.
1791: '<textarea name="ipaccess_range_'.$num.'" rows="3" cols="80">'.
1792: $ipranges.'</textarea></fieldset>'.
1793: '<fieldset><legend>'.&mt('Functionality Blocked?').'</legend>'.
1794: &blocker_checkboxes($num,$blocksref).'</fieldset>'.
1795: '<fieldset><legend>'.&mt('Courses/Communities allowed').'</legend>'.
1796: '<table>';
1797: foreach my $cid (sort(keys(%currcourses))) {
1798: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
1799: $output .= '<tr><td><span class="LC_nobreak">'.
1800: '<label><input type="checkbox" name="ipaccess_course_delete_'.$num.'" value="'.$cid.'" />'.
1801: &mt('Delete?').' <span class="LC_cusr_emph">'.$courseinfo{'description'}.'</span></label></span>'.
1802: ' <span class="LC_fontsize_medium">('.$cid.')</span></td></tr>';
1803: }
1804: $output .= '<tr><td><span class="LC_nobreak">'.&mt('Add').': '.
1805: '<input type="text" name="ipaccess_cdesc_'.$num.'" value="" onfocus="this.blur();opencrsbrowser('."'display','ipaccess_cnum_$num','ipaccess_cdom_$num','ipaccess_cdesc_$num'".');" />'.
1806: &Apache::loncommon::selectcourse_link('display','ipaccess_cnum_'.$num,'ipaccess_cdom_'.$num,'ipaccess_cdesc_'.$num,$dom,undef,'Course/Community').
1807: '<input type="hidden" name="ipaccess_cnum_'.$num.'" value="" />'.
1808: '<input type="hidden" name="ipaccess_cdom_'.$num.'" value="" />'.
1809: '</span></td></tr></table>'."\n".
1810: '</fieldset>';
1811: return $output;
1812: }
1813:
1814: sub blocker_checkboxes {
1815: my ($num,$blocks) = @_;
1816: my ($typeorder,$types) = &commblocktype_text();
1817: my $numinrow = 6;
1818: my $output = '<table>';
1819: for (my $i=0; $i<@{$typeorder}; $i++) {
1820: my $block = $typeorder->[$i];
1821: my $blockstatus;
1822: if (ref($blocks) eq 'HASH') {
1823: if ($blocks->{$block} eq 'on') {
1824: $blockstatus = 'checked="checked"';
1825: }
1826: }
1827: my $rem = $i%($numinrow);
1828: if ($rem == 0) {
1829: if ($i > 0) {
1830: $output .= '</tr>';
1831: }
1832: $output .= '<tr>';
1833: }
1834: if ($i == scalar(@{$typeorder})-1) {
1835: my $colsleft = $numinrow-$rem;
1836: if ($colsleft > 1) {
1837: $output .= '<td colspan="'.$colsleft.'">';
1838: } else {
1839: $output .= '<td>';
1840: }
1841: } else {
1842: $output .= '<td>';
1843: }
1844: my $item = 'ipaccess_block_'.$num;
1845: if ($blockstatus) {
1846: $blockstatus = ' '.$blockstatus;
1847: }
1848: $output .= '<span class="LC_nobreak"><label>'."\n".
1849: '<input type="checkbox" name="'.$item.'"'.
1850: $blockstatus.' value="'.$block.'"'.' />'.
1851: $types->{$block}.'</label></span>'."\n".
1852: '<br /></td>';
1853: }
1854: $output .= '</tr></table>';
1855: return $output;
1856: }
1857:
1858: sub commblocktype_text {
1859: my %types = &Apache::lonlocal::texthash(
1860: 'com' => 'Messaging',
1861: 'chat' => 'Chat Room',
1862: 'boards' => 'Discussion',
1863: 'port' => 'Portfolio',
1864: 'groups' => 'Groups',
1865: 'blogs' => 'Blogs',
1866: 'about' => 'User Information',
1867: 'printout' => 'Printouts',
1868: 'passwd' => 'Change Password',
1869: 'grades' => 'Gradebook',
1.160.6.115 raeburn 1870: 'search' => 'Course search',
1871: 'wishlist' => 'Stored links',
1872: 'annotate' => 'Annotations',
1.160.6.113 raeburn 1873: );
1.160.6.115 raeburn 1874: my $typeorder = ['com','chat','boards','port','groups','blogs','about','wishlist','printout','grades','search','annotate','passwd'];
1.160.6.113 raeburn 1875: return ($typeorder,\%types);
1876: }
1877:
1.6 raeburn 1878: sub print_rolecolors {
1.30 raeburn 1879: my ($phase,$role,$dom,$confname,$settings,$rowtotal) = @_;
1.6 raeburn 1880: my %choices = &color_font_choices();
1881: my @bgs = ('pgbg','tabbg','sidebg');
1882: my @links = ('link','alink','vlink');
1.160.6.118.2 26(raebu 1883:25): my @images = ();
1.6 raeburn 1884: my %alt_text = &Apache::lonlocal::texthash(img => "Banner for $role role");
1.7 albertel 1885: my %designhash = &Apache::loncommon::get_domainconf($dom);
1.6 raeburn 1886: my %defaultdesign = %Apache::loncommon::defaultdesign;
1887: my (%is_custom,%designs);
1.160.6.22 raeburn 1888: my %defaults = &role_defaults($role,\@bgs,\@links,\@images);
1.6 raeburn 1889: if (ref($settings) eq 'HASH') {
1890: if (ref($settings->{$role}) eq 'HASH') {
1891: if ($settings->{$role}->{'font'} ne '') {
1892: $designs{'font'} = $settings->{$role}->{'font'};
1893: $is_custom{'font'} = 1;
1894: }
1.97 tempelho 1895: if ($settings->{$role}->{'fontmenu'} ne '') {
1896: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1897: $is_custom{'fontmenu'} = 1;
1898: }
1.6 raeburn 1899: foreach my $item (@bgs) {
1900: if ($settings->{$role}->{$item} ne '') {
1901: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1902: $is_custom{$item} = 1;
1903: }
1904: }
1905: foreach my $item (@links) {
1906: if ($settings->{$role}->{$item} ne '') {
1907: $designs{'links'}{$item} = $settings->{$role}->{$item};
1908: $is_custom{$item} = 1;
1909: }
1910: }
1911: }
1912: } else {
1.97 tempelho 1913: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1914: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1915: $is_custom{'fontmenu'} = 1;
1916: }
1.6 raeburn 1917: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1918: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1919: $is_custom{'font'} = 1;
1920: }
1921: foreach my $item (@bgs) {
1922: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1923: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1924: $is_custom{$item} = 1;
1925:
1926: }
1927: }
1928: foreach my $item (@links) {
1929: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1930: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1931: $is_custom{$item} = 1;
1932: }
1933: }
1934: }
1935: my $itemcount = 1;
1.30 raeburn 1936: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1937: $datatable .= '</tr></table></td></tr>';
1938: return $datatable;
1939: }
1940:
1.160.6.22 raeburn 1941: sub role_defaults {
1942: my ($role,$bgs,$links,$images,$logintext) = @_;
1943: my %defaults;
1944: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1945: return %defaults;
1946: }
1947: my %defaultdesign = %Apache::loncommon::defaultdesign;
1948: if ($role eq 'login') {
1949: %defaults = (
1950: font => $defaultdesign{$role.'.font'},
1951: );
1952: if (ref($logintext) eq 'ARRAY') {
1953: foreach my $item (@{$logintext}) {
1954: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1955: }
1956: }
1957: foreach my $item (@{$images}) {
1958: $defaults{'showlogo'}{$item} = 1;
1959: }
1960: } else {
1961: %defaults = (
1962: font => $defaultdesign{$role.'.font'},
1963: fontmenu => $defaultdesign{$role.'.fontmenu'},
1964: );
1965: }
1966: foreach my $item (@{$bgs}) {
1967: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1968: }
1969: foreach my $item (@{$links}) {
1970: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1971: }
1972: foreach my $item (@{$images}) {
1973: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1974: }
1975: return %defaults;
1976: }
1977:
1.6 raeburn 1978: sub display_color_options {
1.9 raeburn 1979: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1980: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1981: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1982: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1983: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1984: '<td>'.$choices->{'font'}.'</td>';
1985: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1986: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1987: } else {
1988: $datatable .= '<td> </td>';
1989: }
1.160.6.9 raeburn 1990: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
1991:
1.8 raeburn 1992: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 1993: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
1994: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 1995: ' </span></td></tr>';
1.107 raeburn 1996: unless ($role eq 'login') {
1997: $datatable .= '<tr'.$css_class.'>'.
1998: '<td>'.$choices->{'fontmenu'}.'</td>';
1999: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 2000: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2001: } else {
2002: $datatable .= '<td> </td>';
2003: }
1.160.6.22 raeburn 2004: $current_color = $designs->{'fontmenu'} ?
2005: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2006: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 2007: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 2008: .$role.'_fontmenu"'.
1.160.6.9 raeburn 2009: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 2010: ' </span></td></tr>';
1.97 tempelho 2011: }
1.9 raeburn 2012: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2013: foreach my $img (@{$images}) {
1.18 albertel 2014: $itemcount ++;
1.6 raeburn 2015: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2016: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2017: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 2018:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2019: if ($role eq 'login') {
2020: if ($img eq 'login') {
2021: $login_hdr_pick =
1.135 bisitz 2022: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2023: $logincolors =
2024: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 2025: $designs,$defaults);
1.160.6.118.2 2(raebur 2026:2): } else {
2027:2): if ($img ne 'domlogo') {
2028:2): $datatable.= &logo_display_options($img,$defaults,$designs);
2029:2): }
2030:2): if (ref($designs->{'alttext'}) eq 'HASH') {
2031:2): $alttext = $designs->{'alttext'}{$img};
2032:2): }
1.70 raeburn 2033: }
2034: }
2035: $datatable .= '</td>';
1.6 raeburn 2036: if ($designs->{$img} ne '') {
2037: $imgfile = $designs->{$img};
1.18 albertel 2038: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2039: } else {
2040: $imgfile = $defaults->{$img};
2041: }
2042: if ($imgfile) {
1.9 raeburn 2043: my ($showfile,$fullsize);
2044: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2045: my $urldir = $1;
2046: my $filename = $2;
2047: my @info = &Apache::lonnet::stat_file($designs->{$img});
2048: if (@info) {
2049: my $thumbfile = 'tn-'.$filename;
2050: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2051: if (@thumb) {
2052: $showfile = $urldir.'/'.$thumbfile;
2053: } else {
2054: $showfile = $imgfile;
2055: }
2056: } else {
2057: $showfile = '';
2058: }
2059: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2060: $showfile = $imgfile;
1.6 raeburn 2061: my $imgdir = $1;
2062: my $filename = $2;
1.159 raeburn 2063: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2064: $showfile = "/$imgdir/tn-".$filename;
2065: } else {
1.159 raeburn 2066: my $input = $londocroot.$imgfile;
2067: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2068: if (!-e $output) {
1.9 raeburn 2069: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2070: my ($fullwidth,$fullheight) = &check_dimensions($input);
2071: if ($fullwidth ne '' && $fullheight ne '') {
2072: if ($fullwidth > $width && $fullheight > $height) {
2073: my $size = $width.'x'.$height;
1.160.6.88 raeburn 2074: my @args = ('convert','-sample',$size,$input,$output);
2075: system({$args[0]} @args);
1.159 raeburn 2076: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2077: }
2078: }
1.6 raeburn 2079: }
2080: }
1.16 raeburn 2081: }
1.6 raeburn 2082: if ($showfile) {
1.40 raeburn 2083: if ($showfile =~ m{^/(adm|res)/}) {
2084: if ($showfile =~ m{^/res/}) {
2085: my $local_showfile =
2086: &Apache::lonnet::filelocation('',$showfile);
2087: &Apache::lonnet::repcopy($local_showfile);
2088: }
2089: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2090: }
2091: if ($imgfile) {
2092: if ($imgfile =~ m{^/(adm|res)/}) {
2093: if ($imgfile =~ m{^/res/}) {
2094: my $local_imgfile =
2095: &Apache::lonnet::filelocation('',$imgfile);
2096: &Apache::lonnet::repcopy($local_imgfile);
2097: }
2098: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2099: } else {
2100: $fullsize = $imgfile;
2101: }
2102: }
1.41 raeburn 2103: $datatable .= '<td>';
2104: if ($img eq 'login') {
1.135 bisitz 2105: $datatable .= $login_hdr_pick;
2106: }
1.41 raeburn 2107: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2108: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2109: } else {
1.160.6.22 raeburn 2110: $datatable .= '<td> </td><td class="LC_left_item">'.
2111: &mt('Upload:').'<br />';
1.6 raeburn 2112: }
2113: } else {
1.160.6.22 raeburn 2114: $datatable .= '<td> </td><td class="LC_left_item">'.
2115: &mt('Upload:').'<br />';
1.6 raeburn 2116: }
1.9 raeburn 2117: if ($switchserver) {
2118: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2119: } else {
1.135 bisitz 2120: if ($img ne 'login') { # suppress file selection for Log-in header
2121: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2122: }
1.9 raeburn 2123: }
1.160.6.118.2 2(raebur 2124:2): if (($role eq 'login') && ($img ne 'login')) {
2125:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2126:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2127:2): '</label></span>';
2128:2): }
1.9 raeburn 2129: $datatable .= '</td></tr>';
1.6 raeburn 2130: }
2131: $itemcount ++;
2132: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2133: $datatable .= '<tr'.$css_class.'>'.
2134: '<td>'.$choices->{'bgs'}.'</td>';
2135: my $bgs_def;
2136: foreach my $item (@{$bgs}) {
2137: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2138: $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 2139: }
2140: }
2141: if ($bgs_def) {
1.8 raeburn 2142: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2143: } else {
2144: $datatable .= '<td> </td>';
2145: }
2146: $datatable .= '<td class="LC_right_item">'.
2147: '<table border="0"><tr>';
1.160.6.13 raeburn 2148:
1.6 raeburn 2149: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2150: $datatable .= '<td align="center">'.$choices->{$item};
2151: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2152: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2153: $datatable .= ' ';
1.6 raeburn 2154: }
1.160.6.9 raeburn 2155: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2156: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2157: }
2158: $datatable .= '</tr></table></td></tr>';
2159: $itemcount ++;
2160: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2161: $datatable .= '<tr'.$css_class.'>'.
2162: '<td>'.$choices->{'links'}.'</td>';
2163: my $links_def;
2164: foreach my $item (@{$links}) {
2165: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2166: $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 2167: }
2168: }
2169: if ($links_def) {
1.8 raeburn 2170: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2171: } else {
2172: $datatable .= '<td> </td>';
2173: }
2174: $datatable .= '<td class="LC_right_item">'.
2175: '<table border="0"><tr>';
2176: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2177: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2178: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2179: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2180: $datatable.=' ';
1.6 raeburn 2181: }
1.160.6.9 raeburn 2182: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2183: '" /></td>';
2184: }
1.30 raeburn 2185: $$rowtotal += $itemcount;
1.3 raeburn 2186: return $datatable;
2187: }
2188:
1.70 raeburn 2189: sub logo_display_options {
2190: my ($img,$defaults,$designs) = @_;
2191: my $checkedon;
2192: if (ref($defaults) eq 'HASH') {
2193: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2194: if ($defaults->{'showlogo'}{$img}) {
2195: $checkedon = 'checked="checked" ';
2196: }
2197: }
2198: }
2199: if (ref($designs) eq 'HASH') {
2200: if (ref($designs->{'showlogo'}) eq 'HASH') {
2201: if (defined($designs->{'showlogo'}{$img})) {
2202: if ($designs->{'showlogo'}{$img} == 0) {
2203: $checkedon = '';
2204: } elsif ($designs->{'showlogo'}{$img} == 1) {
2205: $checkedon = 'checked="checked" ';
2206: }
2207: }
2208: }
2209: }
2210: return '<br /><label> <input type="checkbox" name="'.
2211: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2212: &mt('show').'</label>'."\n";
2213: }
2214:
1.41 raeburn 2215: sub login_header_options {
1.135 bisitz 2216: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2217: my $output = '';
1.41 raeburn 2218: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2219: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2220: if (!$is_custom->{'textcol'}) {
2221: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2222: ' ';
2223: }
2224: if (!$is_custom->{'bgcol'}) {
2225: $output .= $choices->{'bgcol'}.': '.
2226: '<span id="css_'.$role.'_font" style="background-color: '.
2227: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2228: }
2229: $output .= '<br />';
2230: }
2231: $output .='<br />';
2232: return $output;
2233: }
2234:
2235: sub login_text_colors {
1.160.6.22 raeburn 2236: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2237: my $color_menu = '<table border="0"><tr>';
2238: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2239: $color_menu .= '<td align="center">'.$choices->{$item};
2240: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2241: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2242: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2243: }
2244: $color_menu .= '</tr></table><br />';
2245: return $color_menu;
2246: }
2247:
2248: sub image_changes {
2249: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2250: my $output;
1.135 bisitz 2251: if ($img eq 'login') {
1.160.6.87 raeburn 2252: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2253: } elsif (!$is_custom) {
1.70 raeburn 2254: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2255: $output = &mt('Default image:').'<br />';
1.41 raeburn 2256: } else {
1.160.6.87 raeburn 2257: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2258: }
2259: }
1.160.6.87 raeburn 2260: if ($img ne 'login') {
1.135 bisitz 2261: if ($img_import) {
2262: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2263: }
2264: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2265: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2266: if ($is_custom) {
2267: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2268: '<input type="checkbox" name="'.
2269: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2270: '</label> '.&mt('Replace:').'</span><br />';
2271: } else {
1.160.6.22 raeburn 2272: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2273: }
1.41 raeburn 2274: }
2275: return $output;
2276: }
2277:
1.3 raeburn 2278: sub print_quotas {
1.86 raeburn 2279: my ($dom,$settings,$rowtotal,$action) = @_;
2280: my $context;
2281: if ($action eq 'quotas') {
2282: $context = 'tools';
2283: } else {
2284: $context = $action;
2285: }
1.160.6.118.2 20(raebu 2286:24): my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2287: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2288: my $typecount = 0;
1.101 raeburn 2289: my ($css_class,%titles);
1.86 raeburn 2290: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 2291:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 2292: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2293: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2294: %titles = &courserequest_titles();
1.160.6.5 raeburn 2295: } elsif ($context eq 'requestauthor') {
2296: @usertools = ('author');
2297: @options = ('norequest','approval','automatic');
2298: %titles = &authorrequest_titles();
1.86 raeburn 2299: } else {
1.160.6.118.2 23(raebu 2300:24): @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2301: %titles = &tool_titles();
1.86 raeburn 2302: }
1.26 raeburn 2303: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2304: foreach my $type (@{$types}) {
1.160.6.118.2 20(raebu 2305:24): my $currdefquota;
1.160.6.5 raeburn 2306: unless (($context eq 'requestcourses') ||
2307: ($context eq 'requestauthor')) {
1.86 raeburn 2308: if (ref($settings) eq 'HASH') {
2309: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2310: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2311: } else {
2312: $currdefquota = $settings->{$type};
2313: }
1.78 raeburn 2314: }
1.72 raeburn 2315: }
1.3 raeburn 2316: if (defined($usertypes->{$type})) {
2317: $typecount ++;
2318: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2319: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2320: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2321: '<td class="LC_left_item">';
1.101 raeburn 2322: if ($context eq 'requestcourses') {
2323: $datatable .= '<table><tr>';
2324: }
2325: my %cell;
1.72 raeburn 2326: foreach my $item (@usertools) {
1.101 raeburn 2327: if ($context eq 'requestcourses') {
2328: my ($curroption,$currlimit);
2329: if (ref($settings) eq 'HASH') {
2330: if (ref($settings->{$item}) eq 'HASH') {
2331: $curroption = $settings->{$item}->{$type};
2332: if ($curroption =~ /^autolimit=(\d*)$/) {
2333: $currlimit = $1;
2334: }
2335: }
2336: }
2337: if (!$curroption) {
2338: $curroption = 'norequest';
2339: }
2340: $datatable .= '<th>'.$titles{$item}.'</th>';
2341: foreach my $option (@options) {
2342: my $val = $option;
2343: if ($option eq 'norequest') {
2344: $val = 0;
2345: }
2346: if ($option eq 'validate') {
2347: my $canvalidate = 0;
2348: if (ref($validations{$item}) eq 'HASH') {
2349: if ($validations{$item}{$type}) {
2350: $canvalidate = 1;
2351: }
2352: }
2353: next if (!$canvalidate);
2354: }
2355: my $checked = '';
2356: if ($option eq $curroption) {
2357: $checked = ' checked="checked"';
2358: } elsif ($option eq 'autolimit') {
2359: if ($curroption =~ /^autolimit/) {
2360: $checked = ' checked="checked"';
2361: }
2362: }
2363: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2364: '<input type="radio" name="crsreq_'.$item.
2365: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2366: $titles{$option}.'</label>';
1.101 raeburn 2367: if ($option eq 'autolimit') {
1.127 raeburn 2368: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2369: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2370: 'value="'.$currlimit.'" />';
1.101 raeburn 2371: }
1.127 raeburn 2372: $cell{$item} .= '</span> ';
1.103 raeburn 2373: if ($option eq 'autolimit') {
1.127 raeburn 2374: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2375: }
1.101 raeburn 2376: }
1.160.6.5 raeburn 2377: } elsif ($context eq 'requestauthor') {
2378: my $curroption;
2379: if (ref($settings) eq 'HASH') {
2380: $curroption = $settings->{$type};
2381: }
2382: if (!$curroption) {
2383: $curroption = 'norequest';
2384: }
2385: foreach my $option (@options) {
2386: my $val = $option;
2387: if ($option eq 'norequest') {
2388: $val = 0;
2389: }
2390: my $checked = '';
2391: if ($option eq $curroption) {
2392: $checked = ' checked="checked"';
2393: }
2394: $datatable .= '<span class="LC_nobreak"><label>'.
2395: '<input type="radio" name="authorreq_'.$type.
2396: '" value="'.$val.'"'.$checked.' />'.
2397: $titles{$option}.'</label></span> ';
2398: }
1.101 raeburn 2399: } else {
2400: my $checked = 'checked="checked" ';
1.160.6.118.2 10(raebu 2401:22): if ($item eq 'timezone') {
2402:22): $checked = '';
2403:22): }
1.101 raeburn 2404: if (ref($settings) eq 'HASH') {
2405: if (ref($settings->{$item}) eq 'HASH') {
1.160.6.118.2 10(raebu 2406:22): if (!$settings->{$item}->{$type}) {
1.101 raeburn 2407: $checked = '';
2408: } elsif ($settings->{$item}->{$type} == 1) {
2409: $checked = 'checked="checked" ';
2410: }
1.78 raeburn 2411: }
1.72 raeburn 2412: }
1.101 raeburn 2413: $datatable .= '<span class="LC_nobreak"><label>'.
2414: '<input type="checkbox" name="'.$context.'_'.$item.
2415: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2416: '</label></span> ';
1.72 raeburn 2417: }
1.101 raeburn 2418: }
2419: if ($context eq 'requestcourses') {
2420: $datatable .= '</tr><tr>';
2421: foreach my $item (@usertools) {
1.106 raeburn 2422: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2423: }
2424: $datatable .= '</tr></table>';
1.72 raeburn 2425: }
1.86 raeburn 2426: $datatable .= '</td>';
1.160.6.5 raeburn 2427: unless (($context eq 'requestcourses') ||
2428: ($context eq 'requestauthor')) {
1.86 raeburn 2429: $datatable .=
1.160.6.20 raeburn 2430: '<td class="LC_right_item">'.
1.160.6.118.2 20(raebu 2431:24): '<span class="LC_nobreak">'.
1.3 raeburn 2432: '<input type="text" name="quota_'.$type.
1.72 raeburn 2433: '" value="'.$currdefquota.
1.160.6.20 raeburn 2434: '" size="5" /></span></td>';
1.86 raeburn 2435: }
2436: $datatable .= '</tr>';
1.3 raeburn 2437: }
2438: }
2439: }
1.160.6.5 raeburn 2440: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2441: $defaultquota = '20';
2442: if (ref($settings) eq 'HASH') {
2443: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2444: $defaultquota = $settings->{'defaultquota'}->{'default'};
2445: } elsif (defined($settings->{'default'})) {
2446: $defaultquota = $settings->{'default'};
2447: }
1.3 raeburn 2448: }
2449: }
2450: $typecount ++;
2451: $css_class = $typecount%2?' class="LC_odd_row"':'';
2452: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2453: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2454: '<td class="LC_left_item">';
1.101 raeburn 2455: if ($context eq 'requestcourses') {
2456: $datatable .= '<table><tr>';
2457: }
2458: my %defcell;
1.72 raeburn 2459: foreach my $item (@usertools) {
1.101 raeburn 2460: if ($context eq 'requestcourses') {
2461: my ($curroption,$currlimit);
2462: if (ref($settings) eq 'HASH') {
2463: if (ref($settings->{$item}) eq 'HASH') {
2464: $curroption = $settings->{$item}->{'default'};
2465: if ($curroption =~ /^autolimit=(\d*)$/) {
2466: $currlimit = $1;
2467: }
2468: }
2469: }
2470: if (!$curroption) {
2471: $curroption = 'norequest';
2472: }
2473: $datatable .= '<th>'.$titles{$item}.'</th>';
2474: foreach my $option (@options) {
2475: my $val = $option;
2476: if ($option eq 'norequest') {
2477: $val = 0;
2478: }
2479: if ($option eq 'validate') {
2480: my $canvalidate = 0;
2481: if (ref($validations{$item}) eq 'HASH') {
2482: if ($validations{$item}{'default'}) {
2483: $canvalidate = 1;
2484: }
2485: }
2486: next if (!$canvalidate);
2487: }
2488: my $checked = '';
2489: if ($option eq $curroption) {
2490: $checked = ' checked="checked"';
2491: } elsif ($option eq 'autolimit') {
2492: if ($curroption =~ /^autolimit/) {
2493: $checked = ' checked="checked"';
2494: }
2495: }
2496: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2497: '<input type="radio" name="crsreq_'.$item.
2498: '_default" value="'.$val.'"'.$checked.' />'.
2499: $titles{$option}.'</label>';
2500: if ($option eq 'autolimit') {
1.127 raeburn 2501: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2502: $item.'_limit_default" size="1" '.
2503: 'value="'.$currlimit.'" />';
2504: }
1.127 raeburn 2505: $defcell{$item} .= '</span> ';
1.104 raeburn 2506: if ($option eq 'autolimit') {
1.127 raeburn 2507: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2508: }
1.101 raeburn 2509: }
1.160.6.5 raeburn 2510: } elsif ($context eq 'requestauthor') {
2511: my $curroption;
2512: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2513: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2514: }
2515: if (!$curroption) {
2516: $curroption = 'norequest';
2517: }
2518: foreach my $option (@options) {
2519: my $val = $option;
2520: if ($option eq 'norequest') {
2521: $val = 0;
2522: }
2523: my $checked = '';
2524: if ($option eq $curroption) {
2525: $checked = ' checked="checked"';
2526: }
2527: $datatable .= '<span class="LC_nobreak"><label>'.
2528: '<input type="radio" name="authorreq_default"'.
2529: ' value="'.$val.'"'.$checked.' />'.
2530: $titles{$option}.'</label></span> ';
2531: }
1.101 raeburn 2532: } else {
2533: my $checked = 'checked="checked" ';
2534: if (ref($settings) eq 'HASH') {
2535: if (ref($settings->{$item}) eq 'HASH') {
2536: if ($settings->{$item}->{'default'} == 0) {
2537: $checked = '';
2538: } elsif ($settings->{$item}->{'default'} == 1) {
2539: $checked = 'checked="checked" ';
2540: }
1.78 raeburn 2541: }
1.72 raeburn 2542: }
1.101 raeburn 2543: $datatable .= '<span class="LC_nobreak"><label>'.
2544: '<input type="checkbox" name="'.$context.'_'.$item.
2545: '" value="default" '.$checked.'/>'.$titles{$item}.
2546: '</label></span> ';
2547: }
2548: }
2549: if ($context eq 'requestcourses') {
2550: $datatable .= '</tr><tr>';
2551: foreach my $item (@usertools) {
1.106 raeburn 2552: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2553: }
1.101 raeburn 2554: $datatable .= '</tr></table>';
1.72 raeburn 2555: }
1.86 raeburn 2556: $datatable .= '</td>';
1.160.6.5 raeburn 2557: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2558: $datatable .= '<td class="LC_right_item">'.
1.160.6.118.2 20(raebu 2559:24): '<span class="LC_nobreak">'.
1.86 raeburn 2560: '<input type="text" name="defaultquota" value="'.
1.160.6.118.2 20(raebu 2561:24): $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2562: }
2563: $datatable .= '</tr>';
1.72 raeburn 2564: $typecount ++;
2565: $css_class = $typecount%2?' class="LC_odd_row"':'';
2566: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2567: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2568: if ($context eq 'requestcourses') {
1.109 raeburn 2569: $datatable .= &mt('(overrides affiliation, if set)').
2570: '</td>'.
2571: '<td class="LC_left_item">'.
2572: '<table><tr>';
1.101 raeburn 2573: } else {
1.109 raeburn 2574: $datatable .= &mt('(overrides affiliation, if checked)').
2575: '</td>'.
2576: '<td class="LC_left_item" colspan="2">'.
2577: '<br />';
1.101 raeburn 2578: }
2579: my %advcell;
1.72 raeburn 2580: foreach my $item (@usertools) {
1.101 raeburn 2581: if ($context eq 'requestcourses') {
2582: my ($curroption,$currlimit);
2583: if (ref($settings) eq 'HASH') {
2584: if (ref($settings->{$item}) eq 'HASH') {
2585: $curroption = $settings->{$item}->{'_LC_adv'};
2586: if ($curroption =~ /^autolimit=(\d*)$/) {
2587: $currlimit = $1;
2588: }
2589: }
2590: }
2591: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2592: my $checked = '';
2593: if ($curroption eq '') {
2594: $checked = ' checked="checked"';
2595: }
2596: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2597: '<input type="radio" name="crsreq_'.$item.
2598: '__LC_adv" value=""'.$checked.' />'.
2599: &mt('No override set').'</label></span> ';
1.101 raeburn 2600: foreach my $option (@options) {
2601: my $val = $option;
2602: if ($option eq 'norequest') {
2603: $val = 0;
2604: }
2605: if ($option eq 'validate') {
2606: my $canvalidate = 0;
2607: if (ref($validations{$item}) eq 'HASH') {
2608: if ($validations{$item}{'_LC_adv'}) {
2609: $canvalidate = 1;
2610: }
2611: }
2612: next if (!$canvalidate);
2613: }
2614: my $checked = '';
1.104 raeburn 2615: if ($val eq $curroption) {
1.101 raeburn 2616: $checked = ' checked="checked"';
2617: } elsif ($option eq 'autolimit') {
2618: if ($curroption =~ /^autolimit/) {
2619: $checked = ' checked="checked"';
2620: }
2621: }
2622: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2623: '<input type="radio" name="crsreq_'.$item.
2624: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2625: $titles{$option}.'</label>';
2626: if ($option eq 'autolimit') {
1.127 raeburn 2627: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2628: $item.'_limit__LC_adv" size="1" '.
2629: 'value="'.$currlimit.'" />';
2630: }
1.127 raeburn 2631: $advcell{$item} .= '</span> ';
1.104 raeburn 2632: if ($option eq 'autolimit') {
1.127 raeburn 2633: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2634: }
1.101 raeburn 2635: }
1.160.6.5 raeburn 2636: } elsif ($context eq 'requestauthor') {
2637: my $curroption;
2638: if (ref($settings) eq 'HASH') {
2639: $curroption = $settings->{'_LC_adv'};
2640: }
2641: my $checked = '';
2642: if ($curroption eq '') {
2643: $checked = ' checked="checked"';
2644: }
2645: $datatable .= '<span class="LC_nobreak"><label>'.
2646: '<input type="radio" name="authorreq__LC_adv"'.
2647: ' value=""'.$checked.' />'.
2648: &mt('No override set').'</label></span> ';
2649: foreach my $option (@options) {
2650: my $val = $option;
2651: if ($option eq 'norequest') {
2652: $val = 0;
2653: }
2654: my $checked = '';
2655: if ($val eq $curroption) {
2656: $checked = ' checked="checked"';
2657: }
2658: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2659: '<input type="radio" name="authorreq__LC_adv"'.
2660: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2661: $titles{$option}.'</label></span> ';
2662: }
1.101 raeburn 2663: } else {
2664: my $checked = 'checked="checked" ';
2665: if (ref($settings) eq 'HASH') {
2666: if (ref($settings->{$item}) eq 'HASH') {
2667: if ($settings->{$item}->{'_LC_adv'} == 0) {
2668: $checked = '';
2669: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2670: $checked = 'checked="checked" ';
2671: }
1.79 raeburn 2672: }
1.72 raeburn 2673: }
1.101 raeburn 2674: $datatable .= '<span class="LC_nobreak"><label>'.
2675: '<input type="checkbox" name="'.$context.'_'.$item.
2676: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2677: '</label></span> ';
2678: }
2679: }
2680: if ($context eq 'requestcourses') {
2681: $datatable .= '</tr><tr>';
2682: foreach my $item (@usertools) {
1.106 raeburn 2683: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2684: }
1.101 raeburn 2685: $datatable .= '</tr></table>';
1.72 raeburn 2686: }
1.98 raeburn 2687: $datatable .= '</td></tr>';
1.30 raeburn 2688: $$rowtotal += $typecount;
1.3 raeburn 2689: return $datatable;
2690: }
2691:
1.160.6.5 raeburn 2692: sub print_requestmail {
1.160.6.93 raeburn 2693: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2694: my ($now,$datatable,%currapp);
1.102 raeburn 2695: $now = time;
2696: if (ref($settings) eq 'HASH') {
2697: if (ref($settings->{'notify'}) eq 'HASH') {
2698: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2699: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2700: }
2701: }
2702: }
1.160.6.16 raeburn 2703: my $numinrow = 2;
1.160.6.34 raeburn 2704: my $css_class;
1.160.6.93 raeburn 2705: if ($$rowtotal%2) {
2706: $css_class = 'LC_odd_row';
2707: }
2708: if ($customcss) {
2709: $css_class .= " $customcss";
2710: }
2711: $css_class =~ s/^\s+//;
2712: if ($css_class) {
2713: $css_class = ' class="'.$css_class.'"';
2714: }
2715: if ($rowstyle) {
2716: $css_class .= ' style="'.$rowstyle.'"';
2717: }
1.160.6.5 raeburn 2718: my $text;
2719: if ($action eq 'requestcourses') {
2720: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2721: } elsif ($action eq 'requestauthor') {
2722: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2723: } else {
1.160.6.34 raeburn 2724: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2725: }
1.160.6.34 raeburn 2726: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2727: ' <td>'.$text.'</td>'.
1.102 raeburn 2728: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2729: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2730: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2731: if ($numdc > 0) {
2732: $datatable .= $table;
1.102 raeburn 2733: } else {
2734: $datatable .= &mt('There are no active Domain Coordinators');
2735: }
2736: $datatable .='</td></tr>';
2737: return $datatable;
2738: }
2739:
1.160.6.30 raeburn 2740: sub print_studentcode {
2741: my ($settings,$rowtotal) = @_;
2742: my $rownum = 0;
2743: my ($output,%current);
1.160.6.118.2 14(raebu 2744:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.51 raeburn 2745: if (ref($settings) eq 'HASH') {
2746: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2747: foreach my $type (@crstypes) {
2748: $current{$type} = $settings->{'uniquecode'}{$type};
2749: }
1.160.6.30 raeburn 2750: }
2751: }
2752: $output .= '<tr>'.
2753: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2754: '<td class="LC_left_item">';
2755: foreach my $type (@crstypes) {
2756: my $check = ' ';
2757: if ($current{$type}) {
2758: $check = ' checked="checked" ';
2759: }
2760: $output .= '<span class="LC_nobreak"><label>'.
2761: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2762: &mt($type).'</label></span>'.(' 'x2).' ';
2763: }
2764: $output .= '</td></tr>';
2765: $$rowtotal ++;
2766: return $output;
2767: }
2768:
2769: sub print_textbookcourses {
1.160.6.46 raeburn 2770: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2771: my $rownum = 0;
2772: my $css_class;
2773: my $itemcount = 1;
2774: my $maxnum = 0;
2775: my $bookshash;
2776: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2777: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2778: }
2779: my %ordered;
2780: if (ref($bookshash) eq 'HASH') {
2781: foreach my $item (keys(%{$bookshash})) {
2782: if (ref($bookshash->{$item}) eq 'HASH') {
2783: my $num = $bookshash->{$item}{'order'};
2784: $ordered{$num} = $item;
2785: }
2786: }
2787: }
2788: my $confname = $dom.'-domainconfig';
2789: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2790: my $maxnum = scalar(keys(%ordered));
2791: my $datatable;
1.160.6.30 raeburn 2792: if (keys(%ordered)) {
2793: my @items = sort { $a <=> $b } keys(%ordered);
2794: for (my $i=0; $i<@items; $i++) {
2795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2796: my $key = $ordered{$items[$i]};
2797: my %coursehash=&Apache::lonnet::coursedescription($key);
2798: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2799: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2800: if (ref($bookshash->{$key}) eq 'HASH') {
2801: $subject = $bookshash->{$key}->{'subject'};
2802: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2803: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2804: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2805: $author = $bookshash->{$key}->{'author'};
2806: $image = $bookshash->{$key}->{'image'};
2807: if ($image ne '') {
2808: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2809: my $imagethumb = "$path/tn-".$imagefile;
2810: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2811: }
1.160.6.30 raeburn 2812: }
2813: }
1.160.6.46 raeburn 2814: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2815: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2816: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2817: for (my $k=0; $k<=$maxnum; $k++) {
2818: my $vpos = $k+1;
2819: my $selstr;
2820: if ($k == $i) {
2821: $selstr = ' selected="selected" ';
2822: }
2823: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2824: }
2825: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2826: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2827: &mt('Delete?').'</label></span></td>'.
2828: '<td colspan="2">'.
1.160.6.46 raeburn 2829: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2830: (' 'x2).
1.160.6.46 raeburn 2831: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2832: if ($type eq 'textbooks') {
2833: $datatable .= (' 'x2).
1.160.6.47 raeburn 2834: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2835: (' 'x2).
1.160.6.46 raeburn 2836: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2837: (' 'x2).
2838: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2839: if ($image) {
1.160.6.114 raeburn 2840: $datatable .= $imgsrc.
1.160.6.46 raeburn 2841: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2842: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2843: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2844: }
2845: if ($switchserver) {
2846: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2847: } else {
2848: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2849: }
1.160.6.30 raeburn 2850: }
1.160.6.46 raeburn 2851: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2852: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2853: $coursetitle.'</span></td></tr>'."\n";
2854: $itemcount ++;
2855: }
2856: }
2857: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2858: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2859: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2860: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2861: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2862: for (my $k=0; $k<$maxnum+1; $k++) {
2863: my $vpos = $k+1;
2864: my $selstr;
2865: if ($k == $maxnum) {
2866: $selstr = ' selected="selected" ';
2867: }
2868: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2869: }
2870: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2871: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2872: '<td colspan="2">'.
1.160.6.46 raeburn 2873: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2874: (' 'x2).
1.160.6.46 raeburn 2875: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2876: (' 'x2);
2877: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2878: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2879: (' 'x2).
2880: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2881: (' 'x2).
2882: '<span class="LC_nobreak">'.&mt('Image:').' ';
2883: if ($switchserver) {
2884: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2885: } else {
2886: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2887: }
1.160.6.87 raeburn 2888: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2889: }
1.160.6.87 raeburn 2890: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2891: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2892: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2893: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2894: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2895: '</span></td>'."\n".
2896: '</tr>'."\n";
2897: $itemcount ++;
2898: return $datatable;
2899: }
2900:
2901: sub textbookcourses_javascript {
1.160.6.46 raeburn 2902: my ($settings) = @_;
2903: return unless(ref($settings) eq 'HASH');
2904: my (%ordered,%total,%jstext);
2905: foreach my $type ('textbooks','templates') {
2906: $total{$type} = 0;
2907: if (ref($settings->{$type}) eq 'HASH') {
2908: foreach my $item (keys(%{$settings->{$type}})) {
2909: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2910: my $num = $settings->{$type}->{$item}{'order'};
2911: $ordered{$type}{$num} = $item;
2912: }
2913: }
2914: $total{$type} = scalar(keys(%{$settings->{$type}}));
2915: }
2916: my @jsarray = ();
2917: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2918: push(@jsarray,$ordered{$type}{$item});
2919: }
2920: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2921: }
2922: return <<"ENDSCRIPT";
2923: <script type="text/javascript">
2924: // <![CDATA[
1.160.6.46 raeburn 2925: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2926: var changedVal;
1.160.6.46 raeburn 2927: $jstext{'textbooks'};
2928: $jstext{'templates'};
2929: var newpos;
2930: var maxh;
2931: if (caller == 'textbooks') {
2932: newpos = 'textbooks_addbook_pos';
2933: maxh = 1 + $total{'textbooks'};
2934: } else {
2935: newpos = 'templates_addbook_pos';
2936: maxh = 1 + $total{'templates'};
2937: }
1.160.6.30 raeburn 2938: var current = new Array;
2939: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2940: if (item == newpos) {
2941: changedVal = newitemVal;
2942: } else {
2943: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2944: current[newitemVal] = newpos;
2945: }
1.160.6.46 raeburn 2946: if (caller == 'textbooks') {
2947: for (var i=0; i<textbooks.length; i++) {
2948: var elementName = 'textbooks_'+textbooks[i];
2949: if (elementName != item) {
2950: if (form.elements[elementName]) {
2951: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2952: current[currVal] = elementName;
2953: }
2954: }
2955: }
2956: }
2957: if (caller == 'templates') {
2958: for (var i=0; i<templates.length; i++) {
2959: var elementName = 'templates_'+templates[i];
2960: if (elementName != item) {
2961: if (form.elements[elementName]) {
2962: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2963: current[currVal] = elementName;
2964: }
1.160.6.30 raeburn 2965: }
2966: }
2967: }
2968: var oldVal;
2969: for (var j=0; j<maxh; j++) {
2970: if (current[j] == undefined) {
2971: oldVal = j;
2972: }
2973: }
2974: if (oldVal < changedVal) {
2975: for (var k=oldVal+1; k<=changedVal ; k++) {
2976: var elementName = current[k];
2977: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2978: }
2979: } else {
2980: for (var k=changedVal; k<oldVal; k++) {
2981: var elementName = current[k];
2982: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2983: }
2984: }
2985: return;
2986: }
2987:
2988: // ]]>
2989: </script>
2990:
2991: ENDSCRIPT
2992: }
2993:
1.160.6.118.2 1(raebur 2994:1): sub ltitools_javascript {
2995:1): my ($settings) = @_;
2996:1): my $togglejs = <itools_toggle_js();
2997:1): unless (ref($settings) eq 'HASH') {
2998:1): return $togglejs;
2999:1): }
3000:1): my (%ordered,$total,%jstext);
3001:1): $total = 0;
3002:1): foreach my $item (keys(%{$settings})) {
3003:1): if (ref($settings->{$item}) eq 'HASH') {
3004:1): my $num = $settings->{$item}{'order'};
3005:1): $ordered{$num} = $item;
3006:1): }
3007:1): }
3008:1): $total = scalar(keys(%{$settings}));
3009:1): my @jsarray = ();
3010:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3011:1): push(@jsarray,$ordered{$item});
3012:1): }
3013:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3014:1): return <<"ENDSCRIPT";
3015:1): <script type="text/javascript">
3016:1): // <![CDATA[
3017:1): function reorderLTITools(form,item) {
3018:1): var changedVal;
3019:1): $jstext
3020:1): var newpos = 'ltitools_add_pos';
3021:1): var maxh = 1 + $total;
3022:1): var current = new Array;
3023:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3024:1): if (item == newpos) {
3025:1): changedVal = newitemVal;
3026:1): } else {
3027:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3028:1): current[newitemVal] = newpos;
3029:1): }
3030:1): for (var i=0; i<ltitools.length; i++) {
3031:1): var elementName = 'ltitools_'+ltitools[i];
3032:1): if (elementName != item) {
3033:1): if (form.elements[elementName]) {
3034:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3035:1): current[currVal] = elementName;
3036:1): }
3037:1): }
3038:1): }
3039:1): var oldVal;
3040:1): for (var j=0; j<maxh; j++) {
3041:1): if (current[j] == undefined) {
3042:1): oldVal = j;
3043:1): }
3044:1): }
3045:1): if (oldVal < changedVal) {
3046:1): for (var k=oldVal+1; k<=changedVal ; k++) {
3047:1): var elementName = current[k];
3048:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3049:1): }
3050:1): } else {
3051:1): for (var k=changedVal; k<oldVal; k++) {
3052:1): var elementName = current[k];
3053:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3054:1): }
3055:1): }
3056:1): return;
3057:1): }
3058:1):
3059:1): // ]]>
3060:1): </script>
3061:1):
3062:1): $togglejs
3063:1):
3064:1): ENDSCRIPT
3065:1): }
3066:1):
3067:1): sub ltitools_toggle_js {
3068:1): return <<"ENDSCRIPT";
3069:1): <script type="text/javascript">
3070:1): // <![CDATA[
3071:1):
3072:1): function toggleLTITools(form,setting,item) {
3073:1): var radioname = '';
3074:1): var divid = '';
14(raebu 3075:23): if ((setting == 'passback') || (setting == 'roster')) {
3076:23): radioname = 'ltitools_'+setting+'_'+item;
3077:23): divid = 'ltitools_'+setting+'time_'+item;
3078:23): var num = form.elements[radioname].length;
3079:23): if (num) {
3080:23): var setvis = '';
3081:23): for (var i=0; i<num; i++) {
3082:23): if (form.elements[radioname][i].checked) {
3083:23): if (form.elements[radioname][i].value == '1') {
3084:23): if (document.getElementById(divid)) {
3085:23): document.getElementById(divid).style.display = 'inline-block';
3086:23): }
3087:23): setvis = 1;
3088:23): }
3089:23): break;
3090:23): }
3091:23): }
3092:23): }
3093:23): if (!setvis) {
3094:23): if (document.getElementById(divid)) {
3095:23): document.getElementById(divid).style.display = 'none';
3096:23): }
3097:23): }
3098:23): }
1(raebur 3099:1): if (setting == 'user') {
3100:1): divid = 'ltitools_'+setting+'_div_'+item;
3101:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3102:1): if (document.getElementById(divid)) {
3103:1): if (document.getElementById(checkid)) {
3104:1): if (document.getElementById(checkid).checked) {
3105:1): document.getElementById(divid).style.display = 'inline-block';
3106:1): } else {
3107:1): document.getElementById(divid).style.display = 'none';
3108:1): }
3109:1): }
3110:1): }
3111:1): }
3112:1): return;
3113:1): }
3114:1): // ]]>
3115:1): </script>
3116:1):
3117:1): ENDSCRIPT
3118:1): }
3119:1):
1.160.6.113 raeburn 3120: sub wafproxy_javascript {
3121: my ($dom) = @_;
3122: return <<"ENDSCRIPT";
3123: <script type="text/javascript">
3124: // <![CDATA[
3125: function updateWAF() {
3126: if (document.getElementById('wafproxy_remoteip')) {
3127: var wafremote = 0;
3128: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3129: wafremote = 1;
3130: }
3131: var fields = new Array('header','trust');
3132: for (var i=0; i<fields.length; i++) {
3133: if (document.getElementById('wafproxy_'+fields[i])) {
3134: if (wafremote == 1) {
3135: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3136: }
3137: else {
3138: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3139: }
3140: }
3141: }
3142: if (document.getElementById('wafproxyranges_$dom')) {
3143: if (wafremote == 1) {
3144: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3145: } else {
3146: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3147: if (document.display.wafproxy_vpnaccess[i].checked) {
3148: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3149: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3150: }
3151: }
3152: }
3153: }
3154: }
3155: }
3156: return;
3157: }
3158:
3159: function checkWAF() {
3160: if (document.getElementById('wafproxy_remoteip')) {
3161: var wafvpn = 0;
3162: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3163: if (document.display.wafproxy_vpnaccess[i].checked) {
3164: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3165: wafvpn = 1;
3166: }
3167: break;
3168: }
3169: }
3170: var vpn = new Array('vpnint','vpnext');
3171: for (var i=0; i<vpn.length; i++) {
3172: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3173: if (wafvpn == 1) {
3174: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3175: }
3176: else {
3177: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3178: }
3179: }
3180: }
3181: if (document.getElementById('wafproxyranges_$dom')) {
3182: if (wafvpn == 1) {
3183: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3184: }
3185: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3186: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3187: }
3188: }
3189: }
3190: return;
3191: }
3192:
3193: function toggleWAF() {
3194: if (document.getElementById('wafproxy_table')) {
3195: var wafproxy = 0;
3196: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3197: if (document.display.wafproxy_${dom}[i].checked) {
3198: if (document.display.wafproxy_${dom}[i].value == 1) {
3199: wafproxy = 1;
3200: break;
3201: }
3202: }
3203: }
3204: if (wafproxy == 1) {
3205: document.getElementById('wafproxy_table').style.display='inline';
3206: }
3207: else {
3208: document.getElementById('wafproxy_table').style.display='none';
3209: }
3210: if (document.getElementById('wafproxyrow_${dom}')) {
3211: if (wafproxy == 1) {
3212: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3213: }
3214: else {
3215: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3216: }
3217: }
3218: if (document.getElementById('nowafproxyrow_$dom')) {
3219: if (wafproxy == 1) {
3220: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3221: }
3222: else {
3223: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3224: }
3225: }
3226: }
3227: return;
3228: }
3229: // ]]>
3230: </script>
3231:
3232: ENDSCRIPT
3233: }
3234:
1.160.6.118.2 5(raebur 3235:2): sub lti_javascript {
3236:2): my ($dom,$settings) = @_;
3237:2): my $togglejs = <i_toggle_js($dom);
3238:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
14(raebu 3239:23): unless (ref($settings) eq 'HASH') {
3240:23): return $togglejs.'
3241:23): <script type="text/javascript">
3242:23): // <![CDATA[
3243:23):
3244:23): '.$linkprot_js.'
3245:23):
3246:23): // ]]>
3247:23): </script>
3248:23): ';
3249:23): }
3250:23): my (%ordered,$total,%jstext);
3251:23): $total = scalar(keys(%{$settings}));
3252:23): foreach my $item (keys(%{$settings})) {
3253:23): if (ref($settings->{$item}) eq 'HASH') {
3254:23): my $num = $settings->{$item}{'order'};
3255:23): if ($num eq '') {
3256:23): $num = $total - 1;
3257:23): }
3258:23): $ordered{$num} = $item;
3259:23): }
3260:23): }
3261:23): my @jsarray = ();
3262:23): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3263:23): push(@jsarray,$ordered{$item});
3264:23): }
3265:23): my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
5(raebur 3266:2): return <<"ENDSCRIPT";
3267:2): <script type="text/javascript">
3268:2): // <![CDATA[
14(raebu 3269:23): function reorderLTI(form,item) {
3270:23): var changedVal;
3271:23): $jstext
3272:23): var newpos = 'lti_pos_add';
3273:23): var maxh = 1 + $total;
3274:23): var current = new Array;
3275:23): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3276:23): if (item == newpos) {
3277:23): changedVal = newitemVal;
3278:23): } else {
3279:23): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3280:23): current[newitemVal] = newpos;
3281:23): }
3282:23): for (var i=0; i<lti.length; i++) {
3283:23): var elementName = 'lti_pos_'+lti[i];
3284:23): if (elementName != item) {
3285:23): if (form.elements[elementName]) {
3286:23): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3287:23): current[currVal] = elementName;
3288:23): }
3289:23): }
3290:23): }
3291:23): var oldVal;
3292:23): for (var j=0; j<maxh; j++) {
3293:23): if (current[j] == undefined) {
3294:23): oldVal = j;
3295:23): }
3296:23): }
3297:23): if (oldVal < changedVal) {
3298:23): for (var k=oldVal+1; k<=changedVal ; k++) {
3299:23): var elementName = current[k];
3300:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3301:23): }
3302:23): } else {
3303:23): for (var k=changedVal; k<oldVal; k++) {
3304:23): var elementName = current[k];
3305:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3306:23): }
3307:23): }
3308:23): return;
3309:23): }
5(raebur 3310:2):
3311:2): $linkprot_js
3312:2):
3313:2): // ]]>
3314:2): </script>
3315:2):
3316:2): $togglejs
3317:2):
3318:2): ENDSCRIPT
3319:2): }
3320:2):
3321:2): sub lti_toggle_js {
3322:2): my ($dom) = @_;
14(raebu 3323:23): my %lcauthparmtext = &Apache::lonlocal::texthash (
3324:23): localauth => 'Local auth argument',
3325:23): krb => 'Kerberos domain',
3326:23): );
3327: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");
3328:23): &js_escape(\$crsincalert);
5(raebur 3329:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3330:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3331:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3332:2): return <<"ENDSCRIPT";
3333:2): <script type="text/javascript">
3334:2): // <![CDATA[
14(raebu 3335:23):
3336:23): function toggleLTI(form,setting,item) {
3337:23): if ((setting == 'requser') || (setting == 'crsinc')) {
3338:23): var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3339:23): var setvis = '';
3340:23): var radioname = 'lti_requser_'+item;
3341:23): var num = form.elements[radioname].length;
3342:23): if (num) {
3343:23): for (var i=0; i<num; i++) {
3344:23): if (form.elements[radioname][i].checked) {
3345:23): if (form.elements[radioname][i].value == '1') {
3346:23): setvis = 1;
3347:23): break;
5(raebur 3348:2): }
14(raebu 3349:23): }
3350:23): }
3351:23): }
3352:23): if (usrfieldsets.length) {
3353:23): for (var j=0; j<usrfieldsets.length; j++) {
3354:23): if (setvis) {
3355:23): usrfieldsets[j].style.display = 'block';
3356:23): } else {
3357:23): usrfieldsets[j].style.display = 'none';
3358:23): }
3359:23): }
3360:23): }
3361:23): var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3362:23): if (crsfieldsets.length) {
3363:23): radioname = 'lti_crsinc_'+item;
3364:23): var num = form.elements[radioname].length;
3365:23): if (num) {
3366:23): var crsvis = '';
3367:23): for (var i=0; i<num; i++) {
3368:23): if (form.elements[radioname][i].checked) {
3369:23): if (form.elements[radioname][i].value == '1') {
3370:23): if (setvis == '') {
3371:23): if (setting == 'crsinc'){
3372:23): alert("$crsincalert");
3373:23): form.elements[radioname][0].checked = true;
3374:23): }
3375:23): } else {
3376:23): crsvis = 1;
5(raebur 3377:2): }
14(raebu 3378:23): break;
5(raebur 3379:2): }
3380:2): }
3381:2): }
14(raebu 3382:23): setvis = crsvis;
5(raebur 3383:2): }
14(raebu 3384:23): for (var j=0; j<crsfieldsets.length; j++) {
3385:23): if (setvis) {
3386:23): crsfieldsets[j].style.display = 'block';
3387:23): } else {
3388:23): crsfieldsets[j].style.display = 'none';
5(raebur 3389:2): }
3390:2): }
3391:2): }
14(raebu 3392:23): } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
3393:23): var radioname = '';
3394:23): var divid = '';
3395:23): if (setting == 'user') {
3396:23): radioname = 'lti_mapuser_'+item;
3397:23): divid = 'lti_userfield_'+item;
3398:23): } else if (setting == 'crs') {
3399:23): radioname = 'lti_mapcrs_'+item;
3400:23): divid = 'lti_crsfield_'+item;
3401:23): } else if (setting == 'callback') {
3402:23): radioname = 'lti_callback_'+item;
3403:23): divid = 'lti_callbackfield_'+item;
3404:23): } else {
3405:23): radioname = 'lti_passback_'+item;
3406:23): divid = 'lti_passback_'+item;
3407:23): }
3408:23): var num = form.elements[radioname].length;
3409:23): if (num) {
3410:23): var setvis = '';
3411:23): for (var i=0; i<num; i++) {
3412:23): if (form.elements[radioname][i].checked) {
3413:23): if ((setting == 'passback') || (setting == 'callback')) {
3414:23): if (form.elements[radioname][i].value == '1') {
3415:23): if (document.getElementById(divid)) {
3416:23): document.getElementById(divid).style.display = 'inline-block';
3417:23): }
3418:23): setvis = 1;
3419:23): break;
3420:23): }
3421:23): } else {
3422:23): if (form.elements[radioname][i].value == 'other') {
3423:23): if (document.getElementById(divid)) {
3424:23): document.getElementById(divid).style.display = 'inline-block';
3425:23): }
3426:23): setvis = 1;
3427:23): break;
3428:23): }
3429:23): }
3430:23): }
3431:23): }
3432:23): if (!setvis) {
3433:23): if (document.getElementById(divid)) {
3434:23): document.getElementById(divid).style.display = 'none';
3435:23): }
5(raebur 3436:2): }
3437:2): }
14(raebu 3438:23): } else if ((setting == 'sec') || (setting == 'secsrc')) {
3439:23): var numsec = form.elements['lti_crssec_'+item].length;
3440:23): if (numsec) {
3441:23): var setvis = '';
3442:23): for (var i=0; i<numsec; i++) {
3443:23): if (form.elements['lti_crssec_'+item][i].checked) {
3444:23): if (form.elements['lti_crssec_'+item][i].value == '1') {
3445:23): if (document.getElementById('lti_crssecfield_'+item)) {
3446:23): document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3447:23): setvis = 1;
3448:23): var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3449:23): if (numsrcsec) {
3450:23): var setsrcvis = '';
3451:23): for (var j=0; j<numsrcsec; j++) {
3452:23): if (form.elements['lti_crssecsrc_'+item][j].checked) {
3453:23): if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3454:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3455:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3456:23): setsrcvis = 1;
3457:23): }
3458:23): }
3459:23): }
3460:23): }
3461:23): if (!setsrcvis) {
3462:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3463:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3464:23): }
3465:23): }
3466:23): }
3467:23): }
3468:23): }
3469:23): }
3470:23): }
3471:23): if (!setvis) {
3472:23): if (document.getElementById('lti_crssecfield_'+item)) {
3473:23): document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3474:23): }
3475:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3476:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3477:23): }
3478:23): }
5(raebur 3479:2): }
14(raebu 3480:23): } else if (setting == 'lcauth') {
3481:23): var numauth = form.elements['lti_lcauth_'+item].length;
3482:23): if (numauth) {
3483:23): for (var i=0; i<numauth; i++) {
3484:23): if (form.elements['lti_lcauth_'+item][i].checked) {
3485:23): if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3486:23): if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3487:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3488:23): } else {
3489:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3490:23): if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3491:23): if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3492:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3493:23): } else {
3494:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3495:23): }
3496:23): }
3497:23): }
3498:23): }
5(raebur 3499:2): }
3500:2): }
3501:2): }
14(raebu 3502:23): } else if (setting == 'lcmenu') {
3503:23): var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3504:23): var divid = 'lti_menufield_'+item;
3505:23): var setvis = '';
3506:23): for (var i=0; i<menus.length; i++) {
3507:23): var radioname = menus[i];
3508:23): var num = form.elements[radioname].length;
3509:23): if (num) {
3510:23): for (var j=0; j<num; j++) {
3511:23): if (form.elements[radioname][j].checked) {
3512:23): if (form.elements[radioname][j].value == '1') {
3513:23): if (document.getElementById(divid)) {
3514:23): document.getElementById(divid).style.display = 'inline-block';
3515:23): }
5(raebur 3516:2): setvis = 1;
14(raebu 3517:23): break;
5(raebur 3518:2): }
3519:2): }
3520:2): }
14(raebu 3521:23): }
3522:23): if (setvis == 1) {
3523:23): break;
3524:23): }
3525:23): }
3526:23): if (!setvis) {
3527:23): if (document.getElementById(divid)) {
3528:23): document.getElementById(divid).style.display = 'none';
5(raebur 3529:2): }
3530:2): }
3531:2): }
14(raebu 3532:23): return;
5(raebur 3533:2): }
3534:2):
3535:2): // ]]>
3536:2): </script>
3537:2):
3538:2): ENDSCRIPT
3539:2): }
3540:2):
1.160.6.113 raeburn 3541: sub autoupdate_javascript {
3542: return <<"ENDSCRIPT";
3543: <script type="text/javascript">
3544: // <![CDATA[
3545: function toggleLastActiveDays(form) {
3546: var radioname = 'lastactive';
3547: var divid = 'lastactive_div';
3548: var num = form.elements[radioname].length;
3549: if (num) {
3550: var setvis = '';
3551: for (var i=0; i<num; i++) {
3552: if (form.elements[radioname][i].checked) {
3553: if (form.elements[radioname][i].value == '1') {
3554: if (document.getElementById(divid)) {
3555: document.getElementById(divid).style.display = 'inline-block';
3556: }
3557: setvis = 1;
3558: }
3559: break;
3560: }
3561: }
3562: if (!setvis) {
3563: if (document.getElementById(divid)) {
3564: document.getElementById(divid).style.display = 'none';
3565: }
3566: }
3567: }
3568: return;
3569: }
3570: // ]]>
3571: </script>
3572:
3573: ENDSCRIPT
3574: }
3575:
1.160.6.116 raeburn 3576: sub autoenroll_javascript {
3577: return <<"ENDSCRIPT";
3578: <script type="text/javascript">
3579: // <![CDATA[
3580: function toggleFailsafe(form) {
3581: var radioname = 'autoenroll_failsafe';
3582: var divid = 'autoenroll_failsafe_div';
3583: var num = form.elements[radioname].length;
3584: if (num) {
3585: var setvis = '';
3586: for (var i=0; i<num; i++) {
3587: if (form.elements[radioname][i].checked) {
3588: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3589: if (document.getElementById(divid)) {
3590: document.getElementById(divid).style.display = 'inline-block';
3591: }
3592: setvis = 1;
3593: }
3594: break;
3595: }
3596: }
3597: if (!setvis) {
3598: if (document.getElementById(divid)) {
3599: document.getElementById(divid).style.display = 'none';
3600: }
3601: }
3602: }
3603: return;
3604: }
3605: // ]]>
3606: </script>
3607:
3608: ENDSCRIPT
3609: }
3610:
1.160.6.113 raeburn 3611: sub saml_javascript {
3612: return <<"ENDSCRIPT";
3613: <script type="text/javascript">
3614: // <![CDATA[
3615: function toggleSamlOptions(form,hostid) {
3616: var radioname = 'saml_'+hostid;
3617: var tablecellon = 'samloptionson_'+hostid;
3618: var tablecelloff = 'samloptionsoff_'+hostid;
3619: var num = form.elements[radioname].length;
3620: if (num) {
3621: var setvis = '';
3622: for (var i=0; i<num; i++) {
3623: if (form.elements[radioname][i].checked) {
3624: if (form.elements[radioname][i].value == '1') {
3625: if (document.getElementById(tablecellon)) {
3626: document.getElementById(tablecellon).style.display='';
3627: }
3628: if (document.getElementById(tablecelloff)) {
3629: document.getElementById(tablecelloff).style.display='none';
3630: }
3631: setvis = 1;
3632: }
3633: break;
3634: }
3635: }
3636: if (!setvis) {
3637: if (document.getElementById(tablecellon)) {
3638: document.getElementById(tablecellon).style.display='none';
3639: }
3640: if (document.getElementById(tablecelloff)) {
3641: document.getElementById(tablecelloff).style.display='';
3642: }
3643: }
3644: }
3645: return;
3646: }
3647: // ]]>
3648: </script>
3649:
3650: ENDSCRIPT
3651: }
3652:
3653: sub ipaccess_javascript {
3654: my ($settings) = @_;
3655: my (%ordered,$total,%jstext);
3656: $total = 0;
3657: if (ref($settings) eq 'HASH') {
3658: foreach my $item (keys(%{$settings})) {
3659: if (ref($settings->{$item}) eq 'HASH') {
3660: my $num = $settings->{$item}{'order'};
3661: $ordered{$num} = $item;
3662: }
3663: }
3664: $total = scalar(keys(%{$settings}));
3665: }
3666: my @jsarray = ();
3667: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3668: push(@jsarray,$ordered{$item});
3669: }
3670: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3671: return <<"ENDSCRIPT";
3672: <script type="text/javascript">
3673: // <![CDATA[
3674: function reorderIPaccess(form,item) {
3675: var changedVal;
3676: $jstext
3677: var newpos = 'ipaccess_pos_add';
3678: var maxh = 1 + $total;
3679: var current = new Array;
3680: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3681: if (item == newpos) {
3682: changedVal = newitemVal;
3683: } else {
3684: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3685: current[newitemVal] = newpos;
3686: }
3687: for (var i=0; i<ipaccess.length; i++) {
3688: var elementName = 'ipaccess_pos_'+ipaccess[i];
3689: if (elementName != item) {
3690: if (form.elements[elementName]) {
3691: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3692: current[currVal] = elementName;
3693: }
3694: }
3695: }
3696: var oldVal;
3697: for (var j=0; j<maxh; j++) {
3698: if (current[j] == undefined) {
3699: oldVal = j;
3700: }
3701: }
3702: if (oldVal < changedVal) {
3703: for (var k=oldVal+1; k<=changedVal ; k++) {
3704: var elementName = current[k];
3705: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3706: }
3707: } else {
3708: for (var k=changedVal; k<oldVal; k++) {
3709: var elementName = current[k];
3710: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3711: }
3712: }
3713: return;
3714: }
3715: // ]]>
3716: </script>
3717:
3718: ENDSCRIPT
3719: }
3720:
1.160.6.118.2 20(raebu 3721:24): sub authordefaults_javascript {
3722:24): my %alert = &Apache::lonlocal::texthash (
3723:24): reqd => 'Warning: at least one editor needs to be available.',
3724:24): rest => 'Unchecking this editor disallowed while others unchecked.',
3725:24): );
3726:24): &js_escape(\%alert);
3727:24): return <<"ENDSCRIPT";
3728:24): <script type="text/javascript">
3729:24): // <![CDATA[
3730:24):
3731:24): function checkEditors(form,checkbox,current) {
3732:24): if (form.elements[checkbox].length != undefined) {
3733:24): var count = 0;
3734:24): for (var i=0; i<form.elements[checkbox].length; i++) {
3735:24): if (form.elements[checkbox][i].checked) {
3736:24): count ++;
3737:24): }
3738:24): }
3739:24): if (count == 0) {
3740:24): if (current.type =='radio') {
3741:24): current.checked = true;
3742:24): alert('$alert{reqd}\\n$alert{rest}');
3743:24): }
3744:24): }
3745:24): }
3746:24): return;
3747:24): }
3748:24): // ]]>
3749:24): </script>
3750:24):
3751:24): ENDSCRIPT
3752:24): }
3753:24):
1.3 raeburn 3754: sub print_autoenroll {
1.30 raeburn 3755: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3756: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3757: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3758: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3759: $failsafesty = 'none';
3760: %failsafechecked = (
3761: off => ' checked="checked"',
3762: );
1.3 raeburn 3763: if (ref($settings) eq 'HASH') {
3764: if (exists($settings->{'run'})) {
3765: if ($settings->{'run'} eq '0') {
3766: $runoff = ' checked="checked" ';
3767: $runon = ' ';
3768: } else {
3769: $runon = ' checked="checked" ';
3770: $runoff = ' ';
3771: }
3772: } else {
3773: if ($autorun) {
3774: $runon = ' checked="checked" ';
3775: $runoff = ' ';
3776: } else {
3777: $runoff = ' checked="checked" ';
3778: $runon = ' ';
3779: }
3780: }
1.129 raeburn 3781: if (exists($settings->{'co-owners'})) {
3782: if ($settings->{'co-owners'} eq '0') {
3783: $coownersoff = ' checked="checked" ';
3784: $coownerson = ' ';
3785: } else {
3786: $coownerson = ' checked="checked" ';
3787: $coownersoff = ' ';
3788: }
3789: } else {
3790: $coownersoff = ' checked="checked" ';
3791: $coownerson = ' ';
3792: }
1.3 raeburn 3793: if (exists($settings->{'sender_domain'})) {
3794: $defdom = $settings->{'sender_domain'};
3795: }
1.160.6.116 raeburn 3796: if (exists($settings->{'failsafe'})) {
3797: $failsafe = $settings->{'failsafe'};
3798: if ($failsafe eq 'zero') {
3799: $failsafechecked{'zero'} = ' checked="checked"';
3800: $failsafechecked{'off'} = '';
3801: $failsafesty = 'inline-block';
3802: } elsif ($failsafe eq 'any') {
3803: $failsafechecked{'any'} = ' checked="checked"';
3804: $failsafechecked{'off'} = '';
3805: }
3806: $autofailsafe = $settings->{'autofailsafe'};
3807: } elsif (exists($settings->{'autofailsafe'})) {
3808: $autofailsafe = $settings->{'autofailsafe'};
3809: if ($autofailsafe ne '') {
3810: $failsafechecked{'zero'} = ' checked="checked"';
3811: $failsafe = 'zero';
3812: $failsafechecked{'off'} = '';
3813: }
1.160.6.68 raeburn 3814: }
1.14 raeburn 3815: } else {
3816: if ($autorun) {
3817: $runon = ' checked="checked" ';
3818: $runoff = ' ';
3819: } else {
3820: $runoff = ' checked="checked" ';
3821: $runon = ' ';
3822: }
1.3 raeburn 3823: }
3824: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3825: my $notif_sender;
3826: if (ref($settings) eq 'HASH') {
3827: $notif_sender = $settings->{'sender_uname'};
3828: }
1.3 raeburn 3829: my $datatable='<tr class="LC_odd_row">'.
3830: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3831: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3832: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3833: $runon.' value="1" />'.&mt('Yes').'</label> '.
3834: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3835: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3836: '</tr><tr>'.
3837: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3838: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3839: &mt('username').': '.
3840: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3841: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3842: ': '.$domform.'</span></td></tr>'.
3843: '<tr class="LC_odd_row">'.
3844: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3845: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3846: '<input type="radio" name="autoassign_coowners"'.
3847: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3848: '<label><input type="radio" name="autoassign_coowners"'.
3849: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3850: '</tr><tr>'.
3851: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3852: '<td class="LC_left_item"><span class="LC_nobreak">'.
3853: '<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> '.
3854: '<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 />'.
3855: '<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>'.
3856: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3857: '<span class="LC_nobreak">'.
3858: &mt('Threshold for number of students in section to drop: [_1]',
3859: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3860: '</span></div></td></tr>';
1.160.6.68 raeburn 3861: $$rowtotal += 4;
1.3 raeburn 3862: return $datatable;
3863: }
3864:
3865: sub print_autoupdate {
1.30 raeburn 3866: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3867: my ($enable,$datatable);
1.3 raeburn 3868: if ($position eq 'top') {
1.160.6.113 raeburn 3869: my %choices = &Apache::lonlocal::texthash (
3870: run => 'Auto-update active?',
3871: classlists => 'Update information in classlists?',
3872: unexpired => 'Skip updates for users without active or future roles?',
3873: lastactive => 'Skip updates for inactive users?',
3874: );
3875: my $itemcount = 0;
1.3 raeburn 3876: my $updateon = ' ';
3877: my $updateoff = ' checked="checked" ';
3878: if (ref($settings) eq 'HASH') {
3879: if ($settings->{'run'} eq '1') {
3880: $updateon = $updateoff;
3881: $updateoff = ' ';
3882: }
3883: }
1.160.6.118.2 14(raebu 3884:23): $enable = '<tr class="LC_odd_row">'.
3885:23): '<td>'.$choices{'run'}.'</td>'.
1.160.6.113 raeburn 3886: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3887: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3888: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3889: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3890: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3891: '</tr>';
1.160.6.113 raeburn 3892: my @toggles = ('classlists','unexpired');
3893: my %defaultchecked = ('classlists' => 'off',
3894: 'unexpired' => 'off'
3895: );
3896: $$rowtotal ++;
3897: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3898: \%choices,$itemcount,'','','left','no');
3899: $datatable = $enable.$datatable;
3900: $$rowtotal += $itemcount;
3901: my $lastactiveon = ' ';
3902: my $lastactiveoff = ' checked="checked" ';
3903: my $lastactivestyle = 'none';
3904: my $lastactivedays;
3905: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3906: if (ref($settings) eq 'HASH') {
3907: if ($settings->{'lastactive'} =~ /^\d+$/) {
3908: $lastactiveon = $lastactiveoff;
3909: $lastactiveoff = ' ';
3910: $lastactivestyle = 'inline-block';
3911: $lastactivedays = $settings->{'lastactive'};
3912: }
3913: }
3914: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3915: $datatable .= '<tr'.$css_class.'>'.
3916: '<td>'.$choices{'lastactive'}.'</td>'.
3917: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3918: '<input type="radio" name="lastactive"'.
3919: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3920: ' <label>'.
3921: '<input type="radio" name="lastactive"'.
3922: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3923: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3924: ': '.&mt('inactive = no activity in last [_1] days',
3925: '<input type="text" size="5" name="lastactivedays" value="'.
3926: $lastactivedays.'" />').
3927: '</span></td>'.
3928: '</tr>';
3929: $$rowtotal ++;
1.131 raeburn 3930: } elsif ($position eq 'middle') {
3931: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3932: my $numinrow = 3;
3933: my $locknamesettings;
3934: $datatable .= &insttypes_row($settings,$types,$usertypes,
3935: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3936: 'lockablenames',$rowtotal);
1.131 raeburn 3937: $$rowtotal ++;
1.3 raeburn 3938: } else {
1.44 raeburn 3939: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3940: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3941: 'permanentemail','id');
1.33 raeburn 3942: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3943: my $numrows = 0;
1.26 raeburn 3944: if (ref($types) eq 'ARRAY') {
3945: if (@{$types} > 0) {
3946: $datatable =
3947: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3948: \@fields,$types,\$numrows);
1.30 raeburn 3949: $$rowtotal += @{$types};
1.26 raeburn 3950: }
1.3 raeburn 3951: }
3952: $datatable .=
3953: &usertype_update_row($settings,{'default' => $othertitle},
3954: \%fieldtitles,\@fields,['default'],
3955: \$numrows);
1.30 raeburn 3956: $$rowtotal ++;
1.3 raeburn 3957: }
3958: return $datatable;
3959: }
3960:
1.125 raeburn 3961: sub print_autocreate {
3962: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3963: my (%createon,%createoff,%currhash);
1.125 raeburn 3964: my @types = ('xml','req');
3965: if (ref($settings) eq 'HASH') {
3966: foreach my $item (@types) {
3967: $createoff{$item} = ' checked="checked" ';
3968: $createon{$item} = ' ';
3969: if (exists($settings->{$item})) {
3970: if ($settings->{$item}) {
3971: $createon{$item} = ' checked="checked" ';
3972: $createoff{$item} = ' ';
3973: }
3974: }
3975: }
1.160.6.16 raeburn 3976: if ($settings->{'xmldc'} ne '') {
3977: $currhash{$settings->{'xmldc'}} = 1;
3978: }
1.125 raeburn 3979: } else {
3980: foreach my $item (@types) {
3981: $createoff{$item} = ' checked="checked" ';
3982: $createon{$item} = ' ';
3983: }
3984: }
3985: $$rowtotal += 2;
1.160.6.16 raeburn 3986: my $numinrow = 2;
1.125 raeburn 3987: my $datatable='<tr class="LC_odd_row">'.
3988: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3989: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3990: '<input type="radio" name="autocreate_xml"'.
3991: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
3992: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 3993: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
3994: '</td></tr><tr>'.
3995: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
3996: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3997: '<input type="radio" name="autocreate_req"'.
3998: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
3999: '<label><input type="radio" name="autocreate_req"'.
4000: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 4001: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4002: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 4003: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4004: if ($numdc > 1) {
1.160.6.50 raeburn 4005: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4006: '</td><td class="LC_left_item">';
1.125 raeburn 4007: } else {
1.160.6.50 raeburn 4008: $datatable .= &mt('Course creation processed as:').
4009: '</td><td class="LC_right_item">';
1.125 raeburn 4010: }
1.160.6.50 raeburn 4011: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 4012: $$rowtotal += $rows;
1.125 raeburn 4013: return $datatable;
4014: }
4015:
1.23 raeburn 4016: sub print_directorysrch {
1.160.6.72 raeburn 4017: my ($position,$dom,$settings,$rowtotal) = @_;
4018: my $datatable;
4019: if ($position eq 'top') {
4020: my $instsrchon = ' ';
4021: my $instsrchoff = ' checked="checked" ';
4022: my ($exacton,$containson,$beginson);
4023: my $instlocalon = ' ';
4024: my $instlocaloff = ' checked="checked" ';
4025: if (ref($settings) eq 'HASH') {
4026: if ($settings->{'available'} eq '1') {
4027: $instsrchon = $instsrchoff;
4028: $instsrchoff = ' ';
4029: }
4030: if ($settings->{'localonly'} eq '1') {
4031: $instlocalon = $instlocaloff;
4032: $instlocaloff = ' ';
4033: }
4034: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4035: foreach my $type (@{$settings->{'searchtypes'}}) {
4036: if ($type eq 'exact') {
4037: $exacton = ' checked="checked" ';
4038: } elsif ($type eq 'contains') {
4039: $containson = ' checked="checked" ';
4040: } elsif ($type eq 'begins') {
4041: $beginson = ' checked="checked" ';
4042: }
4043: }
4044: } else {
4045: if ($settings->{'searchtypes'} eq 'exact') {
4046: $exacton = ' checked="checked" ';
4047: } elsif ($settings->{'searchtypes'} eq 'contains') {
4048: $containson = ' checked="checked" ';
4049: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4050: $exacton = ' checked="checked" ';
4051: $containson = ' checked="checked" ';
4052: }
4053: }
1.23 raeburn 4054: }
1.160.6.72 raeburn 4055: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4056: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 4057:
1.160.6.72 raeburn 4058: my $numinrow = 4;
4059: my $cansrchrow = 0;
4060: $datatable='<tr class="LC_odd_row">'.
4061: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4062: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4063: '<input type="radio" name="dirsrch_available"'.
4064: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4065: '<label><input type="radio" name="dirsrch_available"'.
4066: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4067: '</tr><tr>'.
4068: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4069: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4070: '<input type="radio" name="dirsrch_instlocalonly"'.
4071: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4072: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4073: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4074: '</tr>';
4075: $$rowtotal += 2;
4076: if (ref($usertypes) eq 'HASH') {
4077: if (keys(%{$usertypes}) > 0) {
4078: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 4079: $numinrow,$othertitle,'cansearch',
4080: $rowtotal);
1.160.6.72 raeburn 4081: $cansrchrow = 1;
4082: }
1.26 raeburn 4083: }
1.160.6.72 raeburn 4084: if ($cansrchrow) {
4085: $$rowtotal ++;
4086: $datatable .= '<tr>';
4087: } else {
4088: $datatable .= '<tr class="LC_odd_row">';
4089: }
4090: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4091: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4092: foreach my $title (@{$titleorder}) {
4093: if (defined($searchtitles->{$title})) {
4094: my $check = ' ';
4095: if (ref($settings) eq 'HASH') {
4096: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4097: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4098: $check = ' checked="checked" ';
4099: }
1.39 raeburn 4100: }
1.25 raeburn 4101: }
1.160.6.72 raeburn 4102: $datatable .= '<td class="LC_left_item">'.
4103: '<span class="LC_nobreak"><label>'.
4104: '<input type="checkbox" name="searchby" '.
4105: 'value="'.$title.'"'.$check.'/>'.
4106: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4107: }
4108: }
1.160.6.72 raeburn 4109: $datatable .= '</tr></table></td></tr>';
4110: $$rowtotal ++;
4111: if ($cansrchrow) {
4112: $datatable .= '<tr class="LC_odd_row">';
4113: } else {
4114: $datatable .= '<tr>';
4115: }
4116: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4117: '<td class="LC_left_item" colspan="2">'.
4118: '<span class="LC_nobreak"><label>'.
4119: '<input type="checkbox" name="searchtypes" '.
4120: $exacton.' value="exact" />'.&mt('Exact match').
4121: '</label> '.
4122: '<label><input type="checkbox" name="searchtypes" '.
4123: $beginson.' value="begins" />'.&mt('Begins with').
4124: '</label> '.
4125: '<label><input type="checkbox" name="searchtypes" '.
4126: $containson.' value="contains" />'.&mt('Contains').
4127: '</label></span></td></tr>';
4128: $$rowtotal ++;
1.26 raeburn 4129: } else {
1.160.6.72 raeburn 4130: my $domsrchon = ' checked="checked" ';
4131: my $domsrchoff = ' ';
4132: my $domlocalon = ' ';
4133: my $domlocaloff = ' checked="checked" ';
4134: if (ref($settings) eq 'HASH') {
4135: if ($settings->{'lclocalonly'} eq '1') {
4136: $domlocalon = $domlocaloff;
4137: $domlocaloff = ' ';
4138: }
4139: if ($settings->{'lcavailable'} eq '0') {
4140: $domsrchoff = $domsrchon;
4141: $domsrchon = ' ';
4142: }
4143: }
4144: $datatable='<tr class="LC_odd_row">'.
4145: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4146: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4147: '<input type="radio" name="dirsrch_domavailable"'.
4148: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4149: '<label><input type="radio" name="dirsrch_domavailable"'.
4150: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4151: '</tr><tr>'.
4152: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4153: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4154: '<input type="radio" name="dirsrch_domlocalonly"'.
4155: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4156: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4157: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4158: '</tr>';
4159: $$rowtotal += 2;
1.26 raeburn 4160: }
1.25 raeburn 4161: return $datatable;
4162: }
4163:
1.28 raeburn 4164: sub print_contacts {
1.160.6.78 raeburn 4165: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4166: my $datatable;
4167: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 4168: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 4169: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 4170: if ($position eq 'top') {
4171: if (ref($settings) eq 'HASH') {
4172: foreach my $item (@contacts) {
4173: if (exists($settings->{$item})) {
4174: $to{$item} = $settings->{$item};
4175: }
1.28 raeburn 4176: }
4177: }
1.160.6.78 raeburn 4178: } elsif ($position eq 'middle') {
4179: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 4180: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 4181: foreach my $type (@mailings) {
1.160.6.78 raeburn 4182: $otheremails{$type} = '';
4183: }
1.160.6.107 raeburn 4184: } elsif ($position eq 'lower') {
4185: if (ref($settings) eq 'HASH') {
4186: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4187: %lonstatus = %{$settings->{'lonstatus'}};
4188: }
4189: }
1.160.6.78 raeburn 4190: } else {
4191: @mailings = ('helpdeskmail','otherdomsmail');
4192: foreach my $type (@mailings) {
4193: $otheremails{$type} = '';
4194: }
4195: $bccemails{'helpdeskmail'} = '';
4196: $bccemails{'otherdomsmail'} = '';
4197: $includestr{'helpdeskmail'} = '';
4198: $includestr{'otherdomsmail'} = '';
4199: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4200: }
4201: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 4202: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4203: foreach my $type (@mailings) {
4204: if (exists($settings->{$type})) {
4205: if (ref($settings->{$type}) eq 'HASH') {
4206: foreach my $item (@contacts) {
4207: if ($settings->{$type}{$item}) {
4208: $checked{$type}{$item} = ' checked="checked" ';
4209: }
1.28 raeburn 4210: }
1.160.6.78 raeburn 4211: $otheremails{$type} = $settings->{$type}{'others'};
4212: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4213: $bccemails{$type} = $settings->{$type}{'bcc'};
4214: if ($settings->{$type}{'include'} ne '') {
4215: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4216: $includestr{$type} = &unescape($includestr{$type});
4217: }
4218: }
4219: }
4220: } elsif ($type eq 'lonstatusmail') {
4221: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4222: }
4223: }
4224: }
4225: if ($position eq 'bottom') {
4226: foreach my $type (@mailings) {
4227: $bccemails{$type} = $settings->{$type}{'bcc'};
4228: if ($settings->{$type}{'include'} ne '') {
4229: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4230: $includestr{$type} = &unescape($includestr{$type});
4231: }
4232: }
4233: if (ref($settings->{'helpform'}) eq 'HASH') {
4234: if (ref($fields) eq 'ARRAY') {
4235: foreach my $field (@{$fields}) {
4236: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4237: }
1.160.6.78 raeburn 4238: }
4239: if (exists($settings->{'helpform'}{'maxsize'})) {
4240: $maxsize = $settings->{'helpform'}{'maxsize'};
4241: } else {
4242: $maxsize = '1.0';
4243: }
4244: } else {
4245: if (ref($fields) eq 'ARRAY') {
4246: foreach my $field (@{$fields}) {
4247: $currfield{$field} = 'yes';
1.134 raeburn 4248: }
1.28 raeburn 4249: }
1.160.6.78 raeburn 4250: $maxsize = '1.0';
1.28 raeburn 4251: }
4252: }
4253: } else {
1.160.6.78 raeburn 4254: if ($position eq 'top') {
4255: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4256: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4257: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4258: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
4259: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4260: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4261: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4262: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 4263: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 4264: } elsif ($position eq 'bottom') {
4265: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4266: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4267: if (ref($fields) eq 'ARRAY') {
4268: foreach my $field (@{$fields}) {
4269: $currfield{$field} = 'yes';
4270: }
4271: }
4272: $maxsize = '1.0';
4273: }
1.28 raeburn 4274: }
4275: my ($titles,$short_titles) = &contact_titles();
4276: my $rownum = 0;
4277: my $css_class;
1.160.6.78 raeburn 4278: if ($position eq 'top') {
4279: foreach my $item (@contacts) {
4280: $css_class = $rownum%2?' class="LC_odd_row"':'';
4281: $datatable .= '<tr'.$css_class.'>'.
4282: '<td><span class="LC_nobreak">'.$titles->{$item}.
4283: '</span></td><td class="LC_right_item">'.
4284: '<input type="text" name="'.$item.'" value="'.
4285: $to{$item}.'" /></td></tr>';
4286: $rownum ++;
4287: }
1.160.6.101 raeburn 4288: } elsif ($position eq 'bottom') {
4289: $css_class = $rownum%2?' class="LC_odd_row"':'';
4290: $datatable .= '<tr'.$css_class.'>'.
4291: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4292: &mt('(e-mail, subject, and description always shown)').
4293: '</td><td class="LC_left_item">';
4294: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4295: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4296: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4297: foreach my $field (@{$fields}) {
4298: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4299: if (($field eq 'screenshot') || ($field eq 'cc')) {
4300: $datatable .= ' '.&mt('(logged-in users)');
4301: }
4302: $datatable .='</td><td>';
4303: my $clickaction;
4304: if ($field eq 'screenshot') {
4305: $clickaction = ' onclick="screenshotSize(this);"';
4306: }
4307: if (ref($possoptions->{$field}) eq 'ARRAY') {
4308: foreach my $option (@{$possoptions->{$field}}) {
4309: my $checked;
4310: if ($currfield{$field} eq $option) {
4311: $checked = ' checked="checked"';
4312: }
4313: $datatable .= '<span class="LC_nobreak"><label>'.
4314: '<input type="radio" name="helpform_'.$field.'" '.
4315: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4316: '</label></span>'.(' 'x2);
4317: }
4318: }
4319: if ($field eq 'screenshot') {
4320: my $display;
4321: if ($currfield{$field} eq 'no') {
4322: $display = ' style="display:none"';
4323: }
4324: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4325: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4326: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4327: }
4328: $datatable .= '</td></tr>';
4329: }
4330: $datatable .= '</table>';
4331: }
4332: $datatable .= '</td></tr>'."\n";
4333: $rownum ++;
4334: }
1.160.6.107 raeburn 4335: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4336: foreach my $type (@mailings) {
4337: $css_class = $rownum%2?' class="LC_odd_row"':'';
4338: $datatable .= '<tr'.$css_class.'>'.
4339: '<td><span class="LC_nobreak">'.
4340: $titles->{$type}.': </span></td>'.
4341: '<td class="LC_left_item">';
4342: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4343: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4344: }
4345: $datatable .= '<span class="LC_nobreak">';
4346: foreach my $item (@contacts) {
4347: $datatable .= '<label>'.
4348: '<input type="checkbox" name="'.$type.'"'.
4349: $checked{$type}{$item}.
4350: ' value="'.$item.'" />'.$short_titles->{$item}.
4351: '</label> ';
4352: }
4353: $datatable .= '</span><br />'.&mt('Others').': '.
4354: '<input type="text" name="'.$type.'_others" '.
4355: 'value="'.$otheremails{$type}.'" />';
4356: my %locchecked;
4357: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4358: foreach my $loc ('s','b') {
4359: if ($includeloc{$type} eq $loc) {
4360: $locchecked{$loc} = ' checked="checked"';
4361: last;
4362: }
4363: }
4364: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4365: '<input type="text" name="'.$type.'_bcc" '.
4366: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4367: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4368: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4369: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4370: '<span class="LC_nobreak">'.&mt('Location:').' '.
4371: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4372: (' 'x2).
4373: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4374: '</span></fieldset>';
4375: }
4376: $datatable .= '</td></tr>'."\n";
4377: $rownum ++;
4378: }
1.28 raeburn 4379: }
1.160.6.78 raeburn 4380: if ($position eq 'middle') {
4381: my %choices;
1.160.6.107 raeburn 4382: my $corelink = &core_link_msu();
4383: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4384: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4385: $corelink);
4386: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4387: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4388: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4389: 'reportupdates' => 'on',
4390: 'reportstatus' => 'on');
1.160.6.78 raeburn 4391: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4392: \%choices,$rownum);
4393: $datatable .= $reports;
1.160.6.107 raeburn 4394: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4395: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4396: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4397: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4398: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4399: } else {
1.160.6.109 raeburn 4400: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4401: }
4402: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4403: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4404: } else {
1.160.6.109 raeburn 4405: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4406: }
4407: if (ref($lonstatus{'weights'}) eq 'HASH') {
4408: foreach my $type ('E','W','N','U') {
4409: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4410: $weights{$type} = $lonstatus{'weights'}{$type};
4411: } else {
4412: $weights{$type} = $defaults->{$type};
4413: }
4414: }
4415: } else {
4416: foreach my $type ('E','W','N','U') {
4417: $weights{$type} = $defaults->{$type};
4418: }
4419: }
4420: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4421: if (@{$lonstatus{'excluded'}} > 0) {
4422: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4423: }
4424: }
1.160.6.109 raeburn 4425: foreach my $item ('errorthreshold','errorsysmail') {
4426: $css_class = $rownum%2?' class="LC_odd_row"':'';
4427: $datatable .= '<tr'.$css_class.'>'.
4428: '<td class="LC_left_item"><span class="LC_nobreak">'.
4429: $titles->{$item}.
4430: '</span></td><td class="LC_left_item">'.
4431: '<input type="text" name="'.$item.'" value="'.
4432: $current{$item}.'" size="5" /></td></tr>';
4433: $rownum ++;
4434: }
1.160.6.107 raeburn 4435: $css_class = $rownum%2?' class="LC_odd_row"':'';
4436: $datatable .= '<tr'.$css_class.'>'.
4437: '<td class="LC_left_item">'.
4438: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4439: '</span></td><td class="LC_left_item"><table><tr>';
4440: foreach my $type ('E','W','N','U') {
4441: $datatable .= '<td>'.$names->{$type}.'<br />'.
4442: '<input type="text" name="errorweights_'.$type.'" value="'.
4443: $weights{$type}.'" size="5" /></td>';
4444: }
4445: $datatable .= '</tr></table></tr>';
4446: $rownum ++;
4447: $css_class = $rownum%2?' class="LC_odd_row"':'';
4448: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4449: $titles->{'errorexcluded'}.'</td>'.
4450: '<td class="LC_left_item"><table>';
4451: my $numinrow = 4;
4452: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4453: for (my $i=0; $i<@ids; $i++) {
4454: my $rem = $i%($numinrow);
4455: if ($rem == 0) {
4456: if ($i > 0) {
4457: $datatable .= '</tr>';
4458: }
4459: $datatable .= '<tr>';
4460: }
4461: my $check;
4462: if ($excluded{$ids[$i]}) {
4463: $check = ' checked="checked" ';
4464: }
4465: $datatable .= '<td class="LC_left_item">'.
4466: '<span class="LC_nobreak"><label>'.
4467: '<input type="checkbox" name="errorexcluded" '.
4468: 'value="'.$ids[$i].'"'.$check.' />'.
4469: $ids[$i].'</label></span></td>';
4470: }
4471: my $colsleft = $numinrow - @ids%($numinrow);
4472: if ($colsleft > 1 ) {
4473: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4474: ' </td>';
4475: } elsif ($colsleft == 1) {
4476: $datatable .= '<td class="LC_left_item"> </td>';
4477: }
4478: $datatable .= '</tr></table></td></tr>';
4479: $rownum ++;
1.160.6.78 raeburn 4480: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4481: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4482: my (@posstypes,%usertypeshash);
4483: if (ref($types) eq 'ARRAY') {
4484: @posstypes = @{$types};
4485: }
4486: if (@posstypes) {
4487: if (ref($usertypes) eq 'HASH') {
4488: %usertypeshash = %{$usertypes};
4489: }
4490: my @overridden;
4491: my $numinrow = 4;
4492: if (ref($settings) eq 'HASH') {
4493: if (ref($settings->{'overrides'}) eq 'HASH') {
4494: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4495: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4496: push(@overridden,$key);
4497: foreach my $item (@contacts) {
4498: if ($settings->{'overrides'}{$key}{$item}) {
4499: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4500: }
4501: }
4502: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4503: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4504: $includeloc{'override_'.$key} = '';
4505: $includestr{'override_'.$key} = '';
4506: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4507: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4508: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4509: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4510: }
1.160.6.78 raeburn 4511: }
4512: }
4513: }
1.160.6.101 raeburn 4514: }
4515: my $customclass = 'LC_helpdesk_override';
4516: my $optionsprefix = 'LC_options_helpdesk_';
4517:
4518: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4519: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4520: $numinrow,$othertitle,'overrides',
4521: \$rownum,$onclicktypes,$customclass);
4522: $rownum ++;
4523: $usertypeshash{'default'} = $othertitle;
4524: foreach my $status (@posstypes) {
4525: my $css_class;
4526: if ($rownum%2) {
4527: $css_class = 'LC_odd_row ';
4528: }
4529: $css_class .= $customclass;
4530: my $rowid = $optionsprefix.$status;
4531: my $hidden = 1;
4532: my $currstyle = 'display:none';
4533: if (grep(/^\Q$status\E$/,@overridden)) {
4534: $currstyle = 'display:table-row';
4535: $hidden = 0;
4536: }
4537: my $key = 'override_'.$status;
4538: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4539: $includeloc{$key},$includestr{$key},$status,$rowid,
4540: $usertypeshash{$status},$css_class,$currstyle,
4541: \@contacts,$short_titles);
4542: unless ($hidden) {
4543: $rownum ++;
1.160.6.78 raeburn 4544: }
4545: }
1.134 raeburn 4546: }
1.28 raeburn 4547: }
1.30 raeburn 4548: $$rowtotal += $rownum;
1.28 raeburn 4549: return $datatable;
4550: }
4551:
1.160.6.107 raeburn 4552: sub core_link_msu {
4553: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4554: &mt('LON-CAPA core group - MSU'),600,500);
4555: }
4556:
1.160.6.101 raeburn 4557: sub overridden_helpdesk {
4558: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4559: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4560: my $class = 'LC_left_item';
4561: if ($css_class) {
4562: $css_class = ' class="'.$css_class.'"';
4563: }
4564: if ($rowid) {
4565: $rowid = ' id="'.$rowid.'"';
4566: }
4567: if ($rowstyle) {
4568: $rowstyle = ' style="'.$rowstyle.'"';
4569: }
4570: my ($output,$description);
4571: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4572: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4573: "<td>$description</td>\n".
4574: '<td class="'.$class.'" colspan="2">'.
4575: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4576: '<span class="LC_nobreak">';
4577: if (ref($contacts) eq 'ARRAY') {
4578: foreach my $item (@{$contacts}) {
4579: my $check;
4580: if (ref($checked) eq 'HASH') {
4581: $check = $checked->{$item};
4582: }
4583: my $title;
4584: if (ref($short_titles) eq 'HASH') {
4585: $title = $short_titles->{$item};
4586: }
4587: $output .= '<label>'.
4588: '<input type="checkbox" name="override_'.$type.'"'.$check.
4589: ' value="'.$item.'" />'.$title.'</label> ';
4590: }
4591: }
4592: $output .= '</span><br />'.&mt('Others').': '.
4593: '<input type="text" name="override_'.$type.'_others" '.
4594: 'value="'.$otheremails.'" />';
4595: my %locchecked;
4596: foreach my $loc ('s','b') {
4597: if ($includeloc eq $loc) {
4598: $locchecked{$loc} = ' checked="checked"';
4599: last;
4600: }
4601: }
4602: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4603: '<input type="text" name="override_'.$type.'_bcc" '.
4604: 'value="'.$bccemails.'" /></fieldset>'.
4605: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4606: &mt('Text automatically added to e-mail:').' '.
4607: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4608: '<span class="LC_nobreak">'.&mt('Location:').' '.
4609: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4610: (' 'x2).
4611: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4612: '</span></fieldset>'.
4613: '</td></tr>'."\n";
4614: return $output;
4615: }
4616:
1.160.6.78 raeburn 4617: sub contacts_javascript {
4618: return <<"ENDSCRIPT";
4619:
4620: <script type="text/javascript">
4621: // <![CDATA[
4622:
4623: function screenshotSize(field) {
4624: if (document.getElementById('help_screenshotsize')) {
4625: if (field.value == 'no') {
4626: document.getElementById('help_screenshotsize').style.display="none";
4627: } else {
4628: document.getElementById('help_screenshotsize').style.display="";
4629: }
4630: }
4631: return;
4632: }
4633:
1.160.6.101 raeburn 4634: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4635: if (form.elements[checkbox].length != undefined) {
4636: var count = 0;
4637: if (docount) {
4638: for (var i=0; i<form.elements[checkbox].length; i++) {
4639: if (form.elements[checkbox][i].checked) {
4640: count ++;
4641: }
4642: }
4643: }
4644: for (var i=0; i<form.elements[checkbox].length; i++) {
4645: var type = form.elements[checkbox][i].value;
4646: if (document.getElementById(prefix+type)) {
4647: if (form.elements[checkbox][i].checked) {
4648: document.getElementById(prefix+type).style.display = 'table-row';
4649: if (count % 2 == 1) {
4650: document.getElementById(prefix+type).className = target+' LC_odd_row';
4651: } else {
4652: document.getElementById(prefix+type).className = target;
4653: }
4654: count ++;
4655: } else {
4656: document.getElementById(prefix+type).style.display = 'none';
4657: }
4658: }
4659: }
4660: }
4661: return;
4662: }
4663:
1.160.6.78 raeburn 4664: // ]]>
4665: </script>
4666:
4667: ENDSCRIPT
4668: }
4669:
1.118 jms 4670: sub print_helpsettings {
1.160.6.73 raeburn 4671: my ($position,$dom,$settings,$rowtotal) = @_;
4672: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4673: my $formname = 'display';
1.160.6.5 raeburn 4674: my ($datatable,$itemcount);
1.160.6.73 raeburn 4675: if ($position eq 'top') {
4676: $itemcount = 1;
4677: my (%choices,%defaultchecked,@toggles);
4678: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4679: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4680: &mt('LON-CAPA bug tracker'),600,500));
4681: %defaultchecked = ('submitbugs' => 'on');
4682: @toggles = ('submitbugs');
4683: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4684: \%choices,$itemcount);
4685: $$rowtotal ++;
4686: } else {
4687: my $css_class;
4688: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4689: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4690: if (ref($settings) eq 'HASH') {
4691: if (ref($settings->{'adhoc'}) eq 'HASH') {
4692: %current = %{$settings->{'adhoc'}};
4693: }
1.160.6.77 raeburn 4694: }
4695: my $count = 0;
4696: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4697: if ($key=~/^rolesdef\_(\w+)$/) {
4698: my $rolename = $1;
1.160.6.77 raeburn 4699: my (%privs,$order);
1.160.6.73 raeburn 4700: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4701: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4702: if (ref($current{$rolename}) eq 'HASH') {
4703: $order = $current{$rolename}{'order'};
4704: }
4705: if ($order eq '') {
4706: $order = $count;
4707: }
4708: $ordered{$order} = $rolename;
4709: $count++;
1.160.6.73 raeburn 4710: }
4711: }
1.160.6.77 raeburn 4712: my $maxnum = scalar(keys(%ordered));
4713: my @roles_by_num = ();
4714: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4715: push(@roles_by_num,$item);
4716: }
4717: my $context = 'domprefs';
4718: my $crstype = 'Course';
4719: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4720: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4721: my ($numstatustypes,@jsarray);
4722: if (ref($types) eq 'ARRAY') {
4723: if (@{$types} > 0) {
4724: $numstatustypes = scalar(@{$types});
4725: push(@accesstypes,'status');
4726: @jsarray = ('bystatus');
4727: }
4728: }
1.160.6.86 raeburn 4729: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4730: if (keys(%domhelpdesk)) {
4731: push(@accesstypes,('inc','exc'));
4732: push(@jsarray,('notinc','notexc'));
4733: }
4734: my $hiddenstr = join("','",@jsarray);
1.160.6.73 raeburn 4735: my $context = 'domprefs';
4736: my $crstype = 'Course';
1.160.6.77 raeburn 4737: my $prefix = 'helproles_';
4738: my $add_class = 'LC_hidden';
4739: foreach my $num (@roles_by_num) {
4740: my $role = $ordered{$num};
4741: my ($desc,$access,@statuses);
4742: if (ref($current{$role}) eq 'HASH') {
4743: $desc = $current{$role}{'desc'};
4744: $access = $current{$role}{'access'};
4745: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4746: @statuses = @{$current{$role}{'insttypes'}};
4747: }
4748: }
4749: if ($desc eq '') {
4750: $desc = $role;
4751: }
4752: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4753: my %full=();
4754: my %levels= (
4755: course => {},
4756: domain => {},
4757: system => {},
4758: );
4759: my %levelscurrent=(
4760: course => {},
4761: domain => {},
4762: system => {},
4763: );
4764: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4765: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4766: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4767: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4768: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4769: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4770: for (my $k=0; $k<=$maxnum; $k++) {
4771: my $vpos = $k+1;
4772: my $selstr;
4773: if ($k == $num) {
4774: $selstr = ' selected="selected" ';
4775: }
4776: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4777: }
4778: $datatable .= '</select>'.(' 'x2).
4779: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4780: '</td>'.
4781: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4782: &mt('Name shown to users:').
4783: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4784: '</fieldset>'.
4785: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4786: $othertitle,$usertypes,$types,\%domhelpdesk).
4787: '<fieldset>'.
4788: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4789: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4790: \%levelscurrent,$identifier,
4791: 'LC_hidden',$prefix.$num.'_privs').
4792: '</fieldset></td>';
1.160.6.73 raeburn 4793: $itemcount ++;
4794: }
4795: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4796: my $newcust = 'custhelp'.$count;
4797: my (%privs,%levelscurrent);
4798: my %full=();
4799: my %levels= (
4800: course => {},
4801: domain => {},
4802: system => {},
4803: );
4804: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4805: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4806: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4807: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4808: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4809: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4810: for (my $k=0; $k<$maxnum+1; $k++) {
4811: my $vpos = $k+1;
4812: my $selstr;
4813: if ($k == $maxnum) {
4814: $selstr = ' selected="selected" ';
4815: }
4816: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4817: }
4818: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4819: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4820: '</label></span></td>'.
1.160.6.77 raeburn 4821: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4822: '<span class="LC_nobreak">'.
4823: &mt('Internal name:').
4824: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4825: '</span>'.(' 'x4).
4826: '<span class="LC_nobreak">'.
4827: &mt('Name shown to users:').
4828: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4829: '</span></fieldset>'.
4830: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4831: $usertypes,$types,\%domhelpdesk).
4832: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4833: &Apache::lonuserutils::custom_role_header($context,$crstype,
4834: \@templateroles,$newcust).
4835: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4836: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4837: '</fieldset>'.
4838: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4839: '</td></tr>';
1.160.6.73 raeburn 4840: $count ++;
4841: $$rowtotal += $count;
4842: }
1.160.6.5 raeburn 4843: return $datatable;
1.121 raeburn 4844: }
4845:
1.160.6.77 raeburn 4846: sub adhocbutton {
4847: my ($prefix,$num,$field,$visibility) = @_;
4848: my %lt = &Apache::lonlocal::texthash(
4849: show => 'Show details',
4850: hide => 'Hide details',
4851: );
4852: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4853: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4854: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4855: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4856: }
4857:
4858: sub helpsettings_javascript {
4859: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4860: return unless(ref($roles_by_num) eq 'ARRAY');
4861: my %html_js_lt = &Apache::lonlocal::texthash(
4862: show => 'Show details',
4863: hide => 'Hide details',
4864: );
4865: &html_escape(\%html_js_lt);
4866: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4867: return <<"ENDSCRIPT";
4868: <script type="text/javascript">
4869: // <![CDATA[
4870:
4871: function reorderHelpRoles(form,item) {
4872: var changedVal;
4873: $jstext
4874: var newpos = 'helproles_${total}_pos';
4875: var maxh = 1 + $total;
4876: var current = new Array();
4877: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4878: if (item == newpos) {
4879: changedVal = newitemVal;
4880: } else {
4881: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4882: current[newitemVal] = newpos;
4883: }
4884: for (var i=0; i<helproles.length; i++) {
4885: var elementName = 'helproles_'+helproles[i]+'_pos';
4886: if (elementName != item) {
4887: if (form.elements[elementName]) {
4888: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4889: current[currVal] = elementName;
4890: }
4891: }
4892: }
4893: var oldVal;
4894: for (var j=0; j<maxh; j++) {
4895: if (current[j] == undefined) {
4896: oldVal = j;
4897: }
4898: }
4899: if (oldVal < changedVal) {
4900: for (var k=oldVal+1; k<=changedVal ; k++) {
4901: var elementName = current[k];
4902: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4903: }
4904: } else {
4905: for (var k=changedVal; k<oldVal; k++) {
4906: var elementName = current[k];
4907: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4908: }
4909: }
4910: return;
4911: }
4912:
4913: function helpdeskAccess(num) {
4914: var curraccess = null;
4915: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4916: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4917: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4918: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4919: }
4920: }
4921: }
4922: var shown = Array();
4923: var hidden = Array();
4924: if (curraccess == 'none') {
4925: hidden = Array('$hiddenstr');
4926: } else {
4927: if (curraccess == 'status') {
4928: shown = Array('bystatus');
4929: hidden = Array('notinc','notexc');
4930: } else {
4931: if (curraccess == 'exc') {
4932: shown = Array('notexc');
4933: hidden = Array('notinc','bystatus');
4934: }
4935: if (curraccess == 'inc') {
4936: shown = Array('notinc');
4937: hidden = Array('notexc','bystatus');
4938: }
1.160.6.79 raeburn 4939: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4940: hidden = Array('notinc','notexc','bystatus');
4941: }
4942: }
4943: }
4944: if (hidden.length > 0) {
4945: for (var i=0; i<hidden.length; i++) {
4946: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4947: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4948: }
4949: }
4950: }
4951: if (shown.length > 0) {
4952: for (var i=0; i<shown.length; i++) {
4953: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4954: if (shown[i] == 'privs') {
4955: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4956: } else {
4957: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4958: }
4959: }
4960: }
4961: }
4962: return;
4963: }
4964:
4965: function toggleHelpdeskItem(num,field) {
4966: if (document.getElementById('helproles_'+num+'_'+field)) {
4967: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4968: document.getElementById('helproles_'+num+'_'+field).className =
4969: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4970: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4971: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4972: }
4973: } else {
4974: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4975: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4976: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4977: }
4978: }
4979: }
4980: return;
4981: }
4982:
4983: // ]]>
4984: </script>
4985:
4986: ENDSCRIPT
4987: }
4988:
4989: sub helpdeskroles_access {
4990: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
4991: $usertypes,$types,$domhelpdesk) = @_;
4992: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
4993: my %lt = &Apache::lonlocal::texthash(
4994: 'rou' => 'Role usage',
4995: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 4996: 'all' => 'All with domain helpdesk or helpdesk assistant role',
4997: 'dh' => 'All with domain helpdesk role',
4998: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 4999: 'none' => 'None',
5000: 'status' => 'Determined based on institutional status',
5001: 'inc' => 'Include all, but exclude specific personnel',
5002: 'exc' => 'Exclude all, but include specific personnel',
5003: );
5004: my %usecheck = (
5005: all => ' checked="checked"',
5006: );
5007: my %displaydiv = (
5008: status => 'none',
5009: inc => 'none',
5010: exc => 'none',
5011: priv => 'block',
5012: );
5013: my $output;
5014: if (ref($current) eq 'HASH') {
5015: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5016: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5017: $usecheck{$current->{access}} = $usecheck{'all'};
5018: delete($usecheck{'all'});
5019: if ($current->{access} =~ /^(status|inc|exc)$/) {
5020: my $access = $1;
5021: $displaydiv{$access} = 'inline';
5022: } elsif ($current->{access} eq 'none') {
5023: $displaydiv{'priv'} = 'none';
5024: }
5025: }
5026: }
5027: }
5028: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5029: '<p>'.$lt{'whi'}.'</p>';
5030: foreach my $access (@{$accesstypes}) {
5031: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5032: ' onclick="helpdeskAccess('."'$num'".');" />'.
5033: $lt{$access}.'</label>';
5034: if ($access eq 'status') {
5035: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5036: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5037: $othertitle,$usertypes,$types).
5038: '</div>';
5039: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5040: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5041: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5042: '</div>';
5043: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5044: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5045: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5046: '</div>';
5047: }
5048: $output .= '</p>';
5049: }
5050: $output .= '</fieldset>';
5051: return $output;
5052: }
5053:
1.121 raeburn 5054: sub radiobutton_prefs {
1.160.6.16 raeburn 5055: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 5056: $additional,$align,$firstval) = @_;
1.121 raeburn 5057: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5058: (ref($choices) eq 'HASH'));
5059:
5060: my (%checkedon,%checkedoff,$datatable,$css_class);
5061:
5062: foreach my $item (@{$toggles}) {
5063: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5064: $checkedon{$item} = ' checked="checked" ';
5065: $checkedoff{$item} = ' ';
1.121 raeburn 5066: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5067: $checkedoff{$item} = ' checked="checked" ';
5068: $checkedon{$item} = ' ';
5069: }
5070: }
5071: if (ref($settings) eq 'HASH') {
1.121 raeburn 5072: foreach my $item (@{$toggles}) {
1.118 jms 5073: if ($settings->{$item} eq '1') {
5074: $checkedon{$item} = ' checked="checked" ';
5075: $checkedoff{$item} = ' ';
5076: } elsif ($settings->{$item} eq '0') {
5077: $checkedoff{$item} = ' checked="checked" ';
5078: $checkedon{$item} = ' ';
5079: }
5080: }
1.121 raeburn 5081: }
1.160.6.16 raeburn 5082: if ($onclick) {
5083: $onclick = ' onclick="'.$onclick.'"';
5084: }
1.121 raeburn 5085: foreach my $item (@{$toggles}) {
1.118 jms 5086: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5087: $datatable .=
1.160.6.16 raeburn 5088: '<tr'.$css_class.'><td valign="top">'.
5089: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 5090: '</span></td>';
5091: if ($align eq 'left') {
5092: $datatable .= '<td class="LC_left_item">';
5093: } else {
5094: $datatable .= '<td class="LC_right_item">';
5095: }
1.160.6.113 raeburn 5096: $datatable .= '<span class="LC_nobreak">';
5097: if ($firstval eq 'no') {
5098: $datatable .=
5099: '<label><input type="radio" name="'.
5100: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5101: '</label> <label><input type="radio" name="'.$item.'" '.
5102: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5103: } else {
5104: $datatable .=
1.160.6.118.2 14(raebu 5105:23): '<label><input type="radio" name="'.
5106:23): $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5107:23): '</label> <label><input type="radio" name="'.$item.'" '.
5108:23): $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
1.160.6.113 raeburn 5109: }
5110: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5111: $itemcount ++;
1.121 raeburn 5112: }
5113: return ($datatable,$itemcount);
5114: }
5115:
1.160.6.118.2 1(raebur 5116:1): sub print_ltitools {
14(raebu 5117:23): my ($position,$dom,$settings,$rowtotal) = @_;
5118:23): my (%rules,%encrypt,%privkeys,%linkprot);
1(raebur 5119:1): if (ref($settings) eq 'HASH') {
14(raebu 5120:23): if ($position eq 'top') {
5121:23): if (exists($settings->{'encrypt'})) {
5122:23): if (ref($settings->{'encrypt'}) eq 'HASH') {
5123:23): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5124:23): $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1(raebur 5125:1): }
5126:1): }
5127:1): }
14(raebu 5128:23): if (exists($settings->{'private'})) {
5129:23): if (ref($settings->{'private'}) eq 'HASH') {
5130:23): if (ref($settings->{'private'}) eq 'HASH') {
5131:23): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5132:23): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1(raebur 5133:1): }
5134:1): }
5135:1): }
5136:1): }
14(raebu 5137:23): } elsif ($position eq 'middle') {
5138:23): if (exists($settings->{'rules'})) {
5139:23): if (ref($settings->{'rules'}) eq 'HASH') {
5140:23): %rules = %{$settings->{'rules'}};
1(raebur 5141:1): }
5142:1): }
14(raebu 5143:23): } else {
5144:23): foreach my $key ('encrypt','private','rules') {
5145:23): if (exists($settings->{$key})) {
5146:23): delete($settings->{$key});
1(raebur 5147:1): }
5148:1): }
5149:1): }
5150:1): }
14(raebu 5151:23): my $datatable;
5152:23): my $itemcount = 1;
5153:23): if ($position eq 'top') {
5154:23): $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5155:23): } elsif ($position eq 'middle') {
5156:23): $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5157:23): $$rowtotal += $itemcount;
5158:23): } else {
5159:23): $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1(raebur 5160:1): }
5161:1): return $datatable;
5162:1): }
5163:1):
5164:1): sub ltitools_names {
5165:1): my %lt = &Apache::lonlocal::texthash(
5166:1): 'title' => 'Title',
5167:1): 'version' => 'Version',
5168:1): 'msgtype' => 'Message Type',
5169:1): 'sigmethod' => 'Signature Method',
5170:1): 'url' => 'URL',
5171:1): 'key' => 'Key',
5172:1): 'lifetime' => 'Nonce lifetime (s)',
5173:1): 'secret' => 'Secret',
5174:1): 'icon' => 'Icon',
5175:1): 'user' => 'User',
5176:1): 'fullname' => 'Full Name',
5177:1): 'firstname' => 'First Name',
5178:1): 'lastname' => 'Last Name',
5179:1): 'email' => 'E-mail',
5180:1): 'roles' => 'Role',
5181:1): 'window' => 'Window',
5182:1): 'tab' => 'Tab',
5183:1): 'iframe' => 'iFrame',
5184:1): 'height' => 'Height',
5185:1): 'width' => 'Width',
5186:1): 'linktext' => 'Default Link Text',
5187:1): 'explanation' => 'Default Explanation',
14(raebu 5188:23): 'passback' => 'Tool can return grades:',
5189:23): 'roster' => 'Tool can retrieve roster:',
1(raebur 5190:1): 'crstarget' => 'Display target',
5191:1): 'crslabel' => 'Course label',
5192:1): 'crstitle' => 'Course title',
5193:1): 'crslinktext' => 'Link Text',
5194:1): 'crsexplanation' => 'Explanation',
5195:1): 'crsappend' => 'Provider URL',
5196:1): );
5197:1): return %lt;
5198:1): }
5199:1):
14(raebu 5200:23): sub secrets_form {
5201:23): my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5202:23): my @ids=&Apache::lonnet::current_machine_ids();
5203:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
5204:23): my $primary = &Apache::lonnet::domain($dom,'primary');
5205:23): my ($css_class,$extra,$numshown,$itemcount,$output);
5206:23): $itemcount = 0;
5207:23): foreach my $hostid (sort(keys(%servers))) {
5208:23): my ($showextra,$divsty,$switch);
5209:23): if ($hostid eq $primary) {
5210:23): if ($context eq 'ltisec') {
5211:23): if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5212:23): $showextra = 1;
5213:23): }
5214:23): if ($encrypt->{'ltisec_crslinkprot'}) {
5215:23): $showextra = 1;
5216:23): }
5217:23): } else {
5218:23): if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5219:23): $showextra = 1;
5220:23): }
5221:23): }
5222:23): unless (grep(/^\Q$hostid\E$/,@ids)) {
5223:23): $switch = 1;
5224:23): }
5225:23): if ($showextra) {
5226:23): $numshown ++;
5227:23): $divsty = 'display:inline-block';
5228:23): } else {
5229:23): $divsty = 'display:none';
5230:23): }
5231:23): $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5232:23): '<legend>'.$hostid.'</legend>';
5233:23): if ($switch) {
5234:23): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5235:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5236:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5237:23): if (exists($privkeys->{$hostid})) {
5238:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5239:23): '<span class="LC_nobreak">'.
5240:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5241:23): '<span class="LC_nobreak">'.&mt('Change?').
5242:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5243:23): (' 'x2).
5244:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5245:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5246:23): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5247:23): '</span></div>';
5248:23): } else {
5249:23): $extra .= '<span class="LC_nobreak">'.
5250:23): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5251:23): '</span>'."\n";
5252:23): }
5253:23): } elsif (exists($privkeys->{$hostid})) {
5254:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5255:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5256:23): '<span class="LC_nobreak">'.&mt('Change?').
5257:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5258:23): (' 'x2).
5259:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5260:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5261:23): '<span class="LC_nobreak">'.&mt('New Key').':'.
5262:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5263: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>'.
5264:23): '</span></div>';
5265:23): } else {
5266:23): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5267:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5268: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>';
5269:23): }
5270:23): $extra .= '</fieldset>';
5271:23): }
5272:23): }
5273:23): my (%choices,@toggles,%defaultchecked);
5274:23): if ($context eq 'ltisec') {
5275:23): %choices = &Apache::lonlocal::texthash (
5276:23): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5277:23): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5278:23): ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5279:23): );
5280:23): @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5281:23): %defaultchecked = (
5282:23): 'ltisec_crslinkprot' => 'off',
5283:23): 'ltisec_domlinkprot' => 'off',
5284:23): 'ltisec_consumers' => 'off',
5285:23): );
5286:23): } else {
5287:23): %choices = &Apache::lonlocal::texthash (
5288:23): toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5289:23): toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5290:23): );
5291:23): @toggles = qw(toolsec_crs toolsec_dom);
5292:23): %defaultchecked = (
5293:23): 'toolsec_crs' => 'off',
5294:23): 'toolsec_dom' => 'off',
5295:23): );
5296:23): }
5297:23): my ($onclick,$itemcount);
5298:23): $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5299:23): ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5300:23): \%choices,$itemcount,$onclick,'','left','no');
5301:23):
5302:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5303:23): my $noprivkeysty = 'display:inline-block';
5304:23): if ($numshown) {
5305:23): $noprivkeysty = 'display:none';
5306:23): }
5307:23): $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5308:23): '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5309:23): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5310:23): $extra.
5311:23): '</td></tr>';
5312:23): $itemcount ++;
5313:23): $$rowtotal += $itemcount;
5314:23): return $output;
5315:23): }
5316:23):
5(raebur 5317:2): sub print_lti {
5318:2): my ($position,$dom,$settings,$rowtotal) = @_;
5319:2): my $itemcount = 1;
5320:2): my ($datatable,$css_class);
18(raebu 5321:24): my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
5(raebur 5322:2): if (ref($settings) eq 'HASH') {
5323:2): if ($position eq 'top') {
5324:2): if (exists($settings->{'encrypt'})) {
5325:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5326:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
14(raebu 5327:23): if ($key eq 'consumers') {
5328:23): $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5329:23): } else {
5330:23): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5331:23): }
5(raebur 5332:2): }
5333:2): }
5334:2): }
5335:2): if (exists($settings->{'private'})) {
5336:2): if (ref($settings->{'private'}) eq 'HASH') {
5337:2): if (ref($settings->{'private'}) eq 'HASH') {
5338:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5339:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5340:2): }
5341:2): }
5342:2): }
5343:2): }
18(raebu 5344:24): } elsif ($position eq 'upper') {
5(raebur 5345:2): if (exists($settings->{'rules'})) {
5346:2): if (ref($settings->{'rules'}) eq 'HASH') {
5347:2): %rules = %{$settings->{'rules'}};
5348:2): }
5349:2): }
18(raebu 5350:24): } elsif ($position eq 'middle') {
5351:24): if (exists($settings->{'suggested'})) {
5352:24): if (ref($settings->{'suggested'}) eq 'HASH') {
5353:24): %suggestions = %{$settings->{'suggested'}};
5354:24): }
5355:24): }
14(raebu 5356:23): } elsif ($position eq 'lower') {
5(raebur 5357:2): if (exists($settings->{'linkprot'})) {
5358:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5359:2): %linkprot = %{$settings->{'linkprot'}};
5360:2): if ($linkprot{'lock'}) {
5361:2): delete($linkprot{'lock'});
5362:2): }
5363:2): }
5364:2): }
14(raebu 5365:23): } else {
18(raebu 5366:24): foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
14(raebu 5367:23): if (exists($settings->{$key})) {
5368:23): delete($settings->{$key});
5369:23): }
5370:23): }
5(raebur 5371:2): }
5372:2): }
5373:2): if ($position eq 'top') {
14(raebu 5374:23): $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
18(raebu 5375:24): } elsif ($position eq 'upper') {
14(raebu 5376:23): $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5377:23): $$rowtotal += $itemcount;
18(raebu 5378:24): } elsif ($position eq 'middle') {
5379:24): $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
5380:24): $$rowtotal += $itemcount;
14(raebu 5381:23): } elsif ($position eq 'lower') {
18(raebu 5382:24): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
14(raebu 5383:23): } else {
5384:23): my ($switchserver,$switchmessage);
5385:23): $switchserver = &check_switchserver($dom);
5386:23): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5387:23): my $maxnum = 0;
5388:23): my %ordered;
5389:23): if (ref($settings) eq 'HASH') {
5390:23): foreach my $item (keys(%{$settings})) {
5391:23): if (ref($settings->{$item}) eq 'HASH') {
5392:23): my $num = $settings->{$item}{'order'};
5393:23): if ($num eq '') {
5394:23): $num = scalar(keys(%{$settings}));
5395:23): }
5396:23): $ordered{$num} = $item;
5(raebur 5397:2): }
5398:2): }
14(raebu 5399:23): }
5400:23): $maxnum = scalar(keys(%ordered));
5401:23): my %lt = <i_names();
5402:23): if (keys(%ordered)) {
5403:23): my @items = sort { $a <=> $b } keys(%ordered);
5404:23): for (my $i=0; $i<@items; $i++) {
5405:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5406:23): my $item = $ordered{$items[$i]};
5407:23): my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5408:23): if (ref($settings->{$item}) eq 'HASH') {
5409:23): $key = $settings->{$item}->{'key'};
5410:23): $usable = $settings->{$item}->{'usable'};
5411:23): $lifetime = $settings->{$item}->{'lifetime'};
5412:23): $consumer = $settings->{$item}->{'consumer'};
5413:23): $requser = $settings->{$item}->{'requser'};
5414:23): $crsinc = $settings->{$item}->{'crsinc'};
5415:23): $current = $settings->{$item};
5416:23): }
5417:23): my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5418:23): my %checkedrequser = (
5419:23): yes => ' checked="checked"',
5420:23): no => '',
5421:23): );
5422:23): if (!$requser) {
5423:23): $checkedrequser{'no'} = $checkedrequser{'yes'};
5424:23): $checkedrequser{'yes'} = '';
5425:23): }
5426:23): my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5427:23): my %checkedcrsinc = (
5428:23): yes => ' checked="checked"',
5429:23): no => '',
5430:23): );
5431:23): if (!$crsinc) {
5432:23): $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5433:23): $checkedcrsinc{'yes'} = '';
5434:23): }
5435:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5436:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5437:23): .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5438:23): for (my $k=0; $k<=$maxnum; $k++) {
5439:23): my $vpos = $k+1;
5440:23): my $selstr;
5441:23): if ($k == $i) {
5442:23): $selstr = ' selected="selected" ';
5443:23): }
5444:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5445:23): }
5446:23): $datatable .= '</select>'.(' 'x2).
5447:23): '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5448:23): &mt('Delete?').'</label></span></td>'.
5449:23): '<td colspan="2">'.
5450:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5451:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5452:23): ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5453:23): (' 'x2).
5454:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5455:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5456:23): (' 'x2).
5457:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5458:23): 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5459:23): if ($key ne '') {
5460:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5461:23): if ($switchserver) {
5462:23): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5463:23): } else {
5464:23): $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5465:23): }
5466:23): $datatable .= '</span> '.(' 'x2);
5467:23): } elsif (!$switchserver) {
5468:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5469:23): '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5470:23): '</span> '.(' 'x2);
5471:23): }
5472:23): if ($switchserver) {
5473:23): if ($usable ne '') {
5474:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5475:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5476:23): '<span class="LC_nobreak">'.&mt('Change secret?').
5477:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5478:23): (' 'x2).
5479:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5480:23): '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5481:23): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5482:23): '</div>';
5483:23): } elsif ($key eq '') {
5484:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5485:23): } else {
5486:23): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5487:23): }
5488:23): } else {
5489:23): if ($usable ne '') {
5490:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5491:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5492:23): '<span class="LC_nobreak">'.&mt('Change?').
5493:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5494:23): (' 'x2).
5495:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5496:23): '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5497:23): '<span class="LC_nobreak">'.&mt('New Secret').':'.
5498:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5499: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>';
5500:23): } else {
5501:23): $datatable .=
5502:23): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5503:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5504: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>';
5505:23): }
5506:23): }
5507:23): $datatable .= '<br /><br />'.
5508:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5509:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5510:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5511:23): '<br /><br />'.
5512:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5513:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5514:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5515:23): (' 'x4).
5516:23): '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5517:23): '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5518:23): $itemcount ++;
5(raebur 5519:2): }
14(raebu 5520:23): }
5521:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5522:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5523:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5524:23): '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5525:23): '<select name="lti_pos_add"'.$chgstr.'>';
5526:23): for (my $k=0; $k<$maxnum+1; $k++) {
5527:23): my $vpos = $k+1;
5528:23): my $selstr;
5529:23): if ($k == $maxnum) {
5530:23): $selstr = ' selected="selected" ';
5(raebur 5531:2): }
14(raebu 5532:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5533:23): }
5534:23): $datatable .= '</select> '."\n".
5535:23): '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5536:23): '<td colspan="2">'.
5537:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5538:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5539:23): ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5540:23): (' 'x2).
5541:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5542:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5543:23): (' 'x2).
5544:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5545:23): if ($switchserver) {
5546:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5547:23): } else {
5548:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5549:23): (' 'x2).
5550:23): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5551: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";
5552:23): }
5553:23): $datatable .= '<br /><br />'.
5554:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5555:23): '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5556:23): '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5557:23): '<br /><br />'.
5558:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5559:23): '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5560:23): '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5561:23): '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5562:23): '</td>'."\n".
5563:23): '</tr>'."\n";
5564:23): $itemcount ++;
5565:23): }
5566:23): $$rowtotal += $itemcount;
5567:23): return $datatable;
5568:23): }
5569:23):
5570:23): sub lti_names {
5571:23): my %lt = &Apache::lonlocal::texthash(
5572:23): 'version' => 'LTI Version',
5573:23): 'url' => 'URL',
5574:23): 'key' => 'Key',
5575:23): 'lifetime' => 'Nonce lifetime (s)',
5576:23): 'consumer' => 'Consumer',
5577:23): 'secret' => 'Secret',
5578:23): 'requser' => "User's identity sent",
5579:23): 'crsinc' => "Course's identity sent",
5580:23): 'email' => 'Email address',
5581:23): 'sourcedid' => 'User ID',
5582:23): 'other' => 'Other',
5583:23): 'passback' => 'Can return grades to Consumer:',
5584:23): 'roster' => 'Can retrieve roster from Consumer:',
5585:23): 'topmenu' => 'Display LON-CAPA page header',
5586:23): 'inlinemenu'=> 'Display LON-CAPA inline menu',
5587:23): );
5588:23): return %lt;
5589:23): }
5590:23):
5591:23): sub lti_options {
5592:23): my ($num,$current,$itemcount,%lt) = @_;
5593:23): my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5594:23): $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5595:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5596:23): $checked{'storecrs'}{'Y'} = ' checked="checked"';
5597:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5598:23): $checked{'mapcrstype'} = {};
5599:23): $checked{'makeuser'} = {};
5600:23): $checked{'selfenroll'} = {};
5601:23): $checked{'crssec'} = {};
5602:23): $checked{'crssecsrc'} = {};
5603:23): $checked{'lcauth'} = {};
5604:23): $checked{'menuitem'} = {};
5605:23): if ($num eq 'add') {
5606:23): $checked{'lcauth'}{'lti'} = ' checked="checked"';
5607:23): }
5608:23): my $userfieldsty = 'none';
5609:23): my $crsfieldsty = 'none';
5610:23): my $crssecfieldsty = 'none';
5611:23): my $secsrcfieldsty = 'none';
5612:23): my $callbacksty = 'none';
5613:23): my $passbacksty = 'none';
5614:23): my $optionsty = 'block';
5615:23): my $crssty = 'block';
5616:23): my $lcauthparm;
5617:23): my $lcauthparmstyle = 'display:none';
5618:23): my $lcauthparmtext;
5619:23): my $menusty;
5620:23): my $numinrow = 4;
5621:23): my %menutitles = <imenu_titles();
5622:23):
5623:23): if (ref($current) eq 'HASH') {
5624:23): if (!$current->{'requser'}) {
5625:23): $optionsty = 'none';
5626:23): $crssty = 'none';
5627:23): } elsif (!$current->{'crsinc'}) {
5628:23): $crssty = 'none';
5629:23): }
5630:23): if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5631:23): $checked{'mapuser'}{'sourcedid'} = '';
5632:23): if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5633:23): $checked{'mapuser'}{'email'} = ' checked="checked"';
5(raebur 5634:2): } else {
14(raebu 5635:23): $checked{'mapuser'}{'other'} = ' checked="checked"';
5636:23): $userfield = $current->{'mapuser'};
5637:23): $userfieldsty = 'inline-block';
5(raebur 5638:2): }
14(raebu 5639:23): }
5640:23): if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5641:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5642:23): if ($current->{'mapcrs'} eq 'context_id') {
5643:23): $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5644:23): } else {
5645:23): $checked{'mapcrs'}{'other'} = ' checked="checked"';
5646:23): $cidfield = $current->{'mapcrs'};
5647:23): $crsfieldsty = 'inline-block';
5648:23): }
5649:23): }
5650:23): if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5651:23): foreach my $type (@{$current->{'mapcrstype'}}) {
5652:23): $checked{'mapcrstype'}{$type} = ' checked="checked"';
5653:23): }
5654:23): }
5655:23): if (!$current->{'storecrs'}) {
5656:23): $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5657:23): $checked{'storecrs'}{'Y'} = '';
5658:23): }
5659:23): if ($current->{'makecrs'}) {
5660:23): $checked{'makecrs'}{'Y'} = ' checked="checked"';
5661:23): }
5662:23): if (ref($current->{'makeuser'}) eq 'ARRAY') {
5663:23): foreach my $role (@{$current->{'makeuser'}}) {
5664:23): $checked{'makeuser'}{$role} = ' checked="checked"';
5665:23): }
5666:23): }
5667:23): if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5668:23): $checked{'lcauth'}{$1} = ' checked="checked"';
5669:23): unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5670:23): $lcauthparm = $current->{'lcauthparm'};
5671:23): $lcauthparmstyle = 'display:table-row';
5672:23): if ($current->{'lcauth'} eq 'localauth') {
5673:23): $lcauthparmtext = &mt('Local auth argument');
5(raebur 5674:2): } else {
14(raebu 5675:23): $lcauthparmtext = &mt('Kerberos domain');
5(raebur 5676:2): }
14(raebu 5677:23): }
5678:23): }
5679:23): if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5680:23): foreach my $role (@{$current->{'selfenroll'}}) {
5681:23): $checked{'selfenroll'}{$role} = ' checked="checked"';
5682:23): }
5683:23): }
5684:23): if (ref($current->{'maproles'}) eq 'HASH') {
5685:23): %rolemaps = %{$current->{'maproles'}};
5686:23): }
5687:23): if ($current->{'section'} ne '') {
5688:23): $checked{'crssec'}{'Y'} = ' checked="checked"';
5689:23): $crssecfieldsty = 'inline-block';
5690:23): if ($current->{'section'} eq 'course_section_sourcedid') {
5691:23): $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5(raebur 5692:2): } else {
14(raebu 5693:23): $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5694:23): $crssecsrc = $current->{'section'};
5695:23): $secsrcfieldsty = 'inline-block';
5(raebur 5696:2): }
14(raebu 5697:23): } else {
5698:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5(raebur 5699:2): }
14(raebu 5700:23): if ($current->{'callback'} ne '') {
5701:23): $callback = $current->{'callback'};
5702:23): $checked{'callback'}{'Y'} = ' checked="checked"';
5703:23): $callbacksty = 'inline-block';
5704:23): } else {
5705:23): $checked{'callback'}{'N'} = ' checked="checked"';
5706:23): }
5707:23): if ($current->{'topmenu'}) {
5708:23): $checked{'topmenu'}{'Y'} = ' checked="checked"';
5709:23): } else {
5710:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5711:23): }
5712:23): if ($current->{'inlinemenu'}) {
5713:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5714:23): } else {
5715:23): $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5716:23): }
5717:23): if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5718:23): $menusty = 'inline-block';
5719:23): if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5720:23): foreach my $item (@{$current->{'lcmenu'}}) {
5721:23): if (exists($menutitles{$item})) {
5722:23): $checked{'menuitem'}{$item} = ' checked="checked"';
5723:23): }
5724:23): }
5725:23): }
5726:23): } else {
5727:23): $menusty = 'none';
5728:23): }
5729:23): } else {
5730:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5731:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5732:23): $checked{'callback'}{'N'} = ' checked="checked"';
5733:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5734:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5735:23): $checked{'menuitem'}{'grades'} = ' checked="checked"';
5736:23): $menusty = 'inline-block';
5(raebur 5737:2): }
14(raebu 5738:23): my @coursetypes = ('official','unofficial','community','textbook','lti');
5739:23): my %coursetypetitles = &Apache::lonlocal::texthash (
5740:23): official => 'Official',
5741:23): unofficial => 'Unofficial',
5742:23): community => 'Community',
5743:23): textbook => 'Textbook',
5744:23): lti => 'LTI Provider',
5745:23): );
5746:23): my @authtypes = ('internal','krb4','krb5','localauth');
5747:23): my %shortauth = (
5748:23): internal => 'int',
5749:23): krb4 => 'krb4',
5750:23): krb5 => 'krb5',
5751:23): localauth => 'loc'
5752:23): );
5753:23): my %authnames = &authtype_names();
5754:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5755:23): my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5756:23): my @courseroles = ('cc','in','ta','ep','st');
5757:23): my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5758:23): my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5759:23): my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5760:23): my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5761:23): my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5762:23): my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5763:23): my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5764:23): my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5765:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5766:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5767:23): $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5768:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5769:23): $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5770:23): '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5771:23): '<span class="LC_nobreak">'.&mt('Parameter').': '.
5772:23): '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5773:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5774:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5775:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5776:23): foreach my $option ('sourcedid','email','other') {
5777:23): $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5778:23): $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5779:23): ($option eq 'other' ? '' : (' 'x2) );
5780:23): }
5781:23): $output .= '</span></div>'.
5782:23): '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5783:23): '<input type="text" name="lti_customuser_'.$num.'" '.
5784:23): 'value="'.$userfield.'" /></div></fieldset>'.
5785:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5786:23): foreach my $ltirole (@ltiroles) {
5787:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5788:23): $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5789:23): }
5790:23): $output .= '</fieldset>'.
5791:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5792:23): '<table>'.
5793:23): &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5794:23): '</table>'.
5795:23): '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5796:23): '<td class="LC_left_item">';
5797:23): foreach my $auth ('lti',@authtypes) {
5798:23): my $authtext;
5799:23): if ($auth eq 'lti') {
5800:23): $authtext = &mt('None');
5801:23): } else {
5802:23): $authtext = $authnames{$shortauth{$auth}};
5803:23): }
5804:23): $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5805:23): '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5806:23): $authtext.'</label></span> ';
5807:23): }
5808:23): $output .= '</td></tr>'.
5809:23): '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5810:23): '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5811:23): '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5812:23): '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5813:23): '</table></fieldset>'.
5814:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5815:23): &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5816:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5817:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5818:23): $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5819:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5820:23): $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5821:23): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5822:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5823:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5824:23): $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5825:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5826:23): $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5827:23): $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5828:23): '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5829:23): '<span class="LC_nobreak">'.&mt('Menu items').': ';
5830:23): foreach my $type ('fullname','coursetitle','role','logout','grades') {
5831:23): $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5832:23): $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5833:23): (' 'x2);
5834:23): }
5835:23): $output .= '</span></div></fieldset>'.
5836:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5837:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.
5838:23): &mt('Unique course identifier').': ';
5839:23): foreach my $option ('course_offering_sourcedid','context_id','other') {
5840:23): $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5841:23): $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5842:23): ($option eq 'other' ? '' : (' 'x2) );
5843:23): }
5844:23): $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5845:23): '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5846:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5847:23): '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5848:23): foreach my $type (@coursetypes) {
5849:23): $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5850:23): $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5851:23): (' 'x2);
5852:23): }
5853:23): $output .= '</span><br /><br />'.
5854:23): '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5855:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5856:23): $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5857:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5858:23): $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5859:23): '</fieldset>'.
5860:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5861:23): foreach my $ltirole (@lticourseroles) {
5862:23): my ($selected,$selectnone);
5863:23): if ($rolemaps{$ltirole} eq '') {
5864:23): $selectnone = ' selected="selected"';
5865:23): }
5866:23): $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5867:23): '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5868:23): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5869:23): foreach my $role (@courseroles) {
5870:23): unless ($selectnone) {
5871:23): if ($rolemaps{$ltirole} eq $role) {
5872:23): $selected = ' selected="selected"';
5873:23): } else {
5874:23): $selected = '';
5875:23): }
5876:23): }
5877:23): $output .= '<option value="'.$role.'"'.$selected.'>'.
5878:23): &Apache::lonnet::plaintext($role,'Course').
5879:23): '</option>';
5880:23): }
5881:23): $output .= '</select></td>';
5882:23): }
5883:23): $output .= '</tr></table></fieldset>'.
5884:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5885:23): '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5886:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5887:23): $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5888:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5889:23): $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5890:23): '</fieldset>'.
5891:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5892:23): foreach my $lticrsrole (@lticourseroles) {
5893:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5894:23): $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5895:23): }
5896:23): $output .= '</fieldset>'.
5897:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5898:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5899:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5900:23): $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5901:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5902:23): $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5903:23): '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5904:23): '<span class="LC_nobreak">'.&mt('From').':<label>'.
5905:23): '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5906:23): $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5907:23): &mt('Standard field').'</label>'.(' 'x2).
5908:23): '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5909:23): $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5910:23): '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5911:23): '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5912:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5913:23): my ($pb1p1chk,$pb1p0chk,$onclickpb);
5914:23): foreach my $extra ('roster','passback') {
5915:23): my $checkedon = '';
5916:23): my $checkedoff = ' checked="checked"';
5917:23): if ($extra eq 'passback') {
5918:23): $pb1p1chk = ' checked="checked"';
5919:23): $pb1p0chk = '';
5920:23): $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5921:23): } else {
5922:23): $onclickpb = '';
5923:23): }
5924:23): if (ref($current) eq 'HASH') {
5925:23): if (($current->{$extra})) {
5926:23): $checkedon = $checkedoff;
5927:23): $checkedoff = '';
5928:23): if ($extra eq 'passback') {
5929:23): $passbacksty = 'inline-block';
5930:23): }
5931:23): if ($current->{'passbackformat'} eq '1.0') {
5932:23): $pb1p0chk = ' checked="checked"';
5933:23): $pb1p1chk = '';
5934:23): }
5935:23): }
5936:23): }
5937:23): $output .= $lt{$extra}.' '.
5938:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5939:23): &mt('No').'</label>'.(' 'x2).
5940:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5941:23): &mt('Yes').'</label><br />';
5942:23): }
5943:23): $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5944:23): '<span class="LC_nobreak">'.&mt('Grade format').
5945:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5946:23): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5947:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5948:23): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5949:23): '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5950:23): $output .= '</span></div></fieldset>';
5951:23): # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5952:23): #
5953:23): # $output .= '</fieldset>'.
5954:23): # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5955:23): return $output;
5956:23): }
5957:23):
5958:23): sub ltimenu_titles {
5959:23): return &Apache::lonlocal::texthash(
5960:23): fullname => 'Full name',
5961:23): coursetitle => 'Course title',
5962:23): role => 'Role',
5963:23): logout => 'Logout',
5964:23): grades => 'Grades',
5965:23): );
5(raebur 5966:2): }
5967:2):
18(raebu 5968:24): sub linkprot_suggestions {
5969:24): my ($suggested,$itemcount) = @_;
5970:24): my $count = 0;
5971:24): my $next = 1;
5972:24): my %lt = &Apache::lonlocal::texthash(
5973:24): 'name' => 'Suggested Launcher',
5974:24): 'info' => 'Recommendations',
5975:24): );
5976:24): my ($datatable,$css_class,$dest);
5977:24): if (ref($suggested) eq 'HASH') {
5978:24): my @current = sort { $a <=> $b } keys(%{$suggested});
5979:24): $next += $current[-1];
5980:24): for (my $i=0; $i<@current; $i++) {
5981:24): my $num = $current[$i];
5982:24): my %values;
5983:24): if (ref($suggested->{$num}) eq 'HASH') {
5984:24): %values = %{$suggested->{$num}};
5985:24): } else {
5986:24): next;
5987:24): }
5988:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5989:24): $datatable .=
5990:24): '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5991:24): '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
5992:24): &mt('Delete?').'</label></span></td><td>'."\n".
5993:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
5994:24): '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
5995:24): '</fieldset></div>'.
5996:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
5997:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
5998:24): '</fieldset></div>'.
5999:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6000:24): '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6001:24): $$itemcount ++;
6002:24): }
6003:24): }
6004:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6005:24): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6006:24): '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6007:24): '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6008:24): '<td>'."\n".
6009:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6010:24): '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6011:24): '</fieldset></div>'.
6012:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6013:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6014:24): '</fieldset></div>'.
6015:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6016:24): '</td></tr>'."\n";
6017:24): return $datatable;
6018:24): }
14(raebu 6019:23):
1.121 raeburn 6020: sub print_coursedefaults {
1.139 raeburn 6021: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 6022: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6023: my $itemcount = 1;
1.160.6.16 raeburn 6024: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 6025: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.118.2 20(raebu 6026:24): coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.160.6.16 raeburn 6027: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6028: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 6029: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6030: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 6031: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 6032: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 6033: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 6034: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 6035: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 6036:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
14(raebu 6037:23): domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6038:23): exttool => 'External Tools can be defined and configured in courses/communities (by type)',
22(raebu 6039:24): crseditors => 'Available editors for web pages and/or problems created in a course/community',
7(raebur 6040:2): );
1.160.6.21 raeburn 6041: my %staticdefaults = (
6042: anonsurvey_threshold => 10,
6043: uploadquota => 500,
1.160.6.118.2 15(raebu 6044:23): coursequota => 20,
1.160.6.57 raeburn 6045: postsubmit => 60,
1.160.6.70 raeburn 6046: mysqltables => 172800,
1.160.6.118.2 14(raebu 6047:23): domexttool => 1,
6048:23): exttool => 0,
22(raebu 6049:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 6050: );
1.139 raeburn 6051: if ($position eq 'top') {
1.160.6.57 raeburn 6052: %defaultchecked = (
6053: 'uselcmath' => 'on',
6054: 'usejsme' => 'on',
1.160.6.115 raeburn 6055: 'inline_chem' => 'on',
1.160.6.64 raeburn 6056: 'canclone' => 'none',
1.160.6.57 raeburn 6057: );
1.160.6.115 raeburn 6058: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 6059: my $deftex = $Apache::lonnet::deftex;
6060: if (ref($settings) eq 'HASH') {
6061: if ($settings->{'texengine'}) {
6062: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6063: $deftex = $settings->{'texengine'};
6064: }
6065: }
6066: }
6067: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6068: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6069: '<span class="LC_nobreak">'.$choices{'texengine'}.
6070: '</span></td><td class="LC_right_item">'.
6071: '<select name="texengine">'."\n";
6072: my %texoptions = (
6073: MathJax => 'MathJax',
6074: mimetex => &mt('Convert to Images'),
6075: tth => &mt('TeX to HTML'),
6076: );
6077: foreach my $renderer ('MathJax','mimetex','tth') {
6078: my $selected = '';
6079: if ($renderer eq $deftex) {
6080: $selected = ' selected="selected"';
6081: }
6082: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6083: }
6084: $mathdisp .= '</select></td></tr>'."\n";
6085: $itemcount ++;
1.139 raeburn 6086: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6087: \%choices,$itemcount);
1.160.6.90 raeburn 6088: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 6089: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6090: $datatable .=
6091: '<tr'.$css_class.'><td valign="top">'.
6092: '<span class="LC_nobreak">'.$choices{'canclone'}.
6093: '</span></td><td class="LC_left_item">';
6094: my $currcanclone = 'none';
6095: my $onclick;
6096: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 6097: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 6098: none => 'No additional course requesters',
6099: domain => "Any course requester in course's domain",
6100: instcode => 'Course requests for official courses ...',
6101: );
6102: my (%codedefaults,@code_order,@posscodes);
6103: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6104: \@code_order) eq 'ok') {
6105: if (@code_order > 0) {
6106: push(@cloneoptions,'instcode');
6107: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6108: }
6109: }
6110: if (ref($settings) eq 'HASH') {
6111: if ($settings->{'canclone'}) {
6112: if (ref($settings->{'canclone'}) eq 'HASH') {
6113: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6114: if (@code_order > 0) {
6115: $currcanclone = 'instcode';
6116: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6117: }
6118: }
6119: } elsif ($settings->{'canclone'} eq 'domain') {
6120: $currcanclone = $settings->{'canclone'};
6121: }
6122: }
6123: }
6124: foreach my $option (@cloneoptions) {
6125: my ($checked,$additional);
6126: if ($currcanclone eq $option) {
6127: $checked = ' checked="checked"';
6128: }
6129: if ($option eq 'instcode') {
6130: if (@code_order) {
6131: my $show = 'none';
6132: if ($checked) {
6133: $show = 'block';
6134: }
1.160.6.118.2 14(raebu 6135:23): $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.160.6.64 raeburn 6136: &mt('Institutional codes for new and cloned course have identical:').
6137: '<br />';
6138: foreach my $item (@code_order) {
6139: my $codechk;
6140: if ($checked) {
6141: if (grep(/^\Q$item\E$/,@posscodes)) {
6142: $codechk = ' checked="checked"';
6143: }
6144: }
6145: $additional .= '<label>'.
6146: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6147: $item.'</label>';
6148: }
6149: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6150: }
6151: }
6152: $datatable .=
6153: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6154: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6155: '</label> '.$additional.'</span><br />';
6156: }
6157: $datatable .= '</td>'.
6158: '</tr>';
6159: $itemcount ++;
1.139 raeburn 6160: } else {
6161: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.118.2 15(raebu 6162:23): my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6163:23): %deftimeout,%currmysql);
1.160.6.16 raeburn 6164: my $currusecredits = 0;
1.160.6.57 raeburn 6165: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 6166:2): my $ltiauth = 0;
14(raebu 6167:23): my %domexttool;
6168:23): my %exttool;
22(raebu 6169:24): my %crseditors;
1.160.6.30 raeburn 6170: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 6171: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 6172:2): if ($settings->{'ltiauth'}) {
6173:2): $ltiauth = 1;
6174:2): }
14(raebu 6175:23): if (ref($settings->{'domexttool'}) eq 'HASH') {
6176:23): foreach my $type (@types) {
6177:23): if ($settings->{'domexttool'}->{$type}) {
6178:23): $domexttool{$type} = ' checked="checked"';
6179:23): }
6180:23): }
6181:23): } else {
6182:23): foreach my $type (@types) {
6183:23): if ($staticdefaults{'domexttool'}) {
6184:23): $domexttool{$type} = ' checked="checked"';
6185:23): }
6186:23): }
6187:23): }
6188:23): if (ref($settings->{'exttool'}) eq 'HASH') {
6189:23): foreach my $type (@types) {
6190:23): if ($settings->{'exttool'}->{$type}) {
6191:23): $exttool{$type} = ' checked="checked"';
6192:23): }
6193:23): }
6194:23): }
22(raebu 6195:24): if (ref($settings->{'crseditors'}) eq 'ARRAY') {
6196:24): foreach my $editor (@{$settings->{'crseditors'}}) {
6197:24): $crseditors{$editor} = ' checked="checked"';
6198:24): }
6199:24): } else {
6200:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6201:24): $crseditors{$editor} = ' checked="checked"';
6202:24): }
6203:24): }
1.139 raeburn 6204: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 6205: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6206: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6207: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6208: }
6209: }
1.160.6.118.2 15(raebu 6210:23): if (ref($settings->{'coursequota'}) eq 'HASH') {
6211:23): foreach my $type (keys(%{$settings->{'coursequota'}})) {
6212:23): $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6213:23): }
6214:23): }
1.160.6.16 raeburn 6215: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 6216: foreach my $type (@types) {
6217: next if ($type eq 'community');
6218: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6219: if ($defcredits{$type} ne '') {
6220: $currusecredits = 1;
6221: }
6222: }
6223: }
6224: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6225: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6226: $postsubmitclient = 0;
6227: foreach my $type (@types) {
6228: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6229: }
6230: } else {
6231: foreach my $type (@types) {
6232: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6233: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6234: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6235: } else {
6236: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6237: }
6238: } else {
6239: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6240: }
6241: }
6242: }
6243: } else {
6244: foreach my $type (@types) {
6245: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 6246: }
6247: }
1.160.6.70 raeburn 6248: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6249: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6250: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6251: }
6252: } else {
6253: foreach my $type (@types) {
6254: $currmysql{$type} = $staticdefaults{'mysqltables'};
6255: }
6256: }
1.160.6.58 raeburn 6257: } else {
6258: foreach my $type (@types) {
6259: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.118.2 14(raebu 6260:23): if ($staticdefaults{'domexttool'}) {
6261:23): $domexttool{$type} = ' checked="checked"';
6262:23): }
1.160.6.58 raeburn 6263: }
1.160.6.118.2 22(raebu 6264:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6265:24): $crseditors{$editor} = ' checked="checked"';
6266:24): }
1.139 raeburn 6267: }
6268: if (!$currdefresponder) {
1.160.6.21 raeburn 6269: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6270: } elsif ($currdefresponder < 1) {
6271: $currdefresponder = 1;
6272: }
1.160.6.21 raeburn 6273: foreach my $type (@types) {
6274: if ($curruploadquota{$type} eq '') {
6275: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6276: }
1.160.6.118.2 15(raebu 6277:23): if ($currcoursequota{$type} eq '') {
6278:23): $currcoursequota{$type} = $staticdefaults{'coursequota'};
6279:23): }
1.160.6.21 raeburn 6280: }
1.139 raeburn 6281: $datatable .=
1.160.6.16 raeburn 6282: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6283: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6284: '</span></td>'.
6285: '<td class="LC_right_item"><span class="LC_nobreak">'.
6286: '<input type="text" name="anonsurvey_threshold"'.
6287: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 6288: '</td></tr>'."\n";
6289: $itemcount ++;
6290: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6291: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6292: $choices{'uploadquota'}.
6293: '</span></td>'.
6294: '<td align="right" class="LC_right_item">'.
6295: '<table><tr>';
1.160.6.21 raeburn 6296: foreach my $type (@types) {
6297: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6298: '<input type="text" name="uploadquota_'.$type.'"'.
6299: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6300: }
6301: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 6302: $itemcount ++;
1.160.6.118.2 15(raebu 6303:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6304:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6305:23): $choices{'coursequota'}.
6306:23): '</span></td>'.
6307:23): '<td style="text-align: right" class="LC_right_item">'.
6308:23): '<table><tr>';
6309:23): foreach my $type (@types) {
6310:23): $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6311:23): '<input type="text" name="coursequota_'.$type.'"'.
6312:23): ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6313:23): }
6314:23): $datatable .= '</tr></table></td></tr>'."\n";
6315:23): $itemcount ++;
1.160.6.40 raeburn 6316: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 6317: my $display = 'none';
6318: if ($currusecredits) {
6319: $display = 'block';
6320: }
6321: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 6322: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6323: foreach my $type (@types) {
6324: next if ($type eq 'community');
6325: $additional .= '<td align="center">'.&mt($type).'<br />'.
6326: '<input type="text" name="'.$type.'_credits"'.
6327: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6328: }
6329: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 6330: %defaultchecked = ('coursecredits' => 'off');
6331: @toggles = ('coursecredits');
6332: my $current = {
6333: 'coursecredits' => $currusecredits,
6334: };
6335: (my $table,$itemcount) =
6336: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6337: \%choices,$itemcount,$onclick,$additional,'left');
6338: $datatable .= $table;
6339: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6340: my $display = 'none';
6341: if ($postsubmitclient) {
6342: $display = 'block';
6343: }
6344: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 6345: &mt('Number of seconds submit is disabled').'<br />'.
6346: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6347: '<table><tr>';
1.160.6.57 raeburn 6348: foreach my $type (@types) {
6349: $additional .= '<td align="center">'.&mt($type).'<br />'.
6350: '<input type="text" name="'.$type.'_timeout" value="'.
6351: $deftimeout{$type}.'" size="5" /></td>';
6352: }
6353: $additional .= '</tr></table></div>'."\n";
6354: %defaultchecked = ('postsubmit' => 'on');
6355: @toggles = ('postsubmit');
1.160.6.70 raeburn 6356: $current = {
6357: 'postsubmit' => $postsubmitclient,
6358: };
1.160.6.57 raeburn 6359: ($table,$itemcount) =
6360: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6361: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 6362: $datatable .= $table;
1.160.6.70 raeburn 6363: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6364: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6365: $choices{'mysqltables'}.
6366: '</span></td>'.
6367: '<td align="right" class="LC_right_item">'.
6368: '<table><tr>';
6369: foreach my $type (@types) {
6370: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6371: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 6372: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 6373: }
6374: $datatable .= '</tr></table></td></tr>'."\n";
6375: $itemcount ++;
1.160.6.118.2 4(raebur 6376:2): %defaultchecked = ('ltiauth' => 'off');
6377:2): @toggles = ('ltiauth');
6378:2): $current = {
6379:2): 'ltiauth' => $ltiauth,
6380:2): };
6381:2): ($table,$itemcount) =
6382:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6383:2): \%choices,$itemcount,undef,undef,'left');
6384:2): $datatable .= $table;
14(raebu 6385:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6386:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6387:23): $choices{'domexttool'}.
6388:23): '</span></td>'.
6389:23): '<td style="text-align: right" class="LC_right_item">'.
6390:23): '<table><tr>';
6391:23): foreach my $type (@types) {
6392:23): $datatable .= '<td style="text-align: left">'.
6393:23): '<span class="LC_nobreak">'.
22(raebu 6394:24): '<label><input type="checkbox" name="domexttool"'.
14(raebu 6395:23): ' value="'.$type.'"'.$domexttool{$type}.' />'.
22(raebu 6396:24): &mt($type).'</label></span></td>'."\n";
14(raebu 6397:23): }
6398:23): $datatable .= '</tr></table></td></tr>'."\n";
4(raebur 6399:2): $itemcount ++;
14(raebu 6400:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6401:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6402:23): $choices{'exttool'}.
6403:23): '</span></td>'.
6404:23): '<td style="text-align: right" class="LC_right_item">'.
6405:23): '<table><tr>';
6406:23): foreach my $type (@types) {
6407:23): $datatable .= '<td style="text-align: left">'.
6408:23): '<span class="LC_nobreak">'.
22(raebu 6409:24): '<label><input type="checkbox" name="exttool"'.
14(raebu 6410:23): ' value="'.$type.'"'.$exttool{$type}.' />'.
22(raebu 6411:24): &mt($type).'</label></span></td>'."\n";
6412:24): }
6413:24): $datatable .= '</tr></table></td></tr>'."\n";
6414:24): $itemcount ++;
6415:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6416:24): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6417:24): $choices{'crseditors'}.
6418:24): '</span></td>'.
6419:24): '<td style="text-align: right" class="LC_right_item">'.
6420:24): '<table><tr>';
6421:24): my @editors = ('edit','xml','daxe');
6422:24): my %editornames = &crseditor_titles();
6423:24): foreach my $editor (@editors) {
6424:24): $datatable .= '<td style="text-align: left">'.
6425:24): '<span class="LC_nobreak">'.
6426:24): '<label><input type="checkbox" name="crseditors"'.
6427:24): ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
6428:24): $editornames{$editor}.'</label></span></td>'."\n";
14(raebu 6429:23): }
6430:23): $datatable .= '</tr></table></td></tr>'."\n";
6431:23): }
6432:23): $$rowtotal += $itemcount;
6433:23): return $datatable;
6434:23): }
6435:23):
22(raebu 6436:24): sub crseditor_titles {
6437:24): return &Apache::lonlocal::texthash(
6438:24): edit => 'Standard editor (Edit)',
6439:24): xml => 'Text editor (EditXML)',
6440:24): daxe => 'Daxe editor (Daxe)',
6441:24): );
6442:24): }
6443:24):
20(raebu 6444:24): sub print_authordefaults {
6445:24): my ($position,$dom,$settings,$rowtotal) = @_;
6446:24): my ($css_class,$datatable,%checkedon,%checkedoff);
6447:24): my $itemcount = 1;
6448:24): my %titles = &authordefaults_titles();
6449:24): if ($position eq 'top') {
6450:24): my %defaultchecked = (
6451:24): 'nocodemirror' => 'off',
21(raebu 6452:24): 'daxecollapse' => 'off',
20(raebu 6453:24): 'domcoordacc' => 'on',
6454:24): );
21(raebu 6455:24): my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
20(raebu 6456:24): ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
6457:24): \%titles,$itemcount);
6458:24): my %staticdefaults = (
6459:24): 'copyright' => 'default',
6460:24): 'sourceavail' => 'closed',
6461:24): );
6462:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6463:24): my %currrights;
6464:24): foreach my $item ('copyright','sourceavail') {
6465:24): $currrights{$item} = $staticdefaults{$item};
6466:24): if (ref($settings) eq 'HASH') {
6467:24): if (exists($settings->{$item})) {
6468:24): $currrights{$item} = $settings->{$item};
6469:24): }
6470:24): }
6471:24): }
6472:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6473:24): '<span class="LC_nobreak">'.$titles{'copyright'}.
6474:24): '</span></td><td class="LC_right_item">'.
6475:24): &selectbox('copyright',$currrights{'copyright'},'',
6476:24): \&Apache::loncommon::copyrightdescription,
6477:24): (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
6478:24): '</td></tr>'."\n";
6479:24): $itemcount ++;
6480:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6481:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6482:24): '<span class="LC_nobreak">'.$titles{'sourceavail'}.
6483:24): '</span></td><td class="LC_right_item">'.
6484:24): &selectbox('sourceavail',$currrights{'sourceavail'},'',
6485:24): \&Apache::loncommon::source_copyrightdescription,
6486:24): (&Apache::loncommon::source_copyrightids)).
6487:24): '</td></tr>'."\n";
6488:24): } else {
6489:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6490:24): my $curreditors;
6491:24): my %staticdefaults = (
6492:24): editors => ['edit','xml'],
6493:24): authorquota => 500,
6494:24): webdav => 0,
6495:24): );
6496:24): my $curreditors = $staticdefaults{'editors'};
6497:24): if ((ref($settings) eq 'HASH') &&
6498:24): (ref($settings->{'editors'}) eq 'ARRAY')) {
6499:24): $curreditors = $settings->{'editors'};
6500:24): } else {
6501:24): $curreditors = $staticdefaults{'editors'};
6502:24): }
6503:24): my @editors = ('edit','xml','daxe');
6504:24): $datatable = '<tr'.$css_class.'>'."\n".
6505:24): '<td>'.$titles{'editors'}.'</td>'."\n".
6506:24): '<td class="LC_left_item">'."\n".
6507:24): '<span class="LC_nobreak">';
6508:24): foreach my $editor (@editors) {
6509:24): my $checked;
6510:24): if (grep(/^\Q$editor\E$/,@{$curreditors})) {
6511:24): $checked = ' checked="checked"';
6512:24): }
6513:24): $datatable .= '<label>'.
6514:24): '<input type="checkbox" name="author_editors" '.
6515:24): $checked.' value="'.$editor.'" '.
6516:24): 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
6517:24): $titles{$editor}.'</label> ';
6518:24): }
6519:24): $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
6520:24): $itemcount ++;
6521:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6522:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6523:24): my @insttypes;
6524:24): if (ref($types) eq 'ARRAY') {
6525:24): @insttypes = @{$types};
6526:24): }
6527:24): my $typecount = 0;
6528:24): my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
6529:24): my @items = ('webdav','authorquota');
6530:24): my %quotas;
6531:24): if (ref($domconf{'quotas'}) eq 'HASH') {
6532:24): %quotas = %{$domconf{'quotas'}};
6533:24): foreach my $item (@items) {
6534:24): if (ref($quotas{$item}) eq 'HASH') {
6535:24): foreach my $type (@insttypes,'default') {
6536:24): if ($item eq 'authorquota') {
6537:24): if ($quotas{$item}{$type} !~ /^\d+$/) {
6538:24): $quotas{$item}{$type} = $staticdefaults{$item};
6539:24): }
6540:24): } elsif ($item eq 'webdav') {
6541:24): if ($quotas{$item}{$type} !~ /^(0|1)$/) {
6542:24): $quotas{$item}{$type} = $staticdefaults{$item};
6543:24): }
6544:24): }
6545:24): }
6546:24): } else {
6547:24): foreach my $type (@insttypes,'default') {
6548:24): $quotas{$item}{$type} = $staticdefaults{$item};
6549:24): }
6550:24): }
6551:24): }
6552:24): } else {
6553:24): foreach my $item (@items) {
6554:24): foreach my $type (@insttypes,'default') {
6555:24): $quotas{$item}{$type} = $staticdefaults{$item};
6556:24): }
6557:24): }
6558:24): }
6559:24): if (ref($usertypes) eq 'HASH') {
6560:24): my $numinrow = 4;
6561:24): my $onclick = '';
6562:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6563:24): $numinrow,$othertitle,'authorquota',
6564:24): \$itemcount,$onclick);
6565:24): $itemcount ++;
6566:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6567:24): $numinrow,$othertitle,'webdav',
6568:24): \$itemcount);
6569:24): $itemcount ++;
6570:24): }
6571:24): my $checkedno = ' checked="checked"';
6572:24): my ($checkedon,$checkedoff);
6573:24): if (ref($quotas{'webdav'}) eq 'HASH') {
6574:24): if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
6575:24): if ($quotas{'webdav'}{'_LC_adv'}) {
6576:24): $checkedon = $checkedno;
6577:24): } else {
6578:24): $checkedoff = $checkedno;
6579:24): }
6580:24): undef($checkedno);
6581:24): }
6582:24): }
6583:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6584:24): $datatable .= '<tr'.$css_class.'>'.
6585:24): '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
6586:24): $titles{'webdav_LC_adv_over'}.
6587:24): '</td>'.
6588:24): '<td class="LC_left_item">';
6589:24): foreach my $option ('none','off','on') {
6590:24): my ($text,$val,$checked);
6591:24): if ($option eq 'none') {
6592:24): $text = $titles{'none'};
6593:24): $val = '';
6594:24): $checked = $checkedno;
6595:24): } elsif ($option eq 'off') {
6596:24): $text = $titles{'overoff'};
6597:24): $val = 0;
6598:24): $checked = $checkedoff;
6599:24): } elsif ($option eq 'on') {
6600:24): $text = $titles{'overon'};
6601:24): $val = 1;
6602:24): $checked = $checkedon;
6603:24): }
6604:24): $datatable .= '<span class="LC_nobreak"><label>'.
6605:24): '<input type="radio" name="webdav_LC_adv"'.
6606:24): ' value="'.$val.'"'.$checked.' />'.
6607:24): $text.'</label></span> ';
6608:24): }
6609:24): $datatable .= '</td></tr>';
6610:24): $itemcount ++;
22(raebu 6611:24): my %defchecked = (
6612:24): 'archive' => 'off',
6613:24): );
6614:24): my @toggles = ('archive');
6615:24): (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
6616:24): {'archive' => 'off'},
6617:24): \%titles,$itemcount);
6618:24): $datatable .= $archive."\n";
6619:24): $itemcount ++;
20(raebu 6620:24): }
6621:24): $$rowtotal += $itemcount;
6622:24): return $datatable;
6623:24): }
6624:24):
6625:24): sub authordefaults_titles {
6626:24): return &Apache::lonlocal::texthash(
6627:24): copyright => 'Copyright/Distribution',
6628:24): sourceavail => ' Source Available',
6629:24): editors => 'Available Editors',
6630:24): webdav => 'WebDAV',
6631:24): authorquota => 'Authoring Space quotas (MB)',
6632:24): nocodemirror => 'Deactivate CodeMirror for EditXML editor',
21(raebu 6633:24): daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
20(raebu 6634:24): domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
6635:24): edit => 'Standard editor (Edit)',
6636:24): xml => 'Text editor (EditXML)',
6637:24): daxe => 'Daxe editor (Daxe)',
6638:24): webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
6639:24): webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
6640:24): none => 'No override set',
6641:24): overon => 'Override -- webDAV on',
6642:24): overoff => 'Override -- webDAV off',
22(raebu 6643:24): archive => 'Authors can download tar.gz file of Authoring Space',
20(raebu 6644:24): );
6645:24): }
6646:24):
6647:24): sub selectbox {
6648:24): my ($name,$value,$readonly,$functionref,@idlist)=@_;
6649:24): my $selout = '<select name="'.$name.'">';
6650:24): foreach my $id (@idlist) {
6651:24): $selout.='<option value="'.$id.'"';
6652:24): if ($id eq $value) {
6653:24): $selout.=' selected="selected"';
6654:24): }
6655:24): if ($readonly) {
6656:24): $selout .= ' disabled="disabled"';
6657:24): }
6658:24): $selout.='>'.&{$functionref}($id).'</option>';
6659:24): }
6660:24): $selout.='</select>';
6661:24): return $selout;
6662:24): }
6663:24):
14(raebu 6664:23): sub print_selfenrollment {
1.160.6.37 raeburn 6665: my ($position,$dom,$settings,$rowtotal) = @_;
6666: my ($css_class,$datatable);
6667: my $itemcount = 1;
6668: my @types = ('official','unofficial','community','textbook');
6669: if (($position eq 'top') || ($position eq 'middle')) {
6670: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6671: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6672: my @rows;
6673: my $key;
6674: if ($position eq 'top') {
6675: $key = 'admin';
6676: if (ref($rowsref) eq 'ARRAY') {
6677: @rows = @{$rowsref};
6678: }
6679: } elsif ($position eq 'middle') {
6680: $key = 'default';
6681: @rows = ('types','registered','approval','limit');
6682: }
6683: foreach my $row (@rows) {
6684: if (defined($titlesref->{$row})) {
6685: $itemcount ++;
6686: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6687: $datatable .= '<tr'.$css_class.'>'.
6688: '<td>'.$titlesref->{$row}.'</td>'.
6689: '<td class="LC_left_item">'.
6690: '<table><tr>';
6691: my (%current,%currentcap);
6692: if (ref($settings) eq 'HASH') {
6693: if (ref($settings->{$key}) eq 'HASH') {
6694: foreach my $type (@types) {
6695: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6696: $current{$type} = $settings->{$key}->{$type}->{$row};
6697: }
6698: if (($row eq 'limit') && ($key eq 'default')) {
6699: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6700: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6701: }
6702: }
6703: }
6704: }
6705: }
6706: my %roles = (
6707: '0' => &Apache::lonnet::plaintext('dc'),
6708: );
6709:
6710: foreach my $type (@types) {
6711: unless (($row eq 'registered') && ($key eq 'default')) {
6712: $datatable .= '<th>'.&mt($type).'</th>';
6713: }
6714: }
6715: unless (($row eq 'registered') && ($key eq 'default')) {
6716: $datatable .= '</tr><tr>';
6717: }
6718: foreach my $type (@types) {
6719: if ($type eq 'community') {
6720: $roles{'1'} = &mt('Community personnel');
6721: } else {
6722: $roles{'1'} = &mt('Course personnel');
6723: }
6724: $datatable .= '<td style="vertical-align: top">';
6725: if ($position eq 'top') {
6726: my %checked;
6727: if ($current{$type} eq '0') {
6728: $checked{'0'} = ' checked="checked"';
6729: } else {
6730: $checked{'1'} = ' checked="checked"';
6731: }
6732: foreach my $role ('1','0') {
6733: $datatable .= '<span class="LC_nobreak"><label>'.
6734: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6735: 'value="'.$role.'"'.$checked{$role}.' />'.
6736: $roles{$role}.'</label></span> ';
6737: }
6738: } else {
6739: if ($row eq 'types') {
6740: my %checked;
6741: if ($current{$type} =~ /^(all|dom)$/) {
6742: $checked{$1} = ' checked="checked"';
6743: } else {
6744: $checked{''} = ' checked="checked"';
6745: }
6746: foreach my $val ('','dom','all') {
6747: $datatable .= '<span class="LC_nobreak"><label>'.
6748: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6749: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6750: }
6751: } elsif ($row eq 'registered') {
6752: my %checked;
6753: if ($current{$type} eq '1') {
6754: $checked{'1'} = ' checked="checked"';
6755: } else {
6756: $checked{'0'} = ' checked="checked"';
6757: }
6758: foreach my $val ('0','1') {
6759: $datatable .= '<span class="LC_nobreak"><label>'.
6760: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6761: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6762: }
6763: } elsif ($row eq 'approval') {
6764: my %checked;
6765: if ($current{$type} =~ /^([12])$/) {
6766: $checked{$1} = ' checked="checked"';
6767: } else {
6768: $checked{'0'} = ' checked="checked"';
6769: }
6770: for my $val (0..2) {
6771: $datatable .= '<span class="LC_nobreak"><label>'.
6772: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6773: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6774: }
6775: } elsif ($row eq 'limit') {
6776: my %checked;
6777: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6778: $checked{$1} = ' checked="checked"';
6779: } else {
6780: $checked{'none'} = ' checked="checked"';
6781: }
6782: my $cap;
6783: if ($currentcap{$type} =~ /^\d+$/) {
6784: $cap = $currentcap{$type};
6785: }
6786: foreach my $val ('none','allstudents','selfenrolled') {
6787: $datatable .= '<span class="LC_nobreak"><label>'.
6788: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6789: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6790: }
6791: $datatable .= '<br />'.
6792: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6793: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6794: '</span>';
6795: }
6796: }
6797: $datatable .= '</td>';
6798: }
6799: $datatable .= '</tr>';
6800: }
6801: $datatable .= '</table></td></tr>';
6802: }
6803: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 6804: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6805: }
6806: $$rowtotal += $itemcount;
6807: return $datatable;
6808: }
6809:
6810: sub print_validation_rows {
6811: my ($caller,$dom,$settings,$rowtotal) = @_;
6812: my ($itemsref,$namesref,$fieldsref);
6813: if ($caller eq 'selfenroll') {
6814: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6815: } elsif ($caller eq 'requestcourses') {
6816: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6817: }
6818: my %currvalidation;
6819: if (ref($settings) eq 'HASH') {
6820: if (ref($settings->{'validation'}) eq 'HASH') {
6821: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 6822: }
1.160.6.39 raeburn 6823: }
6824: my $datatable;
6825: my $itemcount = 0;
6826: foreach my $item (@{$itemsref}) {
6827: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6828: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6829: $namesref->{$item}.
6830: '</span></td>'.
6831: '<td class="LC_left_item">';
6832: if (($item eq 'url') || ($item eq 'button')) {
6833: $datatable .= '<span class="LC_nobreak">'.
6834: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6835: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6836: } elsif ($item eq 'fields') {
6837: my @currfields;
6838: if (ref($currvalidation{$item}) eq 'ARRAY') {
6839: @currfields = @{$currvalidation{$item}};
6840: }
6841: foreach my $field (@{$fieldsref}) {
6842: my $check = '';
6843: if (grep(/^\Q$field\E$/,@currfields)) {
6844: $check = ' checked="checked"';
6845: }
6846: $datatable .= '<span class="LC_nobreak"><label>'.
6847: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6848: ' value="'.$field.'"'.$check.' />'.$field.
6849: '</label></span> ';
6850: }
6851: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 6852: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 6853: $currvalidation{$item}.
1.160.6.37 raeburn 6854: '</textarea>';
1.160.6.39 raeburn 6855: }
6856: $datatable .= '</td></tr>'."\n";
6857: if (ref($rowtotal)) {
1.160.6.37 raeburn 6858: $itemcount ++;
6859: }
1.139 raeburn 6860: }
1.160.6.39 raeburn 6861: if ($caller eq 'requestcourses') {
6862: my %currhash;
1.160.6.51 raeburn 6863: if (ref($settings) eq 'HASH') {
6864: if (ref($settings->{'validation'}) eq 'HASH') {
6865: if ($settings->{'validation'}{'dc'} ne '') {
6866: $currhash{$settings->{'validation'}{'dc'}} = 1;
6867: }
1.160.6.39 raeburn 6868: }
6869: }
6870: my $numinrow = 2;
6871: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6872: 'validationdc',%currhash);
1.160.6.50 raeburn 6873: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 6874: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 6875: if ($numdc > 1) {
1.160.6.50 raeburn 6876: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 6877: } else {
1.160.6.50 raeburn 6878: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 6879: }
1.160.6.50 raeburn 6880: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 6881: $itemcount ++;
6882: }
6883: if (ref($rowtotal)) {
6884: $$rowtotal += $itemcount;
6885: }
1.121 raeburn 6886: return $datatable;
1.118 jms 6887: }
6888:
1.160.6.98 raeburn 6889: sub print_passwords {
6890: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6891: my ($datatable,$css_class);
6892: my $itemcount = 0;
6893: my %titles = &Apache::lonlocal::texthash (
6894: captcha => '"Forgot Password" CAPTCHA validation',
6895: link => 'Reset link expiration (hours)',
6896: case => 'Case-sensitive usernames/e-mail',
6897: prelink => 'Information required (form 1)',
6898: postlink => 'Information required (form 2)',
6899: emailsrc => 'LON-CAPA e-mail address type(s)',
6900: customtext => 'Domain specific text (HTML)',
6901: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6902: intauth_check => 'Check bcrypt cost if authenticated',
6903: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6904: permanent => 'Permanent e-mail address',
6905: critical => 'Critical notification address',
6906: notify => 'Notification address',
6907: min => 'Minimum password length',
6908: max => 'Maximum password length',
6909: chars => 'Required characters',
6910: numsaved => 'Number of previous passwords to save and disallow reuse',
6911: );
6912: if ($position eq 'top') {
6913: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6914: my $shownlinklife = 2;
6915: my $prelink = 'both';
6916: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6917: if (ref($settings) eq 'HASH') {
6918: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6919: $shownlinklife = $settings->{resetlink};
6920: }
6921: if (ref($settings->{resetcase}) eq 'ARRAY') {
6922: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6923: }
6924: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6925: $prelink = $settings->{resetprelink};
6926: }
6927: if (ref($settings->{resetpostlink}) eq 'HASH') {
6928: %postlink = %{$settings->{resetpostlink}};
6929: }
6930: if (ref($settings->{resetemail}) eq 'ARRAY') {
6931: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6932: }
6933: if ($settings->{resetremove}) {
6934: $nostdtext = 1;
6935: }
6936: if ($settings->{resetcustom}) {
6937: $customurl = $settings->{resetcustom};
6938: }
6939: } else {
6940: if (ref($types) eq 'ARRAY') {
6941: foreach my $item (@{$types}) {
6942: $casesens{$item} = 1;
6943: $postlink{$item} = ['username','email'];
6944: }
6945: }
6946: $casesens{'default'} = 1;
6947: $postlink{'default'} = ['username','email'];
6948: $prelink = 'both';
6949: %emailsrc = (
6950: permanent => 1,
6951: critical => 1,
6952: notify => 1,
6953: );
6954: }
6955: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6956: $itemcount ++;
6957: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6958: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6959: '<td class="LC_left_item">'.
6960: '<input type="textbox" value="'.$shownlinklife.'" '.
6961: 'name="passwords_link" size="3" /></td></tr>';
6962: $itemcount ++;
6963: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6964: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6965: '<td class="LC_left_item">';
6966: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6967: foreach my $item (@{$types}) {
6968: my $checkedcase;
6969: if ($casesens{$item}) {
6970: $checkedcase = ' checked="checked"';
6971: }
6972: $datatable .= '<span class="LC_nobreak"><label>'.
6973: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6974: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 6975: '</span> ';
1.160.6.98 raeburn 6976: }
6977: }
6978: my $checkedcase;
6979: if ($casesens{'default'}) {
6980: $checkedcase = ' checked="checked"';
6981: }
6982: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6983: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6984: $othertitle.'</label></span></td>';
6985: $itemcount ++;
6986: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6987: my %checkedpre = (
6988: both => ' checked="checked"',
6989: either => '',
6990: );
6991: if ($prelink eq 'either') {
6992: $checkedpre{either} = ' checked="checked"';
6993: $checkedpre{both} = '';
6994: }
6995: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6996: '<td class="LC_left_item"><span class="LC_nobreak">'.
6997: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6998: &mt('Both username and e-mail address').'</label></span> '.
6999: '<span class="LC_nobreak"><label>'.
7000: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7001: &mt('Either username or e-mail address').'</label></span></td></tr>';
7002: $itemcount ++;
7003: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7004: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7005: '<td class="LC_left_item">';
7006: my %postlinked;
7007: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7008: foreach my $item (@{$types}) {
7009: undef(%postlinked);
7010: $datatable .= '<fieldset style="display: inline-block;">'.
7011: '<legend>'.$usertypes->{$item}.'</legend>';
7012: if (ref($postlink{$item}) eq 'ARRAY') {
7013: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7014: }
7015: foreach my $field ('email','username') {
7016: my $checked;
7017: if ($postlinked{$field}) {
7018: $checked = ' checked="checked"';
7019: }
7020: $datatable .= '<span class="LC_nobreak"><label>'.
7021: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7022: $field.'"'.$checked.' />'.$field.'</label>'.
7023: '<span> ';
7024: }
7025: $datatable .= '</fieldset>';
7026: }
7027: }
7028: if (ref($postlink{'default'}) eq 'ARRAY') {
7029: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7030: }
7031: $datatable .= '<fieldset style="display: inline-block;">'.
7032: '<legend>'.$othertitle.'</legend>';
7033: foreach my $field ('email','username') {
7034: my $checked;
7035: if ($postlinked{$field}) {
7036: $checked = ' checked="checked"';
7037: }
7038: $datatable .= '<span class="LC_nobreak"><label>'.
7039: '<input type="checkbox" name="passwords_postlink_default" value="'.
7040: $field.'"'.$checked.' />'.$field.'</label>'.
7041: '<span> ';
7042: }
7043: $datatable .= '</fieldset></td></tr>';
7044: $itemcount ++;
7045: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7046: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7047: '<td class="LC_left_item">';
7048: foreach my $type ('permanent','critical','notify') {
7049: my $checkedemail;
7050: if ($emailsrc{$type}) {
7051: $checkedemail = ' checked="checked"';
7052: }
7053: $datatable .= '<span class="LC_nobreak"><label>'.
7054: '<input type="checkbox" name="passwords_emailsrc" value="'.
7055: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7056: '<span> ';
7057: }
7058: $datatable .= '</td></tr>';
7059: $itemcount ++;
7060: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7061: my $switchserver = &check_switchserver($dom,$confname);
7062: my ($showstd,$noshowstd);
7063: if ($nostdtext) {
7064: $noshowstd = ' checked="checked"';
7065: } else {
7066: $showstd = ' checked="checked"';
7067: }
7068: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7069: '<td class="LC_left_item"><span class="LC_nobreak">'.
7070: &mt('Retain standard text:').
7071: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7072: &mt('Yes').'</label>'.' '.
7073: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7074: &mt('No').'</label></span><br />'.
7075: '<span class="LC_fontsize_small">'.
7076: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7077: &mt('Include custom text:');
7078: if ($customurl) {
1.160.6.104 raeburn 7079: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 7080: undef,undef,undef,undef,'background-color:#ffffff');
7081: $datatable .= '<span class="LC_nobreak"> '.$link.
7082: '<label><input type="checkbox" name="passwords_custom_del"'.
7083: ' value="1" />'.&mt('Delete?').'</label></span>'.
7084: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7085: }
7086: if ($switchserver) {
7087: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7088: } else {
7089: $datatable .='<span class="LC_nobreak"> '.
7090: '<input type="file" name="passwords_customfile" /></span>';
7091: }
7092: $datatable .= '</td></tr>';
7093: } elsif ($position eq 'middle') {
7094: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7095: my @items = ('intauth_cost','intauth_check','intauth_switch');
7096: my %defaults;
7097: if (ref($domconf{'defaults'}) eq 'HASH') {
7098: %defaults = %{$domconf{'defaults'}};
7099: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7100: $defaults{'intauth_cost'} = 10;
7101: }
7102: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7103: $defaults{'intauth_check'} = 0;
7104: }
7105: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7106: $defaults{'intauth_switch'} = 0;
7107: }
7108: } else {
7109: %defaults = (
7110: 'intauth_cost' => 10,
7111: 'intauth_check' => 0,
7112: 'intauth_switch' => 0,
7113: );
7114: }
7115: foreach my $item (@items) {
7116: if ($itemcount%2) {
7117: $css_class = '';
7118: } else {
7119: $css_class = ' class="LC_odd_row" ';
7120: }
7121: $datatable .= '<tr'.$css_class.'>'.
7122: '<td><span class="LC_nobreak">'.$titles{$item}.
7123: '</span></td><td class="LC_left_item" colspan="3">';
7124: if ($item eq 'intauth_switch') {
7125: my @options = (0,1,2);
7126: my %optiondesc = &Apache::lonlocal::texthash (
7127: 0 => 'No',
7128: 1 => 'Yes',
7129: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7130: );
7131: $datatable .= '<table width="100%">';
7132: foreach my $option (@options) {
7133: my $checked = ' ';
7134: if ($defaults{$item} eq $option) {
7135: $checked = ' checked="checked"';
7136: }
7137: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7138: '<label><input type="radio" name="'.$item.
7139: '" value="'.$option.'"'.$checked.' />'.
7140: $optiondesc{$option}.'</label></span></td></tr>';
7141: }
7142: $datatable .= '</table>';
7143: } elsif ($item eq 'intauth_check') {
7144: my @options = (0,1,2);
7145: my %optiondesc = &Apache::lonlocal::texthash (
7146: 0 => 'No',
7147: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7148: 2 => 'Yes, disallow login if stored cost is less than domain default',
7149: );
7150: $datatable .= '<table width="100%">';
7151: foreach my $option (@options) {
7152: my $checked = ' ';
7153: my $onclick;
7154: if ($defaults{$item} eq $option) {
7155: $checked = ' checked="checked"';
7156: }
7157: if ($option == 2) {
7158: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7159: }
7160: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7161: '<label><input type="radio" name="'.$item.
7162: '" value="'.$option.'"'.$checked.$onclick.' />'.
7163: $optiondesc{$option}.'</label></span></td></tr>';
7164: }
7165: $datatable .= '</table>';
7166: } else {
7167: $datatable .= '<input type="text" name="'.$item.'" value="'.
7168: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7169: }
7170: $datatable .= '</td></tr>';
7171: $itemcount ++;
7172: }
7173: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 7174:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 7175: } else {
7176: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7177: my %ownerchg = (
7178: by => {},
7179: for => {},
7180: );
7181: my %ownertitles = &Apache::lonlocal::texthash (
7182: by => 'Course owner status(es) allowed',
7183: for => 'Student status(es) allowed',
7184: );
7185: if (ref($settings) eq 'HASH') {
7186: if (ref($settings->{crsownerchg}) eq 'HASH') {
7187: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7188: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7189: }
7190: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7191: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7192: }
7193: }
7194: }
7195: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7196: $datatable .= '<tr '.$css_class.'>'.
7197: '<td>'.
7198: &mt('Requirements').'<ul>'.
7199: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
7200: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7201: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
7202: '<li>'.&mt('User, course, and student share same domain').'</li>'.
7203: '</ul>'.
7204: '</td>'.
7205: '<td class="LC_left_item">';
7206: foreach my $item ('by','for') {
7207: $datatable .= '<fieldset style="display: inline-block;">'.
7208: '<legend>'.$ownertitles{$item}.'</legend>';
7209: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7210: foreach my $type (@{$types}) {
7211: my $checked;
7212: if ($ownerchg{$item}{$type}) {
7213: $checked = ' checked="checked"';
7214: }
7215: $datatable .= '<span class="LC_nobreak"><label>'.
7216: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7217: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 7218: '</span> ';
1.160.6.98 raeburn 7219: }
7220: }
7221: my $checked;
7222: if ($ownerchg{$item}{'default'}) {
7223: $checked = ' checked="checked"';
7224: }
7225: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7226: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7227: $othertitle.'</label></span></fieldset>';
7228: }
7229: $datatable .= '</td></tr>';
7230: }
7231: return $datatable;
7232: }
7233:
1.160.6.118.2 5(raebur 7234:2): sub password_rules {
7235:2): my ($prefix,$itemcountref,$settings) = @_;
7236:2): my ($min,$max,%chars,$numsaved,$numinrow);
7237:2): my %titles;
7238:2): if ($prefix eq 'passwords') {
7239:2): %titles = &Apache::lonlocal::texthash (
7240:2): min => 'Minimum password length',
7241:2): max => 'Maximum password length',
7242:2): chars => 'Required characters',
7243:2): );
14(raebu 7244:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 7245:2): %titles = &Apache::lonlocal::texthash (
7246:2): min => 'Minimum secret length',
7247:2): max => 'Maximum secret length',
7248:2): chars => 'Required characters',
7249:2): );
7250:2): }
7251:2): $min = $Apache::lonnet::passwdmin;
7252:2): my $datatable;
7253:2): my $itemcount;
7254:2): if (ref($itemcountref)) {
7255:2): $itemcount = $$itemcountref;
7256:2): }
7257:2): if (ref($settings) eq 'HASH') {
7258:2): if ($settings->{min}) {
7259:2): $min = $settings->{min};
7260:2): }
7261:2): if ($settings->{max}) {
7262:2): $max = $settings->{max};
7263:2): }
7264:2): if (ref($settings->{chars}) eq 'ARRAY') {
7265:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
7266:2): }
7267:2): if ($prefix eq 'passwords') {
7268:2): if ($settings->{numsaved}) {
7269:2): $numsaved = $settings->{numsaved};
7270:2): }
7271:2): }
7272:2): }
7273:2): my %rulenames = &Apache::lonlocal::texthash(
7274:2): uc => 'At least one upper case letter',
7275:2): lc => 'At least one lower case letter',
7276:2): num => 'At least one number',
7277:2): spec => 'At least one non-alphanumeric',
7278:2): );
7279:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7280:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7281:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7282:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7283:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7284:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7285:2): '</span></td></tr>';
7286:2): $itemcount ++;
7287:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7288:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7289:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7290:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7291:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7292:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7293:2): '</span></td></tr>';
7294:2): $itemcount ++;
7295:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7296:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7297:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7298:2): '</span></td>';
7299:2): my $numinrow = 2;
7300:2): my @possrules = ('uc','lc','num','spec');
7301:2): $datatable .= '<td class="LC_left_item"><table>';
7302:2): for (my $i=0; $i<@possrules; $i++) {
7303:2): my ($rem,$checked);
7304:2): if ($chars{$possrules[$i]}) {
7305:2): $checked = ' checked="checked"';
7306:2): }
7307:2): $rem = $i%($numinrow);
7308:2): if ($rem == 0) {
7309:2): if ($i > 0) {
7310:2): $datatable .= '</tr>';
7311:2): }
7312:2): $datatable .= '<tr>';
7313:2): }
7314:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
7315:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7316:2): $rulenames{$possrules[$i]}.'</label></span></td>';
7317:2): }
7318:2): my $rem = @possrules%($numinrow);
7319:2): my $colsleft = $numinrow - $rem;
7320:2): if ($colsleft > 1 ) {
7321:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7322:2): ' </td>';
7323:2): } elsif ($colsleft == 1) {
7324:2): $datatable .= '<td class="LC_left_item"> </td>';
7325:2): }
7326:2): $datatable .='</table></td></tr>';
7327:2): $itemcount ++;
7328:2): if ($prefix eq 'passwords') {
7329:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7330:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7331:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7332:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7333:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7334:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7335:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7336:2): '</span></td></tr>';
7337:2): $itemcount ++;
7338:2): }
7339:2): if (ref($itemcountref)) {
7340:2): $$itemcountref += $itemcount;
7341:2): }
7342:2): return $datatable;
7343:2): }
7344:2):
1.160.6.113 raeburn 7345: sub print_wafproxy {
7346: my ($position,$dom,$settings,$rowtotal) = @_;
7347: my $css_class;
7348: my $itemcount = 0;
7349: my $datatable;
7350: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7351: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
7352: my %lt = &wafproxy_titles();
7353: foreach my $server (sort(keys(%servers))) {
7354: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7355: next if ($serverhome eq '');
7356: my $serverdom;
7357: if ($serverhome ne $server) {
7358: $serverdom = &Apache::lonnet::host_domain($serverhome);
7359: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7360: $othercontrol{$server} = $serverdom;
7361: }
7362: } else {
7363: $serverdom = &Apache::lonnet::host_domain($server);
7364: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7365: if ($serverdom ne $dom) {
7366: $othercontrol{$server} = $serverdom;
7367: } else {
7368: $setdom = 1;
7369: if (ref($settings) eq 'HASH') {
7370: if (ref($settings->{'alias'}) eq 'HASH') {
7371: $aliases{$dom} = $settings->{'alias'};
7372: if ($aliases{$dom} ne '') {
7373: $showdom = 1;
7374: }
7375: }
7376: if (ref($settings->{'saml'}) eq 'HASH') {
7377: $saml{$dom} = $settings->{'saml'};
7378: }
7379: }
7380: }
7381: }
7382: }
7383: if ($setdom) {
7384: %{$values{$dom}} = ();
7385: if (ref($settings) eq 'HASH') {
7386: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7387: $values{$dom}{$item} = $settings->{$item};
7388: }
7389: }
7390: }
7391: if (keys(%othercontrol)) {
7392: %otherdoms = reverse(%othercontrol);
7393: foreach my $domain (keys(%otherdoms)) {
7394: %{$values{$domain}} = ();
7395: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7396: if (ref($config{'wafproxy'}) eq 'HASH') {
7397: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7398: if (exists($config{'wafproxy'}{'saml'})) {
7399: $saml{$domain} = $config{'wafproxy'}{'saml'};
7400: }
7401: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7402: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7403: }
7404: }
7405: }
7406: }
7407: if ($position eq 'top') {
7408: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7409: my %aliasinfo;
7410: foreach my $server (sort(keys(%servers))) {
7411: $itemcount ++;
7412: my $dom_in_effect;
7413: my $aliasrows = '<tr>'.
7414: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.118.2 17(raebu 7415:24): &mt('Hostname').': '.
16(raebu 7416:24): '<span class="LC_nobreak LC_cusr_emph">'.
7417:24): &Apache::lonnet::hostname($server).'</span></td><td> </td>';
1.160.6.113 raeburn 7418: if ($othercontrol{$server}) {
7419: $dom_in_effect = $othercontrol{$server};
7420: my ($current,$forsaml);
7421: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7422: $current = $aliases{$dom_in_effect}{$server};
7423: }
7424: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7425: if ($saml{$dom_in_effect}{$server}) {
7426: $forsaml = 1;
7427: }
7428: }
7429: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7430: &mt('Alias').': ';
7431: if ($current) {
7432: $aliasrows .= $current;
7433: if ($forsaml) {
7434: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7435: }
7436: } else {
7437: $aliasrows .= &mt('None');
7438: }
7439: $aliasrows .= ' <span class="LC_small">('.
7440: &mt('controlled by domain: [_1]',
7441: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7442: } else {
7443: $dom_in_effect = $dom;
7444: my ($current,$samlon,$samloff);
7445: $samloff = ' checked="checked"';
7446: if (ref($aliases{$dom}) eq 'HASH') {
7447: if ($aliases{$dom}{$server}) {
7448: $current = $aliases{$dom}{$server};
7449: }
7450: }
7451: if (ref($saml{$dom}) eq 'HASH') {
7452: if ($saml{$dom}{$server}) {
7453: $samlon = $samloff;
7454: undef($samloff);
7455: }
7456: }
7457: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7458: &mt('Alias').': '.
7459: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7460: 'value="'.$current.'" size="30" />'.
7461: (' 'x2).'<span class="LC_nobreak">'.
7462: &mt('Alias used for SSO Auth').': <label>'.
7463: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7464: &mt('No').'</label> <label>'.
7465: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7466: &mt('Yes').'</label></span>'.
7467: '</td>';
7468: }
7469: $aliasrows .= '</tr>';
7470: $aliasinfo{$dom_in_effect} .= $aliasrows;
7471: }
7472: if ($aliasinfo{$dom}) {
7473: my ($onclick,$wafon,$wafoff,$showtable);
7474: $onclick = ' onclick="javascript:toggleWAF();"';
7475: $wafoff = ' checked="checked"';
7476: $showtable = ' style="display:none";';
7477: if ($showdom) {
7478: $wafon = $wafoff;
7479: $wafoff = '';
7480: $showtable = ' style="display:inline;"';
7481: }
7482: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7483: $datatable = '<tr'.$css_class.'>'.
7484: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7485: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7486: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7487: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7488: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7489: &mt('No').'</label></span></td>'.
7490: '<td class="LC_left_item">'.
7491: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7492: '</table></td></tr>';
7493: $itemcount++;
7494: }
7495: if (keys(%otherdoms)) {
7496: foreach my $key (sort(keys(%otherdoms))) {
7497: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7498: $datatable .= '<tr'.$css_class.'>'.
7499: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7500: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7501: '</table></td></tr>';
7502: $itemcount++;
7503: }
7504: }
7505: } else {
7506: my %ip_methods = &remoteip_methods();
7507: if ($setdom) {
7508: $itemcount ++;
7509: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7510: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7511: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7512: $wafstyle = ' style="display:none;"';
7513: $nowafstyle = ' style="display:table-row;"';
7514: $currwafdisplay = ' style="display: none"';
7515: $wafrangestyle = ' style="display: none"';
7516: $curr_remotip = 'n';
7517: $ssltossl = ' checked="checked"';
7518: if ($showdom) {
7519: $wafstyle = ' style="display:table-row;"';
7520: $nowafstyle = ' style="display:none;"';
7521: if (keys(%{$values{$dom}})) {
7522: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7523: $curr_remotip = $values{$dom}{remoteip};
7524: }
7525: if ($curr_remotip eq 'h') {
7526: $currwafdisplay = ' style="display:table-row"';
7527: $wafrangestyle = ' style="display:inline-block;"';
7528: }
7529: if ($values{$dom}{'sslopt'}) {
7530: $alltossl = ' checked="checked"';
7531: $ssltossl = '';
7532: }
7533: }
7534: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7535: $vpndircheck = ' checked="checked"';
7536: $currwafvpn = ' style="display:table-row;"';
7537: $wafrangestyle = ' style="display:inline-block;"';
7538: } else {
7539: $vpnaliascheck = ' checked="checked"';
7540: $currwafvpn = ' style="display:none;"';
7541: }
7542: }
7543: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7544: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7545: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7546: '</tr>'.
7547: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7548: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7549: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7550: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7551: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7552: '<td class="LC_left_item"><table>'.
7553: '<tr>'.
7554: '<td valign="top">'.$lt{'remoteip'}.': '.
7555: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7556: foreach my $option ('m','h','n') {
7557: my $sel;
1.160.6.114 raeburn 7558: if ($option eq $curr_remotip) {
7559: $sel = ' selected="selected"';
7560: }
7561: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7562: $ip_methods{$option}.'</option>';
7563: }
7564: $datatable .= '</select></td></tr>'."\n".
7565: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7566: $lt{'ipheader'}.': '.
7567: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7568: 'name="wafproxy_ipheader" />'.
7569: '</td></tr>'."\n".
7570: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7571: $lt{'trusted'}.':<br />'.
7572: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7573: $values{$dom}{'trusted'}.'</textarea>'.
7574: '</td></tr>'."\n".
7575: '<tr><td><hr /></td></tr>'."\n".
7576: '<tr>'.
1.160.6.113 raeburn 7577: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7578: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7579: $lt{'vpndirect'}.'</label>'.(' 'x2).
7580: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7581: $lt{'vpnaliased'}.'</label></span></td></tr>';
7582: foreach my $item ('vpnint','vpnext') {
7583: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7584: '<td valign="top">'.$lt{$item}.':<br />'.
7585: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7586: $values{$dom}{$item}.'</textarea>'.
7587: '</td></tr>'."\n";
7588: }
7589: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7590: '<tr>'.
7591: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7592: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7593: $lt{'alltossl'}.'</label>'.(' 'x2).
7594: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7595: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7596: '</table></td></tr>';
7597: }
7598: if (keys(%otherdoms)) {
7599: foreach my $domain (sort(keys(%otherdoms))) {
7600: $itemcount ++;
7601: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7602: $datatable .= '<tr'.$css_class.'>'.
7603: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7604: '<td class="LC_left_item"><table>';
7605: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7606: my $showval = &mt('None');
7607: if ($item eq 'ssl') {
7608: $showval = $lt{'ssltossl'};
7609: }
7610: if ($values{$domain}{$item}) {
7611: $showval = $values{$domain}{$item};
7612: if ($item eq 'ssl') {
7613: $showval = $lt{'alltossl'};
7614: } elsif ($item eq 'remoteip') {
7615: $showval = $ip_methods{$values{$domain}{$item}};
7616: }
7617: }
7618: $datatable .= '<tr>'.
7619: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7620: }
7621: $datatable .= '</table></td></tr>';
7622: }
7623: }
7624: }
7625: $$rowtotal += $itemcount;
7626: return $datatable;
7627: }
7628:
7629: sub wafproxy_titles {
7630: return &Apache::lonlocal::texthash(
7631: remoteip => "Method for determining user's IP",
7632: ipheader => 'Request header containing remote IP',
7633: trusted => 'Trusted IP range(s)',
7634: vpnaccess => 'Access from institutional VPN',
7635: vpndirect => 'via regular hostname (no WAF)',
7636: vpnaliased => 'via aliased hostname (WAF)',
7637: vpnint => 'Internal IP Range(s) for VPN sessions',
7638: vpnext => 'IP Range(s) for backend WAF connections',
7639: sslopt => 'Forwarding http/https',
7640: alltossl => 'WAF forwards both http and https requests to https',
7641: ssltossl => 'WAF forwards http requests to http and https to https',
7642: );
7643: }
7644:
7645: sub remoteip_methods {
7646: return &Apache::lonlocal::texthash(
7647: m => 'Use Apache mod_remoteip',
7648: h => 'Use headers parsed by LON-CAPA',
7649: n => 'Not in use',
7650: );
7651: }
7652:
1.137 raeburn 7653: sub print_usersessions {
7654: my ($position,$dom,$settings,$rowtotal) = @_;
7655: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 7656: my (%by_ip,%by_location,@intdoms);
7657: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 7658:
7659: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7660: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7661: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7662: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7663: my $itemcount = 1;
7664: if ($position eq 'top') {
1.152 raeburn 7665: if (keys(%serverhomes) > 1) {
1.145 raeburn 7666: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 7667: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 7668: if (ref($settings) eq 'HASH') {
7669: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7670: $curroffloadnow = $settings->{'offloadnow'};
7671: }
1.160.6.105 raeburn 7672: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7673: $curroffloadoth = $settings->{'offloadoth'};
7674: }
1.160.6.61 raeburn 7675: }
1.160.6.105 raeburn 7676: my $other_insts = scalar(keys(%by_location));
7677: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7678: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7679: } else {
1.140 raeburn 7680: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7681:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7682:23): '</td></tr>';
1.140 raeburn 7683: }
1.137 raeburn 7684: } else {
1.145 raeburn 7685: if (keys(%by_location) == 0) {
7686: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7687:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7688:23): '</td></tr>';
1.145 raeburn 7689: } else {
7690: my %lt = &usersession_titles();
7691: my $numinrow = 5;
7692: my $prefix;
7693: my @types;
7694: if ($position eq 'bottom') {
7695: $prefix = 'remote';
7696: @types = ('version','excludedomain','includedomain');
7697: } else {
7698: $prefix = 'hosted';
7699: @types = ('excludedomain','includedomain');
7700: }
7701: my (%current,%checkedon,%checkedoff);
7702: my @lcversions = &Apache::lonnet::all_loncaparevs();
7703: my @locations = sort(keys(%by_location));
7704: foreach my $type (@types) {
7705: $checkedon{$type} = '';
7706: $checkedoff{$type} = ' checked="checked"';
7707: }
7708: if (ref($settings) eq 'HASH') {
7709: if (ref($settings->{$prefix}) eq 'HASH') {
7710: foreach my $key (keys(%{$settings->{$prefix}})) {
7711: $current{$key} = $settings->{$prefix}{$key};
7712: if ($key eq 'version') {
7713: if ($current{$key} ne '') {
7714: $checkedon{$key} = ' checked="checked"';
7715: $checkedoff{$key} = '';
7716: }
7717: } elsif (ref($current{$key}) eq 'ARRAY') {
7718: $checkedon{$key} = ' checked="checked"';
7719: $checkedoff{$key} = '';
7720: }
1.137 raeburn 7721: }
7722: }
7723: }
1.145 raeburn 7724: foreach my $type (@types) {
7725: next if ($type ne 'version' && !@locations);
7726: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7727: $datatable .= '<tr'.$css_class.'>
7728: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7729: <span class="LC_nobreak">
7730: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7731: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7732: if ($type eq 'version') {
7733: my $selector = '<select name="'.$prefix.'_version">';
7734: foreach my $version (@lcversions) {
7735: my $selected = '';
7736: if ($current{'version'} eq $version) {
7737: $selected = ' selected="selected"';
7738: }
7739: $selector .= ' <option value="'.$version.'"'.
7740: $selected.'>'.$version.'</option>';
7741: }
7742: $selector .= '</select> ';
7743: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7744: } else {
7745: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7746: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7747: ' />'.(' 'x2).
7748: '<input type="button" value="'.&mt('uncheck all').'" '.
7749: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7750: "\n".
7751: '</div><div><table>';
7752: my $rem;
7753: for (my $i=0; $i<@locations; $i++) {
7754: my ($showloc,$value,$checkedtype);
7755: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7756: my $ip = $by_location{$locations[$i]}->[0];
7757: if (ref($by_ip{$ip}) eq 'ARRAY') {
7758: $value = join(':',@{$by_ip{$ip}});
7759: $showloc = join(', ',@{$by_ip{$ip}});
7760: if (ref($current{$type}) eq 'ARRAY') {
7761: foreach my $loc (@{$by_ip{$ip}}) {
7762: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7763: $checkedtype = ' checked="checked"';
7764: last;
7765: }
7766: }
1.138 raeburn 7767: }
7768: }
7769: }
1.145 raeburn 7770: $rem = $i%($numinrow);
7771: if ($rem == 0) {
7772: if ($i > 0) {
7773: $datatable .= '</tr>';
7774: }
7775: $datatable .= '<tr>';
7776: }
7777: $datatable .= '<td class="LC_left_item">'.
7778: '<span class="LC_nobreak"><label>'.
7779: '<input type="checkbox" name="'.$prefix.'_'.$type.
7780: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7781: '</label></span></td>';
1.137 raeburn 7782: }
1.145 raeburn 7783: $rem = @locations%($numinrow);
7784: my $colsleft = $numinrow - $rem;
7785: if ($colsleft > 1 ) {
7786: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7787: ' </td>';
7788: } elsif ($colsleft == 1) {
7789: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7790: }
1.145 raeburn 7791: $datatable .= '</tr></table>';
1.137 raeburn 7792: }
1.145 raeburn 7793: $datatable .= '</td></tr>';
7794: $itemcount ++;
1.137 raeburn 7795: }
7796: }
7797: }
7798: $$rowtotal += $itemcount;
7799: return $datatable;
7800: }
7801:
1.138 raeburn 7802: sub build_location_hashes {
7803: my ($intdoms,$by_ip,$by_location) = @_;
7804: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7805: (ref($by_location) eq 'HASH'));
7806: my %iphost = &Apache::lonnet::get_iphost();
7807: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7808: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7809: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7810: foreach my $id (@{$iphost{$primary_ip}}) {
7811: my $intdom = &Apache::lonnet::internet_dom($id);
7812: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7813: push(@{$intdoms},$intdom);
7814: }
7815: }
7816: }
7817: foreach my $ip (keys(%iphost)) {
7818: if (ref($iphost{$ip}) eq 'ARRAY') {
7819: foreach my $id (@{$iphost{$ip}}) {
7820: my $location = &Apache::lonnet::internet_dom($id);
7821: if ($location) {
7822: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7823: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7824: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7825: push(@{$by_ip->{$ip}},$location);
7826: }
7827: } else {
7828: $by_ip->{$ip} = [$location];
7829: }
7830: }
7831: }
7832: }
7833: }
7834: foreach my $ip (sort(keys(%{$by_ip}))) {
7835: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7836: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7837: my $first = $by_ip->{$ip}->[0];
7838: if (ref($by_location->{$first}) eq 'ARRAY') {
7839: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7840: push(@{$by_location->{$first}},$ip);
7841: }
7842: } else {
7843: $by_location->{$first} = [$ip];
7844: }
7845: }
7846: }
7847: return;
7848: }
7849:
1.145 raeburn 7850: sub current_offloads_to {
7851: my ($dom,$settings,$servers) = @_;
7852: my (%spareid,%otherdomconfigs);
1.152 raeburn 7853: if (ref($servers) eq 'HASH') {
1.145 raeburn 7854: foreach my $lonhost (sort(keys(%{$servers}))) {
7855: my $gotspares;
1.152 raeburn 7856: if (ref($settings) eq 'HASH') {
7857: if (ref($settings->{'spares'}) eq 'HASH') {
7858: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7859: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7860: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7861: $gotspares = 1;
7862: }
1.145 raeburn 7863: }
7864: }
7865: unless ($gotspares) {
7866: my $gotspares;
7867: my $serverhomeID =
7868: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7869: my $serverhomedom =
7870: &Apache::lonnet::host_domain($serverhomeID);
7871: if ($serverhomedom ne $dom) {
7872: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7873: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7874: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7875: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7876: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7877: $gotspares = 1;
7878: }
7879: }
7880: } else {
7881: $otherdomconfigs{$serverhomedom} =
7882: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7883: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7884: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7885: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7886: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7887: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7888: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7889: $gotspares = 1;
7890: }
7891: }
7892: }
7893: }
7894: }
7895: }
7896: }
7897: unless ($gotspares) {
7898: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7899: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7900: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7901: } else {
7902: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7903: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7904: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7905: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7906: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7907: } else {
1.150 raeburn 7908: my %what = (
7909: spareid => 1,
7910: );
7911: my ($result,$returnhash) =
7912: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7913: if ($result eq 'ok') {
7914: if (ref($returnhash) eq 'HASH') {
7915: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7916: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7917: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7918: }
7919: }
1.145 raeburn 7920: }
7921: }
7922: }
7923: }
7924: }
7925: }
7926: return %spareid;
7927: }
7928:
7929: sub spares_row {
1.160.6.105 raeburn 7930: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7931: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7932: my $css_class;
7933: my $numinrow = 4;
7934: my $itemcount = 1;
7935: my $datatable;
1.152 raeburn 7936: my %typetitles = &sparestype_titles();
7937: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7938: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7939: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7940: my ($othercontrol,$serverdom);
7941: if ($serverhome ne $server) {
7942: $serverdom = &Apache::lonnet::host_domain($serverhome);
7943: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7944: } else {
7945: $serverdom = &Apache::lonnet::host_domain($server);
7946: if ($serverdom ne $dom) {
7947: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7948: }
7949: }
7950: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 7951: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 7952: if (ref($curroffloadnow) eq 'HASH') {
7953: if ($curroffloadnow->{$server}) {
7954: $checkednow = ' checked="checked"';
7955: }
7956: }
1.160.6.105 raeburn 7957: if (ref($curroffloadoth) eq 'HASH') {
7958: if ($curroffloadoth->{$server}) {
7959: $checkedoth = ' checked="checked"';
7960: }
7961: }
1.145 raeburn 7962: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7963: $datatable .= '<tr'.$css_class.'>
7964: <td rowspan="2">
1.160.6.13 raeburn 7965: <span class="LC_nobreak">'.
7966: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 7967: ,'<b>'.$server.'</b>').'</span><br />'.
7968: '<span class="LC_nobreak">'."\n".
7969: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 7970: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 7971: "\n";
1.160.6.105 raeburn 7972: if ($other_insts) {
7973: $datatable .= '<br />'.
7974: '<span class="LC_nobreak">'."\n".
7975: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7976: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7977: "\n";
7978: }
1.145 raeburn 7979: my (%current,%canselect);
1.152 raeburn 7980: my @choices =
7981: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7982: foreach my $type ('primary','default') {
7983: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7984: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7985: my @spares = @{$spareid->{$server}{$type}};
7986: if (@spares > 0) {
1.152 raeburn 7987: if ($othercontrol) {
7988: $current{$type} = join(', ',@spares);
7989: } else {
7990: $current{$type} .= '<table>';
7991: my $numspares = scalar(@spares);
7992: for (my $i=0; $i<@spares; $i++) {
7993: my $rem = $i%($numinrow);
7994: if ($rem == 0) {
7995: if ($i > 0) {
7996: $current{$type} .= '</tr>';
7997: }
7998: $current{$type} .= '<tr>';
1.145 raeburn 7999: }
1.152 raeburn 8000: $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'".');" /> '.
8001: $spareid->{$server}{$type}[$i].
8002: '</label></td>'."\n";
8003: }
8004: my $rem = @spares%($numinrow);
8005: my $colsleft = $numinrow - $rem;
8006: if ($colsleft > 1 ) {
8007: $current{$type} .= '<td colspan="'.$colsleft.
8008: '" class="LC_left_item">'.
8009: ' </td>';
8010: } elsif ($colsleft == 1) {
8011: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8012: }
1.152 raeburn 8013: $current{$type} .= '</tr></table>';
1.150 raeburn 8014: }
1.145 raeburn 8015: }
8016: }
8017: if ($current{$type} eq '') {
8018: $current{$type} = &mt('None specified');
8019: }
1.152 raeburn 8020: if ($othercontrol) {
8021: if ($type eq 'primary') {
8022: $canselect{$type} = $othercontrol;
8023: }
8024: } else {
8025: $canselect{$type} =
8026: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8027: '<select name="newspare_'.$type.'_'.$server.'" '.
8028: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8029: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8030: if (@choices > 0) {
8031: foreach my $lonhost (@choices) {
8032: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8033: }
8034: }
8035: $canselect{$type} .= '</select>'."\n";
8036: }
8037: } else {
8038: $current{$type} = &mt('Could not be determined');
8039: if ($type eq 'primary') {
8040: $canselect{$type} = $othercontrol;
8041: }
1.145 raeburn 8042: }
1.152 raeburn 8043: if ($type eq 'default') {
8044: $datatable .= '<tr'.$css_class.'>';
8045: }
8046: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8047: '<td>'.$current{$type}.'</td>'."\n".
8048: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8049: }
8050: $itemcount ++;
8051: }
8052: }
8053: $$rowtotal += $itemcount;
8054: return $datatable;
8055: }
8056:
1.152 raeburn 8057: sub possible_newspares {
8058: my ($server,$currspares,$serverhomes,$altids) = @_;
8059: my $serverhostname = &Apache::lonnet::hostname($server);
8060: my %excluded;
8061: if ($serverhostname ne '') {
8062: %excluded = (
8063: $serverhostname => 1,
8064: );
8065: }
8066: if (ref($currspares) eq 'HASH') {
8067: foreach my $type (keys(%{$currspares})) {
8068: if (ref($currspares->{$type}) eq 'ARRAY') {
8069: if (@{$currspares->{$type}} > 0) {
8070: foreach my $curr (@{$currspares->{$type}}) {
8071: my $hostname = &Apache::lonnet::hostname($curr);
8072: $excluded{$hostname} = 1;
8073: }
8074: }
8075: }
8076: }
8077: }
8078: my @choices;
8079: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8080: if (keys(%{$serverhomes}) > 1) {
8081: foreach my $name (sort(keys(%{$serverhomes}))) {
8082: unless ($excluded{$name}) {
8083: if (exists($altids->{$serverhomes->{$name}})) {
8084: push(@choices,$altids->{$serverhomes->{$name}});
8085: } else {
8086: push(@choices,$serverhomes->{$name});
1.145 raeburn 8087: }
8088: }
8089: }
8090: }
8091: }
1.152 raeburn 8092: return sort(@choices);
1.145 raeburn 8093: }
8094:
1.150 raeburn 8095: sub print_loadbalancing {
8096: my ($dom,$settings,$rowtotal) = @_;
8097: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8098: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8099: my $numinrow = 1;
8100: my $datatable;
8101: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 8102: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 8103: if (ref($settings) eq 'HASH') {
8104: %existing = %{$settings};
8105: }
8106: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8107: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 8108: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8109: } else {
8110: return;
8111: }
8112: my ($othertitle,$usertypes,$types) =
8113: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 8114: my $rownum = 8;
1.150 raeburn 8115: if (ref($types) eq 'ARRAY') {
8116: $rownum += scalar(@{$types});
8117: }
1.160.6.7 raeburn 8118: my @css_class = ('LC_odd_row','LC_even_row');
8119: my $balnum = 0;
8120: my $islast;
8121: my (@toshow,$disabledtext);
8122: if (keys(%currbalancer) > 0) {
8123: @toshow = sort(keys(%currbalancer));
8124: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8125: push(@toshow,'');
8126: }
8127: } else {
8128: @toshow = ('');
8129: $disabledtext = &mt('No existing load balancer');
8130: }
8131: foreach my $lonhost (@toshow) {
8132: if ($balnum == scalar(@toshow)-1) {
8133: $islast = 1;
8134: } else {
8135: $islast = 0;
8136: }
8137: my $cssidx = $balnum%2;
8138: my $targets_div_style = 'display: none';
8139: my $disabled_div_style = 'display: block';
8140: my $homedom_div_style = 'display: none';
8141: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
8142: '<td rowspan="'.$rownum.'" valign="top">'.
8143: '<p>';
8144: if ($lonhost eq '') {
8145: $datatable .= '<span class="LC_nobreak">';
8146: if (keys(%currbalancer) > 0) {
8147: $datatable .= &mt('Add balancer:');
8148: } else {
8149: $datatable .= &mt('Enable balancer:');
8150: }
8151: $datatable .= ' '.
8152: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8153: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8154: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8155: '<option value="" selected="selected">'.&mt('None').
8156: '</option>'."\n";
8157: foreach my $server (sort(keys(%servers))) {
8158: next if ($currbalancer{$server});
8159: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8160: }
8161: $datatable .=
8162: '</select>'."\n".
8163: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8164: } else {
8165: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8166: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8167: &mt('Stop balancing').'</label>'.
8168: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8169: $targets_div_style = 'display: block';
8170: $disabled_div_style = 'display: none';
8171: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8172: $homedom_div_style = 'display: block';
8173: }
8174: }
8175: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
8176: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8177: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8178: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8179: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8180: my @sparestypes = ('primary','default');
8181: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 8182: my %hostherechecked = (
8183: no => ' checked="checked"',
8184: );
1.160.6.94 raeburn 8185: my %balcookiechecked = (
8186: no => ' checked="checked"',
8187: );
1.160.6.7 raeburn 8188: foreach my $sparetype (@sparestypes) {
8189: my $targettable;
8190: for (my $i=0; $i<$numspares; $i++) {
8191: my $checked;
8192: if (ref($currtargets{$lonhost}) eq 'HASH') {
8193: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8194: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8195: $checked = ' checked="checked"';
8196: }
8197: }
8198: }
8199: my ($chkboxval,$disabled);
8200: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8201: $chkboxval = $spares[$i];
8202: }
8203: if (exists($currbalancer{$spares[$i]})) {
8204: $disabled = ' disabled="disabled"';
8205: }
8206: $targettable .=
1.160.6.55 raeburn 8207: '<td><span class="LC_nobreak"><label>'.
8208: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 8209: $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 8210: '</span></label></span></td>';
1.160.6.7 raeburn 8211: my $rem = $i%($numinrow);
8212: if ($rem == 0) {
8213: if (($i > 0) && ($i < $numspares-1)) {
8214: $targettable .= '</tr>';
8215: }
8216: if ($i < $numspares-1) {
8217: $targettable .= '<tr>';
1.150 raeburn 8218: }
8219: }
8220: }
1.160.6.7 raeburn 8221: if ($targettable ne '') {
8222: my $rem = $numspares%($numinrow);
8223: my $colsleft = $numinrow - $rem;
8224: if ($colsleft > 1 ) {
8225: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8226: ' </td>';
8227: } elsif ($colsleft == 1) {
8228: $targettable .= '<td class="LC_left_item"> </td>';
8229: }
8230: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8231: '<table><tr>'.$targettable.'</tr></table><br />';
8232: }
1.160.6.76 raeburn 8233: $hostherechecked{$sparetype} = '';
8234: if (ref($currtargets{$lonhost}) eq 'HASH') {
8235: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8236: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8237: $hostherechecked{$sparetype} = ' checked="checked"';
8238: $hostherechecked{'no'} = '';
8239: }
8240: }
8241: }
8242: }
1.160.6.94 raeburn 8243: if ($currcookies{$lonhost}) {
8244: %balcookiechecked = (
8245: yes => ' checked="checked"',
8246: );
8247: }
1.160.6.76 raeburn 8248: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8249: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8250: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8251: foreach my $sparetype (@sparestypes) {
8252: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8253: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8254: '</i></label><br />';
1.160.6.7 raeburn 8255: }
1.160.6.94 raeburn 8256: $datatable .= &mt('Use balancer cookie').'<br />'.
8257: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8258: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8259: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8260: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8261: '</div></td></tr>'.
1.160.6.7 raeburn 8262: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8263: $othertitle,$usertypes,$types,\%servers,
8264: \%currbalancer,$lonhost,
8265: $targets_div_style,$homedom_div_style,
8266: $css_class[$cssidx],$balnum,$islast);
8267: $$rowtotal += $rownum;
8268: $balnum ++;
8269: }
8270: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8271: return $datatable;
8272: }
8273:
8274: sub get_loadbalancers_config {
1.160.6.94 raeburn 8275: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 8276: return unless ((ref($servers) eq 'HASH') &&
8277: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 8278: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8279: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 8280: if (keys(%{$existing}) > 0) {
8281: my $oldlonhost;
8282: foreach my $key (sort(keys(%{$existing}))) {
8283: if ($key eq 'lonhost') {
8284: $oldlonhost = $existing->{'lonhost'};
8285: $currbalancer->{$oldlonhost} = 1;
8286: } elsif ($key eq 'targets') {
8287: if ($oldlonhost) {
8288: $currtargets->{$oldlonhost} = $existing->{'targets'};
8289: }
8290: } elsif ($key eq 'rules') {
8291: if ($oldlonhost) {
8292: $currrules->{$oldlonhost} = $existing->{'rules'};
8293: }
8294: } elsif (ref($existing->{$key}) eq 'HASH') {
8295: $currbalancer->{$key} = 1;
8296: $currtargets->{$key} = $existing->{$key}{'targets'};
8297: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 8298: if ($existing->{$key}{'cookie'}) {
8299: $currcookies->{$key} = 1;
8300: }
1.150 raeburn 8301: }
8302: }
1.160.6.7 raeburn 8303: } else {
8304: my ($balancerref,$targetsref) =
8305: &Apache::lonnet::get_lonbalancer_config($servers);
8306: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8307: foreach my $server (sort(keys(%{$balancerref}))) {
8308: $currbalancer->{$server} = 1;
8309: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8310: }
8311: }
8312: }
1.160.6.7 raeburn 8313: return;
1.150 raeburn 8314: }
8315:
8316: sub loadbalancing_rules {
8317: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 8318: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8319: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8320: my $output;
1.160.6.7 raeburn 8321: my $num = 0;
8322: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8323: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8324: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8325: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 8326: $num ++;
1.150 raeburn 8327: my $current;
8328: if (ref($currrules) eq 'HASH') {
8329: $current = $currrules->{$type};
8330: }
1.160.6.55 raeburn 8331: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 8332: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8333: $current = '';
8334: }
8335: }
8336: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 8337: $servers,$currbalancer,$lonhost,$dom,
8338: $targets_div_style,$homedom_div_style,
8339: $css_class,$balnum,$num,$islast);
1.150 raeburn 8340: }
8341: }
8342: return $output;
8343: }
8344:
8345: sub loadbalancing_titles {
8346: my ($dom,$intdom,$usertypes,$types) = @_;
8347: my %othertypes = (
8348: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8349: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8350: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8351: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 8352: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8353: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8354: );
1.160.6.26 raeburn 8355: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 8356: my @available;
1.150 raeburn 8357: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8358: @available = @{$types};
1.150 raeburn 8359: }
1.160.6.89 raeburn 8360: unless (grep(/^default$/,@available)) {
8361: push(@available,'default');
8362: }
8363: unshift(@alltypes,@available);
1.150 raeburn 8364: my %titles;
8365: foreach my $type (@alltypes) {
8366: if ($type =~ /^_LC_/) {
8367: $titles{$type} = $othertypes{$type};
8368: } elsif ($type eq 'default') {
8369: $titles{$type} = &mt('All users from [_1]',$dom);
8370: if (ref($types) eq 'ARRAY') {
8371: if (@{$types} > 0) {
8372: $titles{$type} = &mt('Other users from [_1]',$dom);
8373: }
8374: }
8375: } elsif (ref($usertypes) eq 'HASH') {
8376: $titles{$type} = $usertypes->{$type};
8377: }
8378: }
8379: return (\@alltypes,\%othertypes,\%titles);
8380: }
8381:
8382: sub loadbalance_rule_row {
1.160.6.7 raeburn 8383: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8384: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 8385: my @rulenames;
1.150 raeburn 8386: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 8387: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 8388: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8389: } else {
1.160.6.26 raeburn 8390: @rulenames = ('default','homeserver');
8391: if ($type eq '_LC_external') {
8392: push(@rulenames,'externalbalancer');
8393: } else {
8394: push(@rulenames,'specific');
8395: }
8396: push(@rulenames,'none');
1.150 raeburn 8397: }
8398: my $style = $targets_div_style;
1.160.6.55 raeburn 8399: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8400: $style = $homedom_div_style;
8401: }
1.160.6.7 raeburn 8402: my $space;
8403: if ($islast && $num == 1) {
1.160.6.118.2 14(raebu 8404:23): $space = '<div style="display:inline-block;"> </div>';
1.160.6.7 raeburn 8405: }
8406: my $output =
8407: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8408: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8409: '<td valaign="top">'.$space.
8410: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8411: for (my $i=0; $i<@rulenames; $i++) {
8412: my $rule = $rulenames[$i];
8413: my ($checked,$extra);
8414: if ($rulenames[$i] eq 'default') {
8415: $rule = '';
8416: }
8417: if ($rulenames[$i] eq 'specific') {
8418: if (ref($servers) eq 'HASH') {
8419: my $default;
8420: if (($current ne '') && (exists($servers->{$current}))) {
8421: $checked = ' checked="checked"';
8422: }
8423: unless ($checked) {
8424: $default = ' selected="selected"';
8425: }
1.160.6.7 raeburn 8426: $extra =
8427: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8428: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8429: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8430: '<option value=""'.$default.'></option>'."\n";
8431: foreach my $server (sort(keys(%{$servers}))) {
8432: if (ref($currbalancer) eq 'HASH') {
8433: next if (exists($currbalancer->{$server}));
8434: }
1.150 raeburn 8435: my $selected;
1.160.6.7 raeburn 8436: if ($server eq $current) {
1.150 raeburn 8437: $selected = ' selected="selected"';
8438: }
1.160.6.7 raeburn 8439: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8440: }
8441: $extra .= '</select>';
8442: }
8443: } elsif ($rule eq $current) {
8444: $checked = ' checked="checked"';
8445: }
8446: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 8447: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8448: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8449: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 8450: ')"'.$checked.' /> ';
1.160.6.56 raeburn 8451: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 8452: $output .= $ruletitles{'particular'};
8453: } else {
8454: $output .= $ruletitles{$rulenames[$i]};
8455: }
8456: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8457: }
8458: $output .= '</div></td></tr>'."\n";
8459: return $output;
8460: }
8461:
8462: sub offloadtype_text {
8463: my %ruletitles = &Apache::lonlocal::texthash (
8464: 'default' => 'Offloads to default destinations',
8465: 'homeserver' => "Offloads to user's home server",
8466: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8467: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 8468: 'none' => 'No offload',
1.160.6.26 raeburn 8469: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8470: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 8471: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8472: );
8473: return %ruletitles;
8474: }
8475:
8476: sub sparestype_titles {
8477: my %typestitles = &Apache::lonlocal::texthash (
8478: 'primary' => 'primary',
8479: 'default' => 'default',
8480: );
8481: return %typestitles;
8482: }
8483:
1.28 raeburn 8484: sub contact_titles {
8485: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 8486: 'supportemail' => 'Support E-mail address',
8487: 'adminemail' => 'Default Server Admin E-mail address',
8488: 'errormail' => 'Error reports to be e-mailed to',
8489: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 8490: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8491: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 8492: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8493: 'requestsmail' => 'E-mail from course requests requiring approval',
8494: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 8495: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 8496: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 8497: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8498: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 8499: 'errorweights' => 'Weights used to compute error count',
8500: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8501: );
8502: my %short_titles = &Apache::lonlocal::texthash (
8503: adminemail => 'Admin E-mail address',
8504: supportemail => 'Support E-mail',
8505: );
8506: return (\%titles,\%short_titles);
8507: }
8508:
1.160.6.78 raeburn 8509: sub helpform_fields {
8510: my %titles = &Apache::lonlocal::texthash (
8511: 'username' => 'Name',
8512: 'user' => 'Username/domain',
8513: 'phone' => 'Phone',
8514: 'cc' => 'Cc e-mail',
8515: 'course' => 'Course Details',
8516: 'section' => 'Sections',
8517: 'screenshot' => 'File upload',
8518: );
8519: my @fields = ('username','phone','user','course','section','cc','screenshot');
8520: my %possoptions = (
8521: username => ['yes','no','req'],
8522: phone => ['yes','no','req'],
8523: user => ['yes','no'],
8524: cc => ['yes','no'],
8525: course => ['yes','no'],
8526: section => ['yes','no'],
8527: screenshot => ['yes','no'],
8528: );
8529: my %fieldoptions = &Apache::lonlocal::texthash (
8530: 'yes' => 'Optional',
8531: 'req' => 'Required',
8532: 'no' => "Not shown",
8533: );
8534: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8535: }
8536:
1.72 raeburn 8537: sub tool_titles {
8538: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 8539: aboutme => 'Personal web page',
1.86 raeburn 8540: blog => 'Blog',
8541: portfolio => 'Portfolio',
1.160.6.118.2 23(raebu 8542:24): portaccess => 'Share portfolio files',
10(raebu 8543:22): timezone => 'Can set time zone',
1.88 bisitz 8544: official => 'Official courses (with institutional codes)',
8545: unofficial => 'Unofficial courses',
1.98 raeburn 8546: community => 'Communities',
1.160.6.30 raeburn 8547: textbook => 'Textbook courses',
1.86 raeburn 8548: );
1.72 raeburn 8549: return %titles;
8550: }
8551:
1.101 raeburn 8552: sub courserequest_titles {
8553: my %titles = &Apache::lonlocal::texthash (
8554: official => 'Official',
8555: unofficial => 'Unofficial',
8556: community => 'Communities',
1.160.6.30 raeburn 8557: textbook => 'Textbook',
1.160.6.118.2 14(raebu 8558:23): lti => 'LTI Provider',
1.101 raeburn 8559: norequest => 'Not allowed',
1.104 raeburn 8560: approval => 'Approval by Dom. Coord.',
1.101 raeburn 8561: validate => 'With validation',
8562: autolimit => 'Numerical limit',
1.103 raeburn 8563: unlimited => '(blank for unlimited)',
1.101 raeburn 8564: );
8565: return %titles;
8566: }
8567:
1.160.6.5 raeburn 8568: sub authorrequest_titles {
8569: my %titles = &Apache::lonlocal::texthash (
8570: norequest => 'Not allowed',
8571: approval => 'Approval by Dom. Coord.',
8572: automatic => 'Automatic approval',
8573: );
8574: return %titles;
8575: }
8576:
1.101 raeburn 8577: sub courserequest_conditions {
8578: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8579: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 8580: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8581: );
8582: return %conditions;
8583: }
8584:
8585:
1.27 raeburn 8586: sub print_usercreation {
1.30 raeburn 8587: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8588: my $numinrow = 4;
1.28 raeburn 8589: my $datatable;
8590: if ($position eq 'top') {
1.30 raeburn 8591: $$rowtotal ++;
1.34 raeburn 8592: my $rowcount = 0;
1.32 raeburn 8593: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8594: if (ref($rules) eq 'HASH') {
8595: if (keys(%{$rules}) > 0) {
1.32 raeburn 8596: $datatable .= &user_formats_row('username',$settings,$rules,
8597: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8598: $$rowtotal ++;
1.32 raeburn 8599: $rowcount ++;
8600: }
8601: }
8602: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8603: if (ref($idrules) eq 'HASH') {
8604: if (keys(%{$idrules}) > 0) {
8605: $datatable .= &user_formats_row('id',$settings,$idrules,
8606: $idruleorder,$numinrow,$rowcount);
8607: $$rowtotal ++;
8608: $rowcount ++;
1.28 raeburn 8609: }
8610: }
1.39 raeburn 8611: if ($rowcount == 0) {
8612: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8613: $$rowtotal ++;
8614: $rowcount ++;
8615: }
1.34 raeburn 8616: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 8617: my @creators = ('author','course','requestcrs');
1.37 raeburn 8618: my ($rules,$ruleorder) =
8619: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8620: my %lt = &usercreation_types();
8621: my %checked;
8622: if (ref($settings) eq 'HASH') {
8623: if (ref($settings->{'cancreate'}) eq 'HASH') {
8624: foreach my $item (@creators) {
8625: $checked{$item} = $settings->{'cancreate'}{$item};
8626: }
8627: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8628: foreach my $item (@creators) {
8629: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8630: $checked{$item} = 'none';
8631: }
8632: }
8633: }
8634: }
8635: my $rownum = 0;
8636: foreach my $item (@creators) {
8637: $rownum ++;
1.160.6.34 raeburn 8638: if ($checked{$item} eq '') {
8639: $checked{$item} = 'any';
1.34 raeburn 8640: }
8641: my $css_class;
8642: if ($rownum%2) {
8643: $css_class = '';
8644: } else {
8645: $css_class = ' class="LC_odd_row" ';
8646: }
8647: $datatable .= '<tr'.$css_class.'>'.
8648: '<td><span class="LC_nobreak">'.$lt{$item}.
8649: '</span></td><td align="right">';
1.160.6.34 raeburn 8650: my @options = ('any');
8651: if (ref($rules) eq 'HASH') {
8652: if (keys(%{$rules}) > 0) {
8653: push(@options,('official','unofficial'));
1.37 raeburn 8654: }
8655: }
1.160.6.34 raeburn 8656: push(@options,'none');
1.37 raeburn 8657: foreach my $option (@options) {
1.50 raeburn 8658: my $type = 'radio';
1.34 raeburn 8659: my $check = ' ';
1.160.6.34 raeburn 8660: if ($checked{$item} eq $option) {
8661: $check = ' checked="checked" ';
1.34 raeburn 8662: }
8663: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8664: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8665: $item.'" value="'.$option.'"'.$check.'/> '.
8666: $lt{$option}.'</label> </span>';
8667: }
8668: $datatable .= '</td></tr>';
8669: }
1.28 raeburn 8670: } else {
8671: my @contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 8672:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8673: my %checked;
8674: if (ref($settings) eq 'HASH') {
8675: if (ref($settings->{'authtypes'}) eq 'HASH') {
8676: foreach my $item (@contexts) {
8677: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8678: foreach my $auth (@authtypes) {
8679: if ($settings->{'authtypes'}{$item}{$auth}) {
8680: $checked{$item}{$auth} = ' checked="checked" ';
8681: }
8682: }
8683: }
8684: }
1.27 raeburn 8685: }
1.35 raeburn 8686: } else {
8687: foreach my $item (@contexts) {
1.36 raeburn 8688: foreach my $auth (@authtypes) {
1.35 raeburn 8689: $checked{$item}{$auth} = ' checked="checked" ';
8690: }
8691: }
1.27 raeburn 8692: }
1.28 raeburn 8693: my %title = &context_names();
8694: my %authname = &authtype_names();
8695: my $rownum = 0;
8696: my $css_class;
8697: foreach my $item (@contexts) {
8698: if ($rownum%2) {
8699: $css_class = '';
8700: } else {
8701: $css_class = ' class="LC_odd_row" ';
8702: }
1.30 raeburn 8703: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8704: '<td>'.$title{$item}.
8705: '</td><td class="LC_left_item">'.
8706: '<span class="LC_nobreak">';
8707: foreach my $auth (@authtypes) {
8708: $datatable .= '<label>'.
8709: '<input type="checkbox" name="'.$item.'_auth" '.
8710: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8711: $authname{$auth}.'</label> ';
8712: }
8713: $datatable .= '</span></td></tr>';
8714: $rownum ++;
1.27 raeburn 8715: }
1.30 raeburn 8716: $$rowtotal += $rownum;
1.27 raeburn 8717: }
8718: return $datatable;
8719: }
8720:
1.160.6.34 raeburn 8721: sub print_selfcreation {
8722: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 8723: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8724: $emaildomain,$datatable);
1.160.6.34 raeburn 8725: if (ref($settings) eq 'HASH') {
8726: if (ref($settings->{'cancreate'}) eq 'HASH') {
8727: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 8728: if (ref($createsettings) eq 'HASH') {
8729: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8730: @selfcreate = @{$createsettings->{'selfcreate'}};
8731: } elsif ($createsettings->{'selfcreate'} ne '') {
8732: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8733: @selfcreate = ('email','login','sso');
8734: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8735: @selfcreate = ($createsettings->{'selfcreate'});
8736: }
8737: }
8738: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8739: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 8740: }
1.160.6.93 raeburn 8741: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8742: $emailoptions = $createsettings->{'emailoptions'};
8743: }
8744: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8745: $emailverified = $createsettings->{'emailverified'};
8746: }
8747: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8748: $emaildomain = $createsettings->{'emaildomain'};
8749: }
1.160.6.34 raeburn 8750: }
8751: }
8752: }
8753: my %radiohash;
8754: my $numinrow = 4;
8755: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 8756: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 8757: if ($position eq 'top') {
8758: my %choices = &Apache::lonlocal::texthash (
8759: cancreate_login => 'Institutional Login',
8760: cancreate_sso => 'Institutional Single Sign On',
8761: );
8762: my @toggles = sort(keys(%choices));
8763: my %defaultchecked = (
8764: 'cancreate_login' => 'off',
8765: 'cancreate_sso' => 'off',
8766: );
1.160.6.35 raeburn 8767: my ($onclick,$itemcount);
1.160.6.34 raeburn 8768: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8769: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 8770: $$rowtotal += $itemcount;
1.160.6.34 raeburn 8771:
8772: if (ref($usertypes) eq 'HASH') {
8773: if (keys(%{$usertypes}) > 0) {
8774: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8775: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 8776: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 8777: $$rowtotal ++;
8778: }
8779: }
1.160.6.44 raeburn 8780: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8781: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8782: $fieldtitles{'inststatus'} = &mt('Institutional status');
8783: my $rem;
8784: my $numperrow = 2;
8785: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8786: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 8787: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 8788: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 8789: '<table>'."\n";
1.160.6.44 raeburn 8790: for (my $i=0; $i<@fields; $i++) {
8791: $rem = $i%($numperrow);
8792: if ($rem == 0) {
8793: if ($i > 0) {
8794: $datatable .= '</tr>';
8795: }
8796: $datatable .= '<tr>';
8797: }
8798: my $currval;
1.160.6.51 raeburn 8799: if (ref($createsettings) eq 'HASH') {
8800: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8801: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8802: }
1.160.6.44 raeburn 8803: }
8804: $datatable .= '<td class="LC_left_item">'.
8805: '<span class="LC_nobreak">'.
8806: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8807: 'value="'.$currval.'" size="10" /> '.
8808: $fieldtitles{$fields[$i]}.'</span></td>';
8809: }
8810: my $colsleft = $numperrow - $rem;
8811: if ($colsleft > 1 ) {
8812: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8813: ' </td>';
8814: } elsif ($colsleft == 1) {
8815: $datatable .= '<td class="LC_left_item"> </td>';
8816: }
8817: $datatable .= '</tr></table></td></tr>';
8818: $$rowtotal ++;
1.160.6.34 raeburn 8819: } elsif ($position eq 'middle') {
8820: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 8821: my @posstypes;
1.160.6.34 raeburn 8822: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8823: @posstypes = @{$types};
8824: }
8825: unless (grep(/^default$/,@posstypes)) {
8826: push(@posstypes,'default');
8827: }
8828: my %usertypeshash;
8829: if (ref($usertypes) eq 'HASH') {
8830: %usertypeshash = %{$usertypes};
8831: }
8832: $usertypeshash{'default'} = $othertitle;
8833: foreach my $status (@posstypes) {
8834: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8835: $numinrow,$$rowtotal,\%usertypeshash);
8836: $$rowtotal ++;
1.160.6.34 raeburn 8837: }
8838: } else {
1.160.6.40 raeburn 8839: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 8840: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 8841: );
8842: my @toggles = sort(keys(%choices));
8843: my %defaultchecked = (
8844: 'cancreate_email' => 'off',
8845: );
1.160.6.93 raeburn 8846: my $customclass = 'LC_selfcreate_email';
8847: my $classprefix = 'LC_canmodify_emailusername_';
8848: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 8849: my $display = 'none';
1.160.6.93 raeburn 8850: my $rowstyle = 'display:none';
1.160.6.40 raeburn 8851: if (grep(/^\Qemail\E$/,@selfcreate)) {
8852: $display = 'block';
1.160.6.93 raeburn 8853: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 8854: }
1.160.6.93 raeburn 8855: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8856: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8857: \%choices,$$rowtotal,$onclick);
8858: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8859: $rowstyle);
8860: $$rowtotal ++;
8861: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8862: $rowstyle);
8863: $$rowtotal ++;
8864: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 8865: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 8866: my ($emailrules,$emailruleorder) =
8867: &Apache::lonnet::inst_userrules($dom,'email');
8868: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8869: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8870: if (ref($types) eq 'ARRAY') {
8871: @posstypes = @{$types};
8872: }
8873: if (@posstypes) {
8874: unless (grep(/^default$/,@posstypes)) {
8875: push(@posstypes,'default');
1.160.6.89 raeburn 8876: }
8877: if (ref($usertypes) eq 'HASH') {
8878: %usertypeshash = %{$usertypes};
8879: }
1.160.6.93 raeburn 8880: my $currassign;
8881: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8882: $currassign = {
8883: selfassign => $domdefaults{'inststatusguest'},
8884: };
8885: @ordered = @{$domdefaults{'inststatusguest'}};
8886: } else {
8887: $currassign = { selfassign => [] };
8888: }
8889: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8890: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8891: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8892: $numinrow,$othertitle,'selfassign',
8893: $rowtotal,$onclicktypes,$customclass,
8894: $rowstyle);
8895: $$rowtotal ++;
1.160.6.89 raeburn 8896: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8897: foreach my $status (@posstypes) {
8898: my $css_class;
8899: if ($$rowtotal%2) {
8900: $css_class = 'LC_odd_row ';
8901: }
8902: $css_class .= $customclass;
8903: my $rowid = $optionsprefix.$status;
8904: my $hidden = 1;
8905: my $currstyle = 'display:none';
8906: if (grep(/^\Q$status\E$/,@ordered)) {
8907: $currstyle = $rowstyle;
8908: $hidden = 0;
8909: }
8910: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8911: $emailrules,$emailruleorder,$settings,$status,$rowid,
8912: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8913: unless ($hidden) {
8914: $$rowtotal ++;
8915: }
1.160.6.89 raeburn 8916: }
8917: } else {
1.160.6.93 raeburn 8918: my $css_class;
8919: if ($$rowtotal%2) {
8920: $css_class = 'LC_odd_row ';
8921: }
8922: $css_class .= $customclass;
1.160.6.89 raeburn 8923: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8924: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8925: $emailrules,$emailruleorder,$settings,'default','',
8926: $othertitle,$css_class,$rowstyle,$intdom);
8927: $$rowtotal ++;
1.160.6.34 raeburn 8928: }
1.160.6.35 raeburn 8929: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8930: $numinrow = 1;
1.160.6.93 raeburn 8931: if (@posstypes) {
8932: foreach my $status (@posstypes) {
8933: my $rowid = $classprefix.$status;
8934: my $datarowstyle = 'display:none';
8935: if (grep(/^\Q$status\E$/,@ordered)) {
8936: $datarowstyle = $rowstyle;
8937: }
8938: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8939: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8940: $infotitles,$rowid,$customclass,$datarowstyle);
8941: unless ($datarowstyle eq 'display:none') {
8942: $$rowtotal ++;
8943: }
1.160.6.34 raeburn 8944: }
1.160.6.93 raeburn 8945: } else {
8946: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8947: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8948: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 8949: }
8950: }
8951: return $datatable;
8952: }
8953:
1.160.6.93 raeburn 8954: sub selfcreate_javascript {
8955: return <<"ENDSCRIPT";
8956:
8957: <script type="text/javascript">
8958: // <![CDATA[
8959:
8960: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8961: var x = document.getElementsByClassName(target);
8962: var insttypes = 0;
8963: var insttypeRegExp = new RegExp(prefix);
8964: if ((x.length != undefined) && (x.length > 0)) {
8965: if (form.elements[radio].length != undefined) {
8966: for (var i=0; i<form.elements[radio].length; i++) {
8967: if (form.elements[radio][i].checked) {
8968: if (form.elements[radio][i].value == 1) {
8969: for (var j=0; j<x.length; j++) {
8970: if (x[j].id == 'undefined') {
8971: x[j].style.display = 'table-row';
8972: } else if (insttypeRegExp.test(x[j].id)) {
8973: insttypes ++;
8974: } else {
8975: x[j].style.display = 'table-row';
8976: }
8977: }
8978: } else {
8979: for (var j=0; j<x.length; j++) {
8980: x[j].style.display = 'none';
8981: }
1.160.6.40 raeburn 8982: }
1.160.6.93 raeburn 8983: break;
8984: }
8985: }
8986: if (insttypes > 0) {
8987: toggleDataRow(form,checkbox,target,altprefix);
8988: toggleDataRow(form,checkbox,target,prefix,1);
8989: }
8990: }
8991: }
8992: return;
8993: }
8994:
8995: function toggleDataRow(form,checkbox,target,prefix,docount) {
8996: if (form.elements[checkbox].length != undefined) {
8997: var count = 0;
8998: if (docount) {
8999: for (var i=0; i<form.elements[checkbox].length; i++) {
9000: if (form.elements[checkbox][i].checked) {
9001: count ++;
9002: }
9003: }
9004: }
9005: for (var i=0; i<form.elements[checkbox].length; i++) {
9006: var type = form.elements[checkbox][i].value;
9007: if (document.getElementById(prefix+type)) {
9008: if (form.elements[checkbox][i].checked) {
9009: document.getElementById(prefix+type).style.display = 'table-row';
9010: if (count % 2 == 1) {
9011: document.getElementById(prefix+type).className = target+' LC_odd_row';
9012: } else {
9013: document.getElementById(prefix+type).className = target;
9014: }
9015: count ++;
1.160.6.40 raeburn 9016: } else {
1.160.6.93 raeburn 9017: document.getElementById(prefix+type).style.display = 'none';
9018: }
9019: }
9020: }
9021: }
9022: return;
9023: }
9024:
9025: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9026: var caller = radio+'_'+status;
9027: if (form.elements[caller].length != undefined) {
9028: for (var i=0; i<form.elements[caller].length; i++) {
9029: if (form.elements[caller][i].checked) {
9030: if (document.getElementById(altprefix+'_inst_'+status)) {
9031: var curr = form.elements[caller][i].value;
9032: if (prefix) {
9033: document.getElementById(prefix+'_'+status).style.display = 'none';
9034: }
9035: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9036: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9037: if (curr == 'custom') {
9038: if (prefix) {
9039: document.getElementById(prefix+'_'+status).style.display = 'inline';
9040: }
9041: } else if (curr == 'inst') {
9042: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9043: } else if (curr == 'noninst') {
9044: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 9045: }
1.160.6.93 raeburn 9046: break;
1.160.6.40 raeburn 9047: }
1.160.6.93 raeburn 9048: }
9049: }
9050: }
9051: }
9052:
9053: // ]]>
9054: </script>
9055:
9056: ENDSCRIPT
9057: }
9058:
9059: sub noninst_users {
9060: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9061: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9062: my $class = 'LC_left_item';
9063: if ($css_class) {
9064: $css_class = ' class="'.$css_class.'"';
9065: }
9066: if ($rowid) {
9067: $rowid = ' id="'.$rowid.'"';
9068: }
9069: if ($rowstyle) {
9070: $rowstyle = ' style="'.$rowstyle.'"';
9071: }
9072: my ($output,$description);
9073: if ($type eq 'default') {
9074: $description = &mt('Requests for: [_1]',$typetitle);
9075: } else {
9076: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9077: }
9078: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9079: "<td>$description</td>\n".
9080: '<td class="'.$class.'" colspan="2">'.
9081: '<table><tr>';
9082: my %headers = &Apache::lonlocal::texthash(
9083: approve => 'Processing',
9084: email => 'E-mail',
9085: username => 'Username',
9086: );
9087: foreach my $item ('approve','email','username') {
9088: $output .= '<th>'.$headers{$item}.'</th>';
9089: }
9090: $output .= '</tr><tr>';
9091: foreach my $item ('approve','email','username') {
9092: $output .= '<td valign="top">';
9093: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9094: if ($item eq 'approve') {
9095: %choices = &Apache::lonlocal::texthash (
9096: automatic => 'Automatically approved',
9097: approval => 'Queued for approval',
9098: );
9099: @options = ('automatic','approval');
9100: $hashref = $processing;
9101: $defoption = 'automatic';
9102: $name = 'cancreate_emailprocess_'.$type;
9103: } elsif ($item eq 'email') {
9104: %choices = &Apache::lonlocal::texthash (
9105: any => 'Any e-mail',
9106: inst => 'Institutional only',
9107: noninst => 'Non-institutional only',
9108: custom => 'Custom restrictions',
9109: );
9110: @options = ('any','inst','noninst');
9111: my $showcustom;
9112: if (ref($emailrules) eq 'HASH') {
9113: if (keys(%{$emailrules}) > 0) {
9114: push(@options,'custom');
9115: $showcustom = 'cancreate_emailrule';
9116: if (ref($settings) eq 'HASH') {
9117: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9118: foreach my $rule (@{$settings->{'email_rule'}}) {
9119: if (exists($emailrules->{$rule})) {
9120: $hascustom ++;
9121: }
9122: }
9123: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9124: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9125: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9126: if (exists($emailrules->{$rule})) {
9127: $hascustom ++;
9128: }
9129: }
9130: }
9131: }
9132: }
9133: }
9134: }
9135: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9136: "'cancreate_emaildomain','$type'".');"';
9137: $hashref = $emailoptions;
9138: $defoption = 'any';
9139: $name = 'cancreate_emailoptions_'.$type;
9140: } elsif ($item eq 'username') {
9141: %choices = &Apache::lonlocal::texthash (
9142: all => 'Same as e-mail',
9143: first => 'Omit @domain',
9144: free => 'Free to choose',
9145: );
9146: @options = ('all','first','free');
9147: $hashref = $emailverified;
9148: $defoption = 'all';
9149: $name = 'cancreate_usernameoptions_'.$type;
9150: }
9151: foreach my $option (@options) {
9152: my $checked;
9153: if (ref($hashref) eq 'HASH') {
9154: if ($type eq '') {
9155: if (!exists($hashref->{'default'})) {
9156: if ($option eq $defoption) {
9157: $checked = ' checked="checked"';
9158: }
9159: } else {
9160: if ($hashref->{'default'} eq $option) {
9161: $checked = ' checked="checked"';
9162: }
1.160.6.40 raeburn 9163: }
9164: } else {
1.160.6.93 raeburn 9165: if (!exists($hashref->{$type})) {
9166: if ($option eq $defoption) {
9167: $checked = ' checked="checked"';
9168: }
9169: } else {
9170: if ($hashref->{$type} eq $option) {
9171: $checked = ' checked="checked"';
9172: }
1.160.6.40 raeburn 9173: }
9174: }
1.160.6.93 raeburn 9175: } elsif (($item eq 'email') && ($hascustom)) {
9176: if ($option eq 'custom') {
9177: $checked = ' checked="checked"';
9178: }
9179: } elsif ($option eq $defoption) {
9180: $checked = ' checked="checked"';
9181: }
9182: $output .= '<span class="LC_nobreak"><label>'.
9183: '<input type="radio" name="'.$name.'"'.
9184: $checked.' value="'.$option.'"'.$onclick.' />'.
9185: $choices{$option}.'</label></span><br />';
9186: if ($item eq 'email') {
9187: if ($option eq 'custom') {
9188: my $id = 'cancreate_emailrule_'.$type;
9189: my $display = 'none';
9190: if ($checked) {
9191: $display = 'inline';
9192: }
9193: my $numinrow = 2;
9194: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9195: '<legend>'.&mt('Disallow').'</legend><table>'.
9196: &user_formats_row('email',$settings,$emailrules,
9197: $emailruleorder,$numinrow,'',$type);
9198: '</table></fieldset>';
9199: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9200: my %text = &Apache::lonlocal::texthash (
9201: inst => 'must end:',
9202: noninst => 'cannot end:',
9203: );
9204: my $value;
9205: if (ref($emaildomain) eq 'HASH') {
9206: if (ref($emaildomain->{$type}) eq 'HASH') {
9207: $value = $emaildomain->{$type}->{$option};
9208: }
9209: }
9210: if ($value eq '') {
9211: $value = '@'.$intdom;
9212: }
9213: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9214: my $display = 'none';
9215: if ($checked) {
9216: $display = 'inline';
9217: }
9218: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9219: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9220: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9221: '</div>';
9222: }
1.160.6.40 raeburn 9223: }
9224: }
1.160.6.93 raeburn 9225: $output .= '</td>'."\n";
1.160.6.40 raeburn 9226: }
1.160.6.93 raeburn 9227: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 9228: return $output;
9229: }
9230:
1.160.6.5 raeburn 9231: sub captcha_choice {
1.160.6.93 raeburn 9232: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 9233: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
1.160.6.118.2 14(raebu 9234:23): $vertext,$currver);
1.160.6.5 raeburn 9235: my %lt = &captcha_phrases();
9236: $keyentry = 'hidden';
1.160.6.98 raeburn 9237: my $colspan=2;
1.160.6.5 raeburn 9238: if ($context eq 'cancreate') {
1.160.6.34 raeburn 9239: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 9240: } elsif ($context eq 'login') {
9241: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 9242: } elsif ($context eq 'passwords') {
9243: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9244: $colspan=1;
1.160.6.5 raeburn 9245: }
9246: if (ref($settings) eq 'HASH') {
9247: if ($settings->{'captcha'}) {
9248: $checked{$settings->{'captcha'}} = ' checked="checked"';
9249: } else {
9250: $checked{'original'} = ' checked="checked"';
9251: }
9252: if ($settings->{'captcha'} eq 'recaptcha') {
9253: $pubtext = $lt{'pub'};
9254: $privtext = $lt{'priv'};
9255: $keyentry = 'text';
1.160.6.69 raeburn 9256: $vertext = $lt{'ver'};
9257: $currver = $settings->{'recaptchaversion'};
9258: if ($currver ne '2') {
9259: $currver = 1;
9260: }
1.160.6.5 raeburn 9261: }
9262: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9263: $currpub = $settings->{'recaptchakeys'}{'public'};
9264: $currpriv = $settings->{'recaptchakeys'}{'private'};
9265: }
9266: } else {
9267: $checked{'original'} = ' checked="checked"';
9268: }
1.160.6.93 raeburn 9269: my $css_class;
9270: if ($itemcount%2) {
9271: $css_class = 'LC_odd_row';
9272: }
9273: if ($customcss) {
9274: $css_class .= " $customcss";
9275: }
9276: $css_class =~ s/^\s+//;
9277: if ($css_class) {
9278: $css_class = ' class="'.$css_class.'"';
9279: }
9280: if ($rowstyle) {
9281: $css_class .= ' style="'.$rowstyle.'"';
9282: }
1.160.6.5 raeburn 9283: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 9284: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 9285: '<table><tr><td>'."\n";
9286: foreach my $option ('original','recaptcha','notused') {
9287: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9288: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9289: $lt{$option}.'</label></span>';
9290: unless ($option eq 'notused') {
9291: $output .= (' 'x2)."\n";
9292: }
9293: }
9294: #
9295: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9296: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
9297: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
9298: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
9299: #
9300: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 9301: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 9302: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9303: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9304: $currpub.'" size="40" /></span><br />'."\n".
9305: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9306: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 9307: $currpriv.'" size="40" /></span><br />'.
9308: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9309: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9310: $currver.'" size="3" /></span><br />'.
9311: '</td></tr></table>'."\n".
1.160.6.5 raeburn 9312: '</td></tr>';
9313: return $output;
9314: }
9315:
1.32 raeburn 9316: sub user_formats_row {
1.160.6.93 raeburn 9317: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9318: my $output;
9319: my %text = (
9320: 'username' => 'new usernames',
9321: 'id' => 'IDs',
9322: );
1.160.6.118.2 8(raebur 9323:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 9324: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9325: $output = '<tr '.$css_class.'>'.
9326: '<td><span class="LC_nobreak">'.
9327: &mt("Format rules to check for $text{$type}: ").
9328: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9329: }
1.27 raeburn 9330: my $rem;
9331: if (ref($ruleorder) eq 'ARRAY') {
9332: for (my $i=0; $i<@{$ruleorder}; $i++) {
9333: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9334: my $rem = $i%($numinrow);
9335: if ($rem == 0) {
9336: if ($i > 0) {
9337: $output .= '</tr>';
9338: }
9339: $output .= '<tr>';
9340: }
9341: my $check = ' ';
1.39 raeburn 9342: if (ref($settings) eq 'HASH') {
9343: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9344: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9345: $check = ' checked="checked" ';
9346: }
1.160.6.93 raeburn 9347: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9348: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9349: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9350: $check = ' checked="checked" ';
9351: }
9352: }
1.27 raeburn 9353: }
9354: }
1.160.6.93 raeburn 9355: my $name = $type.'_rule';
9356: if ($type eq 'email') {
9357: $name .= '_'.$status;
9358: }
1.27 raeburn 9359: $output .= '<td class="LC_left_item">'.
9360: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 9361: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9362: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9363: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9364: }
9365: }
9366: $rem = @{$ruleorder}%($numinrow);
9367: }
1.160.6.93 raeburn 9368: my $colsleft;
9369: if ($rem) {
9370: $colsleft = $numinrow - $rem;
9371: }
1.27 raeburn 9372: if ($colsleft > 1 ) {
9373: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9374: ' </td>';
9375: } elsif ($colsleft == 1) {
9376: $output .= '<td class="LC_left_item"> </td>';
9377: }
1.160.6.118.2 8(raebur 9378:2): $output .= '</tr>';
9379:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
9380:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 9381: }
1.27 raeburn 9382: return $output;
9383: }
9384:
1.34 raeburn 9385: sub usercreation_types {
9386: my %lt = &Apache::lonlocal::texthash (
9387: author => 'When adding a co-author',
9388: course => 'When adding a user to a course',
1.100 raeburn 9389: requestcrs => 'When requesting a course',
1.34 raeburn 9390: any => 'Any',
9391: official => 'Institutional only ',
9392: unofficial => 'Non-institutional only',
9393: none => 'None',
9394: );
9395: return %lt;
1.48 raeburn 9396: }
1.34 raeburn 9397:
1.160.6.34 raeburn 9398: sub selfcreation_types {
9399: my %lt = &Apache::lonlocal::texthash (
9400: selfcreate => 'User creates own account',
9401: any => 'Any',
9402: official => 'Institutional only ',
9403: unofficial => 'Non-institutional only',
9404: email => 'E-mail address',
9405: login => 'Institutional Login',
9406: sso => 'SSO',
9407: );
9408: }
9409:
1.28 raeburn 9410: sub authtype_names {
9411: my %lt = &Apache::lonlocal::texthash(
9412: int => 'Internal',
9413: krb4 => 'Kerberos 4',
9414: krb5 => 'Kerberos 5',
9415: loc => 'Local',
1.160.6.118.2 14(raebu 9416:23): lti => 'LTI',
1.28 raeburn 9417: );
9418: return %lt;
9419: }
9420:
9421: sub context_names {
9422: my %context_title = &Apache::lonlocal::texthash(
9423: author => 'Creating users when an Author',
9424: course => 'Creating users when in a course',
9425: domain => 'Creating users when a Domain Coordinator',
9426: );
9427: return %context_title;
9428: }
9429:
1.33 raeburn 9430: sub print_usermodification {
9431: my ($position,$dom,$settings,$rowtotal) = @_;
9432: my $numinrow = 4;
9433: my ($context,$datatable,$rowcount);
9434: if ($position eq 'top') {
9435: $rowcount = 0;
9436: $context = 'author';
9437: foreach my $role ('ca','aa') {
9438: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9439: $numinrow,$rowcount);
9440: $$rowtotal ++;
9441: $rowcount ++;
9442: }
1.160.6.118.2 25(raebu 9443:24): } elsif ($position eq 'middle') {
9444:24): $rowcount = 0;
9445:24): $context = 'coauthor';
9446:24): foreach my $role ('ca','aa') {
9447:24): $datatable .= &modifiable_userdata_row($context,$role,$settings,
9448:24): $numinrow,$rowcount);
9449:24): $$rowtotal ++;
9450:24): $rowcount ++;
9451:24): }
1.160.6.37 raeburn 9452: } elsif ($position eq 'bottom') {
1.33 raeburn 9453: $context = 'course';
9454: $rowcount = 0;
9455: foreach my $role ('st','ep','ta','in','cr') {
9456: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9457: $numinrow,$rowcount);
9458: $$rowtotal ++;
9459: $rowcount ++;
9460: }
9461: }
9462: return $datatable;
9463: }
9464:
1.43 raeburn 9465: sub print_defaults {
1.160.6.40 raeburn 9466: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9467: my $rownum = 0;
1.160.6.80 raeburn 9468: my ($datatable,$css_class,$titles);
9469: unless ($position eq 'bottom') {
9470: $titles = &defaults_titles($dom);
9471: }
1.160.6.40 raeburn 9472: if ($position eq 'top') {
9473: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9474: 'datelocale_def','portal_def');
9475: my %defaults;
9476: if (ref($settings) eq 'HASH') {
9477: %defaults = %{$settings};
1.43 raeburn 9478: } else {
1.160.6.40 raeburn 9479: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9480: foreach my $item (@items) {
9481: $defaults{$item} = $domdefaults{$item};
9482: }
1.43 raeburn 9483: }
1.160.6.40 raeburn 9484: foreach my $item (@items) {
9485: if ($rownum%2) {
9486: $css_class = '';
9487: } else {
9488: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 9489: }
1.160.6.40 raeburn 9490: $datatable .= '<tr'.$css_class.'>'.
9491: '<td><span class="LC_nobreak">'.$titles->{$item}.
9492: '</span></td><td class="LC_right_item" colspan="3">';
9493: if ($item eq 'auth_def') {
1.160.6.118.2 14(raebu 9494:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.160.6.40 raeburn 9495: my %shortauth = (
9496: internal => 'int',
9497: krb4 => 'krb4',
9498: krb5 => 'krb5',
1.160.6.118.2 14(raebu 9499:23): localauth => 'loc',
9500:23): lti => 'lti',
1.160.6.40 raeburn 9501: );
9502: my %authnames = &authtype_names();
9503: foreach my $auth (@authtypes) {
9504: my $checked = ' ';
9505: if ($defaults{$item} eq $auth) {
9506: $checked = ' checked="checked" ';
9507: }
9508: $datatable .= '<label><input type="radio" name="'.$item.
9509: '" value="'.$auth.'"'.$checked.'/>'.
9510: $authnames{$shortauth{$auth}}.'</label> ';
9511: }
9512: } elsif ($item eq 'timezone_def') {
9513: my $includeempty = 1;
9514: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9515: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 9516: my $includeempty = 1;
9517: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9518: } elsif ($item eq 'lang_def') {
9519: my $includeempty = 1;
9520: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 9521:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 9522: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 9523:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9524:23): my $portalsty = 'none';
9525:23): if ($defaults{$item}) {
9526:23): $portalsty = 'block';
9527:23): }
9528:23): foreach my $field ('email','web') {
9529:23): my $checkedoff = ' checked="checked"';
9530:23): my $checkedon;
9531:23): if ($defaults{$item.'_'.$field}) {
9532:23): $checkedon = $checkedoff;
9533:23): $checkedoff = '';
9534:23): }
9535:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9536:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
9537:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9538:23): (' 'x2).
9539:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9540:23): '</div>';
9541:23): }
9542:23): } else {
9543:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 9544: }
9545: $datatable .= '</td></tr>';
9546: $rownum ++;
9547: }
1.160.6.118.2 8(raebur 9548:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 9549: my %defaults;
1.160.6.40 raeburn 9550: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 9551: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 9552: my $maxnum = @{$settings->{'inststatusorder'}};
9553: for (my $i=0; $i<$maxnum; $i++) {
9554: $css_class = $rownum%2?' class="LC_odd_row"':'';
9555: my $item = $settings->{'inststatusorder'}->[$i];
9556: my $title = $settings->{'inststatustypes'}->{$item};
9557: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9558: $datatable .= '<tr'.$css_class.'>'.
9559: '<td><span class="LC_nobreak">'.
9560: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9561: for (my $k=0; $k<=$maxnum; $k++) {
9562: my $vpos = $k+1;
9563: my $selstr;
9564: if ($k == $i) {
9565: $selstr = ' selected="selected" ';
9566: }
9567: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9568: }
9569: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9570: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9571: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 9572: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 9573: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 9574: '</span></td></tr>';
1.160.6.40 raeburn 9575: }
9576: $css_class = $rownum%2?' class="LC_odd_row"':'';
9577: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9578: $datatable .= '<tr '.$css_class.'>'.
9579: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9580: for (my $k=0; $k<=$maxnum; $k++) {
9581: my $vpos = $k+1;
9582: my $selstr;
9583: if ($k == $maxnum) {
9584: $selstr = ' selected="selected" ';
9585: }
9586: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9587: }
9588: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 9589: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 9590: ' '.&mt('(new)').
9591: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 9592: &mt('Name displayed').':'.
1.160.6.40 raeburn 9593: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9594: '</tr>'."\n";
9595: $rownum ++;
1.141 raeburn 9596: }
1.43 raeburn 9597: }
1.160.6.118.2 8(raebur 9598:2): } else {
9599:2): my ($unamemaprules,$ruleorder) =
9600:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
9601:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
9602:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9603:2): my $numinrow = 2;
9604:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9605:2): &user_formats_row('unamemap',$settings,$unamemaprules,
9606:2): $ruleorder,$numinrow).
9607:2): '</table></td></tr>';
9608:2): }
9609:2): if ($datatable eq '') {
9610:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9611:2): &mt('No rules set for domain in customized localenroll.pm').
9612:2): '</td></tr>';
9613:2): }
1.43 raeburn 9614: }
9615: $$rowtotal += $rownum;
9616: return $datatable;
9617: }
9618:
1.160.6.5 raeburn 9619: sub get_languages_hash {
9620: my %langchoices;
9621: foreach my $id (&Apache::loncommon::languageids()) {
9622: my $code = &Apache::loncommon::supportedlanguagecode($id);
9623: if ($code ne '') {
9624: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9625: }
9626: }
9627: return %langchoices;
9628: }
9629:
1.43 raeburn 9630: sub defaults_titles {
1.141 raeburn 9631: my ($dom) = @_;
1.43 raeburn 9632: my %titles = &Apache::lonlocal::texthash (
9633: 'auth_def' => 'Default authentication type',
9634: 'auth_arg_def' => 'Default authentication argument',
9635: 'lang_def' => 'Default language',
1.54 raeburn 9636: 'timezone_def' => 'Default timezone',
1.68 raeburn 9637: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9638: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 9639:23): 'email' => 'Email links use portal URL',
9640:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 9641: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9642: 'intauth_check' => 'Check bcrypt cost if authenticated',
9643: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9644: );
1.141 raeburn 9645: if ($dom) {
9646: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9647: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9648: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9649: $protocol = 'http' if ($protocol ne 'https');
9650: if ($uint_dom) {
9651: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9652: $uint_dom);
9653: }
9654: }
1.43 raeburn 9655: return (\%titles);
9656: }
9657:
1.160.6.97 raeburn 9658: sub print_scantron {
9659: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9660: if ($position eq 'top') {
9661: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9662: } else {
9663: return &print_scantronconfig($dom,$settings,\$rowtotal);
9664: }
9665: }
9666:
9667: sub scantron_javascript {
9668: return <<"ENDSCRIPT";
9669:
9670: <script type="text/javascript">
9671: // <![CDATA[
9672:
9673: function toggleScantron(form) {
9674: var csvfieldset = new Array();
9675: if (document.getElementById('scantroncsv_cols')) {
9676: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9677: }
9678: if (document.getElementById('scantroncsv_options')) {
9679: csvfieldset.push(document.getElementById('scantroncsv_options'));
9680: }
9681: if (csvfieldset.length) {
9682: if (document.getElementById('scantronconfcsv')) {
9683: var scantroncsv = document.getElementById('scantronconfcsv');
9684: if (scantroncsv.checked) {
9685: for (var i=0; i<csvfieldset.length; i++) {
9686: csvfieldset[i].style.display = 'block';
9687: }
9688: } else {
9689: for (var i=0; i<csvfieldset.length; i++) {
9690: csvfieldset[i].style.display = 'none';
9691: }
9692: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9693: if (csvselects.length) {
9694: for (var j=0; j<csvselects.length; j++) {
9695: csvselects[j].selectedIndex = 0;
9696: }
9697: }
9698: }
9699: }
9700: }
9701: return;
9702: }
9703: // ]]>
9704: </script>
9705:
9706: ENDSCRIPT
9707:
9708: }
9709:
1.46 raeburn 9710: sub print_scantronformat {
9711: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9712: my $itemcount = 1;
1.60 raeburn 9713: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9714: %confhash);
1.46 raeburn 9715: my $switchserver = &check_switchserver($dom,$confname);
9716: my %lt = &Apache::lonlocal::texthash (
1.95 www 9717: default => 'Default bubblesheet format file error',
9718: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9719: );
9720: my %scantronfiles = (
9721: default => 'default.tab',
9722: custom => 'custom.tab',
9723: );
9724: foreach my $key (keys(%scantronfiles)) {
9725: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9726: .$scantronfiles{$key};
9727: }
9728: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9729: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9730: if (!$switchserver) {
9731: my $servadm = $r->dir_config('lonAdmEMail');
9732: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9733: if ($configuserok eq 'ok') {
9734: if ($author_ok eq 'ok') {
9735: my %legacyfile = (
1.160.6.97 raeburn 9736: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9737: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9738: );
9739: my %md5chk;
9740: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9741: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9742: chomp($md5chk{$type});
1.46 raeburn 9743: }
9744: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9745: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 9746: ($scantronurls{$type},my $error) =
1.46 raeburn 9747: &legacy_scantronformat($r,$dom,$confname,
9748: $type,$legacyfile{$type},
9749: $scantronurls{$type},
9750: $scantronfiles{$type});
1.60 raeburn 9751: if ($error ne '') {
9752: $error{$type} = $error;
9753: }
9754: }
9755: if (keys(%error) == 0) {
9756: $is_custom = 1;
1.160.6.97 raeburn 9757: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9758: $scantronurls{'custom'};
1.160.6.97 raeburn 9759: my $putresult =
1.60 raeburn 9760: &Apache::lonnet::put_dom('configuration',
9761: \%confhash,$dom);
9762: if ($putresult ne 'ok') {
1.160.6.97 raeburn 9763: $error{'custom'} =
1.60 raeburn 9764: '<span class="LC_error">'.
9765: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9766: }
1.46 raeburn 9767: }
9768: } else {
1.60 raeburn 9769: ($scantronurls{'default'},my $error) =
1.46 raeburn 9770: &legacy_scantronformat($r,$dom,$confname,
9771: 'default',$legacyfile{'default'},
9772: $scantronurls{'default'},
9773: $scantronfiles{'default'});
1.60 raeburn 9774: if ($error eq '') {
9775: $confhash{'scantron'}{'scantronformat'} = '';
9776: my $putresult =
9777: &Apache::lonnet::put_dom('configuration',
9778: \%confhash,$dom);
9779: if ($putresult ne 'ok') {
9780: $error{'default'} =
9781: '<span class="LC_error">'.
9782: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9783: }
9784: } else {
9785: $error{'default'} = $error;
9786: }
1.46 raeburn 9787: }
9788: }
9789: }
9790: } else {
1.95 www 9791: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9792: }
9793: }
9794: if (ref($settings) eq 'HASH') {
9795: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9796: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9797: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9798: $scantronurl = '';
9799: } else {
9800: $scantronurl = $settings->{'scantronformat'};
9801: }
9802: $is_custom = 1;
9803: } else {
9804: $scantronurl = $scantronurls{'default'};
9805: }
9806: } else {
1.60 raeburn 9807: if ($is_custom) {
9808: $scantronurl = $scantronurls{'custom'};
9809: } else {
9810: $scantronurl = $scantronurls{'default'};
9811: }
1.46 raeburn 9812: }
9813: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9814: $datatable .= '<tr'.$css_class.'>';
9815: if (!$is_custom) {
1.65 raeburn 9816: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9817: '<span class="LC_nobreak">';
1.46 raeburn 9818: if ($scantronurl) {
1.160.6.21 raeburn 9819: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9820: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9821: } else {
9822: $datatable = &mt('File unavailable for display');
9823: }
1.65 raeburn 9824: $datatable .= '</span></td>';
1.60 raeburn 9825: if (keys(%error) == 0) {
9826: $datatable .= '<td valign="bottom">';
9827: if (!$switchserver) {
9828: $datatable .= &mt('Upload:').'<br />';
9829: }
9830: } else {
9831: my $errorstr;
9832: foreach my $key (sort(keys(%error))) {
9833: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9834: }
9835: $datatable .= '<td>'.$errorstr;
9836: }
1.46 raeburn 9837: } else {
9838: if (keys(%error) > 0) {
9839: my $errorstr;
9840: foreach my $key (sort(keys(%error))) {
9841: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9842: }
1.60 raeburn 9843: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9844: } elsif ($scantronurl) {
1.160.6.26 raeburn 9845: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 9846: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9847: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 9848: $link.
9849: '<label><input type="checkbox" name="scantronformat_del"'.
9850: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9851: '<td><span class="LC_nobreak"> '.
9852: &mt('Replace:').'</span><br />';
1.46 raeburn 9853: }
9854: }
9855: if (keys(%error) == 0) {
9856: if ($switchserver) {
9857: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9858: } else {
1.65 raeburn 9859: $datatable .='<span class="LC_nobreak"> '.
9860: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9861: }
9862: }
9863: $datatable .= '</td></tr>';
9864: $$rowtotal ++;
9865: return $datatable;
9866: }
9867:
9868: sub legacy_scantronformat {
9869: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9870: my ($url,$error);
9871: my @statinfo = &Apache::lonnet::stat_file($newurl);
9872: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.160.6.118.2 14(raebu 9873:23): my $modified = [];
1.46 raeburn 9874: (my $result,$url) =
1.160.6.118.2 14(raebu 9875:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9876:23): 'scantron','','',$newfile,$modified);
9877:23): if ($result eq 'ok') {
9878:23): &update_modify_urls($r,$modified);
9879:23): } else {
1.130 raeburn 9880: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9881: }
9882: }
9883: return ($url,$error);
9884: }
1.43 raeburn 9885:
1.160.6.97 raeburn 9886: sub print_scantronconfig {
9887: my ($dom,$settings,$rowtotal) = @_;
9888: my $itemcount = 2;
9889: my $is_checked = ' checked="checked"';
9890: my %optionson = (
9891: hdr => ' checked="checked"',
9892: pad => ' checked="checked"',
9893: rem => ' checked="checked"',
9894: );
9895: my %optionsoff = (
9896: hdr => '',
9897: pad => '',
9898: rem => '',
9899: );
9900: my $currcsvsty = 'none';
9901: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9902: my @fields = &scantroncsv_fields();
9903: my %titles = &scantronconfig_titles();
9904: if (ref($settings) eq 'HASH') {
9905: if (ref($settings->{config}) eq 'HASH') {
9906: if ($settings->{config}->{dat}) {
9907: $checked{'dat'} = $is_checked;
9908: }
9909: if (ref($settings->{config}->{csv}) eq 'HASH') {
9910: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9911: %csvfields = %{$settings->{config}->{csv}->{fields}};
9912: if (keys(%csvfields) > 0) {
9913: $checked{'csv'} = $is_checked;
9914: $currcsvsty = 'block';
9915: }
9916: }
9917: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9918: %csvoptions = %{$settings->{config}->{csv}->{options}};
9919: foreach my $option (keys(%optionson)) {
9920: unless ($csvoptions{$option}) {
9921: $optionsoff{$option} = $optionson{$option};
9922: $optionson{$option} = '';
9923: }
9924: }
9925: }
9926: }
9927: } else {
9928: $checked{'dat'} = $is_checked;
9929: }
9930: } else {
9931: $checked{'dat'} = $is_checked;
9932: }
9933: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9934: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9935: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9936: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9937: foreach my $item ('dat','csv') {
9938: my $id;
9939: if ($item eq 'csv') {
9940: $id = 'id="scantronconfcsv" ';
9941: }
9942: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9943: $titles{$item}.'</label>'.(' 'x3);
9944: if ($item eq 'csv') {
9945: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9946: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9947: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9948: foreach my $col (@fields) {
9949: my $selnone;
9950: if ($csvfields{$col} eq '') {
9951: $selnone = ' selected="selected"';
9952: }
9953: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9954: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9955: '<option value=""'.$selnone.'></option>';
9956: for (my $i=0; $i<20; $i++) {
9957: my $shown = $i+1;
9958: my $sel;
9959: unless ($selnone) {
9960: if (exists($csvfields{$col})) {
9961: if ($csvfields{$col} == $i) {
9962: $sel = ' selected="selected"';
9963: }
9964: }
9965: }
9966: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9967: }
9968: $datatable .= '</select></td></tr>';
9969: }
9970: $datatable .= '</table></fieldset>'.
9971: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9972: '<legend>'.&mt('CSV Options').'</legend>';
9973: foreach my $option ('hdr','pad','rem') {
9974: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9975: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9976: &mt('Yes').'</label>'.(' 'x2)."\n".
9977: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9978: }
9979: $datatable .= '</fieldset>';
9980: $itemcount ++;
9981: }
9982: }
9983: $datatable .= '</td></tr>';
9984: $$rowtotal ++;
9985: return $datatable;
9986: }
9987:
9988: sub scantronconfig_titles {
9989: return &Apache::lonlocal::texthash(
9990: dat => 'Standard format (.dat)',
9991: csv => 'Comma separated values (.csv)',
9992: hdr => 'Remove first line in file (contains column titles)',
9993: pad => 'Prepend 0s to PaperID',
9994: rem => 'Remove leading spaces (except Question Response columns)',
9995: CODE => 'CODE',
9996: ID => 'Student ID',
9997: PaperID => 'Paper ID',
9998: FirstName => 'First Name',
9999: LastName => 'Last Name',
10000: FirstQuestion => 'First Question Response',
10001: Section => 'Section',
10002: );
10003: }
10004:
10005: sub scantroncsv_fields {
10006: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10007: }
10008:
1.49 raeburn 10009: sub print_coursecategories {
1.57 raeburn 10010: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10011: my $datatable;
10012: if ($position eq 'top') {
1.160.6.42 raeburn 10013: my (%checked);
10014: my @catitems = ('unauth','auth');
10015: my @cattypes = ('std','domonly','codesrch','none');
10016: $checked{'unauth'} = 'std';
10017: $checked{'auth'} = 'std';
10018: if (ref($settings) eq 'HASH') {
10019: foreach my $type (@cattypes) {
10020: if ($type eq $settings->{'unauth'}) {
10021: $checked{'unauth'} = $type;
10022: }
10023: if ($type eq $settings->{'auth'}) {
10024: $checked{'auth'} = $type;
10025: }
10026: }
10027: }
10028: my %lt = &Apache::lonlocal::texthash (
10029: unauth => 'Catalog type for unauthenticated users',
10030: auth => 'Catalog type for authenticated users',
10031: none => 'No catalog',
10032: std => 'Standard catalog',
10033: domonly => 'Domain-only catalog',
10034: codesrch => "Code search form",
10035: );
10036: my $itemcount = 0;
10037: foreach my $item (@catitems) {
10038: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10039: $datatable .= '<tr '.$css_class.'>'.
10040: '<td>'.$lt{$item}.'</td>'.
10041: '<td class="LC_right_item"><span class="LC_nobreak">';
10042: foreach my $type (@cattypes) {
10043: my $ischecked;
10044: if ($checked{$item} eq $type) {
10045: $ischecked=' checked="checked"';
10046: }
10047: $datatable .= '<label>'.
10048: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10049: ' />'.$lt{$type}.'</label> ';
10050: }
1.160.6.87 raeburn 10051: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 10052: $itemcount ++;
10053: }
10054: $$rowtotal += $itemcount;
10055: } elsif ($position eq 'middle') {
1.57 raeburn 10056: my $toggle_cats_crs = ' ';
10057: my $toggle_cats_dom = ' checked="checked" ';
10058: my $can_cat_crs = ' ';
10059: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10060: my $toggle_catscomm_comm = ' ';
10061: my $toggle_catscomm_dom = ' checked="checked" ';
10062: my $can_catcomm_comm = ' ';
10063: my $can_catcomm_dom = ' checked="checked" ';
10064:
1.57 raeburn 10065: if (ref($settings) eq 'HASH') {
10066: if ($settings->{'togglecats'} eq 'crs') {
10067: $toggle_cats_crs = $toggle_cats_dom;
10068: $toggle_cats_dom = ' ';
10069: }
10070: if ($settings->{'categorize'} eq 'crs') {
10071: $can_cat_crs = $can_cat_dom;
10072: $can_cat_dom = ' ';
10073: }
1.120 raeburn 10074: if ($settings->{'togglecatscomm'} eq 'comm') {
10075: $toggle_catscomm_comm = $toggle_catscomm_dom;
10076: $toggle_catscomm_dom = ' ';
10077: }
10078: if ($settings->{'categorizecomm'} eq 'comm') {
10079: $can_catcomm_comm = $can_catcomm_dom;
10080: $can_catcomm_dom = ' ';
10081: }
1.57 raeburn 10082: }
10083: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 10084: togglecats => 'Show/Hide a course in catalog',
10085: togglecatscomm => 'Show/Hide a community in catalog',
10086: categorize => 'Assign a category to a course',
10087: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10088: );
10089: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 10090: dom => 'Set in Domain',
10091: crs => 'Set in Course',
10092: comm => 'Set in Community',
1.57 raeburn 10093: );
10094: $datatable = '<tr class="LC_odd_row">'.
10095: '<td>'.$title{'togglecats'}.'</td>'.
10096: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10097: '<input type="radio" name="togglecats"'.
10098: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10099: '<label><input type="radio" name="togglecats"'.
10100: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10101: '</tr><tr>'.
10102: '<td>'.$title{'categorize'}.'</td>'.
10103: '<td class="LC_right_item"><span class="LC_nobreak">'.
10104: '<label><input type="radio" name="categorize"'.
10105: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10106: '<label><input type="radio" name="categorize"'.
10107: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10108: '</tr><tr class="LC_odd_row">'.
10109: '<td>'.$title{'togglecatscomm'}.'</td>'.
10110: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10111: '<input type="radio" name="togglecatscomm"'.
10112: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10113: '<label><input type="radio" name="togglecatscomm"'.
10114: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10115: '</tr><tr>'.
10116: '<td>'.$title{'categorizecomm'}.'</td>'.
10117: '<td class="LC_right_item"><span class="LC_nobreak">'.
10118: '<label><input type="radio" name="categorizecomm"'.
10119: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10120: '<label><input type="radio" name="categorizecomm"'.
10121: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 10122: '</tr>';
1.120 raeburn 10123: $$rowtotal += 4;
1.57 raeburn 10124: } else {
10125: my $css_class;
10126: my $itemcount = 1;
10127: my $cathash;
10128: if (ref($settings) eq 'HASH') {
10129: $cathash = $settings->{'cats'};
10130: }
10131: if (ref($cathash) eq 'HASH') {
10132: my (@cats,@trails,%allitems,%idx,@jsarray);
10133: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10134: \%allitems,\%idx,\@jsarray);
10135: my $maxdepth = scalar(@cats);
10136: my $colattrib = '';
10137: if ($maxdepth > 2) {
10138: $colattrib = ' colspan="2" ';
10139: }
10140: my @path;
10141: if (@cats > 0) {
10142: if (ref($cats[0]) eq 'ARRAY') {
10143: my $numtop = @{$cats[0]};
10144: my $maxnum = $numtop;
1.120 raeburn 10145: my %default_names = (
10146: instcode => &mt('Official courses'),
10147: communities => &mt('Communities'),
10148: );
10149:
10150: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10151: ($cathash->{'instcode::0'} eq '') ||
10152: (!grep(/^communities$/,@{$cats[0]})) ||
10153: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 10154: $maxnum ++;
10155: }
10156: my $lastidx;
10157: for (my $i=0; $i<$numtop; $i++) {
10158: my $parent = $cats[0][$i];
10159: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10160: my $item = &escape($parent).'::0';
10161: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10162: $lastidx = $idx{$item};
10163: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10164: .'<select name="'.$item.'"'.$chgstr.'>';
10165: for (my $k=0; $k<=$maxnum; $k++) {
10166: my $vpos = $k+1;
10167: my $selstr;
10168: if ($k == $i) {
10169: $selstr = ' selected="selected" ';
10170: }
10171: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10172: }
1.160.6.29 raeburn 10173: $datatable .= '</select></span></td><td>';
1.120 raeburn 10174: if ($parent eq 'instcode' || $parent eq 'communities') {
10175: $datatable .= '<span class="LC_nobreak">'
10176: .$default_names{$parent}.'</span>';
10177: if ($parent eq 'instcode') {
10178: $datatable .= '<br /><span class="LC_nobreak">('
10179: .&mt('with institutional codes')
10180: .')</span></td><td'.$colattrib.'>';
10181: } else {
10182: $datatable .= '<table><tr><td>';
10183: }
10184: $datatable .= '<span class="LC_nobreak">'
10185: .'<label><input type="radio" name="'
10186: .$parent.'" value="1" checked="checked" />'
10187: .&mt('Display').'</label>';
10188: if ($parent eq 'instcode') {
10189: $datatable .= ' ';
10190: } else {
10191: $datatable .= '</span></td></tr><tr><td>'
10192: .'<span class="LC_nobreak">';
10193: }
10194: $datatable .= '<label><input type="radio" name="'
10195: .$parent.'" value="0" />'
10196: .&mt('Do not display').'</label></span>';
10197: if ($parent eq 'communities') {
10198: $datatable .= '</td></tr></table>';
10199: }
10200: $datatable .= '</td>';
1.57 raeburn 10201: } else {
10202: $datatable .= $parent
1.160.6.29 raeburn 10203: .' <span class="LC_nobreak"><label>'
10204: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10205: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10206: }
10207: my $depth = 1;
10208: push(@path,$parent);
10209: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10210: pop(@path);
10211: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10212: $itemcount ++;
10213: }
1.48 raeburn 10214: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10215: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10216: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10217: for (my $k=0; $k<=$maxnum; $k++) {
10218: my $vpos = $k+1;
10219: my $selstr;
1.57 raeburn 10220: if ($k == $numtop) {
1.48 raeburn 10221: $selstr = ' selected="selected" ';
10222: }
10223: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10224: }
1.59 bisitz 10225: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10226: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10227: .'</tr>'."\n";
1.48 raeburn 10228: $itemcount ++;
1.120 raeburn 10229: foreach my $default ('instcode','communities') {
10230: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10231: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10232: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10233: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10234: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10235: for (my $k=0; $k<=$maxnum; $k++) {
10236: my $vpos = $k+1;
10237: my $selstr;
10238: if ($k == $maxnum) {
10239: $selstr = ' selected="selected" ';
10240: }
10241: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10242: }
1.120 raeburn 10243: $datatable .= '</select></span></td>'.
10244: '<td><span class="LC_nobreak">'.
10245: $default_names{$default}.'</span>';
10246: if ($default eq 'instcode') {
10247: $datatable .= '<br /><span class="LC_nobreak">('
10248: .&mt('with institutional codes').')</span>';
10249: }
10250: $datatable .= '</td>'
10251: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10252: .&mt('Display').'</label> '
10253: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10254: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10255: }
10256: }
10257: }
1.57 raeburn 10258: } else {
10259: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10260: }
10261: } else {
1.160.6.87 raeburn 10262: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10263: .&initialize_categories($itemcount);
1.48 raeburn 10264: }
1.57 raeburn 10265: $$rowtotal += $itemcount;
1.48 raeburn 10266: }
10267: return $datatable;
10268: }
10269:
1.69 raeburn 10270: sub print_serverstatuses {
10271: my ($dom,$settings,$rowtotal) = @_;
10272: my $datatable;
10273: my @pages = &serverstatus_pages();
10274: my (%namedaccess,%machineaccess);
10275: foreach my $type (@pages) {
10276: $namedaccess{$type} = '';
10277: $machineaccess{$type}= '';
10278: }
10279: if (ref($settings) eq 'HASH') {
10280: foreach my $type (@pages) {
10281: if (exists($settings->{$type})) {
10282: if (ref($settings->{$type}) eq 'HASH') {
10283: foreach my $key (keys(%{$settings->{$type}})) {
10284: if ($key eq 'namedusers') {
10285: $namedaccess{$type} = $settings->{$type}->{$key};
10286: } elsif ($key eq 'machines') {
10287: $machineaccess{$type} = $settings->{$type}->{$key};
10288: }
10289: }
10290: }
10291: }
10292: }
10293: }
1.81 raeburn 10294: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10295: my $rownum = 0;
10296: my $css_class;
10297: foreach my $type (@pages) {
10298: $rownum ++;
10299: $css_class = $rownum%2?' class="LC_odd_row"':'';
10300: $datatable .= '<tr'.$css_class.'>'.
10301: '<td><span class="LC_nobreak">'.
10302: $titles->{$type}.'</span></td>'.
10303: '<td class="LC_left_item">'.
10304: '<input type="text" name="'.$type.'_namedusers" '.
10305: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10306: '<td class="LC_right_item">'.
10307: '<span class="LC_nobreak">'.
10308: '<input type="text" name="'.$type.'_machines" '.
10309: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 10310: '</span></td></tr>'."\n";
1.69 raeburn 10311: }
10312: $$rowtotal += $rownum;
10313: return $datatable;
10314: }
10315:
10316: sub serverstatus_pages {
10317: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 10318: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 10319: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 10320: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10321: }
10322:
1.160.6.40 raeburn 10323: sub defaults_javascript {
10324: my ($settings) = @_;
1.160.6.98 raeburn 10325: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 10326:23): my $portal_js = <<"ENDPORTAL";
10327:23):
10328:23): function portalExtras(caller) {
10329:23): var x = caller.value;
10330:23): var y = new Array('email','web');
10331:23): for (var i=0; i<y.length; i++) {
10332:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
10333:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
10334:23): if (x.length > 0) {
10335:23): z.style.display = 'block';
10336:23): } else {
10337:23): z.style.display = 'none';
10338:23): }
10339:23): }
10340:23): }
10341:23): }
10342:23): ENDPORTAL
1.160.6.40 raeburn 10343: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10344: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10345: if ($maxnum eq '') {
10346: $maxnum = 0;
10347: }
10348: $maxnum ++;
1.160.6.51 raeburn 10349: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 10350: return <<"ENDSCRIPT";
10351: <script type="text/javascript">
10352: // <![CDATA[
10353: function reorderTypes(form,caller) {
10354: var changedVal;
10355: $jstext
10356: var newpos = 'addinststatus_pos';
10357: var current = new Array;
10358: var maxh = $maxnum;
10359: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10360: var oldVal;
10361: if (caller == newpos) {
10362: changedVal = newitemVal;
10363: } else {
10364: var curritem = 'inststatus_pos_'+caller;
10365: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10366: current[newitemVal] = newpos;
10367: }
10368: for (var i=0; i<inststatuses.length; i++) {
10369: if (inststatuses[i] != caller) {
10370: var elementName = 'inststatus_pos_'+inststatuses[i];
10371: if (form.elements[elementName]) {
10372: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10373: current[currVal] = elementName;
10374: }
10375: }
10376: }
10377: for (var j=0; j<maxh; j++) {
10378: if (current[j] == undefined) {
10379: oldVal = j;
10380: }
10381: }
10382: if (oldVal < changedVal) {
10383: for (var k=oldVal+1; k<=changedVal ; k++) {
10384: var elementName = current[k];
10385: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10386: }
10387: } else {
10388: for (var k=changedVal; k<oldVal; k++) {
10389: var elementName = current[k];
10390: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10391: }
10392: }
10393: return;
10394: }
10395:
1.160.6.118.2 12(raebu 10396:23): $portal_js
10397:23):
10398:23): // ]]>
10399:23): </script>
10400:23):
10401:23): ENDSCRIPT
10402:23): } else {
10403:23): return <<"ENDSCRIPT";
10404:23): <script type="text/javascript">
10405:23): // <![CDATA[
10406:23): $portal_js
1.160.6.40 raeburn 10407: // ]]>
10408: </script>
10409:
10410: ENDSCRIPT
10411: }
1.160.6.118.2 14(raebu 10412:23): return;
1.160.6.40 raeburn 10413: }
10414:
1.160.6.98 raeburn 10415: sub passwords_javascript {
1.160.6.118.2 5(raebur 10416:2): my ($prefix) = @_;
10417:2): my %intalert;
10418:2): if ($prefix eq 'passwords') {
10419:2): %intalert = &Apache::lonlocal::texthash (
10420: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.',
10421:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10422:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10423:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10424:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10425:2): );
14(raebu 10426:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 10427:2): %intalert = &Apache::lonlocal::texthash (
10428:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10429:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10430:2): );
10431:2): }
1.160.6.99 raeburn 10432: &js_escape(\%intalert);
10433: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 10434:2): my $intauthjs;
10435:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 10436:
10437: function warnIntAuth(field) {
10438: if (field.name == 'intauth_check') {
10439: if (field.value == '2') {
1.160.6.99 raeburn 10440: alert('$intalert{authcheck}');
1.160.6.98 raeburn 10441: }
10442: }
10443: if (field.name == 'intauth_cost') {
10444: field.value.replace(/\s/g,'');
10445: if (field.value != '') {
10446: var regexdigit=/^\\d+\$/;
10447: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 10448: alert('$intalert{authcost}');
10449: }
10450: }
10451: }
10452: return;
10453: }
10454:
1.160.6.118.2 5(raebur 10455:2): ENDSCRIPT
10456:2):
10457:2): }
10458:2):
10459:2): $intauthjs .= <<"ENDSCRIPT";
10460:2):
10461:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 10462: field.value.replace(/^\s+/,'');
10463: field.value.replace(/\s+\$/,'');
10464: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 10465:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 10466: if (field.value == '') {
10467: alert('$intalert{passmin}');
10468: field.value = '$defmin';
10469: } else {
10470: if (!regexdigit.test(field.value)) {
10471: alert('$intalert{passmin}');
10472: field.value = '$defmin';
10473: }
10474: var minval = parseInt(field.value,10);
10475: if (minval < $defmin) {
10476: alert('$intalert{passmin}');
10477: field.value = '$defmin';
10478: }
10479: }
10480: } else {
10481: if (field.value == '0') {
10482: field.value = '';
10483: }
10484: if (field.value != '') {
1.160.6.118.2 5(raebur 10485:2): if (!regexdigit.test(field.value)) {
10486:2): if (field.name == '${prefix}_max') {
10487:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 10488: } else {
1.160.6.118.2 5(raebur 10489:2): if (field.name == '${prefix}_numsaved') {
10490:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 10491: }
10492: }
1.160.6.118.2 5(raebur 10493:2): field.value = '';
1.160.6.98 raeburn 10494: }
10495: }
10496: }
10497: return;
10498: }
10499:
10500: ENDSCRIPT
10501: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10502: }
10503:
1.49 raeburn 10504: sub coursecategories_javascript {
10505: my ($settings) = @_;
1.57 raeburn 10506: my ($output,$jstext,$cathash);
1.49 raeburn 10507: if (ref($settings) eq 'HASH') {
1.57 raeburn 10508: $cathash = $settings->{'cats'};
10509: }
10510: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10511: my (@cats,@jsarray,%idx);
1.57 raeburn 10512: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10513: if (@jsarray > 0) {
10514: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10515: for (my $i=0; $i<@jsarray; $i++) {
10516: if (ref($jsarray[$i]) eq 'ARRAY') {
10517: my $catstr = join('","',@{$jsarray[$i]});
10518: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10519: }
10520: }
10521: }
10522: } else {
10523: $jstext = ' var categories = Array(1);'."\n".
10524: ' categories[0] = Array("instcode_pos");'."\n";
10525: }
1.160.6.42 raeburn 10526: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10527: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 10528: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10529: &js_escape(\$instcode_reserved);
10530: &js_escape(\$communities_reserved);
10531: &js_escape(\$choose_again);
1.49 raeburn 10532: $output = <<"ENDSCRIPT";
10533: <script type="text/javascript">
1.109 raeburn 10534: // <![CDATA[
1.49 raeburn 10535: function reorderCats(form,parent,item,idx) {
10536: var changedVal;
10537: $jstext
10538: var newpos = 'addcategory_pos';
10539: if (parent == '') {
10540: var has_instcode = 0;
10541: var maxtop = categories[idx].length;
10542: for (var j=0; j<maxtop; j++) {
10543: if (categories[idx][j] == 'instcode::0') {
10544: has_instcode == 1;
10545: }
10546: }
10547: if (has_instcode == 0) {
10548: categories[idx][maxtop] = 'instcode_pos';
10549: }
10550: } else {
10551: newpos += '_'+parent;
10552: }
10553: var maxh = 1 + categories[idx].length;
10554: var current = new Array;
10555: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10556: if (item == newpos) {
10557: changedVal = newitemVal;
10558: } else {
10559: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10560: current[newitemVal] = newpos;
10561: }
10562: for (var i=0; i<categories[idx].length; i++) {
10563: var elementName = categories[idx][i];
10564: if (elementName != item) {
10565: if (form.elements[elementName]) {
10566: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10567: current[currVal] = elementName;
10568: }
10569: }
10570: }
10571: var oldVal;
10572: for (var j=0; j<maxh; j++) {
10573: if (current[j] == undefined) {
10574: oldVal = j;
10575: }
10576: }
10577: if (oldVal < changedVal) {
10578: for (var k=oldVal+1; k<=changedVal ; k++) {
10579: var elementName = current[k];
10580: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10581: }
10582: } else {
10583: for (var k=changedVal; k<oldVal; k++) {
10584: var elementName = current[k];
10585: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10586: }
10587: }
10588: return;
10589: }
1.120 raeburn 10590:
10591: function categoryCheck(form) {
10592: if (form.elements['addcategory_name'].value == 'instcode') {
10593: alert('$instcode_reserved\\n$choose_again');
10594: return false;
10595: }
10596: if (form.elements['addcategory_name'].value == 'communities') {
10597: alert('$communities_reserved\\n$choose_again');
10598: return false;
10599: }
10600: return true;
10601: }
10602:
1.109 raeburn 10603: // ]]>
1.49 raeburn 10604: </script>
10605:
10606: ENDSCRIPT
10607: return $output;
10608: }
10609:
1.48 raeburn 10610: sub initialize_categories {
10611: my ($itemcount) = @_;
1.120 raeburn 10612: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 10613: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10614: instcode => 'Official courses (with institutional codes)',
10615: communities => 'Communities',
10616: );
10617: my $select0 = ' selected="selected"';
10618: my $select1 = '';
10619: foreach my $default ('instcode','communities') {
10620: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 10621: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 10622: if ($default eq 'communities') {
10623: $select1 = $select0;
10624: $select0 = '';
10625: }
10626: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10627: .'<select name="'.$default.'_pos">'
10628: .'<option value="0"'.$select0.'>1</option>'
10629: .'<option value="1"'.$select1.'>2</option>'
10630: .'<option value="2">3</option></select> '
10631: .$default_names{$default}
10632: .'</span></td><td><span class="LC_nobreak">'
10633: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10634: .&mt('Display').'</label> <label>'
10635: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10636: .'</label></span></td></tr>';
1.120 raeburn 10637: $itemcount ++;
10638: }
1.48 raeburn 10639: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10640: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10641: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10642: .'<select name="addcategory_pos"'.$chgstr.'>'
10643: .'<option value="0">1</option>'
10644: .'<option value="1">2</option>'
10645: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 10646: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 10647: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10648: .'</td></tr>';
1.48 raeburn 10649: return $datatable;
10650: }
10651:
10652: sub build_category_rows {
1.49 raeburn 10653: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10654: my ($text,$name,$item,$chgstr);
1.48 raeburn 10655: if (ref($cats) eq 'ARRAY') {
10656: my $maxdepth = scalar(@{$cats});
10657: if (ref($cats->[$depth]) eq 'HASH') {
10658: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10659: my $numchildren = @{$cats->[$depth]{$parent}};
10660: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 10661: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10662: my ($idxnum,$parent_name,$parent_item);
10663: my $higher = $depth - 1;
10664: if ($higher == 0) {
10665: $parent_name = &escape($parent).'::'.$higher;
10666: } else {
10667: if (ref($path) eq 'ARRAY') {
10668: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10669: }
10670: }
10671: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10672: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10673: if ($j < $numchildren) {
1.48 raeburn 10674: $name = $cats->[$depth]{$parent}[$j];
10675: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10676: $idxnum = $idx->{$item};
10677: } else {
10678: $name = $parent_name;
10679: $item = $parent_item;
1.48 raeburn 10680: }
1.49 raeburn 10681: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10682: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10683: for (my $i=0; $i<=$numchildren; $i++) {
10684: my $vpos = $i+1;
10685: my $selstr;
10686: if ($j == $i) {
10687: $selstr = ' selected="selected" ';
10688: }
10689: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10690: }
10691: $text .= '</select> ';
10692: if ($j < $numchildren) {
10693: my $deeper = $depth+1;
10694: $text .= $name.' '
10695: .'<label><input type="checkbox" name="deletecategory" value="'
10696: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10697: if(ref($path) eq 'ARRAY') {
10698: push(@{$path},$name);
1.49 raeburn 10699: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10700: pop(@{$path});
10701: }
10702: } else {
1.160.6.87 raeburn 10703: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10704: if ($j == $numchildren) {
10705: $text .= $name;
10706: } else {
10707: $text .= $item;
10708: }
10709: $text .= '" value="" />';
10710: }
10711: $text .= '</td></tr>';
10712: }
10713: $text .= '</table></td>';
10714: } else {
10715: my $higher = $depth-1;
10716: if ($higher == 0) {
10717: $name = &escape($parent).'::'.$higher;
10718: } else {
10719: if (ref($path) eq 'ARRAY') {
10720: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10721: }
10722: }
10723: my $colspan;
10724: if ($parent ne 'instcode') {
10725: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 10726: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10727: }
10728: }
10729: }
10730: }
10731: return $text;
10732: }
10733:
1.33 raeburn 10734: sub modifiable_userdata_row {
1.160.6.93 raeburn 10735: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.160.6.118.2 14(raebu 10736:23): $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.160.6.35 raeburn 10737: my ($role,$rolename,$statustype);
10738: $role = $item;
1.160.6.34 raeburn 10739: if ($context eq 'cancreate') {
1.160.6.93 raeburn 10740: if ($item =~ /^(emailusername)_(.+)$/) {
10741: $role = $1;
10742: $statustype = $2;
1.160.6.35 raeburn 10743: if (ref($usertypes) eq 'HASH') {
10744: if ($usertypes->{$statustype}) {
10745: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10746: } else {
10747: $rolename = &mt('Data provided by user');
10748: }
10749: }
1.160.6.34 raeburn 10750: }
10751: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10752: if (ref($usertypes) eq 'HASH') {
10753: $rolename = $usertypes->{$role};
10754: } else {
10755: $rolename = $role;
10756: }
1.160.6.118.2 14(raebu 10757:23): } elsif ($context eq 'lti') {
10758:23): $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 10759: } else {
1.63 raeburn 10760: if ($role eq 'cr') {
10761: $rolename = &mt('Custom role');
10762: } else {
10763: $rolename = &Apache::lonnet::plaintext($role);
10764: }
1.33 raeburn 10765: }
1.160.6.34 raeburn 10766: my (@fields,%fieldtitles);
10767: if (ref($fieldsref) eq 'ARRAY') {
10768: @fields = @{$fieldsref};
10769: } else {
10770: @fields = ('lastname','firstname','middlename','generation',
10771: 'permanentemail','id');
10772: }
10773: if ((ref($titlesref) eq 'HASH')) {
10774: %fieldtitles = %{$titlesref};
10775: } else {
10776: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10777: }
1.33 raeburn 10778: my $output;
1.160.6.93 raeburn 10779: my $css_class;
10780: if ($rowcount%2) {
10781: $css_class = 'LC_odd_row';
10782: }
10783: if ($customcss) {
10784: $css_class .= " $customcss";
10785: }
10786: $css_class =~ s/^\s+//;
10787: if ($css_class) {
10788: $css_class = ' class="'.$css_class.'"';
10789: }
10790: if ($rowstyle) {
10791: $css_class .= ' style="'.$rowstyle.'"';
10792: }
10793: if ($rowid) {
10794: $rowid = ' id="'.$rowid.'"';
10795: }
10796: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10797: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10798: '<td class="LC_left_item" colspan="2"><table>';
10799: my $rem;
10800: my %checks;
10801: if (ref($settings) eq 'HASH') {
1.160.6.118.2 14(raebu 10802:23): my $hashref;
10803:23): if ($context eq 'lti') {
10804:23): if (ref($settings) eq 'HASH') {
10805:23): $hashref = $settings->{'instdata'};
10806:23): }
10807:23): } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10808: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.118.2 14(raebu 10809:23): $hashref = $settings->{'lti_instdata'};
10810:23): }
10811:23): if ($role eq 'emailusername') {
10812:23): if ($statustype) {
10813:23): if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10814:23): $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.35 raeburn 10815: }
1.160.6.118.2 14(raebu 10816:23): }
10817:23): }
10818:23): }
10819:23): if (ref($hashref) eq 'HASH') {
10820:23): foreach my $field (@fields) {
10821:23): if ($hashref->{$field}) {
10822:23): if ($role eq 'emailusername') {
10823:23): $checks{$field} = $hashref->{$field};
10824:23): } else {
10825:23): $checks{$field} = ' checked="checked" ';
1.33 raeburn 10826: }
10827: }
10828: }
10829: }
10830: }
1.160.6.93 raeburn 10831: my $total = scalar(@fields);
10832: for (my $i=0; $i<$total; $i++) {
10833: $rem = $i%($numinrow);
1.33 raeburn 10834: if ($rem == 0) {
10835: if ($i > 0) {
10836: $output .= '</tr>';
10837: }
10838: $output .= '<tr>';
10839: }
10840: my $check = ' ';
1.160.6.35 raeburn 10841: unless ($role eq 'emailusername') {
10842: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 10843: $check = $checks{$fields[$i]};
1.160.6.118.2 14(raebu 10844:23): } elsif ($context ne 'lti') {
1.160.6.35 raeburn 10845: if ($role eq 'st') {
10846: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 10847: $check = ' checked="checked" ';
1.160.6.35 raeburn 10848: }
1.33 raeburn 10849: }
10850: }
10851: }
10852: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 10853: '<span class="LC_nobreak">';
1.160.6.118.2 14(raebu 10854:23): my $prefix = 'canmodify';
1.160.6.35 raeburn 10855: if ($role eq 'emailusername') {
10856: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10857: $checks{$fields[$i]} = 'omit';
10858: }
10859: foreach my $option ('required','optional','omit') {
10860: my $checked='';
10861: if ($checks{$fields[$i]} eq $option) {
10862: $checked='checked="checked" ';
10863: }
10864: $output .= '<label>'.
1.160.6.118.2 14(raebu 10865:23): '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.160.6.35 raeburn 10866: &mt($option).'</label>'.(' ' x2);
10867: }
10868: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10869: } else {
1.160.6.118.2 14(raebu 10870:23): if ($context eq 'lti') {
10871:23): $prefix = 'lti';
25(raebu 10872:24): } elsif ($context eq 'coauthor') {
10873:24): $prefix = 'cacanmodify';
14(raebu 10874:23): }
1.160.6.35 raeburn 10875: $output .= '<label>'.
1.160.6.118.2 14(raebu 10876:23): '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.160.6.35 raeburn 10877: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10878: '</label>';
10879: }
10880: $output .= '</span></td>';
1.33 raeburn 10881: }
1.160.6.93 raeburn 10882: $rem = $total%$numinrow;
10883: my $colsleft;
10884: if ($rem) {
10885: $colsleft = $numinrow - $rem;
10886: }
10887: if ($colsleft > 1) {
1.33 raeburn 10888: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10889: ' </td>';
10890: } elsif ($colsleft == 1) {
10891: $output .= '<td class="LC_left_item"> </td>';
10892: }
10893: $output .= '</tr></table></td></tr>';
10894: return $output;
10895: }
1.28 raeburn 10896:
1.93 raeburn 10897: sub insttypes_row {
1.160.6.93 raeburn 10898: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10899: $customcss,$rowstyle) = @_;
1.93 raeburn 10900: my %lt = &Apache::lonlocal::texthash (
1.160.6.118.2 20(raebu 10901:24): cansearch => 'Users allowed to search',
1.93 raeburn 10902: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.160.6.118.2 20(raebu 10903:24): lockablenames => 'User preference to lock name',
10904:24): selfassign => 'Self-reportable affiliations',
10905:24): overrides => "Override domain's helpdesk settings based on requester's affiliation",
10906:24): webdav => 'WebDAV access available',
10907:24): authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 10908: );
1.160.6.118.2 20(raebu 10909:24): my ($showdom,$defaultquota);
1.93 raeburn 10910: if ($context eq 'cansearch') {
10911: $showdom = ' ('.$dom.')';
1.160.6.118.2 20(raebu 10912:24): } elsif ($context eq 'authorquota') {
10913:24): $defaultquota = 500;
1.93 raeburn 10914: }
1.160.6.5 raeburn 10915: my $class = 'LC_left_item';
10916: if ($context eq 'statustocreate') {
10917: $class = 'LC_right_item';
10918: }
1.160.6.93 raeburn 10919: my $css_class;
10920: if ($$rowtotal%2) {
10921: $css_class = 'LC_odd_row';
10922: }
10923: if ($customcss) {
10924: $css_class .= ' '.$customcss;
10925: }
10926: $css_class =~ s/^\s+//;
10927: if ($css_class) {
10928: $css_class = ' class="'.$css_class.'"';
10929: }
10930: if ($rowstyle) {
10931: $css_class .= ' style="'.$rowstyle.'"';
10932: }
10933: if ($onclick) {
10934: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 10935: }
10936: my $output = '<tr'.$css_class.'>'.
10937: '<td>'.$lt{$context}.$showdom.
10938: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10939: my $rem;
10940: if (ref($types) eq 'ARRAY') {
10941: for (my $i=0; $i<@{$types}; $i++) {
10942: if (defined($usertypes->{$types->[$i]})) {
10943: my $rem = $i%($numinrow);
10944: if ($rem == 0) {
10945: if ($i > 0) {
10946: $output .= '</tr>';
10947: }
10948: $output .= '<tr>';
1.23 raeburn 10949: }
1.160.6.118.2 20(raebu 10950:24): if ($context eq 'authorquota') {
10951:24): my $currquota;
10952:24): if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
10953:24): $currquota = $settings->{$context}->{$types->[$i]};
10954:24): } else {
10955:24): $currquota = $defaultquota;
10956:24): }
10957:24): $output .= '<td class="LC_left_item">'."\n".
10958:24): '<label><span class="LC_nobreak">'."\n".
10959:24): $usertypes->{$types->[$i]}.'</span><br />'."\n".
10960:24): '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
10961:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
10962:24): '</label></td>';
10963:24): } else {
10964:24): my $check = ' ';
10965:24): if (ref($settings) eq 'HASH') {
10966:24): if (ref($settings->{$context}) eq 'ARRAY') {
10967:24): if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10968:24): $check = ' checked="checked" ';
10969:24): }
10970:24): } elsif (ref($settings->{$context}) eq 'HASH') {
10971:24): if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10972:24): $check = ' checked="checked" ';
10973:24): } elsif ($context eq 'webdav') {
10974:24): if ($settings->{$context}->{$types->[$i]}) {
10975:24): $check = ' checked="checked" ';
10976:24): }
10977:24): }
10978:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 10979: $check = ' checked="checked" ';
10980: }
1.26 raeburn 10981: }
1.160.6.118.2 20(raebu 10982:24): $output .= '<td class="LC_left_item">'.
10983:24): '<span class="LC_nobreak"><label>'.
10984:24): '<input type="checkbox" name="'.$context.'" '.
10985:24): 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
10986:24): $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10987: }
10988: }
10989: }
1.26 raeburn 10990: $rem = @{$types}%($numinrow);
1.23 raeburn 10991: }
10992: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 10993: if ($context eq 'overrides') {
10994: if ($colsleft > 1) {
10995: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10996: } else {
10997: $output .= '<td class="LC_left_item">';
10998: }
10999: $output .= ' ';
1.23 raeburn 11000: } else {
1.160.6.101 raeburn 11001: if ($rem == 0) {
11002: $output .= '<tr>';
11003: }
11004: if ($colsleft > 1) {
11005: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11006: } else {
11007: $output .= '<td class="LC_left_item">';
11008: }
1.160.6.118.2 20(raebu 11009:24): if ($context eq 'authorquota') {
11010:24): my $currquota = 500;
11011:24): if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
11012:24): if ($settings->{$context}{'default'} =~ /^\d+$/) {
11013:24): $currquota = $settings->{$context}{'default'};
11014:24): }
11015:24): }
11016:24): $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
11017:24): '<input type="text" name="'.$context.'_default" '.
11018:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
11019:24): '</label>';
11020:24): } else {
11021:24): my $defcheck = ' ';
11022:24): if (ref($settings) eq 'HASH') {
11023:24): if (ref($settings->{$context}) eq 'ARRAY') {
11024:24): if (grep(/^default$/,@{$settings->{$context}})) {
11025:24): $defcheck = ' checked="checked" ';
11026:24): }
11027:24): } elsif (ref($settings->{$context}) eq 'HASH') {
11028:24): if (ref($settings->{$context}->{'default'}) eq 'HASH') {
11029:24): $defcheck = ' checked="checked" ';
11030:24): } elsif ($context eq 'webdav') {
11031:24): if ($settings->{$context}->{'default'}) {
11032:24): $defcheck = ' checked="checked" ';
11033:24): }
11034:24): }
11035:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 11036: $defcheck = ' checked="checked" ';
11037: }
1.99 raeburn 11038: }
1.160.6.118.2 20(raebu 11039:24): $output .= '<span class="LC_nobreak"><label>'.
11040:24): '<input type="checkbox" name="'.$context.'" '.
11041:24): 'value="default"'.$defcheck.$onclick.'/>'.
11042:24): $othertitle.'</label></span>';
1.26 raeburn 11043: }
1.23 raeburn 11044: }
1.160.6.101 raeburn 11045: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11046: return $output;
1.23 raeburn 11047: }
11048:
11049: sub sorted_searchtitles {
11050: my %searchtitles = &Apache::lonlocal::texthash(
11051: 'uname' => 'username',
11052: 'lastname' => 'last name',
11053: 'lastfirst' => 'last name, first name',
11054: );
11055: my @titleorder = ('uname','lastname','lastfirst');
11056: return (\%searchtitles,\@titleorder);
11057: }
11058:
1.25 raeburn 11059: sub sorted_searchtypes {
11060: my %srchtypes_desc = (
11061: exact => 'is exact match',
11062: contains => 'contains ..',
11063: begins => 'begins with ..',
11064: );
11065: my @srchtypeorder = ('exact','begins','contains');
11066: return (\%srchtypes_desc,\@srchtypeorder);
11067: }
11068:
1.3 raeburn 11069: sub usertype_update_row {
11070: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11071: my $datatable;
11072: my $numinrow = 4;
11073: foreach my $type (@{$types}) {
11074: if (defined($usertypes->{$type})) {
11075: $$rownums ++;
11076: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11077: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11078: '</td><td class="LC_left_item"><table>';
11079: for (my $i=0; $i<@{$fields}; $i++) {
11080: my $rem = $i%($numinrow);
11081: if ($rem == 0) {
11082: if ($i > 0) {
11083: $datatable .= '</tr>';
11084: }
11085: $datatable .= '<tr>';
11086: }
11087: my $check = ' ';
1.39 raeburn 11088: if (ref($settings) eq 'HASH') {
11089: if (ref($settings->{'fields'}) eq 'HASH') {
11090: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11091: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11092: $check = ' checked="checked" ';
11093: }
1.3 raeburn 11094: }
11095: }
11096: }
11097:
11098: if ($i == @{$fields}-1) {
11099: my $colsleft = $numinrow - $rem;
11100: if ($colsleft > 1) {
11101: $datatable .= '<td colspan="'.$colsleft.'">';
11102: } else {
11103: $datatable .= '<td>';
11104: }
11105: } else {
11106: $datatable .= '<td>';
11107: }
1.8 raeburn 11108: $datatable .= '<span class="LC_nobreak"><label>'.
11109: '<input type="checkbox" name="updateable_'.$type.
11110: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11111: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11112: }
11113: $datatable .= '</tr></table></td></tr>';
11114: }
11115: }
11116: return $datatable;
1.1 raeburn 11117: }
11118:
11119: sub modify_login {
1.160.6.24 raeburn 11120: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11121: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 11122: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 11123:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 11124: %title = ( coursecatalog => 'Display course catalog',
11125: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 11126: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 11127: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 11128: loginheader => 'Log-in box header',
11129: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 11130: @offon = ('off','on');
1.112 raeburn 11131: if (ref($domconfig{login}) eq 'HASH') {
11132: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11133: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11134: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11135: }
11136: }
1.160.6.113 raeburn 11137: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11138: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11139: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11140: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11141: $saml{$lonhost} = 1;
11142: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11143: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11144: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11145: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11146: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 11147:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 11148: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11149: }
11150: }
11151: }
1.112 raeburn 11152: }
1.9 raeburn 11153: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11154: \%domconfig,\%loginhash);
1.160.6.14 raeburn 11155: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11156: foreach my $item (@toggles) {
11157: $loginhash{login}{$item} = $env{'form.'.$item};
11158: }
1.41 raeburn 11159: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11160: if (ref($colchanges{'login'}) eq 'HASH') {
11161: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11162: \%loginhash);
11163: }
1.110 raeburn 11164:
1.149 raeburn 11165: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 11166: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11167: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11168: if (keys(%servers) > 1) {
11169: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11170: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11171: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11172: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11173: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11174: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11175: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11176: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11177: $changes{'loginvia'}{$lonhost} = 1;
11178: } else {
11179: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11180: $changes{'loginvia'}{$lonhost} = 1;
11181: }
11182: } else {
11183: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11184: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11185: $changes{'loginvia'}{$lonhost} = 1;
11186: }
11187: }
11188: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11189: foreach my $item (@loginvia_attribs) {
11190: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11191: }
11192: } else {
11193: foreach my $item (@loginvia_attribs) {
11194: my $new = $env{'form.'.$lonhost.'_'.$item};
11195: if (($item eq 'serverpath') && ($new eq 'custom')) {
11196: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11197: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11198: $new = '/';
11199: }
11200: }
11201: if (($item eq 'custompath') &&
11202: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11203: $new = '';
11204: }
11205: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11206: $changes{'loginvia'}{$lonhost} = 1;
11207: }
11208: if ($item eq 'exempt') {
1.160.6.56 raeburn 11209: $new = &check_exempt_addresses($new);
1.128 raeburn 11210: }
11211: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11212: }
11213: }
1.112 raeburn 11214: } else {
1.128 raeburn 11215: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11216: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11217: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11218: foreach my $item (@loginvia_attribs) {
11219: my $new = $env{'form.'.$lonhost.'_'.$item};
11220: if (($item eq 'serverpath') && ($new eq 'custom')) {
11221: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11222: $new = '/';
11223: }
11224: }
11225: if (($item eq 'custompath') &&
11226: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11227: $new = '';
11228: }
11229: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11230: }
1.110 raeburn 11231: }
11232: }
11233: }
11234: }
1.119 raeburn 11235:
1.160.6.5 raeburn 11236: my $servadm = $r->dir_config('lonAdmEMail');
11237: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11238: if (ref($domconfig{'login'}) eq 'HASH') {
11239: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11240: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11241: if ($lang eq 'nolang') {
11242: push(@currlangs,$lang);
11243: } elsif (defined($langchoices{$lang})) {
11244: push(@currlangs,$lang);
11245: } else {
11246: next;
11247: }
11248: }
11249: }
11250: }
11251: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11252: if (@currlangs > 0) {
11253: foreach my $lang (@currlangs) {
11254: if (grep(/^\Q$lang\E$/,@delurls)) {
11255: $changes{'helpurl'}{$lang} = 1;
11256: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11257: $changes{'helpurl'}{$lang} = 1;
11258: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11259: push(@newlangs,$lang);
11260: } else {
11261: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11262: }
11263: }
11264: }
11265: unless (grep(/^nolang$/,@currlangs)) {
11266: if ($env{'form.loginhelpurl_nolang.filename'}) {
11267: $changes{'helpurl'}{'nolang'} = 1;
11268: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11269: push(@newlangs,'nolang');
11270: }
11271: }
11272: if ($env{'form.loginhelpurl_add_lang'}) {
11273: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11274: ($env{'form.loginhelpurl_add_file.filename'})) {
11275: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11276: $addedfile = $env{'form.loginhelpurl_add_lang'};
11277: }
11278: }
11279: if ((@newlangs > 0) || ($addedfile)) {
11280: my $error;
11281: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11282: if ($configuserok eq 'ok') {
11283: if ($switchserver) {
11284: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11285: } elsif ($author_ok eq 'ok') {
11286: my @allnew = @newlangs;
11287: if ($addedfile ne '') {
11288: push(@allnew,$addedfile);
11289: }
1.160.6.118.2 14(raebu 11290:23): my $modified = [];
1.160.6.5 raeburn 11291: foreach my $lang (@allnew) {
11292: my $formelem = 'loginhelpurl_'.$lang;
11293: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11294: $formelem = 'loginhelpurl_add_file';
11295: }
1.160.6.118.2 14(raebu 11296:23): (my $result,$newurl{$lang}) =
11297:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11298:23): "help/$lang",'','',$newfile{$lang},
11299:23): $modified);
1.160.6.5 raeburn 11300: if ($result eq 'ok') {
11301: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11302: $changes{'helpurl'}{$lang} = 1;
11303: } else {
11304: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11305: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11306: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
11307: (!grep(/^\Q$lang\E$/,@delurls))) {
11308: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11309: }
11310: }
11311: }
1.160.6.118.2 14(raebu 11312:23): &update_modify_urls($r,$modified);
1.160.6.5 raeburn 11313: } else {
11314: $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);
11315: }
11316: } else {
11317: $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);
11318: }
11319: if ($error) {
11320: &Apache::lonnet::logthis($error);
11321: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11322: }
11323: }
1.160.6.56 raeburn 11324:
11325: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11326: if (ref($domconfig{'login'}) eq 'HASH') {
11327: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11328: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11329: if ($domservers{$lonhost}) {
11330: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11331: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 11332: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 11333: }
11334: }
11335: }
11336: }
11337: }
11338: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11339: foreach my $lonhost (sort(keys(%domservers))) {
11340: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11341: $changes{'headtag'}{$lonhost} = 1;
11342: } else {
11343: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11344: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11345: }
11346: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11347: push(@newhosts,$lonhost);
11348: } elsif ($currheadtagurls{$lonhost}) {
11349: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11350: if ($currexempt{$lonhost}) {
11351: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
11352: $changes{'headtag'}{$lonhost} = 1;
11353: }
11354: } elsif ($possexempt{$lonhost}) {
11355: $changes{'headtag'}{$lonhost} = 1;
11356: }
11357: if ($possexempt{$lonhost}) {
11358: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11359: }
11360: }
11361: }
11362: }
11363: if (@newhosts) {
11364: my $error;
11365: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11366: if ($configuserok eq 'ok') {
11367: if ($switchserver) {
11368: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11369: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11370:23): my $modified = [];
1.160.6.56 raeburn 11371: foreach my $lonhost (@newhosts) {
11372: my $formelem = 'loginheadtag_'.$lonhost;
1.160.6.118.2 14(raebu 11373:23): (my $result,$newheadtagurls{$lonhost}) =
11374:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11375:23): "login/headtag/$lonhost",'','',
11376:23): $env{'form.loginheadtag_'.$lonhost.'.filename'},
11377:23): $modified);
1.160.6.56 raeburn 11378: if ($result eq 'ok') {
1.160.6.113 raeburn 11379: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11380: $changes{'headtag'}{$lonhost} = 1;
11381: if ($possexempt{$lonhost}) {
11382: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11383: }
11384: } else {
11385: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11386: $newheadtagurls{$lonhost},$result);
11387: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11388: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11389: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11390: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11391: }
11392: }
11393: }
1.160.6.118.2 14(raebu 11394:23): &update_modify_urls($r,$modified);
1.160.6.113 raeburn 11395: } else {
11396: $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);
11397: }
11398: } else {
11399: $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);
11400: }
11401: if ($error) {
11402: &Apache::lonnet::logthis($error);
11403: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11404: }
11405: }
11406: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11407: my @newsamlimgs;
11408: foreach my $lonhost (keys(%domservers)) {
11409: if ($env{'form.saml_'.$lonhost}) {
11410: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11411: push(@newsamlimgs,$lonhost);
11412: }
1.160.6.118.2 9(raebur 11413:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11414: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11415: }
11416: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 11417:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
11418:2): $env{'form.saml_window_'.$lonhost} = '';
11419:2): }
1.160.6.113 raeburn 11420: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11421: #FIXME Need to obsolete published image
11422: delete($currsaml{$lonhost}{'img'});
11423: $changes{'saml'}{$lonhost} = 1;
11424: }
11425: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11426: $changes{'saml'}{$lonhost} = 1;
11427: }
11428: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11429: $changes{'saml'}{$lonhost} = 1;
11430: }
11431: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11432: $changes{'saml'}{$lonhost} = 1;
11433: }
11434: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11435: $changes{'saml'}{$lonhost} = 1;
11436: }
1.160.6.118.2 9(raebur 11437:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11438:2): $changes{'saml'}{$lonhost} = 1;
11439:2): }
1.160.6.113 raeburn 11440: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11441: $changes{'saml'}{$lonhost} = 1;
11442: }
11443: } else {
11444: $changes{'saml'}{$lonhost} = 1;
11445: }
1.160.6.118.2 9(raebur 11446:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11447: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11448: }
11449: } else {
11450: if ($saml{$lonhost}) {
11451: $changes{'saml'}{$lonhost} = 1;
11452: delete($currsaml{$lonhost});
11453: }
11454: }
11455: }
11456: foreach my $posshost (keys(%currsaml)) {
11457: unless (exists($domservers{$posshost})) {
11458: delete($currsaml{$posshost});
11459: }
11460: }
11461: %{$loginhash{'login'}{'saml'}} = %currsaml;
11462: if (@newsamlimgs) {
11463: my $error;
11464: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11465: if ($configuserok eq 'ok') {
11466: if ($switchserver) {
11467: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11468: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11469:23): my $modified = [];
1.160.6.113 raeburn 11470: foreach my $lonhost (@newsamlimgs) {
11471: my $formelem = 'saml_img_'.$lonhost;
1.160.6.118.2 14(raebu 11472:23): my ($result,$imgurl) =
11473:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11474:23): "login/saml/$lonhost",'','',
11475:23): $env{'form.saml_img_'.$lonhost.'.filename'},
11476:23): $modified);
1.160.6.113 raeburn 11477: if ($result eq 'ok') {
11478: $currsaml{$lonhost}{'img'} = $imgurl;
11479: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11480: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 11481: } else {
1.160.6.113 raeburn 11482: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11483: $lonhost,$result);
1.160.6.56 raeburn 11484: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11485: }
11486: }
1.160.6.118.2 14(raebu 11487:23): &update_modify_urls($r,$modified);
1.160.6.56 raeburn 11488: } else {
1.160.6.113 raeburn 11489: $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 11490: }
11491: } else {
1.160.6.113 raeburn 11492: $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 11493: }
11494: if ($error) {
11495: &Apache::lonnet::logthis($error);
11496: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11497: }
11498: }
1.160.6.5 raeburn 11499: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11500:
11501: my $defaulthelpfile = '/adm/loginproblems.html';
11502: my $defaulttext = &mt('Default in use');
11503:
1.1 raeburn 11504: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11505: $dom);
11506: if ($putresult eq 'ok') {
1.160.6.14 raeburn 11507: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11508: my %defaultchecked = (
11509: 'coursecatalog' => 'on',
1.160.6.14 raeburn 11510: 'helpdesk' => 'on',
1.42 raeburn 11511: 'adminmail' => 'off',
1.43 raeburn 11512: 'newuser' => 'off',
1.42 raeburn 11513: );
1.55 raeburn 11514: if (ref($domconfig{'login'}) eq 'HASH') {
11515: foreach my $item (@toggles) {
11516: if ($defaultchecked{$item} eq 'on') {
11517: if (($domconfig{'login'}{$item} eq '0') &&
11518: ($env{'form.'.$item} eq '1')) {
11519: $changes{$item} = 1;
11520: } elsif (($domconfig{'login'}{$item} eq '' ||
11521: $domconfig{'login'}{$item} eq '1') &&
11522: ($env{'form.'.$item} eq '0')) {
11523: $changes{$item} = 1;
11524: }
11525: } elsif ($defaultchecked{$item} eq 'off') {
11526: if (($domconfig{'login'}{$item} eq '1') &&
11527: ($env{'form.'.$item} eq '0')) {
11528: $changes{$item} = 1;
11529: } elsif (($domconfig{'login'}{$item} eq '' ||
11530: $domconfig{'login'}{$item} eq '0') &&
11531: ($env{'form.'.$item} eq '1')) {
11532: $changes{$item} = 1;
11533: }
1.42 raeburn 11534: }
11535: }
1.41 raeburn 11536: }
1.6 raeburn 11537: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11538: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 11539: if (exists($changes{'saml'})) {
11540: my $hostid_in_use;
11541: my @hosts = &Apache::lonnet::current_machine_ids();
11542: if (@hosts > 1) {
11543: foreach my $hostid (@hosts) {
11544: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11545: $hostid_in_use = $hostid;
11546: last;
11547: }
11548: }
11549: } else {
11550: $hostid_in_use = $r->dir_config('lonHostID');
11551: }
11552: if (($hostid_in_use) &&
11553: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11554: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11555: }
11556: if (ref($lastactref) eq 'HASH') {
11557: if (ref($changes{'saml'}) eq 'HASH') {
11558: my %updates;
11559: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11560: $lastactref->{'samllanding'} = \%updates;
11561: }
11562: }
11563: }
1.160.6.27 raeburn 11564: if (ref($lastactref) eq 'HASH') {
11565: $lastactref->{'domainconfig'} = 1;
11566: }
1.1 raeburn 11567: $resulttext = &mt('Changes made:').'<ul>';
11568: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11569: if ($item eq 'loginvia') {
1.112 raeburn 11570: if (ref($changes{$item}) eq 'HASH') {
11571: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11572: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11573: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11574: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11575: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11576: $protocol = 'http' if ($protocol ne 'https');
11577: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11578:
11579: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11580: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11581: } else {
11582: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11583: }
11584: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11585: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11586: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11587: }
11588: $resulttext .= '</li>';
11589: } else {
11590: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11591: }
1.112 raeburn 11592: } else {
1.128 raeburn 11593: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11594: }
11595: }
1.128 raeburn 11596: $resulttext .= '</ul></li>';
1.112 raeburn 11597: }
1.160.6.5 raeburn 11598: } elsif ($item eq 'helpurl') {
11599: if (ref($changes{$item}) eq 'HASH') {
11600: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11601: if (grep(/^\Q$lang\E$/,@delurls)) {
11602: my ($chg,$link);
11603: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11604: if ($lang eq 'nolang') {
11605: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11606: } else {
11607: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11608: }
11609: $resulttext .= '<li>'.$chg.'</li>';
11610: } else {
11611: my $chg;
11612: if ($lang eq 'nolang') {
11613: $chg = &mt('custom log-in help file for no preferred language');
11614: } else {
11615: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11616: }
11617: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11618: $loginhash{'login'}{'helpurl'}{$lang}.
11619: '?inhibitmenu=yes',$chg,600,500).
11620: '</li>';
11621: }
11622: }
11623: }
1.160.6.56 raeburn 11624: } elsif ($item eq 'headtag') {
11625: if (ref($changes{$item}) eq 'HASH') {
11626: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11627: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11628: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11629: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11630: $resulttext .= '<li><a href="'.
11631: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11632: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11633: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11634: if ($possexempt{$lonhost}) {
11635: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11636: } else {
11637: $resulttext .= &mt('included for any client IP');
11638: }
11639: $resulttext .= '</li>';
11640: }
11641: }
11642: }
1.160.6.113 raeburn 11643: } elsif ($item eq 'saml') {
11644: if (ref($changes{$item}) eq 'HASH') {
11645: my %notlt = (
11646: text => 'Text for log-in by SSO',
11647: img => 'SSO button image',
11648: alt => 'Alt text for button image',
11649: url => 'SSO URL',
11650: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 11651:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 11652: notsso => 'Text for non-SSO log-in',
11653: );
11654: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11655: if (ref($currsaml{$lonhost}) eq 'HASH') {
11656: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11657: '<ul>';
1.160.6.118.2 9(raebur 11658:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11659: if ($currsaml{$lonhost}{$key} eq '') {
11660: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11661: } else {
11662: my $value = "'$currsaml{$lonhost}{$key}'";
11663: if ($key eq 'img') {
11664: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 11665:2): } elsif ($key eq 'window') {
11666:2): $value = 'On';
1.160.6.113 raeburn 11667: }
11668: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11669: $value).'</li>';
11670: }
11671: }
11672: $resulttext .= '</ul></li>';
11673: } else {
11674: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11675: }
11676: }
11677: }
1.160.6.5 raeburn 11678: } elsif ($item eq 'captcha') {
11679: if (ref($loginhash{'login'}) eq 'HASH') {
11680: my $chgtxt;
11681: if ($loginhash{'login'}{$item} eq 'notused') {
11682: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11683: } else {
11684: my %captchas = &captcha_phrases();
11685: if ($captchas{$loginhash{'login'}{$item}}) {
11686: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11687: } else {
11688: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11689: }
11690: }
11691: $resulttext .= '<li>'.$chgtxt.'</li>';
11692: }
11693: } elsif ($item eq 'recaptchakeys') {
11694: if (ref($loginhash{'login'}) eq 'HASH') {
11695: my ($privkey,$pubkey);
11696: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11697: $pubkey = $loginhash{'login'}{$item}{'public'};
11698: $privkey = $loginhash{'login'}{$item}{'private'};
11699: }
11700: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11701: if (!$pubkey) {
11702: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11703: } else {
11704: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11705: }
11706: if (!$privkey) {
11707: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11708: } else {
1.160.6.53 raeburn 11709: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 11710: }
11711: $chgtxt .= '</ul>';
11712: $resulttext .= '<li>'.$chgtxt.'</li>';
11713: }
1.160.6.69 raeburn 11714: } elsif ($item eq 'recaptchaversion') {
11715: if (ref($loginhash{'login'}) eq 'HASH') {
11716: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11717: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11718: '</li>';
11719: }
11720: }
1.41 raeburn 11721: } else {
11722: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11723: }
1.1 raeburn 11724: }
1.6 raeburn 11725: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11726: } else {
11727: $resulttext = &mt('No changes made to log-in page settings');
11728: }
11729: } else {
1.11 albertel 11730: $resulttext = '<span class="LC_error">'.
11731: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11732: }
1.6 raeburn 11733: if ($errors) {
1.9 raeburn 11734: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11735: $errors.'</ul>';
11736: }
11737: return $resulttext;
11738: }
11739:
1.160.6.56 raeburn 11740: sub check_exempt_addresses {
11741: my ($iplist) = @_;
11742: $iplist =~ s/^\s+//;
11743: $iplist =~ s/\s+$//;
11744: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11745: my (@okips,$new);
11746: foreach my $ip (@poss_ips) {
11747: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11748: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11749: push(@okips,$ip);
11750: }
11751: }
11752: }
11753: if (@okips > 0) {
11754: $new = join(',',@okips);
11755: } else {
11756: $new = '';
11757: }
11758: return $new;
11759: }
11760:
1.6 raeburn 11761: sub color_font_choices {
11762: my %choices =
11763: &Apache::lonlocal::texthash (
11764: bgs => "Background colors",
11765: links => "Link colors",
1.55 raeburn 11766: images => "Images",
1.6 raeburn 11767: font => "Font color",
1.160.6.22 raeburn 11768: fontmenu => "Font menu",
1.76 raeburn 11769: pgbg => "Page",
1.6 raeburn 11770: tabbg => "Header",
11771: sidebg => "Border",
11772: link => "Link",
11773: alink => "Active link",
11774: vlink => "Visited link",
11775: );
11776: return %choices;
11777: }
11778:
1.160.6.113 raeburn 11779: sub modify_ipaccess {
11780: my ($dom,$lastactref,%domconfig) = @_;
11781: my (@allpos,%changes,%confhash,$errors,$resulttext);
11782: my (@items,%deletions,%itemids,@warnings);
11783: my ($typeorder,$types) = &commblocktype_text();
11784: if ($env{'form.ipaccess_add'}) {
11785: my $name = $env{'form.ipaccess_name_add'};
11786: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11787: if ($newid) {
11788: $itemids{'add'} = $newid;
11789: push(@items,'add');
11790: $changes{$newid} = 1;
11791: } else {
11792: $error = &mt('Failed to acquire unique ID for new IP access control item');
11793: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11794: }
11795: }
11796: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11797: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11798: if (@todelete) {
11799: map { $deletions{$_} = 1; } @todelete;
11800: }
11801: my $maxnum = $env{'form.ipaccess_maxnum'};
11802: for (my $i=0; $i<$maxnum; $i++) {
11803: my $itemid = $env{'form.ipaccess_id_'.$i};
11804: $itemid =~ s/\D+//g;
11805: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11806: if ($deletions{$itemid}) {
11807: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11808: } else {
11809: push(@items,$i);
11810: $itemids{$i} = $itemid;
11811: }
11812: }
11813: }
11814: }
11815: foreach my $idx (@items) {
11816: my $itemid = $itemids{$idx};
11817: next unless ($itemid);
1.160.6.118.2 26(raebu 11818:25): my ($position,%current);
11819:25): if ($idx eq 'add') {
11820:25): $position = $env{'form.ipaccess_pos_add'};
11821:25): } else {
11822:25): $position = $env{'form.ipaccess_pos_'.$itemid};
1.160.6.113 raeburn 11823: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11824: %current = %{$domconfig{'ipaccess'}{$itemid}};
11825: }
11826: }
11827: $position =~ s/\D+//g;
11828: if ($position ne '') {
11829: $allpos[$position] = $itemid;
11830: }
11831: my $name = $env{'form.ipaccess_name_'.$idx};
11832: $name =~ s/^\s+|\s+$//g;
11833: $confhash{$itemid}{'name'} = $name;
11834: my $possrange = $env{'form.ipaccess_range_'.$idx};
11835: $possrange =~ s/^\s+|\s+$//g;
11836: unless ($possrange eq '') {
11837: $possrange =~ s/[\r\n]+/\s/g;
11838: $possrange =~ s/\s*-\s*/-/g;
11839: $possrange =~ s/\s+/,/g;
11840: $possrange =~ s/,+/,/g;
11841: if ($possrange ne '') {
11842: my (@ok,$count);
11843: $count = 0;
11844: foreach my $poss (split(/\,/,$possrange)) {
11845: $count ++;
11846: $poss = &validate_ip_pattern($poss);
11847: if ($poss ne '') {
11848: push(@ok,$poss);
11849: }
11850: }
11851: my $diff = $count - scalar(@ok);
11852: if ($diff) {
11853: $errors .= '<li><span class="LC_error">'.
11854: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11855: $diff,$name).
11856: '</span></li>';
11857: }
11858: if (@ok) {
11859: my @cidr_list;
11860: foreach my $item (@ok) {
11861: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11862: }
11863: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11864: }
11865: }
11866: }
11867: foreach my $field ('name','ip') {
11868: unless (($idx eq 'add') || ($changes{$itemid})) {
11869: if ($current{$field} ne $confhash{$itemid}{$field}) {
11870: $changes{$itemid} = 1;
11871: last;
11872: }
11873: }
11874: }
11875: $confhash{$itemid}{'commblocks'} = {};
11876:
11877: my %commblocks;
11878: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11879: foreach my $type (@{$typeorder}) {
11880: if ($commblocks{$type}) {
11881: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11882: }
11883: unless (($idx eq 'add') || ($changes{$itemid})) {
11884: if (ref($current{'commblocks'}) eq 'HASH') {
11885: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11886: $changes{$itemid} = 1;
11887: }
11888: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11889: $changes{$itemid} = 1;
11890: }
11891: }
11892: }
11893: $confhash{$itemid}{'courses'} = {};
11894: my %crsdeletions;
11895: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11896: if (@delcrs) {
11897: map { $crsdeletions{$_} = 1; } @delcrs;
11898: }
11899: if (ref($current{'courses'}) eq 'HASH') {
11900: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11901: if ($crsdeletions{$cid}) {
11902: $changes{$itemid} = 1;
11903: } else {
11904: $confhash{$itemid}{'courses'}{$cid} = 1;
11905: }
11906: }
11907: }
11908: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11909: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11910: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11911: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11912: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11913: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11914: $errors .= '<li><span class="LC_error">'.
11915: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11916: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11917: '</span></li>';
11918: } else {
11919: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11920: $changes{$itemid} = 1;
11921: }
11922: }
11923: }
11924: if (@allpos > 0) {
11925: my $idx = 0;
11926: foreach my $itemid (@allpos) {
11927: if ($itemid ne '') {
11928: $confhash{$itemid}{'order'} = $idx;
11929: unless ($changes{$itemid}) {
11930: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11931: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11932: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11933: $changes{$itemid} = 1;
11934: }
11935: }
11936: }
11937: }
11938: $idx ++;
11939: }
11940: }
11941: }
11942: if (keys(%changes)) {
11943: my %defaultshash = (
11944: ipaccess => \%confhash,
11945: );
11946: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11947: $dom);
11948: if ($putresult eq 'ok') {
11949: my $cachetime = 1800;
11950: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11951: if (ref($lastactref) eq 'HASH') {
11952: $lastactref->{'ipaccess'} = 1;
11953: }
11954: $resulttext = &mt('Changes made:').'<ul>';
11955: my %bynum;
11956: foreach my $itemid (sort(keys(%changes))) {
11957: if (ref($confhash{$itemid}) eq 'HASH') {
11958: my $position = $confhash{$itemid}{'order'};
11959: if ($position =~ /^\d+$/) {
11960: $bynum{$position} = $itemid;
11961: }
11962: }
11963: }
11964: if (keys(%deletions)) {
11965: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11966: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11967: }
11968: }
11969: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11970: my $itemid = $bynum{$pos};
11971: if (ref($confhash{$itemid}) eq 'HASH') {
11972: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11973: my $position = $pos + 1;
11974: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11975: if ($confhash{$itemid}{'ip'} eq '') {
11976: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11977: } else {
11978: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11979: }
11980: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11981: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11982: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11983: '</li>';
11984: } else {
11985: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11986: }
11987: if (keys(%{$confhash{$itemid}{'courses'}})) {
11988: my @courses;
11989: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11990: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11991: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
11992: }
11993: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
11994: join('</li><li>',@courses).'</li></ul>';
11995: } else {
11996: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
11997: }
11998: $resulttext .= '</ul></li>';
11999: }
12000: }
12001: $resulttext .= '</ul>';
12002: } else {
12003: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12004: }
12005: } else {
12006: $resulttext = &mt('No changes made');
12007: }
12008: if ($errors) {
12009: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12010: $errors.'</ul></p>';
12011: }
12012: return $resulttext;
12013: }
12014:
12015: sub get_ipaccess_id {
12016: my ($domain,$location) = @_;
12017: # get lock on ipaccess db
12018: my $lockhash = {
12019: lock => $env{'user.name'}.
12020: ':'.$env{'user.domain'},
12021: };
12022: my $tries = 0;
12023: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12024: my ($id,$error);
12025:
12026: while (($gotlock ne 'ok') && ($tries<10)) {
12027: $tries ++;
12028: sleep (0.1);
12029: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12030: }
12031: if ($gotlock eq 'ok') {
12032: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12033: if ($currids{'lock'}) {
12034: delete($currids{'lock'});
12035: if (keys(%currids)) {
12036: my @curr = sort { $a <=> $b } keys(%currids);
12037: if ($curr[-1] =~ /^\d+$/) {
12038: $id = 1 + $curr[-1];
12039: }
12040: } else {
12041: $id = 1;
12042: }
12043: if ($id) {
12044: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12045: $error = 'nostore';
12046: }
12047: } else {
12048: $error = 'nonumber';
12049: }
12050: }
12051: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12052: } else {
12053: $error = 'nolock';
12054: }
12055: return ($id,$error);
12056: }
12057:
1.160.6.118.2 20(raebu 12058:24): sub modify_authordefaults {
12059:24): my ($dom,$lastactref,%domconfig) = @_;
12060:24): #
12061:24): # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
12062:24): #
12063:24): my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
12064:24): if (ref($domconfig{'quotas'}) eq 'HASH') {
12065:24): foreach my $key (keys(%{$domconfig{'quotas'}})) {
12066:24): if ($key =~ /^webdav|authorquota$/) {
12067:24): $curr_quotas{$key} = $domconfig{'quotas'}{$key};
12068:24): } else {
12069:24): $save_quotas{$key} = $domconfig{'quotas'}{$key};
12070:24): }
12071:24): }
12072:24): }
12073:24): my %staticdefaults = (
12074:24): 'copyright' => 'default',
12075:24): 'sourceavail' => 'closed',
12076:24): 'nocodemirror' => 'off',
21(raebu 12077:24): 'daxecollapse' => 'off',
20(raebu 12078:24): 'domcoordacc' => 'on',
22(raebu 12079:24): 'editors' => ['edit','xml'],
20(raebu 12080:24): 'authorquota' => 500,
12081:24): 'webdav' => 0,
22(raebu 12082:24): 'archive' => 'off',
20(raebu 12083:24): );
12084:24): my %titles = &authordefaults_titles();
22(raebu 12085:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12086:24): if ($env{'form.'.$item} =~ /^(0|1)$/) {
12087:24): $confhash{$item} = $env{'form.'.$item};
12088:24): }
12089:24): }
12090:24): if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
12091:24): $confhash{'copyright'} = $1;
12092:24): }
12093:24): if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
12094:24): $confhash{'sourceavail'} = $1;
12095:24): }
12096:24): my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
12097:24): my @okeditors = ('edit','xml','daxe');
12098:24): my @editors;
12099:24): foreach my $item (@posseditors) {
12100:24): if (grep(/^\Q$item\E$/,@okeditors)) {
12101:24): push(@editors,$item);
12102:24): }
12103:24): }
12104:24): $confhash{'editors'} = \@editors;
12105:24):
12106:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12107:24): my @insttypes;
12108:24): if (ref($types) eq 'ARRAY') {
12109:24): @insttypes = @{$types};
12110:24): }
12111:24): my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
12112:24): my %webdav;
12113:24): map { $webdav{$_} = 1; } @webdavon;
12114:24): foreach my $type (@insttypes,'default') {
12115:24): my $possquota = $env{'form.authorquota_'.$type};
12116:24): if ($possquota =~ /^\d+$/) {
12117:24): $save_quotas{'authorquota'}{$type} = $possquota;
12118:24): }
12119:24): if ($webdav{$type}) {
12120:24): $save_quotas{'webdav'}{$type} = 1;
12121:24): } else {
12122:24): $save_quotas{'webdav'}{$type} = 0;
12123:24): }
12124:24): }
12125:24): if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
12126:24): $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
12127:24): }
12128:24): if (ref($domconfig{'authordefaults'}) eq 'HASH') {
22(raebu 12129:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
20(raebu 12130:24): if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
12131:24): $changes{$item} = 1;
12132:24): }
12133:24): }
12134:24): if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
12135:24): my @diffs =
12136:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12137:24): $domconfig{'authordefaults'}{'editors'});
12138:24): unless (@diffs == 0) {
12139:24): $changes{'editors'} = 1;
12140:24): }
12141:24): } else {
12142:24): my @diffs =
12143:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12144:24): $staticdefaults{'editors'});
12145:24): unless (@diffs == 0) {
12146:24): $changes{'editors'} = 1;
12147:24): }
12148:24): }
12149:24): } else {
12150:24): my @offon = ('off','on');
22(raebu 12151:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12152:24): if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
12153:24): $changes{$item} = 1;
12154:24): }
12155:24): }
12156:24): foreach my $item ('copyright','sourceavail') {
12157:24): if ($confhash{$item} ne $staticdefaults{$item}) {
12158:24): $changes{$item} = 1;
12159:24): }
12160:24): }
22(raebu 12161:24): my @diffs =
12162:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12163:24): $staticdefaults{'editors'});
12164:24): unless (@diffs == 0) {
12165:24): $changes{'editors'} = 1;
12166:24): }
20(raebu 12167:24): }
12168:24): foreach my $key ('authorquota','webdav') {
12169:24): if (ref($curr_quotas{$key}) eq 'HASH') {
12170:24): foreach my $type (@insttypes,'default') {
12171:24): if (exists($save_quotas{$key}{$type})) {
12172:24): if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
12173:24): $changes{$key}{$type} = 1;
12174:24): }
12175:24): } elsif (exists($curr_quotas{$key}{$type})) {
12176:24): $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
12177:24): } else {
12178:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12179:24): }
12180:24): }
12181:24): } else {
12182:24): foreach my $type (@insttypes,'default') {
12183:24): if (exists($save_quotas{$key}{$type})) {
12184:24): unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
12185:24): $changes{$key}{$type} = 1;
12186:24): }
12187:24): } else {
12188:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12189:24): }
12190:24): }
12191:24): }
12192:24): }
12193:24): if (ref($curr_quotas{'webdav'}) eq 'HASH') {
12194:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12195:24): if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
12196:24): $changes{'webdav_LC_adv'} = 1;
12197:24): }
12198:24): } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
12199:24): $changes{'webdav_LC_adv'} = 1;
12200:24): }
12201:24): } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12202:24): $changes{'webdav_LC_adv'} = 1;
12203:24): }
12204:24): my %confighash = (
12205:24): quotas => \%save_quotas,
12206:24): authordefaults => \%confhash,
12207:24): );
12208:24): my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
12209:24): $dom);
12210:24): my $resulttext;
12211:24): if ($putresult eq 'ok') {
12212:24): if (keys(%changes)) {
12213:24): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12214:24): if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
12215:24): ($changes{'webdav_LC_adv'})) {
12216:24): if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
12217:24): $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
12218:24): }
12219:24): if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
12220:24): (ref($save_quotas{'webdav'}) eq 'HASH')) {
12221:24): $domdefaults{'webdav'} = $save_quotas{'webdav'};
12222:24): }
12223:24): }
12224:24): $resulttext = &mt('Changes made:').'<ul>';
12225:24): my $authoroverride;
21(raebu 12226:24): foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
20(raebu 12227:24): if (exists($changes{$key})) {
12228:24): $domdefaults{$key} = $confhash{$key};
12229:24): my $shown;
12230:24): unless ($authoroverride) {
12231:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
12232:24): $authoroverride = 1;
12233:24): }
21(raebu 12234:24): if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
20(raebu 12235:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
12236:24): } elsif ($key eq 'copyright') {
12237:24): $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
12238:24): } elsif ($key eq 'sourceavail') {
12239:24): $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
12240:24): }
12241:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12242:24): }
12243:24): }
12244:24): if ($authoroverride) {
12245:24): $resulttext .= '</ul></li>';
12246:24): }
12247:24): my $domcoordoverride;
22(raebu 12248:24): foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
20(raebu 12249:24): if (exists($changes{$key})) {
12250:24): my $shown;
12251:24): unless ($domcoordoverride) {
12252:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
12253:24): $domcoordoverride = 1;
12254:24): }
12255:24): if ($key eq 'editors') {
12256:24): if (ref($confhash{'editors'}) eq 'ARRAY') {
12257:24): $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
12258:24): if (@{$confhash{'editors'}}) {
12259:24): $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
12260:24): } else {
12261:24): $shown = &mt('None');
12262:24): }
12263:24): }
12264:24): } elsif ($key eq 'authorquota') {
12265:24): foreach my $type (@insttypes) {
12266:24): $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
12267:24): }
12268:24): $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
12269:24): } elsif ($key eq 'webdav') {
12270:24): foreach my $type (@insttypes) {
12271:24): $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
12272:24): }
12273:24): $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
12274:24): } elsif ($key eq 'webdav_LC_adv') {
12275:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12276:24): $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
12277:24): } else {
12278:24): $shown = $titles{'none'};
12279:24): }
22(raebu 12280:24): } elsif ($key eq 'archive') {
12281:24): $domdefaults{$key} = $confhash{$key};
12282:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
20(raebu 12283:24): }
12284:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12285:24): }
12286:24): }
12287:24): if ($domcoordoverride) {
12288:24): $resulttext .= '</ul></li>';
12289:24): }
22(raebu 12290:24): $resulttext .= '</ul>';
20(raebu 12291:24): my $cachetime = 24*60*60;
12292:24): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12293:24): if (ref($lastactref) eq 'HASH') {
12294:24): $lastactref->{'domdefaults'} = 1;
12295:24): }
12296:24): } else {
12297:24): $resulttext = &mt('No changes made to Authoring Space defaults');
12298:24): }
12299:24): }
12300:24): return $resulttext;
12301:24): }
12302:24):
1.6 raeburn 12303: sub modify_rolecolors {
1.160.6.24 raeburn 12304: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12305: my ($resulttext,%rolehash);
12306: $rolehash{'rolecolors'} = {};
1.55 raeburn 12307: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12308: if ($domconfig{'rolecolors'} eq '') {
12309: $domconfig{'rolecolors'} = {};
12310: }
12311: }
1.9 raeburn 12312: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12313: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12314: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12315: $dom);
12316: if ($putresult eq 'ok') {
12317: if (keys(%changes) > 0) {
1.41 raeburn 12318: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12319: if (ref($lastactref) eq 'HASH') {
12320: $lastactref->{'domainconfig'} = 1;
12321: }
1.6 raeburn 12322: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12323: $rolehash{'rolecolors'});
12324: } else {
12325: $resulttext = &mt('No changes made to default color schemes');
12326: }
12327: } else {
1.11 albertel 12328: $resulttext = '<span class="LC_error">'.
12329: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12330: }
12331: if ($errors) {
12332: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12333: $errors.'</ul>';
12334: }
12335: return $resulttext;
12336: }
12337:
12338: sub modify_colors {
1.9 raeburn 12339: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12340: my (%changes,%choices);
1.51 raeburn 12341: my @bgs;
1.6 raeburn 12342: my @links = ('link','alink','vlink');
1.41 raeburn 12343: my @logintext;
1.6 raeburn 12344: my @images;
12345: my $servadm = $r->dir_config('lonAdmEMail');
12346: my $errors;
1.160.6.22 raeburn 12347: my %defaults;
1.6 raeburn 12348: foreach my $role (@{$roles}) {
12349: if ($role eq 'login') {
1.12 raeburn 12350: %choices = &login_choices();
1.41 raeburn 12351: @logintext = ('textcol','bgcol');
1.12 raeburn 12352: } else {
12353: %choices = &color_font_choices();
12354: }
12355: if ($role eq 'login') {
1.41 raeburn 12356: @images = ('img','logo','domlogo','login');
1.51 raeburn 12357: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12358: } else {
1.160.6.118.2 26(raebu 12359:25): @images = ();
1.160.6.22 raeburn 12360: @bgs = ('pgbg','tabbg','sidebg');
12361: }
12362: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.160.6.118.2 26(raebu 12363:25): $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
12364:25): if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
12365:25): $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
12366:25): }
12367:25): unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.160.6.22 raeburn 12368: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12369: }
12370: if ($role eq 'login') {
12371: foreach my $item (@logintext) {
1.160.6.39 raeburn 12372: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12373: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12374: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12375: }
12376: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 12377: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12378: }
12379: }
12380: } else {
1.160.6.39 raeburn 12381: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12382: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12383: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12384: }
1.160.6.118.2 26(raebu 12385:25): unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 12386: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12387: }
1.6 raeburn 12388: }
1.160.6.22 raeburn 12389: foreach my $item (@bgs) {
1.160.6.39 raeburn 12390: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12391: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12392: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12393: }
12394: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 12395: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12396: }
12397: }
12398: foreach my $item (@links) {
1.160.6.39 raeburn 12399: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12400: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12401: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12402: }
12403: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 12404: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12405: }
1.6 raeburn 12406: }
1.46 raeburn 12407: my ($configuserok,$author_ok,$switchserver) =
12408: &config_check($dom,$confname,$servadm);
1.9 raeburn 12409: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12410: if (ref($domconfig->{$role}) ne 'HASH') {
12411: $domconfig->{$role} = {};
12412: }
1.8 raeburn 12413: foreach my $img (@images) {
1.160.6.118.2 2(raebur 12414:2): if ($role eq 'login') {
12415:2): if (($img eq 'img') || ($img eq 'logo')) {
12416:2): if (defined($env{'form.login_showlogo_'.$img})) {
12417:2): $confhash->{$role}{'showlogo'}{$img} = 1;
12418:2): } else {
12419:2): $confhash->{$role}{'showlogo'}{$img} = 0;
12420:2): }
1.70 raeburn 12421: }
1.160.6.118.2 2(raebur 12422:2): if ($env{'form.login_alt_'.$img} ne '') {
12423:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
12424:2): }
12425:2): }
1.18 albertel 12426: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12427: && !defined($domconfig->{$role}{$img})
12428: && !$env{'form.'.$role.'_del_'.$img}
12429: && $env{'form.'.$role.'_import_'.$img}) {
12430: # import the old configured image from the .tab setting
12431: # if they haven't provided a new one
12432: $domconfig->{$role}{$img} =
12433: $env{'form.'.$role.'_import_'.$img};
12434: }
1.6 raeburn 12435: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12436: my $error;
1.6 raeburn 12437: if ($configuserok eq 'ok') {
1.9 raeburn 12438: if ($switchserver) {
1.12 raeburn 12439: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12440: } else {
12441: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12442:23): my $modified = [];
1.9 raeburn 12443: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12444:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
12445:23): $dom,$confname,$img,$width,$height,
12446:23): '',$modified);
1.9 raeburn 12447: if ($result eq 'ok') {
12448: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12449: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12450:23): &update_modify_urls($r,$modified);
1.9 raeburn 12451: } else {
1.12 raeburn 12452: $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 12453: }
12454: } else {
1.46 raeburn 12455: $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 12456: }
12457: }
12458: } else {
1.46 raeburn 12459: $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 12460: }
12461: if ($error) {
1.8 raeburn 12462: &Apache::lonnet::logthis($error);
1.11 albertel 12463: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12464: }
12465: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12466: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12467: my $error;
12468: if ($configuserok eq 'ok') {
12469: # is confname an author?
12470: if ($switchserver eq '') {
12471: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12472:23): my $modified = [];
1.9 raeburn 12473: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12474:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
12475:23): $dom,$confname,$img,$width,$height,
12476:23): '',$modified);
1.9 raeburn 12477: if ($result eq 'ok') {
12478: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12479: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12480:23): &update_modify_urls($r,$modified);
1.9 raeburn 12481: }
12482: }
12483: }
12484: }
1.6 raeburn 12485: }
12486: }
12487: }
12488: if (ref($domconfig) eq 'HASH') {
12489: if (ref($domconfig->{$role}) eq 'HASH') {
12490: foreach my $img (@images) {
12491: if ($domconfig->{$role}{$img} ne '') {
12492: if ($env{'form.'.$role.'_del_'.$img}) {
12493: $confhash->{$role}{$img} = '';
1.12 raeburn 12494: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12495: } else {
1.9 raeburn 12496: if ($confhash->{$role}{$img} eq '') {
12497: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12498: }
1.6 raeburn 12499: }
12500: } else {
12501: if ($env{'form.'.$role.'_del_'.$img}) {
12502: $confhash->{$role}{$img} = '';
1.12 raeburn 12503: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12504: }
12505: }
1.160.6.118.2 2(raebur 12506:2): if ($role eq 'login') {
12507:2): if (($img eq 'logo') || ($img eq 'img')) {
12508:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12509:2): if ($confhash->{$role}{'showlogo'}{$img} ne
12510:2): $domconfig->{$role}{'showlogo'}{$img}) {
12511:2): $changes{$role}{'showlogo'}{$img} = 1;
12512:2): }
12513:2): } else {
12514:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12515:2): $changes{$role}{'showlogo'}{$img} = 1;
12516:2): }
1.70 raeburn 12517: }
1.160.6.118.2 2(raebur 12518:2): }
12519:2): if ($img ne 'login') {
12520:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
12521:2): if ($confhash->{$role}{'alttext'}{$img} ne
12522:2): $domconfig->{$role}{'alttext'}{$img}) {
12523:2): $changes{$role}{'alttext'}{$img} = 1;
12524:2): }
12525:2): } else {
12526:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12527:2): $changes{$role}{'alttext'}{$img} = 1;
12528:2): }
1.70 raeburn 12529: }
12530: }
12531: }
12532: }
1.6 raeburn 12533: if ($domconfig->{$role}{'font'} ne '') {
12534: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12535: $changes{$role}{'font'} = 1;
12536: }
12537: } else {
12538: if ($confhash->{$role}{'font'}) {
12539: $changes{$role}{'font'} = 1;
12540: }
12541: }
1.107 raeburn 12542: if ($role ne 'login') {
12543: if ($domconfig->{$role}{'fontmenu'} ne '') {
12544: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12545: $changes{$role}{'fontmenu'} = 1;
12546: }
12547: } else {
12548: if ($confhash->{$role}{'fontmenu'}) {
12549: $changes{$role}{'fontmenu'} = 1;
12550: }
1.97 tempelho 12551: }
12552: }
1.6 raeburn 12553: foreach my $item (@bgs) {
12554: if ($domconfig->{$role}{$item} ne '') {
12555: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12556: $changes{$role}{'bgs'}{$item} = 1;
12557: }
12558: } else {
12559: if ($confhash->{$role}{$item}) {
12560: $changes{$role}{'bgs'}{$item} = 1;
12561: }
12562: }
12563: }
12564: foreach my $item (@links) {
12565: if ($domconfig->{$role}{$item} ne '') {
12566: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12567: $changes{$role}{'links'}{$item} = 1;
12568: }
12569: } else {
12570: if ($confhash->{$role}{$item}) {
12571: $changes{$role}{'links'}{$item} = 1;
12572: }
12573: }
12574: }
1.41 raeburn 12575: foreach my $item (@logintext) {
12576: if ($domconfig->{$role}{$item} ne '') {
12577: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12578: $changes{$role}{'logintext'}{$item} = 1;
12579: }
12580: } else {
12581: if ($confhash->{$role}{$item}) {
12582: $changes{$role}{'logintext'}{$item} = 1;
12583: }
12584: }
12585: }
1.6 raeburn 12586: } else {
12587: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12588: \@logintext,$confhash,\%changes);
1.6 raeburn 12589: }
12590: } else {
12591: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12592: \@logintext,$confhash,\%changes);
1.6 raeburn 12593: }
12594: }
12595: return ($errors,%changes);
12596: }
12597:
1.46 raeburn 12598: sub config_check {
12599: my ($dom,$confname,$servadm) = @_;
12600: my ($configuserok,$author_ok,$switchserver,%currroles);
12601: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12602: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12603: $confname,$servadm);
12604: if ($configuserok eq 'ok') {
12605: $switchserver = &check_switchserver($dom,$confname);
12606: if ($switchserver eq '') {
12607: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12608: }
12609: }
12610: return ($configuserok,$author_ok,$switchserver);
12611: }
12612:
1.6 raeburn 12613: sub default_change_checker {
1.41 raeburn 12614: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12615: foreach my $item (@{$links}) {
12616: if ($confhash->{$role}{$item}) {
12617: $changes->{$role}{'links'}{$item} = 1;
12618: }
12619: }
12620: foreach my $item (@{$bgs}) {
12621: if ($confhash->{$role}{$item}) {
12622: $changes->{$role}{'bgs'}{$item} = 1;
12623: }
12624: }
1.41 raeburn 12625: foreach my $item (@{$logintext}) {
12626: if ($confhash->{$role}{$item}) {
12627: $changes->{$role}{'logintext'}{$item} = 1;
12628: }
12629: }
1.6 raeburn 12630: foreach my $img (@{$images}) {
12631: if ($env{'form.'.$role.'_del_'.$img}) {
12632: $confhash->{$role}{$img} = '';
1.12 raeburn 12633: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12634: }
1.70 raeburn 12635: if ($role eq 'login') {
12636: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12637: $changes->{$role}{'showlogo'}{$img} = 1;
12638: }
1.160.6.118.2 2(raebur 12639:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
12640:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12641:2): $changes->{$role}{'alttext'}{$img} = 1;
12642:2): }
12643:2): }
1.70 raeburn 12644: }
1.6 raeburn 12645: }
12646: if ($confhash->{$role}{'font'}) {
12647: $changes->{$role}{'font'} = 1;
12648: }
1.48 raeburn 12649: }
1.6 raeburn 12650:
12651: sub display_colorchgs {
12652: my ($dom,$changes,$roles,$confhash) = @_;
12653: my (%choices,$resulttext);
12654: if (!grep(/^login$/,@{$roles})) {
12655: $resulttext = &mt('Changes made:').'<br />';
12656: }
12657: foreach my $role (@{$roles}) {
12658: if ($role eq 'login') {
12659: %choices = &login_choices();
12660: } else {
12661: %choices = &color_font_choices();
12662: }
12663: if (ref($changes->{$role}) eq 'HASH') {
12664: if ($role ne 'login') {
12665: $resulttext .= '<h4>'.&mt($role).'</h4>';
12666: }
12667: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12668: if ($role ne 'login') {
12669: $resulttext .= '<ul>';
12670: }
12671: if (ref($changes->{$role}{$key}) eq 'HASH') {
12672: if ($role ne 'login') {
12673: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12674: }
12675: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12676: if (($role eq 'login') && ($key eq 'showlogo')) {
12677: if ($confhash->{$role}{$key}{$item}) {
12678: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12679: } else {
12680: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12681: }
1.160.6.118.2 2(raebur 12682:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
12683:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 12684:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 12685:2): $confhash->{$role}{$key}{$item}).'</li>';
12686:2): } else {
12687:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12688:2): }
1.70 raeburn 12689: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12690: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12691: } else {
1.12 raeburn 12692: my $newitem = $confhash->{$role}{$item};
12693: if ($key eq 'images') {
12694: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12695: }
12696: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12697: }
12698: }
12699: if ($role ne 'login') {
12700: $resulttext .= '</ul></li>';
12701: }
12702: } else {
12703: if ($confhash->{$role}{$key} eq '') {
12704: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12705: } else {
12706: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12707: }
12708: }
12709: if ($role ne 'login') {
12710: $resulttext .= '</ul>';
12711: }
12712: }
12713: }
12714: }
1.3 raeburn 12715: return $resulttext;
1.1 raeburn 12716: }
12717:
1.9 raeburn 12718: sub thumb_dimensions {
12719: return ('200','50');
12720: }
12721:
1.16 raeburn 12722: sub check_dimensions {
12723: my ($inputfile) = @_;
12724: my ($fullwidth,$fullheight);
12725: if ($inputfile =~ m|^[/\w.\-]+$|) {
12726: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12727: my $imageinfo = <PIPE>;
12728: if (!close(PIPE)) {
12729: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12730: }
12731: chomp($imageinfo);
12732: my ($fullsize) =
1.21 raeburn 12733: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12734: if ($fullsize) {
12735: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12736: }
12737: }
12738: }
12739: return ($fullwidth,$fullheight);
12740: }
12741:
1.9 raeburn 12742: sub check_configuser {
12743: my ($uhome,$dom,$confname,$servadm) = @_;
12744: my ($configuserok,%currroles);
12745: if ($uhome eq 'no_host') {
12746: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 12747: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12748: $configuserok =
12749: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12750: $configpass,'','','','','',undef,$servadm);
12751: } else {
12752: $configuserok = 'ok';
12753: %currroles =
12754: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12755: }
12756: return ($configuserok,%currroles);
12757: }
12758:
12759: sub check_authorstatus {
12760: my ($dom,$confname,%currroles) = @_;
12761: my $author_ok;
1.40 raeburn 12762: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12763: my $start = time;
12764: my $end = 0;
12765: $author_ok =
12766: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12767: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12768: } else {
12769: $author_ok = 'ok';
12770: }
12771: return $author_ok;
12772: }
12773:
1.160.6.118.2 14(raebu 12774:23): sub update_modify_urls {
12775:23): my ($r,$modified) = @_;
12776:23): if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12777:23): push(@{$modified_urls},$modified);
12778:23): unless ($registered_cleanup) {
12779:23): my $handlers = $r->get_handlers('PerlCleanupHandler');
12780:23): $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12781:23): $registered_cleanup=1;
1.9 raeburn 12782: }
12783: }
1.155 raeburn 12784: }
12785:
12786: sub notifysubscribed {
12787: foreach my $targetsource (@{$modified_urls}){
12788: next unless (ref($targetsource) eq 'ARRAY');
12789: my ($target,$source)=@{$targetsource};
12790: if ($source ne '') {
1.160.6.88 raeburn 12791: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12792: print $logfh "\nCleanup phase: Notifications\n";
12793: my @subscribed=&subscribed_hosts($target);
12794: foreach my $subhost (@subscribed) {
12795: print $logfh "\nNotifying host ".$subhost.':';
12796: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12797: print $logfh $reply;
12798: }
12799: my @subscribedmeta=&subscribed_hosts("$target.meta");
12800: foreach my $subhost (@subscribedmeta) {
12801: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12802: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12803: $subhost);
12804: print $logfh $reply;
12805: }
12806: print $logfh "\n============ Done ============\n";
1.160 raeburn 12807: close($logfh);
1.155 raeburn 12808: }
12809: }
12810: }
12811: return OK;
12812: }
12813:
12814: sub subscribed_hosts {
12815: my ($target) = @_;
12816: my @subscribed;
1.160.6.88 raeburn 12817: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12818: while (my $subline=<$fh>) {
12819: if ($subline =~ /^($match_lonid):/) {
12820: my $host = $1;
12821: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12822: unless (grep(/^\Q$host\E$/,@subscribed)) {
12823: push(@subscribed,$host);
12824: }
12825: }
12826: }
12827: }
12828: }
12829: return @subscribed;
1.9 raeburn 12830: }
12831:
12832: sub check_switchserver {
12833: my ($dom,$confname) = @_;
1.160.6.118.2 14(raebu 12834:23): my ($allowed,$switchserver,$home);
12835:23): if ($confname eq '') {
1.9 raeburn 12836: $home = &Apache::lonnet::domain($dom,'primary');
1.160.6.118.2 14(raebu 12837:23): } else {
12838:23): $home = &Apache::lonnet::homeserver($confname,$dom);
12839:23): if ($home eq 'no_host') {
12840:23): $home = &Apache::lonnet::domain($dom,'primary');
12841:23): }
1.9 raeburn 12842: }
12843: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12844: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12845: if (!$allowed) {
1.160.6.118.2 14(raebu 12846:23): $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12847:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12848:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12849: }
12850: return $switchserver;
12851: }
12852:
1.1 raeburn 12853: sub modify_quotas {
1.160.6.30 raeburn 12854: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12855: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 12856: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 12857: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12858: $validationfieldsref);
1.86 raeburn 12859: if ($action eq 'quotas') {
1.160.6.118.2 20(raebu 12860:24): $context = 'tools';
1.160.6.26 raeburn 12861: } else {
1.86 raeburn 12862: $context = $action;
12863: }
12864: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 12865:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 12866: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12867: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12868: %titles = &courserequest_titles();
12869: $toolregexp = join('|',@usertools);
12870: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 12871: $confname = $dom.'-domainconfig';
12872: my $servadm = $r->dir_config('lonAdmEMail');
12873: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 12874: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12875: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 12876: } elsif ($context eq 'requestauthor') {
12877: @usertools = ('author');
12878: %titles = &authorrequest_titles();
1.86 raeburn 12879: } else {
1.160.6.118.2 23(raebu 12880:24): @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 12881: %titles = &tool_titles();
1.86 raeburn 12882: }
1.160.6.27 raeburn 12883: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12884: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12885: foreach my $key (keys(%env)) {
1.101 raeburn 12886: if ($context eq 'requestcourses') {
12887: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12888: my $item = $1;
12889: my $type = $2;
12890: if ($type =~ /^limit_(.+)/) {
12891: $limithash{$item}{$1} = $env{$key};
12892: } else {
12893: $confhash{$item}{$type} = $env{$key};
12894: }
12895: }
1.160.6.5 raeburn 12896: } elsif ($context eq 'requestauthor') {
12897: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12898: $confhash{$1} = $env{$key};
12899: }
1.101 raeburn 12900: } else {
1.86 raeburn 12901: if ($key =~ /^form\.quota_(.+)$/) {
12902: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 12903: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12904: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12905: }
1.72 raeburn 12906: }
12907: }
1.160.6.5 raeburn 12908: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 12909: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12910: @approvalnotify = sort(@approvalnotify);
12911: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.118.2 14(raebu 12912:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.30 raeburn 12913: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12914: foreach my $type (@hasuniquecode) {
12915: if (grep(/^\Q$type\E$/,@crstypes)) {
12916: $confhash{'uniquecode'}{$type} = 1;
12917: }
12918: }
1.160.6.46 raeburn 12919: my (%newbook,%allpos);
1.160.6.30 raeburn 12920: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12921: foreach my $type ('textbooks','templates') {
12922: @{$allpos{$type}} = ();
12923: my $invalid;
12924: if ($type eq 'textbooks') {
12925: $invalid = &mt('Invalid LON-CAPA course for textbook');
12926: } else {
12927: $invalid = &mt('Invalid LON-CAPA course for template');
12928: }
12929: if ($env{'form.'.$type.'_addbook'}) {
12930: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12931: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12932: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12933: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12934: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12935: } else {
12936: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12937: my $position = $env{'form.'.$type.'_addbook_pos'};
12938: $position =~ s/\D+//g;
12939: if ($position ne '') {
12940: $allpos{$type}[$position] = $newbook{$type};
12941: }
1.160.6.30 raeburn 12942: }
1.160.6.46 raeburn 12943: } else {
12944: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 12945: }
12946: }
1.160.6.46 raeburn 12947: }
1.160.6.30 raeburn 12948: }
1.102 raeburn 12949: if (ref($domconfig{$action}) eq 'HASH') {
12950: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12951: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12952: $changes{'notify'}{'approval'} = 1;
12953: }
12954: } else {
1.144 raeburn 12955: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12956: $changes{'notify'}{'approval'} = 1;
12957: }
12958: }
1.160.6.30 raeburn 12959: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12960: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12961: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12962: unless ($confhash{'uniquecode'}{$crstype}) {
12963: $changes{'uniquecode'} = 1;
12964: }
12965: }
12966: unless ($changes{'uniquecode'}) {
12967: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12968: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12969: $changes{'uniquecode'} = 1;
12970: }
12971: }
12972: }
12973: } else {
12974: $changes{'uniquecode'} = 1;
12975: }
12976: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12977: $changes{'uniquecode'} = 1;
12978: }
12979: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12980: foreach my $type ('textbooks','templates') {
12981: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12982: my %deletions;
12983: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12984: if (@todelete) {
12985: map { $deletions{$_} = 1; } @todelete;
12986: }
12987: my %imgdeletions;
12988: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12989: if (@todeleteimages) {
12990: map { $imgdeletions{$_} = 1; } @todeleteimages;
12991: }
12992: my $maxnum = $env{'form.'.$type.'_maxnum'};
12993: for (my $i=0; $i<=$maxnum; $i++) {
12994: my $itemid = $env{'form.'.$type.'_id_'.$i};
12995: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12996: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12997: if ($deletions{$key}) {
12998: if ($domconfig{$action}{$type}{$key}{'image'}) {
12999: #FIXME need to obsolete item in RES space
13000: }
13001: next;
13002: } else {
13003: my $newpos = $env{'form.'.$itemid};
13004: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 13005: foreach my $item ('subject','title','publisher','author') {
13006: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13007: ($type eq 'templates'));
1.160.6.46 raeburn 13008: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13009: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13010: $changes{$type}{$key} = 1;
13011: }
13012: }
13013: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 13014: }
1.160.6.46 raeburn 13015: if ($imgdeletions{$key}) {
13016: $changes{$type}{$key} = 1;
13017: #FIXME need to obsolete item in RES space
13018: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13019: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 13020: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13021: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13022: } else {
13023: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13024: $cdom,$cnum,$type,$configuserok,
13025: $switchserver,$author_ok);
13026: if ($imgurl) {
13027: $confhash{$type}{$key}{'image'} = $imgurl;
13028: $changes{$type}{$key} = 1;
13029: }
13030: if ($error) {
13031: &Apache::lonnet::logthis($error);
13032: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13033: }
1.160.6.118.2 14(raebu 13034:23): }
1.160.6.46 raeburn 13035: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13036: $confhash{$type}{$key}{'image'} =
13037: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 13038: }
13039: }
13040: }
13041: }
13042: }
13043: }
1.102 raeburn 13044: } else {
1.144 raeburn 13045: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13046: $changes{'notify'}{'approval'} = 1;
13047: }
1.160.6.30 raeburn 13048: if (ref($confhash{'uniquecode'} eq 'HASH')) {
13049: $changes{'uniquecode'} = 1;
13050: }
13051: }
13052: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 13053: foreach my $type ('textbooks','templates') {
13054: if ($newbook{$type}) {
13055: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 13056: foreach my $item ('subject','title','publisher','author') {
13057: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13058: ($type eq 'template'));
1.160.6.46 raeburn 13059: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13060: if ($env{'form.'.$type.'_addbook_'.$item}) {
13061: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13062: }
13063: }
13064: if ($type eq 'textbooks') {
13065: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13066: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 13067: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13068: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13069: } else {
13070: my ($imageurl,$error) =
13071: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13072: $configuserok,$switchserver,$author_ok);
13073: if ($imageurl) {
13074: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13075: }
13076: if ($error) {
13077: &Apache::lonnet::logthis($error);
13078: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13079: }
1.160.6.46 raeburn 13080: }
13081: }
1.160.6.30 raeburn 13082: }
13083: }
1.160.6.46 raeburn 13084: if (@{$allpos{$type}} > 0) {
13085: my $idx = 0;
13086: foreach my $item (@{$allpos{$type}}) {
13087: if ($item ne '') {
13088: $confhash{$type}{$item}{'order'} = $idx;
13089: if (ref($domconfig{$action}) eq 'HASH') {
13090: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13091: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13092: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13093: $changes{$type}{$item} = 1;
13094: }
1.160.6.30 raeburn 13095: }
13096: }
13097: }
1.160.6.46 raeburn 13098: $idx ++;
1.160.6.30 raeburn 13099: }
13100: }
13101: }
13102: }
1.160.6.39 raeburn 13103: if (ref($validationitemsref) eq 'ARRAY') {
13104: foreach my $item (@{$validationitemsref}) {
13105: if ($item eq 'fields') {
13106: my @changed;
13107: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13108: if (@{$confhash{'validation'}{$item}} > 0) {
13109: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13110: }
1.160.6.65 raeburn 13111: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13112: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13113: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13114: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13115: $domconfig{'requestcourses'}{'validation'}{$item});
13116: } else {
13117: @changed = @{$confhash{'validation'}{$item}};
13118: }
1.160.6.39 raeburn 13119: } else {
13120: @changed = @{$confhash{'validation'}{$item}};
13121: }
13122: } else {
13123: @changed = @{$confhash{'validation'}{$item}};
13124: }
13125: if (@changed) {
13126: if ($confhash{'validation'}{$item}) {
13127: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13128: } else {
13129: $changes{'validation'}{$item} = &mt('None');
13130: }
13131: }
13132: } else {
13133: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13134: if ($item eq 'markup') {
13135: if ($env{'form.requestcourses_validation_'.$item}) {
13136: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13137: }
13138: }
1.160.6.65 raeburn 13139: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13140: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13141: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13142: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13143: }
13144: } else {
13145: if ($confhash{'validation'}{$item} ne '') {
13146: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13147: }
1.160.6.39 raeburn 13148: }
13149: } else {
13150: if ($confhash{'validation'}{$item} ne '') {
13151: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13152: }
13153: }
13154: }
13155: }
13156: }
13157: if ($env{'form.validationdc'}) {
13158: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 13159: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 13160: if (exists($domcoords{$newval})) {
13161: $confhash{'validation'}{'dc'} = $newval;
13162: }
13163: }
13164: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 13165: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13166: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13167: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13168: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13169: if ($confhash{'validation'}{'dc'} eq '') {
13170: $changes{'validation'}{'dc'} = &mt('None');
13171: } else {
13172: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13173: }
1.160.6.39 raeburn 13174: }
1.160.6.65 raeburn 13175: } elsif ($confhash{'validation'}{'dc'} ne '') {
13176: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 13177: }
13178: } elsif ($confhash{'validation'}{'dc'} ne '') {
13179: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13180: }
13181: } elsif ($confhash{'validation'}{'dc'} ne '') {
13182: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13183: }
1.160.6.65 raeburn 13184: } else {
13185: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13186: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13187: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13188: $changes{'validation'}{'dc'} = &mt('None');
13189: }
13190: }
1.160.6.39 raeburn 13191: }
13192: }
1.102 raeburn 13193: }
13194: } else {
1.86 raeburn 13195: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
13196: }
1.72 raeburn 13197: foreach my $item (@usertools) {
13198: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13199: my $unset;
1.101 raeburn 13200: if ($context eq 'requestcourses') {
1.104 raeburn 13201: $unset = '0';
13202: if ($type eq '_LC_adv') {
13203: $unset = '';
13204: }
1.101 raeburn 13205: if ($confhash{$item}{$type} eq 'autolimit') {
13206: $confhash{$item}{$type} .= '=';
13207: unless ($limithash{$item}{$type} =~ /\D/) {
13208: $confhash{$item}{$type} .= $limithash{$item}{$type};
13209: }
13210: }
1.160.6.5 raeburn 13211: } elsif ($context eq 'requestauthor') {
13212: $unset = '0';
13213: if ($type eq '_LC_adv') {
13214: $unset = '';
13215: }
1.72 raeburn 13216: } else {
1.101 raeburn 13217: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13218: $confhash{$item}{$type} = 1;
13219: } else {
13220: $confhash{$item}{$type} = 0;
13221: }
1.72 raeburn 13222: }
1.86 raeburn 13223: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 13224: if ($action eq 'requestauthor') {
13225: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13226: $changes{$type} = 1;
13227: }
13228: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13229: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13230: $changes{$item}{$type} = 1;
13231: }
13232: } else {
13233: if ($context eq 'requestcourses') {
1.104 raeburn 13234: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13235: $changes{$item}{$type} = 1;
13236: }
13237: } else {
13238: if (!$confhash{$item}{$type}) {
13239: $changes{$item}{$type} = 1;
13240: }
13241: }
13242: }
13243: } else {
13244: if ($context eq 'requestcourses') {
1.104 raeburn 13245: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13246: $changes{$item}{$type} = 1;
13247: }
1.160.6.5 raeburn 13248: } elsif ($context eq 'requestauthor') {
13249: if ($confhash{$type} ne $unset) {
13250: $changes{$type} = 1;
13251: }
1.72 raeburn 13252: } else {
13253: if (!$confhash{$item}{$type}) {
13254: $changes{$item}{$type} = 1;
13255: }
13256: }
13257: }
1.1 raeburn 13258: }
13259: }
1.160.6.5 raeburn 13260: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13261: if (ref($domconfig{'quotas'}) eq 'HASH') {
13262: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13263: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13264: if (exists($confhash{'defaultquota'}{$key})) {
13265: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13266: $changes{'defaultquota'}{$key} = 1;
13267: }
13268: } else {
13269: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13270: }
13271: }
1.86 raeburn 13272: } else {
13273: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13274: if (exists($confhash{'defaultquota'}{$key})) {
13275: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13276: $changes{'defaultquota'}{$key} = 1;
13277: }
13278: } else {
13279: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13280: }
1.1 raeburn 13281: }
13282: }
1.160.6.20 raeburn 13283: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.160.6.118.2 20(raebu 13284:24): $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
13285:24): }
13286:24): if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
13287:24): $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.160.6.20 raeburn 13288: }
1.1 raeburn 13289: }
1.86 raeburn 13290: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13291: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13292: if (ref($domconfig{'quotas'}) eq 'HASH') {
13293: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13294: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13295: $changes{'defaultquota'}{$key} = 1;
13296: }
13297: } else {
13298: if (!exists($domconfig{'quotas'}{$key})) {
13299: $changes{'defaultquota'}{$key} = 1;
13300: }
1.72 raeburn 13301: }
13302: } else {
1.86 raeburn 13303: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13304: }
1.1 raeburn 13305: }
13306: }
13307: }
1.72 raeburn 13308:
1.160.6.5 raeburn 13309: if ($context eq 'requestauthor') {
13310: $domdefaults{'requestauthor'} = \%confhash;
13311: } else {
13312: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 13313: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 13314: $domdefaults{$key} = $confhash{$key};
13315: }
1.160.6.5 raeburn 13316: }
1.72 raeburn 13317: }
1.160.6.5 raeburn 13318:
1.1 raeburn 13319: my %quotahash = (
1.86 raeburn 13320: $action => { %confhash }
1.1 raeburn 13321: );
13322: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13323: $dom);
13324: if ($putresult eq 'ok') {
13325: if (keys(%changes) > 0) {
1.72 raeburn 13326: my $cachetime = 24*60*60;
13327: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13328: if (ref($lastactref) eq 'HASH') {
13329: $lastactref->{'domdefaults'} = 1;
13330: }
1.1 raeburn 13331: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 13332: unless (($context eq 'requestcourses') ||
13333: ($context eq 'requestauthor')) {
1.86 raeburn 13334: if (ref($changes{'defaultquota'}) eq 'HASH') {
13335: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13336: foreach my $type (@{$types},'default') {
13337: if (defined($changes{'defaultquota'}{$type})) {
13338: my $typetitle = $usertypes->{$type};
13339: if ($type eq 'default') {
13340: $typetitle = $othertitle;
13341: }
1.160.6.28 raeburn 13342: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13343: }
13344: }
1.86 raeburn 13345: $resulttext .= '</ul></li>';
1.72 raeburn 13346: }
13347: }
1.80 raeburn 13348: my %newenv;
1.72 raeburn 13349: foreach my $item (@usertools) {
1.160.6.5 raeburn 13350: my (%haschgs,%inconf);
13351: if ($context eq 'requestauthor') {
13352: %haschgs = %changes;
13353: %inconf = %confhash;
13354: } else {
13355: if (ref($changes{$item}) eq 'HASH') {
13356: %haschgs = %{$changes{$item}};
13357: }
13358: if (ref($confhash{$item}) eq 'HASH') {
13359: %inconf = %{$confhash{$item}};
13360: }
13361: }
13362: if (keys(%haschgs) > 0) {
1.80 raeburn 13363: my $newacc =
13364: &Apache::lonnet::usertools_access($env{'user.name'},
13365: $env{'user.domain'},
1.86 raeburn 13366: $item,'reload',$context);
1.160.6.5 raeburn 13367: if (($context eq 'requestcourses') ||
13368: ($context eq 'requestauthor')) {
1.108 raeburn 13369: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13370: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13371: }
13372: } else {
13373: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13374: $newenv{'environment.availabletools.'.$item} = $newacc;
13375: }
1.80 raeburn 13376: }
1.160.6.5 raeburn 13377: unless ($context eq 'requestauthor') {
13378: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13379: }
1.72 raeburn 13380: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 13381: if ($haschgs{$type}) {
1.72 raeburn 13382: my $typetitle = $usertypes->{$type};
13383: if ($type eq 'default') {
13384: $typetitle = $othertitle;
13385: } elsif ($type eq '_LC_adv') {
13386: $typetitle = 'LON-CAPA Advanced Users';
13387: }
1.160.6.5 raeburn 13388: if ($inconf{$type}) {
1.101 raeburn 13389: if ($context eq 'requestcourses') {
13390: my $cond;
1.160.6.5 raeburn 13391: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13392: if ($1 eq '') {
13393: $cond = &mt('(Automatic processing of any request).');
13394: } else {
13395: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13396: }
13397: } else {
1.160.6.5 raeburn 13398: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13399: }
13400: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 13401: } elsif ($context eq 'requestauthor') {
13402: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13403: $titles{$inconf{$type}},$typetitle);
13404:
1.101 raeburn 13405: } else {
13406: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13407: }
1.72 raeburn 13408: } else {
1.104 raeburn 13409: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 13410: if ($inconf{$type} eq '0') {
1.104 raeburn 13411: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13412: } else {
13413: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13414: }
13415: } else {
13416: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13417: }
1.72 raeburn 13418: }
13419: }
1.26 raeburn 13420: }
1.160.6.5 raeburn 13421: unless ($context eq 'requestauthor') {
13422: $resulttext .= '</ul></li>';
13423: }
1.26 raeburn 13424: }
1.1 raeburn 13425: }
1.160.6.5 raeburn 13426: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13427: if (ref($changes{'notify'}) eq 'HASH') {
13428: if ($changes{'notify'}{'approval'}) {
13429: if (ref($confhash{'notify'}) eq 'HASH') {
13430: if ($confhash{'notify'}{'approval'}) {
13431: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13432: } else {
1.160.6.5 raeburn 13433: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13434: }
13435: }
13436: }
13437: }
13438: }
1.160.6.30 raeburn 13439: if ($action eq 'requestcourses') {
13440: my @offon = ('off','on');
13441: if ($changes{'uniquecode'}) {
13442: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13443: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13444: $resulttext .= '<li>'.
13445: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13446: '</li>';
13447: } else {
13448: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13449: '</li>';
13450: }
13451: }
1.160.6.46 raeburn 13452: foreach my $type ('textbooks','templates') {
13453: if (ref($changes{$type}) eq 'HASH') {
13454: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13455: foreach my $key (sort(keys(%{$changes{$type}}))) {
13456: my %coursehash = &Apache::lonnet::coursedescription($key);
13457: my $coursetitle = $coursehash{'description'};
13458: my $position = $confhash{$type}{$key}{'order'} + 1;
13459: $resulttext .= '<li>';
1.160.6.47 raeburn 13460: foreach my $item ('subject','title','publisher','author') {
13461: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13462: ($type eq 'templates'));
1.160.6.46 raeburn 13463: my $name = $item.':';
13464: $name =~ s/^(\w)/\U$1/;
13465: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13466: }
13467: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13468: if ($type eq 'textbooks') {
13469: if ($confhash{$type}{$key}{'image'}) {
13470: $resulttext .= ' '.&mt('Image: [_1]',
13471: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13472: ' alt="Textbook cover" />').'<br />';
13473: }
13474: }
13475: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 13476: }
1.160.6.46 raeburn 13477: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 13478: }
13479: }
1.160.6.39 raeburn 13480: if (ref($changes{'validation'}) eq 'HASH') {
13481: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13482: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13483: foreach my $item (@{$validationitemsref}) {
13484: if (exists($changes{'validation'}{$item})) {
13485: if ($item eq 'markup') {
13486: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13487: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13488: } else {
13489: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13490: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13491: }
13492: }
13493: }
13494: if (exists($changes{'validation'}{'dc'})) {
13495: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13496: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13497: }
1.160.6.118.2 24(raebu 13498:24): $resulttext .= '</ul></li>';
1.160.6.39 raeburn 13499: }
13500: }
1.160.6.30 raeburn 13501: }
1.1 raeburn 13502: $resulttext .= '</ul>';
1.80 raeburn 13503: if (keys(%newenv)) {
13504: &Apache::lonnet::appenv(\%newenv);
13505: }
1.1 raeburn 13506: } else {
1.86 raeburn 13507: if ($context eq 'requestcourses') {
13508: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 13509: } elsif ($context eq 'requestauthor') {
13510: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13511: } else {
1.90 weissno 13512: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13513: }
1.1 raeburn 13514: }
13515: } else {
1.11 albertel 13516: $resulttext = '<span class="LC_error">'.
13517: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13518: }
1.160.6.30 raeburn 13519: if ($errors) {
13520: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13521: '<ul>'.$errors.'</ul></p>';
13522: }
1.3 raeburn 13523: return $resulttext;
1.1 raeburn 13524: }
13525:
1.160.6.30 raeburn 13526: sub process_textbook_image {
1.160.6.46 raeburn 13527: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 13528: my $filename = $env{'form.'.$caller.'.filename'};
13529: my ($error,$url);
13530: my ($width,$height) = (50,50);
13531: if ($configuserok eq 'ok') {
13532: if ($switchserver) {
13533: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13534: $switchserver);
13535: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 13536:23): my $modified = [];
1.160.6.30 raeburn 13537: my ($result,$imageurl) =
1.160.6.118.2 14(raebu 13538:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
13539:23): "$type/$cdom/$cnum/cover",$width,$height,
13540:23): '',$modified);
1.160.6.30 raeburn 13541: if ($result eq 'ok') {
13542: $url = $imageurl;
1.160.6.118.2 14(raebu 13543:23): &update_modify_urls($r,$modified);
1.160.6.30 raeburn 13544: } else {
13545: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13546: }
13547: } else {
13548: $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);
13549: }
13550: } else {
13551: $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);
13552: }
13553: return ($url,$error);
13554: }
13555:
1.160.6.118.2 1(raebur 13556:1): sub modify_ltitools {
13557:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14(raebu 13558:23): my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
13559:23): &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
13560:23):
1(raebur 13561:1): my $confname = $dom.'-domainconfig';
13562:1): my $servadm = $r->dir_config('lonAdmEMail');
13563:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14(raebu 13564:23):
13565:23): my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
13566:23): my $toolserror =
13567:23): &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
13568:23): $lastactref,$configuserok,$switchserver,$author_ok);
13569:23):
13570:23): my $home = &Apache::lonnet::domain($dom,'primary');
13571:23): unless (($home eq 'no_host') || ($home eq '')) {
13572:23): my @ids=&Apache::lonnet::current_machine_ids();
13573:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
13574:23): }
13575:23):
13576:23): if (keys(%ltitoolschg)) {
13577:23): foreach my $id (keys(%ltitoolschg)) {
13578:23): if (ref($ltitoolschg{$id}) eq 'HASH') {
13579:23): foreach my $inner (keys(%{$ltitoolschg{$id}})) {
13580:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13581:23): if ($is_home) {
13582:23): $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
13583:23): }
13584:23): }
1(raebur 13585:1): }
14(raebu 13586:23): }
13587:23): }
13588:23): $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
13589:23): if (keys(%ltitoolschg)) {
13590:23): %newltitools = %ltitoolschg;
13591:23): }
13592:23): }
13593:23): if (ref($domconfig{'ltitools'}) eq 'HASH') {
13594:23): foreach my $id (%{$domconfig{'ltitools'}}) {
13595:23): next if ($id !~ /^\d+$/);
13596:23): unless (exists($ltitoolschg{$id})) {
13597:23): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
13598:23): foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
13599:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13600:23): if ($is_home) {
13601:23): $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13602:23): }
13603:23): } else {
13604:23): $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13605:23): }
1(raebur 13606:1): }
14(raebu 13607:23): } else {
13608:23): $newltitools{$id} = $domconfig{'ltitools'}{$id};
1(raebur 13609:1): }
13610:1): }
14(raebu 13611:23): }
13612:23): }
13613:23): if ($toolserror) {
13614:23): $errors = '<li>'.$toolserror.'</li>';
13615:23): }
13616:23): if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
13617:23): $resulttext = &mt('No changes made.');
13618:23): if ($errors) {
13619:23): $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13620:23): $errors.'</ul>';
13621:23): }
13622:23): return $resulttext;
13623:23): }
13624:23): my %ltitoolshash = (
13625:23): $action => { %newltitools }
13626:23): );
13627:23): if (keys(%secchanges)) {
13628:23): $ltitoolshash{'toolsec'} = \%newtoolsec;
13629:23): }
13630:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
13631:23): if ($putresult eq 'ok') {
13632:23): my %keystore;
13633:23): if ($is_home) {
13634:23): my %toolsenchash = (
13635:23): $action => { %newtoolsenc }
13636:23): );
13637:23): &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13638:23): my $cachetime = 24*60*60;
13639:23): &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13640:23): &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13641:23): }
13642:23): $resulttext = &mt('Changes made:').'<ul>';
13643:23): if (keys(%secchanges) > 0) {
13644:23): $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13645:23): }
13646:23): if (keys(%ltitoolschg) > 0) {
13647:23): $resulttext .= $ltitoolsoutput;
13648:23): }
13649:23): my $cachetime = 24*60*60;
13650:23): &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13651:23): if (ref($lastactref) eq 'HASH') {
13652:23): $lastactref->{'ltitools'} = 1;
13653:23): }
13654:23): } else {
13655:23): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13656:23): }
13657:23): if ($errors) {
13658:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13659:23): $errors.'</ul></p>';
13660:23): }
13661:23): return $resulttext;
13662:23): }
13663:23):
13664:23): sub fetch_secrets {
13665:23): my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13666:23): my %keyset;
13667:23): %{$currsec} = ();
13668:23): $newsec->{'private'}{'keys'} = [];
13669:23): $newsec->{'encrypt'} = {};
13670:23): $newsec->{'rules'} = {};
13671:23): if ($context eq 'ltisec') {
13672:23): $newsec->{'linkprot'} = {};
13673:23): }
13674:23): if (ref($domconfig->{$context}) eq 'HASH') {
13675:23): %{$currsec} = %{$domconfig->{$context}};
13676:23): if ($context eq 'ltisec') {
13677:23): if (ref($currsec->{'linkprot'}) eq 'HASH') {
13678:23): foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13679:23): unless ($id =~ /^\d+$/) {
13680:23): delete($currsec->{'linkprot'}{$id});
13681:23): }
13682:23): }
1(raebur 13683:1): }
14(raebu 13684:23): }
13685:23): if (ref($currsec->{'private'}) eq 'HASH') {
13686:23): if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13687:23): $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13688:23): map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1(raebur 13689:1): }
14(raebu 13690:23): }
13691:23): }
13692:23): my @items= ('crs','dom');
13693:23): if ($context eq 'ltisec') {
13694:23): push(@items,'consumers');
13695:23): }
13696:23): foreach my $item (@items) {
13697:23): my $formelement;
13698:23): if (($context eq 'toolsec') || ($item eq 'consumers')) {
13699:23): $formelement = 'form.'.$context.'_'.$item;
13700:23): } else {
13701:23): $formelement = 'form.'.$context.'_'.$item.'linkprot';
13702:23): }
13703:23): if ($env{$formelement}) {
13704:23): $newsec->{'encrypt'}{$item} = 1;
13705:23): if (ref($currsec->{'encrypt'}) eq 'HASH') {
13706:23): unless ($currsec->{'encrypt'}{$item}) {
13707:23): $secchanges->{'encrypt'} = 1;
13708:23): }
1(raebur 13709:1): } else {
14(raebu 13710:23): $secchanges->{'encrypt'} = 1;
13711:23): }
13712:23): } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13713:23): if ($currsec->{'encrypt'}{$item}) {
13714:23): $secchanges->{'encrypt'} = 1;
1(raebur 13715:1): }
14(raebu 13716:23): }
13717:23): }
13718:23): my $secrets;
13719:23): if ($context eq 'ltisec') {
13720:23): $secrets = 'ltisecrets';
13721:23): } else {
13722:23): $secrets = 'toolsecrets';
13723:23): }
13724:23): unless (exists($currsec->{'rules'})) {
13725:23): $currsec->{'rules'} = {};
13726:23): }
13727:23): &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13728:23):
13729:23): my @ids=&Apache::lonnet::current_machine_ids();
13730:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
13731:23):
13732:23): foreach my $hostid (keys(%servers)) {
13733:23): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13734:23): my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13735:23): if (exists($env{$keyitem})) {
13736:23): $env{$keyitem} =~ s/(`)/'/g;
13737:23): if ($keyset{$hostid}) {
13738:23): if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13739:23): if ($env{$keyitem} ne '') {
13740:23): $secchanges->{'private'} = 1;
13741:23): $newkeyset->{$hostid} = $env{$keyitem};
13742:23): }
1(raebur 13743:1): }
14(raebu 13744:23): } elsif ($env{$keyitem} ne '') {
13745:23): unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13746:23): push(@{$newsec->{'private'}{'keys'}},$hostid);
1(raebur 13747:1): }
14(raebu 13748:23): $secchanges->{'private'} = 1;
13749:23): $newkeyset->{$hostid} = $env{$keyitem};
1(raebur 13750:1): }
13751:1): }
14(raebu 13752:23): }
13753:23): }
13754:23): }
13755:23):
13756:23): sub store_security {
13757:23): my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13758:23): return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13759:23): (ref($keystore) eq 'HASH'));
13760:23): if (keys(%{$secchanges})) {
13761:23): if ($secchanges->{'private'}) {
13762:23): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13763:23): foreach my $hostid (keys(%{$newkeyset})) {
13764:23): my $storehash = {
13765:23): key => $newkeyset->{$hostid},
13766:23): who => $env{'user.name'}.':'.$env{'user.domain'},
13767:23): };
13768:23): $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13769:23): $dom,$hostid);
13770:23): }
13771:23): }
13772:23): }
13773:23): }
13774:23):
13775:23): sub lti_security_results {
13776:23): my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13777:23): my $output;
13778:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13779:23): my $needs_update;
13780:23): foreach my $item (keys(%{$secchanges})) {
13781:23): if ($item eq 'encrypt') {
13782:23): $needs_update = 1;
13783:23): my %encrypted;
13784:23): if ($context eq 'lti') {
13785:23): %encrypted = (
13786:23): crs => {
13787:23): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13788:23): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13789:23): },
13790:23): dom => {
13791:23): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13792:23): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13793:23): },
13794:23): consumers => {
13795:23): on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13796:23): off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13797:23): },
13798:23): );
1(raebur 13799:1): } else {
14(raebu 13800:23): %encrypted = (
13801:23): crs => {
13802:23): on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13803:23): off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13804:23): },
13805:23): dom => {
13806:23): on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13807:23): off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13808:23): },
13809:23): );
1(raebur 13810:1): }
14(raebu 13811:23): my @types= ('crs','dom');
13812:23): if ($context eq 'lti') {
13813:23): foreach my $type (@types) {
13814:23): undef($domdefaults{'linkprotenc_'.$type});
1(raebur 13815:1): }
14(raebu 13816:23): push(@types,'consumers');
13817:23): undef($domdefaults{'ltienc_consumers'});
13818:23): } elsif ($context eq 'ltitools') {
13819:23): foreach my $type (@types) {
13820:23): undef($domdefaults{'toolenc_'.$type});
1(raebur 13821:1): }
13822:1): }
14(raebu 13823:23): foreach my $type (@types) {
13824:23): my $shown = $encrypted{$type}{'off'};
13825:23): if (ref($newsec->{$item}) eq 'HASH') {
13826:23): if ($newsec->{$item}{$type}) {
13827:23): if ($context eq 'lti') {
13828:23): if ($type eq 'consumers') {
13829:23): $domdefaults{'ltienc_consumers'} = 1;
13830:23): } else {
13831:23): $domdefaults{'linkprotenc_'.$type} = 1;
1(raebur 13832:1): }
14(raebu 13833:23): } elsif ($context eq 'ltitools') {
13834:23): $domdefaults{'toolenc_'.$type} = 1;
1(raebur 13835:1): }
14(raebu 13836:23): $shown = $encrypted{$type}{'on'};
1(raebur 13837:1): }
13838:1): }
14(raebu 13839:23): $output .= '<li>'.$shown.'</li>';
13840:23): }
13841:23): } elsif ($item eq 'rules') {
13842:23): my %titles = &Apache::lonlocal::texthash(
13843:23): min => 'Minimum password length',
13844:23): max => 'Maximum password length',
13845:23): chars => 'Required characters',
13846:23): );
13847:23): foreach my $rule ('min','max') {
13848:23): if ($newsec->{rules}{$rule} eq '') {
13849:23): if ($rule eq 'min') {
13850:23): $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13851:23): ' '.&mt('Default of [_1] will be used',
13852:23): $Apache::lonnet::passwdmin).'</li>';
13853:23): } else {
13854:23): $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13855:23): }
13856:23): } else {
13857:23): $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13858:23): }
13859:23): }
13860:23): if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13861:23): if (@{$newsec->{'rules'}{'chars'}} > 0) {
13862:23): my %rulenames = &Apache::lonlocal::texthash(
13863:23): uc => 'At least one upper case letter',
13864:23): lc => 'At least one lower case letter',
13865:23): num => 'At least one number',
13866:23): spec => 'At least one non-alphanumeric',
13867:23): );
13868:23): my $needed = '<ul><li>'.
13869:23): join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13870:23): '</li></ul>';
13871:23): $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13872:23): } else {
13873:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13874:23): }
13875:23): } else {
13876:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1(raebur 13877:1): }
14(raebu 13878:23): } elsif ($item eq 'private') {
13879:23): $needs_update = 1;
13880:23): if ($context eq 'lti') {
13881:23): undef($domdefaults{'ltiprivhosts'});
13882:23): } elsif ($context eq 'ltitools') {
13883:23): undef($domdefaults{'toolprivhosts'});
13884:23): }
13885:23): if (keys(%{$newkeyset})) {
13886:23): my @privhosts;
13887:23): foreach my $hostid (sort(keys(%{$newkeyset}))) {
13888:23): if ($keystore->{$hostid} eq 'ok') {
13889:23): $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13890:23): unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13891:23): push(@privhosts,$hostid);
13892:23): }
13893:23): }
13894:23): }
13895:23): if (@privhosts) {
13896:23): if ($context eq 'lti') {
13897:23): $domdefaults{'ltiprivhosts'} = \@privhosts;
13898:23): } elsif ($context eq 'ltitools') {
13899:23): $domdefaults{'toolprivhosts'} = \@privhosts;
1(raebur 13900:1): }
13901:1): }
13902:1): }
14(raebu 13903:23): } elsif ($item eq 'linkprot') {
13904:23): next;
18(raebu 13905:24): } elsif ($item eq 'suggested') {
13906:24): if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
13907:24): (ref($newsec->{'suggested'}) eq 'HASH')) {
13908:24): my $suggestions;
13909:24): foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
13910:24): if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
13911:24): my $name = $newsec->{'suggested'}->{$id}->{'name'};
13912:24): my $info = $newsec->{'suggested'}->{$id}->{'info'};
13913:24): $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
13914:24): &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
13915:24): '</li>';
13916:24): } else {
13917:24): $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
13918:24): $newsec->{'suggested'}->{$id}).'</li>';
13919:24): }
13920:24): }
13921:24): if ($suggestions) {
13922:24): $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
13923:24): '<ul>'.$suggestions.'</ul>'.
13924:24): '</li>';
13925:24): }
13926:24): }
14(raebu 13927:23): }
13928:23): }
13929:23): if ($needs_update) {
13930:23): my $cachetime = 24*60*60;
13931:23): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13932:23): }
13933:23): return $output;
13934:23): }
13935:23):
13936:23): sub modify_lti {
13937:23): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13938:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13939:23): my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13940:23): my (%posslti,%posslticrs,%posscrstype);
13941:23): my @courseroles = ('cc','in','ta','ep','st');
13942:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13943:23): my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13944:23): my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13945:23): my %coursetypetitles = &Apache::lonlocal::texthash (
13946:23): official => 'Official',
13947:23): unofficial => 'Unofficial',
13948:23): community => 'Community',
13949:23): textbook => 'Textbook',
13950:23): placement => 'Placement Test',
13951:23): lti => 'LTI Provider',
13952:23): );
13953:23): my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13954:23): my %lt = <i_names();
13955:23): map { $posslti{$_} = 1; } @ltiroles;
13956:23): map { $posslticrs{$_} = 1; } @lticourseroles;
13957:23): map { $posscrstype{$_} = 1; } @coursetypes;
13958:23):
13959:23): my %menutitles = <imenu_titles();
13960:23): my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13961:23):
13962:23): &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13963:23):
13964:23): my (%linkprotchg,$linkprotoutput,$is_home);
13965:23): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13966:23): \%linkprotchg,'domain');
13967:23): my $home = &Apache::lonnet::domain($dom,'primary');
13968:23): unless (($home eq 'no_host') || ($home eq '')) {
13969:23): my @ids=&Apache::lonnet::current_machine_ids();
13970:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13971:23): }
13972:23):
13973:23): if (keys(%linkprotchg)) {
13974:23): $secchanges{'linkprot'} = 1;
13975:23): my %oldlinkprot;
13976:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13977:23): %oldlinkprot = %{$currltisec{'linkprot'}};
13978:23): }
13979:23): foreach my $id (keys(%linkprotchg)) {
13980:23): if (ref($linkprotchg{$id}) eq 'HASH') {
13981:23): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13982:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13983:23): if ($is_home) {
13984:23): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13985:23): }
13986:23): }
13987:23): }
13988:23): } else {
13989:23): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
1(raebur 13990:1): }
14(raebu 13991:23): }
13992:23): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13993:23): if (keys(%linkprotchg)) {
13994:23): %{$newltisec{'linkprot'}} = %linkprotchg;
13995:23): }
13996:23): }
13997:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
18(raebu 13998:24): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
14(raebu 13999:23): next if ($id !~ /^\d+$/);
14000:23): unless (exists($linkprotchg{$id})) {
14001:23): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
14002:23): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
14003:23): if (($inner eq 'secret') || ($inner eq 'key')) {
14004:23): if ($is_home) {
14005:23): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
14006:23): }
14007:23): } else {
14008:23): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
14009:23): }
14010:23): }
14011:23): } else {
14012:23): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
14013:23): }
1(raebur 14014:1): }
14(raebu 14015:23): }
14016:23): }
14017:23): if ($proterror) {
14018:23): $errors .= '<li>'.$proterror.'</li>';
14019:23): }
18(raebu 14020:24):
14021:24): my (%delsuggested,%suggids,@suggested);;
14022:24): if (ref($currltisec{'suggested'}) eq 'HASH') {
14023:24): my $maxnum = $env{'form.linkprot_suggested_maxnum'};
14024:24): my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
14025:24): for (my $i=0; $i<$maxnum; $i++) {
14026:24): my $itemid = $env{'form.linkprot_suggested_id_'.$i};
14027:24): $itemid =~ s/\D+//g;
14028:24): if ($itemid) {
14029:24): if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
14030:24): push(@suggested,$i);
14031:24): $suggids{$i} = $itemid;
14032:24): if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
14033:24): if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
14034:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14035:24): }
14036:24): } else {
14037:24): if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
14038:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14039:24): } else {
14040:24): $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
14041:24): $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
14042:24): $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
14043:24): $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
14044:24): if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
14045:24): ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
14046:24): $secchanges{'suggested'}{$itemid} = 1;
14047:24): }
14048:24): }
14049:24): }
14050:24): }
14051:24): }
14052:24): }
14053:24): }
14054:24): foreach my $key (keys(%delsuggested)) {
14055:24): $newltisec{'suggested'}{$key} = $delsuggested{$key};
14056:24): $secchanges{'suggested'}{$key} = 1;
14057:24): }
14058:24): if (($env{'form.linkprot_suggested_add'}) &&
14059:24): ($env{'form.linkprot_suggested_name_add'} ne '')) {
14060:24): $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
14061:24): $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
14062:24): my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
14063:24): if ($newsuggid) {
14064:24): $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
14065:24): $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
14066:24): $secchanges{'suggested'}{$newsuggid} = 1;
14067:24): } else {
14068:24): my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
14069:24): if ($errormsg) {
14070:24): $error .= ' ('.$errormsg.')';
14071:24): }
14072:24): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14073:24): }
14074:24): }
14(raebu 14075:23): my (@items,%deletions,%itemids);
14076:23): if ($env{'form.lti_add'}) {
14077:23): my $consumer = $env{'form.lti_consumer_add'};
14078:23): $consumer =~ s/(`)/'/g;
19(raebu 14079:24): ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
14(raebu 14080:23): if ($newid) {
14081:23): $itemids{'add'} = $newid;
14082:23): push(@items,'add');
14083:23): $changes{$newid} = 1;
1(raebur 14084:1): } else {
14(raebu 14085:23): my $error = &mt('Failed to acquire unique ID for new LTI configuration');
18(raebu 14086:24): if ($errormsg) {
14087:24): $error .= ' ('.$errormsg.')';
14088:24): }
1(raebur 14089:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14090:1): }
14091:1): }
14092:1): if (ref($domconfig{$action}) eq 'HASH') {
14(raebu 14093:23): my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
1(raebur 14094:1): if (@todelete) {
14095:1): map { $deletions{$_} = 1; } @todelete;
14096:1): }
14(raebu 14097:23): my $maxnum = $env{'form.lti_maxnum'};
14098:23): for (my $i=0; $i<$maxnum; $i++) {
14099:23): my $itemid = $env{'form.lti_id_'.$i};
1(raebur 14100:1): $itemid =~ s/\D+//g;
14101:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14102:1): if ($deletions{$itemid}) {
14(raebu 14103:23): $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
1(raebur 14104:1): } else {
14(raebu 14105:23): push(@items,$i);
14106:23): $itemids{$i} = $itemid;
14107:23): }
14108:23): }
14109:23): }
14110:23): }
14111:23): my (%keystore,$secstored);
14112:23): if ($is_home) {
14113:23): &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
14114:23): }
14115:23):
14116:23): my ($cipher,$privnum);
14117:23): if ((@items > 0) && ($is_home)) {
14118:23): ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
14119:23): $newltisec{'encrypt'},$keystore{$home});
14120:23): }
14121:23): foreach my $idx (@items) {
14122:23): my $itemid = $itemids{$idx};
14123:23): next unless ($itemid);
14124:23): my %currlti;
14125:23): unless ($idx eq 'add') {
14126:23): if (ref($domconfig{$action}) eq 'HASH') {
14127:23): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14128:23): %currlti = %{$domconfig{$action}{$itemid}};
14129:23): }
14130:23): }
14131:23): }
14132:23): my $position = $env{'form.lti_pos_'.$itemid};
14133:23): $position =~ s/\D+//g;
14134:23): if ($position ne '') {
14135:23): $allpos[$position] = $itemid;
14136:23): }
14137:23): foreach my $item ('consumer','lifetime','requser','crsinc') {
14138:23): my $formitem = 'form.lti_'.$item.'_'.$idx;
14139:23): $env{$formitem} =~ s/(`)/'/g;
14140:23): if ($item eq 'lifetime') {
14141:23): $env{$formitem} =~ s/[^\d.]//g;
14142:23): }
14143:23): if ($env{$formitem} ne '') {
14144:23): $confhash{$itemid}{$item} = $env{$formitem};
14145:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14146:23): if ($currlti{$item} ne $confhash{$itemid}{$item}) {
14147:23): $changes{$itemid} = 1;
14148:23): }
14149:23): }
14150:23): }
14151:23): }
14152:23): if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14153:23): $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14154:23): }
14155:23): if ($confhash{$itemid}{'requser'}) {
14156:23): if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14157:23): $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14158:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14159:23): $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14160:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14161:23): my $mapuser = $env{'form.lti_customuser_'.$idx};
14162:23): $mapuser =~ s/(`)/'/g;
14163:23): $mapuser =~ s/^\s+|\s+$//g;
14164:23): $confhash{$itemid}{'mapuser'} = $mapuser;
14165:23): }
14166:23): my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14167:23): my @makeuser;
14168:23): foreach my $ltirole (sort(@possmakeuser)) {
14169:23): if ($posslti{$ltirole}) {
14170:23): push(@makeuser,$ltirole);
14171:23): }
14172:23): }
14173:23): $confhash{$itemid}{'makeuser'} = \@makeuser;
14174:23): if (@makeuser) {
14175:23): my $lcauth = $env{'form.lti_lcauth_'.$idx};
14176:23): if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14177:23): $confhash{$itemid}{'lcauth'} = $lcauth;
14178:23): if ($lcauth ne 'internal') {
14179:23): my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14180:23): $lcauthparm =~ s/^(\s+|\s+)$//g;
14181:23): $lcauthparm =~ s/`//g;
14182:23): if ($lcauthparm ne '') {
14183:23): $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
1(raebur 14184:1): }
14185:1): }
14(raebu 14186:23): } else {
14187:23): $confhash{$itemid}{'lcauth'} = 'lti';
14188:23): }
14189:23): }
14190:23): my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14191:23): if (@possinstdata) {
14192:23): foreach my $field (@possinstdata) {
14193:23): if (exists($fieldtitles{$field})) {
14194:23): push(@{$confhash{$itemid}{'instdata'}});
14195:23): }
14196:23): }
14197:23): }
14198:23): if ($env{'form.lti_callback_'.$idx}) {
14199:23): if ($env{'form.lti_callbackparam_'.$idx}) {
14200:23): my $callback = $env{'form.lti_callbackparam_'.$idx};
14201:23): $callback =~ s/^\s+|\s+$//g;
14202:23): $confhash{$itemid}{'callback'} = $callback;
14203:23): }
14204:23): }
14205:23): foreach my $field ('topmenu','inlinemenu') {
14206:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14207:23): $confhash{$itemid}{$field} = 1;
14208:23): }
14209:23): }
14210:23): if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14211:23): $confhash{$itemid}{lcmenu} = [];
14212:23): my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14213:23): foreach my $field (@possmenu) {
14214:23): if (exists($menutitles{$field})) {
14215:23): if ($field eq 'grades') {
14216:23): next unless ($env{'form.lti_inlinemenu_'.$idx});
1(raebur 14217:1): }
14(raebu 14218:23): push(@{$confhash{$itemid}{lcmenu}},$field);
14219:23): }
14220:23): }
14221:23): }
14222:23): if ($confhash{$itemid}{'crsinc'}) {
14223:23): if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14224:23): ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14225:23): $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14226:23): } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14227:23): my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14228:23): $mapcrs =~ s/(`)/'/g;
14229:23): $mapcrs =~ s/^\s+|\s+$//g;
14230:23): $confhash{$itemid}{'mapcrs'} = $mapcrs;
14231:23): }
14232:23): my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14233:23): my @crstypes;
14234:23): foreach my $type (sort(@posstypes)) {
14235:23): if ($posscrstype{$type}) {
14236:23): push(@crstypes,$type);
14237:23): }
14238:23): }
14239:23): $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14240:23): if ($env{'form.lti_storecrs_'.$idx}) {
14241:23): $confhash{$itemid}{'storecrs'} = 1;
14242:23): }
14243:23): if ($env{'form.lti_makecrs_'.$idx}) {
14244:23): $confhash{$itemid}{'makecrs'} = 1;
14245:23): }
14246:23): foreach my $ltirole (@lticourseroles) {
14247:23): my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14248:23): if (grep(/^\Q$possrole\E$/,@courseroles)) {
14249:23): $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
1(raebur 14250:1): }
14(raebu 14251:23): }
14252:23): my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14253:23): my @selfenroll;
14254:23): foreach my $type (sort(@possenroll)) {
14255:23): if ($posslticrs{$type}) {
14256:23): push(@selfenroll,$type);
14257:23): }
14258:23): }
14259:23): $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14260:23): if ($env{'form.lti_crssec_'.$idx}) {
14261:23): if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14262:23): $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14263:23): } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14264:23): my $section = $env{'form.lti_customsection_'.$idx};
14265:23): $section =~ s/(`)/'/g;
14266:23): $section =~ s/^\s+|\s+$//g;
14267:23): if ($section ne '') {
14268:23): $confhash{$itemid}{'section'} = $section;
14269:23): }
1(raebur 14270:1): }
14(raebu 14271:23): }
14272:23): foreach my $field ('passback','roster') {
14273:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14274:23): $confhash{$itemid}{$field} = 1;
1(raebur 14275:1): }
14(raebu 14276:23): }
14277:23): if ($env{'form.lti_passback_'.$idx}) {
14278:23): if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14279:23): $confhash{$itemid}{'passbackformat'} = '1.0';
1(raebur 14280:1): } else {
14(raebu 14281:23): $confhash{$itemid}{'passbackformat'} = '1.1';
1(raebur 14282:1): }
14(raebu 14283:23): }
14284:23): }
14285:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14286:23): if ($confhash{$itemid}{'crsinc'}) {
14287:23): foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
14288:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1(raebur 14289:1): $changes{$itemid} = 1;
14290:1): }
14291:1): }
14(raebu 14292:23): unless ($changes{$itemid}) {
14293:23): if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
14294:23): if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1(raebur 14295:1): $changes{$itemid} = 1;
14296:1): }
14297:1): }
14298:1): }
14(raebu 14299:23): foreach my $field ('mapcrstype','selfenroll') {
14300:23): unless ($changes{$itemid}) {
14301:23): if (ref($currlti{$field}) eq 'ARRAY') {
14302:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14303:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14304:23): $confhash{$itemid}{$field});
14305:23): if (@diffs) {
14306:23): $changes{$itemid} = 1;
14307:23): }
14308:23): } elsif (@{$currlti{$field}} > 0) {
1(raebur 14309:1): $changes{$itemid} = 1;
14310:1): }
14(raebu 14311:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14312:23): if (@{$confhash{$itemid}{$field}} > 0) {
1(raebur 14313:1): $changes{$itemid} = 1;
14314:1): }
14315:1): }
14316:1): }
14317:1): }
14(raebu 14318:23): unless ($changes{$itemid}) {
14319:23): if (ref($currlti{'maproles'}) eq 'HASH') {
14320:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14321:23): foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
14322:23): if ($currlti{'maproles'}{$ltirole} ne
14323:23): $confhash{$itemid}{'maproles'}{$ltirole}) {
14324:23): $changes{$itemid} = 1;
14325:23): last;
1(raebur 14326:1): }
14(raebu 14327:23): }
14328:23): unless ($changes{$itemid}) {
14329:23): foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14330:23): if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14331:23): $currlti{'maproles'}{$ltirole}) {
1(raebur 14332:1): $changes{$itemid} = 1;
14(raebu 14333:23): last;
1(raebur 14334:1): }
14335:1): }
14336:1): }
14(raebu 14337:23): } elsif (keys(%{$currlti{'maproles'}}) > 0) {
14338:23): $changes{$itemid} = 1;
14339:23): }
14340:23): } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14341:23): unless ($changes{$itemid}) {
14342:23): if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
1(raebur 14343:1): $changes{$itemid} = 1;
14344:1): }
14345:1): }
14346:1): }
14347:1): }
14(raebu 14348:23): }
14349:23): unless ($changes{$itemid}) {
14350:23): foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
14351:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
14352:23): $changes{$itemid} = 1;
14353:23): }
14354:23): }
14355:23): unless ($changes{$itemid}) {
14356:23): foreach my $field ('makeuser','lcmenu') {
14357:23): if (ref($currlti{$field}) eq 'ARRAY') {
14358:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14359:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14360:23): $confhash{$itemid}{$field});
14361:23): if (@diffs) {
14362:23): $changes{$itemid} = 1;
14363:23): }
14364:23): } elsif (@{$currlti{$field}} > 0) {
14365:23): $changes{$itemid} = 1;
14366:23): }
14367:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14368:23): if (@{$confhash{$itemid}{$field}} > 0) {
14369:23): $changes{$itemid} = 1;
14370:23): }
1(raebur 14371:1): }
14372:1): }
14373:1): }
14374:1): }
14(raebu 14375:23): }
14376:23): }
14377:23): if ($is_home) {
14378:23): my $keyitem = 'form.lti_key_'.$idx;
14379:23): $env{$keyitem} =~ s/(`)/'/g;
14380:23): if ($env{$keyitem} ne '') {
14381:23): $ltienc{$itemid}{'key'} = $env{$keyitem};
14382:23): unless ($changes{$itemid}) {
14383:23): if ($currlti{'key'} ne $env{$keyitem}) {
1(raebur 14384:1): $changes{$itemid} = 1;
14385:1): }
14(raebu 14386:23): }
14387:23): }
14388:23): my $secretitem = 'form.lti_secret_'.$idx;
14389:23): $env{$secretitem} =~ s/(`)/'/g;
14390:23): if ($currlti{'usable'}) {
14391:23): if ($env{'form.lti_changesecret_'.$idx}) {
14392:23): if ($env{$secretitem} ne '') {
14393:23): if ($privnum && $cipher) {
14394:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14395:23): $confhash{$itemid}{'cipher'} = $privnum;
14396:23): } else {
14397:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14398:23): }
1(raebur 14399:1): $changes{$itemid} = 1;
14400:1): }
14(raebu 14401:23): } else {
14402:23): $ltienc{$itemid}{'secret'} = $currlti{'secret'};
14403:23): $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
1(raebur 14404:1): }
14(raebu 14405:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14406:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
14407:23): $confhash{$itemid}{'usable'} = 1;
14408:23): }
1(raebur 14409:1): }
14(raebu 14410:23): } elsif ($env{$secretitem} ne '') {
14411:23): if ($privnum && $cipher) {
14412:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14413:23): $confhash{$itemid}{'cipher'} = $privnum;
14414:23): } else {
14415:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14416:23): }
14417:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14418:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
14419:23): $confhash{$itemid}{'usable'} = 1;
1(raebur 14420:1): }
14421:1): }
14(raebu 14422:23): $changes{$itemid} = 1;
14423:23): }
14424:23): }
14425:23): unless ($changes{$itemid}) {
14426:23): foreach my $key (keys(%currlti)) {
14427:23): if (ref($currlti{$key}) eq 'HASH') {
14428:23): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
14429:23): foreach my $innerkey (keys(%{$currlti{$key}})) {
14430:23): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
1(raebur 14431:1): $changes{$itemid} = 1;
14(raebu 14432:23): last;
1(raebur 14433:1): }
14434:1): }
14(raebu 14435:23): } elsif (keys(%{$currlti{$key}}) > 0) {
14436:23): $changes{$itemid} = 1;
1(raebur 14437:1): }
14438:1): }
14(raebu 14439:23): last if ($changes{$itemid});
1(raebur 14440:1): }
14441:1): }
14442:1): }
14443:1): if (@allpos > 0) {
14444:1): my $idx = 0;
14445:1): foreach my $itemid (@allpos) {
14446:1): if ($itemid ne '') {
14447:1): $confhash{$itemid}{'order'} = $idx;
14448:1): if (ref($domconfig{$action}) eq 'HASH') {
14449:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14450:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14451:1): $changes{$itemid} = 1;
14452:1): }
14453:1): }
14454:1): }
14455:1): $idx ++;
14456:1): }
14457:1): }
14458:1): }
14(raebu 14459:23):
14460:23): if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
14461:23): return &mt('No changes made.');
14462:23): }
14463:23):
14464:23): my %ltihash = (
14465:23): $action => { %confhash }
14466:23): );
14467:23): my %ltienchash;
14468:23):
14469:23): if ($is_home) {
14470:23): %ltienchash = (
14471:23): $action => { %ltienc }
14472:23): );
14473:23): }
14474:23): if (keys(%secchanges)) {
14475:23): $ltihash{'ltisec'} = \%newltisec;
14476:23): if ($secchanges{'linkprot'}) {
14477:23): if ($is_home) {
14478:23): $ltienchash{'linkprot'} = \%newltienc;
14479:23): }
14480:23): }
14481:23): }
14482:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1(raebur 14483:1): if ($putresult eq 'ok') {
14(raebu 14484:23): if (keys(%ltienchash)) {
14485:23): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
14486:23): }
14487:23): $resulttext = &mt('Changes made:').'<ul>';
14488:23): if (keys(%secchanges) > 0) {
14489:23): $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
14490:23): if (exists($secchanges{'linkprot'})) {
14491:23): $resulttext .= $linkprotoutput;
14492:23): }
14493:23): }
1(raebur 14494:1): if (keys(%changes) > 0) {
14495:1): my $cachetime = 24*60*60;
14(raebu 14496:23): &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1(raebur 14497:1): if (ref($lastactref) eq 'HASH') {
14(raebu 14498:23): $lastactref->{'lti'} = 1;
1(raebur 14499:1): }
14500:1): my %bynum;
14501:1): foreach my $itemid (sort(keys(%changes))) {
14(raebu 14502:23): if (ref($confhash{$itemid}) eq 'HASH') {
14503:23): my $position = $confhash{$itemid}{'order'};
14504:23): $bynum{$position} = $itemid;
14505:23): }
1(raebur 14506:1): }
14507:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14508:1): my $itemid = $bynum{$pos};
14(raebu 14509:23): if (ref($confhash{$itemid}) eq 'HASH') {
14510:23): $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1(raebur 14511:1): my $position = $pos + 1;
14512:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14(raebu 14513:23): foreach my $item ('version','lifetime') {
1(raebur 14514:1): if ($confhash{$itemid}{$item} ne '') {
14515:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14516:1): }
14517:1): }
14(raebu 14518:23): if ($ltienc{$itemid}{'key'} ne '') {
14519:23): $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
14520:23): }
14521:23): if ($ltienc{$itemid}{'secret'} ne '') {
14522:23): $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1(raebur 14523:1): }
14(raebu 14524:23): if ($confhash{$itemid}{'requser'}) {
14525:23): if ($confhash{$itemid}{'callback'}) {
14526:23): $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14527:23): } else {
14528:23): $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
14529:23): }
14530:23): if ($confhash{$itemid}{'mapuser'}) {
14531:23): my $shownmapuser;
14532:23): if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14533:23): $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14534:23): } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14535:23): $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14536:23): } else {
14537:23): $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
14538:23): }
14539:23): $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
14540:23): }
14541:23): if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14542:23): if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14543:23): $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14544:23): join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14545:23): if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14546:23): $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14547:23): } else {
14548:23): $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14549:23): $confhash{$itemid}{'lcauth'});
14550:23): if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14551:23): $resulttext .= '; '.&mt('a randomly generated password will be created');
14552:23): } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14553:23): if ($confhash{$itemid}{'lcauthparm'} ne '') {
14554:23): $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14555:23): }
14556:23): } else {
14557:23): $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14558:23): }
14559:23): }
14560:23): $resulttext .= '</li>';
14561:23): } else {
14562:23): $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
1(raebur 14563:1): }
14564:1): }
14(raebu 14565:23): if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14566:23): if (@{$confhash{$itemid}{'instdata'}} > 0) {
14567:23): $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14568:23): join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
14569:23): } else {
14570:23): $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1(raebur 14571:1): }
14572:1): }
14(raebu 14573:23): foreach my $item ('topmenu','inlinemenu') {
14574:23): $resulttext .= '<li>'.$lt{$item}.': ';
14575:23): if ($confhash{$itemid}{$item}) {
14576:23): $resulttext .= &mt('Yes');
14577:23): } else {
14578:23): $resulttext .= &mt('No');
1(raebur 14579:1): }
14(raebu 14580:23): $resulttext .= '</li>';
1(raebur 14581:1): }
14(raebu 14582:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14583:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14584:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14585:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14586:23): } else {
14587:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
1(raebur 14588:1): }
14589:1): }
14(raebu 14590:23): if ($confhash{$itemid}{'crsinc'}) {
14591:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14592:23): my $rolemaps;
14593:23): foreach my $role (@ltiroles) {
14594:23): if ($confhash{$itemid}{'maproles'}{$role}) {
14595:23): $rolemaps .= (' 'x2).$role.'='.
14596:23): &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14597:23): 'Course').',';
14598:23): }
14599:23): }
14600:23): if ($rolemaps) {
14601:23): $rolemaps =~ s/,$//;
14602:23): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14603:23): }
14604:23): }
14605:23): if ($confhash{$itemid}{'mapcrs'}) {
14606:23): $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14607:23): }
14608:23): if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14609:23): if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14610:23): $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14611:23): join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14612:23): '</li>';
1(raebur 14613:1): } else {
14(raebu 14614:23): $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
1(raebur 14615:1): }
14616:1): }
14(raebu 14617:23): if ($confhash{$itemid}{'storecrs'}) {
14618:23): $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
1(raebur 14619:1): }
14(raebu 14620:23): if ($confhash{$itemid}{'makecrs'}) {
14621:23): $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
14622:23): } else {
14623:23): $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
14624:23): }
14625:23): if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14626:23): if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14627:23): $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14628:23): join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14629:23): '</li>';
14630:23): } else {
14631:23): $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14632:23): }
14633:23): }
14634:23): if ($confhash{$itemid}{'section'}) {
14635:23): if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14636:23): $resulttext .= '<li>'.&mt('User section from standard field:').
14637:23): ' (course_section_sourcedid)'.'</li>';
14638:23): } else {
14639:23): $resulttext .= '<li>'.&mt('User section from:').' '.
14640:23): $confhash{$itemid}{'section'}.'</li>';
14641:23): }
14642:23): } else {
14643:23): $resulttext .= '<li>'.&mt('No section assignment').'</li>';
14644:23): }
14645:23): foreach my $item ('passback','roster','topmenu','inlinemenu') {
14646:23): $resulttext .= '<li>'.$lt{$item}.': ';
14647:23): if ($confhash{$itemid}{$item}) {
14648:23): $resulttext .= &mt('Yes');
14649:23): if ($item eq 'passback') {
14650:23): if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14651:23): $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14652:23): } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14653:23): $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14654:23): }
14655:23): }
14656:23): } else {
14657:23): $resulttext .= &mt('No');
14658:23): }
14659:23): $resulttext .= '</li>';
14660:23): }
14661:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14662:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14663:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14664:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14665:23): } else {
14666:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14667:23): }
1(raebur 14668:1): }
14669:1): }
14670:1): }
14671:1): $resulttext .= '</ul></li>';
14672:1): }
14673:1): }
14(raebu 14674:23): if (keys(%deletions)) {
14675:23): foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
14676:23): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14677:23): }
14678:23): }
14679:23): }
14680:23): $resulttext .= '</ul>';
14681:23): if (ref($lastactref) eq 'HASH') {
18(raebu 14682:24): if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
14683:24): &Apache::lonnet::get_domain_defaults($dom,1);
14(raebu 14684:23): $lastactref->{'domdefaults'} = 1;
14685:23): }
1(raebur 14686:1): }
14687:1): } else {
14688:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14689:1): }
14690:1): if ($errors) {
14691:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14692:1): $errors.'</ul>';
14693:1): }
14694:1): return $resulttext;
14695:1): }
14696:1):
14(raebu 14697:23): sub get_priv_creds {
14698:23): my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
14699:23): my ($needenc,$cipher,$privnum);
14700:23): my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
14701:23): if (($encchg) && (ref($encrypt) eq 'HASH')) {
14702:23): $needenc = $encrypt->{'consumers'}
14703:23): } else {
14704:23): $needenc = $domdefs{'ltienc_consumers'};
14705:23): }
14706:23): if ($needenc) {
14707:23): if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
14708:23): (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
14709:23): my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
14710:23): my $privkey = $privhash{'key'};
14711:23): $privnum = $privhash{'version'};
14712:23): if (($privnum) && ($privkey ne '')) {
14713:23): $cipher = Crypt::CBC->new({'key' => $privkey,
14714:23): 'cipher' => 'DES'});
1(raebur 14715:1): }
14716:1): }
14717:1): }
14(raebu 14718:23): return ($cipher,$privnum);
1(raebur 14719:1): }
14720:1):
14(raebu 14721:23): sub get_lti_id {
18(raebu 14722:24): my ($domain,$consumer,$dbname) = @_;
14723:24): unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
14724:24): return ('','invalid db');
14725:24): }
14726:24): # get lock on db
1(raebur 14727:1): my $lockhash = {
14728:1): lock => $env{'user.name'}.
14729:1): ':'.$env{'user.domain'},
14730:1): };
14731:1): my $tries = 0;
18(raebu 14732:24): my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14733:1): my ($id,$error);
14734:1):
14735:1): while (($gotlock ne 'ok') && ($tries<10)) {
14736:1): $tries ++;
14737:1): sleep (0.1);
18(raebu 14738:24): $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14739:1): }
14740:1): if ($gotlock eq 'ok') {
18(raebu 14741:24): my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1(raebur 14742:1): if ($currids{'lock'}) {
14743:1): delete($currids{'lock'});
14744:1): if (keys(%currids)) {
14745:1): my @curr = sort { $a <=> $b } keys(%currids);
14746:1): if ($curr[-1] =~ /^\d+$/) {
14747:1): $id = 1 + $curr[-1];
14748:1): }
14749:1): } else {
14750:1): $id = 1;
14751:1): }
14752:1): if ($id) {
18(raebu 14753:24): unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1(raebur 14754:1): $error = 'nostore';
14755:1): }
14756:1): } else {
14757:1): $error = 'nonumber';
14758:1): }
14759:1): }
18(raebu 14760:24): my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1(raebur 14761:1): } else {
14762:1): $error = 'nolock';
14763:1): }
14764:1): return ($id,$error);
14765:1): }
14766:1):
1.3 raeburn 14767: sub modify_autoenroll {
1.160.6.24 raeburn 14768: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14769: my ($resulttext,%changes);
14770: my %currautoenroll;
14771: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14772: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14773: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14774: }
14775: }
14776: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14777: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14778: sender => 'Sender for notification messages',
1.160.6.68 raeburn 14779: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 14780: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14781: my @offon = ('off','on');
1.17 raeburn 14782: my $sender_uname = $env{'form.sender_uname'};
14783: my $sender_domain = $env{'form.sender_domain'};
14784: if ($sender_domain eq '') {
14785: $sender_uname = '';
14786: } elsif ($sender_uname eq '') {
14787: $sender_domain = '';
14788: }
1.129 raeburn 14789: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 14790: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14791: $autofailsafe =~ s{^\s+|\s+$}{}g;
14792: if ($autofailsafe =~ /\D/) {
14793: undef($autofailsafe);
14794: }
1.160.6.68 raeburn 14795: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 14796: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14797: $failsafe = 'off';
14798: undef($autofailsafe);
1.160.6.68 raeburn 14799: }
1.1 raeburn 14800: my %autoenrollhash = (
1.129 raeburn 14801: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14802: 'sender_uname' => $sender_uname,
14803: 'sender_domain' => $sender_domain,
14804: 'co-owners' => $coowners,
1.160.6.116 raeburn 14805: 'autofailsafe' => $autofailsafe,
14806: 'failsafe' => $failsafe,
1.1 raeburn 14807: }
14808: );
1.4 raeburn 14809: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14810: $dom);
1.1 raeburn 14811: if ($putresult eq 'ok') {
14812: if (exists($currautoenroll{'run'})) {
14813: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14814: $changes{'run'} = 1;
14815: }
14816: } elsif ($autorun) {
14817: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14818: $changes{'run'} = 1;
1.1 raeburn 14819: }
14820: }
1.17 raeburn 14821: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14822: $changes{'sender'} = 1;
14823: }
1.17 raeburn 14824: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14825: $changes{'sender'} = 1;
14826: }
1.129 raeburn 14827: if ($currautoenroll{'co-owners'} ne '') {
14828: if ($currautoenroll{'co-owners'} ne $coowners) {
14829: $changes{'coowners'} = 1;
14830: }
14831: } elsif ($coowners) {
14832: $changes{'coowners'} = 1;
1.160.6.68 raeburn 14833: }
1.160.6.116 raeburn 14834: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 14835: $changes{'autofailsafe'} = 1;
14836: }
1.160.6.116 raeburn 14837: if ($currautoenroll{'failsafe'} ne $failsafe) {
14838: $changes{'failsafe'} = 1;
14839: }
1.1 raeburn 14840: if (keys(%changes) > 0) {
14841: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14842: if ($changes{'run'}) {
1.1 raeburn 14843: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14844: }
14845: if ($changes{'sender'}) {
1.17 raeburn 14846: if ($sender_uname eq '' || $sender_domain eq '') {
14847: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14848: } else {
14849: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14850: }
1.1 raeburn 14851: }
1.129 raeburn 14852: if ($changes{'coowners'}) {
14853: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14854: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14855: if (ref($lastactref) eq 'HASH') {
14856: $lastactref->{'domainconfig'} = 1;
14857: }
1.129 raeburn 14858: }
1.160.6.68 raeburn 14859: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 14860: if ($autofailsafe ne '') {
14861: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 14862: } else {
1.160.6.116 raeburn 14863: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 14864: }
1.160.6.116 raeburn 14865: }
14866: if ($changes{'failsafe'}) {
14867: if ($failsafe eq 'off') {
14868: unless ($changes{'autofailsafe'}) {
14869: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14870: }
14871: } elsif ($failsafe eq 'zero') {
14872: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14873: } else {
14874: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14875: }
14876: }
14877: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 14878: &Apache::lonnet::get_domain_defaults($dom,1);
14879: if (ref($lastactref) eq 'HASH') {
14880: $lastactref->{'domdefaults'} = 1;
14881: }
14882: }
1.1 raeburn 14883: $resulttext .= '</ul>';
14884: } else {
14885: $resulttext = &mt('No changes made to auto-enrollment settings');
14886: }
14887: } else {
1.11 albertel 14888: $resulttext = '<span class="LC_error">'.
14889: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14890: }
1.3 raeburn 14891: return $resulttext;
1.1 raeburn 14892: }
14893:
14894: sub modify_autoupdate {
1.3 raeburn 14895: my ($dom,%domconfig) = @_;
1.1 raeburn 14896: my ($resulttext,%currautoupdate,%fields,%changes);
14897: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14898: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14899: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14900: }
14901: }
14902: my @offon = ('off','on');
14903: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 14904: run => 'Auto-update:',
14905: classlists => 'Updates to user information in classlists?',
14906: unexpired => 'Skip updates for users without active or future roles?',
14907: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 14908: );
1.44 raeburn 14909: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14910: my %fieldtitles = &Apache::lonlocal::texthash (
14911: id => 'Student/Employee ID',
1.20 raeburn 14912: permanentemail => 'E-mail address',
1.1 raeburn 14913: lastname => 'Last Name',
14914: firstname => 'First Name',
14915: middlename => 'Middle Name',
1.132 raeburn 14916: generation => 'Generation',
1.1 raeburn 14917: );
1.142 raeburn 14918: $othertitle = &mt('All users');
1.1 raeburn 14919: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14920: $othertitle = &mt('Other users');
1.1 raeburn 14921: }
14922: foreach my $key (keys(%env)) {
14923: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14924: my ($usertype,$item) = ($1,$2);
14925: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14926: if ($usertype eq 'default') {
14927: push(@{$fields{$1}},$2);
14928: } elsif (ref($types) eq 'ARRAY') {
14929: if (grep(/^\Q$usertype\E$/,@{$types})) {
14930: push(@{$fields{$1}},$2);
14931: }
14932: }
14933: }
1.1 raeburn 14934: }
14935: }
1.131 raeburn 14936: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14937: @lockablenames = sort(@lockablenames);
14938: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14939: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14940: if (@changed) {
14941: $changes{'lockablenames'} = 1;
14942: }
14943: } else {
14944: if (@lockablenames) {
14945: $changes{'lockablenames'} = 1;
14946: }
14947: }
1.1 raeburn 14948: my %updatehash = (
14949: autoupdate => { run => $env{'form.autoupdate_run'},
14950: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 14951: unexpired => $env{'form.unexpired'},
1.1 raeburn 14952: fields => {%fields},
1.131 raeburn 14953: lockablenames => \@lockablenames,
1.1 raeburn 14954: }
14955: );
1.160.6.113 raeburn 14956: my $lastactivedays;
14957: if ($env{'form.lastactive'}) {
14958: $lastactivedays = $env{'form.lastactivedays'};
14959: $lastactivedays =~ s/^\s+|\s+$//g;
14960: unless ($lastactivedays =~ /^\d+$/) {
14961: undef($lastactivedays);
14962: $env{'form.lastactive'} = 0;
14963: }
14964: }
14965: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 14966: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 14967: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 14968: if (exists($updatehash{autoupdate}{$key})) {
14969: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14970: $changes{$key} = 1;
14971: }
14972: }
14973: } elsif ($key eq 'fields') {
14974: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14975: foreach my $item (@{$types},'default') {
1.1 raeburn 14976: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14977: my $change = 0;
14978: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14979: if (!exists($fields{$item})) {
14980: $change = 1;
1.132 raeburn 14981: last;
1.1 raeburn 14982: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14983: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14984: $change = 1;
1.132 raeburn 14985: last;
1.1 raeburn 14986: }
14987: }
14988: }
14989: if ($change) {
14990: push(@{$changes{$key}},$item);
14991: }
1.26 raeburn 14992: }
1.1 raeburn 14993: }
14994: }
1.131 raeburn 14995: } elsif ($key eq 'lockablenames') {
14996: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14997: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14998: if (@changed) {
14999: $changes{'lockablenames'} = 1;
15000: }
15001: } else {
15002: if (@lockablenames) {
15003: $changes{'lockablenames'} = 1;
15004: }
15005: }
15006: }
15007: }
15008: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15009: if (@lockablenames) {
15010: $changes{'lockablenames'} = 1;
1.1 raeburn 15011: }
15012: }
1.160.6.113 raeburn 15013: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15014: if ($updatehash{'autoupdate'}{'unexpired'}) {
15015: $changes{'unexpired'} = 1;
15016: }
15017: }
15018: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15019: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15020: $changes{'lastactive'} = 1;
15021: }
15022: }
1.26 raeburn 15023: foreach my $item (@{$types},'default') {
15024: if (defined($fields{$item})) {
15025: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15026: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15027: my $change = 0;
15028: if (ref($fields{$item}) eq 'ARRAY') {
15029: foreach my $type (@{$fields{$item}}) {
15030: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15031: $change = 1;
15032: last;
15033: }
15034: }
15035: }
15036: if ($change) {
15037: push(@{$changes{'fields'}},$item);
15038: }
15039: } else {
1.26 raeburn 15040: push(@{$changes{'fields'}},$item);
15041: }
15042: } else {
15043: push(@{$changes{'fields'}},$item);
1.1 raeburn 15044: }
15045: }
15046: }
15047: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15048: $dom);
15049: if ($putresult eq 'ok') {
15050: if (keys(%changes) > 0) {
15051: $resulttext = &mt('Changes made:').'<ul>';
15052: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15053: if ($key eq 'lockablenames') {
15054: $resulttext .= '<li>';
15055: if (@lockablenames) {
15056: $usertypes->{'default'} = $othertitle;
15057: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15058: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15059: } else {
15060: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15061: }
15062: $resulttext .= '</li>';
15063: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15064: foreach my $item (@{$changes{$key}}) {
15065: my @newvalues;
15066: foreach my $type (@{$fields{$item}}) {
15067: push(@newvalues,$fieldtitles{$type});
15068: }
1.3 raeburn 15069: my $newvaluestr;
15070: if (@newvalues > 0) {
15071: $newvaluestr = join(', ',@newvalues);
15072: } else {
15073: $newvaluestr = &mt('none');
1.6 raeburn 15074: }
1.1 raeburn 15075: if ($item eq 'default') {
1.26 raeburn 15076: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15077: } else {
1.26 raeburn 15078: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15079: }
15080: }
15081: } else {
15082: my $newvalue;
15083: if ($key eq 'run') {
15084: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 15085: } elsif ($key eq 'lastactive') {
15086: $newvalue = $offon[$env{'form.lastactive'}];
15087: unless ($lastactivedays eq '') {
15088: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15089: }
1.1 raeburn 15090: } else {
15091: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15092: }
1.1 raeburn 15093: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15094: }
15095: }
15096: $resulttext .= '</ul>';
15097: } else {
1.3 raeburn 15098: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15099: }
15100: } else {
1.11 albertel 15101: $resulttext = '<span class="LC_error">'.
15102: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15103: }
1.3 raeburn 15104: return $resulttext;
1.1 raeburn 15105: }
15106:
1.125 raeburn 15107: sub modify_autocreate {
15108: my ($dom,%domconfig) = @_;
15109: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15110: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15111: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15112: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15113: }
15114: }
15115: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15116: req => 'Auto-creation of validated requests for official courses',
15117: xmldc => 'Identity of course creator of courses from XML files',
15118: );
15119: my @types = ('xml','req');
15120: foreach my $item (@types) {
15121: $newvals{$item} = $env{'form.autocreate_'.$item};
15122: $newvals{$item} =~ s/\D//g;
15123: $newvals{$item} = 0 if ($newvals{$item} eq '');
15124: }
15125: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 15126: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15127: unless (exists($domcoords{$newvals{'xmldc'}})) {
15128: $newvals{'xmldc'} = '';
15129: }
15130: %autocreatehash = (
15131: autocreate => { xml => $newvals{'xml'},
15132: req => $newvals{'req'},
15133: }
15134: );
15135: if ($newvals{'xmldc'} ne '') {
15136: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15137: }
15138: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15139: $dom);
15140: if ($putresult eq 'ok') {
15141: my @items = @types;
15142: if ($newvals{'xml'}) {
15143: push(@items,'xmldc');
15144: }
15145: foreach my $item (@items) {
15146: if (exists($currautocreate{$item})) {
15147: if ($currautocreate{$item} ne $newvals{$item}) {
15148: $changes{$item} = 1;
15149: }
15150: } elsif ($newvals{$item}) {
15151: $changes{$item} = 1;
15152: }
15153: }
15154: if (keys(%changes) > 0) {
15155: my @offon = ('off','on');
15156: $resulttext = &mt('Changes made:').'<ul>';
15157: foreach my $item (@types) {
15158: if ($changes{$item}) {
15159: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 15160: $resulttext .= '<li>'.
15161: &mt("$title{$item} set to [_1]$newtxt [_2]",
15162: '<b>','</b>').
15163: '</li>';
1.125 raeburn 15164: }
15165: }
15166: if ($changes{'xmldc'}) {
15167: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15168: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 15169: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15170: }
15171: $resulttext .= '</ul>';
15172: } else {
15173: $resulttext = &mt('No changes made to auto-creation settings');
15174: }
15175: } else {
15176: $resulttext = '<span class="LC_error">'.
15177: &mt('An error occurred: [_1]',$putresult).'</span>';
15178: }
15179: return $resulttext;
15180: }
15181:
1.23 raeburn 15182: sub modify_directorysrch {
1.160.6.81 raeburn 15183: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15184: my ($resulttext,%changes);
15185: my %currdirsrch;
15186: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15187: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15188: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15189: }
15190: }
1.160.6.72 raeburn 15191: my %title = ( available => 'Institutional directory search available',
15192: localonly => 'Other domains can search institution',
15193: lcavailable => 'LON-CAPA directory search available',
15194: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15195: searchby => 'Search types',
15196: searchtypes => 'Search latitude');
15197: my @offon = ('off','on');
1.24 raeburn 15198: my @otherdoms = ('Yes','No');
1.23 raeburn 15199:
1.25 raeburn 15200: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15201: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15202: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15203:
1.44 raeburn 15204: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15205: if (keys(%{$usertypes}) == 0) {
15206: @cansearch = ('default');
15207: } else {
15208: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15209: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15210: if (!grep(/^\Q$type\E$/,@cansearch)) {
15211: push(@{$changes{'cansearch'}},$type);
15212: }
1.23 raeburn 15213: }
1.26 raeburn 15214: foreach my $type (@cansearch) {
15215: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15216: push(@{$changes{'cansearch'}},$type);
15217: }
1.23 raeburn 15218: }
1.26 raeburn 15219: } else {
15220: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15221: }
15222: }
15223:
15224: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15225: foreach my $by (@{$currdirsrch{'searchby'}}) {
15226: if (!grep(/^\Q$by\E$/,@searchby)) {
15227: push(@{$changes{'searchby'}},$by);
15228: }
15229: }
15230: foreach my $by (@searchby) {
15231: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15232: push(@{$changes{'searchby'}},$by);
15233: }
15234: }
15235: } else {
15236: push(@{$changes{'searchby'}},@searchby);
15237: }
1.25 raeburn 15238:
15239: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15240: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15241: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15242: push(@{$changes{'searchtypes'}},$type);
15243: }
15244: }
15245: foreach my $type (@searchtypes) {
15246: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15247: push(@{$changes{'searchtypes'}},$type);
15248: }
15249: }
15250: } else {
15251: if (exists($currdirsrch{'searchtypes'})) {
15252: foreach my $type (@searchtypes) {
15253: if ($type ne $currdirsrch{'searchtypes'}) {
15254: push(@{$changes{'searchtypes'}},$type);
15255: }
15256: }
15257: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15258: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15259: }
15260: } else {
15261: push(@{$changes{'searchtypes'}},@searchtypes);
15262: }
15263: }
15264:
1.23 raeburn 15265: my %dirsrch_hash = (
15266: directorysrch => { available => $env{'form.dirsrch_available'},
15267: cansearch => \@cansearch,
1.160.6.72 raeburn 15268: localonly => $env{'form.dirsrch_instlocalonly'},
15269: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15270: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15271: searchby => \@searchby,
1.25 raeburn 15272: searchtypes => \@searchtypes,
1.23 raeburn 15273: }
15274: );
15275: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15276: $dom);
15277: if ($putresult eq 'ok') {
15278: if (exists($currdirsrch{'available'})) {
15279: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15280: $changes{'available'} = 1;
15281: }
15282: } else {
15283: if ($env{'form.dirsrch_available'} eq '1') {
15284: $changes{'available'} = 1;
15285: }
15286: }
1.160.6.72 raeburn 15287: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 15288: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15289: $changes{'lcavailable'} = 1;
15290: }
1.24 raeburn 15291: } else {
1.160.6.72 raeburn 15292: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15293: $changes{'lcavailable'} = 1;
15294: }
15295: }
15296: if (exists($currdirsrch{'localonly'})) {
15297: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 15298: $changes{'localonly'} = 1;
15299: }
1.160.6.72 raeburn 15300: } else {
15301: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
15302: $changes{'localonly'} = 1;
15303: }
15304: }
15305: if (exists($currdirsrch{'lclocalonly'})) {
15306: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15307: $changes{'lclocalonly'} = 1;
15308: }
15309: } else {
15310: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15311: $changes{'lclocalonly'} = 1;
15312: }
1.24 raeburn 15313: }
1.23 raeburn 15314: if (keys(%changes) > 0) {
15315: $resulttext = &mt('Changes made:').'<ul>';
15316: if ($changes{'available'}) {
15317: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15318: }
1.160.6.72 raeburn 15319: if ($changes{'lcavailable'}) {
15320: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15321: }
1.24 raeburn 15322: if ($changes{'localonly'}) {
1.160.6.72 raeburn 15323: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
15324: }
15325: if ($changes{'lclocalonly'}) {
15326: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 15327: }
1.23 raeburn 15328: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15329: my $chgtext;
1.26 raeburn 15330: if (ref($usertypes) eq 'HASH') {
15331: if (keys(%{$usertypes}) > 0) {
15332: foreach my $type (@{$types}) {
15333: if (grep(/^\Q$type\E$/,@cansearch)) {
15334: $chgtext .= $usertypes->{$type}.'; ';
15335: }
15336: }
15337: if (grep(/^default$/,@cansearch)) {
15338: $chgtext .= $othertitle;
15339: } else {
15340: $chgtext =~ s/\; $//;
15341: }
1.160.6.13 raeburn 15342: $resulttext .=
15343: '<li>'.
15344: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15345: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15346: '</li>';
1.23 raeburn 15347: }
15348: }
15349: }
15350: if (ref($changes{'searchby'}) eq 'ARRAY') {
15351: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15352: my $chgtext;
15353: foreach my $type (@{$titleorder}) {
15354: if (grep(/^\Q$type\E$/,@searchby)) {
15355: if (defined($searchtitles->{$type})) {
15356: $chgtext .= $searchtitles->{$type}.'; ';
15357: }
15358: }
15359: }
15360: $chgtext =~ s/\; $//;
15361: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15362: }
1.25 raeburn 15363: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15364: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15365: my $chgtext;
15366: foreach my $type (@{$srchtypeorder}) {
15367: if (grep(/^\Q$type\E$/,@searchtypes)) {
15368: if (defined($srchtypes_desc->{$type})) {
15369: $chgtext .= $srchtypes_desc->{$type}.'; ';
15370: }
15371: }
15372: }
15373: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 15374: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15375: }
15376: $resulttext .= '</ul>';
1.160.6.81 raeburn 15377: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15378: if (ref($lastactref) eq 'HASH') {
15379: $lastactref->{'directorysrch'} = 1;
15380: }
1.23 raeburn 15381: } else {
1.160.6.72 raeburn 15382: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15383: }
15384: } else {
15385: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15386: &mt('An error occurred: [_1]',$putresult).'</span>';
15387: }
15388: return $resulttext;
15389: }
15390:
1.28 raeburn 15391: sub modify_contacts {
1.160.6.24 raeburn 15392: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15393: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15394: if (ref($domconfig{'contacts'}) eq 'HASH') {
15395: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15396: $currsetting{$key} = $domconfig{'contacts'}{$key};
15397: }
15398: }
1.160.6.78 raeburn 15399: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15400: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 15401: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 15402: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 15403: my @toggles = ('reporterrors','reportupdates','reportstatus');
15404: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 15405: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15406: foreach my $type (@mailings) {
15407: @{$newsetting{$type}} =
15408: &Apache::loncommon::get_env_multiple('form.'.$type);
15409: foreach my $item (@contacts) {
15410: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15411: $contacts_hash{contacts}{$type}{$item} = 1;
15412: } else {
15413: $contacts_hash{contacts}{$type}{$item} = 0;
15414: }
1.160.6.78 raeburn 15415: }
1.28 raeburn 15416: $others{$type} = $env{'form.'.$type.'_others'};
15417: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 15418: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15419: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15420: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 15421: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15422: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15423: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15424: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15425: }
1.134 raeburn 15426: }
1.28 raeburn 15427: }
15428: foreach my $item (@contacts) {
15429: $to{$item} = $env{'form.'.$item};
15430: $contacts_hash{'contacts'}{$item} = $to{$item};
15431: }
1.160.6.23 raeburn 15432: foreach my $item (@toggles) {
15433: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15434: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15435: }
15436: }
1.160.6.107 raeburn 15437: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15438: foreach my $item (@lonstatus) {
15439: if ($item eq 'excluded') {
15440: my (%serverhomes,@excluded);
15441: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15442: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15443: if (@possexcluded) {
15444: foreach my $id (sort(@possexcluded)) {
15445: if ($serverhomes{$id}) {
15446: push(@excluded,$id);
15447: }
15448: }
15449: }
15450: if (@excluded) {
15451: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15452: }
15453: } elsif ($item eq 'weights') {
15454: foreach my $type ('E','W','N','U') {
15455: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15456: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15457: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15458: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15459: $env{'form.error'.$item.'_'.$type};
15460: }
15461: }
15462: }
15463: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15464: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15465: if ($env{'form.error'.$item} =~ /^\d+$/) {
15466: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15467: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15468: }
15469: }
15470: }
15471: }
1.160.6.78 raeburn 15472: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15473: foreach my $field (@{$fields}) {
15474: if (ref($possoptions->{$field}) eq 'ARRAY') {
15475: my $value = $env{'form.helpform_'.$field};
15476: $value =~ s/^\s+|\s+$//g;
15477: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 15478: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 15479: if ($field eq 'screenshot') {
15480: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15481: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 15482: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 15483: }
15484: }
15485: }
15486: }
15487: }
15488: }
1.160.6.101 raeburn 15489: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15490: my (@statuses,%usertypeshash,@overrides);
15491: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15492: @statuses = @{$types};
15493: if (ref($usertypes) eq 'HASH') {
15494: %usertypeshash = %{$usertypes};
15495: }
15496: }
15497: if (@statuses) {
15498: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15499: foreach my $type (@possoverrides) {
15500: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15501: push(@overrides,$type);
15502: }
15503: }
15504: if (@overrides) {
15505: foreach my $type (@overrides) {
15506: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15507: foreach my $item (@contacts) {
15508: if (grep(/^\Q$item\E$/,@standard)) {
15509: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15510: $newsetting{'override_'.$type}{$item} = 1;
15511: } else {
15512: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15513: $newsetting{'override_'.$type}{$item} = 0;
15514: }
15515: }
15516: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15517: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15518: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15519: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15520: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15521: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15522: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15523: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15524: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15525: }
1.160.6.118.2 14(raebu 15526:23): }
1.160.6.101 raeburn 15527: }
15528: }
1.28 raeburn 15529: if (keys(%currsetting) > 0) {
15530: foreach my $item (@contacts) {
15531: if ($to{$item} ne $currsetting{$item}) {
15532: $changes{$item} = 1;
15533: }
15534: }
15535: foreach my $type (@mailings) {
15536: foreach my $item (@contacts) {
15537: if (ref($currsetting{$type}) eq 'HASH') {
15538: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15539: push(@{$changes{$type}},$item);
15540: }
15541: } else {
15542: push(@{$changes{$type}},@{$newsetting{$type}});
15543: }
15544: }
15545: if ($others{$type} ne $currsetting{$type}{'others'}) {
15546: push(@{$changes{$type}},'others');
15547: }
1.160.6.78 raeburn 15548: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15549: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15550: push(@{$changes{$type}},'bcc');
15551: }
1.160.6.78 raeburn 15552: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15553: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15554: push(@{$changes{$type}},'include');
15555: }
15556: }
15557: }
15558: if (ref($fields) eq 'ARRAY') {
15559: if (ref($currsetting{'helpform'}) eq 'HASH') {
15560: foreach my $field (@{$fields}) {
15561: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15562: push(@{$changes{'helpform'}},$field);
15563: }
15564: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15565: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15566: push(@{$changes{'helpform'}},'maxsize');
15567: }
15568: }
15569: }
15570: } else {
15571: foreach my $field (@{$fields}) {
15572: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15573: push(@{$changes{'helpform'}},$field);
15574: }
15575: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15576: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15577: push(@{$changes{'helpform'}},'maxsize');
15578: }
15579: }
15580: }
1.134 raeburn 15581: }
1.28 raeburn 15582: }
1.160.6.101 raeburn 15583: if (@statuses) {
15584: if (ref($currsetting{'overrides'}) eq 'HASH') {
15585: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15586: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15587: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15588: foreach my $item (@contacts,'bcc','others','include') {
15589: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15590: push(@{$changes{'overrides'}},$key);
15591: last;
15592: }
15593: }
15594: } else {
15595: push(@{$changes{'overrides'}},$key);
15596: }
15597: }
15598: }
15599: foreach my $key (@overrides) {
15600: unless (exists($currsetting{'overrides'}{$key})) {
15601: push(@{$changes{'overrides'}},$key);
15602: }
15603: }
15604: } else {
15605: foreach my $key (@overrides) {
15606: push(@{$changes{'overrides'}},$key);
15607: }
15608: }
15609: }
1.160.6.107 raeburn 15610: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15611: foreach my $key ('excluded','weights','threshold','sysmail') {
15612: if ($key eq 'excluded') {
15613: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15614: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15615: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15616: (@{$currsetting{'lonstatus'}{$key}})) {
15617: my @diffs =
15618: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15619: $currsetting{'lonstatus'}{$key});
15620: if (@diffs) {
15621: push(@{$changes{'lonstatus'}},$key);
15622: }
15623: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15624: push(@{$changes{'lonstatus'}},$key);
15625: }
15626: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15627: (@{$currsetting{'lonstatus'}{$key}})) {
15628: push(@{$changes{'lonstatus'}},$key);
15629: }
15630: } elsif ($key eq 'weights') {
15631: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15632: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15633: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15634: foreach my $type ('E','W','N','U') {
15635: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15636: $currsetting{'lonstatus'}{$key}{$type}) {
15637: push(@{$changes{'lonstatus'}},$key);
15638: last;
15639: }
15640: }
15641: } else {
15642: foreach my $type ('E','W','N','U') {
15643: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15644: push(@{$changes{'lonstatus'}},$key);
15645: last;
15646: }
15647: }
15648: }
15649: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15650: foreach my $type ('E','W','N','U') {
15651: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15652: push(@{$changes{'lonstatus'}},$key);
15653: last;
15654: }
15655: }
15656: }
15657: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15658: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15659: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15660: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15661: push(@{$changes{'lonstatus'}},$key);
15662: }
15663: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15664: push(@{$changes{'lonstatus'}},$key);
15665: }
15666: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15667: push(@{$changes{'lonstatus'}},$key);
15668: }
15669: }
15670: }
15671: } else {
15672: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15673: foreach my $key ('excluded','weights','threshold','sysmail') {
15674: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15675: push(@{$changes{'lonstatus'}},$key);
15676: }
15677: }
15678: }
15679: }
1.28 raeburn 15680: } else {
15681: my %default;
15682: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15683: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15684: $default{'errormail'} = 'adminemail';
15685: $default{'packagesmail'} = 'adminemail';
15686: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 15687: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15688: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15689: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 15690: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 15691: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15692: foreach my $item (@contacts) {
15693: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 15694: $changes{$item} = 1;
1.160.6.23 raeburn 15695: }
1.28 raeburn 15696: }
15697: foreach my $type (@mailings) {
15698: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15699: push(@{$changes{$type}},@{$newsetting{$type}});
15700: }
15701: if ($others{$type} ne '') {
15702: push(@{$changes{$type}},'others');
1.134 raeburn 15703: }
1.160.6.78 raeburn 15704: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15705: if ($bcc{$type} ne '') {
15706: push(@{$changes{$type}},'bcc');
15707: }
1.160.6.78 raeburn 15708: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15709: push(@{$changes{$type}},'include');
15710: }
15711: }
15712: }
15713: if (ref($fields) eq 'ARRAY') {
15714: foreach my $field (@{$fields}) {
15715: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15716: push(@{$changes{'helpform'}},$field);
15717: }
15718: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15719: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15720: push(@{$changes{'helpform'}},'maxsize');
15721: }
15722: }
1.134 raeburn 15723: }
1.28 raeburn 15724: }
1.160.6.107 raeburn 15725: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15726: foreach my $key ('excluded','weights','threshold','sysmail') {
15727: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15728: push(@{$changes{'lonstatus'}},$key);
15729: }
15730: }
15731: }
1.28 raeburn 15732: }
1.160.6.23 raeburn 15733: foreach my $item (@toggles) {
15734: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15735: $changes{$item} = 1;
15736: } elsif ((!$env{'form.'.$item}) &&
15737: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15738: $changes{$item} = 1;
15739: }
15740: }
1.28 raeburn 15741: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15742: $dom);
15743: if ($putresult eq 'ok') {
15744: if (keys(%changes) > 0) {
1.160.6.24 raeburn 15745: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 15746: if (ref($lastactref) eq 'HASH') {
15747: $lastactref->{'domainconfig'} = 1;
15748: }
1.28 raeburn 15749: my ($titles,$short_titles) = &contact_titles();
15750: $resulttext = &mt('Changes made:').'<ul>';
15751: foreach my $item (@contacts) {
15752: if ($changes{$item}) {
15753: $resulttext .= '<li>'.$titles->{$item}.
15754: &mt(' set to: ').
15755: '<span class="LC_cusr_emph">'.
15756: $to{$item}.'</span></li>';
15757: }
15758: }
15759: foreach my $type (@mailings) {
15760: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 15761: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15762: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15763: } else {
15764: $resulttext .= '<li>'.$titles->{$type}.': ';
15765: }
1.28 raeburn 15766: my @text;
15767: foreach my $item (@{$newsetting{$type}}) {
15768: push(@text,$short_titles->{$item});
15769: }
15770: if ($others{$type} ne '') {
15771: push(@text,$others{$type});
15772: }
1.160.6.78 raeburn 15773: if (@text) {
15774: $resulttext .= '<span class="LC_cusr_emph">'.
15775: join(', ',@text).'</span>';
15776: }
15777: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15778: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 15779: my $bcctext;
15780: if (@text) {
15781: $bcctext = ' '.&mt('with Bcc to');
15782: } else {
15783: $bcctext = '(Bcc)';
15784: }
15785: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15786: } elsif (!@text) {
15787: $resulttext .= &mt('No one');
1.134 raeburn 15788: }
1.160.6.78 raeburn 15789: if ($includestr{$type} ne '') {
15790: if ($includeloc{$type} eq 'b') {
15791: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15792: } elsif ($includeloc{$type} eq 's') {
15793: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15794: }
15795: }
15796: } elsif (!@text) {
15797: $resulttext .= &mt('No recipients');
1.134 raeburn 15798: }
15799: $resulttext .= '</li>';
1.28 raeburn 15800: }
15801: }
1.160.6.101 raeburn 15802: if (ref($changes{'overrides'}) eq 'ARRAY') {
15803: my @deletions;
15804: foreach my $type (@{$changes{'overrides'}}) {
15805: if ($usertypeshash{$type}) {
15806: if (grep(/^\Q$type\E/,@overrides)) {
15807: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15808: $usertypeshash{$type}).'<ul><li>';
15809: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15810: my @text;
15811: foreach my $item (@contacts) {
15812: if ($newsetting{'override_'.$type}{$item}) {
15813: push(@text,$short_titles->{$item});
15814: }
15815: }
15816: if ($newsetting{'override_'.$type}{'others'} ne '') {
15817: push(@text,$newsetting{'override_'.$type}{'others'});
15818: }
15819:
15820: if (@text) {
15821: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15822: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15823: }
15824: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15825: my $bcctext;
15826: if (@text) {
15827: $bcctext = ' '.&mt('with Bcc to');
15828: } else {
15829: $bcctext = '(Bcc)';
15830: }
15831: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15832: } elsif (!@text) {
15833: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15834: }
15835: $resulttext .= '</li>';
15836: if ($newsetting{'override_'.$type}{'include'} ne '') {
15837: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15838: if ($loc eq 'b') {
15839: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15840: } elsif ($loc eq 's') {
15841: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15842: }
15843: }
15844: }
15845: $resulttext .= '</li></ul></li>';
15846: } else {
15847: push(@deletions,$usertypeshash{$type});
15848: }
15849: }
15850: }
15851: if (@deletions) {
15852: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15853: join(', ',@deletions)).'</li>';
15854: }
15855: }
1.160.6.23 raeburn 15856: my @offon = ('off','on');
1.160.6.107 raeburn 15857: my $corelink = &core_link_msu();
1.160.6.23 raeburn 15858: if ($changes{'reporterrors'}) {
15859: $resulttext .= '<li>'.
15860: &mt('E-mail error reports to [_1] set to "'.
15861: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 15862: $corelink).
1.160.6.23 raeburn 15863: '</li>';
15864: }
15865: if ($changes{'reportupdates'}) {
15866: $resulttext .= '<li>'.
15867: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15868: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 15869: $corelink).
1.160.6.23 raeburn 15870: '</li>';
15871: }
1.160.6.107 raeburn 15872: if ($changes{'reportstatus'}) {
15873: $resulttext .= '<li>'.
15874: &mt('E-mail status if errors above threshold to [_1] set to "'.
15875: $offon[$env{'form.reportstatus'}].'".',
15876: $corelink).
15877: '</li>';
15878: }
15879: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15880: $resulttext .= '<li>'.
15881: &mt('Nightly status check e-mail settings').':<ul>';
15882: my (%defval,%use_def,%shown);
15883: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15884: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15885: $defval{'weights'} =
15886: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15887: $defval{'excluded'} = &mt('None');
15888: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15889: foreach my $item ('threshold','sysmail','weights','excluded') {
15890: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15891: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15892: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15893: } elsif ($item eq 'weights') {
15894: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15895: foreach my $type ('E','W','N','U') {
15896: $shown{$item} .= $lonstatus_names->{$type}.'=';
15897: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15898: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15899: } else {
15900: $shown{$item} .= $lonstatus_defs->{$type};
15901: }
15902: $shown{$item} .= ', ';
15903: }
15904: $shown{$item} =~ s/, $//;
15905: } else {
15906: $shown{$item} = $defval{$item};
15907: }
15908: } elsif ($item eq 'excluded') {
15909: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15910: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15911: } else {
15912: $shown{$item} = $defval{$item};
15913: }
15914: }
15915: } else {
15916: $shown{$item} = $defval{$item};
15917: }
15918: }
15919: } else {
15920: foreach my $item ('threshold','weights','excluded','sysmail') {
15921: $shown{$item} = $defval{$item};
15922: }
15923: }
15924: foreach my $item ('threshold','weights','excluded','sysmail') {
15925: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15926: $shown{$item}).'</li>';
15927: }
15928: $resulttext .= '</ul></li>';
15929: }
1.160.6.78 raeburn 15930: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15931: my (@optional,@required,@unused,$maxsizechg);
15932: foreach my $field (@{$changes{'helpform'}}) {
15933: if ($field eq 'maxsize') {
15934: $maxsizechg = 1;
15935: next;
15936: }
15937: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15938: push(@optional,$field);
15939: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15940: push(@unused,$field);
15941: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15942: push(@required,$field);
15943: }
15944: }
15945: if (@optional) {
15946: $resulttext .= '<li>'.
15947: &mt('Help form fields changed to "Optional": [_1].',
15948: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15949: '</li>';
15950: }
15951: if (@required) {
15952: $resulttext .= '<li>'.
15953: &mt('Help form fields changed to "Required": [_1].',
15954: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15955: '</li>';
15956: }
15957: if (@unused) {
15958: $resulttext .= '<li>'.
15959: &mt('Help form fields changed to "Not shown": [_1].',
15960: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15961: '</li>';
15962: }
15963: if ($maxsizechg) {
15964: $resulttext .= '<li>'.
15965: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15966: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15967: '</li>';
15968: }
15969: }
1.28 raeburn 15970: $resulttext .= '</ul>';
15971: } else {
1.160.6.78 raeburn 15972: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15973: }
15974: } else {
15975: $resulttext = '<span class="LC_error">'.
1.160.6.118.2 14(raebu 15976:23): &mt('An error occurred: [_1]',$putresult).'</span>';
1.28 raeburn 15977: }
15978: return $resulttext;
15979: }
15980:
1.160.6.98 raeburn 15981: sub modify_passwords {
15982: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15983: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15984: $updatedefaults,$updateconf);
15985: my $customfn = 'resetpw.html';
15986: if (ref($domconfig{'passwords'}) eq 'HASH') {
15987: %current = %{$domconfig{'passwords'}};
15988: }
15989: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15990: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15991: if (ref($types) eq 'ARRAY') {
15992: @oktypes = @{$types};
15993: }
15994: push(@oktypes,'default');
15995:
15996: my %titles = &Apache::lonlocal::texthash (
15997: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15998: intauth_check => 'Check bcrypt cost if authenticated',
15999: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16000: permanent => 'Permanent e-mail address',
16001: critical => 'Critical notification address',
16002: notify => 'Notification address',
16003: min => 'Minimum password length',
16004: max => 'Maximum password length',
16005: chars => 'Required characters',
16006: numsaved => 'Number of previous passwords to save',
16007: reset => 'Resetting Forgotten Password',
16008: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16009: rules => 'Rules for LON-CAPA Passwords',
16010: crsownerchg => 'Course Owner Changing Student Passwords',
16011: username => 'Username',
16012: email => 'E-mail address',
16013: );
16014:
16015: #
16016: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16017: #
16018: my (%curr_defaults,%save_defaults);
16019: if (ref($domconfig{'defaults'}) eq 'HASH') {
16020: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16021: if ($key =~ /^intauth_(cost|check|switch)$/) {
16022: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16023: } else {
16024: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16025: }
16026: }
16027: }
16028: my %staticdefaults = (
16029: 'resetlink' => 2,
16030: 'resetcase' => \@oktypes,
16031: 'resetprelink' => 'both',
16032: 'resetemail' => ['critical','notify','permanent'],
16033: 'intauth_cost' => 10,
16034: 'intauth_check' => 0,
16035: 'intauth_switch' => 0,
16036: );
1.160.6.99 raeburn 16037: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 16038: foreach my $type (@oktypes) {
16039: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16040: }
16041: my $linklife = $env{'form.passwords_link'};
16042: $linklife =~ s/^\s+|\s+$//g;
16043: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16044: $newvalues{'resetlink'} = $linklife;
16045: if ($current{'resetlink'}) {
16046: if ($current{'resetlink'} ne $linklife) {
16047: $changes{'reset'} = 1;
16048: }
1.160.6.102 raeburn 16049: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16050: if ($staticdefaults{'resetlink'} ne $linklife) {
16051: $changes{'reset'} = 1;
16052: }
16053: }
16054: } elsif ($current{'resetlink'}) {
16055: $changes{'reset'} = 1;
16056: }
16057: my @casesens;
16058: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16059: foreach my $case (sort(@posscase)) {
16060: if (grep(/^\Q$case\E$/,@oktypes)) {
16061: push(@casesens,$case);
16062: }
16063: }
16064: $newvalues{'resetcase'} = \@casesens;
16065: if (ref($current{'resetcase'}) eq 'ARRAY') {
16066: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16067: if (@diffs > 0) {
16068: $changes{'reset'} = 1;
16069: }
1.160.6.102 raeburn 16070: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16071: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16072: if (@diffs > 0) {
16073: $changes{'reset'} = 1;
16074: }
16075: }
16076: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16077: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16078: if (exists($current{'resetprelink'})) {
16079: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16080: $changes{'reset'} = 1;
16081: }
1.160.6.102 raeburn 16082: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16083: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16084: $changes{'reset'} = 1;
16085: }
16086: }
16087: } elsif ($current{'resetprelink'}) {
16088: $changes{'reset'} = 1;
16089: }
16090: foreach my $type (@oktypes) {
16091: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16092: my @postlink;
16093: foreach my $item (sort(@possplink)) {
16094: if ($item =~ /^(email|username)$/) {
16095: push(@postlink,$item);
16096: }
16097: }
16098: $newvalues{'resetpostlink'}{$type} = \@postlink;
16099: unless ($changes{'reset'}) {
16100: if (ref($current{'resetpostlink'}) eq 'HASH') {
16101: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16102: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16103: if (@diffs > 0) {
16104: $changes{'reset'} = 1;
16105: }
16106: } else {
16107: $changes{'reset'} = 1;
16108: }
1.160.6.102 raeburn 16109: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16110: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16111: if (@diffs > 0) {
16112: $changes{'reset'} = 1;
16113: }
16114: }
16115: }
16116: }
16117: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16118: my @resetemail;
16119: foreach my $item (sort(@possemailsrc)) {
16120: if ($item =~ /^(permanent|critical|notify)$/) {
16121: push(@resetemail,$item);
16122: }
16123: }
16124: $newvalues{'resetemail'} = \@resetemail;
16125: unless ($changes{'reset'}) {
16126: if (ref($current{'resetemail'}) eq 'ARRAY') {
16127: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16128: if (@diffs > 0) {
16129: $changes{'reset'} = 1;
16130: }
1.160.6.102 raeburn 16131: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16132: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16133: if (@diffs > 0) {
16134: $changes{'reset'} = 1;
16135: }
16136: }
16137: }
16138: if ($env{'form.passwords_stdtext'} == 0) {
16139: $newvalues{'resetremove'} = 1;
16140: unless ($current{'resetremove'}) {
16141: $changes{'reset'} = 1;
16142: }
16143: } elsif ($current{'resetremove'}) {
16144: $changes{'reset'} = 1;
16145: }
16146: if ($env{'form.passwords_customfile.filename'} ne '') {
16147: my $servadm = $r->dir_config('lonAdmEMail');
16148: my ($configuserok,$author_ok,$switchserver) =
16149: &config_check($dom,$confname,$servadm);
16150: my $error;
16151: if ($configuserok eq 'ok') {
16152: if ($switchserver) {
16153: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16154: } else {
16155: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 16156:23): my $modified = [];
1.160.6.98 raeburn 16157: my ($result,$customurl) =
1.160.6.118.2 14(raebu 16158:23): &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
16159:23): $confname,'customtext/resetpw','','',$customfn,
16160:23): $modified);
1.160.6.98 raeburn 16161: if ($result eq 'ok') {
16162: $newvalues{'resetcustom'} = $customurl;
16163: $changes{'reset'} = 1;
1.160.6.118.2 14(raebu 16164:23): &update_modify_urls($r,$modified);
1.160.6.98 raeburn 16165: } else {
16166: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16167: }
16168: } else {
16169: $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);
16170: }
16171: }
16172: } else {
16173: $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);
16174: }
16175: if ($error) {
16176: &Apache::lonnet::logthis($error);
16177: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16178: }
16179: } elsif ($current{'resetcustom'}) {
16180: if ($env{'form.passwords_custom_del'}) {
16181: $changes{'reset'} = 1;
16182: } else {
16183: $newvalues{'resetcustom'} = $current{'resetcustom'};
16184: }
16185: }
16186: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16187: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16188: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16189: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16190: $changes{'intauth'} = 1;
16191: }
16192: } else {
16193: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16194: }
16195: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16196: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16197: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16198: $changes{'intauth'} = 1;
16199: }
16200: } else {
16201: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16202: }
16203: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16204: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16205: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16206: $changes{'intauth'} = 1;
16207: }
16208: } else {
16209: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16210: }
16211: foreach my $item ('cost','check','switch') {
16212: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16213: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16214: $updatedefaults = 1;
16215: }
16216: }
1.160.6.118.2 5(raebur 16217:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 16218: my %crsownerchg = (
16219: by => [],
16220: for => [],
16221: );
16222: foreach my $item ('by','for') {
16223: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16224: foreach my $type (sort(@posstypes)) {
16225: if (grep(/^\Q$type\E$/,@oktypes)) {
16226: push(@{$crsownerchg{$item}},$type);
16227: }
16228: }
16229: }
16230: $newvalues{'crsownerchg'} = \%crsownerchg;
16231: if (ref($current{'crsownerchg'}) eq 'HASH') {
16232: foreach my $item ('by','for') {
16233: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16234: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16235: if (@diffs > 0) {
16236: $changes{'crsownerchg'} = 1;
16237: last;
16238: }
16239: }
16240: }
1.160.6.102 raeburn 16241: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 16242: foreach my $item ('by','for') {
16243: if (@{$crsownerchg{$item}} > 0) {
16244: $changes{'crsownerchg'} = 1;
16245: last;
16246: }
16247: }
16248: }
16249:
16250: my %confighash = (
16251: defaults => \%save_defaults,
16252: passwords => \%newvalues,
16253: );
16254: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16255:
16256: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16257: if ($putresult eq 'ok') {
16258: if (keys(%changes) > 0) {
16259: $resulttext = &mt('Changes made: ').'<ul>';
16260: foreach my $key ('reset','intauth','rules','crsownerchg') {
16261: if ($changes{$key}) {
16262: unless ($key eq 'intauth') {
16263: $updateconf = 1;
16264: }
16265: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16266: if ($key eq 'reset') {
16267: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16268: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16269: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16270: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 16271: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16272: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16273: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16274: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16275: }
1.160.6.98 raeburn 16276: } else {
16277: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16278: }
16279: if ($confighash{'passwords'}{'resetlink'}) {
16280: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16281: } else {
16282: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16283: &mt('Will default to 2 hours').'</li>';
16284: }
16285: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16286: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16287: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16288: } else {
16289: my $casesens;
16290: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16291: if ($type eq 'default') {
16292: $casesens .= $othertitle.', ';
16293: } elsif ($usertypes->{$type} ne '') {
16294: $casesens .= $usertypes->{$type}.', ';
16295: }
16296: }
16297: $casesens =~ s/\Q, \E$//;
16298: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16299: }
16300: } else {
16301: $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>';
16302: }
16303: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16304: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16305: } else {
16306: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16307: }
16308: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16309: my $output;
16310: if (ref($types) eq 'ARRAY') {
16311: foreach my $type (@{$types}) {
16312: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16313: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16314: $output .= $usertypes->{$type}.' -- '.&mt('none');
16315: } else {
16316: $output .= $usertypes->{$type}.' -- '.
16317: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16318: }
16319: }
16320: }
16321: }
16322: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16323: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16324: $output .= $othertitle.' -- '.&mt('none');
16325: } else {
16326: $output .= $othertitle.' -- '.
16327: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16328: }
16329: }
16330: if ($output) {
16331: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16332: } else {
16333: $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>';
16334: }
16335: } else {
16336: $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>';
16337: }
16338: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16339: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16340: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16341: } else {
16342: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16343: }
16344: } else {
1.160.6.110 raeburn 16345: $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 16346: }
16347: if ($confighash{'passwords'}{'resetremove'}) {
16348: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16349: } else {
16350: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16351: }
16352: if ($confighash{'passwords'}{'resetcustom'}) {
16353: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 16354: &mt('custom text'),600,500,undef,undef,
16355: undef,undef,'background-color:#ffffff');
16356: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 16357: } else {
16358: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16359: }
16360: } elsif ($key eq 'intauth') {
16361: foreach my $item ('cost','switch','check') {
16362: my $value = $save_defaults{$key.'_'.$item};
16363: if ($item eq 'switch') {
16364: my %optiondesc = &Apache::lonlocal::texthash (
16365: 0 => 'No',
16366: 1 => 'Yes',
16367: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16368: );
16369: if ($value =~ /^(0|1|2)$/) {
16370: $value = $optiondesc{$value};
16371: } else {
16372: $value = &mt('none -- defaults to No');
16373: }
16374: } elsif ($item eq 'check') {
16375: my %optiondesc = &Apache::lonlocal::texthash (
16376: 0 => 'No',
16377: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16378: 2 => 'Yes, disallow login if stored cost is less than domain default',
16379: );
16380: if ($value =~ /^(0|1|2)$/) {
16381: $value = $optiondesc{$value};
16382: } else {
16383: $value = &mt('none -- defaults to No');
16384: }
16385: }
16386: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16387: }
16388: } elsif ($key eq 'rules') {
16389: foreach my $rule ('min','max','numsaved') {
16390: if ($confighash{'passwords'}{$rule} eq '') {
16391: if ($rule eq 'min') {
16392: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 16393: ' '.&mt('Default of [_1] will be used',
16394: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 16395: } else {
16396: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
16397: }
16398: } else {
16399: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16400: }
16401: }
1.160.6.104 raeburn 16402: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16403: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16404: my %rulenames = &Apache::lonlocal::texthash(
16405: uc => 'At least one upper case letter',
16406: lc => 'At least one lower case letter',
16407: num => 'At least one number',
16408: spec => 'At least one non-alphanumeric',
16409: );
16410: my $needed = '<ul><li>'.
16411: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16412: '</li></ul>';
16413: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16414: } else {
16415: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16416: }
16417: } else {
16418: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16419: }
1.160.6.98 raeburn 16420: } elsif ($key eq 'crsownerchg') {
16421: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16422: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16423: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16424: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16425: } else {
16426: my %crsownerstr;
16427: foreach my $item ('by','for') {
16428: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16429: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16430: if ($type eq 'default') {
16431: $crsownerstr{$item} .= $othertitle.', ';
16432: } elsif ($usertypes->{$type} ne '') {
16433: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16434: }
16435: }
16436: $crsownerstr{$item} =~ s/\Q, \E$//;
16437: }
16438: }
16439: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16440: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16441: }
16442: } else {
16443: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16444: }
16445: }
16446: $resulttext .= '</ul></li>';
16447: }
16448: }
16449: $resulttext .= '</ul>';
16450: } else {
16451: $resulttext = &mt('No changes made to password settings');
16452: }
16453: my $cachetime = 24*60*60;
16454: if ($updatedefaults) {
16455: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16456: if (ref($lastactref) eq 'HASH') {
16457: $lastactref->{'domdefaults'} = 1;
16458: }
16459: }
16460: if ($updateconf) {
16461: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16462: if (ref($lastactref) eq 'HASH') {
16463: $lastactref->{'passwdconf'} = 1;
16464: }
16465: }
16466: } else {
16467: $resulttext = '<span class="LC_error">'.
16468: &mt('An error occurred: [_1]',$putresult).'</span>';
16469: }
16470: if ($errors) {
16471: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16472: $errors.'</ul></p>';
16473: }
16474: return $resulttext;
16475: }
16476:
1.160.6.118.2 5(raebur 16477:2): sub password_rule_changes {
16478:2): my ($prefix,$newvalues,$current,$changes) = @_;
16479:2): return unless ((ref($newvalues) eq 'HASH') &&
16480:2): (ref($current) eq 'HASH') &&
16481:2): (ref($changes) eq 'HASH'));
16482:2): my (@rules,%staticdefaults);
16483:2): if ($prefix eq 'passwords') {
16484:2): @rules = ('min','max','numsaved');
14(raebu 16485:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 16486:2): @rules = ('min','max');
16487:2): }
16488:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
16489:2): foreach my $rule (@rules) {
16490:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
16491:2): my $ruleok;
16492:2): if ($rule eq 'min') {
16493:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
16494:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
16495:2): $ruleok = 1;
16496:2): }
16497:2): }
16498:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
16499:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
16500:2): $ruleok = 1;
16501:2): }
16502:2): if ($ruleok) {
16503:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
16504:2): if (exists($current->{$rule})) {
16505:2): if ($newvalues->{$rule} ne $current->{$rule}) {
16506:2): $changes->{'rules'} = 1;
16507:2): }
16508:2): } elsif ($rule eq 'min') {
16509:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
16510:2): $changes->{'rules'} = 1;
16511:2): }
16512:2): } else {
16513:2): $changes->{'rules'} = 1;
16514:2): }
16515:2): } elsif (exists($current->{$rule})) {
16516:2): $changes->{'rules'} = 1;
16517:2): }
16518:2): }
16519:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
16520:2): my @chars;
16521:2): foreach my $item (sort(@posschars)) {
16522:2): if ($item =~ /^(uc|lc|num|spec)$/) {
16523:2): push(@chars,$item);
16524:2): }
16525:2): }
16526:2): $newvalues->{'chars'} = \@chars;
16527:2): unless ($changes->{'rules'}) {
16528:2): if (ref($current->{'chars'}) eq 'ARRAY') {
16529:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
16530:2): if (@diffs > 0) {
16531:2): $changes->{'rules'} = 1;
16532:2): }
16533:2): } else {
16534:2): if (@chars > 0) {
16535:2): $changes->{'rules'} = 1;
16536:2): }
16537:2): }
16538:2): }
16539:2): return;
16540:2): }
16541:2):
1.28 raeburn 16542: sub modify_usercreation {
1.27 raeburn 16543: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16544: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16545: my $warningmsg;
1.27 raeburn 16546: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16547: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 16548: if ($key eq 'cancreate') {
16549: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16550: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 16551: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 16552: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 16553: } else {
16554: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 16555: }
1.50 raeburn 16556: }
1.43 raeburn 16557: }
1.160.6.34 raeburn 16558: } elsif ($key eq 'email_rule') {
16559: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16560: } else {
16561: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 16562: }
16563: }
1.34 raeburn 16564: }
1.160.6.34 raeburn 16565: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
16566: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
16567: my @contexts = ('author','course','requestcrs');
16568: foreach my $item(@contexts) {
16569: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16570: }
1.34 raeburn 16571: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16572: foreach my $item (@contexts) {
1.160.6.34 raeburn 16573: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16574: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16575: }
1.27 raeburn 16576: }
1.34 raeburn 16577: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16578: foreach my $item (@contexts) {
1.43 raeburn 16579: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16580: if ($cancreate{$item} ne 'any') {
16581: push(@{$changes{'cancreate'}},$item);
16582: }
16583: } else {
16584: if ($cancreate{$item} ne 'none') {
16585: push(@{$changes{'cancreate'}},$item);
16586: }
1.27 raeburn 16587: }
16588: }
16589: } else {
1.43 raeburn 16590: foreach my $item (@contexts) {
1.34 raeburn 16591: push(@{$changes{'cancreate'}},$item);
16592: }
1.27 raeburn 16593: }
1.34 raeburn 16594:
1.27 raeburn 16595: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16596: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16597: if (!grep(/^\Q$type\E$/,@username_rule)) {
16598: push(@{$changes{'username_rule'}},$type);
16599: }
16600: }
16601: foreach my $type (@username_rule) {
16602: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16603: push(@{$changes{'username_rule'}},$type);
16604: }
16605: }
16606: } else {
16607: push(@{$changes{'username_rule'}},@username_rule);
16608: }
16609:
1.32 raeburn 16610: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16611: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16612: if (!grep(/^\Q$type\E$/,@id_rule)) {
16613: push(@{$changes{'id_rule'}},$type);
16614: }
16615: }
16616: foreach my $type (@id_rule) {
16617: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16618: push(@{$changes{'id_rule'}},$type);
16619: }
16620: }
16621: } else {
16622: push(@{$changes{'id_rule'}},@id_rule);
16623: }
16624:
1.43 raeburn 16625: my @authen_contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 16626:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16627: my %authhash;
1.43 raeburn 16628: foreach my $item (@authen_contexts) {
1.28 raeburn 16629: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16630: foreach my $auth (@authtypes) {
16631: if (grep(/^\Q$auth\E$/,@authallowed)) {
16632: $authhash{$item}{$auth} = 1;
16633: } else {
16634: $authhash{$item}{$auth} = 0;
16635: }
16636: }
16637: }
16638: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16639: foreach my $item (@authen_contexts) {
1.28 raeburn 16640: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16641: foreach my $auth (@authtypes) {
16642: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16643: push(@{$changes{'authtypes'}},$item);
16644: last;
16645: }
16646: }
16647: }
16648: }
16649: } else {
1.43 raeburn 16650: foreach my $item (@authen_contexts) {
1.28 raeburn 16651: push(@{$changes{'authtypes'}},$item);
16652: }
16653: }
16654:
1.160.6.34 raeburn 16655: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16656: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16657: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16658: $save_usercreate{'id_rule'} = \@id_rule;
16659: $save_usercreate{'username_rule'} = \@username_rule,
16660: $save_usercreate{'authtypes'} = \%authhash;
16661:
1.27 raeburn 16662: my %usercreation_hash = (
1.160.6.34 raeburn 16663: usercreation => \%save_usercreate,
16664: );
1.27 raeburn 16665:
16666: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16667: $dom);
1.50 raeburn 16668:
1.160.6.34 raeburn 16669: if ($putresult eq 'ok') {
16670: if (keys(%changes) > 0) {
16671: $resulttext = &mt('Changes made:').'<ul>';
16672: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16673: my %lt = &usercreation_types();
16674: foreach my $type (@{$changes{'cancreate'}}) {
16675: my $chgtext = $lt{$type}.', ';
16676: if ($cancreate{$type} eq 'none') {
16677: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16678: } elsif ($cancreate{$type} eq 'any') {
16679: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16680: } elsif ($cancreate{$type} eq 'official') {
16681: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16682: } elsif ($cancreate{$type} eq 'unofficial') {
16683: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16684: }
16685: $resulttext .= '<li>'.$chgtext.'</li>';
16686: }
16687: }
16688: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16689: my ($rules,$ruleorder) =
16690: &Apache::lonnet::inst_userrules($dom,'username');
16691: my $chgtext = '<ul>';
16692: foreach my $type (@username_rule) {
16693: if (ref($rules->{$type}) eq 'HASH') {
16694: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16695: }
16696: }
16697: $chgtext .= '</ul>';
16698: if (@username_rule > 0) {
16699: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16700: } else {
16701: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16702: }
16703: }
16704: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16705: my ($idrules,$idruleorder) =
16706: &Apache::lonnet::inst_userrules($dom,'id');
16707: my $chgtext = '<ul>';
16708: foreach my $type (@id_rule) {
16709: if (ref($idrules->{$type}) eq 'HASH') {
16710: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16711: }
16712: }
16713: $chgtext .= '</ul>';
16714: if (@id_rule > 0) {
16715: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16716: } else {
16717: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16718: }
16719: }
16720: my %authname = &authtype_names();
16721: my %context_title = &context_names();
16722: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16723: my $chgtext = '<ul>';
16724: foreach my $type (@{$changes{'authtypes'}}) {
16725: my @allowed;
16726: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16727: foreach my $auth (@authtypes) {
16728: if ($authhash{$type}{$auth}) {
16729: push(@allowed,$authname{$auth});
16730: }
16731: }
16732: if (@allowed > 0) {
16733: $chgtext .= join(', ',@allowed).'</li>';
16734: } else {
16735: $chgtext .= &mt('none').'</li>';
16736: }
16737: }
16738: $chgtext .= '</ul>';
16739: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16740: $resulttext .= '</li>';
16741: }
16742: $resulttext .= '</ul>';
16743: } else {
16744: $resulttext = &mt('No changes made to user creation settings');
16745: }
16746: } else {
16747: $resulttext = '<span class="LC_error">'.
16748: &mt('An error occurred: [_1]',$putresult).'</span>';
16749: }
16750: if ($warningmsg ne '') {
16751: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16752: }
16753: return $resulttext;
16754: }
16755:
16756: sub modify_selfcreation {
1.160.6.93 raeburn 16757: my ($dom,$lastactref,%domconfig) = @_;
16758: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16759: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16760: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16761: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16762: if (ref($typesref) eq 'ARRAY') {
16763: @types = @{$typesref};
16764: }
16765: if (ref($usertypesref) eq 'HASH') {
16766: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 16767: }
1.160.6.93 raeburn 16768: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 16769: #
16770: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16771: #
16772: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16773: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16774: if ($key eq 'cancreate') {
16775: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16776: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16777: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 16778: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16779: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16780: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16781: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16782: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 16783: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16784: } else {
16785: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16786: }
16787: }
16788: }
16789: } elsif ($key eq 'email_rule') {
16790: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16791: } else {
16792: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16793: }
16794: }
16795: }
16796: #
16797: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16798: #
16799: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16800: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16801: if ($key eq 'selfcreate') {
16802: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16803: } else {
16804: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16805: }
16806: }
16807: }
1.160.6.93 raeburn 16808: #
16809: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16810: #
16811: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16812: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16813: if ($key eq 'inststatusguest') {
16814: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16815: } else {
16816: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16817: }
16818: }
16819: }
1.160.6.34 raeburn 16820:
16821: my @contexts = ('selfcreate');
16822: @{$cancreate{'selfcreate'}} = ();
16823: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 16824: if (@types) {
16825: @{$cancreate{'statustocreate'}} = ();
16826: }
1.160.6.40 raeburn 16827: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 16828: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 16829: %{$cancreate{'emailverified'}} = ();
16830: %{$cancreate{'emailoptions'}} = ();
16831: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16832: my %selfcreatetypes = (
16833: sso => 'users authenticated by institutional single sign on',
16834: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 16835: email => 'users verified by e-mail',
1.50 raeburn 16836: );
1.160.6.34 raeburn 16837: #
16838: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16839: # is permitted.
16840: #
1.160.6.93 raeburn 16841: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 16842:
1.160.6.93 raeburn 16843: my (@statuses,%email_rule);
1.160.6.35 raeburn 16844: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 16845: if ($item eq 'email') {
1.160.6.40 raeburn 16846: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 16847: if (@types) {
16848: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16849: foreach my $status (@poss_statuses) {
16850: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16851: push(@statuses,$status);
16852: }
16853: }
16854: $save_inststatus{'inststatusguest'} = \@statuses;
16855: } else {
16856: push(@statuses,'default');
16857: }
16858: if (@statuses) {
16859: my %curr_rule;
16860: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16861: foreach my $type (@statuses) {
16862: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16863: }
16864: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16865: foreach my $type (@statuses) {
16866: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16867: }
16868: }
16869: push(@{$cancreate{'selfcreate'}},'email');
16870: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16871: my %curremaildom;
16872: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16873: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16874: }
16875: foreach my $type (@statuses) {
16876: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16877: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16878: }
16879: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16880: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16881: }
16882: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16883: #
16884: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16885: #
16886: my $chosen = $1;
16887: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16888: my $emaildom;
16889: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16890: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16891: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16892: if (ref($curremaildom{$type}) eq 'HASH') {
16893: if (exists($curremaildom{$type}{$chosen})) {
16894: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16895: push(@{$changes{'cancreate'}},'emaildomain');
16896: }
16897: } elsif ($emaildom ne '') {
16898: push(@{$changes{'cancreate'}},'emaildomain');
16899: }
16900: } elsif ($emaildom ne '') {
16901: push(@{$changes{'cancreate'}},'emaildomain');
16902: }
16903: }
16904: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16905: } elsif ($chosen eq 'custom') {
16906: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16907: $email_rule{$type} = [];
16908: if (ref($emailrules) eq 'HASH') {
16909: foreach my $rule (@possemail_rules) {
16910: if (exists($emailrules->{$rule})) {
16911: push(@{$email_rule{$type}},$rule);
16912: }
16913: }
16914: }
16915: if (@{$email_rule{$type}}) {
16916: $cancreate{'emailoptions'}{$type} = 'custom';
16917: if (ref($curr_rule{$type}) eq 'ARRAY') {
16918: if (@{$curr_rule{$type}} > 0) {
16919: foreach my $rule (@{$curr_rule{$type}}) {
16920: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16921: push(@{$changes{'email_rule'}},$type);
16922: }
16923: }
16924: }
16925: foreach my $type (@{$email_rule{$type}}) {
16926: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16927: push(@{$changes{'email_rule'}},$type);
16928: }
16929: }
16930: } else {
16931: push(@{$changes{'email_rule'}},$type);
16932: }
16933: }
16934: } else {
16935: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16936: }
16937: }
16938: }
16939: if (@types) {
16940: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16941: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16942: if (@changed) {
16943: push(@{$changes{'inststatus'}},'inststatusguest');
16944: }
16945: } else {
16946: push(@{$changes{'inststatus'}},'inststatusguest');
16947: }
16948: }
16949: } else {
16950: delete($env{'form.cancreate_email'});
16951: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16952: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16953: push(@{$changes{'inststatus'}},'inststatusguest');
16954: }
16955: }
16956: }
16957: } else {
16958: $save_inststatus{'inststatusguest'} = [];
16959: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16960: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16961: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 16962: }
16963: }
1.160.6.34 raeburn 16964: }
16965: } else {
16966: if ($env{'form.cancreate_'.$item}) {
16967: push(@{$cancreate{'selfcreate'}},$item);
16968: }
16969: }
16970: }
1.160.6.93 raeburn 16971: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 16972: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16973: #
1.160.6.35 raeburn 16974: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16975: # 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 16976: #
1.160.6.40 raeburn 16977:
1.160.6.48 raeburn 16978: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 16979: push(@contexts,'emailusername');
1.160.6.93 raeburn 16980: if (@statuses) {
16981: foreach my $type (@statuses) {
1.160.6.35 raeburn 16982: if (ref($infofields) eq 'ARRAY') {
16983: foreach my $field (@{$infofields}) {
16984: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16985: $cancreate{'emailusername'}{$type}{$field} = $1;
16986: }
16987: }
1.160.6.34 raeburn 16988: }
16989: }
16990: }
16991: #
16992: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 16993: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 16994: #
16995:
16996: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16997: @approvalnotify = sort(@approvalnotify);
16998: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16999: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17000: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17001: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17002: push(@{$changes{'cancreate'}},'notify');
17003: }
17004: } else {
17005: if ($cancreate{'notify'}{'approval'}) {
17006: push(@{$changes{'cancreate'}},'notify');
17007: }
17008: }
17009: } elsif ($cancreate{'notify'}{'approval'}) {
17010: push(@{$changes{'cancreate'}},'notify');
17011: }
17012:
17013: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17014: }
17015: #
1.160.6.40 raeburn 17016: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 17017: # institutional log-in.
17018: #
17019: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17020: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17021: ($domdefaults{'auth_def'} eq 'localauth'))) {
17022: $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.').' '.
17023: &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.');
17024: }
17025: }
17026: my @fields = ('lastname','firstname','middlename','generation',
17027: 'permanentemail','id');
1.160.6.44 raeburn 17028: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 17029: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17030: #
17031: # Where usernames may created for institutional log-in and/or institutional single sign on:
17032: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17033: # may self-create accounts
17034: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17035: # which the user may supply, if institutional data is unavailable.
17036: #
17037: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 17038: if (@types) {
17039: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17040: push(@contexts,'statustocreate');
17041: foreach my $type (@types) {
1.160.6.34 raeburn 17042: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17043: foreach my $field (@fields) {
17044: if (grep(/^\Q$field\E$/,@modifiable)) {
17045: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17046: } else {
17047: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17048: }
17049: }
17050: }
17051: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 17052: foreach my $type (@types) {
1.160.6.34 raeburn 17053: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17054: foreach my $field (@fields) {
17055: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17056: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17057: push(@{$changes{'selfcreate'}},$type);
17058: last;
17059: }
17060: }
17061: }
17062: }
17063: } else {
1.160.6.93 raeburn 17064: foreach my $type (@types) {
1.160.6.34 raeburn 17065: push(@{$changes{'selfcreate'}},$type);
17066: }
17067: }
17068: }
1.160.6.44 raeburn 17069: foreach my $field (@shibfields) {
17070: if ($env{'form.shibenv_'.$field} ne '') {
17071: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17072: }
17073: }
17074: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17075: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17076: foreach my $field (@shibfields) {
17077: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17078: push(@{$changes{'cancreate'}},'shibenv');
17079: }
17080: }
17081: } else {
17082: foreach my $field (@shibfields) {
17083: if ($env{'form.shibenv_'.$field}) {
17084: push(@{$changes{'cancreate'}},'shibenv');
17085: last;
17086: }
17087: }
17088: }
17089: }
1.160.6.34 raeburn 17090: }
17091: foreach my $item (@contexts) {
17092: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17093: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17094: if (ref($cancreate{$item}) eq 'ARRAY') {
17095: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17096: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17097: push(@{$changes{'cancreate'}},$item);
17098: }
17099: }
17100: }
17101: }
17102: if (ref($cancreate{$item}) eq 'ARRAY') {
17103: foreach my $type (@{$cancreate{$item}}) {
17104: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17105: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17106: push(@{$changes{'cancreate'}},$item);
17107: }
17108: }
17109: }
17110: }
17111: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17112: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 17113: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17114: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17115: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17116: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17117: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17118: push(@{$changes{'cancreate'}},$item);
17119: }
17120: }
17121: }
1.160.6.93 raeburn 17122: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17123: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17124: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17125: push(@{$changes{'cancreate'}},$item);
17126: }
1.160.6.34 raeburn 17127: }
17128: }
17129: }
1.160.6.93 raeburn 17130: foreach my $type (keys(%{$cancreate{$item}})) {
17131: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17132: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17133: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17134: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17135: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17136: push(@{$changes{'cancreate'}},$item);
17137: }
17138: }
17139: } else {
17140: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17141: push(@{$changes{'cancreate'}},$item);
17142: }
17143: }
17144: }
1.160.6.93 raeburn 17145: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17146: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17147: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17148: push(@{$changes{'cancreate'}},$item);
17149: }
1.160.6.34 raeburn 17150: }
17151: }
17152: }
17153: }
17154: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17155: if (ref($cancreate{$item}) eq 'ARRAY') {
17156: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17157: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17158: push(@{$changes{'cancreate'}},$item);
17159: }
17160: }
1.160.6.93 raeburn 17161: }
17162: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17163: if (ref($cancreate{$item}) eq 'HASH') {
17164: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17165: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 17166: }
17167: }
17168: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 17169: if (ref($cancreate{$item}) eq 'HASH') {
17170: foreach my $type (keys(%{$cancreate{$item}})) {
17171: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17172: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17173: if ($cancreate{$item}{$type}{$field}) {
17174: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17175: push(@{$changes{'cancreate'}},$item);
17176: }
17177: last;
17178: }
17179: }
17180: }
17181: }
1.160.6.34 raeburn 17182: }
17183: }
17184: }
17185: #
17186: # Populate %save_usercreate hash with updates to self-creation configuration.
17187: #
17188: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17189: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 17190: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 17191: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17192: if (ref($cancreate{'notify'}) eq 'HASH') {
17193: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17194: }
1.160.6.40 raeburn 17195: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17196: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17197: }
1.160.6.93 raeburn 17198: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17199: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17200: }
17201: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17202: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17203: }
17204: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17205: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17206: }
1.160.6.34 raeburn 17207: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17208: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17209: }
1.160.6.44 raeburn 17210: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17211: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17212: }
1.160.6.34 raeburn 17213: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 17214: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 17215:
17216: my %userconfig_hash = (
17217: usercreation => \%save_usercreate,
17218: usermodification => \%save_usermodify,
1.160.6.93 raeburn 17219: inststatus => \%save_inststatus,
1.160.6.34 raeburn 17220: );
1.160.6.93 raeburn 17221:
1.160.6.34 raeburn 17222: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17223: $dom);
17224: #
1.160.6.93 raeburn 17225: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 17226: #
1.27 raeburn 17227: if ($putresult eq 'ok') {
17228: if (keys(%changes) > 0) {
17229: $resulttext = &mt('Changes made:').'<ul>';
17230: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 17231: my %lt = &selfcreation_types();
1.34 raeburn 17232: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 17233: my $chgtext = '';
1.45 raeburn 17234: if ($type eq 'selfcreate') {
1.50 raeburn 17235: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 17236: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17237: } else {
1.160.6.34 raeburn 17238: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17239: '<ul>';
1.50 raeburn 17240: foreach my $case (@{$cancreate{$type}}) {
17241: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17242: }
17243: $chgtext .= '</ul>';
1.100 raeburn 17244: if (ref($cancreate{$type}) eq 'ARRAY') {
17245: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17246: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17247: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 17248: $chgtext .= '<span class="LC_warning">'.
17249: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17250: '</span><br />';
1.100 raeburn 17251: }
17252: }
17253: }
1.160.6.93 raeburn 17254: if (grep(/^email$/,@{$cancreate{$type}})) {
17255: if (!@statuses) {
17256: $chgtext .= '<span class="LC_warning">'.
17257: &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.").
17258: '</span><br />';
17259:
17260: }
17261: }
1.100 raeburn 17262: }
1.43 raeburn 17263: }
1.160.6.44 raeburn 17264: } elsif ($type eq 'shibenv') {
17265: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 17266: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 17267: } else {
17268: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17269: '<ul>';
17270: foreach my $field (@shibfields) {
17271: next if ($cancreate{$type}{$field} eq '');
17272: if ($field eq 'inststatus') {
17273: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17274: } else {
17275: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17276: }
17277: }
17278: $chgtext .= '</ul>';
1.160.6.93 raeburn 17279: }
1.93 raeburn 17280: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17281: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17282: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17283: if (@{$cancreate{'selfcreate'}} > 0) {
17284: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17285: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17286: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 17287: $chgtext .= '<br />'.
17288: '<span class="LC_warning">'.
17289: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17290: '</span>';
17291: }
1.160.6.93 raeburn 17292: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17293: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17294: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17295: } else {
17296: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17297: }
17298: $chgtext .= '<ul>';
17299: foreach my $case (@{$cancreate{$type}}) {
17300: if ($case eq 'default') {
17301: $chgtext .= '<li>'.$othertitle.'</li>';
17302: } else {
1.160.6.93 raeburn 17303: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17304: }
17305: }
1.100 raeburn 17306: $chgtext .= '</ul>';
17307: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 17308: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 17309: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17310: '</span>';
1.100 raeburn 17311: }
17312: }
17313: } else {
17314: if (@{$cancreate{$type}} == 0) {
17315: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17316: } else {
17317: $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 17318: }
17319: }
1.160.6.93 raeburn 17320: $chgtext .= '<br />';
1.93 raeburn 17321: }
1.160.6.40 raeburn 17322: } elsif ($type eq 'selfcreateprocessing') {
17323: my %choices = &Apache::lonlocal::texthash (
17324: automatic => 'Automatic approval',
17325: approval => 'Queued for approval',
17326: );
1.160.6.93 raeburn 17327: if (@types) {
17328: if (@statuses) {
17329: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
17330: '<ul>';
17331: foreach my $status (@statuses) {
17332: if ($status eq 'default') {
17333: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17334: } else {
17335: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17336: }
17337: }
17338: $chgtext .= '</ul>';
17339: }
17340: } else {
17341: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17342: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17343: }
17344: } elsif ($type eq 'emailverified') {
17345: my %options = &Apache::lonlocal::texthash (
17346: all => 'Same as e-mail',
17347: first => 'Omit @domain',
17348: free => 'Free to choose',
17349: );
17350: if (@types) {
17351: if (@statuses) {
17352: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17353: '<ul>';
17354: foreach my $status (@statuses) {
17355: if ($status eq 'default') {
17356: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17357: } else {
17358: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17359: }
17360: }
17361: $chgtext .= '</ul>';
17362: }
1.160.6.40 raeburn 17363: } else {
1.160.6.93 raeburn 17364: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
17365: $options{$cancreate{'emailverified'}{'default'}});
17366: }
17367: } elsif ($type eq 'emailoptions') {
17368: my %options = &Apache::lonlocal::texthash (
17369: any => 'Any e-mail',
17370: inst => 'Institutional only',
17371: noninst => 'Non-institutional only',
17372: custom => 'Custom restrictions',
17373: );
17374: if (@types) {
17375: if (@statuses) {
17376: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17377: '<ul>';
17378: foreach my $status (@statuses) {
17379: if ($type eq 'default') {
17380: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17381: } else {
17382: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17383: }
17384: }
17385: $chgtext .= '</ul>';
17386: }
17387: } else {
17388: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17389: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17390: } else {
17391: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17392: $options{$cancreate{'emailoptions'}{'default'}});
17393: }
17394: }
17395: } elsif ($type eq 'emaildomain') {
17396: my $output;
17397: if (@statuses) {
17398: foreach my $type (@statuses) {
17399: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17400: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17401: if ($type eq 'default') {
17402: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17403: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17404: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17405: } else {
17406: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17407: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17408: }
17409: } else {
17410: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17411: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17412: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17413: } else {
17414: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17415: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17416: }
17417: }
17418: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17419: if ($type eq 'default') {
17420: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17421: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17422: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17423: } else {
17424: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17425: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17426: }
17427: } else {
17428: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17429: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17430: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17431: } else {
17432: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17433: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17434: }
17435: }
17436: }
17437: }
17438: }
17439: }
17440: if ($output ne '') {
17441: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17442: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 17443: }
1.160.6.5 raeburn 17444: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 17445: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 17446: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17447: } else {
17448: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 17449: if ($captchas{$savecaptcha{$type}}) {
17450: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 17451: } else {
17452: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
17453: }
17454: }
17455: } elsif ($type eq 'recaptchakeys') {
17456: my ($privkey,$pubkey);
1.160.6.34 raeburn 17457: if (ref($savecaptcha{$type}) eq 'HASH') {
17458: $pubkey = $savecaptcha{$type}{'public'};
17459: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 17460: }
17461: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17462: if (!$pubkey) {
17463: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17464: } else {
17465: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17466: }
17467: if (!$privkey) {
17468: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17469: } else {
17470: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17471: }
17472: $chgtext .= '</ul>';
1.160.6.69 raeburn 17473: } elsif ($type eq 'recaptchaversion') {
17474: if ($savecaptcha{'captcha'} eq 'recaptcha') {
17475: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
17476: }
1.160.6.34 raeburn 17477: } elsif ($type eq 'emailusername') {
17478: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 17479: if (@statuses) {
17480: foreach my $type (@statuses) {
1.160.6.35 raeburn 17481: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17482: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 17483: $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 17484: '<ul>';
17485: foreach my $field (@{$infofields}) {
17486: if ($cancreate{'emailusername'}{$type}{$field}) {
17487: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17488: }
17489: }
1.160.6.50 raeburn 17490: $chgtext .= '</ul>';
17491: } else {
1.160.6.93 raeburn 17492: $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 17493: }
17494: } else {
1.160.6.93 raeburn 17495: $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 17496: }
17497: }
17498: }
17499: }
17500: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 17501: my $numapprove = 0;
1.160.6.34 raeburn 17502: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17503: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17504: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 17505: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17506: $numapprove ++;
1.160.6.34 raeburn 17507: }
17508: }
1.43 raeburn 17509: }
1.160.6.93 raeburn 17510: unless ($numapprove) {
17511: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17512: }
1.34 raeburn 17513: }
1.160.6.34 raeburn 17514: if ($chgtext) {
17515: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17516: }
17517: }
17518: }
1.160.6.93 raeburn 17519: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17520: my ($emailrules,$emailruleorder) =
17521: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 17522: foreach my $type (@{$changes{'email_rule'}}) {
17523: if (ref($email_rule{$type}) eq 'ARRAY') {
17524: my $chgtext = '<ul>';
17525: foreach my $rule (@{$email_rule{$type}}) {
17526: if (ref($emailrules->{$rule}) eq 'HASH') {
17527: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17528: }
17529: }
17530: $chgtext .= '</ul>';
17531: my $typename;
17532: if (@types) {
17533: if ($type eq 'default') {
17534: $typename = $othertitle;
17535: } else {
17536: $typename = $usertypes{$type};
17537: }
17538: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17539: }
17540: if (@{$email_rule{$type}} > 0) {
17541: $resulttext .= '<li>'.
17542: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17543: $usertypes{$type}).
17544: $chgtext.
17545: '</li>';
17546: } else {
17547: $resulttext .= '<li>'.
17548: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
17549: '</li>'.
17550: &mt('(Affiliation: [_1])',$typename);
17551: }
1.43 raeburn 17552: }
17553: }
1.160.6.93 raeburn 17554: }
17555: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17556: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17557: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17558: my $chgtext = '<ul>';
17559: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17560: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17561: }
17562: $chgtext .= '</ul>';
17563: $resulttext .= '<li>'.
17564: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17565: $chgtext.
17566: '</li>';
17567: } else {
17568: $resulttext .= '<li>'.
17569: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17570: '</li>';
17571: }
1.43 raeburn 17572: }
17573: }
1.160.6.34 raeburn 17574: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17575: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17576: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17577: foreach my $type (@{$changes{'selfcreate'}}) {
17578: my $typename = $type;
1.160.6.93 raeburn 17579: if (keys(%usertypes) > 0) {
17580: if ($usertypes{$type} ne '') {
17581: $typename = $usertypes{$type};
1.28 raeburn 17582: }
17583: }
1.160.6.34 raeburn 17584: my @modifiable;
17585: $resulttext .= '<li>'.
17586: &mt('Self-creation of account by users with status: [_1]',
17587: '<span class="LC_cusr_emph">'.$typename.'</span>').
17588: ' - '.&mt('modifiable fields (if institutional data blank): ');
17589: foreach my $field (@fields) {
17590: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17591: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
17592: }
17593: }
17594: if (@modifiable > 0) {
17595: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17596: } else {
1.160.6.34 raeburn 17597: $resulttext .= &mt('none');
1.43 raeburn 17598: }
1.160.6.34 raeburn 17599: $resulttext .= '</li>';
1.28 raeburn 17600: }
1.160.6.34 raeburn 17601: $resulttext .= '</ul></li>';
1.28 raeburn 17602: }
1.27 raeburn 17603: $resulttext .= '</ul>';
1.160.6.93 raeburn 17604: my $cachetime = 24*60*60;
17605: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17606: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17607: if (ref($lastactref) eq 'HASH') {
17608: $lastactref->{'domdefaults'} = 1;
17609: }
1.27 raeburn 17610: } else {
1.160.6.34 raeburn 17611: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17612: }
17613: } else {
17614: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17615: &mt('An error occurred: [_1]',$putresult).'</span>';
17616: }
1.43 raeburn 17617: if ($warningmsg ne '') {
17618: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17619: }
1.23 raeburn 17620: return $resulttext;
17621: }
17622:
1.160.6.5 raeburn 17623: sub process_captcha {
1.160.6.104 raeburn 17624: my ($container,$changes,$newsettings,$currsettings) = @_;
17625: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 17626: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17627: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17628: $newsettings->{'captcha'} = 'original';
17629: }
1.160.6.104 raeburn 17630: my %current;
17631: if (ref($currsettings) eq 'HASH') {
17632: %current = %{$currsettings};
17633: }
17634: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 17635: if ($container eq 'cancreate') {
17636: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17637: push(@{$changes->{'cancreate'}},'captcha');
17638: } elsif (!defined($changes->{'cancreate'})) {
17639: $changes->{'cancreate'} = ['captcha'];
17640: }
1.160.6.102 raeburn 17641: } elsif ($container eq 'passwords') {
17642: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17643: } else {
17644: $changes->{'captcha'} = 1;
17645: }
17646: }
1.160.6.69 raeburn 17647: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 17648: if ($newsettings->{'captcha'} eq 'recaptcha') {
17649: $newpub = $env{'form.'.$container.'_recaptchapub'};
17650: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 17651: $newpub =~ s/[^\w\-]//g;
17652: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 17653: $newsettings->{'recaptchakeys'} = {
17654: public => $newpub,
17655: private => $newpriv,
17656: };
1.160.6.69 raeburn 17657: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17658: $newversion =~ s/\D//g;
17659: if ($newversion ne '2') {
17660: $newversion = 1;
17661: }
17662: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 17663: }
1.160.6.104 raeburn 17664: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17665: $currpub = $current{'recaptchakeys'}{'public'};
17666: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 17667: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17668: $newsettings->{'recaptchakeys'} = {
17669: public => '',
17670: private => '',
17671: }
17672: }
1.160.6.5 raeburn 17673: }
1.160.6.104 raeburn 17674: if ($current{'captcha'} eq 'recaptcha') {
17675: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 17676: if ($currversion ne '2') {
17677: $currversion = 1;
17678: }
17679: }
17680: if ($currversion ne $newversion) {
17681: if ($container eq 'cancreate') {
17682: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17683: push(@{$changes->{'cancreate'}},'recaptchaversion');
17684: } elsif (!defined($changes->{'cancreate'})) {
17685: $changes->{'cancreate'} = ['recaptchaversion'];
17686: }
1.160.6.102 raeburn 17687: } elsif ($container eq 'passwords') {
17688: $changes->{'reset'} = 1;
1.160.6.69 raeburn 17689: } else {
17690: $changes->{'recaptchaversion'} = 1;
17691: }
17692: }
1.160.6.5 raeburn 17693: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
17694: if ($container eq 'cancreate') {
17695: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17696: push(@{$changes->{'cancreate'}},'recaptchakeys');
17697: } elsif (!defined($changes->{'cancreate'})) {
17698: $changes->{'cancreate'} = ['recaptchakeys'];
17699: }
1.160.6.102 raeburn 17700: } elsif ($container eq 'passwords') {
17701: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17702: } else {
17703: $changes->{'recaptchakeys'} = 1;
17704: }
17705: }
17706: return;
17707: }
17708:
1.33 raeburn 17709: sub modify_usermodification {
17710: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 17711: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17712: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17713: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 17714: if ($key eq 'selfcreate') {
17715: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17716: } else {
17717: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17718: }
1.33 raeburn 17719: }
17720: }
1.160.6.118.2 25(raebu 17721:24): my @contexts = ('author','coauthor','course');
1.33 raeburn 17722: my %context_title = (
17723: author => 'In author context',
1.160.6.118.2 25(raebu 17724:24): coauthor => 'As co-author manager',
1.33 raeburn 17725: course => 'In course context',
17726: );
17727: my @fields = ('lastname','firstname','middlename','generation',
17728: 'permanentemail','id');
17729: my %roles = (
17730: author => ['ca','aa'],
1.160.6.118.2 25(raebu 17731:24): coauthor => ['ca','aa'],
1.33 raeburn 17732: course => ['st','ep','ta','in','cr'],
17733: );
17734: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17735: foreach my $context (@contexts) {
1.160.6.118.2 25(raebu 17736:24): my $prefix = 'canmodify';
17737:24): if ($context eq 'coauthor') {
17738:24): $prefix = 'cacanmodify';
17739:24): }
1.33 raeburn 17740: foreach my $role (@{$roles{$context}}) {
1.160.6.118.2 25(raebu 17741:24): my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 17742: foreach my $item (@fields) {
17743: if (grep(/^\Q$item\E$/,@modifiable)) {
17744: $modifyhash{$context}{$role}{$item} = 1;
17745: } else {
17746: $modifyhash{$context}{$role}{$item} = 0;
17747: }
17748: }
17749: }
17750: if (ref($curr_usermodification{$context}) eq 'HASH') {
17751: foreach my $role (@{$roles{$context}}) {
17752: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17753: foreach my $field (@fields) {
17754: if ($modifyhash{$context}{$role}{$field} ne
17755: $curr_usermodification{$context}{$role}{$field}) {
17756: push(@{$changes{$context}},$role);
17757: last;
17758: }
17759: }
17760: }
17761: }
17762: } else {
17763: foreach my $context (@contexts) {
17764: foreach my $role (@{$roles{$context}}) {
17765: push(@{$changes{$context}},$role);
17766: }
17767: }
17768: }
17769: }
17770: my %usermodification_hash = (
17771: usermodification => \%modifyhash,
17772: );
17773: my $putresult = &Apache::lonnet::put_dom('configuration',
17774: \%usermodification_hash,$dom);
17775: if ($putresult eq 'ok') {
17776: if (keys(%changes) > 0) {
17777: $resulttext = &mt('Changes made: ').'<ul>';
17778: foreach my $context (@contexts) {
17779: if (ref($changes{$context}) eq 'ARRAY') {
17780: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17781: if (ref($changes{$context}) eq 'ARRAY') {
17782: foreach my $role (@{$changes{$context}}) {
17783: my $rolename;
1.160.6.34 raeburn 17784: if ($role eq 'cr') {
17785: $rolename = &mt('Custom');
1.33 raeburn 17786: } else {
1.160.6.34 raeburn 17787: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17788: }
17789: my @modifiable;
1.160.6.34 raeburn 17790: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17791: foreach my $field (@fields) {
17792: if ($modifyhash{$context}{$role}{$field}) {
17793: push(@modifiable,$fieldtitles{$field});
17794: }
17795: }
17796: if (@modifiable > 0) {
17797: $resulttext .= join(', ',@modifiable);
17798: } else {
17799: $resulttext .= &mt('none');
17800: }
17801: $resulttext .= '</li>';
17802: }
17803: $resulttext .= '</ul></li>';
17804: }
17805: }
17806: }
17807: $resulttext .= '</ul>';
17808: } else {
17809: $resulttext = &mt('No changes made to user modification settings');
17810: }
17811: } else {
17812: $resulttext = '<span class="LC_error">'.
17813: &mt('An error occurred: [_1]',$putresult).'</span>';
17814: }
17815: return $resulttext;
17816: }
17817:
1.43 raeburn 17818: sub modify_defaults {
1.160.6.27 raeburn 17819: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17820: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 17821: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 17822: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 17823: 'portal_def');
1.160.6.118.2 14(raebu 17824:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17825: foreach my $item (@items) {
17826: $newvalues{$item} = $env{'form.'.$item};
17827: if ($item eq 'auth_def') {
17828: if ($newvalues{$item} ne '') {
17829: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17830: push(@errors,$item);
17831: }
17832: }
17833: } elsif ($item eq 'lang_def') {
17834: if ($newvalues{$item} ne '') {
17835: if ($newvalues{$item} =~ /^(\w+)/) {
17836: my $langcode = $1;
1.103 raeburn 17837: if ($langcode ne 'x_chef') {
17838: if (code2language($langcode) eq '') {
17839: push(@errors,$item);
17840: }
1.43 raeburn 17841: }
17842: } else {
17843: push(@errors,$item);
17844: }
17845: }
1.54 raeburn 17846: } elsif ($item eq 'timezone_def') {
17847: if ($newvalues{$item} ne '') {
1.62 raeburn 17848: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17849: push(@errors,$item);
17850: }
17851: }
1.68 raeburn 17852: } elsif ($item eq 'datelocale_def') {
17853: if ($newvalues{$item} ne '') {
17854: my @datelocale_ids = DateTime::Locale->ids();
17855: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17856: push(@errors,$item);
17857: }
17858: }
1.141 raeburn 17859: } elsif ($item eq 'portal_def') {
17860: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 17861: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])\/?$/) {
17862:23): foreach my $field ('email','web') {
17863:23): if ($env{'form.'.$item.'_'.$field}) {
17864:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17865:23): }
17866:23): }
17867:23): } else {
1.141 raeburn 17868: push(@errors,$item);
17869: }
17870: }
1.43 raeburn 17871: }
17872: if (grep(/^\Q$item\E$/,@errors)) {
17873: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 17874:23): if ($item eq 'portal_def') {
17875:23): if ($domdefaults{$item}) {
17876:23): foreach my $field ('email','web') {
17877:23): if (exists($domdefaults{$item.'_'.$field})) {
17878:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17879:23): }
17880:23): }
17881:23): }
17882:23): }
1.43 raeburn 17883: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17884: $changes{$item} = 1;
17885: }
1.160.6.118.2 12(raebu 17886:23): if ($item eq 'portal_def') {
17887:23): unless (grep(/^\Q$item\E$/,@errors)) {
17888:23): if ($newvalues{$item} eq '') {
17889:23): foreach my $field ('email','web') {
17890:23): if (exists($domdefaults{$item.'_'.$field})) {
17891:23): delete($domdefaults{$item.'_'.$field});
17892:23): }
17893:23): }
17894:23): } else {
17895:23): unless ($changes{$item}) {
17896:23): foreach my $field ('email','web') {
17897:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17898:23): $changes{$item} = 1;
17899:23): last;
17900:23): }
17901:23): }
17902:23): }
17903:23): foreach my $field ('email','web') {
17904:23): if ($newvalues{$item.'_'.$field}) {
17905:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17906:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
17907:23): delete($domdefaults{$item.'_'.$field});
17908:23): }
17909:23): }
17910:23): }
17911:23): }
17912:23): }
1.72 raeburn 17913: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17914: }
1.160.6.98 raeburn 17915: my %staticdefaults = (
17916: 'intauth_cost' => 10,
17917: 'intauth_check' => 0,
17918: 'intauth_switch' => 0,
17919: );
17920: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17921: if (exists($domdefaults{$item})) {
17922: $newvalues{$item} = $domdefaults{$item};
17923: } else {
17924: $newvalues{$item} = $staticdefaults{$item};
17925: }
17926: }
1.160.6.118.2 8(raebur 17927:2): my ($unamemaprules,$ruleorder);
17928:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17929:2): if (@possunamemaprules) {
17930:2): ($unamemaprules,$ruleorder) =
17931:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
17932:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17933:2): if (@{$ruleorder} > 0) {
17934:2): my %possrules;
17935:2): map { $possrules{$_} = 1; } @possunamemaprules;
17936:2): foreach my $rule (@{$ruleorder}) {
17937:2): if ($possrules{$rule}) {
17938:2): push(@{$newvalues{'unamemap_rule'}},$rule);
17939:2): }
17940:2): }
17941:2): }
17942:2): }
17943:2): }
17944:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17945:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17946:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17947:2): $newvalues{'unamemap_rule'});
17948:2): if (@rulediffs) {
17949:2): $changes{'unamemap_rule'} = 1;
17950:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17951:2): }
17952:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17953:2): $changes{'unamemap_rule'} = 1;
17954:2): delete($domdefaults{'unamemap_rule'});
17955:2): }
17956:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17957:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
17958:2): $changes{'unamemap_rule'} = 1;
17959:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17960:2): }
17961:2): }
1.43 raeburn 17962: my %defaults_hash = (
1.72 raeburn 17963: defaults => \%newvalues,
17964: );
1.43 raeburn 17965: my $title = &defaults_titles();
1.160.6.40 raeburn 17966:
17967: my $currinststatus;
17968: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17969: $currinststatus = $domconfig{'inststatus'};
17970: } else {
17971: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17972: $currinststatus = {
17973: inststatustypes => $usertypes,
17974: inststatusorder => $types,
17975: inststatusguest => [],
17976: };
17977: }
17978: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17979: my @allpos;
17980: my %alltypes;
1.160.6.93 raeburn 17981: my @inststatusguest;
17982: if (ref($currinststatus) eq 'HASH') {
17983: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17984: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17985: unless (grep(/^\Q$type\E$/,@todelete)) {
17986: push(@inststatusguest,$type);
17987: }
17988: }
17989: }
17990: }
17991: my ($currtitles,$currorder);
1.160.6.40 raeburn 17992: if (ref($currinststatus) eq 'HASH') {
17993: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17994: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17995: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17996: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17997: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17998: }
17999: }
18000: unless (grep(/^\Q$type\E$/,@todelete)) {
18001: my $position = $env{'form.inststatus_pos_'.$type};
18002: $position =~ s/\D+//g;
18003: $allpos[$position] = $type;
18004: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18005: $alltypes{$type} =~ s/`//g;
18006: }
18007: }
18008: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18009: $currtitles =~ s/,$//;
18010: }
18011: }
18012: if ($env{'form.addinststatus'}) {
18013: my $newtype = $env{'form.addinststatus'};
18014: $newtype =~ s/\W//g;
18015: unless (exists($alltypes{$newtype})) {
18016: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18017: $alltypes{$newtype} =~ s/`//g;
18018: my $position = $env{'form.addinststatus_pos'};
18019: $position =~ s/\D+//g;
18020: if ($position ne '') {
18021: $allpos[$position] = $newtype;
18022: }
18023: }
18024: }
1.160.6.93 raeburn 18025: my @orderedstatus;
1.160.6.40 raeburn 18026: foreach my $type (@allpos) {
18027: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18028: push(@orderedstatus,$type);
18029: }
18030: }
18031: foreach my $type (keys(%alltypes)) {
18032: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18033: delete($alltypes{$type});
18034: }
18035: }
18036: $defaults_hash{'inststatus'} = {
18037: inststatustypes => \%alltypes,
18038: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 18039: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 18040: };
18041: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18042: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18043: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18044: }
18045: }
18046: if ($currorder ne join(',',@orderedstatus)) {
18047: $changes{'inststatus'}{'inststatusorder'} = 1;
18048: }
18049: my $newtitles;
18050: foreach my $item (@orderedstatus) {
18051: $newtitles .= $alltypes{$item}.',';
18052: }
18053: $newtitles =~ s/,$//;
18054: if ($currtitles ne $newtitles) {
18055: $changes{'inststatus'}{'inststatustypes'} = 1;
18056: }
1.43 raeburn 18057: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18058: $dom);
18059: if ($putresult eq 'ok') {
18060: if (keys(%changes) > 0) {
18061: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 18062: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18063: 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";
18064: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 18065: if ($item eq 'inststatus') {
18066: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 18067: if (@orderedstatus) {
1.160.6.40 raeburn 18068: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18069: foreach my $type (@orderedstatus) {
18070: $resulttext .= $alltypes{$type}.', ';
18071: }
18072: $resulttext =~ s/, $//;
18073: $resulttext .= '</li>';
1.160.6.93 raeburn 18074: } else {
18075: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 18076: }
18077: }
1.160.6.118.2 8(raebur 18078:2): } elsif ($item eq 'unamemap_rule') {
18079:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
18080:2): my @rulenames;
18081:2): if (ref($unamemaprules) eq 'HASH') {
18082:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
18083:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
18084:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
18085:2): }
18086:2): }
18087:2): }
18088:2): if (@rulenames) {
18089:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
18090:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
18091:2): '</li>';
18092:2): } else {
14(raebu 18093:23): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
18094:23): }
8(raebur 18095:2): } else {
18096:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
18097:2): }
1.160.6.40 raeburn 18098: } else {
18099: my $value = $env{'form.'.$item};
18100: if ($value eq '') {
18101: $value = &mt('none');
18102: } elsif ($item eq 'auth_def') {
18103: my %authnames = &authtype_names();
18104: my %shortauth = (
18105: internal => 'int',
18106: krb4 => 'krb4',
18107: krb5 => 'krb5',
18108: localauth => 'loc',
1.160.6.118.2 14(raebu 18109:23): lti => 'lti',
1.160.6.40 raeburn 18110: );
18111: $value = $authnames{$shortauth{$value}};
18112: }
18113: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 18114:23): $mailmsgtext .= "$title->{$item} set to $value\n";
18115:23): if ($item eq 'portal_def') {
18116:23): if ($env{'form.'.$item} ne '') {
18117:23): foreach my $field ('email','web') {
18118:23): $value = $env{'form.'.$item.'_'.$field};
18119:23): if ($value) {
18120:23): $value = &mt('Yes');
18121:23): } else {
18122:23): $value = &mt('No');
18123:23): }
18124:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
18125:23): }
18126:23): }
18127:23): }
1.43 raeburn 18128: }
18129: }
18130: $resulttext .= '</ul>';
18131: $mailmsgtext .= "\n";
18132: my $cachetime = 24*60*60;
1.72 raeburn 18133: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 18134: if (ref($lastactref) eq 'HASH') {
18135: $lastactref->{'domdefaults'} = 1;
18136: }
1.68 raeburn 18137: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 18138: my $notify = 1;
18139: if (ref($domconfig{'contacts'}) eq 'HASH') {
18140: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18141: $notify = 0;
18142: }
18143: }
18144: if ($notify) {
18145: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18146: "LON-CAPA Domain Settings Change - $dom",
18147: $mailmsgtext);
18148: }
1.54 raeburn 18149: }
1.43 raeburn 18150: } else {
1.54 raeburn 18151: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18152: }
18153: } else {
18154: $resulttext = '<span class="LC_error">'.
18155: &mt('An error occurred: [_1]',$putresult).'</span>';
18156: }
18157: if (@errors > 0) {
18158: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18159: foreach my $item (@errors) {
18160: $resulttext .= ' "'.$title->{$item}.'",';
18161: }
18162: $resulttext =~ s/,$//;
18163: }
18164: return $resulttext;
18165: }
18166:
1.46 raeburn 18167: sub modify_scantron {
1.160.6.24 raeburn 18168: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18169: my ($resulttext,%confhash,%changes,$errors);
18170: my $custom = 'custom.tab';
18171: my $default = 'default.tab';
18172: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 18173: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18174: &config_check($dom,$confname,$servadm);
18175: if ($env{'form.scantronformat.filename'} ne '') {
18176: my $error;
18177: if ($configuserok eq 'ok') {
18178: if ($switchserver) {
1.130 raeburn 18179: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18180: } else {
18181: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 18182:23): my $modified = [];
1.46 raeburn 18183: my ($result,$scantronurl) =
1.160.6.118.2 14(raebu 18184:23): &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
18185:23): $confname,'scantron','','',$custom,
18186:23): $modified);
1.46 raeburn 18187: if ($result eq 'ok') {
18188: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18189: $changes{'scantronformat'} = 1;
1.160.6.118.2 14(raebu 18190:23): &update_modify_urls($r,$modified);
1.46 raeburn 18191: } else {
18192: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18193: }
18194: } else {
18195: $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);
18196: }
18197: }
18198: } else {
18199: $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);
18200: }
18201: if ($error) {
18202: &Apache::lonnet::logthis($error);
18203: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18204: }
18205: }
1.48 raeburn 18206: if (ref($domconfig{'scantron'}) eq 'HASH') {
18207: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18208: if ($env{'form.scantronformat_del'}) {
18209: $confhash{'scantron'}{'scantronformat'} = '';
18210: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 18211: } else {
18212: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
18213: }
18214: }
18215: }
18216: my @options = ('hdr','pad','rem');
18217: my @fields = &scantroncsv_fields();
18218: my %titles = &scantronconfig_titles();
18219: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
18220: my ($newdat,$currdat,%newcol,%currcol);
18221: if (grep(/^dat$/,@formats)) {
18222: $confhash{'scantron'}{config}{dat} = 1;
18223: $newdat = 1;
18224: } else {
18225: $newdat = 0;
18226: }
18227: if (grep(/^csv$/,@formats)) {
18228: my %bynum;
18229: foreach my $field (@fields) {
18230: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18231: my $posscol = $1;
18232: if (($posscol < 20) && (!$bynum{$posscol})) {
18233: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
18234: $bynum{$posscol} = $field;
18235: $newcol{$field} = $posscol;
18236: }
18237: }
18238: }
18239: if (keys(%newcol)) {
18240: foreach my $option (@options) {
18241: if ($env{'form.scantroncsv_'.$option}) {
18242: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18243: }
18244: }
18245: }
18246: }
18247: $currdat = 1;
18248: if (ref($domconfig{'scantron'}) eq 'HASH') {
18249: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
18250: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
18251: $currdat = 0;
18252: }
18253: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18254: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18255: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18256: }
18257: }
18258: }
18259: }
18260: if ($currdat != $newdat) {
18261: $changes{'config'} = 1;
18262: } else {
18263: foreach my $field (@fields) {
18264: if ($currcol{$field} ne '') {
18265: if ($currcol{$field} ne $newcol{$field}) {
18266: $changes{'config'} = 1;
18267: last;
18268: }
18269: } elsif ($newcol{$field} ne '') {
18270: $changes{'config'} = 1;
18271: last;
1.46 raeburn 18272: }
18273: }
18274: }
18275: if (keys(%confhash) > 0) {
18276: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18277: $dom);
18278: if ($putresult eq 'ok') {
18279: if (keys(%changes) > 0) {
1.48 raeburn 18280: if (ref($confhash{'scantron'}) eq 'HASH') {
18281: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 18282: if ($changes{'scantronformat'}) {
18283: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18284: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18285: } else {
18286: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18287: }
18288: }
18289: if ($changes{'config'}) {
18290: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18291: if ($confhash{'scantron'}{'config'}{'dat'}) {
18292: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18293: }
18294: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18295: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18296: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18297: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18298: foreach my $field (@fields) {
18299: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18300: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18301: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18302: }
18303: }
18304: $resulttext .= '</ul></li>';
18305: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18306: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18307: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18308: foreach my $option (@options) {
18309: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18310: $resulttext .= '<li>'.$titles{$option}.'</li>';
18311: }
18312: }
18313: $resulttext .= '</ul></li>';
18314: }
18315: }
18316: }
18317: }
18318: }
18319: } else {
18320: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18321: }
1.46 raeburn 18322: }
1.48 raeburn 18323: $resulttext .= '</ul>';
18324: } else {
1.130 raeburn 18325: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18326: }
18327: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 18328: if (ref($lastactref) eq 'HASH') {
18329: $lastactref->{'domainconfig'} = 1;
18330: }
1.46 raeburn 18331: } else {
1.160.6.97 raeburn 18332: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18333: }
18334: } else {
18335: $resulttext = '<span class="LC_error">'.
18336: &mt('An error occurred: [_1]',$putresult).'</span>';
18337: }
18338: } else {
1.160.6.97 raeburn 18339: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18340: }
18341: if ($errors) {
1.160.6.118.2 14(raebu 18342:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18343:23): $errors.'</ul></p>';
1.46 raeburn 18344: }
18345: return $resulttext;
18346: }
18347:
1.48 raeburn 18348: sub modify_coursecategories {
1.160.6.43 raeburn 18349: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18350: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18351: $cathash);
1.48 raeburn 18352: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 18353: my @catitems = ('unauth','auth');
18354: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18355: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18356: $cathash = $domconfig{'coursecategories'}{'cats'};
18357: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18358: $changes{'togglecats'} = 1;
18359: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18360: }
18361: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18362: $changes{'categorize'} = 1;
18363: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18364: }
1.120 raeburn 18365: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18366: $changes{'togglecatscomm'} = 1;
18367: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18368: }
18369: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18370: $changes{'categorizecomm'} = 1;
18371: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
18372: }
1.160.6.42 raeburn 18373: foreach my $item (@catitems) {
18374: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18375: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18376: $changes{$item} = 1;
18377: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18378: }
18379: }
18380: }
1.57 raeburn 18381: } else {
18382: $changes{'togglecats'} = 1;
18383: $changes{'categorize'} = 1;
1.124 raeburn 18384: $changes{'togglecatscomm'} = 1;
18385: $changes{'categorizecomm'} = 1;
1.87 raeburn 18386: $domconfig{'coursecategories'} = {
18387: togglecats => $env{'form.togglecats'},
18388: categorize => $env{'form.categorize'},
1.124 raeburn 18389: togglecatscomm => $env{'form.togglecatscomm'},
18390: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 18391: };
1.160.6.42 raeburn 18392: foreach my $item (@catitems) {
18393: if ($env{'form.coursecat_'.$item} ne 'std') {
18394: $changes{$item} = 1;
18395: }
18396: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18397: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18398: }
18399: }
1.57 raeburn 18400: }
18401: if (ref($cathash) eq 'HASH') {
18402: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18403: push (@deletecategory,'instcode::0');
18404: }
1.120 raeburn 18405: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18406: push(@deletecategory,'communities::0');
18407: }
1.48 raeburn 18408: }
1.57 raeburn 18409: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18410: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18411: if (@deletecategory > 0) {
18412: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18413: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18414: foreach my $item (@deletecategory) {
1.57 raeburn 18415: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18416: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18417: $deletions{$item} = 1;
1.57 raeburn 18418: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18419: }
18420: }
18421: }
1.57 raeburn 18422: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18423: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18424: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18425: $reorderings{$item} = 1;
1.57 raeburn 18426: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18427: }
18428: if ($env{'form.addcategory_name_'.$item} ne '') {
18429: my $newcat = $env{'form.addcategory_name_'.$item};
18430: my $newdepth = $depth+1;
18431: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18432: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18433: $adds{$newitem} = 1;
18434: }
18435: if ($env{'form.subcat_'.$item} ne '') {
18436: my $newcat = $env{'form.subcat_'.$item};
18437: my $newdepth = $depth+1;
18438: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18439: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18440: $adds{$newitem} = 1;
18441: }
18442: }
18443: }
18444: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18445: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18446: my $newitem = 'instcode::0';
1.57 raeburn 18447: if ($cathash->{$newitem} eq '') {
18448: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18449: $adds{$newitem} = 1;
18450: }
18451: } else {
18452: my $newitem = 'instcode::0';
1.57 raeburn 18453: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18454: $adds{$newitem} = 1;
18455: }
18456: }
1.120 raeburn 18457: if ($env{'form.communities'} eq '1') {
18458: if (ref($cathash) eq 'HASH') {
18459: my $newitem = 'communities::0';
18460: if ($cathash->{$newitem} eq '') {
18461: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18462: $adds{$newitem} = 1;
18463: }
18464: } else {
18465: my $newitem = 'communities::0';
18466: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18467: $adds{$newitem} = 1;
18468: }
18469: }
1.48 raeburn 18470: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18471: if (($env{'form.addcategory_name'} ne 'instcode') &&
18472: ($env{'form.addcategory_name'} ne 'communities')) {
18473: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18474: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18475: $adds{$newitem} = 1;
18476: }
1.48 raeburn 18477: }
1.57 raeburn 18478: my $putresult;
1.48 raeburn 18479: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18480: if (keys(%deletions) > 0) {
18481: foreach my $key (keys(%deletions)) {
18482: if ($predelallitems{$key} ne '') {
18483: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18484: }
18485: }
18486: }
18487: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18488: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18489: if (ref($chkcats[0]) eq 'ARRAY') {
18490: my $depth = 0;
18491: my $chg = 0;
18492: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18493: my $name = $chkcats[0][$i];
18494: my $item;
18495: if ($name eq '') {
18496: $chg ++;
18497: } else {
18498: $item = &escape($name).'::0';
18499: if ($chg) {
1.57 raeburn 18500: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18501: }
18502: $depth ++;
1.57 raeburn 18503: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18504: $depth --;
18505: }
18506: }
18507: }
1.57 raeburn 18508: }
18509: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18510: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18511: if ($putresult eq 'ok') {
1.57 raeburn 18512: my %title = (
1.120 raeburn 18513: togglecats => 'Show/Hide a course in catalog',
18514: categorize => 'Assign a category to a course',
18515: togglecatscomm => 'Show/Hide a community in catalog',
18516: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18517: );
18518: my %level = (
1.120 raeburn 18519: dom => 'set in Domain ("Modify Course/Community")',
18520: crs => 'set in Course ("Course Configuration")',
18521: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 18522: none => 'No catalog',
18523: std => 'Standard catalog',
18524: domonly => 'Domain-only catalog',
18525: codesrch => 'Code search form',
1.57 raeburn 18526: );
1.48 raeburn 18527: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18528: if ($changes{'togglecats'}) {
18529: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18530: }
18531: if ($changes{'categorize'}) {
18532: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18533: }
1.120 raeburn 18534: if ($changes{'togglecatscomm'}) {
18535: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18536: }
18537: if ($changes{'categorizecomm'}) {
18538: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18539: }
1.160.6.42 raeburn 18540: if ($changes{'unauth'}) {
18541: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18542: }
18543: if ($changes{'auth'}) {
18544: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18545: }
1.57 raeburn 18546: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18547: my $cathash;
18548: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18549: $cathash = $domconfig{'coursecategories'}{'cats'};
18550: } else {
18551: $cathash = {};
18552: }
18553: my (@cats,@trails,%allitems);
18554: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18555: if (keys(%deletions) > 0) {
18556: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18557: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18558: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18559: }
18560: $resulttext .= '</ul></li>';
18561: }
18562: if (keys(%reorderings) > 0) {
18563: my %sort_by_trail;
18564: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18565: foreach my $key (keys(%reorderings)) {
18566: if ($allitems{$key} ne '') {
18567: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18568: }
1.48 raeburn 18569: }
1.57 raeburn 18570: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18571: $resulttext .= '<li>'.$trails[$trail].'</li>';
18572: }
18573: $resulttext .= '</ul></li>';
1.48 raeburn 18574: }
1.57 raeburn 18575: if (keys(%adds) > 0) {
18576: my %sort_by_trail;
18577: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18578: foreach my $key (keys(%adds)) {
18579: if ($allitems{$key} ne '') {
18580: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18581: }
18582: }
18583: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18584: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18585: }
1.57 raeburn 18586: $resulttext .= '</ul></li>';
1.48 raeburn 18587: }
1.160.6.92 raeburn 18588: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18589: if (ref($lastactref) eq 'HASH') {
18590: $lastactref->{'cats'} = 1;
18591: }
1.48 raeburn 18592: }
18593: $resulttext .= '</ul>';
1.160.6.43 raeburn 18594: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 18595: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18596: if ($changes{'auth'}) {
18597: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18598: }
18599: if ($changes{'unauth'}) {
18600: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18601: }
18602: my $cachetime = 24*60*60;
18603: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 18604: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 18605: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 18606: }
18607: }
1.48 raeburn 18608: } else {
18609: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18610: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18611: }
18612: } else {
1.120 raeburn 18613: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18614: }
18615: return $resulttext;
18616: }
18617:
1.69 raeburn 18618: sub modify_serverstatuses {
18619: my ($dom,%domconfig) = @_;
18620: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18621: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18622: %currserverstatus = %{$domconfig{'serverstatuses'}};
18623: }
18624: my @pages = &serverstatus_pages();
18625: foreach my $type (@pages) {
18626: $newserverstatus{$type}{'namedusers'} = '';
18627: $newserverstatus{$type}{'machines'} = '';
18628: if (defined($env{'form.'.$type.'_namedusers'})) {
18629: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18630: my @okusers;
18631: foreach my $user (@users) {
18632: my ($uname,$udom) = split(/:/,$user);
18633: if (($udom =~ /^$match_domain$/) &&
18634: (&Apache::lonnet::domain($udom)) &&
18635: ($uname =~ /^$match_username$/)) {
18636: if (!grep(/^\Q$user\E/,@okusers)) {
18637: push(@okusers,$user);
18638: }
18639: }
18640: }
18641: if (@okusers > 0) {
18642: @okusers = sort(@okusers);
18643: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18644: }
18645: }
18646: if (defined($env{'form.'.$type.'_machines'})) {
18647: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18648: my @okmachines;
18649: foreach my $ip (@machines) {
18650: my @parts = split(/\./,$ip);
18651: next if (@parts < 4);
18652: my $badip = 0;
18653: for (my $i=0; $i<4; $i++) {
18654: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18655: $badip = 1;
18656: last;
18657: }
18658: }
18659: if (!$badip) {
18660: push(@okmachines,$ip);
18661: }
18662: }
18663: @okmachines = sort(@okmachines);
18664: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18665: }
18666: }
18667: my %serverstatushash = (
18668: serverstatuses => \%newserverstatus,
18669: );
18670: foreach my $type (@pages) {
1.83 raeburn 18671: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18672: my (@current,@new);
1.83 raeburn 18673: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18674: if ($currserverstatus{$type}{$setting} ne '') {
18675: @current = split(/,/,$currserverstatus{$type}{$setting});
18676: }
18677: }
18678: if ($newserverstatus{$type}{$setting} ne '') {
18679: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18680: }
18681: if (@current > 0) {
18682: if (@new > 0) {
18683: foreach my $item (@current) {
18684: if (!grep(/^\Q$item\E$/,@new)) {
18685: $changes{$type}{$setting} = 1;
1.82 raeburn 18686: last;
18687: }
18688: }
1.84 raeburn 18689: foreach my $item (@new) {
18690: if (!grep(/^\Q$item\E$/,@current)) {
18691: $changes{$type}{$setting} = 1;
18692: last;
1.82 raeburn 18693: }
18694: }
18695: } else {
1.83 raeburn 18696: $changes{$type}{$setting} = 1;
1.69 raeburn 18697: }
1.83 raeburn 18698: } elsif (@new > 0) {
18699: $changes{$type}{$setting} = 1;
1.69 raeburn 18700: }
18701: }
18702: }
18703: if (keys(%changes) > 0) {
1.81 raeburn 18704: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18705: my $putresult = &Apache::lonnet::put_dom('configuration',
18706: \%serverstatushash,$dom);
18707: if ($putresult eq 'ok') {
18708: $resulttext .= &mt('Changes made:').'<ul>';
18709: foreach my $type (@pages) {
1.84 raeburn 18710: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18711: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18712: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18713: if ($newserverstatus{$type}{'namedusers'} eq '') {
18714: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18715: } else {
18716: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18717: }
1.84 raeburn 18718: }
18719: if ($changes{$type}{'machines'}) {
1.69 raeburn 18720: if ($newserverstatus{$type}{'machines'} eq '') {
18721: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18722: } else {
18723: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18724: }
18725:
18726: }
18727: $resulttext .= '</ul></li>';
18728: }
18729: }
18730: $resulttext .= '</ul>';
18731: } else {
18732: $resulttext = '<span class="LC_error">'.
18733: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18734:
18735: }
18736: } else {
18737: $resulttext = &mt('No changes made to access to server status pages');
18738: }
18739: return $resulttext;
18740: }
18741:
1.118 jms 18742: sub modify_helpsettings {
1.160.6.77 raeburn 18743: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 18744: my ($resulttext,$errors,%changes,%helphash);
18745: my %defaultchecked = ('submitbugs' => 'on');
18746: my @offon = ('off','on');
1.118 jms 18747: my @toggles = ('submitbugs');
1.160.6.77 raeburn 18748: my %current = ('submitbugs' => '',
18749: 'adhoc' => {},
18750: );
1.118 jms 18751: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 18752: %current = %{$domconfig{'helpsettings'}};
18753: }
1.160.6.77 raeburn 18754: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 18755: foreach my $item (@toggles) {
18756: if ($defaultchecked{$item} eq 'on') {
18757: if ($current{$item} eq '') {
18758: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 18759: $changes{$item} = 1;
18760: }
1.160.6.73 raeburn 18761: } elsif ($current{$item} ne $env{'form.'.$item}) {
18762: $changes{$item} = 1;
18763: }
18764: } elsif ($defaultchecked{$item} eq 'off') {
18765: if ($current{$item} eq '') {
18766: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 18767: $changes{$item} = 1;
18768: }
1.160.6.73 raeburn 18769: } elsif ($current{$item} ne $env{'form.'.$item}) {
18770: $changes{$item} = 1;
18771: }
18772: }
18773: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18774: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18775: }
18776: }
1.160.6.77 raeburn 18777: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 18778: my $confname = $dom.'-domainconfig';
18779: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 18780: my (@allpos,%newsettings,%changedprivs,$newrole);
18781: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 18782: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18783: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 18784: my %lt = &Apache::lonlocal::texthash(
18785: s => 'system',
18786: d => 'domain',
18787: order => 'Display order',
18788: access => 'Role usage',
1.160.6.79 raeburn 18789: all => 'All with domain helpdesk or helpdesk assistant role',
18790: dh => 'All with domain helpdesk role',
18791: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 18792: none => 'None',
18793: status => 'Determined based on institutional status',
18794: inc => 'Include all, but exclude specific personnel',
18795: exc => 'Exclude all, but include specific personnel',
18796: );
18797: for (my $num=0; $num<=$maxnum; $num++) {
18798: my ($prefix,$identifier,$rolename,%curr);
18799: if ($num == $maxnum) {
18800: next unless ($env{'form.newcusthelp'} == $maxnum);
18801: $identifier = 'custhelp'.$num;
18802: $prefix = 'helproles_'.$num;
18803: $rolename = $env{'form.custhelpname'.$num};
18804: $rolename=~s/[^A-Za-z0-9]//gs;
18805: next if ($rolename eq '');
18806: next if (exists($existing{'rolesdef_'.$rolename}));
18807: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18808: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18809: $newprivs{'c'},$confname,$dom);
18810: if ($result ne 'ok') {
18811: $errors .= '<li><span class="LC_error">'.
18812: &mt('An error occurred storing the new custom role: [_1]',
18813: $result).'</span></li>';
18814: next;
18815: } else {
18816: $changedprivs{$rolename} = \%newprivs;
18817: $newrole = $rolename;
18818: }
18819: } else {
18820: $prefix = 'helproles_'.$num;
18821: $rolename = $env{'form.'.$prefix};
18822: next if ($rolename eq '');
18823: next unless (exists($existing{'rolesdef_'.$rolename}));
18824: $identifier = 'custhelp'.$num;
18825: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18826: my %currprivs;
18827: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18828: split(/\_/,$existing{'rolesdef_'.$rolename});
18829: foreach my $level ('c','d','s') {
18830: if ($newprivs{$level} ne $currprivs{$level}) {
18831: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18832: $newprivs{'c'},$confname,$dom);
18833: if ($result ne 'ok') {
18834: $errors .= '<li><span class="LC_error">'.
18835: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18836: $rolename,$result).'</span></li>';
18837: } else {
18838: $changedprivs{$rolename} = \%newprivs;
18839: }
18840: last;
18841: }
18842: }
18843: if (ref($current{'adhoc'}) eq 'HASH') {
18844: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18845: %curr = %{$current{'adhoc'}{$rolename}};
18846: }
18847: }
18848: }
18849: my $newpos = $env{'form.'.$prefix.'_pos'};
18850: $newpos =~ s/\D+//g;
18851: $allpos[$newpos] = $rolename;
18852: my $newdesc = $env{'form.'.$prefix.'_desc'};
18853: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18854: if ($curr{'desc'}) {
18855: if ($curr{'desc'} ne $newdesc) {
18856: $changes{'customrole'}{$rolename}{'desc'} = 1;
18857: $newsettings{$rolename}{'desc'} = $newdesc;
18858: }
18859: } elsif ($newdesc ne '') {
18860: $changes{'customrole'}{$rolename}{'desc'} = 1;
18861: $newsettings{$rolename}{'desc'} = $newdesc;
18862: }
18863: my $access = $env{'form.'.$prefix.'_access'};
18864: if (grep(/^\Q$access\E$/,@accesstypes)) {
18865: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18866: if ($access eq 'status') {
18867: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18868: if (scalar(@statuses) == 0) {
18869: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18870: } else {
18871: my (@shownstatus,$numtypes);
18872: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18873: if (ref($types) eq 'ARRAY') {
18874: $numtypes = scalar(@{$types});
18875: foreach my $type (sort(@statuses)) {
18876: if ($type eq 'default') {
18877: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18878: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18879: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18880: push(@shownstatus,$usertypes->{$type});
18881: }
1.160.6.73 raeburn 18882: }
18883: }
1.160.6.77 raeburn 18884: if (grep(/^default$/,@statuses)) {
18885: push(@shownstatus,$othertitle);
18886: }
18887: if (scalar(@shownstatus) == 1+$numtypes) {
18888: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18889: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18890: } else {
18891: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18892: if (ref($curr{'status'}) eq 'ARRAY') {
18893: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18894: if (@diffs) {
18895: $changes{'customrole'}{$rolename}{$access} = 1;
18896: }
18897: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18898: $changes{'customrole'}{$rolename}{$access} = 1;
18899: }
18900: }
18901: }
18902: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18903: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18904: my @newspecstaff;
18905: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18906: foreach my $person (sort(@personnel)) {
18907: if ($domhelpdesk{$person}) {
18908: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18909: }
18910: }
18911: if (ref($curr{$access}) eq 'ARRAY') {
18912: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18913: if (@diffs) {
18914: $changes{'customrole'}{$rolename}{$access} = 1;
18915: }
18916: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18917: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 18918: }
1.160.6.77 raeburn 18919: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18920: my ($uname,$udom) = split(/:/,$person);
18921: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18922: }
18923: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 18924: }
1.160.6.77 raeburn 18925: } else {
18926: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18927: }
18928: unless ($curr{'access'} eq $access) {
18929: $changes{'customrole'}{$rolename}{'access'} = 1;
18930: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 18931: }
18932: }
1.160.6.77 raeburn 18933: if (@allpos > 0) {
18934: my $idx = 0;
18935: foreach my $rolename (@allpos) {
18936: if ($rolename ne '') {
18937: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18938: if (ref($current{'adhoc'}) eq 'HASH') {
18939: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18940: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18941: $changes{'customrole'}{$rolename}{'order'} = 1;
18942: $newsettings{$rolename}{'order'} = $idx+1;
18943: }
18944: }
1.160.6.73 raeburn 18945: }
1.160.6.77 raeburn 18946: $idx ++;
1.122 jms 18947: }
18948: }
1.118 jms 18949: }
1.123 jms 18950: my $putresult;
18951: if (keys(%changes) > 0) {
1.160.6.5 raeburn 18952: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18953: if ($putresult eq 'ok') {
1.160.6.77 raeburn 18954: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18955: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18956: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18957: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18958: }
18959: }
18960: my $cachetime = 24*60*60;
18961: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18962: if (ref($lastactref) eq 'HASH') {
18963: $lastactref->{'domdefaults'} = 1;
18964: }
18965: } else {
18966: $errors .= '<li><span class="LC_error">'.
18967: &mt('An error occurred storing the settings: [_1]',
18968: $putresult).'</span></li>';
18969: }
18970: }
18971: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18972: $resulttext = &mt('Changes made:').'<ul>';
18973: my (%shownprivs,@levelorder);
18974: @levelorder = ('c','d','s');
18975: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 18976: foreach my $item (sort(keys(%changes))) {
18977: if ($item eq 'submitbugs') {
18978: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18979: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18980: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 18981: } elsif ($item eq 'customrole') {
18982: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 18983: my @keyorder = ('order','desc','access','status','exc','inc');
18984: my %keytext = &Apache::lonlocal::texthash(
18985: order => 'Order',
18986: desc => 'Role description',
18987: access => 'Role usage',
1.160.6.83 raeburn 18988: status => 'Allowed institutional types',
1.160.6.77 raeburn 18989: exc => 'Allowed personnel',
18990: inc => 'Disallowed personnel',
18991: );
1.160.6.73 raeburn 18992: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 18993: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18994: if ($role eq $newrole) {
18995: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18996: $role).'<ul>';
18997: } else {
18998: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18999: $role).'<ul>';
19000: }
19001: foreach my $key (@keyorder) {
19002: if ($changes{'customrole'}{$role}{$key}) {
19003: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19004: $keytext{$key},$newsettings{$role}{$key}).
19005: '</li>';
19006: }
19007: }
19008: if (ref($changedprivs{$role}) eq 'HASH') {
19009: $shownprivs{$role} = 1;
19010: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19011: foreach my $level (@levelorder) {
19012: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19013: next if ($item eq '');
19014: my ($priv) = split(/\&/,$item,2);
19015: if (&Apache::lonnet::plaintext($priv)) {
19016: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19017: unless ($level eq 'c') {
19018: $resulttext .= ' ('.$lt{$level}.')';
19019: }
19020: $resulttext .= '</li>';
19021: }
19022: }
19023: }
19024: $resulttext .= '</ul>';
19025: }
19026: $resulttext .= '</ul></li>';
19027: }
1.160.6.73 raeburn 19028: }
19029: }
1.160.6.5 raeburn 19030: }
19031: }
19032: }
1.160.6.77 raeburn 19033: if (keys(%changedprivs)) {
19034: foreach my $role (sort(keys(%changedprivs))) {
19035: unless ($shownprivs{$role}) {
19036: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19037: $role).'<ul>'.
19038: '<li>'.&mt('Privileges set to :').'<ul>';
19039: foreach my $level (@levelorder) {
19040: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19041: next if ($item eq '');
19042: my ($priv) = split(/\&/,$item,2);
19043: if (&Apache::lonnet::plaintext($priv)) {
19044: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19045: unless ($level eq 'c') {
19046: $resulttext .= ' ('.$lt{$level}.')';
19047: }
19048: $resulttext .= '</li>';
19049: }
19050: }
19051: }
19052: $resulttext .= '</ul></li></ul></li>';
19053: }
19054: }
19055: }
19056: $resulttext .= '</ul>';
19057: } else {
19058: $resulttext = &mt('No changes made to help settings');
1.118 jms 19059: }
19060: if ($errors) {
1.160.6.5 raeburn 19061: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 19062: $errors.'</ul>';
1.118 jms 19063: }
19064: return $resulttext;
19065: }
19066:
1.121 raeburn 19067: sub modify_coursedefaults {
1.160.6.27 raeburn 19068: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19069: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 19070: my %defaultchecked = (
19071: 'uselcmath' => 'on',
1.160.6.115 raeburn 19072: 'usejsme' => 'on',
19073: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 19074:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 19075: );
1.160.6.118.2 4(raebur 19076:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 19077: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.118.2 15(raebu 19078:23): 'uploadquota_community','uploadquota_textbook','coursequota_official',
19079:23): 'coursequota_unofficial','coursequota_community','coursequota_textbook',
19080:23): 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19081:23): 'mysqltables_textbook');
1.160.6.30 raeburn 19082: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 19083: my %staticdefaults = (
19084: anonsurvey_threshold => 10,
19085: uploadquota => 500,
1.160.6.118.2 15(raebu 19086:23): coursequota => 20,
1.160.6.57 raeburn 19087: postsubmit => 60,
1.160.6.70 raeburn 19088: mysqltables => 172800,
1.160.6.118.2 14(raebu 19089:23): domexttool => 1,
22(raebu 19090:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 19091: );
1.160.6.90 raeburn 19092: my %texoptions = (
19093: MathJax => 'MathJax',
19094: mimetex => &mt('Convert to Images'),
19095: tth => &mt('TeX to HTML'),
19096: );
1.160.6.118.2 22(raebu 19097:24):
19098:24): my @editors = ('edit','xml','daxe');
19099:24): my %editornames = &crseditor_titles();
19100:24):
1.121 raeburn 19101: $defaultshash{'coursedefaults'} = {};
19102:
19103: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19104: if ($domconfig{'coursedefaults'} eq '') {
19105: $domconfig{'coursedefaults'} = {};
19106: }
19107: }
19108:
19109: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19110: foreach my $item (@toggles) {
19111: if ($defaultchecked{$item} eq 'on') {
19112: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19113: ($env{'form.'.$item} eq '0')) {
19114: $changes{$item} = 1;
1.160.6.16 raeburn 19115: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19116: $changes{$item} = 1;
19117: }
19118: } elsif ($defaultchecked{$item} eq 'off') {
19119: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19120: ($env{'form.'.$item} eq '1')) {
19121: $changes{$item} = 1;
19122: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19123: $changes{$item} = 1;
19124: }
19125: }
19126: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19127: }
1.160.6.21 raeburn 19128: foreach my $item (@numbers) {
19129: my ($currdef,$newdef);
1.160.6.26 raeburn 19130: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 19131: if ($item eq 'anonsurvey_threshold') {
19132: $currdef = $domconfig{'coursedefaults'}{$item};
19133: $newdef =~ s/\D//g;
19134: if ($newdef eq '' || $newdef < 1) {
19135: $newdef = 1;
19136: }
19137: $defaultshash{'coursedefaults'}{$item} = $newdef;
19138: } else {
1.160.6.118.2 15(raebu 19139:23): my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.160.6.70 raeburn 19140: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19141: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 19142: }
19143: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 19144: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 19145: }
19146: if ($currdef ne $newdef) {
19147: if ($item eq 'anonsurvey_threshold') {
19148: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19149: $changes{$item} = 1;
19150: }
1.160.6.118.2 15(raebu 19151:23): } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.160.6.70 raeburn 19152: my $setting = $1;
19153: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19154: $changes{$setting} = 1;
1.160.6.21 raeburn 19155: }
19156: }
1.139 raeburn 19157: }
19158: }
1.160.6.90 raeburn 19159: my $texengine;
19160: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19161: $texengine = $env{'form.texengine'};
19162: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19163: if ($currdef eq '') {
19164: unless ($texengine eq $Apache::lonnet::deftex) {
19165: $changes{'texengine'} = 1;
19166: }
19167: } elsif ($currdef ne $texengine) {
19168: $changes{'texengine'} = 1;
19169: }
19170: }
19171: if ($texengine ne '') {
19172: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19173: }
1.160.6.64 raeburn 19174: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19175: my @currclonecode;
19176: if (ref($currclone) eq 'HASH') {
19177: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19178: @currclonecode = @{$currclone->{'instcode'}};
19179: }
19180: }
19181: my $newclone;
19182: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
19183: $newclone = $env{'form.canclone'};
19184: }
19185: if ($newclone eq 'instcode') {
19186: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19187: my (%codedefaults,@code_order,@clonecode);
19188: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19189: \@code_order);
19190: foreach my $item (@code_order) {
19191: if (grep(/^\Q$item\E$/,@newcodes)) {
19192: push(@clonecode,$item);
19193: }
19194: }
19195: if (@clonecode) {
19196: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19197: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19198: if (@diffs) {
19199: $changes{'canclone'} = 1;
19200: }
19201: } else {
19202: $newclone eq '';
19203: }
19204: } elsif ($newclone ne '') {
19205: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19206: }
19207: if ($newclone ne $currclone) {
19208: $changes{'canclone'} = 1;
19209: }
1.160.6.57 raeburn 19210: my %credits;
19211: foreach my $type (@types) {
19212: unless ($type eq 'community') {
19213: $credits{$type} = $env{'form.'.$type.'_credits'};
19214: $credits{$type} =~ s/[^\d.]+//g;
19215: }
19216: }
19217: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19218: ($env{'form.coursecredits'} eq '1')) {
19219: $changes{'coursecredits'} = 1;
19220: foreach my $type (keys(%credits)) {
19221: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19222: }
19223: } else {
19224: if ($env{'form.coursecredits'} eq '1') {
19225: foreach my $type (@types) {
19226: unless ($type eq 'community') {
19227: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
19228: $changes{'coursecredits'} = 1;
19229: }
19230: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19231: }
19232: }
19233: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19234: foreach my $type (@types) {
19235: unless ($type eq 'community') {
19236: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19237: $changes{'coursecredits'} = 1;
19238: last;
19239: }
19240: }
19241: }
19242: }
19243: }
19244: if ($env{'form.postsubmit'} eq '1') {
19245: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19246: my %currtimeout;
19247: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19248: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19249: $changes{'postsubmit'} = 1;
19250: }
19251: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19252: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19253: }
19254: } else {
19255: $changes{'postsubmit'} = 1;
19256: }
19257: foreach my $type (@types) {
19258: my $timeout = $env{'form.'.$type.'_timeout'};
19259: $timeout =~ s/\D//g;
19260: if ($timeout == $staticdefaults{'postsubmit'}) {
19261: $timeout = '';
19262: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19263: $timeout = '0';
19264: }
19265: unless ($timeout eq '') {
19266: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19267: }
19268: if (exists($currtimeout{$type})) {
19269: if ($timeout ne $currtimeout{$type}) {
19270: $changes{'postsubmit'} = 1;
19271: }
19272: } elsif ($timeout ne '') {
19273: $changes{'postsubmit'} = 1;
19274: }
19275: }
19276: } else {
19277: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19278: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19279: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19280: $changes{'postsubmit'} = 1;
19281: }
19282: } else {
19283: $changes{'postsubmit'} = 1;
19284: }
1.160.6.16 raeburn 19285: }
1.160.6.118.2 22(raebu 19286:24): my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool,%posscrseditors);
14(raebu 19287:23): map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
19288:23): map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
22(raebu 19289:24): map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
14(raebu 19290:23): if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19291:23): %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
19292:23): } else {
19293:23): foreach my $type (@types) {
19294:23): if ($staticdefaults{'domexttool'}) {
19295:23): $olddomexttool{$type} = 1;
19296:23): } else {
19297:23): $olddomexttool{$type} = 0;
19298:23): }
19299:23): }
19300:23): }
19301:23): if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
19302:23): %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
19303:23): } else {
19304:23): foreach my $type (@types) {
19305:23): if ($staticdefaults{'exttool'}) {
19306:23): $oldexttool{$type} = 1;
19307:23): } else {
19308:23): $oldexttool{$type} = 0;
19309:23): }
19310:23): }
19311:23): }
22(raebu 19312:24): my @newcrseditors = ();
19313:24): foreach my $editor (@editors) {
19314:24): if ($posscrseditors{$editor}) {
19315:24): push(@newcrseditors,$editor);
19316:24): }
19317:24): }
19318:24): if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19319:24): my @diffs =
19320:24): &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
19321:24): \@newcrseditors);
19322:24): if (@diffs) {
19323:24): $changes{'crseditors'} = 1;
19324:24): }
19325:24): } else {
19326:24): my @diffs =
19327:24): &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
19328:24): \@newcrseditors);
19329:24): unless (@diffs == 0) {
19330:24): $changes{'crseditors'} = 1;
19331:24): }
19332:24): }
14(raebu 19333:23): foreach my $type (@types) {
19334:23): unless ($newdomexttool{$type}) {
19335:23): $newdomexttool{$type} = 0;
19336:23): }
19337:23): unless ($newexttool{$type}) {
19338:23): $newexttool{$type} = 0;
19339:23): }
19340:23): if ($newdomexttool{$type} != $olddomexttool{$type}) {
19341:23): $changes{'domexttool'} = 1;
19342:23): }
19343:23): if ($newexttool{$type} != $oldexttool{$type}) {
19344:23): $changes{'exttool'} = 1;
19345:23): }
19346:23): }
19347:23): $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
19348:23): $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
22(raebu 19349:24): $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 19350: }
19351: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19352: $dom);
19353: if ($putresult eq 'ok') {
19354: if (keys(%changes) > 0) {
1.160.6.27 raeburn 19355: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 19356: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 19357: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 19358: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 14(raebu 19359:23): ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
15(raebu 19360:23): ($changes{'exttool'}) || ($changes{'coursequota'})) {
4(raebur 19361:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 19362: if ($changes{$item}) {
19363: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19364: }
1.160.6.16 raeburn 19365: }
19366: if ($changes{'coursecredits'}) {
19367: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 19368: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19369: $domdefaults{$type.'credits'} =
19370: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19371: }
19372: }
19373: }
19374: if ($changes{'postsubmit'}) {
19375: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19376: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19377: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19378: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19379: $domdefaults{$type.'postsubtimeout'} =
19380: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19381: }
19382: }
1.160.6.16 raeburn 19383: }
19384: }
1.160.6.21 raeburn 19385: if ($changes{'uploadquota'}) {
19386: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19387: foreach my $type (@types) {
19388: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19389: }
19390: }
19391: }
1.160.6.118.2 15(raebu 19392:23): if ($changes{'coursequota'}) {
19393:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19394:23): foreach my $type (@types) {
19395:23): $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
19396:23): }
19397:23): }
19398:23): }
1.160.6.64 raeburn 19399: if ($changes{'canclone'}) {
19400: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19401: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19402: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19403: if (@clonecodes) {
19404: $domdefaults{'canclone'} = join('+',@clonecodes);
19405: }
19406: }
19407: } else {
19408: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19409: }
19410: }
1.160.6.118.2 14(raebu 19411:23): if ($changes{'domexttool'}) {
19412:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19413:23): foreach my $type (@types) {
19414:23): $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
19415:23): }
19416:23): }
19417:23): }
19418:23): if ($changes{'exttool'}) {
19419:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19420:23): foreach my $type (@types) {
19421:23): $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
19422:23): }
19423:23): }
19424:23): }
22(raebu 19425:24): if ($changes{'crseditors'}) {
19426:24): if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19427:24): $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
19428:24): }
19429:24): }
1.121 raeburn 19430: my $cachetime = 24*60*60;
19431: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 19432: if (ref($lastactref) eq 'HASH') {
19433: $lastactref->{'domdefaults'} = 1;
19434: }
1.121 raeburn 19435: }
19436: $resulttext = &mt('Changes made:').'<ul>';
19437: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 19438: if ($item eq 'uselcmath') {
1.121 raeburn 19439: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 19440: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 19441: } else {
1.160.6.57 raeburn 19442: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19443: }
19444: } elsif ($item eq 'usejsme') {
19445: if ($env{'form.'.$item} eq '1') {
19446: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19447: } else {
19448: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 19449: }
1.160.6.115 raeburn 19450: } elsif ($item eq 'inline_chem') {
19451: if ($env{'form.'.$item} eq '1') {
19452: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
19453: } else {
19454: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
19455: }
1.160.6.90 raeburn 19456: } elsif ($item eq 'texengine') {
19457: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19458: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19459: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19460: }
1.139 raeburn 19461: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 19462: $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 19463: } elsif ($item eq 'uploadquota') {
19464: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19465: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19466: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19467: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 19468: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.160.6.21 raeburn 19469: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19470: '</ul>'.
19471: '</li>';
19472: } else {
19473: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19474: }
1.160.6.118.2 15(raebu 19475:23): } elsif ($item eq 'coursequota') {
19476:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19477:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
19478:23): '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
19479:23): '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
19480:23): '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
19481:23): '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
19482:23): '</ul>'.
19483:23): '</li>';
19484:23): } else {
19485:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
19486:23): }
1.160.6.70 raeburn 19487: } elsif ($item eq 'mysqltables') {
19488: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19489: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19490: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19491: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19492: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19493: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19494: '</ul>'.
19495: '</li>';
19496: } else {
19497: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19498: }
1.160.6.57 raeburn 19499: } elsif ($item eq 'postsubmit') {
19500: if ($domdefaults{'postsubmit'} eq 'off') {
19501: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19502: } else {
19503: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
19504: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19505: $resulttext .= &mt('durations:').'<ul>';
19506: foreach my $type (@types) {
19507: $resulttext .= '<li>';
19508: my $timeout;
19509: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19510: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19511: }
19512: my $display;
19513: if ($timeout eq '0') {
19514: $display = &mt('unlimited');
19515: } elsif ($timeout eq '') {
19516: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19517: } else {
19518: $display = &mt('[quant,_1,second]',$timeout);
19519: }
19520: if ($type eq 'community') {
19521: $resulttext .= &mt('Communities');
19522: } elsif ($type eq 'official') {
19523: $resulttext .= &mt('Official courses');
19524: } elsif ($type eq 'unofficial') {
19525: $resulttext .= &mt('Unofficial courses');
19526: } elsif ($type eq 'textbook') {
19527: $resulttext .= &mt('Textbook courses');
19528: }
19529: $resulttext .= ' -- '.$display.'</li>';
19530: }
19531: $resulttext .= '</ul>';
19532: }
19533: $resulttext .= '</li>';
19534: }
1.160.6.16 raeburn 19535: } elsif ($item eq 'coursecredits') {
19536: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19537: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 19538: ($domdefaults{'unofficialcredits'} eq '') &&
19539: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 19540: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19541: } else {
19542: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19543: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19544: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 19545: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 19546: '</ul>'.
19547: '</li>';
19548: }
19549: } else {
19550: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19551: }
1.160.6.64 raeburn 19552: } elsif ($item eq 'canclone') {
19553: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19554: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19555: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19556: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19557: }
19558: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19559: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19560: } else {
19561: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
19562: }
1.160.6.118.2 4(raebur 19563:2): } elsif ($item eq 'ltiauth') {
19564:2): if ($env{'form.'.$item} eq '1') {
19565:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
19566:2): } else {
19567:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
19568:2): }
14(raebu 19569:23): } elsif ($item eq 'domexttool') {
19570:23): my @noyes = (&mt('no'),&mt('yes'));
19571:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19572:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
19573:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
19574:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
19575:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
19576:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
19577:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
19578:23): '</ul>'.
19579:23): '</li>';
19580:23): } else {
19581:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
19582:23): }
19583:23): } elsif ($item eq 'exttool') {
19584:23): my @noyes = (&mt('no'),&mt('yes'));
19585:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19586:23): $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
19587:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
19588:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
19589:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
19590:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
19591:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
19592:23): '</ul>'.
19593:23): '</li>';
19594:23): } else {
19595:23): $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
19596:23): }
22(raebu 19597:24): } elsif ($item eq 'crseditors') {
19598:24): if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
19599:24): my $shown;
19600:24): if (@{$defaultshash{'coursedefaults'}{$item}}) {
19601:24): $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
19602:24): } else {
19603:24): $shown = &mt('None');
19604:24): }
19605:24): $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
19606:24): }
1.140 raeburn 19607: }
1.121 raeburn 19608: }
19609: $resulttext .= '</ul>';
19610: } else {
19611: $resulttext = &mt('No changes made to course defaults');
19612: }
19613: } else {
19614: $resulttext = '<span class="LC_error">'.
19615: &mt('An error occurred: [_1]',$putresult).'</span>';
19616: }
19617: return $resulttext;
19618: }
19619:
1.160.6.37 raeburn 19620: sub modify_selfenrollment {
19621: my ($dom,$lastactref,%domconfig) = @_;
19622: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
19623: my @types = ('official','unofficial','community','textbook');
19624: my %titles = &tool_titles();
19625: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19626: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
19627: $ordered{'default'} = ['types','registered','approval','limit'];
19628:
19629: my (%roles,%shown,%toplevel);
19630: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19631:
19632: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19633: if ($domconfig{'selfenrollment'} eq '') {
19634: $domconfig{'selfenrollment'} = {};
19635: }
19636: }
19637: %toplevel = (
19638: admin => 'Configuration Rights',
19639: default => 'Default settings',
19640: validation => 'Validation of self-enrollment requests',
19641: );
19642: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
19643:
19644: if (ref($ordered{'admin'}) eq 'ARRAY') {
19645: foreach my $item (@{$ordered{'admin'}}) {
19646: foreach my $type (@types) {
19647: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19648: $selfenrollhash{'admin'}{$type}{$item} = 1;
19649: } else {
19650: $selfenrollhash{'admin'}{$type}{$item} = 0;
19651: }
19652: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19653: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19654: if ($selfenrollhash{'admin'}{$type}{$item} ne
19655: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19656: push(@{$changes{'admin'}{$type}},$item);
19657: }
19658: } else {
19659: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19660: push(@{$changes{'admin'}{$type}},$item);
19661: }
19662: }
19663: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19664: push(@{$changes{'admin'}{$type}},$item);
19665: }
19666: }
19667: }
19668: }
19669:
19670: foreach my $item (@{$ordered{'default'}}) {
19671: foreach my $type (@types) {
19672: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19673: if ($item eq 'types') {
19674: unless (($value eq 'all') || ($value eq 'dom')) {
19675: $value = '';
19676: }
19677: } elsif ($item eq 'registered') {
19678: unless ($value eq '1') {
19679: $value = 0;
19680: }
19681: } elsif ($item eq 'approval') {
19682: unless ($value =~ /^[012]$/) {
19683: $value = 0;
19684: }
19685: } else {
19686: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19687: $value = 'none';
19688: }
19689: }
19690: $selfenrollhash{'default'}{$type}{$item} = $value;
19691: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19692: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19693: if ($selfenrollhash{'default'}{$type}{$item} ne
19694: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19695: push(@{$changes{'default'}{$type}},$item);
19696: }
19697: } else {
19698: push(@{$changes{'default'}{$type}},$item);
19699: }
19700: } else {
19701: push(@{$changes{'default'}{$type}},$item);
19702: }
19703: if ($item eq 'limit') {
19704: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19705: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19706: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19707: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19708: }
19709: } else {
19710: $selfenrollhash{'default'}{$type}{'cap'} = '';
19711: }
19712: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19713: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19714: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19715: push(@{$changes{'default'}{$type}},'cap');
19716: }
19717: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19718: push(@{$changes{'default'}{$type}},'cap');
19719: }
19720: }
19721: }
19722: }
19723:
19724: foreach my $item (@{$itemsref}) {
19725: if ($item eq 'fields') {
19726: my @changed;
19727: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19728: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19729: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19730: }
19731: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19732: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19733: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19734: $domconfig{'selfenrollment'}{'validation'}{$item});
19735: } else {
19736: @changed = @{$selfenrollhash{'validation'}{$item}};
19737: }
19738: } else {
19739: @changed = @{$selfenrollhash{'validation'}{$item}};
19740: }
19741: if (@changed) {
19742: if ($selfenrollhash{'validation'}{$item}) {
19743: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19744: } else {
19745: $changes{'validation'}{$item} = &mt('None');
19746: }
19747: }
19748: } else {
19749: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19750: if ($item eq 'markup') {
19751: if ($env{'form.selfenroll_validation_'.$item}) {
19752: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19753: }
19754: }
19755: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19756: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19757: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19758: }
19759: }
19760: }
19761: }
19762:
19763: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19764: $dom);
19765: if ($putresult eq 'ok') {
19766: if (keys(%changes) > 0) {
19767: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19768: $resulttext = &mt('Changes made:').'<ul>';
19769: foreach my $key ('admin','default','validation') {
19770: if (ref($changes{$key}) eq 'HASH') {
19771: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19772: if ($key eq 'validation') {
19773: foreach my $item (@{$itemsref}) {
19774: if (exists($changes{$key}{$item})) {
19775: if ($item eq 'markup') {
19776: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19777: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19778: } else {
19779: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19780: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19781: }
19782: }
19783: }
19784: } else {
19785: foreach my $type (@types) {
19786: if ($type eq 'community') {
19787: $roles{'1'} = &mt('Community personnel');
19788: } else {
19789: $roles{'1'} = &mt('Course personnel');
19790: }
19791: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19792: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19793: if ($key eq 'admin') {
19794: my @mgrdc = ();
19795: if (ref($ordered{$key}) eq 'ARRAY') {
19796: foreach my $item (@{$ordered{'admin'}}) {
19797: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19798: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19799: push(@mgrdc,$item);
19800: }
19801: }
19802: }
19803: if (@mgrdc) {
19804: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19805: } else {
19806: delete($domdefaults{$type.'selfenrolladmdc'});
19807: }
19808: }
19809: } else {
19810: if (ref($ordered{$key}) eq 'ARRAY') {
19811: foreach my $item (@{$ordered{$key}}) {
19812: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19813: $domdefaults{$type.'selfenroll'.$item} =
19814: $selfenrollhash{$key}{$type}{$item};
19815: }
19816: }
19817: }
19818: }
19819: }
19820: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19821: foreach my $item (@{$ordered{$key}}) {
19822: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19823: $resulttext .= '<li>';
19824: if ($key eq 'admin') {
19825: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19826: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19827: } else {
19828: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19829: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19830: }
19831: $resulttext .= '</li>';
19832: }
19833: }
19834: $resulttext .= '</ul></li>';
19835: }
19836: }
19837: $resulttext .= '</ul></li>';
19838: }
19839: }
1.160.6.93 raeburn 19840: }
19841: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19842: my $cachetime = 24*60*60;
19843: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19844: if (ref($lastactref) eq 'HASH') {
19845: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 19846: }
19847: }
19848: $resulttext .= '</ul>';
19849: } else {
19850: $resulttext = &mt('No changes made to self-enrollment settings');
19851: }
19852: } else {
19853: $resulttext = '<span class="LC_error">'.
19854: &mt('An error occurred: [_1]',$putresult).'</span>';
19855: }
19856: return $resulttext;
19857: }
19858:
1.160.6.113 raeburn 19859: sub modify_wafproxy {
19860: my ($dom,$action,$lastactref,%domconfig) = @_;
19861: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19862: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19863: %wafproxy,%changes,%expirecache,%expiresaml);
19864: foreach my $server (sort(keys(%servers))) {
19865: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19866: if ($serverhome eq $server) {
19867: my $serverdom = &Apache::lonnet::host_domain($server);
19868: if ($serverdom eq $dom) {
19869: $canset{$server} = 1;
19870: }
19871: }
19872: }
19873: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19874: %{$values{$dom}} = ();
19875: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19876: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19877: }
19878: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19879: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19880: }
19881: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19882: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19883: }
19884: }
19885: my $output;
19886: if (keys(%canset)) {
19887: %{$wafproxy{'alias'}} = ();
19888: %{$wafproxy{'saml'}} = ();
19889: foreach my $key (sort(keys(%canset))) {
19890: if ($env{'form.wafproxy_'.$dom}) {
19891: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19892: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19893: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19894: $changes{'alias'} = 1;
19895: }
19896: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19897: $wafproxy{'saml'}{$key} = 1;
19898: }
19899: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19900: $changes{'saml'} = 1;
19901: }
19902: } else {
19903: $wafproxy{'alias'}{$key} = '';
19904: $wafproxy{'saml'}{$key} = '';
19905: if ($curralias{$key}) {
19906: $changes{'alias'} = 1;
19907: }
19908: if ($currsaml{$key}) {
19909: $changes{'saml'} = 1;
19910: }
19911: }
19912: if ($wafproxy{'alias'}{$key} eq '') {
19913: if ($curralias{$key}) {
19914: $expirecache{$key} = 1;
19915: }
19916: delete($wafproxy{'alias'}{$key});
19917: }
19918: if ($wafproxy{'saml'}{$key} eq '') {
19919: if ($currsaml{$key}) {
19920: $expiresaml{$key} = 1;
19921: }
19922: delete($wafproxy{'saml'}{$key});
19923: }
19924: }
19925: unless (keys(%{$wafproxy{'alias'}})) {
19926: delete($wafproxy{'alias'});
19927: }
19928: unless (keys(%{$wafproxy{'saml'}})) {
19929: delete($wafproxy{'saml'});
19930: }
19931: # Localization for values in %warn occurs in &mt() calls separately.
19932: my %warn = (
19933: trusted => 'trusted IP range(s)',
19934: vpnint => 'internal IP range(s) for VPN sessions(s)',
19935: vpnext => 'IP range(s) for backend WAF connections',
19936: );
19937: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19938: my $possible = $env{'form.wafproxy_'.$item};
19939: $possible =~ s/^\s+|\s+$//g;
19940: if ($possible ne '') {
19941: if ($item eq 'remoteip') {
19942: if ($possible =~ /^[mhn]$/) {
19943: $wafproxy{$item} = $possible;
19944: }
19945: } elsif ($item eq 'ipheader') {
19946: if ($wafproxy{'remoteip'} eq 'h') {
19947: $wafproxy{$item} = $possible;
19948: }
19949: } elsif ($item eq 'sslopt') {
19950: if ($possible =~ /^0|1$/) {
19951: $wafproxy{$item} = $possible;
19952: }
19953: } else {
19954: my (@ok,$count);
19955: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19956: unless ($env{'form.wafproxy_vpnaccess'}) {
19957: $possible = '';
19958: }
19959: } elsif ($item eq 'trusted') {
19960: unless ($wafproxy{'remoteip'} eq 'h') {
19961: $possible = '';
19962: }
19963: }
19964: unless ($possible eq '') {
19965: $possible =~ s/[\r\n]+/\s/g;
19966: $possible =~ s/\s*-\s*/-/g;
19967: $possible =~ s/\s+/,/g;
19968: $possible =~ s/,+/,/g;
19969: }
19970: $count = 0;
19971: if ($possible ne '') {
19972: foreach my $poss (split(/\,/,$possible)) {
19973: $count ++;
19974: $poss = &validate_ip_pattern($poss);
19975: if ($poss ne '') {
19976: push(@ok,$poss);
19977: }
19978: }
19979: my $diff = $count - scalar(@ok);
19980: if ($diff) {
19981: push(@warnings,'<li>'.
19982: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19983: $diff,$warn{$item}).
19984: '</li>');
19985: }
19986: if (@ok) {
19987: my @cidr_list;
19988: foreach my $item (@ok) {
19989: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19990: }
19991: $wafproxy{$item} = join(',',@cidr_list);
19992: }
19993: }
19994: }
19995: if ($wafproxy{$item} ne $currvalue{$item}) {
19996: $changes{$item} = 1;
19997: }
19998: } elsif ($currvalue{$item}) {
19999: $changes{$item} = 1;
20000: }
20001: }
20002: } else {
20003: if (keys(%curralias)) {
20004: $changes{'alias'} = 1;
20005: }
20006: if (keys(%currsaml)) {
20007: $changes{'saml'} = 1;
20008: }
20009: if (keys(%currvalue)) {
20010: foreach my $key (keys(%currvalue)) {
20011: $changes{$key} = 1;
20012: }
20013: }
20014: }
20015: if (keys(%changes)) {
20016: my %defaultshash = (
20017: wafproxy => \%wafproxy,
20018: );
20019: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20020: $dom);
20021: if ($putresult eq 'ok') {
20022: my $cachetime = 24*60*60;
20023: my (%domdefaults,$updatedomdefs);
20024: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
20025: if ($changes{$item}) {
20026: unless ($updatedomdefs) {
20027: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20028: $updatedomdefs = 1;
20029: }
20030: if ($wafproxy{$item}) {
20031: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20032: } elsif (exists($domdefaults{'waf_'.$item})) {
20033: delete($domdefaults{'waf_'.$item});
20034: }
20035: }
20036: }
20037: if ($updatedomdefs) {
20038: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20039: if (ref($lastactref) eq 'HASH') {
20040: $lastactref->{'domdefaults'} = 1;
20041: }
20042: }
20043: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20044: my %updates = %expirecache;
20045: foreach my $key (keys(%expirecache)) {
20046: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20047: }
20048: if (ref($wafproxy{'alias'}) eq 'HASH') {
20049: my $cachetime = 24*60*60;
20050: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20051: $updates{$key} = 1;
20052: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20053: $cachetime);
20054: }
20055: }
20056: if (ref($lastactref) eq 'HASH') {
20057: $lastactref->{'proxyalias'} = \%updates;
20058: }
20059: }
20060: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20061: my %samlupdates = %expiresaml;
20062: foreach my $key (keys(%expiresaml)) {
20063: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20064: }
20065: if (ref($wafproxy{'saml'}) eq 'HASH') {
20066: my $cachetime = 24*60*60;
20067: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20068: $samlupdates{$key} = 1;
20069: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20070: $cachetime);
20071: }
20072: }
20073: if (ref($lastactref) eq 'HASH') {
20074: $lastactref->{'proxysaml'} = \%samlupdates;
20075: }
20076: }
20077: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 20078: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 20079: if ($changes{$item}) {
20080: if ($item eq 'alias') {
20081: my $numaliased = 0;
20082: if (ref($wafproxy{'alias'}) eq 'HASH') {
20083: my $shown;
20084: if (keys(%{$wafproxy{'alias'}})) {
20085: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20086: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20087: &Apache::lonnet::hostname($server),
20088: $wafproxy{'alias'}{$server}).'</li>';
20089: $numaliased ++;
20090: }
20091: if ($numaliased) {
20092: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20093: '<ul>'.$shown.'</ul>').'</li>';
20094: }
20095: }
20096: }
20097: unless ($numaliased) {
20098: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20099: }
20100: } elsif ($item eq 'saml') {
20101: my $shown;
20102: if (ref($wafproxy{'saml'}) eq 'HASH') {
20103: if (keys(%{$wafproxy{'saml'}})) {
20104: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20105: }
20106: }
20107: if ($shown) {
20108: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
20109: $shown).'</li>';
20110: } else {
20111: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
20112: }
20113: } else {
20114: if ($item eq 'remoteip') {
20115: my %ip_methods = &remoteip_methods();
20116: if ($wafproxy{$item} =~ /^[mh]$/) {
20117: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20118: $ip_methods{$wafproxy{$item}}).'</li>';
20119: } else {
20120: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20121: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20122: '</li>';
20123: } else {
20124: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20125: }
20126: }
20127: } elsif ($item eq 'ipheader') {
20128: if ($wafproxy{$item}) {
20129: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
20130: $wafproxy{$item}).'</li>';
20131: } else {
20132: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
20133: }
20134: } elsif ($item eq 'trusted') {
20135: if ($wafproxy{$item}) {
20136: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
20137: $wafproxy{$item}).'</li>';
20138: } else {
20139: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20140: }
20141: } elsif ($item eq 'vpnint') {
20142: if ($wafproxy{$item}) {
20143: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20144: $wafproxy{$item}).'</li>';
20145: } else {
20146: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20147: }
20148: } elsif ($item eq 'vpnext') {
20149: if ($wafproxy{$item}) {
20150: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
20151: $wafproxy{$item}).'</li>';
20152: } else {
20153: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
20154: }
20155: } elsif ($item eq 'sslopt') {
20156: if ($wafproxy{$item}) {
20157: $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>';
20158: } else {
20159: $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>';
20160: }
20161: }
20162: }
20163: }
20164: }
1.160.6.118.2 14(raebu 20165:23): $output .= '</ul>';
1.160.6.113 raeburn 20166: } else {
20167: $output = '<span class="LC_error">'.
20168: &mt('An error occurred: [_1]',$putresult).'</span>';
20169: }
20170: } elsif (keys(%canset)) {
20171: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20172: }
20173: if (@warnings) {
20174: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20175: join("\n",@warnings).'</ul>';
20176: }
20177: return $output;
20178: }
20179:
20180: sub validate_ip_pattern {
20181: my ($pattern) = @_;
20182: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20183: my ($start,$end) = ($1,$2);
20184: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20185: if (($start !~ m{/}) && ($end !~ m{/})) {
20186: return $start.'-'.$end;
20187: }
20188: }
20189: } elsif ($pattern ne '') {
20190: $pattern = &Net::CIDR::cidrvalidate($pattern);
20191: if ($pattern ne '') {
20192: return $pattern;
20193: }
20194: }
20195: return;
20196: }
20197:
1.137 raeburn 20198: sub modify_usersessions {
1.160.6.27 raeburn 20199: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20200: my @hostingtypes = ('version','excludedomain','includedomain');
20201: my @offloadtypes = ('primary','default');
20202: my %types = (
20203: remote => \@hostingtypes,
20204: hosted => \@hostingtypes,
20205: spares => \@offloadtypes,
20206: );
20207: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20208: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 20209: my (%by_ip,%by_location,@intdoms);
20210: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
20211: my @locations = sort(keys(%by_location));
1.137 raeburn 20212: my (%defaultshash,%changes);
20213: foreach my $prefix (@prefixes) {
20214: $defaultshash{'usersessions'}{$prefix} = {};
20215: }
1.160.6.27 raeburn 20216: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20217: my $resulttext;
1.138 raeburn 20218: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20219: foreach my $prefix (@prefixes) {
1.145 raeburn 20220: next if ($prefix eq 'spares');
20221: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20222: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20223: if ($type eq 'version') {
20224: my $value = $env{'form.'.$prefix.'_'.$type};
20225: my $okvalue;
20226: if ($value ne '') {
20227: if (grep(/^\Q$value\E$/,@lcversions)) {
20228: $okvalue = $value;
20229: }
20230: }
20231: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20232: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20233: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20234: if ($inuse == 0) {
20235: $changes{$prefix}{$type} = 1;
20236: } else {
20237: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20238: $changes{$prefix}{$type} = 1;
20239: }
20240: if ($okvalue ne '') {
20241: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20242: }
20243: }
20244: } else {
20245: if (($inuse == 1) && ($okvalue ne '')) {
20246: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20247: $changes{$prefix}{$type} = 1;
20248: }
20249: }
20250: } else {
20251: if (($inuse == 1) && ($okvalue ne '')) {
20252: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20253: $changes{$prefix}{$type} = 1;
20254: }
20255: }
20256: } else {
20257: if (($inuse == 1) && ($okvalue ne '')) {
20258: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20259: $changes{$prefix}{$type} = 1;
20260: }
20261: }
20262: } else {
20263: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20264: my @okvals;
20265: foreach my $val (@vals) {
1.138 raeburn 20266: if ($val =~ /:/) {
20267: my @items = split(/:/,$val);
20268: foreach my $item (@items) {
20269: if (ref($by_location{$item}) eq 'ARRAY') {
20270: push(@okvals,$item);
20271: }
20272: }
20273: } else {
20274: if (ref($by_location{$val}) eq 'ARRAY') {
20275: push(@okvals,$val);
20276: }
1.137 raeburn 20277: }
20278: }
20279: @okvals = sort(@okvals);
20280: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20281: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20282: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20283: if ($inuse == 0) {
20284: $changes{$prefix}{$type} = 1;
20285: } else {
20286: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20287: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20288: if (@changed > 0) {
20289: $changes{$prefix}{$type} = 1;
20290: }
20291: }
20292: } else {
20293: if ($inuse == 1) {
20294: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20295: $changes{$prefix}{$type} = 1;
20296: }
20297: }
20298: } else {
20299: if ($inuse == 1) {
20300: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20301: $changes{$prefix}{$type} = 1;
20302: }
20303: }
20304: } else {
20305: if ($inuse == 1) {
20306: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20307: $changes{$prefix}{$type} = 1;
20308: }
20309: }
20310: }
20311: }
20312: }
1.145 raeburn 20313:
20314: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20315: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20316: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20317: my $savespares;
20318:
20319: foreach my $lonhost (sort(keys(%servers))) {
20320: my $serverhomeID =
20321: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20322: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20323: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20324: my %spareschg;
20325: foreach my $type (@{$types{'spares'}}) {
20326: my @okspares;
20327: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20328: foreach my $server (@checked) {
1.152 raeburn 20329: if (&Apache::lonnet::hostname($server) ne '') {
20330: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20331: unless (grep(/^\Q$server\E$/,@okspares)) {
20332: push(@okspares,$server);
20333: }
1.145 raeburn 20334: }
20335: }
20336: }
20337: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20338: my $newspare;
1.152 raeburn 20339: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20340: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20341: $newspare = $new;
20342: }
20343: }
1.152 raeburn 20344: my @spares;
20345: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20346: @spares = sort(@okspares,$newspare);
20347: } else {
20348: @spares = sort(@okspares);
20349: }
20350: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20351: if (ref($spareid{$lonhost}) eq 'HASH') {
20352: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20353: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20354: if (@diffs > 0) {
20355: $spareschg{$type} = 1;
20356: }
20357: }
20358: }
20359: }
20360: if (keys(%spareschg) > 0) {
20361: $changes{'spares'}{$lonhost} = \%spareschg;
20362: }
20363: }
1.160.6.61 raeburn 20364: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 20365: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 20366: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20367: my @okoffload;
20368: if (@offloadnow) {
20369: foreach my $server (@offloadnow) {
20370: if (&Apache::lonnet::hostname($server) ne '') {
20371: unless (grep(/^\Q$server\E$/,@okoffload)) {
20372: push(@okoffload,$server);
20373: }
20374: }
20375: }
20376: if (@okoffload) {
20377: foreach my $lonhost (@okoffload) {
20378: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20379: }
20380: }
20381: }
1.160.6.105 raeburn 20382: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20383: my @okoffloadoth;
20384: if (@offloadoth) {
20385: foreach my $server (@offloadoth) {
20386: if (&Apache::lonnet::hostname($server) ne '') {
20387: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20388: push(@okoffloadoth,$server);
20389: }
20390: }
20391: }
20392: if (@okoffloadoth) {
20393: foreach my $lonhost (@okoffloadoth) {
20394: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20395: }
20396: }
20397: }
1.145 raeburn 20398: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20399: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20400: if (ref($changes{'spares'}) eq 'HASH') {
20401: if (keys(%{$changes{'spares'}}) > 0) {
20402: $savespares = 1;
20403: }
20404: }
20405: } else {
20406: $savespares = 1;
20407: }
1.160.6.105 raeburn 20408: foreach my $offload ('offloadnow','offloadoth') {
20409: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20410: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20411: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20412: $changes{$offload} = 1;
1.160.6.61 raeburn 20413: last;
20414: }
20415: }
1.160.6.105 raeburn 20416: unless ($changes{$offload}) {
20417: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20418: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20419: $changes{$offload} = 1;
20420: last;
20421: }
20422: }
20423: }
20424: } else {
20425: if (($offload eq 'offloadnow') && (@okoffload)) {
20426: $changes{'offloadnow'} = 1;
20427: }
20428: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20429: $changes{'offloadoth'} = 1;
20430: }
1.160.6.61 raeburn 20431: }
1.160.6.105 raeburn 20432: }
20433: } else {
20434: if (@okoffload) {
1.160.6.61 raeburn 20435: $changes{'offloadnow'} = 1;
20436: }
1.160.6.105 raeburn 20437: if (@okoffloadoth) {
20438: $changes{'offloadoth'} = 1;
20439: }
1.145 raeburn 20440: }
1.147 raeburn 20441: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20442: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20443: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20444: $dom);
20445: if ($putresult eq 'ok') {
20446: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20447: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20448: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20449: }
20450: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20451: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20452: }
1.160.6.61 raeburn 20453: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20454: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20455: }
1.160.6.105 raeburn 20456: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20457: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20458: }
1.137 raeburn 20459: }
20460: my $cachetime = 24*60*60;
20461: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 20462: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 20463: if (ref($lastactref) eq 'HASH') {
20464: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 20465: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 20466: }
1.147 raeburn 20467: if (keys(%changes) > 0) {
20468: my %lt = &usersession_titles();
20469: $resulttext = &mt('Changes made:').'<ul>';
20470: foreach my $prefix (@prefixes) {
20471: if (ref($changes{$prefix}) eq 'HASH') {
20472: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20473: if ($prefix eq 'spares') {
20474: if (ref($changes{$prefix}) eq 'HASH') {
20475: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20476: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20477: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 20478: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20479: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20480: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20481: foreach my $type (@{$types{$prefix}}) {
20482: if ($changes{$prefix}{$lonhost}{$type}) {
20483: my $offloadto = &mt('None');
20484: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20485: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20486: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20487: }
1.145 raeburn 20488: }
1.147 raeburn 20489: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20490: }
1.137 raeburn 20491: }
20492: }
1.147 raeburn 20493: $resulttext .= '</li>';
1.137 raeburn 20494: }
20495: }
1.147 raeburn 20496: } else {
20497: foreach my $type (@{$types{$prefix}}) {
20498: if (defined($changes{$prefix}{$type})) {
20499: my $newvalue;
20500: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20501: if (ref($defaultshash{'usersessions'}{$prefix})) {
20502: if ($type eq 'version') {
20503: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
20504: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20505: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20506: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20507: }
1.145 raeburn 20508: }
20509: }
20510: }
1.147 raeburn 20511: if ($newvalue eq '') {
20512: if ($type eq 'version') {
20513: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
20514: } else {
20515: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20516: }
1.145 raeburn 20517: } else {
1.147 raeburn 20518: if ($type eq 'version') {
1.160.6.118.2 14(raebu 20519:23): $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20520: }
20521: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20522: }
1.137 raeburn 20523: }
20524: }
20525: }
1.147 raeburn 20526: $resulttext .= '</ul>';
1.137 raeburn 20527: }
20528: }
1.160.6.61 raeburn 20529: if ($changes{'offloadnow'}) {
20530: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20531: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 20532: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 20533: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20534: $resulttext .= '<li>'.$lonhost.'</li>';
20535: }
20536: $resulttext .= '</ul>';
20537: } else {
1.160.6.105 raeburn 20538: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20539: }
20540: } else {
20541: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20542: }
20543: }
20544: if ($changes{'offloadoth'}) {
20545: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20546: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20547: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20548: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20549: $resulttext .= '<li>'.$lonhost.'</li>';
20550: }
20551: $resulttext .= '</ul>';
20552: } else {
20553: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 20554: }
20555: } else {
1.160.6.105 raeburn 20556: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 20557: }
20558: }
1.147 raeburn 20559: $resulttext .= '</ul>';
20560: } else {
20561: $resulttext = $nochgmsg;
1.137 raeburn 20562: }
20563: } else {
20564: $resulttext = '<span class="LC_error">'.
20565: &mt('An error occurred: [_1]',$putresult).'</span>';
20566: }
20567: } else {
1.147 raeburn 20568: $resulttext = $nochgmsg;
1.137 raeburn 20569: }
20570: return $resulttext;
20571: }
20572:
1.150 raeburn 20573: sub modify_loadbalancing {
20574: my ($dom,%domconfig) = @_;
20575: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20576: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20577: my ($othertitle,$usertypes,$types) =
20578: &Apache::loncommon::sorted_inst_types($dom);
20579: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 20580: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20581: my @sparestypes = ('primary','default');
20582: my %typetitles = &sparestype_titles();
20583: my $resulttext;
1.160.6.94 raeburn 20584: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 20585: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20586: %existing = %{$domconfig{'loadbalancing'}};
20587: }
20588: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 20589: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 20590: my ($saveloadbalancing,%defaultshash,%changes);
20591: my ($alltypes,$othertypes,$titles) =
20592: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20593: my %ruletitles = &offloadtype_text();
20594: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20595: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20596: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20597: if ($balancer eq '') {
20598: next;
20599: }
20600: if (!exists($servers{$balancer})) {
20601: if (exists($currbalancer{$balancer})) {
20602: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20603: }
1.160.6.7 raeburn 20604: next;
20605: }
20606: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20607: push(@{$changes{'delete'}},$balancer);
20608: next;
20609: }
20610: if (!exists($currbalancer{$balancer})) {
20611: push(@{$changes{'add'}},$balancer);
20612: }
20613: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20614: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20615: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20616: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20617: $saveloadbalancing = 1;
20618: }
20619: foreach my $sparetype (@sparestypes) {
20620: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20621: my @offloadto;
20622: foreach my $target (@targets) {
20623: if (($servers{$target}) && ($target ne $balancer)) {
20624: if ($sparetype eq 'default') {
20625: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20626: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20627: }
20628: }
1.160.6.7 raeburn 20629: unless(grep(/^\Q$target\E$/,@offloadto)) {
20630: push(@offloadto,$target);
20631: }
1.150 raeburn 20632: }
20633: }
1.160.6.76 raeburn 20634: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20635: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20636: push(@offloadto,$balancer);
20637: }
20638: }
20639: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20640: }
1.160.6.94 raeburn 20641: if ($env{'form.loadbalancing_cookie_'.$i}) {
20642: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20643: if (exists($currbalancer{$balancer})) {
20644: unless ($currcookies{$balancer}) {
20645: $changes{'curr'}{$balancer}{'cookie'} = 1;
20646: }
20647: }
20648: } elsif (exists($currbalancer{$balancer})) {
20649: if ($currcookies{$balancer}) {
20650: $changes{'curr'}{$balancer}{'cookie'} = 1;
20651: }
20652: }
1.160.6.7 raeburn 20653: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20654: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 20655: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20656: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20657: if (@targetdiffs > 0) {
1.160.6.7 raeburn 20658: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20659: }
1.160.6.7 raeburn 20660: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20661: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20662: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20663: }
20664: }
20665: }
20666: } else {
1.160.6.7 raeburn 20667: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
20668: foreach my $sparetype (@sparestypes) {
20669: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20670: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20671: $changes{'curr'}{$balancer}{'targets'} = 1;
20672: }
1.150 raeburn 20673: }
20674: }
1.160.6.7 raeburn 20675: }
1.150 raeburn 20676: }
20677: my $ishomedom;
1.160.6.7 raeburn 20678: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20679: $ishomedom = 1;
1.150 raeburn 20680: }
20681: if (ref($alltypes) eq 'ARRAY') {
20682: foreach my $type (@{$alltypes}) {
20683: my $rule;
1.160.6.7 raeburn 20684: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20685: (!$ishomedom)) {
1.160.6.7 raeburn 20686: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20687: }
20688: if ($rule eq 'specific') {
1.160.6.55 raeburn 20689: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
20690: if (exists($servers{$specifiedhost})) {
20691: $rule = $specifiedhost;
20692: }
1.150 raeburn 20693: }
1.160.6.7 raeburn 20694: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20695: if (ref($currrules{$balancer}) eq 'HASH') {
20696: if ($rule ne $currrules{$balancer}{$type}) {
20697: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20698: }
20699: } elsif ($rule ne '') {
1.160.6.7 raeburn 20700: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20701: }
20702: }
20703: }
1.160.6.7 raeburn 20704: }
20705: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20706: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20707: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20708: $defaultshash{'loadbalancing'} = {};
20709: }
20710: my $putresult = &Apache::lonnet::put_dom('configuration',
20711: \%defaultshash,$dom);
20712: if ($putresult eq 'ok') {
20713: if (keys(%changes) > 0) {
1.160.6.54 raeburn 20714: my %toupdate;
1.160.6.7 raeburn 20715: if (ref($changes{'delete'}) eq 'ARRAY') {
20716: foreach my $balancer (sort(@{$changes{'delete'}})) {
20717: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 20718: $toupdate{$balancer} = 1;
1.150 raeburn 20719: }
1.160.6.7 raeburn 20720: }
20721: if (ref($changes{'add'}) eq 'ARRAY') {
20722: foreach my $balancer (sort(@{$changes{'add'}})) {
20723: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 20724: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20725: }
20726: }
20727: if (ref($changes{'curr'}) eq 'HASH') {
20728: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 20729: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20730: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20731: if ($changes{'curr'}{$balancer}{'targets'}) {
20732: my %offloadstr;
20733: foreach my $sparetype (@sparestypes) {
20734: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20735: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20736: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20737: }
20738: }
1.150 raeburn 20739: }
1.160.6.7 raeburn 20740: if (keys(%offloadstr) == 0) {
20741: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20742: } else {
1.160.6.7 raeburn 20743: my $showoffload;
20744: foreach my $sparetype (@sparestypes) {
20745: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20746: if (defined($offloadstr{$sparetype})) {
20747: $showoffload .= $offloadstr{$sparetype};
20748: } else {
20749: $showoffload .= &mt('None');
20750: }
20751: $showoffload .= (' 'x3);
20752: }
20753: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20754: }
20755: }
20756: }
1.160.6.7 raeburn 20757: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20758: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20759: foreach my $type (@{$alltypes}) {
20760: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20761: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20762: my $balancetext;
20763: if ($rule eq '') {
20764: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 20765: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 20766: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20767: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 20768: foreach my $sparetype (@sparestypes) {
20769: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20770: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20771: }
20772: }
1.160.6.55 raeburn 20773: foreach my $item (@{$alltypes}) {
20774: next if ($item =~ /^_LC_ipchange/);
20775: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20776: if ($hasrule eq 'homeserver') {
20777: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20778: } else {
20779: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20780: if ($servers{$hasrule}) {
20781: $toupdate{$hasrule} = 1;
20782: }
20783: }
20784: }
20785: }
20786: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20787: $balancetext = $ruletitles{$rule};
20788: } else {
20789: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20790: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20791: if ($receiver) {
20792: $toupdate{$receiver};
20793: }
20794: }
20795: } else {
20796: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 20797: }
1.160.6.7 raeburn 20798: } else {
20799: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20800: }
1.160.6.26 raeburn 20801: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20802: }
20803: }
20804: }
20805: }
1.160.6.94 raeburn 20806: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 20807: if ($currcookies{$balancer}) {
20808: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20809: $balancer).'</li>';
20810: } else {
20811: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20812: $balancer).'</li>';
20813: }
1.160.6.94 raeburn 20814: }
1.160.6.106 raeburn 20815: }
20816: }
20817: if (keys(%toupdate)) {
20818: my %thismachine;
20819: my $updatedhere;
20820: my $cachetime = 60*60*24;
20821: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20822: foreach my $lonhost (keys(%toupdate)) {
20823: if ($thismachine{$lonhost}) {
20824: unless ($updatedhere) {
20825: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20826: $defaultshash{'loadbalancing'},
20827: $cachetime);
20828: $updatedhere = 1;
1.160.6.54 raeburn 20829: }
1.160.6.106 raeburn 20830: } else {
20831: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20832: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 20833: }
1.150 raeburn 20834: }
1.160.6.7 raeburn 20835: }
20836: if ($resulttext ne '') {
20837: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20838: } else {
20839: $resulttext = $nochgmsg;
20840: }
20841: } else {
1.160.6.7 raeburn 20842: $resulttext = $nochgmsg;
1.150 raeburn 20843: }
20844: } else {
1.160.6.7 raeburn 20845: $resulttext = '<span class="LC_error">'.
20846: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20847: }
20848: } else {
1.160.6.7 raeburn 20849: $resulttext = $nochgmsg;
1.150 raeburn 20850: }
20851: return $resulttext;
20852: }
20853:
1.48 raeburn 20854: sub recurse_check {
20855: my ($chkcats,$categories,$depth,$name) = @_;
20856: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20857: my $chg = 0;
20858: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20859: my $category = $chkcats->[$depth]{$name}[$j];
20860: my $item;
20861: if ($category eq '') {
20862: $chg ++;
20863: } else {
20864: my $deeper = $depth + 1;
20865: $item = &escape($category).':'.&escape($name).':'.$depth;
20866: if ($chg) {
20867: $categories->{$item} -= $chg;
20868: }
20869: &recurse_check($chkcats,$categories,$deeper,$category);
20870: $deeper --;
20871: }
20872: }
20873: }
20874: return;
20875: }
20876:
20877: sub recurse_cat_deletes {
20878: my ($item,$coursecategories,$deletions) = @_;
20879: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20880: my $subdepth = $depth + 1;
20881: if (ref($coursecategories) eq 'HASH') {
20882: foreach my $subitem (keys(%{$coursecategories})) {
20883: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20884: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20885: delete($coursecategories->{$subitem});
20886: $deletions->{$subitem} = 1;
20887: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 20888: }
1.48 raeburn 20889: }
20890: }
20891: return;
20892: }
20893:
1.125 raeburn 20894: sub active_dc_picker {
1.160.6.16 raeburn 20895: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 20896: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 20897: my @domcoord = keys(%domcoords);
20898: if (keys(%currhash)) {
20899: foreach my $dc (keys(%currhash)) {
20900: unless (exists($domcoords{$dc})) {
20901: push(@domcoord,$dc);
20902: }
20903: }
20904: }
20905: @domcoord = sort(@domcoord);
20906: my $numdcs = scalar(@domcoord);
20907: my $rows = 0;
20908: my $table;
1.125 raeburn 20909: if ($numdcs > 1) {
1.160.6.16 raeburn 20910: $table = '<table>';
20911: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20912: my $rem = $i%($numinrow);
20913: if ($rem == 0) {
20914: if ($i > 0) {
1.160.6.16 raeburn 20915: $table .= '</tr>';
1.125 raeburn 20916: }
1.160.6.16 raeburn 20917: $table .= '<tr>';
20918: $rows ++;
1.125 raeburn 20919: }
1.160.6.16 raeburn 20920: my $check = '';
20921: if ($inputtype eq 'radio') {
20922: if (keys(%currhash) == 0) {
20923: if (!$i) {
20924: $check = ' checked="checked"';
20925: }
20926: } elsif (exists($currhash{$domcoord[$i]})) {
20927: $check = ' checked="checked"';
20928: }
20929: } else {
20930: if (exists($currhash{$domcoord[$i]})) {
20931: $check = ' checked="checked"';
1.125 raeburn 20932: }
20933: }
1.160.6.16 raeburn 20934: if ($i == @domcoord - 1) {
1.125 raeburn 20935: my $colsleft = $numinrow - $rem;
20936: if ($colsleft > 1) {
1.160.6.16 raeburn 20937: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20938: } else {
1.160.6.16 raeburn 20939: $table .= '<td class="LC_left_item">';
1.125 raeburn 20940: }
20941: } else {
1.160.6.16 raeburn 20942: $table .= '<td class="LC_left_item">';
20943: }
20944: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20945: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20946: $table .= '<span class="LC_nobreak"><label>'.
20947: '<input type="'.$inputtype.'" name="'.$name.'"'.
20948: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20949: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 20950: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 20951: }
1.160.6.33 raeburn 20952: $table .= '</label></span></td>';
1.125 raeburn 20953: }
1.160.6.16 raeburn 20954: $table .= '</tr></table>';
20955: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 20956: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20957: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 20958: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 20959: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 20960: if ($user ne $dcname.':'.$dcdom) {
20961: $table .= ' ('.$dcname.':'.$dcdom.')';
20962: }
1.160.6.16 raeburn 20963: } else {
20964: my $check;
20965: if (exists($currhash{$domcoord[0]})) {
20966: $check = ' checked="checked"';
20967: }
1.160.6.50 raeburn 20968: $table = '<span class="LC_nobreak"><label>'.
20969: '<input type="checkbox" name="'.$name.'" '.
20970: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 20971: if ($user ne $dcname.':'.$dcdom) {
20972: $table .= ' ('.$dcname.':'.$dcdom.')';
20973: }
20974: $table .= '</label></span>';
1.160.6.16 raeburn 20975: $rows ++;
20976: }
1.125 raeburn 20977: }
1.160.6.16 raeburn 20978: return ($numdcs,$table,$rows);
1.125 raeburn 20979: }
20980:
1.137 raeburn 20981: sub usersession_titles {
20982: return &Apache::lonlocal::texthash(
20983: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20984: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20985: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20986: version => 'LON-CAPA version requirement',
1.138 raeburn 20987: excludedomain => 'Allow all, but exclude specific domains',
20988: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20989: primary => 'Primary (checked first)',
1.154 raeburn 20990: default => 'Default',
1.137 raeburn 20991: );
20992: }
20993:
1.152 raeburn 20994: sub id_for_thisdom {
20995: my (%servers) = @_;
20996: my %altids;
20997: foreach my $server (keys(%servers)) {
20998: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20999: if ($serverhome ne $server) {
21000: $altids{$serverhome} = $server;
21001: }
21002: }
21003: return %altids;
21004: }
21005:
1.150 raeburn 21006: sub count_servers {
21007: my ($currbalancer,%servers) = @_;
21008: my (@spares,$numspares);
21009: foreach my $lonhost (sort(keys(%servers))) {
21010: next if ($currbalancer eq $lonhost);
21011: push(@spares,$lonhost);
21012: }
21013: if ($currbalancer) {
21014: $numspares = scalar(@spares);
21015: } else {
21016: $numspares = scalar(@spares) - 1;
21017: }
21018: return ($numspares,@spares);
21019: }
21020:
21021: sub lonbalance_targets_js {
1.160.6.7 raeburn 21022: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21023: my $select = &mt('Select');
21024: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21025: if (ref($servers) eq 'HASH') {
21026: $alltargets = join("','",sort(keys(%{$servers})));
21027: my @homedoms;
21028: foreach my $server (sort(keys(%{$servers}))) {
21029: if (&Apache::lonnet::host_domain($server) eq $dom) {
21030: push(@homedoms,'1');
21031: } else {
21032: push(@homedoms,'0');
21033: }
21034: }
21035: $allishome = join("','",@homedoms);
21036: }
21037: if (ref($types) eq 'ARRAY') {
21038: if (@{$types} > 0) {
21039: @alltypes = @{$types};
21040: }
21041: }
21042: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21043: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 21044: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 21045: if (ref($settings) eq 'HASH') {
21046: %existing = %{$settings};
21047: }
21048: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 21049: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 21050: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21051: return <<"END";
21052:
21053: <script type="text/javascript">
21054: // <![CDATA[
21055:
1.160.6.7 raeburn 21056: currBalancers = new Array('$balancers');
21057:
21058: function toggleTargets(balnum) {
21059: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21060: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21061: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21062: var prevbalancer = prevhostitem.value;
21063: var baltotal = document.getElementById('loadbalancing_total').value;
21064: prevhostitem.value = balancer;
21065: if (prevbalancer != '') {
21066: var prevIdx = currBalancers.indexOf(prevbalancer);
21067: if (prevIdx != -1) {
21068: currBalancers.splice(prevIdx,1);
21069: }
21070: }
1.150 raeburn 21071: if (balancer == '') {
1.160.6.7 raeburn 21072: hideSpares(balnum);
1.150 raeburn 21073: } else {
1.160.6.7 raeburn 21074: var currIdx = currBalancers.indexOf(balancer);
21075: if (currIdx == -1) {
21076: currBalancers.push(balancer);
21077: }
1.150 raeburn 21078: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 21079: var ishomedom = homedoms[lonhostitem.selectedIndex];
21080: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21081: }
1.160.6.7 raeburn 21082: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21083: return;
21084: }
21085:
1.160.6.7 raeburn 21086: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21087: var alltargets = new Array('$alltargets');
21088: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21089: var offloadtypes = new Array('primary','default');
21090:
1.160.6.7 raeburn 21091: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21092: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21093:
1.151 raeburn 21094: for (var i=0; i<offloadtypes.length; i++) {
21095: var count = 0;
21096: for (var j=0; j<alltargets.length; j++) {
21097: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 21098: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21099: item.value = alltargets[j];
21100: item.style.textAlign='left';
21101: item.style.textFace='normal';
21102: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21103: if (currBalancers.indexOf(alltargets[j]) == -1) {
21104: item.disabled = '';
21105: } else {
21106: item.disabled = 'disabled';
21107: item.checked = false;
21108: }
1.151 raeburn 21109: count ++;
21110: }
1.150 raeburn 21111: }
21112: }
1.151 raeburn 21113: for (var k=0; k<insttypes.length; k++) {
21114: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21115: if (ishomedom == 1) {
1.160.6.7 raeburn 21116: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21117: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21118: } else {
1.160.6.7 raeburn 21119: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21120: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21121: }
21122: } else {
1.160.6.7 raeburn 21123: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21124: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21125: }
1.151 raeburn 21126: if ((insttypes[k] != '_LC_external') &&
21127: ((insttypes[k] != '_LC_internetdom') ||
21128: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 21129: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21130: item.options.length = 0;
21131: item.options[0] = new Option("","",true,true);
21132: var idx = 0;
1.151 raeburn 21133: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 21134: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21135: idx ++;
21136: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21137: }
21138: }
21139: }
21140: }
21141: return;
21142: }
21143:
1.160.6.7 raeburn 21144: function hideSpares(balnum) {
1.150 raeburn 21145: var alltargets = new Array('$alltargets');
21146: var insttypes = new Array('$allinsttypes');
21147: var offloadtypes = new Array('primary','default');
21148:
1.160.6.7 raeburn 21149: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21150: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21151:
21152: var total = alltargets.length - 1;
21153: for (var i=0; i<offloadtypes; i++) {
21154: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 21155: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21156: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21157: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21158: }
1.150 raeburn 21159: }
21160: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 21161: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21162: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21163: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 21164: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21165: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21166: }
21167: }
21168: return;
21169: }
21170:
1.160.6.7 raeburn 21171: function checkOffloads(item,balnum,type) {
1.150 raeburn 21172: var alltargets = new Array('$alltargets');
21173: var offloadtypes = new Array('primary','default');
21174: if (item.checked) {
21175: var total = alltargets.length - 1;
21176: var other;
21177: if (type == offloadtypes[0]) {
1.151 raeburn 21178: other = offloadtypes[1];
1.150 raeburn 21179: } else {
1.151 raeburn 21180: other = offloadtypes[0];
1.150 raeburn 21181: }
21182: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 21183: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21184: if (server == item.value) {
1.160.6.7 raeburn 21185: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21186: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21187: }
21188: }
21189: }
21190: }
21191: return;
21192: }
21193:
1.160.6.7 raeburn 21194: function singleServerToggle(balnum,type) {
21195: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21196: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 21197: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21198: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21199:
21200: } else {
1.160.6.7 raeburn 21201: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21203: }
21204: return;
21205: }
21206:
1.160.6.7 raeburn 21207: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21208: if (type == '_LC_external') {
1.160.6.26 raeburn 21209: return;
1.150 raeburn 21210: }
1.160.6.7 raeburn 21211: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21212: for (var i=0; i<typesRules.length; i++) {
21213: if (formname.elements[typesRules[i]].checked) {
21214: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 21215: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21216: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21217: } else {
1.160.6.7 raeburn 21218: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21219: }
21220: }
21221: }
21222: return;
21223: }
21224:
21225: function balancerDeleteChange(balnum) {
21226: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21227: var baltotal = document.getElementById('loadbalancing_total').value;
21228: var addtarget;
21229: var removetarget;
21230: var action = 'delete';
21231: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21232: var lonhost = hostitem.value;
21233: var currIdx = currBalancers.indexOf(lonhost);
21234: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21235: if (currIdx != -1) {
21236: currBalancers.splice(currIdx,1);
21237: }
21238: addtarget = lonhost;
21239: } else {
21240: if (currIdx == -1) {
21241: currBalancers.push(lonhost);
21242: }
21243: removetarget = lonhost;
21244: action = 'undelete';
21245: }
21246: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21247: }
21248: return;
21249: }
21250:
21251: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21252: if (baltotal > 1) {
21253: var offloadtypes = new Array('primary','default');
21254: var alltargets = new Array('$alltargets');
21255: var insttypes = new Array('$allinsttypes');
21256: for (var i=0; i<baltotal; i++) {
21257: if (i != balnum) {
21258: for (var j=0; j<offloadtypes.length; j++) {
21259: var total = alltargets.length - 1;
21260: for (var k=0; k<total; k++) {
21261: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21262: var server = serveritem.value;
21263: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21264: if (server == addtarget) {
21265: serveritem.disabled = '';
21266: }
21267: }
21268: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21269: if (server == removetarget) {
21270: serveritem.disabled = 'disabled';
21271: serveritem.checked = false;
21272: }
21273: }
21274: }
21275: }
21276: for (var j=0; j<insttypes.length; j++) {
21277: if (insttypes[j] != '_LC_external') {
21278: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21279: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21280: var currSel = singleserver.selectedIndex;
21281: var currVal = singleserver.options[currSel].value;
21282: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21283: var numoptions = singleserver.options.length;
21284: var needsnew = 1;
21285: for (var k=0; k<numoptions; k++) {
21286: if (singleserver.options[k] == addtarget) {
21287: needsnew = 0;
21288: break;
21289: }
21290: }
21291: if (needsnew == 1) {
21292: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21293: }
21294: }
21295: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21296: singleserver.options.length = 0;
21297: if ((currVal) && (currVal != removetarget)) {
21298: singleserver.options[0] = new Option("","",false,false);
21299: } else {
21300: singleserver.options[0] = new Option("","",true,true);
21301: }
21302: var idx = 0;
21303: for (var m=0; m<alltargets.length; m++) {
21304: if (currBalancers.indexOf(alltargets[m]) == -1) {
21305: idx ++;
21306: if (currVal == alltargets[m]) {
21307: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21308: } else {
21309: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21310: }
21311: }
21312: }
21313: }
21314: }
21315: }
21316: }
1.150 raeburn 21317: }
21318: }
21319: }
21320: return;
21321: }
21322:
1.152 raeburn 21323: // ]]>
21324: </script>
21325:
21326: END
21327: }
21328:
21329: sub new_spares_js {
21330: my @sparestypes = ('primary','default');
21331: my $types = join("','",@sparestypes);
21332: my $select = &mt('Select');
21333: return <<"END";
21334:
21335: <script type="text/javascript">
21336: // <![CDATA[
21337:
21338: function updateNewSpares(formname,lonhost) {
21339: var types = new Array('$types');
21340: var include = new Array();
21341: var exclude = new Array();
21342: for (var i=0; i<types.length; i++) {
21343: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21344: for (var j=0; j<spareboxes.length; j++) {
21345: if (formname.elements[spareboxes[j]].checked) {
21346: exclude.push(formname.elements[spareboxes[j]].value);
21347: } else {
21348: include.push(formname.elements[spareboxes[j]].value);
21349: }
21350: }
21351: }
21352: for (var i=0; i<types.length; i++) {
21353: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21354: var selIdx = newSpare.selectedIndex;
21355: var currnew = newSpare.options[selIdx].value;
21356: var okSpares = new Array();
21357: for (var j=0; j<newSpare.options.length; j++) {
21358: var possible = newSpare.options[j].value;
21359: if (possible != '') {
21360: if (exclude.indexOf(possible) == -1) {
21361: okSpares.push(possible);
21362: } else {
21363: if (currnew == possible) {
21364: selIdx = 0;
21365: }
21366: }
21367: }
21368: }
21369: for (var k=0; k<include.length; k++) {
21370: if (okSpares.indexOf(include[k]) == -1) {
21371: okSpares.push(include[k]);
21372: }
21373: }
21374: okSpares.sort();
21375: newSpare.options.length = 0;
21376: if (selIdx == 0) {
21377: newSpare.options[0] = new Option("$select","",true,true);
21378: } else {
21379: newSpare.options[0] = new Option("$select","",false,false);
21380: }
21381: for (var m=0; m<okSpares.length; m++) {
21382: var idx = m+1;
21383: var selThis = 0;
21384: if (selIdx != 0) {
21385: if (okSpares[m] == currnew) {
21386: selThis = 1;
21387: }
21388: }
21389: if (selThis == 1) {
21390: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21391: } else {
21392: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21393: }
21394: }
21395: }
21396: return;
21397: }
21398:
21399: function checkNewSpares(lonhost,type) {
21400: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21401: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.160.6.118.2 14(raebu 21402:23): if (chosen != '') {
1.152 raeburn 21403: var othertype;
21404: var othernewSpare;
21405: if (type == 'primary') {
21406: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21407: }
21408: if (type == 'default') {
21409: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21410: }
21411: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21412: othernewSpare.selectedIndex = 0;
21413: }
21414: }
21415: return;
21416: }
21417:
21418: // ]]>
21419: </script>
21420:
21421: END
21422:
21423: }
21424:
21425: sub common_domprefs_js {
21426: return <<"END";
21427:
21428: <script type="text/javascript">
21429: // <![CDATA[
21430:
1.150 raeburn 21431: function getIndicesByName(formname,item) {
1.152 raeburn 21432: var group = new Array();
1.150 raeburn 21433: for (var i=0;i<formname.elements.length;i++) {
21434: if (formname.elements[i].name == item) {
1.152 raeburn 21435: group.push(formname.elements[i].id);
1.150 raeburn 21436: }
21437: }
1.152 raeburn 21438: return group;
1.150 raeburn 21439: }
21440:
21441: // ]]>
21442: </script>
21443:
21444: END
1.152 raeburn 21445:
1.150 raeburn 21446: }
21447:
1.160.6.5 raeburn 21448: sub recaptcha_js {
21449: my %lt = &captcha_phrases();
21450: return <<"END";
21451:
21452: <script type="text/javascript">
21453: // <![CDATA[
21454:
21455: function updateCaptcha(caller,context) {
21456: var privitem;
21457: var pubitem;
21458: var privtext;
21459: var pubtext;
1.160.6.69 raeburn 21460: var versionitem;
21461: var versiontext;
1.160.6.5 raeburn 21462: if (document.getElementById(context+'_recaptchapub')) {
21463: pubitem = document.getElementById(context+'_recaptchapub');
21464: } else {
21465: return;
21466: }
21467: if (document.getElementById(context+'_recaptchapriv')) {
21468: privitem = document.getElementById(context+'_recaptchapriv');
21469: } else {
21470: return;
21471: }
21472: if (document.getElementById(context+'_recaptchapubtxt')) {
21473: pubtext = document.getElementById(context+'_recaptchapubtxt');
21474: } else {
21475: return;
21476: }
21477: if (document.getElementById(context+'_recaptchaprivtxt')) {
21478: privtext = document.getElementById(context+'_recaptchaprivtxt');
21479: } else {
21480: return;
21481: }
1.160.6.69 raeburn 21482: if (document.getElementById(context+'_recaptchaversion')) {
21483: versionitem = document.getElementById(context+'_recaptchaversion');
21484: } else {
21485: return;
21486: }
21487: if (document.getElementById(context+'_recaptchavertxt')) {
21488: versiontext = document.getElementById(context+'_recaptchavertxt');
21489: } else {
21490: return;
21491: }
1.160.6.5 raeburn 21492: if (caller.checked) {
21493: if (caller.value == 'recaptcha') {
21494: pubitem.type = 'text';
21495: privitem.type = 'text';
21496: pubitem.size = '40';
21497: privitem.size = '40';
21498: pubtext.innerHTML = "$lt{'pub'}";
21499: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 21500: versionitem.type = 'text';
21501: versionitem.size = '3';
21502: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 21503: } else {
21504: pubitem.type = 'hidden';
21505: privitem.type = 'hidden';
1.160.6.69 raeburn 21506: versionitem.type = 'hidden';
1.160.6.5 raeburn 21507: pubtext.innerHTML = '';
21508: privtext.innerHTML = '';
1.160.6.69 raeburn 21509: versiontext.innerHTML = '';
1.160.6.5 raeburn 21510: }
21511: }
21512: return;
21513: }
21514:
21515: // ]]>
21516: </script>
21517:
21518: END
21519:
21520: }
21521:
1.160.6.40 raeburn 21522: sub toggle_display_js {
1.160.6.16 raeburn 21523: return <<"END";
21524:
21525: <script type="text/javascript">
21526: // <![CDATA[
21527:
1.160.6.40 raeburn 21528: function toggleDisplay(domForm,caller) {
21529: if (document.getElementById(caller)) {
21530: var divitem = document.getElementById(caller);
21531: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 21532: var checkval = 1;
21533: var dispval = 'block';
1.160.6.93 raeburn 21534: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 21535: if (caller == 'emailoptions') {
1.160.6.118.2 14(raebu 21536:23): optionsElement = domForm.cancreate_email;
1.160.6.40 raeburn 21537: }
1.160.6.57 raeburn 21538: if (caller == 'studentsubmission') {
21539: optionsElement = domForm.postsubmit;
21540: }
1.160.6.64 raeburn 21541: if (caller == 'cloneinstcode') {
21542: optionsElement = domForm.canclone;
21543: checkval = 'instcode';
21544: }
1.160.6.93 raeburn 21545: if (selfcreateRegExp.test(caller)) {
21546: optionsElement = domForm.elements[caller];
21547: checkval = 'other';
21548: dispval = 'inline'
21549: }
1.160.6.40 raeburn 21550: if (optionsElement.length) {
1.160.6.16 raeburn 21551: var currval;
1.160.6.40 raeburn 21552: for (var i=0; i<optionsElement.length; i++) {
21553: if (optionsElement[i].checked) {
21554: currval = optionsElement[i].value;
1.160.6.16 raeburn 21555: }
21556: }
1.160.6.64 raeburn 21557: if (currval == checkval) {
21558: divitem.style.display = dispval;
1.160.6.16 raeburn 21559: } else {
1.160.6.40 raeburn 21560: divitem.style.display = 'none';
1.160.6.16 raeburn 21561: }
21562: }
21563: }
21564: return;
21565: }
21566:
21567: // ]]>
21568: </script>
21569:
21570: END
21571:
21572: }
21573:
1.160.6.5 raeburn 21574: sub captcha_phrases {
21575: return &Apache::lonlocal::texthash (
21576: priv => 'Private key',
21577: pub => 'Public key',
21578: original => 'original (CAPTCHA)',
21579: recaptcha => 'successor (ReCAPTCHA)',
21580: notused => 'unused',
1.160.6.69 raeburn 21581: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 21582: );
21583: }
21584:
1.160.6.24 raeburn 21585: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 21586: my ($dom,$cachekeys) = @_;
21587: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 21588: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21589: my %thismachine;
21590: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 21591:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 21592: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
21593: 'ipaccess');
21594: my %cache_by_lonhost;
21595: if (exists($cachekeys->{'samllanding'})) {
21596: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
21597: my %landing = %{$cachekeys->{'samllanding'}};
21598: my %domservers = &Apache::lonnet::get_servers($dom);
21599: if (keys(%domservers)) {
21600: foreach my $server (keys(%domservers)) {
21601: my @cached;
21602: next if ($thismachine{$server});
21603: if ($landing{$server}) {
21604: push(@cached,&escape('samllanding').':'.&escape($server));
21605: }
21606: if (@cached) {
21607: $cache_by_lonhost{$server} = \@cached;
21608: }
21609: }
21610: }
21611: }
21612: }
1.160.6.61 raeburn 21613: if (keys(%servers)) {
1.160.6.24 raeburn 21614: foreach my $server (keys(%servers)) {
21615: next if ($thismachine{$server});
1.160.6.27 raeburn 21616: my @cached;
21617: foreach my $name (@posscached) {
21618: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 21619: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
21620: if (ref($cachekeys->{$name}) eq 'HASH') {
21621: foreach my $key (keys(%{$cachekeys->{$name}})) {
21622: push(@cached,&escape($name).':'.&escape($key));
21623: }
21624: }
21625: } else {
21626: push(@cached,&escape($name).':'.&escape($dom));
21627: }
1.160.6.27 raeburn 21628: }
21629: }
1.160.6.113 raeburn 21630: if ((exists($cache_by_lonhost{$server})) &&
21631: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
21632: push(@cached,@{$cache_by_lonhost{$server}});
21633: }
1.160.6.27 raeburn 21634: if (@cached) {
21635: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21636: }
1.160.6.24 raeburn 21637: }
21638: }
21639: return;
21640: }
21641:
1.3 raeburn 21642: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>