Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.27
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 27(raebu 4:25): # $Id: domainprefs.pm,v 1.160.6.118.2.26 2025/01/16 15:42: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):
14(raebu 5164:23): sub secrets_form {
5165:23): my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5166:23): my @ids=&Apache::lonnet::current_machine_ids();
5167:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
5168:23): my $primary = &Apache::lonnet::domain($dom,'primary');
5169:23): my ($css_class,$extra,$numshown,$itemcount,$output);
5170:23): $itemcount = 0;
5171:23): foreach my $hostid (sort(keys(%servers))) {
5172:23): my ($showextra,$divsty,$switch);
5173:23): if ($hostid eq $primary) {
5174:23): if ($context eq 'ltisec') {
5175:23): if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5176:23): $showextra = 1;
5177:23): }
5178:23): if ($encrypt->{'ltisec_crslinkprot'}) {
5179:23): $showextra = 1;
5180:23): }
5181:23): } else {
5182:23): if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5183:23): $showextra = 1;
5184:23): }
5185:23): }
5186:23): unless (grep(/^\Q$hostid\E$/,@ids)) {
5187:23): $switch = 1;
5188:23): }
5189:23): if ($showextra) {
5190:23): $numshown ++;
5191:23): $divsty = 'display:inline-block';
5192:23): } else {
5193:23): $divsty = 'display:none';
5194:23): }
5195:23): $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5196:23): '<legend>'.$hostid.'</legend>';
5197:23): if ($switch) {
5198:23): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5199:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5200:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5201:23): if (exists($privkeys->{$hostid})) {
5202:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5203:23): '<span class="LC_nobreak">'.
5204:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5205:23): '<span class="LC_nobreak">'.&mt('Change?').
5206:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5207:23): (' 'x2).
5208:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5209:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5210:23): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5211:23): '</span></div>';
5212:23): } else {
5213:23): $extra .= '<span class="LC_nobreak">'.
5214:23): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5215:23): '</span>'."\n";
5216:23): }
5217:23): } elsif (exists($privkeys->{$hostid})) {
5218:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5219:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5220:23): '<span class="LC_nobreak">'.&mt('Change?').
5221:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5222:23): (' 'x2).
5223:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5224:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5225:23): '<span class="LC_nobreak">'.&mt('New Key').':'.
5226:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5227: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>'.
5228:23): '</span></div>';
5229:23): } else {
5230:23): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5231:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5232: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>';
5233:23): }
5234:23): $extra .= '</fieldset>';
5235:23): }
5236:23): }
5237:23): my (%choices,@toggles,%defaultchecked);
5238:23): if ($context eq 'ltisec') {
5239:23): %choices = &Apache::lonlocal::texthash (
5240:23): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5241:23): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5242:23): ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5243:23): );
5244:23): @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5245:23): %defaultchecked = (
5246:23): 'ltisec_crslinkprot' => 'off',
5247:23): 'ltisec_domlinkprot' => 'off',
5248:23): 'ltisec_consumers' => 'off',
5249:23): );
5250:23): } else {
5251:23): %choices = &Apache::lonlocal::texthash (
5252:23): toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5253:23): toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5254:23): );
5255:23): @toggles = qw(toolsec_crs toolsec_dom);
5256:23): %defaultchecked = (
5257:23): 'toolsec_crs' => 'off',
5258:23): 'toolsec_dom' => 'off',
5259:23): );
5260:23): }
5261:23): my ($onclick,$itemcount);
5262:23): $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5263:23): ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5264:23): \%choices,$itemcount,$onclick,'','left','no');
5265:23):
5266:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5267:23): my $noprivkeysty = 'display:inline-block';
5268:23): if ($numshown) {
5269:23): $noprivkeysty = 'display:none';
5270:23): }
5271:23): $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5272:23): '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5273:23): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5274:23): $extra.
5275:23): '</td></tr>';
5276:23): $itemcount ++;
5277:23): $$rowtotal += $itemcount;
5278:23): return $output;
5279:23): }
5280:23):
5(raebur 5281:2): sub print_lti {
5282:2): my ($position,$dom,$settings,$rowtotal) = @_;
5283:2): my $itemcount = 1;
5284:2): my ($datatable,$css_class);
18(raebu 5285:24): my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
5(raebur 5286:2): if (ref($settings) eq 'HASH') {
5287:2): if ($position eq 'top') {
5288:2): if (exists($settings->{'encrypt'})) {
5289:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5290:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
14(raebu 5291:23): if ($key eq 'consumers') {
5292:23): $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5293:23): } else {
5294:23): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5295:23): }
5(raebur 5296:2): }
5297:2): }
5298:2): }
5299:2): if (exists($settings->{'private'})) {
5300:2): if (ref($settings->{'private'}) eq 'HASH') {
5301:2): if (ref($settings->{'private'}) eq 'HASH') {
5302:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5303:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5304:2): }
5305:2): }
5306:2): }
5307:2): }
18(raebu 5308:24): } elsif ($position eq 'upper') {
5(raebur 5309:2): if (exists($settings->{'rules'})) {
5310:2): if (ref($settings->{'rules'}) eq 'HASH') {
5311:2): %rules = %{$settings->{'rules'}};
5312:2): }
5313:2): }
18(raebu 5314:24): } elsif ($position eq 'middle') {
5315:24): if (exists($settings->{'suggested'})) {
5316:24): if (ref($settings->{'suggested'}) eq 'HASH') {
5317:24): %suggestions = %{$settings->{'suggested'}};
5318:24): }
5319:24): }
14(raebu 5320:23): } elsif ($position eq 'lower') {
5(raebur 5321:2): if (exists($settings->{'linkprot'})) {
5322:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5323:2): %linkprot = %{$settings->{'linkprot'}};
5324:2): if ($linkprot{'lock'}) {
5325:2): delete($linkprot{'lock'});
5326:2): }
5327:2): }
5328:2): }
14(raebu 5329:23): } else {
18(raebu 5330:24): foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
14(raebu 5331:23): if (exists($settings->{$key})) {
5332:23): delete($settings->{$key});
5333:23): }
5334:23): }
5(raebur 5335:2): }
5336:2): }
5337:2): if ($position eq 'top') {
14(raebu 5338:23): $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
18(raebu 5339:24): } elsif ($position eq 'upper') {
14(raebu 5340:23): $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5341:23): $$rowtotal += $itemcount;
18(raebu 5342:24): } elsif ($position eq 'middle') {
5343:24): $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
5344:24): $$rowtotal += $itemcount;
14(raebu 5345:23): } elsif ($position eq 'lower') {
18(raebu 5346:24): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
14(raebu 5347:23): } else {
5348:23): my ($switchserver,$switchmessage);
5349:23): $switchserver = &check_switchserver($dom);
5350:23): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5351:23): my $maxnum = 0;
5352:23): my %ordered;
5353:23): if (ref($settings) eq 'HASH') {
5354:23): foreach my $item (keys(%{$settings})) {
5355:23): if (ref($settings->{$item}) eq 'HASH') {
5356:23): my $num = $settings->{$item}{'order'};
5357:23): if ($num eq '') {
5358:23): $num = scalar(keys(%{$settings}));
5359:23): }
5360:23): $ordered{$num} = $item;
5(raebur 5361:2): }
5362:2): }
14(raebu 5363:23): }
5364:23): $maxnum = scalar(keys(%ordered));
5365:23): my %lt = <i_names();
5366:23): if (keys(%ordered)) {
5367:23): my @items = sort { $a <=> $b } keys(%ordered);
5368:23): for (my $i=0; $i<@items; $i++) {
5369:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5370:23): my $item = $ordered{$items[$i]};
5371:23): my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5372:23): if (ref($settings->{$item}) eq 'HASH') {
5373:23): $key = $settings->{$item}->{'key'};
5374:23): $usable = $settings->{$item}->{'usable'};
5375:23): $lifetime = $settings->{$item}->{'lifetime'};
5376:23): $consumer = $settings->{$item}->{'consumer'};
5377:23): $requser = $settings->{$item}->{'requser'};
5378:23): $crsinc = $settings->{$item}->{'crsinc'};
5379:23): $current = $settings->{$item};
5380:23): }
5381:23): my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5382:23): my %checkedrequser = (
5383:23): yes => ' checked="checked"',
5384:23): no => '',
5385:23): );
5386:23): if (!$requser) {
5387:23): $checkedrequser{'no'} = $checkedrequser{'yes'};
5388:23): $checkedrequser{'yes'} = '';
5389:23): }
5390:23): my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5391:23): my %checkedcrsinc = (
5392:23): yes => ' checked="checked"',
5393:23): no => '',
5394:23): );
5395:23): if (!$crsinc) {
5396:23): $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5397:23): $checkedcrsinc{'yes'} = '';
5398:23): }
5399:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5400:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5401:23): .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5402:23): for (my $k=0; $k<=$maxnum; $k++) {
5403:23): my $vpos = $k+1;
5404:23): my $selstr;
5405:23): if ($k == $i) {
5406:23): $selstr = ' selected="selected" ';
5407:23): }
5408:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5409:23): }
5410:23): $datatable .= '</select>'.(' 'x2).
5411:23): '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5412:23): &mt('Delete?').'</label></span></td>'.
5413:23): '<td colspan="2">'.
5414:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5415:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5416:23): ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5417:23): (' 'x2).
5418:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5419:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5420:23): (' 'x2).
5421:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5422:23): 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5423:23): if ($key ne '') {
5424:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5425:23): if ($switchserver) {
5426:23): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5427:23): } else {
5428:23): $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5429:23): }
5430:23): $datatable .= '</span> '.(' 'x2);
5431:23): } elsif (!$switchserver) {
5432:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5433:23): '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5434:23): '</span> '.(' 'x2);
5435:23): }
5436:23): if ($switchserver) {
5437:23): if ($usable ne '') {
5438:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5439:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5440:23): '<span class="LC_nobreak">'.&mt('Change secret?').
5441:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5442:23): (' 'x2).
5443:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5444:23): '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5445:23): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5446:23): '</div>';
5447:23): } elsif ($key eq '') {
5448:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5449:23): } else {
5450:23): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5451:23): }
5452:23): } else {
5453:23): if ($usable ne '') {
5454:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5455:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5456:23): '<span class="LC_nobreak">'.&mt('Change?').
5457:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5458:23): (' 'x2).
5459:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5460:23): '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5461:23): '<span class="LC_nobreak">'.&mt('New Secret').':'.
5462:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5463: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>';
5464:23): } else {
5465:23): $datatable .=
5466:23): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5467:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5468: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>';
5469:23): }
5470:23): }
5471:23): $datatable .= '<br /><br />'.
5472:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5473:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5474:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5475:23): '<br /><br />'.
5476:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5477:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5478:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5479:23): (' 'x4).
5480:23): '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5481:23): '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5482:23): $itemcount ++;
5(raebur 5483:2): }
14(raebu 5484:23): }
5485:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5486:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5487:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5488:23): '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5489:23): '<select name="lti_pos_add"'.$chgstr.'>';
5490:23): for (my $k=0; $k<$maxnum+1; $k++) {
5491:23): my $vpos = $k+1;
5492:23): my $selstr;
5493:23): if ($k == $maxnum) {
5494:23): $selstr = ' selected="selected" ';
5(raebur 5495:2): }
14(raebu 5496:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5497:23): }
5498:23): $datatable .= '</select> '."\n".
5499:23): '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5500:23): '<td colspan="2">'.
5501:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5502:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5503:23): ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5504:23): (' 'x2).
5505:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5506:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5507:23): (' 'x2).
5508:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5509:23): if ($switchserver) {
5510:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5511:23): } else {
5512:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5513:23): (' 'x2).
5514:23): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5515: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";
5516:23): }
5517:23): $datatable .= '<br /><br />'.
5518:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5519:23): '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5520:23): '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5521:23): '<br /><br />'.
5522:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5523:23): '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5524:23): '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5525:23): '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5526:23): '</td>'."\n".
5527:23): '</tr>'."\n";
5528:23): $itemcount ++;
5529:23): }
5530:23): $$rowtotal += $itemcount;
5531:23): return $datatable;
5532:23): }
5533:23):
5534:23): sub lti_names {
5535:23): my %lt = &Apache::lonlocal::texthash(
5536:23): 'version' => 'LTI Version',
5537:23): 'url' => 'URL',
5538:23): 'key' => 'Key',
5539:23): 'lifetime' => 'Nonce lifetime (s)',
5540:23): 'consumer' => 'Consumer',
5541:23): 'secret' => 'Secret',
5542:23): 'requser' => "User's identity sent",
5543:23): 'crsinc' => "Course's identity sent",
5544:23): 'email' => 'Email address',
5545:23): 'sourcedid' => 'User ID',
5546:23): 'other' => 'Other',
5547:23): 'passback' => 'Can return grades to Consumer:',
5548:23): 'roster' => 'Can retrieve roster from Consumer:',
5549:23): 'topmenu' => 'Display LON-CAPA page header',
5550:23): 'inlinemenu'=> 'Display LON-CAPA inline menu',
5551:23): );
5552:23): return %lt;
5553:23): }
5554:23):
5555:23): sub lti_options {
5556:23): my ($num,$current,$itemcount,%lt) = @_;
5557:23): my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5558:23): $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5559:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5560:23): $checked{'storecrs'}{'Y'} = ' checked="checked"';
5561:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5562:23): $checked{'mapcrstype'} = {};
5563:23): $checked{'makeuser'} = {};
5564:23): $checked{'selfenroll'} = {};
5565:23): $checked{'crssec'} = {};
5566:23): $checked{'crssecsrc'} = {};
5567:23): $checked{'lcauth'} = {};
5568:23): $checked{'menuitem'} = {};
5569:23): if ($num eq 'add') {
5570:23): $checked{'lcauth'}{'lti'} = ' checked="checked"';
5571:23): }
5572:23): my $userfieldsty = 'none';
5573:23): my $crsfieldsty = 'none';
5574:23): my $crssecfieldsty = 'none';
5575:23): my $secsrcfieldsty = 'none';
5576:23): my $callbacksty = 'none';
5577:23): my $passbacksty = 'none';
5578:23): my $optionsty = 'block';
5579:23): my $crssty = 'block';
5580:23): my $lcauthparm;
5581:23): my $lcauthparmstyle = 'display:none';
5582:23): my $lcauthparmtext;
5583:23): my $menusty;
5584:23): my $numinrow = 4;
5585:23): my %menutitles = <imenu_titles();
5586:23):
5587:23): if (ref($current) eq 'HASH') {
5588:23): if (!$current->{'requser'}) {
5589:23): $optionsty = 'none';
5590:23): $crssty = 'none';
5591:23): } elsif (!$current->{'crsinc'}) {
5592:23): $crssty = 'none';
5593:23): }
5594:23): if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5595:23): $checked{'mapuser'}{'sourcedid'} = '';
5596:23): if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5597:23): $checked{'mapuser'}{'email'} = ' checked="checked"';
5(raebur 5598:2): } else {
14(raebu 5599:23): $checked{'mapuser'}{'other'} = ' checked="checked"';
5600:23): $userfield = $current->{'mapuser'};
5601:23): $userfieldsty = 'inline-block';
5(raebur 5602:2): }
14(raebu 5603:23): }
5604:23): if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5605:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5606:23): if ($current->{'mapcrs'} eq 'context_id') {
5607:23): $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5608:23): } else {
5609:23): $checked{'mapcrs'}{'other'} = ' checked="checked"';
5610:23): $cidfield = $current->{'mapcrs'};
5611:23): $crsfieldsty = 'inline-block';
5612:23): }
5613:23): }
5614:23): if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5615:23): foreach my $type (@{$current->{'mapcrstype'}}) {
5616:23): $checked{'mapcrstype'}{$type} = ' checked="checked"';
5617:23): }
5618:23): }
5619:23): if (!$current->{'storecrs'}) {
5620:23): $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5621:23): $checked{'storecrs'}{'Y'} = '';
5622:23): }
5623:23): if ($current->{'makecrs'}) {
5624:23): $checked{'makecrs'}{'Y'} = ' checked="checked"';
5625:23): }
5626:23): if (ref($current->{'makeuser'}) eq 'ARRAY') {
5627:23): foreach my $role (@{$current->{'makeuser'}}) {
5628:23): $checked{'makeuser'}{$role} = ' checked="checked"';
5629:23): }
5630:23): }
5631:23): if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5632:23): $checked{'lcauth'}{$1} = ' checked="checked"';
5633:23): unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5634:23): $lcauthparm = $current->{'lcauthparm'};
5635:23): $lcauthparmstyle = 'display:table-row';
5636:23): if ($current->{'lcauth'} eq 'localauth') {
5637:23): $lcauthparmtext = &mt('Local auth argument');
5(raebur 5638:2): } else {
14(raebu 5639:23): $lcauthparmtext = &mt('Kerberos domain');
5(raebur 5640:2): }
14(raebu 5641:23): }
5642:23): }
5643:23): if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5644:23): foreach my $role (@{$current->{'selfenroll'}}) {
5645:23): $checked{'selfenroll'}{$role} = ' checked="checked"';
5646:23): }
5647:23): }
5648:23): if (ref($current->{'maproles'}) eq 'HASH') {
5649:23): %rolemaps = %{$current->{'maproles'}};
5650:23): }
5651:23): if ($current->{'section'} ne '') {
5652:23): $checked{'crssec'}{'Y'} = ' checked="checked"';
5653:23): $crssecfieldsty = 'inline-block';
5654:23): if ($current->{'section'} eq 'course_section_sourcedid') {
5655:23): $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5(raebur 5656:2): } else {
14(raebu 5657:23): $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5658:23): $crssecsrc = $current->{'section'};
5659:23): $secsrcfieldsty = 'inline-block';
5(raebur 5660:2): }
14(raebu 5661:23): } else {
5662:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5(raebur 5663:2): }
14(raebu 5664:23): if ($current->{'callback'} ne '') {
5665:23): $callback = $current->{'callback'};
5666:23): $checked{'callback'}{'Y'} = ' checked="checked"';
5667:23): $callbacksty = 'inline-block';
5668:23): } else {
5669:23): $checked{'callback'}{'N'} = ' checked="checked"';
5670:23): }
5671:23): if ($current->{'topmenu'}) {
5672:23): $checked{'topmenu'}{'Y'} = ' checked="checked"';
5673:23): } else {
5674:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5675:23): }
5676:23): if ($current->{'inlinemenu'}) {
5677:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5678:23): } else {
5679:23): $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5680:23): }
5681:23): if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5682:23): $menusty = 'inline-block';
5683:23): if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5684:23): foreach my $item (@{$current->{'lcmenu'}}) {
5685:23): if (exists($menutitles{$item})) {
5686:23): $checked{'menuitem'}{$item} = ' checked="checked"';
5687:23): }
5688:23): }
5689:23): }
5690:23): } else {
5691:23): $menusty = 'none';
5692:23): }
5693:23): } else {
5694:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5695:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5696:23): $checked{'callback'}{'N'} = ' checked="checked"';
5697:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5698:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5699:23): $checked{'menuitem'}{'grades'} = ' checked="checked"';
5700:23): $menusty = 'inline-block';
5(raebur 5701:2): }
14(raebu 5702:23): my @coursetypes = ('official','unofficial','community','textbook','lti');
5703:23): my %coursetypetitles = &Apache::lonlocal::texthash (
5704:23): official => 'Official',
5705:23): unofficial => 'Unofficial',
5706:23): community => 'Community',
5707:23): textbook => 'Textbook',
5708:23): lti => 'LTI Provider',
5709:23): );
5710:23): my @authtypes = ('internal','krb4','krb5','localauth');
5711:23): my %shortauth = (
5712:23): internal => 'int',
5713:23): krb4 => 'krb4',
5714:23): krb5 => 'krb5',
5715:23): localauth => 'loc'
5716:23): );
5717:23): my %authnames = &authtype_names();
5718:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5719:23): my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5720:23): my @courseroles = ('cc','in','ta','ep','st');
5721:23): my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5722:23): my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5723:23): my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5724:23): my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5725:23): my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5726:23): my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5727:23): my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5728:23): my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5729:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5730:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5731:23): $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5732:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5733:23): $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5734:23): '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5735:23): '<span class="LC_nobreak">'.&mt('Parameter').': '.
5736:23): '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5737:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5738:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5739:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5740:23): foreach my $option ('sourcedid','email','other') {
5741:23): $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5742:23): $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5743:23): ($option eq 'other' ? '' : (' 'x2) );
5744:23): }
5745:23): $output .= '</span></div>'.
5746:23): '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5747:23): '<input type="text" name="lti_customuser_'.$num.'" '.
5748:23): 'value="'.$userfield.'" /></div></fieldset>'.
5749:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5750:23): foreach my $ltirole (@ltiroles) {
5751:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5752:23): $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5753:23): }
5754:23): $output .= '</fieldset>'.
5755:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5756:23): '<table>'.
5757:23): &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5758:23): '</table>'.
5759:23): '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5760:23): '<td class="LC_left_item">';
5761:23): foreach my $auth ('lti',@authtypes) {
5762:23): my $authtext;
5763:23): if ($auth eq 'lti') {
5764:23): $authtext = &mt('None');
5765:23): } else {
5766:23): $authtext = $authnames{$shortauth{$auth}};
5767:23): }
5768:23): $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5769:23): '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5770:23): $authtext.'</label></span> ';
5771:23): }
5772:23): $output .= '</td></tr>'.
5773:23): '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5774:23): '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5775:23): '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5776:23): '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5777:23): '</table></fieldset>'.
5778:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5779:23): &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5780:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5781:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5782:23): $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5783:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5784:23): $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5785:23): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5786:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5787:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5788:23): $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5789:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5790:23): $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5791:23): $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5792:23): '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5793:23): '<span class="LC_nobreak">'.&mt('Menu items').': ';
5794:23): foreach my $type ('fullname','coursetitle','role','logout','grades') {
5795:23): $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5796:23): $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5797:23): (' 'x2);
5798:23): }
5799:23): $output .= '</span></div></fieldset>'.
5800:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5801:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.
5802:23): &mt('Unique course identifier').': ';
5803:23): foreach my $option ('course_offering_sourcedid','context_id','other') {
5804:23): $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5805:23): $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5806:23): ($option eq 'other' ? '' : (' 'x2) );
5807:23): }
5808:23): $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5809:23): '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5810:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5811:23): '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5812:23): foreach my $type (@coursetypes) {
5813:23): $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5814:23): $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5815:23): (' 'x2);
5816:23): }
5817:23): $output .= '</span><br /><br />'.
5818:23): '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5819:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5820:23): $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5821:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5822:23): $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5823:23): '</fieldset>'.
5824:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5825:23): foreach my $ltirole (@lticourseroles) {
5826:23): my ($selected,$selectnone);
5827:23): if ($rolemaps{$ltirole} eq '') {
5828:23): $selectnone = ' selected="selected"';
5829:23): }
5830:23): $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5831:23): '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5832:23): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5833:23): foreach my $role (@courseroles) {
5834:23): unless ($selectnone) {
5835:23): if ($rolemaps{$ltirole} eq $role) {
5836:23): $selected = ' selected="selected"';
5837:23): } else {
5838:23): $selected = '';
5839:23): }
5840:23): }
5841:23): $output .= '<option value="'.$role.'"'.$selected.'>'.
5842:23): &Apache::lonnet::plaintext($role,'Course').
5843:23): '</option>';
5844:23): }
5845:23): $output .= '</select></td>';
5846:23): }
5847:23): $output .= '</tr></table></fieldset>'.
5848:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5849:23): '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5850:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5851:23): $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5852:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5853:23): $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5854:23): '</fieldset>'.
5855:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5856:23): foreach my $lticrsrole (@lticourseroles) {
5857:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5858:23): $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5859:23): }
5860:23): $output .= '</fieldset>'.
5861:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5862:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5863:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5864:23): $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5865:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5866:23): $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5867:23): '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5868:23): '<span class="LC_nobreak">'.&mt('From').':<label>'.
5869:23): '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5870:23): $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5871:23): &mt('Standard field').'</label>'.(' 'x2).
5872:23): '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5873:23): $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5874:23): '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5875:23): '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5876:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5877:23): my ($pb1p1chk,$pb1p0chk,$onclickpb);
5878:23): foreach my $extra ('roster','passback') {
5879:23): my $checkedon = '';
5880:23): my $checkedoff = ' checked="checked"';
5881:23): if ($extra eq 'passback') {
5882:23): $pb1p1chk = ' checked="checked"';
5883:23): $pb1p0chk = '';
5884:23): $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5885:23): } else {
5886:23): $onclickpb = '';
5887:23): }
5888:23): if (ref($current) eq 'HASH') {
5889:23): if (($current->{$extra})) {
5890:23): $checkedon = $checkedoff;
5891:23): $checkedoff = '';
5892:23): if ($extra eq 'passback') {
5893:23): $passbacksty = 'inline-block';
5894:23): }
5895:23): if ($current->{'passbackformat'} eq '1.0') {
5896:23): $pb1p0chk = ' checked="checked"';
5897:23): $pb1p1chk = '';
5898:23): }
5899:23): }
5900:23): }
5901:23): $output .= $lt{$extra}.' '.
5902:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5903:23): &mt('No').'</label>'.(' 'x2).
5904:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5905:23): &mt('Yes').'</label><br />';
5906:23): }
5907:23): $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5908:23): '<span class="LC_nobreak">'.&mt('Grade format').
5909:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5910:23): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5911:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5912:23): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5913:23): '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5914:23): $output .= '</span></div></fieldset>';
5915:23): # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5916:23): #
5917:23): # $output .= '</fieldset>'.
5918:23): # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5919:23): return $output;
5920:23): }
5921:23):
5922:23): sub ltimenu_titles {
5923:23): return &Apache::lonlocal::texthash(
5924:23): fullname => 'Full name',
5925:23): coursetitle => 'Course title',
5926:23): role => 'Role',
5927:23): logout => 'Logout',
5928:23): grades => 'Grades',
5929:23): );
5(raebur 5930:2): }
5931:2):
18(raebu 5932:24): sub linkprot_suggestions {
5933:24): my ($suggested,$itemcount) = @_;
5934:24): my $count = 0;
5935:24): my $next = 1;
5936:24): my %lt = &Apache::lonlocal::texthash(
5937:24): 'name' => 'Suggested Launcher',
5938:24): 'info' => 'Recommendations',
5939:24): );
5940:24): my ($datatable,$css_class,$dest);
5941:24): if (ref($suggested) eq 'HASH') {
5942:24): my @current = sort { $a <=> $b } keys(%{$suggested});
5943:24): $next += $current[-1];
5944:24): for (my $i=0; $i<@current; $i++) {
5945:24): my $num = $current[$i];
5946:24): my %values;
5947:24): if (ref($suggested->{$num}) eq 'HASH') {
5948:24): %values = %{$suggested->{$num}};
5949:24): } else {
5950:24): next;
5951:24): }
5952:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5953:24): $datatable .=
5954:24): '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5955:24): '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
5956:24): &mt('Delete?').'</label></span></td><td>'."\n".
5957:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
5958:24): '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
5959:24): '</fieldset></div>'.
5960:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
5961:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
5962:24): '</fieldset></div>'.
5963:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
5964:24): '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
5965:24): $$itemcount ++;
5966:24): }
5967:24): }
5968:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5969:24): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5970:24): '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
5971:24): '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5972:24): '<td>'."\n".
5973:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
5974:24): '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
5975:24): '</fieldset></div>'.
5976:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
5977:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
5978:24): '</fieldset></div>'.
5979:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
5980:24): '</td></tr>'."\n";
5981:24): return $datatable;
5982:24): }
14(raebu 5983:23):
1.121 raeburn 5984: sub print_coursedefaults {
1.139 raeburn 5985: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 5986: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 5987: my $itemcount = 1;
1.160.6.16 raeburn 5988: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 5989: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.118.2 20(raebu 5990:24): coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.160.6.16 raeburn 5991: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
5992: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 5993: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
5994: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 5995: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 5996: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 5997: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 5998: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 5999: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 6000:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
14(raebu 6001:23): domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6002:23): exttool => 'External Tools can be defined and configured in courses/communities (by type)',
22(raebu 6003:24): crseditors => 'Available editors for web pages and/or problems created in a course/community',
7(raebur 6004:2): );
1.160.6.21 raeburn 6005: my %staticdefaults = (
6006: anonsurvey_threshold => 10,
6007: uploadquota => 500,
1.160.6.118.2 15(raebu 6008:23): coursequota => 20,
1.160.6.57 raeburn 6009: postsubmit => 60,
1.160.6.70 raeburn 6010: mysqltables => 172800,
1.160.6.118.2 14(raebu 6011:23): domexttool => 1,
6012:23): exttool => 0,
22(raebu 6013:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 6014: );
1.139 raeburn 6015: if ($position eq 'top') {
1.160.6.57 raeburn 6016: %defaultchecked = (
6017: 'uselcmath' => 'on',
6018: 'usejsme' => 'on',
1.160.6.115 raeburn 6019: 'inline_chem' => 'on',
1.160.6.64 raeburn 6020: 'canclone' => 'none',
1.160.6.57 raeburn 6021: );
1.160.6.115 raeburn 6022: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 6023: my $deftex = $Apache::lonnet::deftex;
6024: if (ref($settings) eq 'HASH') {
6025: if ($settings->{'texengine'}) {
6026: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6027: $deftex = $settings->{'texengine'};
6028: }
6029: }
6030: }
6031: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6032: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6033: '<span class="LC_nobreak">'.$choices{'texengine'}.
6034: '</span></td><td class="LC_right_item">'.
6035: '<select name="texengine">'."\n";
6036: my %texoptions = (
6037: MathJax => 'MathJax',
6038: mimetex => &mt('Convert to Images'),
6039: tth => &mt('TeX to HTML'),
6040: );
6041: foreach my $renderer ('MathJax','mimetex','tth') {
6042: my $selected = '';
6043: if ($renderer eq $deftex) {
6044: $selected = ' selected="selected"';
6045: }
6046: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6047: }
6048: $mathdisp .= '</select></td></tr>'."\n";
6049: $itemcount ++;
1.139 raeburn 6050: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6051: \%choices,$itemcount);
1.160.6.90 raeburn 6052: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 6053: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6054: $datatable .=
6055: '<tr'.$css_class.'><td valign="top">'.
6056: '<span class="LC_nobreak">'.$choices{'canclone'}.
6057: '</span></td><td class="LC_left_item">';
6058: my $currcanclone = 'none';
6059: my $onclick;
6060: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 6061: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 6062: none => 'No additional course requesters',
6063: domain => "Any course requester in course's domain",
6064: instcode => 'Course requests for official courses ...',
6065: );
6066: my (%codedefaults,@code_order,@posscodes);
6067: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6068: \@code_order) eq 'ok') {
6069: if (@code_order > 0) {
6070: push(@cloneoptions,'instcode');
6071: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6072: }
6073: }
6074: if (ref($settings) eq 'HASH') {
6075: if ($settings->{'canclone'}) {
6076: if (ref($settings->{'canclone'}) eq 'HASH') {
6077: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6078: if (@code_order > 0) {
6079: $currcanclone = 'instcode';
6080: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6081: }
6082: }
6083: } elsif ($settings->{'canclone'} eq 'domain') {
6084: $currcanclone = $settings->{'canclone'};
6085: }
6086: }
6087: }
6088: foreach my $option (@cloneoptions) {
6089: my ($checked,$additional);
6090: if ($currcanclone eq $option) {
6091: $checked = ' checked="checked"';
6092: }
6093: if ($option eq 'instcode') {
6094: if (@code_order) {
6095: my $show = 'none';
6096: if ($checked) {
6097: $show = 'block';
6098: }
1.160.6.118.2 14(raebu 6099:23): $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.160.6.64 raeburn 6100: &mt('Institutional codes for new and cloned course have identical:').
6101: '<br />';
6102: foreach my $item (@code_order) {
6103: my $codechk;
6104: if ($checked) {
6105: if (grep(/^\Q$item\E$/,@posscodes)) {
6106: $codechk = ' checked="checked"';
6107: }
6108: }
6109: $additional .= '<label>'.
6110: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6111: $item.'</label>';
6112: }
6113: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6114: }
6115: }
6116: $datatable .=
6117: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6118: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6119: '</label> '.$additional.'</span><br />';
6120: }
6121: $datatable .= '</td>'.
6122: '</tr>';
6123: $itemcount ++;
1.139 raeburn 6124: } else {
6125: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.118.2 15(raebu 6126:23): my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6127:23): %deftimeout,%currmysql);
1.160.6.16 raeburn 6128: my $currusecredits = 0;
1.160.6.57 raeburn 6129: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 6130:2): my $ltiauth = 0;
14(raebu 6131:23): my %domexttool;
6132:23): my %exttool;
22(raebu 6133:24): my %crseditors;
1.160.6.30 raeburn 6134: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 6135: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 6136:2): if ($settings->{'ltiauth'}) {
6137:2): $ltiauth = 1;
6138:2): }
14(raebu 6139:23): if (ref($settings->{'domexttool'}) eq 'HASH') {
6140:23): foreach my $type (@types) {
6141:23): if ($settings->{'domexttool'}->{$type}) {
6142:23): $domexttool{$type} = ' checked="checked"';
6143:23): }
6144:23): }
6145:23): } else {
6146:23): foreach my $type (@types) {
6147:23): if ($staticdefaults{'domexttool'}) {
6148:23): $domexttool{$type} = ' checked="checked"';
6149:23): }
6150:23): }
6151:23): }
6152:23): if (ref($settings->{'exttool'}) eq 'HASH') {
6153:23): foreach my $type (@types) {
6154:23): if ($settings->{'exttool'}->{$type}) {
6155:23): $exttool{$type} = ' checked="checked"';
6156:23): }
6157:23): }
6158:23): }
22(raebu 6159:24): if (ref($settings->{'crseditors'}) eq 'ARRAY') {
6160:24): foreach my $editor (@{$settings->{'crseditors'}}) {
6161:24): $crseditors{$editor} = ' checked="checked"';
6162:24): }
6163:24): } else {
6164:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6165:24): $crseditors{$editor} = ' checked="checked"';
6166:24): }
6167:24): }
1.139 raeburn 6168: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 6169: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6170: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6171: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6172: }
6173: }
1.160.6.118.2 15(raebu 6174:23): if (ref($settings->{'coursequota'}) eq 'HASH') {
6175:23): foreach my $type (keys(%{$settings->{'coursequota'}})) {
6176:23): $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6177:23): }
6178:23): }
1.160.6.16 raeburn 6179: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 6180: foreach my $type (@types) {
6181: next if ($type eq 'community');
6182: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6183: if ($defcredits{$type} ne '') {
6184: $currusecredits = 1;
6185: }
6186: }
6187: }
6188: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6189: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6190: $postsubmitclient = 0;
6191: foreach my $type (@types) {
6192: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6193: }
6194: } else {
6195: foreach my $type (@types) {
6196: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6197: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6198: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6199: } else {
6200: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6201: }
6202: } else {
6203: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6204: }
6205: }
6206: }
6207: } else {
6208: foreach my $type (@types) {
6209: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 6210: }
6211: }
1.160.6.70 raeburn 6212: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6213: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6214: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6215: }
6216: } else {
6217: foreach my $type (@types) {
6218: $currmysql{$type} = $staticdefaults{'mysqltables'};
6219: }
6220: }
1.160.6.58 raeburn 6221: } else {
6222: foreach my $type (@types) {
6223: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.118.2 14(raebu 6224:23): if ($staticdefaults{'domexttool'}) {
6225:23): $domexttool{$type} = ' checked="checked"';
6226:23): }
1.160.6.58 raeburn 6227: }
1.160.6.118.2 22(raebu 6228:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6229:24): $crseditors{$editor} = ' checked="checked"';
6230:24): }
1.139 raeburn 6231: }
6232: if (!$currdefresponder) {
1.160.6.21 raeburn 6233: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6234: } elsif ($currdefresponder < 1) {
6235: $currdefresponder = 1;
6236: }
1.160.6.21 raeburn 6237: foreach my $type (@types) {
6238: if ($curruploadquota{$type} eq '') {
6239: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6240: }
1.160.6.118.2 15(raebu 6241:23): if ($currcoursequota{$type} eq '') {
6242:23): $currcoursequota{$type} = $staticdefaults{'coursequota'};
6243:23): }
1.160.6.21 raeburn 6244: }
1.139 raeburn 6245: $datatable .=
1.160.6.16 raeburn 6246: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6247: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6248: '</span></td>'.
6249: '<td class="LC_right_item"><span class="LC_nobreak">'.
6250: '<input type="text" name="anonsurvey_threshold"'.
6251: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 6252: '</td></tr>'."\n";
6253: $itemcount ++;
6254: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6255: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6256: $choices{'uploadquota'}.
6257: '</span></td>'.
6258: '<td align="right" class="LC_right_item">'.
6259: '<table><tr>';
1.160.6.21 raeburn 6260: foreach my $type (@types) {
6261: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6262: '<input type="text" name="uploadquota_'.$type.'"'.
6263: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6264: }
6265: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 6266: $itemcount ++;
1.160.6.118.2 15(raebu 6267:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6268:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6269:23): $choices{'coursequota'}.
6270:23): '</span></td>'.
6271:23): '<td style="text-align: right" class="LC_right_item">'.
6272:23): '<table><tr>';
6273:23): foreach my $type (@types) {
6274:23): $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6275:23): '<input type="text" name="coursequota_'.$type.'"'.
6276:23): ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6277:23): }
6278:23): $datatable .= '</tr></table></td></tr>'."\n";
6279:23): $itemcount ++;
1.160.6.40 raeburn 6280: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 6281: my $display = 'none';
6282: if ($currusecredits) {
6283: $display = 'block';
6284: }
6285: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 6286: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6287: foreach my $type (@types) {
6288: next if ($type eq 'community');
6289: $additional .= '<td align="center">'.&mt($type).'<br />'.
6290: '<input type="text" name="'.$type.'_credits"'.
6291: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6292: }
6293: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 6294: %defaultchecked = ('coursecredits' => 'off');
6295: @toggles = ('coursecredits');
6296: my $current = {
6297: 'coursecredits' => $currusecredits,
6298: };
6299: (my $table,$itemcount) =
6300: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6301: \%choices,$itemcount,$onclick,$additional,'left');
6302: $datatable .= $table;
6303: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6304: my $display = 'none';
6305: if ($postsubmitclient) {
6306: $display = 'block';
6307: }
6308: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 6309: &mt('Number of seconds submit is disabled').'<br />'.
6310: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6311: '<table><tr>';
1.160.6.57 raeburn 6312: foreach my $type (@types) {
6313: $additional .= '<td align="center">'.&mt($type).'<br />'.
6314: '<input type="text" name="'.$type.'_timeout" value="'.
6315: $deftimeout{$type}.'" size="5" /></td>';
6316: }
6317: $additional .= '</tr></table></div>'."\n";
6318: %defaultchecked = ('postsubmit' => 'on');
6319: @toggles = ('postsubmit');
1.160.6.70 raeburn 6320: $current = {
6321: 'postsubmit' => $postsubmitclient,
6322: };
1.160.6.57 raeburn 6323: ($table,$itemcount) =
6324: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6325: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 6326: $datatable .= $table;
1.160.6.70 raeburn 6327: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6328: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6329: $choices{'mysqltables'}.
6330: '</span></td>'.
6331: '<td align="right" class="LC_right_item">'.
6332: '<table><tr>';
6333: foreach my $type (@types) {
6334: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6335: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 6336: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 6337: }
6338: $datatable .= '</tr></table></td></tr>'."\n";
6339: $itemcount ++;
1.160.6.118.2 4(raebur 6340:2): %defaultchecked = ('ltiauth' => 'off');
6341:2): @toggles = ('ltiauth');
6342:2): $current = {
6343:2): 'ltiauth' => $ltiauth,
6344:2): };
6345:2): ($table,$itemcount) =
6346:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6347:2): \%choices,$itemcount,undef,undef,'left');
6348:2): $datatable .= $table;
14(raebu 6349:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6350:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6351:23): $choices{'domexttool'}.
6352:23): '</span></td>'.
6353:23): '<td style="text-align: right" class="LC_right_item">'.
6354:23): '<table><tr>';
6355:23): foreach my $type (@types) {
6356:23): $datatable .= '<td style="text-align: left">'.
6357:23): '<span class="LC_nobreak">'.
22(raebu 6358:24): '<label><input type="checkbox" name="domexttool"'.
14(raebu 6359:23): ' value="'.$type.'"'.$domexttool{$type}.' />'.
22(raebu 6360:24): &mt($type).'</label></span></td>'."\n";
14(raebu 6361:23): }
6362:23): $datatable .= '</tr></table></td></tr>'."\n";
4(raebur 6363:2): $itemcount ++;
14(raebu 6364:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6365:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6366:23): $choices{'exttool'}.
6367:23): '</span></td>'.
6368:23): '<td style="text-align: right" class="LC_right_item">'.
6369:23): '<table><tr>';
6370:23): foreach my $type (@types) {
6371:23): $datatable .= '<td style="text-align: left">'.
6372:23): '<span class="LC_nobreak">'.
22(raebu 6373:24): '<label><input type="checkbox" name="exttool"'.
14(raebu 6374:23): ' value="'.$type.'"'.$exttool{$type}.' />'.
22(raebu 6375:24): &mt($type).'</label></span></td>'."\n";
6376:24): }
6377:24): $datatable .= '</tr></table></td></tr>'."\n";
6378:24): $itemcount ++;
6379:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6380:24): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6381:24): $choices{'crseditors'}.
6382:24): '</span></td>'.
6383:24): '<td style="text-align: right" class="LC_right_item">'.
6384:24): '<table><tr>';
6385:24): my @editors = ('edit','xml','daxe');
6386:24): my %editornames = &crseditor_titles();
6387:24): foreach my $editor (@editors) {
6388:24): $datatable .= '<td style="text-align: left">'.
6389:24): '<span class="LC_nobreak">'.
6390:24): '<label><input type="checkbox" name="crseditors"'.
6391:24): ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
6392:24): $editornames{$editor}.'</label></span></td>'."\n";
14(raebu 6393:23): }
6394:23): $datatable .= '</tr></table></td></tr>'."\n";
6395:23): }
6396:23): $$rowtotal += $itemcount;
6397:23): return $datatable;
6398:23): }
6399:23):
22(raebu 6400:24): sub crseditor_titles {
6401:24): return &Apache::lonlocal::texthash(
6402:24): edit => 'Standard editor (Edit)',
6403:24): xml => 'Text editor (EditXML)',
6404:24): daxe => 'Daxe editor (Daxe)',
6405:24): );
6406:24): }
6407:24):
20(raebu 6408:24): sub print_authordefaults {
6409:24): my ($position,$dom,$settings,$rowtotal) = @_;
6410:24): my ($css_class,$datatable,%checkedon,%checkedoff);
6411:24): my $itemcount = 1;
6412:24): my %titles = &authordefaults_titles();
6413:24): if ($position eq 'top') {
6414:24): my %defaultchecked = (
6415:24): 'nocodemirror' => 'off',
21(raebu 6416:24): 'daxecollapse' => 'off',
20(raebu 6417:24): 'domcoordacc' => 'on',
6418:24): );
21(raebu 6419:24): my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
20(raebu 6420:24): ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
6421:24): \%titles,$itemcount);
6422:24): my %staticdefaults = (
6423:24): 'copyright' => 'default',
6424:24): 'sourceavail' => 'closed',
6425:24): );
6426:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6427:24): my %currrights;
6428:24): foreach my $item ('copyright','sourceavail') {
6429:24): $currrights{$item} = $staticdefaults{$item};
6430:24): if (ref($settings) eq 'HASH') {
6431:24): if (exists($settings->{$item})) {
6432:24): $currrights{$item} = $settings->{$item};
6433:24): }
6434:24): }
6435:24): }
6436:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6437:24): '<span class="LC_nobreak">'.$titles{'copyright'}.
6438:24): '</span></td><td class="LC_right_item">'.
6439:24): &selectbox('copyright',$currrights{'copyright'},'',
6440:24): \&Apache::loncommon::copyrightdescription,
6441:24): (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
6442:24): '</td></tr>'."\n";
6443:24): $itemcount ++;
6444:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6445:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6446:24): '<span class="LC_nobreak">'.$titles{'sourceavail'}.
6447:24): '</span></td><td class="LC_right_item">'.
6448:24): &selectbox('sourceavail',$currrights{'sourceavail'},'',
6449:24): \&Apache::loncommon::source_copyrightdescription,
6450:24): (&Apache::loncommon::source_copyrightids)).
6451:24): '</td></tr>'."\n";
6452:24): } else {
6453:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6454:24): my $curreditors;
6455:24): my %staticdefaults = (
6456:24): editors => ['edit','xml'],
6457:24): authorquota => 500,
6458:24): webdav => 0,
6459:24): );
6460:24): my $curreditors = $staticdefaults{'editors'};
6461:24): if ((ref($settings) eq 'HASH') &&
6462:24): (ref($settings->{'editors'}) eq 'ARRAY')) {
6463:24): $curreditors = $settings->{'editors'};
6464:24): } else {
6465:24): $curreditors = $staticdefaults{'editors'};
6466:24): }
6467:24): my @editors = ('edit','xml','daxe');
6468:24): $datatable = '<tr'.$css_class.'>'."\n".
6469:24): '<td>'.$titles{'editors'}.'</td>'."\n".
6470:24): '<td class="LC_left_item">'."\n".
6471:24): '<span class="LC_nobreak">';
6472:24): foreach my $editor (@editors) {
6473:24): my $checked;
6474:24): if (grep(/^\Q$editor\E$/,@{$curreditors})) {
6475:24): $checked = ' checked="checked"';
6476:24): }
6477:24): $datatable .= '<label>'.
6478:24): '<input type="checkbox" name="author_editors" '.
6479:24): $checked.' value="'.$editor.'" '.
6480:24): 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
6481:24): $titles{$editor}.'</label> ';
6482:24): }
6483:24): $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
6484:24): $itemcount ++;
6485:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6486:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6487:24): my @insttypes;
6488:24): if (ref($types) eq 'ARRAY') {
6489:24): @insttypes = @{$types};
6490:24): }
6491:24): my $typecount = 0;
6492:24): my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
6493:24): my @items = ('webdav','authorquota');
6494:24): my %quotas;
6495:24): if (ref($domconf{'quotas'}) eq 'HASH') {
6496:24): %quotas = %{$domconf{'quotas'}};
6497:24): foreach my $item (@items) {
6498:24): if (ref($quotas{$item}) eq 'HASH') {
6499:24): foreach my $type (@insttypes,'default') {
6500:24): if ($item eq 'authorquota') {
6501:24): if ($quotas{$item}{$type} !~ /^\d+$/) {
6502:24): $quotas{$item}{$type} = $staticdefaults{$item};
6503:24): }
6504:24): } elsif ($item eq 'webdav') {
6505:24): if ($quotas{$item}{$type} !~ /^(0|1)$/) {
6506:24): $quotas{$item}{$type} = $staticdefaults{$item};
6507:24): }
6508:24): }
6509:24): }
6510:24): } else {
6511:24): foreach my $type (@insttypes,'default') {
6512:24): $quotas{$item}{$type} = $staticdefaults{$item};
6513:24): }
6514:24): }
6515:24): }
6516:24): } else {
6517:24): foreach my $item (@items) {
6518:24): foreach my $type (@insttypes,'default') {
6519:24): $quotas{$item}{$type} = $staticdefaults{$item};
6520:24): }
6521:24): }
6522:24): }
6523:24): if (ref($usertypes) eq 'HASH') {
6524:24): my $numinrow = 4;
6525:24): my $onclick = '';
6526:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6527:24): $numinrow,$othertitle,'authorquota',
6528:24): \$itemcount,$onclick);
6529:24): $itemcount ++;
6530:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6531:24): $numinrow,$othertitle,'webdav',
6532:24): \$itemcount);
6533:24): $itemcount ++;
6534:24): }
6535:24): my $checkedno = ' checked="checked"';
6536:24): my ($checkedon,$checkedoff);
6537:24): if (ref($quotas{'webdav'}) eq 'HASH') {
6538:24): if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
6539:24): if ($quotas{'webdav'}{'_LC_adv'}) {
6540:24): $checkedon = $checkedno;
6541:24): } else {
6542:24): $checkedoff = $checkedno;
6543:24): }
6544:24): undef($checkedno);
6545:24): }
6546:24): }
6547:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6548:24): $datatable .= '<tr'.$css_class.'>'.
6549:24): '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
6550:24): $titles{'webdav_LC_adv_over'}.
6551:24): '</td>'.
6552:24): '<td class="LC_left_item">';
6553:24): foreach my $option ('none','off','on') {
6554:24): my ($text,$val,$checked);
6555:24): if ($option eq 'none') {
6556:24): $text = $titles{'none'};
6557:24): $val = '';
6558:24): $checked = $checkedno;
6559:24): } elsif ($option eq 'off') {
6560:24): $text = $titles{'overoff'};
6561:24): $val = 0;
6562:24): $checked = $checkedoff;
6563:24): } elsif ($option eq 'on') {
6564:24): $text = $titles{'overon'};
6565:24): $val = 1;
6566:24): $checked = $checkedon;
6567:24): }
6568:24): $datatable .= '<span class="LC_nobreak"><label>'.
6569:24): '<input type="radio" name="webdav_LC_adv"'.
6570:24): ' value="'.$val.'"'.$checked.' />'.
6571:24): $text.'</label></span> ';
6572:24): }
6573:24): $datatable .= '</td></tr>';
6574:24): $itemcount ++;
22(raebu 6575:24): my %defchecked = (
6576:24): 'archive' => 'off',
6577:24): );
6578:24): my @toggles = ('archive');
6579:24): (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
6580:24): {'archive' => 'off'},
6581:24): \%titles,$itemcount);
6582:24): $datatable .= $archive."\n";
6583:24): $itemcount ++;
20(raebu 6584:24): }
6585:24): $$rowtotal += $itemcount;
6586:24): return $datatable;
6587:24): }
6588:24):
6589:24): sub authordefaults_titles {
6590:24): return &Apache::lonlocal::texthash(
6591:24): copyright => 'Copyright/Distribution',
6592:24): sourceavail => ' Source Available',
6593:24): editors => 'Available Editors',
6594:24): webdav => 'WebDAV',
6595:24): authorquota => 'Authoring Space quotas (MB)',
6596:24): nocodemirror => 'Deactivate CodeMirror for EditXML editor',
21(raebu 6597:24): daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
20(raebu 6598:24): domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
6599:24): edit => 'Standard editor (Edit)',
6600:24): xml => 'Text editor (EditXML)',
6601:24): daxe => 'Daxe editor (Daxe)',
6602:24): webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
6603:24): webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
6604:24): none => 'No override set',
6605:24): overon => 'Override -- webDAV on',
6606:24): overoff => 'Override -- webDAV off',
22(raebu 6607:24): archive => 'Authors can download tar.gz file of Authoring Space',
20(raebu 6608:24): );
6609:24): }
6610:24):
6611:24): sub selectbox {
6612:24): my ($name,$value,$readonly,$functionref,@idlist)=@_;
6613:24): my $selout = '<select name="'.$name.'">';
6614:24): foreach my $id (@idlist) {
6615:24): $selout.='<option value="'.$id.'"';
6616:24): if ($id eq $value) {
6617:24): $selout.=' selected="selected"';
6618:24): }
6619:24): if ($readonly) {
6620:24): $selout .= ' disabled="disabled"';
6621:24): }
6622:24): $selout.='>'.&{$functionref}($id).'</option>';
6623:24): }
6624:24): $selout.='</select>';
6625:24): return $selout;
6626:24): }
6627:24):
14(raebu 6628:23): sub print_selfenrollment {
1.160.6.37 raeburn 6629: my ($position,$dom,$settings,$rowtotal) = @_;
6630: my ($css_class,$datatable);
6631: my $itemcount = 1;
6632: my @types = ('official','unofficial','community','textbook');
6633: if (($position eq 'top') || ($position eq 'middle')) {
6634: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6635: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6636: my @rows;
6637: my $key;
6638: if ($position eq 'top') {
6639: $key = 'admin';
6640: if (ref($rowsref) eq 'ARRAY') {
6641: @rows = @{$rowsref};
6642: }
6643: } elsif ($position eq 'middle') {
6644: $key = 'default';
6645: @rows = ('types','registered','approval','limit');
6646: }
6647: foreach my $row (@rows) {
6648: if (defined($titlesref->{$row})) {
6649: $itemcount ++;
6650: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6651: $datatable .= '<tr'.$css_class.'>'.
6652: '<td>'.$titlesref->{$row}.'</td>'.
6653: '<td class="LC_left_item">'.
6654: '<table><tr>';
6655: my (%current,%currentcap);
6656: if (ref($settings) eq 'HASH') {
6657: if (ref($settings->{$key}) eq 'HASH') {
6658: foreach my $type (@types) {
6659: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6660: $current{$type} = $settings->{$key}->{$type}->{$row};
6661: }
6662: if (($row eq 'limit') && ($key eq 'default')) {
6663: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6664: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6665: }
6666: }
6667: }
6668: }
6669: }
6670: my %roles = (
6671: '0' => &Apache::lonnet::plaintext('dc'),
6672: );
6673:
6674: foreach my $type (@types) {
6675: unless (($row eq 'registered') && ($key eq 'default')) {
6676: $datatable .= '<th>'.&mt($type).'</th>';
6677: }
6678: }
6679: unless (($row eq 'registered') && ($key eq 'default')) {
6680: $datatable .= '</tr><tr>';
6681: }
6682: foreach my $type (@types) {
6683: if ($type eq 'community') {
6684: $roles{'1'} = &mt('Community personnel');
6685: } else {
6686: $roles{'1'} = &mt('Course personnel');
6687: }
6688: $datatable .= '<td style="vertical-align: top">';
6689: if ($position eq 'top') {
6690: my %checked;
6691: if ($current{$type} eq '0') {
6692: $checked{'0'} = ' checked="checked"';
6693: } else {
6694: $checked{'1'} = ' checked="checked"';
6695: }
6696: foreach my $role ('1','0') {
6697: $datatable .= '<span class="LC_nobreak"><label>'.
6698: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6699: 'value="'.$role.'"'.$checked{$role}.' />'.
6700: $roles{$role}.'</label></span> ';
6701: }
6702: } else {
6703: if ($row eq 'types') {
6704: my %checked;
6705: if ($current{$type} =~ /^(all|dom)$/) {
6706: $checked{$1} = ' checked="checked"';
6707: } else {
6708: $checked{''} = ' checked="checked"';
6709: }
6710: foreach my $val ('','dom','all') {
6711: $datatable .= '<span class="LC_nobreak"><label>'.
6712: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6713: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6714: }
6715: } elsif ($row eq 'registered') {
6716: my %checked;
6717: if ($current{$type} eq '1') {
6718: $checked{'1'} = ' checked="checked"';
6719: } else {
6720: $checked{'0'} = ' checked="checked"';
6721: }
6722: foreach my $val ('0','1') {
6723: $datatable .= '<span class="LC_nobreak"><label>'.
6724: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6725: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6726: }
6727: } elsif ($row eq 'approval') {
6728: my %checked;
6729: if ($current{$type} =~ /^([12])$/) {
6730: $checked{$1} = ' checked="checked"';
6731: } else {
6732: $checked{'0'} = ' checked="checked"';
6733: }
6734: for my $val (0..2) {
6735: $datatable .= '<span class="LC_nobreak"><label>'.
6736: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6737: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6738: }
6739: } elsif ($row eq 'limit') {
6740: my %checked;
6741: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6742: $checked{$1} = ' checked="checked"';
6743: } else {
6744: $checked{'none'} = ' checked="checked"';
6745: }
6746: my $cap;
6747: if ($currentcap{$type} =~ /^\d+$/) {
6748: $cap = $currentcap{$type};
6749: }
6750: foreach my $val ('none','allstudents','selfenrolled') {
6751: $datatable .= '<span class="LC_nobreak"><label>'.
6752: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6753: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6754: }
6755: $datatable .= '<br />'.
6756: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6757: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6758: '</span>';
6759: }
6760: }
6761: $datatable .= '</td>';
6762: }
6763: $datatable .= '</tr>';
6764: }
6765: $datatable .= '</table></td></tr>';
6766: }
6767: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 6768: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6769: }
6770: $$rowtotal += $itemcount;
6771: return $datatable;
6772: }
6773:
6774: sub print_validation_rows {
6775: my ($caller,$dom,$settings,$rowtotal) = @_;
6776: my ($itemsref,$namesref,$fieldsref);
6777: if ($caller eq 'selfenroll') {
6778: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6779: } elsif ($caller eq 'requestcourses') {
6780: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6781: }
6782: my %currvalidation;
6783: if (ref($settings) eq 'HASH') {
6784: if (ref($settings->{'validation'}) eq 'HASH') {
6785: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 6786: }
1.160.6.39 raeburn 6787: }
6788: my $datatable;
6789: my $itemcount = 0;
6790: foreach my $item (@{$itemsref}) {
6791: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6792: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6793: $namesref->{$item}.
6794: '</span></td>'.
6795: '<td class="LC_left_item">';
6796: if (($item eq 'url') || ($item eq 'button')) {
6797: $datatable .= '<span class="LC_nobreak">'.
6798: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6799: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6800: } elsif ($item eq 'fields') {
6801: my @currfields;
6802: if (ref($currvalidation{$item}) eq 'ARRAY') {
6803: @currfields = @{$currvalidation{$item}};
6804: }
6805: foreach my $field (@{$fieldsref}) {
6806: my $check = '';
6807: if (grep(/^\Q$field\E$/,@currfields)) {
6808: $check = ' checked="checked"';
6809: }
6810: $datatable .= '<span class="LC_nobreak"><label>'.
6811: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6812: ' value="'.$field.'"'.$check.' />'.$field.
6813: '</label></span> ';
6814: }
6815: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 6816: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 6817: $currvalidation{$item}.
1.160.6.37 raeburn 6818: '</textarea>';
1.160.6.39 raeburn 6819: }
6820: $datatable .= '</td></tr>'."\n";
6821: if (ref($rowtotal)) {
1.160.6.37 raeburn 6822: $itemcount ++;
6823: }
1.139 raeburn 6824: }
1.160.6.39 raeburn 6825: if ($caller eq 'requestcourses') {
6826: my %currhash;
1.160.6.51 raeburn 6827: if (ref($settings) eq 'HASH') {
6828: if (ref($settings->{'validation'}) eq 'HASH') {
6829: if ($settings->{'validation'}{'dc'} ne '') {
6830: $currhash{$settings->{'validation'}{'dc'}} = 1;
6831: }
1.160.6.39 raeburn 6832: }
6833: }
6834: my $numinrow = 2;
6835: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6836: 'validationdc',%currhash);
1.160.6.50 raeburn 6837: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 6838: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 6839: if ($numdc > 1) {
1.160.6.50 raeburn 6840: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 6841: } else {
1.160.6.50 raeburn 6842: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 6843: }
1.160.6.50 raeburn 6844: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 6845: $itemcount ++;
6846: }
6847: if (ref($rowtotal)) {
6848: $$rowtotal += $itemcount;
6849: }
1.121 raeburn 6850: return $datatable;
1.118 jms 6851: }
6852:
1.160.6.98 raeburn 6853: sub print_passwords {
6854: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6855: my ($datatable,$css_class);
6856: my $itemcount = 0;
6857: my %titles = &Apache::lonlocal::texthash (
6858: captcha => '"Forgot Password" CAPTCHA validation',
6859: link => 'Reset link expiration (hours)',
6860: case => 'Case-sensitive usernames/e-mail',
6861: prelink => 'Information required (form 1)',
6862: postlink => 'Information required (form 2)',
6863: emailsrc => 'LON-CAPA e-mail address type(s)',
6864: customtext => 'Domain specific text (HTML)',
6865: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6866: intauth_check => 'Check bcrypt cost if authenticated',
6867: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6868: permanent => 'Permanent e-mail address',
6869: critical => 'Critical notification address',
6870: notify => 'Notification address',
6871: min => 'Minimum password length',
6872: max => 'Maximum password length',
6873: chars => 'Required characters',
6874: numsaved => 'Number of previous passwords to save and disallow reuse',
6875: );
6876: if ($position eq 'top') {
6877: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6878: my $shownlinklife = 2;
6879: my $prelink = 'both';
6880: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6881: if (ref($settings) eq 'HASH') {
6882: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6883: $shownlinklife = $settings->{resetlink};
6884: }
6885: if (ref($settings->{resetcase}) eq 'ARRAY') {
6886: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6887: }
6888: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6889: $prelink = $settings->{resetprelink};
6890: }
6891: if (ref($settings->{resetpostlink}) eq 'HASH') {
6892: %postlink = %{$settings->{resetpostlink}};
6893: }
6894: if (ref($settings->{resetemail}) eq 'ARRAY') {
6895: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6896: }
6897: if ($settings->{resetremove}) {
6898: $nostdtext = 1;
6899: }
6900: if ($settings->{resetcustom}) {
6901: $customurl = $settings->{resetcustom};
6902: }
6903: } else {
6904: if (ref($types) eq 'ARRAY') {
6905: foreach my $item (@{$types}) {
6906: $casesens{$item} = 1;
6907: $postlink{$item} = ['username','email'];
6908: }
6909: }
6910: $casesens{'default'} = 1;
6911: $postlink{'default'} = ['username','email'];
6912: $prelink = 'both';
6913: %emailsrc = (
6914: permanent => 1,
6915: critical => 1,
6916: notify => 1,
6917: );
6918: }
6919: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6920: $itemcount ++;
6921: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6922: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6923: '<td class="LC_left_item">'.
6924: '<input type="textbox" value="'.$shownlinklife.'" '.
6925: 'name="passwords_link" size="3" /></td></tr>';
6926: $itemcount ++;
6927: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6928: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6929: '<td class="LC_left_item">';
6930: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6931: foreach my $item (@{$types}) {
6932: my $checkedcase;
6933: if ($casesens{$item}) {
6934: $checkedcase = ' checked="checked"';
6935: }
6936: $datatable .= '<span class="LC_nobreak"><label>'.
6937: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6938: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 6939: '</span> ';
1.160.6.98 raeburn 6940: }
6941: }
6942: my $checkedcase;
6943: if ($casesens{'default'}) {
6944: $checkedcase = ' checked="checked"';
6945: }
6946: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6947: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6948: $othertitle.'</label></span></td>';
6949: $itemcount ++;
6950: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6951: my %checkedpre = (
6952: both => ' checked="checked"',
6953: either => '',
6954: );
6955: if ($prelink eq 'either') {
6956: $checkedpre{either} = ' checked="checked"';
6957: $checkedpre{both} = '';
6958: }
6959: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
6960: '<td class="LC_left_item"><span class="LC_nobreak">'.
6961: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
6962: &mt('Both username and e-mail address').'</label></span> '.
6963: '<span class="LC_nobreak"><label>'.
6964: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
6965: &mt('Either username or e-mail address').'</label></span></td></tr>';
6966: $itemcount ++;
6967: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6968: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
6969: '<td class="LC_left_item">';
6970: my %postlinked;
6971: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6972: foreach my $item (@{$types}) {
6973: undef(%postlinked);
6974: $datatable .= '<fieldset style="display: inline-block;">'.
6975: '<legend>'.$usertypes->{$item}.'</legend>';
6976: if (ref($postlink{$item}) eq 'ARRAY') {
6977: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
6978: }
6979: foreach my $field ('email','username') {
6980: my $checked;
6981: if ($postlinked{$field}) {
6982: $checked = ' checked="checked"';
6983: }
6984: $datatable .= '<span class="LC_nobreak"><label>'.
6985: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
6986: $field.'"'.$checked.' />'.$field.'</label>'.
6987: '<span> ';
6988: }
6989: $datatable .= '</fieldset>';
6990: }
6991: }
6992: if (ref($postlink{'default'}) eq 'ARRAY') {
6993: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
6994: }
6995: $datatable .= '<fieldset style="display: inline-block;">'.
6996: '<legend>'.$othertitle.'</legend>';
6997: foreach my $field ('email','username') {
6998: my $checked;
6999: if ($postlinked{$field}) {
7000: $checked = ' checked="checked"';
7001: }
7002: $datatable .= '<span class="LC_nobreak"><label>'.
7003: '<input type="checkbox" name="passwords_postlink_default" value="'.
7004: $field.'"'.$checked.' />'.$field.'</label>'.
7005: '<span> ';
7006: }
7007: $datatable .= '</fieldset></td></tr>';
7008: $itemcount ++;
7009: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7010: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7011: '<td class="LC_left_item">';
7012: foreach my $type ('permanent','critical','notify') {
7013: my $checkedemail;
7014: if ($emailsrc{$type}) {
7015: $checkedemail = ' checked="checked"';
7016: }
7017: $datatable .= '<span class="LC_nobreak"><label>'.
7018: '<input type="checkbox" name="passwords_emailsrc" value="'.
7019: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7020: '<span> ';
7021: }
7022: $datatable .= '</td></tr>';
7023: $itemcount ++;
7024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7025: my $switchserver = &check_switchserver($dom,$confname);
7026: my ($showstd,$noshowstd);
7027: if ($nostdtext) {
7028: $noshowstd = ' checked="checked"';
7029: } else {
7030: $showstd = ' checked="checked"';
7031: }
7032: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7033: '<td class="LC_left_item"><span class="LC_nobreak">'.
7034: &mt('Retain standard text:').
7035: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7036: &mt('Yes').'</label>'.' '.
7037: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7038: &mt('No').'</label></span><br />'.
7039: '<span class="LC_fontsize_small">'.
7040: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7041: &mt('Include custom text:');
7042: if ($customurl) {
1.160.6.104 raeburn 7043: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 7044: undef,undef,undef,undef,'background-color:#ffffff');
7045: $datatable .= '<span class="LC_nobreak"> '.$link.
7046: '<label><input type="checkbox" name="passwords_custom_del"'.
7047: ' value="1" />'.&mt('Delete?').'</label></span>'.
7048: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7049: }
7050: if ($switchserver) {
7051: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7052: } else {
7053: $datatable .='<span class="LC_nobreak"> '.
7054: '<input type="file" name="passwords_customfile" /></span>';
7055: }
7056: $datatable .= '</td></tr>';
7057: } elsif ($position eq 'middle') {
7058: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7059: my @items = ('intauth_cost','intauth_check','intauth_switch');
7060: my %defaults;
7061: if (ref($domconf{'defaults'}) eq 'HASH') {
7062: %defaults = %{$domconf{'defaults'}};
7063: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7064: $defaults{'intauth_cost'} = 10;
7065: }
7066: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7067: $defaults{'intauth_check'} = 0;
7068: }
7069: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7070: $defaults{'intauth_switch'} = 0;
7071: }
7072: } else {
7073: %defaults = (
7074: 'intauth_cost' => 10,
7075: 'intauth_check' => 0,
7076: 'intauth_switch' => 0,
7077: );
7078: }
7079: foreach my $item (@items) {
7080: if ($itemcount%2) {
7081: $css_class = '';
7082: } else {
7083: $css_class = ' class="LC_odd_row" ';
7084: }
7085: $datatable .= '<tr'.$css_class.'>'.
7086: '<td><span class="LC_nobreak">'.$titles{$item}.
7087: '</span></td><td class="LC_left_item" colspan="3">';
7088: if ($item eq 'intauth_switch') {
7089: my @options = (0,1,2);
7090: my %optiondesc = &Apache::lonlocal::texthash (
7091: 0 => 'No',
7092: 1 => 'Yes',
7093: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7094: );
7095: $datatable .= '<table width="100%">';
7096: foreach my $option (@options) {
7097: my $checked = ' ';
7098: if ($defaults{$item} eq $option) {
7099: $checked = ' checked="checked"';
7100: }
7101: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7102: '<label><input type="radio" name="'.$item.
7103: '" value="'.$option.'"'.$checked.' />'.
7104: $optiondesc{$option}.'</label></span></td></tr>';
7105: }
7106: $datatable .= '</table>';
7107: } elsif ($item eq 'intauth_check') {
7108: my @options = (0,1,2);
7109: my %optiondesc = &Apache::lonlocal::texthash (
7110: 0 => 'No',
7111: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7112: 2 => 'Yes, disallow login if stored cost is less than domain default',
7113: );
7114: $datatable .= '<table width="100%">';
7115: foreach my $option (@options) {
7116: my $checked = ' ';
7117: my $onclick;
7118: if ($defaults{$item} eq $option) {
7119: $checked = ' checked="checked"';
7120: }
7121: if ($option == 2) {
7122: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7123: }
7124: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7125: '<label><input type="radio" name="'.$item.
7126: '" value="'.$option.'"'.$checked.$onclick.' />'.
7127: $optiondesc{$option}.'</label></span></td></tr>';
7128: }
7129: $datatable .= '</table>';
7130: } else {
7131: $datatable .= '<input type="text" name="'.$item.'" value="'.
7132: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7133: }
7134: $datatable .= '</td></tr>';
7135: $itemcount ++;
7136: }
7137: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 7138:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 7139: } else {
7140: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7141: my %ownerchg = (
7142: by => {},
7143: for => {},
7144: );
7145: my %ownertitles = &Apache::lonlocal::texthash (
7146: by => 'Course owner status(es) allowed',
7147: for => 'Student status(es) allowed',
7148: );
7149: if (ref($settings) eq 'HASH') {
7150: if (ref($settings->{crsownerchg}) eq 'HASH') {
7151: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7152: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7153: }
7154: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7155: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7156: }
7157: }
7158: }
7159: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7160: $datatable .= '<tr '.$css_class.'>'.
7161: '<td>'.
7162: &mt('Requirements').'<ul>'.
7163: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
7164: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7165: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
7166: '<li>'.&mt('User, course, and student share same domain').'</li>'.
7167: '</ul>'.
7168: '</td>'.
7169: '<td class="LC_left_item">';
7170: foreach my $item ('by','for') {
7171: $datatable .= '<fieldset style="display: inline-block;">'.
7172: '<legend>'.$ownertitles{$item}.'</legend>';
7173: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7174: foreach my $type (@{$types}) {
7175: my $checked;
7176: if ($ownerchg{$item}{$type}) {
7177: $checked = ' checked="checked"';
7178: }
7179: $datatable .= '<span class="LC_nobreak"><label>'.
7180: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7181: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 7182: '</span> ';
1.160.6.98 raeburn 7183: }
7184: }
7185: my $checked;
7186: if ($ownerchg{$item}{'default'}) {
7187: $checked = ' checked="checked"';
7188: }
7189: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7190: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7191: $othertitle.'</label></span></fieldset>';
7192: }
7193: $datatable .= '</td></tr>';
7194: }
7195: return $datatable;
7196: }
7197:
1.160.6.118.2 5(raebur 7198:2): sub password_rules {
7199:2): my ($prefix,$itemcountref,$settings) = @_;
7200:2): my ($min,$max,%chars,$numsaved,$numinrow);
7201:2): my %titles;
7202:2): if ($prefix eq 'passwords') {
7203:2): %titles = &Apache::lonlocal::texthash (
7204:2): min => 'Minimum password length',
7205:2): max => 'Maximum password length',
7206:2): chars => 'Required characters',
7207:2): );
14(raebu 7208:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 7209:2): %titles = &Apache::lonlocal::texthash (
7210:2): min => 'Minimum secret length',
7211:2): max => 'Maximum secret length',
7212:2): chars => 'Required characters',
7213:2): );
7214:2): }
7215:2): $min = $Apache::lonnet::passwdmin;
7216:2): my $datatable;
7217:2): my $itemcount;
7218:2): if (ref($itemcountref)) {
7219:2): $itemcount = $$itemcountref;
7220:2): }
7221:2): if (ref($settings) eq 'HASH') {
7222:2): if ($settings->{min}) {
7223:2): $min = $settings->{min};
7224:2): }
7225:2): if ($settings->{max}) {
7226:2): $max = $settings->{max};
7227:2): }
7228:2): if (ref($settings->{chars}) eq 'ARRAY') {
7229:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
7230:2): }
7231:2): if ($prefix eq 'passwords') {
7232:2): if ($settings->{numsaved}) {
7233:2): $numsaved = $settings->{numsaved};
7234:2): }
7235:2): }
7236:2): }
7237:2): my %rulenames = &Apache::lonlocal::texthash(
7238:2): uc => 'At least one upper case letter',
7239:2): lc => 'At least one lower case letter',
7240:2): num => 'At least one number',
7241:2): spec => 'At least one non-alphanumeric',
7242:2): );
7243:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7244:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7245:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7246:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7247:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7248:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7249:2): '</span></td></tr>';
7250:2): $itemcount ++;
7251:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7252:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7253:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7254:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7255:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7256:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7257:2): '</span></td></tr>';
7258:2): $itemcount ++;
7259:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7260:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7261:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7262:2): '</span></td>';
7263:2): my $numinrow = 2;
7264:2): my @possrules = ('uc','lc','num','spec');
7265:2): $datatable .= '<td class="LC_left_item"><table>';
7266:2): for (my $i=0; $i<@possrules; $i++) {
7267:2): my ($rem,$checked);
7268:2): if ($chars{$possrules[$i]}) {
7269:2): $checked = ' checked="checked"';
7270:2): }
7271:2): $rem = $i%($numinrow);
7272:2): if ($rem == 0) {
7273:2): if ($i > 0) {
7274:2): $datatable .= '</tr>';
7275:2): }
7276:2): $datatable .= '<tr>';
7277:2): }
7278:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
7279:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7280:2): $rulenames{$possrules[$i]}.'</label></span></td>';
7281:2): }
7282:2): my $rem = @possrules%($numinrow);
7283:2): my $colsleft = $numinrow - $rem;
7284:2): if ($colsleft > 1 ) {
7285:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7286:2): ' </td>';
7287:2): } elsif ($colsleft == 1) {
7288:2): $datatable .= '<td class="LC_left_item"> </td>';
7289:2): }
7290:2): $datatable .='</table></td></tr>';
7291:2): $itemcount ++;
7292:2): if ($prefix eq 'passwords') {
7293:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7294:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7295:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7296:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7297:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7298:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7299:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7300:2): '</span></td></tr>';
7301:2): $itemcount ++;
7302:2): }
7303:2): if (ref($itemcountref)) {
7304:2): $$itemcountref += $itemcount;
7305:2): }
7306:2): return $datatable;
7307:2): }
7308:2):
1.160.6.113 raeburn 7309: sub print_wafproxy {
7310: my ($position,$dom,$settings,$rowtotal) = @_;
7311: my $css_class;
7312: my $itemcount = 0;
7313: my $datatable;
7314: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7315: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
7316: my %lt = &wafproxy_titles();
7317: foreach my $server (sort(keys(%servers))) {
7318: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7319: next if ($serverhome eq '');
7320: my $serverdom;
7321: if ($serverhome ne $server) {
7322: $serverdom = &Apache::lonnet::host_domain($serverhome);
7323: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7324: $othercontrol{$server} = $serverdom;
7325: }
7326: } else {
7327: $serverdom = &Apache::lonnet::host_domain($server);
7328: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7329: if ($serverdom ne $dom) {
7330: $othercontrol{$server} = $serverdom;
7331: } else {
7332: $setdom = 1;
7333: if (ref($settings) eq 'HASH') {
7334: if (ref($settings->{'alias'}) eq 'HASH') {
7335: $aliases{$dom} = $settings->{'alias'};
7336: if ($aliases{$dom} ne '') {
7337: $showdom = 1;
7338: }
7339: }
7340: if (ref($settings->{'saml'}) eq 'HASH') {
7341: $saml{$dom} = $settings->{'saml'};
7342: }
7343: }
7344: }
7345: }
7346: }
7347: if ($setdom) {
7348: %{$values{$dom}} = ();
7349: if (ref($settings) eq 'HASH') {
7350: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7351: $values{$dom}{$item} = $settings->{$item};
7352: }
7353: }
7354: }
7355: if (keys(%othercontrol)) {
7356: %otherdoms = reverse(%othercontrol);
7357: foreach my $domain (keys(%otherdoms)) {
7358: %{$values{$domain}} = ();
7359: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7360: if (ref($config{'wafproxy'}) eq 'HASH') {
7361: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7362: if (exists($config{'wafproxy'}{'saml'})) {
7363: $saml{$domain} = $config{'wafproxy'}{'saml'};
7364: }
7365: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7366: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7367: }
7368: }
7369: }
7370: }
7371: if ($position eq 'top') {
7372: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7373: my %aliasinfo;
7374: foreach my $server (sort(keys(%servers))) {
7375: $itemcount ++;
7376: my $dom_in_effect;
7377: my $aliasrows = '<tr>'.
7378: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.118.2 17(raebu 7379:24): &mt('Hostname').': '.
16(raebu 7380:24): '<span class="LC_nobreak LC_cusr_emph">'.
7381:24): &Apache::lonnet::hostname($server).'</span></td><td> </td>';
1.160.6.113 raeburn 7382: if ($othercontrol{$server}) {
7383: $dom_in_effect = $othercontrol{$server};
7384: my ($current,$forsaml);
7385: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7386: $current = $aliases{$dom_in_effect}{$server};
7387: }
7388: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7389: if ($saml{$dom_in_effect}{$server}) {
7390: $forsaml = 1;
7391: }
7392: }
7393: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7394: &mt('Alias').': ';
7395: if ($current) {
7396: $aliasrows .= $current;
7397: if ($forsaml) {
7398: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7399: }
7400: } else {
7401: $aliasrows .= &mt('None');
7402: }
7403: $aliasrows .= ' <span class="LC_small">('.
7404: &mt('controlled by domain: [_1]',
7405: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7406: } else {
7407: $dom_in_effect = $dom;
7408: my ($current,$samlon,$samloff);
7409: $samloff = ' checked="checked"';
7410: if (ref($aliases{$dom}) eq 'HASH') {
7411: if ($aliases{$dom}{$server}) {
7412: $current = $aliases{$dom}{$server};
7413: }
7414: }
7415: if (ref($saml{$dom}) eq 'HASH') {
7416: if ($saml{$dom}{$server}) {
7417: $samlon = $samloff;
7418: undef($samloff);
7419: }
7420: }
7421: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7422: &mt('Alias').': '.
7423: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7424: 'value="'.$current.'" size="30" />'.
7425: (' 'x2).'<span class="LC_nobreak">'.
7426: &mt('Alias used for SSO Auth').': <label>'.
7427: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7428: &mt('No').'</label> <label>'.
7429: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7430: &mt('Yes').'</label></span>'.
7431: '</td>';
7432: }
7433: $aliasrows .= '</tr>';
7434: $aliasinfo{$dom_in_effect} .= $aliasrows;
7435: }
7436: if ($aliasinfo{$dom}) {
7437: my ($onclick,$wafon,$wafoff,$showtable);
7438: $onclick = ' onclick="javascript:toggleWAF();"';
7439: $wafoff = ' checked="checked"';
7440: $showtable = ' style="display:none";';
7441: if ($showdom) {
7442: $wafon = $wafoff;
7443: $wafoff = '';
7444: $showtable = ' style="display:inline;"';
7445: }
7446: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7447: $datatable = '<tr'.$css_class.'>'.
7448: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7449: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7450: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7451: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7452: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7453: &mt('No').'</label></span></td>'.
7454: '<td class="LC_left_item">'.
7455: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7456: '</table></td></tr>';
7457: $itemcount++;
7458: }
7459: if (keys(%otherdoms)) {
7460: foreach my $key (sort(keys(%otherdoms))) {
7461: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7462: $datatable .= '<tr'.$css_class.'>'.
7463: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7464: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7465: '</table></td></tr>';
7466: $itemcount++;
7467: }
7468: }
7469: } else {
7470: my %ip_methods = &remoteip_methods();
7471: if ($setdom) {
7472: $itemcount ++;
7473: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7474: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7475: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7476: $wafstyle = ' style="display:none;"';
7477: $nowafstyle = ' style="display:table-row;"';
7478: $currwafdisplay = ' style="display: none"';
7479: $wafrangestyle = ' style="display: none"';
7480: $curr_remotip = 'n';
7481: $ssltossl = ' checked="checked"';
7482: if ($showdom) {
7483: $wafstyle = ' style="display:table-row;"';
7484: $nowafstyle = ' style="display:none;"';
7485: if (keys(%{$values{$dom}})) {
7486: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7487: $curr_remotip = $values{$dom}{remoteip};
7488: }
7489: if ($curr_remotip eq 'h') {
7490: $currwafdisplay = ' style="display:table-row"';
7491: $wafrangestyle = ' style="display:inline-block;"';
7492: }
7493: if ($values{$dom}{'sslopt'}) {
7494: $alltossl = ' checked="checked"';
7495: $ssltossl = '';
7496: }
7497: }
7498: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7499: $vpndircheck = ' checked="checked"';
7500: $currwafvpn = ' style="display:table-row;"';
7501: $wafrangestyle = ' style="display:inline-block;"';
7502: } else {
7503: $vpnaliascheck = ' checked="checked"';
7504: $currwafvpn = ' style="display:none;"';
7505: }
7506: }
7507: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7508: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7509: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7510: '</tr>'.
7511: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7512: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7513: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7514: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7515: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7516: '<td class="LC_left_item"><table>'.
7517: '<tr>'.
7518: '<td valign="top">'.$lt{'remoteip'}.': '.
7519: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7520: foreach my $option ('m','h','n') {
7521: my $sel;
1.160.6.114 raeburn 7522: if ($option eq $curr_remotip) {
7523: $sel = ' selected="selected"';
7524: }
7525: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7526: $ip_methods{$option}.'</option>';
7527: }
7528: $datatable .= '</select></td></tr>'."\n".
7529: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7530: $lt{'ipheader'}.': '.
7531: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7532: 'name="wafproxy_ipheader" />'.
7533: '</td></tr>'."\n".
7534: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7535: $lt{'trusted'}.':<br />'.
7536: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7537: $values{$dom}{'trusted'}.'</textarea>'.
7538: '</td></tr>'."\n".
7539: '<tr><td><hr /></td></tr>'."\n".
7540: '<tr>'.
1.160.6.113 raeburn 7541: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7542: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7543: $lt{'vpndirect'}.'</label>'.(' 'x2).
7544: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7545: $lt{'vpnaliased'}.'</label></span></td></tr>';
7546: foreach my $item ('vpnint','vpnext') {
7547: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7548: '<td valign="top">'.$lt{$item}.':<br />'.
7549: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7550: $values{$dom}{$item}.'</textarea>'.
7551: '</td></tr>'."\n";
7552: }
7553: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7554: '<tr>'.
7555: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7556: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7557: $lt{'alltossl'}.'</label>'.(' 'x2).
7558: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7559: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7560: '</table></td></tr>';
7561: }
7562: if (keys(%otherdoms)) {
7563: foreach my $domain (sort(keys(%otherdoms))) {
7564: $itemcount ++;
7565: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7566: $datatable .= '<tr'.$css_class.'>'.
7567: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7568: '<td class="LC_left_item"><table>';
7569: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7570: my $showval = &mt('None');
7571: if ($item eq 'ssl') {
7572: $showval = $lt{'ssltossl'};
7573: }
7574: if ($values{$domain}{$item}) {
7575: $showval = $values{$domain}{$item};
7576: if ($item eq 'ssl') {
7577: $showval = $lt{'alltossl'};
7578: } elsif ($item eq 'remoteip') {
7579: $showval = $ip_methods{$values{$domain}{$item}};
7580: }
7581: }
7582: $datatable .= '<tr>'.
7583: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7584: }
7585: $datatable .= '</table></td></tr>';
7586: }
7587: }
7588: }
7589: $$rowtotal += $itemcount;
7590: return $datatable;
7591: }
7592:
7593: sub wafproxy_titles {
7594: return &Apache::lonlocal::texthash(
7595: remoteip => "Method for determining user's IP",
7596: ipheader => 'Request header containing remote IP',
7597: trusted => 'Trusted IP range(s)',
7598: vpnaccess => 'Access from institutional VPN',
7599: vpndirect => 'via regular hostname (no WAF)',
7600: vpnaliased => 'via aliased hostname (WAF)',
7601: vpnint => 'Internal IP Range(s) for VPN sessions',
7602: vpnext => 'IP Range(s) for backend WAF connections',
7603: sslopt => 'Forwarding http/https',
7604: alltossl => 'WAF forwards both http and https requests to https',
7605: ssltossl => 'WAF forwards http requests to http and https to https',
7606: );
7607: }
7608:
7609: sub remoteip_methods {
7610: return &Apache::lonlocal::texthash(
7611: m => 'Use Apache mod_remoteip',
7612: h => 'Use headers parsed by LON-CAPA',
7613: n => 'Not in use',
7614: );
7615: }
7616:
1.137 raeburn 7617: sub print_usersessions {
7618: my ($position,$dom,$settings,$rowtotal) = @_;
7619: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 7620: my (%by_ip,%by_location,@intdoms);
7621: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 7622:
7623: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7624: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7625: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7626: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7627: my $itemcount = 1;
7628: if ($position eq 'top') {
1.152 raeburn 7629: if (keys(%serverhomes) > 1) {
1.145 raeburn 7630: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 7631: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 7632: if (ref($settings) eq 'HASH') {
7633: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7634: $curroffloadnow = $settings->{'offloadnow'};
7635: }
1.160.6.105 raeburn 7636: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7637: $curroffloadoth = $settings->{'offloadoth'};
7638: }
1.160.6.61 raeburn 7639: }
1.160.6.105 raeburn 7640: my $other_insts = scalar(keys(%by_location));
7641: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7642: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7643: } else {
1.140 raeburn 7644: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7645:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7646:23): '</td></tr>';
1.140 raeburn 7647: }
1.137 raeburn 7648: } else {
1.145 raeburn 7649: if (keys(%by_location) == 0) {
7650: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7651:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7652:23): '</td></tr>';
1.145 raeburn 7653: } else {
7654: my %lt = &usersession_titles();
7655: my $numinrow = 5;
7656: my $prefix;
7657: my @types;
7658: if ($position eq 'bottom') {
7659: $prefix = 'remote';
7660: @types = ('version','excludedomain','includedomain');
7661: } else {
7662: $prefix = 'hosted';
7663: @types = ('excludedomain','includedomain');
7664: }
7665: my (%current,%checkedon,%checkedoff);
7666: my @lcversions = &Apache::lonnet::all_loncaparevs();
7667: my @locations = sort(keys(%by_location));
7668: foreach my $type (@types) {
7669: $checkedon{$type} = '';
7670: $checkedoff{$type} = ' checked="checked"';
7671: }
7672: if (ref($settings) eq 'HASH') {
7673: if (ref($settings->{$prefix}) eq 'HASH') {
7674: foreach my $key (keys(%{$settings->{$prefix}})) {
7675: $current{$key} = $settings->{$prefix}{$key};
7676: if ($key eq 'version') {
7677: if ($current{$key} ne '') {
7678: $checkedon{$key} = ' checked="checked"';
7679: $checkedoff{$key} = '';
7680: }
7681: } elsif (ref($current{$key}) eq 'ARRAY') {
7682: $checkedon{$key} = ' checked="checked"';
7683: $checkedoff{$key} = '';
7684: }
1.137 raeburn 7685: }
7686: }
7687: }
1.145 raeburn 7688: foreach my $type (@types) {
7689: next if ($type ne 'version' && !@locations);
7690: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7691: $datatable .= '<tr'.$css_class.'>
7692: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7693: <span class="LC_nobreak">
7694: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7695: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7696: if ($type eq 'version') {
7697: my $selector = '<select name="'.$prefix.'_version">';
7698: foreach my $version (@lcversions) {
7699: my $selected = '';
7700: if ($current{'version'} eq $version) {
7701: $selected = ' selected="selected"';
7702: }
7703: $selector .= ' <option value="'.$version.'"'.
7704: $selected.'>'.$version.'</option>';
7705: }
7706: $selector .= '</select> ';
7707: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7708: } else {
7709: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7710: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7711: ' />'.(' 'x2).
7712: '<input type="button" value="'.&mt('uncheck all').'" '.
7713: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7714: "\n".
7715: '</div><div><table>';
7716: my $rem;
7717: for (my $i=0; $i<@locations; $i++) {
7718: my ($showloc,$value,$checkedtype);
7719: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7720: my $ip = $by_location{$locations[$i]}->[0];
7721: if (ref($by_ip{$ip}) eq 'ARRAY') {
7722: $value = join(':',@{$by_ip{$ip}});
7723: $showloc = join(', ',@{$by_ip{$ip}});
7724: if (ref($current{$type}) eq 'ARRAY') {
7725: foreach my $loc (@{$by_ip{$ip}}) {
7726: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7727: $checkedtype = ' checked="checked"';
7728: last;
7729: }
7730: }
1.138 raeburn 7731: }
7732: }
7733: }
1.145 raeburn 7734: $rem = $i%($numinrow);
7735: if ($rem == 0) {
7736: if ($i > 0) {
7737: $datatable .= '</tr>';
7738: }
7739: $datatable .= '<tr>';
7740: }
7741: $datatable .= '<td class="LC_left_item">'.
7742: '<span class="LC_nobreak"><label>'.
7743: '<input type="checkbox" name="'.$prefix.'_'.$type.
7744: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7745: '</label></span></td>';
1.137 raeburn 7746: }
1.145 raeburn 7747: $rem = @locations%($numinrow);
7748: my $colsleft = $numinrow - $rem;
7749: if ($colsleft > 1 ) {
7750: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7751: ' </td>';
7752: } elsif ($colsleft == 1) {
7753: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7754: }
1.145 raeburn 7755: $datatable .= '</tr></table>';
1.137 raeburn 7756: }
1.145 raeburn 7757: $datatable .= '</td></tr>';
7758: $itemcount ++;
1.137 raeburn 7759: }
7760: }
7761: }
7762: $$rowtotal += $itemcount;
7763: return $datatable;
7764: }
7765:
1.138 raeburn 7766: sub build_location_hashes {
7767: my ($intdoms,$by_ip,$by_location) = @_;
7768: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7769: (ref($by_location) eq 'HASH'));
7770: my %iphost = &Apache::lonnet::get_iphost();
7771: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7772: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7773: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7774: foreach my $id (@{$iphost{$primary_ip}}) {
7775: my $intdom = &Apache::lonnet::internet_dom($id);
7776: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7777: push(@{$intdoms},$intdom);
7778: }
7779: }
7780: }
7781: foreach my $ip (keys(%iphost)) {
7782: if (ref($iphost{$ip}) eq 'ARRAY') {
7783: foreach my $id (@{$iphost{$ip}}) {
7784: my $location = &Apache::lonnet::internet_dom($id);
7785: if ($location) {
7786: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7787: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7788: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7789: push(@{$by_ip->{$ip}},$location);
7790: }
7791: } else {
7792: $by_ip->{$ip} = [$location];
7793: }
7794: }
7795: }
7796: }
7797: }
7798: foreach my $ip (sort(keys(%{$by_ip}))) {
7799: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7800: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7801: my $first = $by_ip->{$ip}->[0];
7802: if (ref($by_location->{$first}) eq 'ARRAY') {
7803: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7804: push(@{$by_location->{$first}},$ip);
7805: }
7806: } else {
7807: $by_location->{$first} = [$ip];
7808: }
7809: }
7810: }
7811: return;
7812: }
7813:
1.145 raeburn 7814: sub current_offloads_to {
7815: my ($dom,$settings,$servers) = @_;
7816: my (%spareid,%otherdomconfigs);
1.152 raeburn 7817: if (ref($servers) eq 'HASH') {
1.145 raeburn 7818: foreach my $lonhost (sort(keys(%{$servers}))) {
7819: my $gotspares;
1.152 raeburn 7820: if (ref($settings) eq 'HASH') {
7821: if (ref($settings->{'spares'}) eq 'HASH') {
7822: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7823: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7824: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7825: $gotspares = 1;
7826: }
1.145 raeburn 7827: }
7828: }
7829: unless ($gotspares) {
7830: my $gotspares;
7831: my $serverhomeID =
7832: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7833: my $serverhomedom =
7834: &Apache::lonnet::host_domain($serverhomeID);
7835: if ($serverhomedom ne $dom) {
7836: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7837: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7838: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7839: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7840: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7841: $gotspares = 1;
7842: }
7843: }
7844: } else {
7845: $otherdomconfigs{$serverhomedom} =
7846: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7847: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7848: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7849: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7850: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7851: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7852: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7853: $gotspares = 1;
7854: }
7855: }
7856: }
7857: }
7858: }
7859: }
7860: }
7861: unless ($gotspares) {
7862: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7863: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7864: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7865: } else {
7866: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7867: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7868: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7869: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7870: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7871: } else {
1.150 raeburn 7872: my %what = (
7873: spareid => 1,
7874: );
7875: my ($result,$returnhash) =
7876: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7877: if ($result eq 'ok') {
7878: if (ref($returnhash) eq 'HASH') {
7879: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7880: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7881: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7882: }
7883: }
1.145 raeburn 7884: }
7885: }
7886: }
7887: }
7888: }
7889: }
7890: return %spareid;
7891: }
7892:
7893: sub spares_row {
1.160.6.105 raeburn 7894: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7895: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7896: my $css_class;
7897: my $numinrow = 4;
7898: my $itemcount = 1;
7899: my $datatable;
1.152 raeburn 7900: my %typetitles = &sparestype_titles();
7901: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7902: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7903: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7904: my ($othercontrol,$serverdom);
7905: if ($serverhome ne $server) {
7906: $serverdom = &Apache::lonnet::host_domain($serverhome);
7907: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7908: } else {
7909: $serverdom = &Apache::lonnet::host_domain($server);
7910: if ($serverdom ne $dom) {
7911: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7912: }
7913: }
7914: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 7915: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 7916: if (ref($curroffloadnow) eq 'HASH') {
7917: if ($curroffloadnow->{$server}) {
7918: $checkednow = ' checked="checked"';
7919: }
7920: }
1.160.6.105 raeburn 7921: if (ref($curroffloadoth) eq 'HASH') {
7922: if ($curroffloadoth->{$server}) {
7923: $checkedoth = ' checked="checked"';
7924: }
7925: }
1.145 raeburn 7926: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7927: $datatable .= '<tr'.$css_class.'>
7928: <td rowspan="2">
1.160.6.13 raeburn 7929: <span class="LC_nobreak">'.
7930: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 7931: ,'<b>'.$server.'</b>').'</span><br />'.
7932: '<span class="LC_nobreak">'."\n".
7933: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 7934: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 7935: "\n";
1.160.6.105 raeburn 7936: if ($other_insts) {
7937: $datatable .= '<br />'.
7938: '<span class="LC_nobreak">'."\n".
7939: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7940: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7941: "\n";
7942: }
1.145 raeburn 7943: my (%current,%canselect);
1.152 raeburn 7944: my @choices =
7945: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7946: foreach my $type ('primary','default') {
7947: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7948: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7949: my @spares = @{$spareid->{$server}{$type}};
7950: if (@spares > 0) {
1.152 raeburn 7951: if ($othercontrol) {
7952: $current{$type} = join(', ',@spares);
7953: } else {
7954: $current{$type} .= '<table>';
7955: my $numspares = scalar(@spares);
7956: for (my $i=0; $i<@spares; $i++) {
7957: my $rem = $i%($numinrow);
7958: if ($rem == 0) {
7959: if ($i > 0) {
7960: $current{$type} .= '</tr>';
7961: }
7962: $current{$type} .= '<tr>';
1.145 raeburn 7963: }
1.152 raeburn 7964: $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'".');" /> '.
7965: $spareid->{$server}{$type}[$i].
7966: '</label></td>'."\n";
7967: }
7968: my $rem = @spares%($numinrow);
7969: my $colsleft = $numinrow - $rem;
7970: if ($colsleft > 1 ) {
7971: $current{$type} .= '<td colspan="'.$colsleft.
7972: '" class="LC_left_item">'.
7973: ' </td>';
7974: } elsif ($colsleft == 1) {
7975: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 7976: }
1.152 raeburn 7977: $current{$type} .= '</tr></table>';
1.150 raeburn 7978: }
1.145 raeburn 7979: }
7980: }
7981: if ($current{$type} eq '') {
7982: $current{$type} = &mt('None specified');
7983: }
1.152 raeburn 7984: if ($othercontrol) {
7985: if ($type eq 'primary') {
7986: $canselect{$type} = $othercontrol;
7987: }
7988: } else {
7989: $canselect{$type} =
7990: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
7991: '<select name="newspare_'.$type.'_'.$server.'" '.
7992: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
7993: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
7994: if (@choices > 0) {
7995: foreach my $lonhost (@choices) {
7996: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
7997: }
7998: }
7999: $canselect{$type} .= '</select>'."\n";
8000: }
8001: } else {
8002: $current{$type} = &mt('Could not be determined');
8003: if ($type eq 'primary') {
8004: $canselect{$type} = $othercontrol;
8005: }
1.145 raeburn 8006: }
1.152 raeburn 8007: if ($type eq 'default') {
8008: $datatable .= '<tr'.$css_class.'>';
8009: }
8010: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8011: '<td>'.$current{$type}.'</td>'."\n".
8012: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8013: }
8014: $itemcount ++;
8015: }
8016: }
8017: $$rowtotal += $itemcount;
8018: return $datatable;
8019: }
8020:
1.152 raeburn 8021: sub possible_newspares {
8022: my ($server,$currspares,$serverhomes,$altids) = @_;
8023: my $serverhostname = &Apache::lonnet::hostname($server);
8024: my %excluded;
8025: if ($serverhostname ne '') {
8026: %excluded = (
8027: $serverhostname => 1,
8028: );
8029: }
8030: if (ref($currspares) eq 'HASH') {
8031: foreach my $type (keys(%{$currspares})) {
8032: if (ref($currspares->{$type}) eq 'ARRAY') {
8033: if (@{$currspares->{$type}} > 0) {
8034: foreach my $curr (@{$currspares->{$type}}) {
8035: my $hostname = &Apache::lonnet::hostname($curr);
8036: $excluded{$hostname} = 1;
8037: }
8038: }
8039: }
8040: }
8041: }
8042: my @choices;
8043: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8044: if (keys(%{$serverhomes}) > 1) {
8045: foreach my $name (sort(keys(%{$serverhomes}))) {
8046: unless ($excluded{$name}) {
8047: if (exists($altids->{$serverhomes->{$name}})) {
8048: push(@choices,$altids->{$serverhomes->{$name}});
8049: } else {
8050: push(@choices,$serverhomes->{$name});
1.145 raeburn 8051: }
8052: }
8053: }
8054: }
8055: }
1.152 raeburn 8056: return sort(@choices);
1.145 raeburn 8057: }
8058:
1.150 raeburn 8059: sub print_loadbalancing {
8060: my ($dom,$settings,$rowtotal) = @_;
8061: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8062: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8063: my $numinrow = 1;
8064: my $datatable;
8065: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 8066: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 8067: if (ref($settings) eq 'HASH') {
8068: %existing = %{$settings};
8069: }
8070: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8071: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 8072: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8073: } else {
8074: return;
8075: }
8076: my ($othertitle,$usertypes,$types) =
8077: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 8078: my $rownum = 8;
1.150 raeburn 8079: if (ref($types) eq 'ARRAY') {
8080: $rownum += scalar(@{$types});
8081: }
1.160.6.7 raeburn 8082: my @css_class = ('LC_odd_row','LC_even_row');
8083: my $balnum = 0;
8084: my $islast;
8085: my (@toshow,$disabledtext);
8086: if (keys(%currbalancer) > 0) {
8087: @toshow = sort(keys(%currbalancer));
8088: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8089: push(@toshow,'');
8090: }
8091: } else {
8092: @toshow = ('');
8093: $disabledtext = &mt('No existing load balancer');
8094: }
8095: foreach my $lonhost (@toshow) {
8096: if ($balnum == scalar(@toshow)-1) {
8097: $islast = 1;
8098: } else {
8099: $islast = 0;
8100: }
8101: my $cssidx = $balnum%2;
8102: my $targets_div_style = 'display: none';
8103: my $disabled_div_style = 'display: block';
8104: my $homedom_div_style = 'display: none';
8105: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
8106: '<td rowspan="'.$rownum.'" valign="top">'.
8107: '<p>';
8108: if ($lonhost eq '') {
8109: $datatable .= '<span class="LC_nobreak">';
8110: if (keys(%currbalancer) > 0) {
8111: $datatable .= &mt('Add balancer:');
8112: } else {
8113: $datatable .= &mt('Enable balancer:');
8114: }
8115: $datatable .= ' '.
8116: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8117: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8118: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8119: '<option value="" selected="selected">'.&mt('None').
8120: '</option>'."\n";
8121: foreach my $server (sort(keys(%servers))) {
8122: next if ($currbalancer{$server});
8123: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8124: }
8125: $datatable .=
8126: '</select>'."\n".
8127: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8128: } else {
8129: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8130: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8131: &mt('Stop balancing').'</label>'.
8132: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8133: $targets_div_style = 'display: block';
8134: $disabled_div_style = 'display: none';
8135: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8136: $homedom_div_style = 'display: block';
8137: }
8138: }
8139: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
8140: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8141: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8142: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8143: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8144: my @sparestypes = ('primary','default');
8145: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 8146: my %hostherechecked = (
8147: no => ' checked="checked"',
8148: );
1.160.6.94 raeburn 8149: my %balcookiechecked = (
8150: no => ' checked="checked"',
8151: );
1.160.6.7 raeburn 8152: foreach my $sparetype (@sparestypes) {
8153: my $targettable;
8154: for (my $i=0; $i<$numspares; $i++) {
8155: my $checked;
8156: if (ref($currtargets{$lonhost}) eq 'HASH') {
8157: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8158: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8159: $checked = ' checked="checked"';
8160: }
8161: }
8162: }
8163: my ($chkboxval,$disabled);
8164: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8165: $chkboxval = $spares[$i];
8166: }
8167: if (exists($currbalancer{$spares[$i]})) {
8168: $disabled = ' disabled="disabled"';
8169: }
8170: $targettable .=
1.160.6.55 raeburn 8171: '<td><span class="LC_nobreak"><label>'.
8172: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 8173: $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 8174: '</span></label></span></td>';
1.160.6.7 raeburn 8175: my $rem = $i%($numinrow);
8176: if ($rem == 0) {
8177: if (($i > 0) && ($i < $numspares-1)) {
8178: $targettable .= '</tr>';
8179: }
8180: if ($i < $numspares-1) {
8181: $targettable .= '<tr>';
1.150 raeburn 8182: }
8183: }
8184: }
1.160.6.7 raeburn 8185: if ($targettable ne '') {
8186: my $rem = $numspares%($numinrow);
8187: my $colsleft = $numinrow - $rem;
8188: if ($colsleft > 1 ) {
8189: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8190: ' </td>';
8191: } elsif ($colsleft == 1) {
8192: $targettable .= '<td class="LC_left_item"> </td>';
8193: }
8194: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8195: '<table><tr>'.$targettable.'</tr></table><br />';
8196: }
1.160.6.76 raeburn 8197: $hostherechecked{$sparetype} = '';
8198: if (ref($currtargets{$lonhost}) eq 'HASH') {
8199: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8200: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8201: $hostherechecked{$sparetype} = ' checked="checked"';
8202: $hostherechecked{'no'} = '';
8203: }
8204: }
8205: }
8206: }
1.160.6.94 raeburn 8207: if ($currcookies{$lonhost}) {
8208: %balcookiechecked = (
8209: yes => ' checked="checked"',
8210: );
8211: }
1.160.6.76 raeburn 8212: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8213: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8214: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8215: foreach my $sparetype (@sparestypes) {
8216: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8217: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8218: '</i></label><br />';
1.160.6.7 raeburn 8219: }
1.160.6.94 raeburn 8220: $datatable .= &mt('Use balancer cookie').'<br />'.
8221: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8222: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8223: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8224: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8225: '</div></td></tr>'.
1.160.6.7 raeburn 8226: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8227: $othertitle,$usertypes,$types,\%servers,
8228: \%currbalancer,$lonhost,
8229: $targets_div_style,$homedom_div_style,
8230: $css_class[$cssidx],$balnum,$islast);
8231: $$rowtotal += $rownum;
8232: $balnum ++;
8233: }
8234: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8235: return $datatable;
8236: }
8237:
8238: sub get_loadbalancers_config {
1.160.6.94 raeburn 8239: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 8240: return unless ((ref($servers) eq 'HASH') &&
8241: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 8242: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8243: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 8244: if (keys(%{$existing}) > 0) {
8245: my $oldlonhost;
8246: foreach my $key (sort(keys(%{$existing}))) {
8247: if ($key eq 'lonhost') {
8248: $oldlonhost = $existing->{'lonhost'};
8249: $currbalancer->{$oldlonhost} = 1;
8250: } elsif ($key eq 'targets') {
8251: if ($oldlonhost) {
8252: $currtargets->{$oldlonhost} = $existing->{'targets'};
8253: }
8254: } elsif ($key eq 'rules') {
8255: if ($oldlonhost) {
8256: $currrules->{$oldlonhost} = $existing->{'rules'};
8257: }
8258: } elsif (ref($existing->{$key}) eq 'HASH') {
8259: $currbalancer->{$key} = 1;
8260: $currtargets->{$key} = $existing->{$key}{'targets'};
8261: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 8262: if ($existing->{$key}{'cookie'}) {
8263: $currcookies->{$key} = 1;
8264: }
1.150 raeburn 8265: }
8266: }
1.160.6.7 raeburn 8267: } else {
8268: my ($balancerref,$targetsref) =
8269: &Apache::lonnet::get_lonbalancer_config($servers);
8270: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8271: foreach my $server (sort(keys(%{$balancerref}))) {
8272: $currbalancer->{$server} = 1;
8273: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8274: }
8275: }
8276: }
1.160.6.7 raeburn 8277: return;
1.150 raeburn 8278: }
8279:
8280: sub loadbalancing_rules {
8281: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 8282: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8283: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8284: my $output;
1.160.6.7 raeburn 8285: my $num = 0;
8286: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8287: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8288: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8289: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 8290: $num ++;
1.150 raeburn 8291: my $current;
8292: if (ref($currrules) eq 'HASH') {
8293: $current = $currrules->{$type};
8294: }
1.160.6.55 raeburn 8295: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 8296: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8297: $current = '';
8298: }
8299: }
8300: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 8301: $servers,$currbalancer,$lonhost,$dom,
8302: $targets_div_style,$homedom_div_style,
8303: $css_class,$balnum,$num,$islast);
1.150 raeburn 8304: }
8305: }
8306: return $output;
8307: }
8308:
8309: sub loadbalancing_titles {
8310: my ($dom,$intdom,$usertypes,$types) = @_;
8311: my %othertypes = (
8312: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8313: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8314: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8315: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 8316: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8317: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8318: );
1.160.6.26 raeburn 8319: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 8320: my @available;
1.150 raeburn 8321: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8322: @available = @{$types};
1.150 raeburn 8323: }
1.160.6.89 raeburn 8324: unless (grep(/^default$/,@available)) {
8325: push(@available,'default');
8326: }
8327: unshift(@alltypes,@available);
1.150 raeburn 8328: my %titles;
8329: foreach my $type (@alltypes) {
8330: if ($type =~ /^_LC_/) {
8331: $titles{$type} = $othertypes{$type};
8332: } elsif ($type eq 'default') {
8333: $titles{$type} = &mt('All users from [_1]',$dom);
8334: if (ref($types) eq 'ARRAY') {
8335: if (@{$types} > 0) {
8336: $titles{$type} = &mt('Other users from [_1]',$dom);
8337: }
8338: }
8339: } elsif (ref($usertypes) eq 'HASH') {
8340: $titles{$type} = $usertypes->{$type};
8341: }
8342: }
8343: return (\@alltypes,\%othertypes,\%titles);
8344: }
8345:
8346: sub loadbalance_rule_row {
1.160.6.7 raeburn 8347: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8348: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 8349: my @rulenames;
1.150 raeburn 8350: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 8351: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 8352: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8353: } else {
1.160.6.26 raeburn 8354: @rulenames = ('default','homeserver');
8355: if ($type eq '_LC_external') {
8356: push(@rulenames,'externalbalancer');
8357: } else {
8358: push(@rulenames,'specific');
8359: }
8360: push(@rulenames,'none');
1.150 raeburn 8361: }
8362: my $style = $targets_div_style;
1.160.6.55 raeburn 8363: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8364: $style = $homedom_div_style;
8365: }
1.160.6.7 raeburn 8366: my $space;
8367: if ($islast && $num == 1) {
1.160.6.118.2 14(raebu 8368:23): $space = '<div style="display:inline-block;"> </div>';
1.160.6.7 raeburn 8369: }
8370: my $output =
8371: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8372: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8373: '<td valaign="top">'.$space.
8374: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8375: for (my $i=0; $i<@rulenames; $i++) {
8376: my $rule = $rulenames[$i];
8377: my ($checked,$extra);
8378: if ($rulenames[$i] eq 'default') {
8379: $rule = '';
8380: }
8381: if ($rulenames[$i] eq 'specific') {
8382: if (ref($servers) eq 'HASH') {
8383: my $default;
8384: if (($current ne '') && (exists($servers->{$current}))) {
8385: $checked = ' checked="checked"';
8386: }
8387: unless ($checked) {
8388: $default = ' selected="selected"';
8389: }
1.160.6.7 raeburn 8390: $extra =
8391: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8392: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8393: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8394: '<option value=""'.$default.'></option>'."\n";
8395: foreach my $server (sort(keys(%{$servers}))) {
8396: if (ref($currbalancer) eq 'HASH') {
8397: next if (exists($currbalancer->{$server}));
8398: }
1.150 raeburn 8399: my $selected;
1.160.6.7 raeburn 8400: if ($server eq $current) {
1.150 raeburn 8401: $selected = ' selected="selected"';
8402: }
1.160.6.7 raeburn 8403: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8404: }
8405: $extra .= '</select>';
8406: }
8407: } elsif ($rule eq $current) {
8408: $checked = ' checked="checked"';
8409: }
8410: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 8411: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8412: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8413: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 8414: ')"'.$checked.' /> ';
1.160.6.56 raeburn 8415: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 8416: $output .= $ruletitles{'particular'};
8417: } else {
8418: $output .= $ruletitles{$rulenames[$i]};
8419: }
8420: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8421: }
8422: $output .= '</div></td></tr>'."\n";
8423: return $output;
8424: }
8425:
8426: sub offloadtype_text {
8427: my %ruletitles = &Apache::lonlocal::texthash (
8428: 'default' => 'Offloads to default destinations',
8429: 'homeserver' => "Offloads to user's home server",
8430: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8431: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 8432: 'none' => 'No offload',
1.160.6.26 raeburn 8433: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8434: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 8435: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8436: );
8437: return %ruletitles;
8438: }
8439:
8440: sub sparestype_titles {
8441: my %typestitles = &Apache::lonlocal::texthash (
8442: 'primary' => 'primary',
8443: 'default' => 'default',
8444: );
8445: return %typestitles;
8446: }
8447:
1.28 raeburn 8448: sub contact_titles {
8449: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 8450: 'supportemail' => 'Support E-mail address',
8451: 'adminemail' => 'Default Server Admin E-mail address',
8452: 'errormail' => 'Error reports to be e-mailed to',
8453: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 8454: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8455: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 8456: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8457: 'requestsmail' => 'E-mail from course requests requiring approval',
8458: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 8459: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 8460: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 8461: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8462: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 8463: 'errorweights' => 'Weights used to compute error count',
8464: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8465: );
8466: my %short_titles = &Apache::lonlocal::texthash (
8467: adminemail => 'Admin E-mail address',
8468: supportemail => 'Support E-mail',
8469: );
8470: return (\%titles,\%short_titles);
8471: }
8472:
1.160.6.78 raeburn 8473: sub helpform_fields {
8474: my %titles = &Apache::lonlocal::texthash (
8475: 'username' => 'Name',
8476: 'user' => 'Username/domain',
8477: 'phone' => 'Phone',
8478: 'cc' => 'Cc e-mail',
8479: 'course' => 'Course Details',
8480: 'section' => 'Sections',
8481: 'screenshot' => 'File upload',
8482: );
8483: my @fields = ('username','phone','user','course','section','cc','screenshot');
8484: my %possoptions = (
8485: username => ['yes','no','req'],
8486: phone => ['yes','no','req'],
8487: user => ['yes','no'],
8488: cc => ['yes','no'],
8489: course => ['yes','no'],
8490: section => ['yes','no'],
8491: screenshot => ['yes','no'],
8492: );
8493: my %fieldoptions = &Apache::lonlocal::texthash (
8494: 'yes' => 'Optional',
8495: 'req' => 'Required',
8496: 'no' => "Not shown",
8497: );
8498: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8499: }
8500:
1.72 raeburn 8501: sub tool_titles {
8502: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 8503: aboutme => 'Personal web page',
1.86 raeburn 8504: blog => 'Blog',
8505: portfolio => 'Portfolio',
1.160.6.118.2 23(raebu 8506:24): portaccess => 'Share portfolio files',
10(raebu 8507:22): timezone => 'Can set time zone',
1.88 bisitz 8508: official => 'Official courses (with institutional codes)',
8509: unofficial => 'Unofficial courses',
1.98 raeburn 8510: community => 'Communities',
1.160.6.30 raeburn 8511: textbook => 'Textbook courses',
1.86 raeburn 8512: );
1.72 raeburn 8513: return %titles;
8514: }
8515:
1.101 raeburn 8516: sub courserequest_titles {
8517: my %titles = &Apache::lonlocal::texthash (
8518: official => 'Official',
8519: unofficial => 'Unofficial',
8520: community => 'Communities',
1.160.6.30 raeburn 8521: textbook => 'Textbook',
1.160.6.118.2 14(raebu 8522:23): lti => 'LTI Provider',
1.101 raeburn 8523: norequest => 'Not allowed',
1.104 raeburn 8524: approval => 'Approval by Dom. Coord.',
1.101 raeburn 8525: validate => 'With validation',
8526: autolimit => 'Numerical limit',
1.103 raeburn 8527: unlimited => '(blank for unlimited)',
1.101 raeburn 8528: );
8529: return %titles;
8530: }
8531:
1.160.6.5 raeburn 8532: sub authorrequest_titles {
8533: my %titles = &Apache::lonlocal::texthash (
8534: norequest => 'Not allowed',
8535: approval => 'Approval by Dom. Coord.',
8536: automatic => 'Automatic approval',
8537: );
8538: return %titles;
8539: }
8540:
1.101 raeburn 8541: sub courserequest_conditions {
8542: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8543: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 8544: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8545: );
8546: return %conditions;
8547: }
8548:
8549:
1.27 raeburn 8550: sub print_usercreation {
1.30 raeburn 8551: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8552: my $numinrow = 4;
1.28 raeburn 8553: my $datatable;
8554: if ($position eq 'top') {
1.30 raeburn 8555: $$rowtotal ++;
1.34 raeburn 8556: my $rowcount = 0;
1.32 raeburn 8557: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8558: if (ref($rules) eq 'HASH') {
8559: if (keys(%{$rules}) > 0) {
1.32 raeburn 8560: $datatable .= &user_formats_row('username',$settings,$rules,
8561: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8562: $$rowtotal ++;
1.32 raeburn 8563: $rowcount ++;
8564: }
8565: }
8566: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8567: if (ref($idrules) eq 'HASH') {
8568: if (keys(%{$idrules}) > 0) {
8569: $datatable .= &user_formats_row('id',$settings,$idrules,
8570: $idruleorder,$numinrow,$rowcount);
8571: $$rowtotal ++;
8572: $rowcount ++;
1.28 raeburn 8573: }
8574: }
1.39 raeburn 8575: if ($rowcount == 0) {
8576: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8577: $$rowtotal ++;
8578: $rowcount ++;
8579: }
1.34 raeburn 8580: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 8581: my @creators = ('author','course','requestcrs');
1.37 raeburn 8582: my ($rules,$ruleorder) =
8583: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8584: my %lt = &usercreation_types();
8585: my %checked;
8586: if (ref($settings) eq 'HASH') {
8587: if (ref($settings->{'cancreate'}) eq 'HASH') {
8588: foreach my $item (@creators) {
8589: $checked{$item} = $settings->{'cancreate'}{$item};
8590: }
8591: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8592: foreach my $item (@creators) {
8593: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8594: $checked{$item} = 'none';
8595: }
8596: }
8597: }
8598: }
8599: my $rownum = 0;
8600: foreach my $item (@creators) {
8601: $rownum ++;
1.160.6.34 raeburn 8602: if ($checked{$item} eq '') {
8603: $checked{$item} = 'any';
1.34 raeburn 8604: }
8605: my $css_class;
8606: if ($rownum%2) {
8607: $css_class = '';
8608: } else {
8609: $css_class = ' class="LC_odd_row" ';
8610: }
8611: $datatable .= '<tr'.$css_class.'>'.
8612: '<td><span class="LC_nobreak">'.$lt{$item}.
8613: '</span></td><td align="right">';
1.160.6.34 raeburn 8614: my @options = ('any');
8615: if (ref($rules) eq 'HASH') {
8616: if (keys(%{$rules}) > 0) {
8617: push(@options,('official','unofficial'));
1.37 raeburn 8618: }
8619: }
1.160.6.34 raeburn 8620: push(@options,'none');
1.37 raeburn 8621: foreach my $option (@options) {
1.50 raeburn 8622: my $type = 'radio';
1.34 raeburn 8623: my $check = ' ';
1.160.6.34 raeburn 8624: if ($checked{$item} eq $option) {
8625: $check = ' checked="checked" ';
1.34 raeburn 8626: }
8627: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8628: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8629: $item.'" value="'.$option.'"'.$check.'/> '.
8630: $lt{$option}.'</label> </span>';
8631: }
8632: $datatable .= '</td></tr>';
8633: }
1.28 raeburn 8634: } else {
8635: my @contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 8636:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8637: my %checked;
8638: if (ref($settings) eq 'HASH') {
8639: if (ref($settings->{'authtypes'}) eq 'HASH') {
8640: foreach my $item (@contexts) {
8641: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8642: foreach my $auth (@authtypes) {
8643: if ($settings->{'authtypes'}{$item}{$auth}) {
8644: $checked{$item}{$auth} = ' checked="checked" ';
8645: }
8646: }
8647: }
8648: }
1.27 raeburn 8649: }
1.35 raeburn 8650: } else {
8651: foreach my $item (@contexts) {
1.36 raeburn 8652: foreach my $auth (@authtypes) {
1.35 raeburn 8653: $checked{$item}{$auth} = ' checked="checked" ';
8654: }
8655: }
1.27 raeburn 8656: }
1.28 raeburn 8657: my %title = &context_names();
8658: my %authname = &authtype_names();
8659: my $rownum = 0;
8660: my $css_class;
8661: foreach my $item (@contexts) {
8662: if ($rownum%2) {
8663: $css_class = '';
8664: } else {
8665: $css_class = ' class="LC_odd_row" ';
8666: }
1.30 raeburn 8667: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8668: '<td>'.$title{$item}.
8669: '</td><td class="LC_left_item">'.
8670: '<span class="LC_nobreak">';
8671: foreach my $auth (@authtypes) {
8672: $datatable .= '<label>'.
8673: '<input type="checkbox" name="'.$item.'_auth" '.
8674: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8675: $authname{$auth}.'</label> ';
8676: }
8677: $datatable .= '</span></td></tr>';
8678: $rownum ++;
1.27 raeburn 8679: }
1.30 raeburn 8680: $$rowtotal += $rownum;
1.27 raeburn 8681: }
8682: return $datatable;
8683: }
8684:
1.160.6.34 raeburn 8685: sub print_selfcreation {
8686: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 8687: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8688: $emaildomain,$datatable);
1.160.6.34 raeburn 8689: if (ref($settings) eq 'HASH') {
8690: if (ref($settings->{'cancreate'}) eq 'HASH') {
8691: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 8692: if (ref($createsettings) eq 'HASH') {
8693: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8694: @selfcreate = @{$createsettings->{'selfcreate'}};
8695: } elsif ($createsettings->{'selfcreate'} ne '') {
8696: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8697: @selfcreate = ('email','login','sso');
8698: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8699: @selfcreate = ($createsettings->{'selfcreate'});
8700: }
8701: }
8702: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8703: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 8704: }
1.160.6.93 raeburn 8705: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8706: $emailoptions = $createsettings->{'emailoptions'};
8707: }
8708: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8709: $emailverified = $createsettings->{'emailverified'};
8710: }
8711: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8712: $emaildomain = $createsettings->{'emaildomain'};
8713: }
1.160.6.34 raeburn 8714: }
8715: }
8716: }
8717: my %radiohash;
8718: my $numinrow = 4;
8719: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 8720: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 8721: if ($position eq 'top') {
8722: my %choices = &Apache::lonlocal::texthash (
8723: cancreate_login => 'Institutional Login',
8724: cancreate_sso => 'Institutional Single Sign On',
8725: );
8726: my @toggles = sort(keys(%choices));
8727: my %defaultchecked = (
8728: 'cancreate_login' => 'off',
8729: 'cancreate_sso' => 'off',
8730: );
1.160.6.35 raeburn 8731: my ($onclick,$itemcount);
1.160.6.34 raeburn 8732: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8733: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 8734: $$rowtotal += $itemcount;
1.160.6.34 raeburn 8735:
8736: if (ref($usertypes) eq 'HASH') {
8737: if (keys(%{$usertypes}) > 0) {
8738: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8739: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 8740: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 8741: $$rowtotal ++;
8742: }
8743: }
1.160.6.44 raeburn 8744: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8745: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8746: $fieldtitles{'inststatus'} = &mt('Institutional status');
8747: my $rem;
8748: my $numperrow = 2;
8749: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8750: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 8751: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 8752: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 8753: '<table>'."\n";
1.160.6.44 raeburn 8754: for (my $i=0; $i<@fields; $i++) {
8755: $rem = $i%($numperrow);
8756: if ($rem == 0) {
8757: if ($i > 0) {
8758: $datatable .= '</tr>';
8759: }
8760: $datatable .= '<tr>';
8761: }
8762: my $currval;
1.160.6.51 raeburn 8763: if (ref($createsettings) eq 'HASH') {
8764: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8765: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8766: }
1.160.6.44 raeburn 8767: }
8768: $datatable .= '<td class="LC_left_item">'.
8769: '<span class="LC_nobreak">'.
8770: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8771: 'value="'.$currval.'" size="10" /> '.
8772: $fieldtitles{$fields[$i]}.'</span></td>';
8773: }
8774: my $colsleft = $numperrow - $rem;
8775: if ($colsleft > 1 ) {
8776: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8777: ' </td>';
8778: } elsif ($colsleft == 1) {
8779: $datatable .= '<td class="LC_left_item"> </td>';
8780: }
8781: $datatable .= '</tr></table></td></tr>';
8782: $$rowtotal ++;
1.160.6.34 raeburn 8783: } elsif ($position eq 'middle') {
8784: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 8785: my @posstypes;
1.160.6.34 raeburn 8786: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8787: @posstypes = @{$types};
8788: }
8789: unless (grep(/^default$/,@posstypes)) {
8790: push(@posstypes,'default');
8791: }
8792: my %usertypeshash;
8793: if (ref($usertypes) eq 'HASH') {
8794: %usertypeshash = %{$usertypes};
8795: }
8796: $usertypeshash{'default'} = $othertitle;
8797: foreach my $status (@posstypes) {
8798: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8799: $numinrow,$$rowtotal,\%usertypeshash);
8800: $$rowtotal ++;
1.160.6.34 raeburn 8801: }
8802: } else {
1.160.6.40 raeburn 8803: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 8804: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 8805: );
8806: my @toggles = sort(keys(%choices));
8807: my %defaultchecked = (
8808: 'cancreate_email' => 'off',
8809: );
1.160.6.93 raeburn 8810: my $customclass = 'LC_selfcreate_email';
8811: my $classprefix = 'LC_canmodify_emailusername_';
8812: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 8813: my $display = 'none';
1.160.6.93 raeburn 8814: my $rowstyle = 'display:none';
1.160.6.40 raeburn 8815: if (grep(/^\Qemail\E$/,@selfcreate)) {
8816: $display = 'block';
1.160.6.93 raeburn 8817: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 8818: }
1.160.6.93 raeburn 8819: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8820: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8821: \%choices,$$rowtotal,$onclick);
8822: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8823: $rowstyle);
8824: $$rowtotal ++;
8825: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8826: $rowstyle);
8827: $$rowtotal ++;
8828: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 8829: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 8830: my ($emailrules,$emailruleorder) =
8831: &Apache::lonnet::inst_userrules($dom,'email');
8832: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8833: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8834: if (ref($types) eq 'ARRAY') {
8835: @posstypes = @{$types};
8836: }
8837: if (@posstypes) {
8838: unless (grep(/^default$/,@posstypes)) {
8839: push(@posstypes,'default');
1.160.6.89 raeburn 8840: }
8841: if (ref($usertypes) eq 'HASH') {
8842: %usertypeshash = %{$usertypes};
8843: }
1.160.6.93 raeburn 8844: my $currassign;
8845: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8846: $currassign = {
8847: selfassign => $domdefaults{'inststatusguest'},
8848: };
8849: @ordered = @{$domdefaults{'inststatusguest'}};
8850: } else {
8851: $currassign = { selfassign => [] };
8852: }
8853: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8854: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8855: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8856: $numinrow,$othertitle,'selfassign',
8857: $rowtotal,$onclicktypes,$customclass,
8858: $rowstyle);
8859: $$rowtotal ++;
1.160.6.89 raeburn 8860: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8861: foreach my $status (@posstypes) {
8862: my $css_class;
8863: if ($$rowtotal%2) {
8864: $css_class = 'LC_odd_row ';
8865: }
8866: $css_class .= $customclass;
8867: my $rowid = $optionsprefix.$status;
8868: my $hidden = 1;
8869: my $currstyle = 'display:none';
8870: if (grep(/^\Q$status\E$/,@ordered)) {
8871: $currstyle = $rowstyle;
8872: $hidden = 0;
8873: }
8874: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8875: $emailrules,$emailruleorder,$settings,$status,$rowid,
8876: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8877: unless ($hidden) {
8878: $$rowtotal ++;
8879: }
1.160.6.89 raeburn 8880: }
8881: } else {
1.160.6.93 raeburn 8882: my $css_class;
8883: if ($$rowtotal%2) {
8884: $css_class = 'LC_odd_row ';
8885: }
8886: $css_class .= $customclass;
1.160.6.89 raeburn 8887: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8888: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8889: $emailrules,$emailruleorder,$settings,'default','',
8890: $othertitle,$css_class,$rowstyle,$intdom);
8891: $$rowtotal ++;
1.160.6.34 raeburn 8892: }
1.160.6.35 raeburn 8893: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8894: $numinrow = 1;
1.160.6.93 raeburn 8895: if (@posstypes) {
8896: foreach my $status (@posstypes) {
8897: my $rowid = $classprefix.$status;
8898: my $datarowstyle = 'display:none';
8899: if (grep(/^\Q$status\E$/,@ordered)) {
8900: $datarowstyle = $rowstyle;
8901: }
8902: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8903: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8904: $infotitles,$rowid,$customclass,$datarowstyle);
8905: unless ($datarowstyle eq 'display:none') {
8906: $$rowtotal ++;
8907: }
1.160.6.34 raeburn 8908: }
1.160.6.93 raeburn 8909: } else {
8910: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8911: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8912: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 8913: }
8914: }
8915: return $datatable;
8916: }
8917:
1.160.6.93 raeburn 8918: sub selfcreate_javascript {
8919: return <<"ENDSCRIPT";
8920:
8921: <script type="text/javascript">
8922: // <![CDATA[
8923:
8924: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8925: var x = document.getElementsByClassName(target);
8926: var insttypes = 0;
8927: var insttypeRegExp = new RegExp(prefix);
8928: if ((x.length != undefined) && (x.length > 0)) {
8929: if (form.elements[radio].length != undefined) {
8930: for (var i=0; i<form.elements[radio].length; i++) {
8931: if (form.elements[radio][i].checked) {
8932: if (form.elements[radio][i].value == 1) {
8933: for (var j=0; j<x.length; j++) {
8934: if (x[j].id == 'undefined') {
8935: x[j].style.display = 'table-row';
8936: } else if (insttypeRegExp.test(x[j].id)) {
8937: insttypes ++;
8938: } else {
8939: x[j].style.display = 'table-row';
8940: }
8941: }
8942: } else {
8943: for (var j=0; j<x.length; j++) {
8944: x[j].style.display = 'none';
8945: }
1.160.6.40 raeburn 8946: }
1.160.6.93 raeburn 8947: break;
8948: }
8949: }
8950: if (insttypes > 0) {
8951: toggleDataRow(form,checkbox,target,altprefix);
8952: toggleDataRow(form,checkbox,target,prefix,1);
8953: }
8954: }
8955: }
8956: return;
8957: }
8958:
8959: function toggleDataRow(form,checkbox,target,prefix,docount) {
8960: if (form.elements[checkbox].length != undefined) {
8961: var count = 0;
8962: if (docount) {
8963: for (var i=0; i<form.elements[checkbox].length; i++) {
8964: if (form.elements[checkbox][i].checked) {
8965: count ++;
8966: }
8967: }
8968: }
8969: for (var i=0; i<form.elements[checkbox].length; i++) {
8970: var type = form.elements[checkbox][i].value;
8971: if (document.getElementById(prefix+type)) {
8972: if (form.elements[checkbox][i].checked) {
8973: document.getElementById(prefix+type).style.display = 'table-row';
8974: if (count % 2 == 1) {
8975: document.getElementById(prefix+type).className = target+' LC_odd_row';
8976: } else {
8977: document.getElementById(prefix+type).className = target;
8978: }
8979: count ++;
1.160.6.40 raeburn 8980: } else {
1.160.6.93 raeburn 8981: document.getElementById(prefix+type).style.display = 'none';
8982: }
8983: }
8984: }
8985: }
8986: return;
8987: }
8988:
8989: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
8990: var caller = radio+'_'+status;
8991: if (form.elements[caller].length != undefined) {
8992: for (var i=0; i<form.elements[caller].length; i++) {
8993: if (form.elements[caller][i].checked) {
8994: if (document.getElementById(altprefix+'_inst_'+status)) {
8995: var curr = form.elements[caller][i].value;
8996: if (prefix) {
8997: document.getElementById(prefix+'_'+status).style.display = 'none';
8998: }
8999: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9000: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9001: if (curr == 'custom') {
9002: if (prefix) {
9003: document.getElementById(prefix+'_'+status).style.display = 'inline';
9004: }
9005: } else if (curr == 'inst') {
9006: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9007: } else if (curr == 'noninst') {
9008: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 9009: }
1.160.6.93 raeburn 9010: break;
1.160.6.40 raeburn 9011: }
1.160.6.93 raeburn 9012: }
9013: }
9014: }
9015: }
9016:
9017: // ]]>
9018: </script>
9019:
9020: ENDSCRIPT
9021: }
9022:
9023: sub noninst_users {
9024: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9025: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9026: my $class = 'LC_left_item';
9027: if ($css_class) {
9028: $css_class = ' class="'.$css_class.'"';
9029: }
9030: if ($rowid) {
9031: $rowid = ' id="'.$rowid.'"';
9032: }
9033: if ($rowstyle) {
9034: $rowstyle = ' style="'.$rowstyle.'"';
9035: }
9036: my ($output,$description);
9037: if ($type eq 'default') {
9038: $description = &mt('Requests for: [_1]',$typetitle);
9039: } else {
9040: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9041: }
9042: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9043: "<td>$description</td>\n".
9044: '<td class="'.$class.'" colspan="2">'.
9045: '<table><tr>';
9046: my %headers = &Apache::lonlocal::texthash(
9047: approve => 'Processing',
9048: email => 'E-mail',
9049: username => 'Username',
9050: );
9051: foreach my $item ('approve','email','username') {
9052: $output .= '<th>'.$headers{$item}.'</th>';
9053: }
9054: $output .= '</tr><tr>';
9055: foreach my $item ('approve','email','username') {
9056: $output .= '<td valign="top">';
9057: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9058: if ($item eq 'approve') {
9059: %choices = &Apache::lonlocal::texthash (
9060: automatic => 'Automatically approved',
9061: approval => 'Queued for approval',
9062: );
9063: @options = ('automatic','approval');
9064: $hashref = $processing;
9065: $defoption = 'automatic';
9066: $name = 'cancreate_emailprocess_'.$type;
9067: } elsif ($item eq 'email') {
9068: %choices = &Apache::lonlocal::texthash (
9069: any => 'Any e-mail',
9070: inst => 'Institutional only',
9071: noninst => 'Non-institutional only',
9072: custom => 'Custom restrictions',
9073: );
9074: @options = ('any','inst','noninst');
9075: my $showcustom;
9076: if (ref($emailrules) eq 'HASH') {
9077: if (keys(%{$emailrules}) > 0) {
9078: push(@options,'custom');
9079: $showcustom = 'cancreate_emailrule';
9080: if (ref($settings) eq 'HASH') {
9081: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9082: foreach my $rule (@{$settings->{'email_rule'}}) {
9083: if (exists($emailrules->{$rule})) {
9084: $hascustom ++;
9085: }
9086: }
9087: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9088: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9089: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9090: if (exists($emailrules->{$rule})) {
9091: $hascustom ++;
9092: }
9093: }
9094: }
9095: }
9096: }
9097: }
9098: }
9099: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9100: "'cancreate_emaildomain','$type'".');"';
9101: $hashref = $emailoptions;
9102: $defoption = 'any';
9103: $name = 'cancreate_emailoptions_'.$type;
9104: } elsif ($item eq 'username') {
9105: %choices = &Apache::lonlocal::texthash (
9106: all => 'Same as e-mail',
9107: first => 'Omit @domain',
9108: free => 'Free to choose',
9109: );
9110: @options = ('all','first','free');
9111: $hashref = $emailverified;
9112: $defoption = 'all';
9113: $name = 'cancreate_usernameoptions_'.$type;
9114: }
9115: foreach my $option (@options) {
9116: my $checked;
9117: if (ref($hashref) eq 'HASH') {
9118: if ($type eq '') {
9119: if (!exists($hashref->{'default'})) {
9120: if ($option eq $defoption) {
9121: $checked = ' checked="checked"';
9122: }
9123: } else {
9124: if ($hashref->{'default'} eq $option) {
9125: $checked = ' checked="checked"';
9126: }
1.160.6.40 raeburn 9127: }
9128: } else {
1.160.6.93 raeburn 9129: if (!exists($hashref->{$type})) {
9130: if ($option eq $defoption) {
9131: $checked = ' checked="checked"';
9132: }
9133: } else {
9134: if ($hashref->{$type} eq $option) {
9135: $checked = ' checked="checked"';
9136: }
1.160.6.40 raeburn 9137: }
9138: }
1.160.6.93 raeburn 9139: } elsif (($item eq 'email') && ($hascustom)) {
9140: if ($option eq 'custom') {
9141: $checked = ' checked="checked"';
9142: }
9143: } elsif ($option eq $defoption) {
9144: $checked = ' checked="checked"';
9145: }
9146: $output .= '<span class="LC_nobreak"><label>'.
9147: '<input type="radio" name="'.$name.'"'.
9148: $checked.' value="'.$option.'"'.$onclick.' />'.
9149: $choices{$option}.'</label></span><br />';
9150: if ($item eq 'email') {
9151: if ($option eq 'custom') {
9152: my $id = 'cancreate_emailrule_'.$type;
9153: my $display = 'none';
9154: if ($checked) {
9155: $display = 'inline';
9156: }
9157: my $numinrow = 2;
9158: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9159: '<legend>'.&mt('Disallow').'</legend><table>'.
9160: &user_formats_row('email',$settings,$emailrules,
9161: $emailruleorder,$numinrow,'',$type);
9162: '</table></fieldset>';
9163: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9164: my %text = &Apache::lonlocal::texthash (
9165: inst => 'must end:',
9166: noninst => 'cannot end:',
9167: );
9168: my $value;
9169: if (ref($emaildomain) eq 'HASH') {
9170: if (ref($emaildomain->{$type}) eq 'HASH') {
9171: $value = $emaildomain->{$type}->{$option};
9172: }
9173: }
9174: if ($value eq '') {
9175: $value = '@'.$intdom;
9176: }
9177: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9178: my $display = 'none';
9179: if ($checked) {
9180: $display = 'inline';
9181: }
9182: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9183: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9184: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9185: '</div>';
9186: }
1.160.6.40 raeburn 9187: }
9188: }
1.160.6.93 raeburn 9189: $output .= '</td>'."\n";
1.160.6.40 raeburn 9190: }
1.160.6.93 raeburn 9191: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 9192: return $output;
9193: }
9194:
1.160.6.5 raeburn 9195: sub captcha_choice {
1.160.6.93 raeburn 9196: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 9197: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
1.160.6.118.2 14(raebu 9198:23): $vertext,$currver);
1.160.6.5 raeburn 9199: my %lt = &captcha_phrases();
9200: $keyentry = 'hidden';
1.160.6.98 raeburn 9201: my $colspan=2;
1.160.6.5 raeburn 9202: if ($context eq 'cancreate') {
1.160.6.34 raeburn 9203: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 9204: } elsif ($context eq 'login') {
9205: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 9206: } elsif ($context eq 'passwords') {
9207: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9208: $colspan=1;
1.160.6.5 raeburn 9209: }
9210: if (ref($settings) eq 'HASH') {
9211: if ($settings->{'captcha'}) {
9212: $checked{$settings->{'captcha'}} = ' checked="checked"';
9213: } else {
9214: $checked{'original'} = ' checked="checked"';
9215: }
9216: if ($settings->{'captcha'} eq 'recaptcha') {
9217: $pubtext = $lt{'pub'};
9218: $privtext = $lt{'priv'};
9219: $keyentry = 'text';
1.160.6.69 raeburn 9220: $vertext = $lt{'ver'};
9221: $currver = $settings->{'recaptchaversion'};
9222: if ($currver ne '2') {
9223: $currver = 1;
9224: }
1.160.6.5 raeburn 9225: }
9226: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9227: $currpub = $settings->{'recaptchakeys'}{'public'};
9228: $currpriv = $settings->{'recaptchakeys'}{'private'};
9229: }
9230: } else {
9231: $checked{'original'} = ' checked="checked"';
9232: }
1.160.6.93 raeburn 9233: my $css_class;
9234: if ($itemcount%2) {
9235: $css_class = 'LC_odd_row';
9236: }
9237: if ($customcss) {
9238: $css_class .= " $customcss";
9239: }
9240: $css_class =~ s/^\s+//;
9241: if ($css_class) {
9242: $css_class = ' class="'.$css_class.'"';
9243: }
9244: if ($rowstyle) {
9245: $css_class .= ' style="'.$rowstyle.'"';
9246: }
1.160.6.5 raeburn 9247: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 9248: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 9249: '<table><tr><td>'."\n";
9250: foreach my $option ('original','recaptcha','notused') {
9251: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9252: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9253: $lt{$option}.'</label></span>';
9254: unless ($option eq 'notused') {
9255: $output .= (' 'x2)."\n";
9256: }
9257: }
9258: #
9259: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9260: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
9261: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
9262: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
9263: #
9264: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 9265: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 9266: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9267: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9268: $currpub.'" size="40" /></span><br />'."\n".
9269: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9270: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 9271: $currpriv.'" size="40" /></span><br />'.
9272: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9273: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9274: $currver.'" size="3" /></span><br />'.
9275: '</td></tr></table>'."\n".
1.160.6.5 raeburn 9276: '</td></tr>';
9277: return $output;
9278: }
9279:
1.32 raeburn 9280: sub user_formats_row {
1.160.6.93 raeburn 9281: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9282: my $output;
9283: my %text = (
9284: 'username' => 'new usernames',
9285: 'id' => 'IDs',
9286: );
1.160.6.118.2 8(raebur 9287:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 9288: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9289: $output = '<tr '.$css_class.'>'.
9290: '<td><span class="LC_nobreak">'.
9291: &mt("Format rules to check for $text{$type}: ").
9292: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9293: }
1.27 raeburn 9294: my $rem;
9295: if (ref($ruleorder) eq 'ARRAY') {
9296: for (my $i=0; $i<@{$ruleorder}; $i++) {
9297: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9298: my $rem = $i%($numinrow);
9299: if ($rem == 0) {
9300: if ($i > 0) {
9301: $output .= '</tr>';
9302: }
9303: $output .= '<tr>';
9304: }
9305: my $check = ' ';
1.39 raeburn 9306: if (ref($settings) eq 'HASH') {
9307: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9308: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9309: $check = ' checked="checked" ';
9310: }
1.160.6.93 raeburn 9311: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9312: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9313: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9314: $check = ' checked="checked" ';
9315: }
9316: }
1.27 raeburn 9317: }
9318: }
1.160.6.93 raeburn 9319: my $name = $type.'_rule';
9320: if ($type eq 'email') {
9321: $name .= '_'.$status;
9322: }
1.27 raeburn 9323: $output .= '<td class="LC_left_item">'.
9324: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 9325: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9326: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9327: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9328: }
9329: }
9330: $rem = @{$ruleorder}%($numinrow);
9331: }
1.160.6.93 raeburn 9332: my $colsleft;
9333: if ($rem) {
9334: $colsleft = $numinrow - $rem;
9335: }
1.27 raeburn 9336: if ($colsleft > 1 ) {
9337: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9338: ' </td>';
9339: } elsif ($colsleft == 1) {
9340: $output .= '<td class="LC_left_item"> </td>';
9341: }
1.160.6.118.2 8(raebur 9342:2): $output .= '</tr>';
9343:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
9344:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 9345: }
1.27 raeburn 9346: return $output;
9347: }
9348:
1.34 raeburn 9349: sub usercreation_types {
9350: my %lt = &Apache::lonlocal::texthash (
9351: author => 'When adding a co-author',
9352: course => 'When adding a user to a course',
1.100 raeburn 9353: requestcrs => 'When requesting a course',
1.34 raeburn 9354: any => 'Any',
9355: official => 'Institutional only ',
9356: unofficial => 'Non-institutional only',
9357: none => 'None',
9358: );
9359: return %lt;
1.48 raeburn 9360: }
1.34 raeburn 9361:
1.160.6.34 raeburn 9362: sub selfcreation_types {
9363: my %lt = &Apache::lonlocal::texthash (
9364: selfcreate => 'User creates own account',
9365: any => 'Any',
9366: official => 'Institutional only ',
9367: unofficial => 'Non-institutional only',
9368: email => 'E-mail address',
9369: login => 'Institutional Login',
9370: sso => 'SSO',
9371: );
9372: }
9373:
1.28 raeburn 9374: sub authtype_names {
9375: my %lt = &Apache::lonlocal::texthash(
9376: int => 'Internal',
9377: krb4 => 'Kerberos 4',
9378: krb5 => 'Kerberos 5',
9379: loc => 'Local',
1.160.6.118.2 14(raebu 9380:23): lti => 'LTI',
1.28 raeburn 9381: );
9382: return %lt;
9383: }
9384:
9385: sub context_names {
9386: my %context_title = &Apache::lonlocal::texthash(
9387: author => 'Creating users when an Author',
9388: course => 'Creating users when in a course',
9389: domain => 'Creating users when a Domain Coordinator',
9390: );
9391: return %context_title;
9392: }
9393:
1.33 raeburn 9394: sub print_usermodification {
9395: my ($position,$dom,$settings,$rowtotal) = @_;
9396: my $numinrow = 4;
9397: my ($context,$datatable,$rowcount);
9398: if ($position eq 'top') {
9399: $rowcount = 0;
9400: $context = 'author';
9401: foreach my $role ('ca','aa') {
9402: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9403: $numinrow,$rowcount);
9404: $$rowtotal ++;
9405: $rowcount ++;
9406: }
1.160.6.118.2 25(raebu 9407:24): } elsif ($position eq 'middle') {
9408:24): $rowcount = 0;
9409:24): $context = 'coauthor';
9410:24): foreach my $role ('ca','aa') {
9411:24): $datatable .= &modifiable_userdata_row($context,$role,$settings,
9412:24): $numinrow,$rowcount);
9413:24): $$rowtotal ++;
9414:24): $rowcount ++;
9415:24): }
1.160.6.37 raeburn 9416: } elsif ($position eq 'bottom') {
1.33 raeburn 9417: $context = 'course';
9418: $rowcount = 0;
9419: foreach my $role ('st','ep','ta','in','cr') {
9420: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9421: $numinrow,$rowcount);
9422: $$rowtotal ++;
9423: $rowcount ++;
9424: }
9425: }
9426: return $datatable;
9427: }
9428:
1.43 raeburn 9429: sub print_defaults {
1.160.6.40 raeburn 9430: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9431: my $rownum = 0;
1.160.6.80 raeburn 9432: my ($datatable,$css_class,$titles);
9433: unless ($position eq 'bottom') {
9434: $titles = &defaults_titles($dom);
9435: }
1.160.6.40 raeburn 9436: if ($position eq 'top') {
9437: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9438: 'datelocale_def','portal_def');
9439: my %defaults;
9440: if (ref($settings) eq 'HASH') {
9441: %defaults = %{$settings};
1.43 raeburn 9442: } else {
1.160.6.40 raeburn 9443: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9444: foreach my $item (@items) {
9445: $defaults{$item} = $domdefaults{$item};
9446: }
1.43 raeburn 9447: }
1.160.6.40 raeburn 9448: foreach my $item (@items) {
9449: if ($rownum%2) {
9450: $css_class = '';
9451: } else {
9452: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 9453: }
1.160.6.40 raeburn 9454: $datatable .= '<tr'.$css_class.'>'.
9455: '<td><span class="LC_nobreak">'.$titles->{$item}.
9456: '</span></td><td class="LC_right_item" colspan="3">';
9457: if ($item eq 'auth_def') {
1.160.6.118.2 14(raebu 9458:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.160.6.40 raeburn 9459: my %shortauth = (
9460: internal => 'int',
9461: krb4 => 'krb4',
9462: krb5 => 'krb5',
1.160.6.118.2 14(raebu 9463:23): localauth => 'loc',
9464:23): lti => 'lti',
1.160.6.40 raeburn 9465: );
9466: my %authnames = &authtype_names();
9467: foreach my $auth (@authtypes) {
9468: my $checked = ' ';
9469: if ($defaults{$item} eq $auth) {
9470: $checked = ' checked="checked" ';
9471: }
9472: $datatable .= '<label><input type="radio" name="'.$item.
9473: '" value="'.$auth.'"'.$checked.'/>'.
9474: $authnames{$shortauth{$auth}}.'</label> ';
9475: }
9476: } elsif ($item eq 'timezone_def') {
9477: my $includeempty = 1;
9478: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9479: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 9480: my $includeempty = 1;
9481: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9482: } elsif ($item eq 'lang_def') {
9483: my $includeempty = 1;
9484: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 9485:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 9486: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 9487:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9488:23): my $portalsty = 'none';
9489:23): if ($defaults{$item}) {
9490:23): $portalsty = 'block';
9491:23): }
9492:23): foreach my $field ('email','web') {
9493:23): my $checkedoff = ' checked="checked"';
9494:23): my $checkedon;
9495:23): if ($defaults{$item.'_'.$field}) {
9496:23): $checkedon = $checkedoff;
9497:23): $checkedoff = '';
9498:23): }
9499:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9500:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
9501:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9502:23): (' 'x2).
9503:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9504:23): '</div>';
9505:23): }
9506:23): } else {
9507:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 9508: }
9509: $datatable .= '</td></tr>';
9510: $rownum ++;
9511: }
1.160.6.118.2 8(raebur 9512:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 9513: my %defaults;
1.160.6.40 raeburn 9514: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 9515: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 9516: my $maxnum = @{$settings->{'inststatusorder'}};
9517: for (my $i=0; $i<$maxnum; $i++) {
9518: $css_class = $rownum%2?' class="LC_odd_row"':'';
9519: my $item = $settings->{'inststatusorder'}->[$i];
9520: my $title = $settings->{'inststatustypes'}->{$item};
9521: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9522: $datatable .= '<tr'.$css_class.'>'.
9523: '<td><span class="LC_nobreak">'.
9524: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9525: for (my $k=0; $k<=$maxnum; $k++) {
9526: my $vpos = $k+1;
9527: my $selstr;
9528: if ($k == $i) {
9529: $selstr = ' selected="selected" ';
9530: }
9531: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9532: }
9533: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9534: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9535: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 9536: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 9537: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 9538: '</span></td></tr>';
1.160.6.40 raeburn 9539: }
9540: $css_class = $rownum%2?' class="LC_odd_row"':'';
9541: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9542: $datatable .= '<tr '.$css_class.'>'.
9543: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9544: for (my $k=0; $k<=$maxnum; $k++) {
9545: my $vpos = $k+1;
9546: my $selstr;
9547: if ($k == $maxnum) {
9548: $selstr = ' selected="selected" ';
9549: }
9550: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9551: }
9552: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 9553: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 9554: ' '.&mt('(new)').
9555: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 9556: &mt('Name displayed').':'.
1.160.6.40 raeburn 9557: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9558: '</tr>'."\n";
9559: $rownum ++;
1.141 raeburn 9560: }
1.43 raeburn 9561: }
1.160.6.118.2 8(raebur 9562:2): } else {
9563:2): my ($unamemaprules,$ruleorder) =
9564:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
9565:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
9566:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9567:2): my $numinrow = 2;
9568:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9569:2): &user_formats_row('unamemap',$settings,$unamemaprules,
9570:2): $ruleorder,$numinrow).
9571:2): '</table></td></tr>';
9572:2): }
9573:2): if ($datatable eq '') {
9574:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9575:2): &mt('No rules set for domain in customized localenroll.pm').
9576:2): '</td></tr>';
9577:2): }
1.43 raeburn 9578: }
9579: $$rowtotal += $rownum;
9580: return $datatable;
9581: }
9582:
1.160.6.5 raeburn 9583: sub get_languages_hash {
9584: my %langchoices;
9585: foreach my $id (&Apache::loncommon::languageids()) {
9586: my $code = &Apache::loncommon::supportedlanguagecode($id);
9587: if ($code ne '') {
9588: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9589: }
9590: }
9591: return %langchoices;
9592: }
9593:
1.43 raeburn 9594: sub defaults_titles {
1.141 raeburn 9595: my ($dom) = @_;
1.43 raeburn 9596: my %titles = &Apache::lonlocal::texthash (
9597: 'auth_def' => 'Default authentication type',
9598: 'auth_arg_def' => 'Default authentication argument',
9599: 'lang_def' => 'Default language',
1.54 raeburn 9600: 'timezone_def' => 'Default timezone',
1.68 raeburn 9601: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9602: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 9603:23): 'email' => 'Email links use portal URL',
9604:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 9605: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9606: 'intauth_check' => 'Check bcrypt cost if authenticated',
9607: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9608: );
1.141 raeburn 9609: if ($dom) {
9610: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9611: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9612: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9613: $protocol = 'http' if ($protocol ne 'https');
9614: if ($uint_dom) {
9615: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9616: $uint_dom);
9617: }
9618: }
1.43 raeburn 9619: return (\%titles);
9620: }
9621:
1.160.6.97 raeburn 9622: sub print_scantron {
9623: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9624: if ($position eq 'top') {
9625: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9626: } else {
9627: return &print_scantronconfig($dom,$settings,\$rowtotal);
9628: }
9629: }
9630:
9631: sub scantron_javascript {
9632: return <<"ENDSCRIPT";
9633:
9634: <script type="text/javascript">
9635: // <![CDATA[
9636:
9637: function toggleScantron(form) {
9638: var csvfieldset = new Array();
9639: if (document.getElementById('scantroncsv_cols')) {
9640: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9641: }
9642: if (document.getElementById('scantroncsv_options')) {
9643: csvfieldset.push(document.getElementById('scantroncsv_options'));
9644: }
9645: if (csvfieldset.length) {
9646: if (document.getElementById('scantronconfcsv')) {
9647: var scantroncsv = document.getElementById('scantronconfcsv');
9648: if (scantroncsv.checked) {
9649: for (var i=0; i<csvfieldset.length; i++) {
9650: csvfieldset[i].style.display = 'block';
9651: }
9652: } else {
9653: for (var i=0; i<csvfieldset.length; i++) {
9654: csvfieldset[i].style.display = 'none';
9655: }
9656: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9657: if (csvselects.length) {
9658: for (var j=0; j<csvselects.length; j++) {
9659: csvselects[j].selectedIndex = 0;
9660: }
9661: }
9662: }
9663: }
9664: }
9665: return;
9666: }
9667: // ]]>
9668: </script>
9669:
9670: ENDSCRIPT
9671:
9672: }
9673:
1.46 raeburn 9674: sub print_scantronformat {
9675: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9676: my $itemcount = 1;
1.60 raeburn 9677: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9678: %confhash);
1.46 raeburn 9679: my $switchserver = &check_switchserver($dom,$confname);
9680: my %lt = &Apache::lonlocal::texthash (
1.95 www 9681: default => 'Default bubblesheet format file error',
9682: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9683: );
9684: my %scantronfiles = (
9685: default => 'default.tab',
9686: custom => 'custom.tab',
9687: );
9688: foreach my $key (keys(%scantronfiles)) {
9689: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9690: .$scantronfiles{$key};
9691: }
9692: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9693: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9694: if (!$switchserver) {
9695: my $servadm = $r->dir_config('lonAdmEMail');
9696: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9697: if ($configuserok eq 'ok') {
9698: if ($author_ok eq 'ok') {
9699: my %legacyfile = (
1.160.6.97 raeburn 9700: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9701: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9702: );
9703: my %md5chk;
9704: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9705: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9706: chomp($md5chk{$type});
1.46 raeburn 9707: }
9708: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9709: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 9710: ($scantronurls{$type},my $error) =
1.46 raeburn 9711: &legacy_scantronformat($r,$dom,$confname,
9712: $type,$legacyfile{$type},
9713: $scantronurls{$type},
9714: $scantronfiles{$type});
1.60 raeburn 9715: if ($error ne '') {
9716: $error{$type} = $error;
9717: }
9718: }
9719: if (keys(%error) == 0) {
9720: $is_custom = 1;
1.160.6.97 raeburn 9721: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9722: $scantronurls{'custom'};
1.160.6.97 raeburn 9723: my $putresult =
1.60 raeburn 9724: &Apache::lonnet::put_dom('configuration',
9725: \%confhash,$dom);
9726: if ($putresult ne 'ok') {
1.160.6.97 raeburn 9727: $error{'custom'} =
1.60 raeburn 9728: '<span class="LC_error">'.
9729: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9730: }
1.46 raeburn 9731: }
9732: } else {
1.60 raeburn 9733: ($scantronurls{'default'},my $error) =
1.46 raeburn 9734: &legacy_scantronformat($r,$dom,$confname,
9735: 'default',$legacyfile{'default'},
9736: $scantronurls{'default'},
9737: $scantronfiles{'default'});
1.60 raeburn 9738: if ($error eq '') {
9739: $confhash{'scantron'}{'scantronformat'} = '';
9740: my $putresult =
9741: &Apache::lonnet::put_dom('configuration',
9742: \%confhash,$dom);
9743: if ($putresult ne 'ok') {
9744: $error{'default'} =
9745: '<span class="LC_error">'.
9746: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9747: }
9748: } else {
9749: $error{'default'} = $error;
9750: }
1.46 raeburn 9751: }
9752: }
9753: }
9754: } else {
1.95 www 9755: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9756: }
9757: }
9758: if (ref($settings) eq 'HASH') {
9759: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9760: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9761: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9762: $scantronurl = '';
9763: } else {
9764: $scantronurl = $settings->{'scantronformat'};
9765: }
9766: $is_custom = 1;
9767: } else {
9768: $scantronurl = $scantronurls{'default'};
9769: }
9770: } else {
1.60 raeburn 9771: if ($is_custom) {
9772: $scantronurl = $scantronurls{'custom'};
9773: } else {
9774: $scantronurl = $scantronurls{'default'};
9775: }
1.46 raeburn 9776: }
9777: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9778: $datatable .= '<tr'.$css_class.'>';
9779: if (!$is_custom) {
1.65 raeburn 9780: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9781: '<span class="LC_nobreak">';
1.46 raeburn 9782: if ($scantronurl) {
1.160.6.21 raeburn 9783: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9784: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9785: } else {
9786: $datatable = &mt('File unavailable for display');
9787: }
1.65 raeburn 9788: $datatable .= '</span></td>';
1.60 raeburn 9789: if (keys(%error) == 0) {
9790: $datatable .= '<td valign="bottom">';
9791: if (!$switchserver) {
9792: $datatable .= &mt('Upload:').'<br />';
9793: }
9794: } else {
9795: my $errorstr;
9796: foreach my $key (sort(keys(%error))) {
9797: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9798: }
9799: $datatable .= '<td>'.$errorstr;
9800: }
1.46 raeburn 9801: } else {
9802: if (keys(%error) > 0) {
9803: my $errorstr;
9804: foreach my $key (sort(keys(%error))) {
9805: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9806: }
1.60 raeburn 9807: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9808: } elsif ($scantronurl) {
1.160.6.26 raeburn 9809: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 9810: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9811: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 9812: $link.
9813: '<label><input type="checkbox" name="scantronformat_del"'.
9814: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9815: '<td><span class="LC_nobreak"> '.
9816: &mt('Replace:').'</span><br />';
1.46 raeburn 9817: }
9818: }
9819: if (keys(%error) == 0) {
9820: if ($switchserver) {
9821: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9822: } else {
1.65 raeburn 9823: $datatable .='<span class="LC_nobreak"> '.
9824: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9825: }
9826: }
9827: $datatable .= '</td></tr>';
9828: $$rowtotal ++;
9829: return $datatable;
9830: }
9831:
9832: sub legacy_scantronformat {
9833: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9834: my ($url,$error);
9835: my @statinfo = &Apache::lonnet::stat_file($newurl);
9836: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.160.6.118.2 14(raebu 9837:23): my $modified = [];
1.46 raeburn 9838: (my $result,$url) =
1.160.6.118.2 14(raebu 9839:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9840:23): 'scantron','','',$newfile,$modified);
9841:23): if ($result eq 'ok') {
9842:23): &update_modify_urls($r,$modified);
9843:23): } else {
1.130 raeburn 9844: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9845: }
9846: }
9847: return ($url,$error);
9848: }
1.43 raeburn 9849:
1.160.6.97 raeburn 9850: sub print_scantronconfig {
9851: my ($dom,$settings,$rowtotal) = @_;
9852: my $itemcount = 2;
9853: my $is_checked = ' checked="checked"';
9854: my %optionson = (
9855: hdr => ' checked="checked"',
9856: pad => ' checked="checked"',
9857: rem => ' checked="checked"',
9858: );
9859: my %optionsoff = (
9860: hdr => '',
9861: pad => '',
9862: rem => '',
9863: );
9864: my $currcsvsty = 'none';
9865: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9866: my @fields = &scantroncsv_fields();
9867: my %titles = &scantronconfig_titles();
9868: if (ref($settings) eq 'HASH') {
9869: if (ref($settings->{config}) eq 'HASH') {
9870: if ($settings->{config}->{dat}) {
9871: $checked{'dat'} = $is_checked;
9872: }
9873: if (ref($settings->{config}->{csv}) eq 'HASH') {
9874: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9875: %csvfields = %{$settings->{config}->{csv}->{fields}};
9876: if (keys(%csvfields) > 0) {
9877: $checked{'csv'} = $is_checked;
9878: $currcsvsty = 'block';
9879: }
9880: }
9881: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9882: %csvoptions = %{$settings->{config}->{csv}->{options}};
9883: foreach my $option (keys(%optionson)) {
9884: unless ($csvoptions{$option}) {
9885: $optionsoff{$option} = $optionson{$option};
9886: $optionson{$option} = '';
9887: }
9888: }
9889: }
9890: }
9891: } else {
9892: $checked{'dat'} = $is_checked;
9893: }
9894: } else {
9895: $checked{'dat'} = $is_checked;
9896: }
9897: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9898: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9899: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9900: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9901: foreach my $item ('dat','csv') {
9902: my $id;
9903: if ($item eq 'csv') {
9904: $id = 'id="scantronconfcsv" ';
9905: }
9906: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9907: $titles{$item}.'</label>'.(' 'x3);
9908: if ($item eq 'csv') {
9909: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9910: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9911: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9912: foreach my $col (@fields) {
9913: my $selnone;
9914: if ($csvfields{$col} eq '') {
9915: $selnone = ' selected="selected"';
9916: }
9917: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9918: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9919: '<option value=""'.$selnone.'></option>';
9920: for (my $i=0; $i<20; $i++) {
9921: my $shown = $i+1;
9922: my $sel;
9923: unless ($selnone) {
9924: if (exists($csvfields{$col})) {
9925: if ($csvfields{$col} == $i) {
9926: $sel = ' selected="selected"';
9927: }
9928: }
9929: }
9930: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9931: }
9932: $datatable .= '</select></td></tr>';
9933: }
9934: $datatable .= '</table></fieldset>'.
9935: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9936: '<legend>'.&mt('CSV Options').'</legend>';
9937: foreach my $option ('hdr','pad','rem') {
9938: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9939: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9940: &mt('Yes').'</label>'.(' 'x2)."\n".
9941: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9942: }
9943: $datatable .= '</fieldset>';
9944: $itemcount ++;
9945: }
9946: }
9947: $datatable .= '</td></tr>';
9948: $$rowtotal ++;
9949: return $datatable;
9950: }
9951:
9952: sub scantronconfig_titles {
9953: return &Apache::lonlocal::texthash(
9954: dat => 'Standard format (.dat)',
9955: csv => 'Comma separated values (.csv)',
9956: hdr => 'Remove first line in file (contains column titles)',
9957: pad => 'Prepend 0s to PaperID',
9958: rem => 'Remove leading spaces (except Question Response columns)',
9959: CODE => 'CODE',
9960: ID => 'Student ID',
9961: PaperID => 'Paper ID',
9962: FirstName => 'First Name',
9963: LastName => 'Last Name',
9964: FirstQuestion => 'First Question Response',
9965: Section => 'Section',
9966: );
9967: }
9968:
9969: sub scantroncsv_fields {
9970: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
9971: }
9972:
1.49 raeburn 9973: sub print_coursecategories {
1.57 raeburn 9974: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
9975: my $datatable;
9976: if ($position eq 'top') {
1.160.6.42 raeburn 9977: my (%checked);
9978: my @catitems = ('unauth','auth');
9979: my @cattypes = ('std','domonly','codesrch','none');
9980: $checked{'unauth'} = 'std';
9981: $checked{'auth'} = 'std';
9982: if (ref($settings) eq 'HASH') {
9983: foreach my $type (@cattypes) {
9984: if ($type eq $settings->{'unauth'}) {
9985: $checked{'unauth'} = $type;
9986: }
9987: if ($type eq $settings->{'auth'}) {
9988: $checked{'auth'} = $type;
9989: }
9990: }
9991: }
9992: my %lt = &Apache::lonlocal::texthash (
9993: unauth => 'Catalog type for unauthenticated users',
9994: auth => 'Catalog type for authenticated users',
9995: none => 'No catalog',
9996: std => 'Standard catalog',
9997: domonly => 'Domain-only catalog',
9998: codesrch => "Code search form",
9999: );
10000: my $itemcount = 0;
10001: foreach my $item (@catitems) {
10002: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10003: $datatable .= '<tr '.$css_class.'>'.
10004: '<td>'.$lt{$item}.'</td>'.
10005: '<td class="LC_right_item"><span class="LC_nobreak">';
10006: foreach my $type (@cattypes) {
10007: my $ischecked;
10008: if ($checked{$item} eq $type) {
10009: $ischecked=' checked="checked"';
10010: }
10011: $datatable .= '<label>'.
10012: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10013: ' />'.$lt{$type}.'</label> ';
10014: }
1.160.6.87 raeburn 10015: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 10016: $itemcount ++;
10017: }
10018: $$rowtotal += $itemcount;
10019: } elsif ($position eq 'middle') {
1.57 raeburn 10020: my $toggle_cats_crs = ' ';
10021: my $toggle_cats_dom = ' checked="checked" ';
10022: my $can_cat_crs = ' ';
10023: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10024: my $toggle_catscomm_comm = ' ';
10025: my $toggle_catscomm_dom = ' checked="checked" ';
10026: my $can_catcomm_comm = ' ';
10027: my $can_catcomm_dom = ' checked="checked" ';
10028:
1.57 raeburn 10029: if (ref($settings) eq 'HASH') {
10030: if ($settings->{'togglecats'} eq 'crs') {
10031: $toggle_cats_crs = $toggle_cats_dom;
10032: $toggle_cats_dom = ' ';
10033: }
10034: if ($settings->{'categorize'} eq 'crs') {
10035: $can_cat_crs = $can_cat_dom;
10036: $can_cat_dom = ' ';
10037: }
1.120 raeburn 10038: if ($settings->{'togglecatscomm'} eq 'comm') {
10039: $toggle_catscomm_comm = $toggle_catscomm_dom;
10040: $toggle_catscomm_dom = ' ';
10041: }
10042: if ($settings->{'categorizecomm'} eq 'comm') {
10043: $can_catcomm_comm = $can_catcomm_dom;
10044: $can_catcomm_dom = ' ';
10045: }
1.57 raeburn 10046: }
10047: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 10048: togglecats => 'Show/Hide a course in catalog',
10049: togglecatscomm => 'Show/Hide a community in catalog',
10050: categorize => 'Assign a category to a course',
10051: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10052: );
10053: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 10054: dom => 'Set in Domain',
10055: crs => 'Set in Course',
10056: comm => 'Set in Community',
1.57 raeburn 10057: );
10058: $datatable = '<tr class="LC_odd_row">'.
10059: '<td>'.$title{'togglecats'}.'</td>'.
10060: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10061: '<input type="radio" name="togglecats"'.
10062: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10063: '<label><input type="radio" name="togglecats"'.
10064: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10065: '</tr><tr>'.
10066: '<td>'.$title{'categorize'}.'</td>'.
10067: '<td class="LC_right_item"><span class="LC_nobreak">'.
10068: '<label><input type="radio" name="categorize"'.
10069: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10070: '<label><input type="radio" name="categorize"'.
10071: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10072: '</tr><tr class="LC_odd_row">'.
10073: '<td>'.$title{'togglecatscomm'}.'</td>'.
10074: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10075: '<input type="radio" name="togglecatscomm"'.
10076: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10077: '<label><input type="radio" name="togglecatscomm"'.
10078: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10079: '</tr><tr>'.
10080: '<td>'.$title{'categorizecomm'}.'</td>'.
10081: '<td class="LC_right_item"><span class="LC_nobreak">'.
10082: '<label><input type="radio" name="categorizecomm"'.
10083: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10084: '<label><input type="radio" name="categorizecomm"'.
10085: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 10086: '</tr>';
1.120 raeburn 10087: $$rowtotal += 4;
1.57 raeburn 10088: } else {
10089: my $css_class;
10090: my $itemcount = 1;
10091: my $cathash;
10092: if (ref($settings) eq 'HASH') {
10093: $cathash = $settings->{'cats'};
10094: }
10095: if (ref($cathash) eq 'HASH') {
10096: my (@cats,@trails,%allitems,%idx,@jsarray);
10097: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10098: \%allitems,\%idx,\@jsarray);
10099: my $maxdepth = scalar(@cats);
10100: my $colattrib = '';
10101: if ($maxdepth > 2) {
10102: $colattrib = ' colspan="2" ';
10103: }
10104: my @path;
10105: if (@cats > 0) {
10106: if (ref($cats[0]) eq 'ARRAY') {
10107: my $numtop = @{$cats[0]};
10108: my $maxnum = $numtop;
1.120 raeburn 10109: my %default_names = (
10110: instcode => &mt('Official courses'),
10111: communities => &mt('Communities'),
10112: );
10113:
10114: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10115: ($cathash->{'instcode::0'} eq '') ||
10116: (!grep(/^communities$/,@{$cats[0]})) ||
10117: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 10118: $maxnum ++;
10119: }
10120: my $lastidx;
10121: for (my $i=0; $i<$numtop; $i++) {
10122: my $parent = $cats[0][$i];
10123: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10124: my $item = &escape($parent).'::0';
10125: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10126: $lastidx = $idx{$item};
10127: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10128: .'<select name="'.$item.'"'.$chgstr.'>';
10129: for (my $k=0; $k<=$maxnum; $k++) {
10130: my $vpos = $k+1;
10131: my $selstr;
10132: if ($k == $i) {
10133: $selstr = ' selected="selected" ';
10134: }
10135: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10136: }
1.160.6.29 raeburn 10137: $datatable .= '</select></span></td><td>';
1.120 raeburn 10138: if ($parent eq 'instcode' || $parent eq 'communities') {
10139: $datatable .= '<span class="LC_nobreak">'
10140: .$default_names{$parent}.'</span>';
10141: if ($parent eq 'instcode') {
10142: $datatable .= '<br /><span class="LC_nobreak">('
10143: .&mt('with institutional codes')
10144: .')</span></td><td'.$colattrib.'>';
10145: } else {
10146: $datatable .= '<table><tr><td>';
10147: }
10148: $datatable .= '<span class="LC_nobreak">'
10149: .'<label><input type="radio" name="'
10150: .$parent.'" value="1" checked="checked" />'
10151: .&mt('Display').'</label>';
10152: if ($parent eq 'instcode') {
10153: $datatable .= ' ';
10154: } else {
10155: $datatable .= '</span></td></tr><tr><td>'
10156: .'<span class="LC_nobreak">';
10157: }
10158: $datatable .= '<label><input type="radio" name="'
10159: .$parent.'" value="0" />'
10160: .&mt('Do not display').'</label></span>';
10161: if ($parent eq 'communities') {
10162: $datatable .= '</td></tr></table>';
10163: }
10164: $datatable .= '</td>';
1.57 raeburn 10165: } else {
10166: $datatable .= $parent
1.160.6.29 raeburn 10167: .' <span class="LC_nobreak"><label>'
10168: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10169: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10170: }
10171: my $depth = 1;
10172: push(@path,$parent);
10173: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10174: pop(@path);
10175: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10176: $itemcount ++;
10177: }
1.48 raeburn 10178: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10179: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10180: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10181: for (my $k=0; $k<=$maxnum; $k++) {
10182: my $vpos = $k+1;
10183: my $selstr;
1.57 raeburn 10184: if ($k == $numtop) {
1.48 raeburn 10185: $selstr = ' selected="selected" ';
10186: }
10187: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10188: }
1.59 bisitz 10189: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10190: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10191: .'</tr>'."\n";
1.48 raeburn 10192: $itemcount ++;
1.120 raeburn 10193: foreach my $default ('instcode','communities') {
10194: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10195: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10196: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10197: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10198: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10199: for (my $k=0; $k<=$maxnum; $k++) {
10200: my $vpos = $k+1;
10201: my $selstr;
10202: if ($k == $maxnum) {
10203: $selstr = ' selected="selected" ';
10204: }
10205: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10206: }
1.120 raeburn 10207: $datatable .= '</select></span></td>'.
10208: '<td><span class="LC_nobreak">'.
10209: $default_names{$default}.'</span>';
10210: if ($default eq 'instcode') {
10211: $datatable .= '<br /><span class="LC_nobreak">('
10212: .&mt('with institutional codes').')</span>';
10213: }
10214: $datatable .= '</td>'
10215: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10216: .&mt('Display').'</label> '
10217: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10218: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10219: }
10220: }
10221: }
1.57 raeburn 10222: } else {
10223: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10224: }
10225: } else {
1.160.6.87 raeburn 10226: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10227: .&initialize_categories($itemcount);
1.48 raeburn 10228: }
1.57 raeburn 10229: $$rowtotal += $itemcount;
1.48 raeburn 10230: }
10231: return $datatable;
10232: }
10233:
1.69 raeburn 10234: sub print_serverstatuses {
10235: my ($dom,$settings,$rowtotal) = @_;
10236: my $datatable;
10237: my @pages = &serverstatus_pages();
10238: my (%namedaccess,%machineaccess);
10239: foreach my $type (@pages) {
10240: $namedaccess{$type} = '';
10241: $machineaccess{$type}= '';
10242: }
10243: if (ref($settings) eq 'HASH') {
10244: foreach my $type (@pages) {
10245: if (exists($settings->{$type})) {
10246: if (ref($settings->{$type}) eq 'HASH') {
10247: foreach my $key (keys(%{$settings->{$type}})) {
10248: if ($key eq 'namedusers') {
10249: $namedaccess{$type} = $settings->{$type}->{$key};
10250: } elsif ($key eq 'machines') {
10251: $machineaccess{$type} = $settings->{$type}->{$key};
10252: }
10253: }
10254: }
10255: }
10256: }
10257: }
1.81 raeburn 10258: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10259: my $rownum = 0;
10260: my $css_class;
10261: foreach my $type (@pages) {
10262: $rownum ++;
10263: $css_class = $rownum%2?' class="LC_odd_row"':'';
10264: $datatable .= '<tr'.$css_class.'>'.
10265: '<td><span class="LC_nobreak">'.
10266: $titles->{$type}.'</span></td>'.
10267: '<td class="LC_left_item">'.
10268: '<input type="text" name="'.$type.'_namedusers" '.
10269: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10270: '<td class="LC_right_item">'.
10271: '<span class="LC_nobreak">'.
10272: '<input type="text" name="'.$type.'_machines" '.
10273: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 10274: '</span></td></tr>'."\n";
1.69 raeburn 10275: }
10276: $$rowtotal += $rownum;
10277: return $datatable;
10278: }
10279:
10280: sub serverstatus_pages {
10281: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 10282: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 10283: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 10284: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10285: }
10286:
1.160.6.40 raeburn 10287: sub defaults_javascript {
10288: my ($settings) = @_;
1.160.6.98 raeburn 10289: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 10290:23): my $portal_js = <<"ENDPORTAL";
10291:23):
10292:23): function portalExtras(caller) {
10293:23): var x = caller.value;
10294:23): var y = new Array('email','web');
10295:23): for (var i=0; i<y.length; i++) {
10296:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
10297:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
10298:23): if (x.length > 0) {
10299:23): z.style.display = 'block';
10300:23): } else {
10301:23): z.style.display = 'none';
10302:23): }
10303:23): }
10304:23): }
10305:23): }
10306:23): ENDPORTAL
1.160.6.40 raeburn 10307: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10308: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10309: if ($maxnum eq '') {
10310: $maxnum = 0;
10311: }
10312: $maxnum ++;
1.160.6.51 raeburn 10313: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 10314: return <<"ENDSCRIPT";
10315: <script type="text/javascript">
10316: // <![CDATA[
10317: function reorderTypes(form,caller) {
10318: var changedVal;
10319: $jstext
10320: var newpos = 'addinststatus_pos';
10321: var current = new Array;
10322: var maxh = $maxnum;
10323: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10324: var oldVal;
10325: if (caller == newpos) {
10326: changedVal = newitemVal;
10327: } else {
10328: var curritem = 'inststatus_pos_'+caller;
10329: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10330: current[newitemVal] = newpos;
10331: }
10332: for (var i=0; i<inststatuses.length; i++) {
10333: if (inststatuses[i] != caller) {
10334: var elementName = 'inststatus_pos_'+inststatuses[i];
10335: if (form.elements[elementName]) {
10336: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10337: current[currVal] = elementName;
10338: }
10339: }
10340: }
10341: for (var j=0; j<maxh; j++) {
10342: if (current[j] == undefined) {
10343: oldVal = j;
10344: }
10345: }
10346: if (oldVal < changedVal) {
10347: for (var k=oldVal+1; k<=changedVal ; k++) {
10348: var elementName = current[k];
10349: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10350: }
10351: } else {
10352: for (var k=changedVal; k<oldVal; k++) {
10353: var elementName = current[k];
10354: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10355: }
10356: }
10357: return;
10358: }
10359:
1.160.6.118.2 12(raebu 10360:23): $portal_js
10361:23):
10362:23): // ]]>
10363:23): </script>
10364:23):
10365:23): ENDSCRIPT
10366:23): } else {
10367:23): return <<"ENDSCRIPT";
10368:23): <script type="text/javascript">
10369:23): // <![CDATA[
10370:23): $portal_js
1.160.6.40 raeburn 10371: // ]]>
10372: </script>
10373:
10374: ENDSCRIPT
10375: }
1.160.6.118.2 14(raebu 10376:23): return;
1.160.6.40 raeburn 10377: }
10378:
1.160.6.98 raeburn 10379: sub passwords_javascript {
1.160.6.118.2 5(raebur 10380:2): my ($prefix) = @_;
10381:2): my %intalert;
10382:2): if ($prefix eq 'passwords') {
10383:2): %intalert = &Apache::lonlocal::texthash (
10384: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.',
10385:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10386:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10387:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10388:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10389:2): );
14(raebu 10390:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 10391:2): %intalert = &Apache::lonlocal::texthash (
10392:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10393:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10394:2): );
10395:2): }
1.160.6.99 raeburn 10396: &js_escape(\%intalert);
10397: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 10398:2): my $intauthjs;
10399:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 10400:
10401: function warnIntAuth(field) {
10402: if (field.name == 'intauth_check') {
10403: if (field.value == '2') {
1.160.6.99 raeburn 10404: alert('$intalert{authcheck}');
1.160.6.98 raeburn 10405: }
10406: }
10407: if (field.name == 'intauth_cost') {
10408: field.value.replace(/\s/g,'');
10409: if (field.value != '') {
10410: var regexdigit=/^\\d+\$/;
10411: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 10412: alert('$intalert{authcost}');
10413: }
10414: }
10415: }
10416: return;
10417: }
10418:
1.160.6.118.2 5(raebur 10419:2): ENDSCRIPT
10420:2):
10421:2): }
10422:2):
10423:2): $intauthjs .= <<"ENDSCRIPT";
10424:2):
10425:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 10426: field.value.replace(/^\s+/,'');
10427: field.value.replace(/\s+\$/,'');
10428: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 10429:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 10430: if (field.value == '') {
10431: alert('$intalert{passmin}');
10432: field.value = '$defmin';
10433: } else {
10434: if (!regexdigit.test(field.value)) {
10435: alert('$intalert{passmin}');
10436: field.value = '$defmin';
10437: }
10438: var minval = parseInt(field.value,10);
10439: if (minval < $defmin) {
10440: alert('$intalert{passmin}');
10441: field.value = '$defmin';
10442: }
10443: }
10444: } else {
10445: if (field.value == '0') {
10446: field.value = '';
10447: }
10448: if (field.value != '') {
1.160.6.118.2 5(raebur 10449:2): if (!regexdigit.test(field.value)) {
10450:2): if (field.name == '${prefix}_max') {
10451:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 10452: } else {
1.160.6.118.2 5(raebur 10453:2): if (field.name == '${prefix}_numsaved') {
10454:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 10455: }
10456: }
1.160.6.118.2 5(raebur 10457:2): field.value = '';
1.160.6.98 raeburn 10458: }
10459: }
10460: }
10461: return;
10462: }
10463:
10464: ENDSCRIPT
10465: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10466: }
10467:
1.49 raeburn 10468: sub coursecategories_javascript {
10469: my ($settings) = @_;
1.57 raeburn 10470: my ($output,$jstext,$cathash);
1.49 raeburn 10471: if (ref($settings) eq 'HASH') {
1.57 raeburn 10472: $cathash = $settings->{'cats'};
10473: }
10474: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10475: my (@cats,@jsarray,%idx);
1.57 raeburn 10476: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10477: if (@jsarray > 0) {
10478: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10479: for (my $i=0; $i<@jsarray; $i++) {
10480: if (ref($jsarray[$i]) eq 'ARRAY') {
10481: my $catstr = join('","',@{$jsarray[$i]});
10482: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10483: }
10484: }
10485: }
10486: } else {
10487: $jstext = ' var categories = Array(1);'."\n".
10488: ' categories[0] = Array("instcode_pos");'."\n";
10489: }
1.160.6.42 raeburn 10490: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10491: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 10492: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10493: &js_escape(\$instcode_reserved);
10494: &js_escape(\$communities_reserved);
10495: &js_escape(\$choose_again);
1.49 raeburn 10496: $output = <<"ENDSCRIPT";
10497: <script type="text/javascript">
1.109 raeburn 10498: // <![CDATA[
1.49 raeburn 10499: function reorderCats(form,parent,item,idx) {
10500: var changedVal;
10501: $jstext
10502: var newpos = 'addcategory_pos';
10503: if (parent == '') {
10504: var has_instcode = 0;
10505: var maxtop = categories[idx].length;
10506: for (var j=0; j<maxtop; j++) {
10507: if (categories[idx][j] == 'instcode::0') {
10508: has_instcode == 1;
10509: }
10510: }
10511: if (has_instcode == 0) {
10512: categories[idx][maxtop] = 'instcode_pos';
10513: }
10514: } else {
10515: newpos += '_'+parent;
10516: }
10517: var maxh = 1 + categories[idx].length;
10518: var current = new Array;
10519: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10520: if (item == newpos) {
10521: changedVal = newitemVal;
10522: } else {
10523: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10524: current[newitemVal] = newpos;
10525: }
10526: for (var i=0; i<categories[idx].length; i++) {
10527: var elementName = categories[idx][i];
10528: if (elementName != item) {
10529: if (form.elements[elementName]) {
10530: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10531: current[currVal] = elementName;
10532: }
10533: }
10534: }
10535: var oldVal;
10536: for (var j=0; j<maxh; j++) {
10537: if (current[j] == undefined) {
10538: oldVal = j;
10539: }
10540: }
10541: if (oldVal < changedVal) {
10542: for (var k=oldVal+1; k<=changedVal ; k++) {
10543: var elementName = current[k];
10544: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10545: }
10546: } else {
10547: for (var k=changedVal; k<oldVal; k++) {
10548: var elementName = current[k];
10549: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10550: }
10551: }
10552: return;
10553: }
1.120 raeburn 10554:
10555: function categoryCheck(form) {
10556: if (form.elements['addcategory_name'].value == 'instcode') {
10557: alert('$instcode_reserved\\n$choose_again');
10558: return false;
10559: }
10560: if (form.elements['addcategory_name'].value == 'communities') {
10561: alert('$communities_reserved\\n$choose_again');
10562: return false;
10563: }
10564: return true;
10565: }
10566:
1.109 raeburn 10567: // ]]>
1.49 raeburn 10568: </script>
10569:
10570: ENDSCRIPT
10571: return $output;
10572: }
10573:
1.48 raeburn 10574: sub initialize_categories {
10575: my ($itemcount) = @_;
1.120 raeburn 10576: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 10577: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10578: instcode => 'Official courses (with institutional codes)',
10579: communities => 'Communities',
10580: );
10581: my $select0 = ' selected="selected"';
10582: my $select1 = '';
10583: foreach my $default ('instcode','communities') {
10584: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 10585: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 10586: if ($default eq 'communities') {
10587: $select1 = $select0;
10588: $select0 = '';
10589: }
10590: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10591: .'<select name="'.$default.'_pos">'
10592: .'<option value="0"'.$select0.'>1</option>'
10593: .'<option value="1"'.$select1.'>2</option>'
10594: .'<option value="2">3</option></select> '
10595: .$default_names{$default}
10596: .'</span></td><td><span class="LC_nobreak">'
10597: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10598: .&mt('Display').'</label> <label>'
10599: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10600: .'</label></span></td></tr>';
1.120 raeburn 10601: $itemcount ++;
10602: }
1.48 raeburn 10603: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10604: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10605: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10606: .'<select name="addcategory_pos"'.$chgstr.'>'
10607: .'<option value="0">1</option>'
10608: .'<option value="1">2</option>'
10609: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 10610: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 10611: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10612: .'</td></tr>';
1.48 raeburn 10613: return $datatable;
10614: }
10615:
10616: sub build_category_rows {
1.49 raeburn 10617: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10618: my ($text,$name,$item,$chgstr);
1.48 raeburn 10619: if (ref($cats) eq 'ARRAY') {
10620: my $maxdepth = scalar(@{$cats});
10621: if (ref($cats->[$depth]) eq 'HASH') {
10622: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10623: my $numchildren = @{$cats->[$depth]{$parent}};
10624: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 10625: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10626: my ($idxnum,$parent_name,$parent_item);
10627: my $higher = $depth - 1;
10628: if ($higher == 0) {
10629: $parent_name = &escape($parent).'::'.$higher;
10630: } else {
10631: if (ref($path) eq 'ARRAY') {
10632: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10633: }
10634: }
10635: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10636: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10637: if ($j < $numchildren) {
1.48 raeburn 10638: $name = $cats->[$depth]{$parent}[$j];
10639: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10640: $idxnum = $idx->{$item};
10641: } else {
10642: $name = $parent_name;
10643: $item = $parent_item;
1.48 raeburn 10644: }
1.49 raeburn 10645: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10646: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10647: for (my $i=0; $i<=$numchildren; $i++) {
10648: my $vpos = $i+1;
10649: my $selstr;
10650: if ($j == $i) {
10651: $selstr = ' selected="selected" ';
10652: }
10653: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10654: }
10655: $text .= '</select> ';
10656: if ($j < $numchildren) {
10657: my $deeper = $depth+1;
10658: $text .= $name.' '
10659: .'<label><input type="checkbox" name="deletecategory" value="'
10660: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10661: if(ref($path) eq 'ARRAY') {
10662: push(@{$path},$name);
1.49 raeburn 10663: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10664: pop(@{$path});
10665: }
10666: } else {
1.160.6.87 raeburn 10667: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10668: if ($j == $numchildren) {
10669: $text .= $name;
10670: } else {
10671: $text .= $item;
10672: }
10673: $text .= '" value="" />';
10674: }
10675: $text .= '</td></tr>';
10676: }
10677: $text .= '</table></td>';
10678: } else {
10679: my $higher = $depth-1;
10680: if ($higher == 0) {
10681: $name = &escape($parent).'::'.$higher;
10682: } else {
10683: if (ref($path) eq 'ARRAY') {
10684: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10685: }
10686: }
10687: my $colspan;
10688: if ($parent ne 'instcode') {
10689: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 10690: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10691: }
10692: }
10693: }
10694: }
10695: return $text;
10696: }
10697:
1.33 raeburn 10698: sub modifiable_userdata_row {
1.160.6.93 raeburn 10699: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.160.6.118.2 14(raebu 10700:23): $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.160.6.35 raeburn 10701: my ($role,$rolename,$statustype);
10702: $role = $item;
1.160.6.34 raeburn 10703: if ($context eq 'cancreate') {
1.160.6.93 raeburn 10704: if ($item =~ /^(emailusername)_(.+)$/) {
10705: $role = $1;
10706: $statustype = $2;
1.160.6.35 raeburn 10707: if (ref($usertypes) eq 'HASH') {
10708: if ($usertypes->{$statustype}) {
10709: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10710: } else {
10711: $rolename = &mt('Data provided by user');
10712: }
10713: }
1.160.6.34 raeburn 10714: }
10715: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10716: if (ref($usertypes) eq 'HASH') {
10717: $rolename = $usertypes->{$role};
10718: } else {
10719: $rolename = $role;
10720: }
1.160.6.118.2 14(raebu 10721:23): } elsif ($context eq 'lti') {
10722:23): $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 10723: } else {
1.63 raeburn 10724: if ($role eq 'cr') {
10725: $rolename = &mt('Custom role');
10726: } else {
10727: $rolename = &Apache::lonnet::plaintext($role);
10728: }
1.33 raeburn 10729: }
1.160.6.34 raeburn 10730: my (@fields,%fieldtitles);
10731: if (ref($fieldsref) eq 'ARRAY') {
10732: @fields = @{$fieldsref};
10733: } else {
10734: @fields = ('lastname','firstname','middlename','generation',
10735: 'permanentemail','id');
10736: }
10737: if ((ref($titlesref) eq 'HASH')) {
10738: %fieldtitles = %{$titlesref};
10739: } else {
10740: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10741: }
1.33 raeburn 10742: my $output;
1.160.6.93 raeburn 10743: my $css_class;
10744: if ($rowcount%2) {
10745: $css_class = 'LC_odd_row';
10746: }
10747: if ($customcss) {
10748: $css_class .= " $customcss";
10749: }
10750: $css_class =~ s/^\s+//;
10751: if ($css_class) {
10752: $css_class = ' class="'.$css_class.'"';
10753: }
10754: if ($rowstyle) {
10755: $css_class .= ' style="'.$rowstyle.'"';
10756: }
10757: if ($rowid) {
10758: $rowid = ' id="'.$rowid.'"';
10759: }
10760: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10761: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10762: '<td class="LC_left_item" colspan="2"><table>';
10763: my $rem;
10764: my %checks;
10765: if (ref($settings) eq 'HASH') {
1.160.6.118.2 14(raebu 10766:23): my $hashref;
10767:23): if ($context eq 'lti') {
10768:23): if (ref($settings) eq 'HASH') {
10769:23): $hashref = $settings->{'instdata'};
10770:23): }
10771:23): } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10772: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.118.2 14(raebu 10773:23): $hashref = $settings->{'lti_instdata'};
10774:23): }
10775:23): if ($role eq 'emailusername') {
10776:23): if ($statustype) {
10777:23): if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10778:23): $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.35 raeburn 10779: }
1.160.6.118.2 14(raebu 10780:23): }
10781:23): }
10782:23): }
10783:23): if (ref($hashref) eq 'HASH') {
10784:23): foreach my $field (@fields) {
10785:23): if ($hashref->{$field}) {
10786:23): if ($role eq 'emailusername') {
10787:23): $checks{$field} = $hashref->{$field};
10788:23): } else {
10789:23): $checks{$field} = ' checked="checked" ';
1.33 raeburn 10790: }
10791: }
10792: }
10793: }
10794: }
1.160.6.93 raeburn 10795: my $total = scalar(@fields);
10796: for (my $i=0; $i<$total; $i++) {
10797: $rem = $i%($numinrow);
1.33 raeburn 10798: if ($rem == 0) {
10799: if ($i > 0) {
10800: $output .= '</tr>';
10801: }
10802: $output .= '<tr>';
10803: }
10804: my $check = ' ';
1.160.6.35 raeburn 10805: unless ($role eq 'emailusername') {
10806: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 10807: $check = $checks{$fields[$i]};
1.160.6.118.2 14(raebu 10808:23): } elsif ($context ne 'lti') {
1.160.6.35 raeburn 10809: if ($role eq 'st') {
10810: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 10811: $check = ' checked="checked" ';
1.160.6.35 raeburn 10812: }
1.33 raeburn 10813: }
10814: }
10815: }
10816: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 10817: '<span class="LC_nobreak">';
1.160.6.118.2 14(raebu 10818:23): my $prefix = 'canmodify';
1.160.6.35 raeburn 10819: if ($role eq 'emailusername') {
10820: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10821: $checks{$fields[$i]} = 'omit';
10822: }
10823: foreach my $option ('required','optional','omit') {
10824: my $checked='';
10825: if ($checks{$fields[$i]} eq $option) {
10826: $checked='checked="checked" ';
10827: }
10828: $output .= '<label>'.
1.160.6.118.2 14(raebu 10829:23): '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.160.6.35 raeburn 10830: &mt($option).'</label>'.(' ' x2);
10831: }
10832: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10833: } else {
1.160.6.118.2 14(raebu 10834:23): if ($context eq 'lti') {
10835:23): $prefix = 'lti';
25(raebu 10836:24): } elsif ($context eq 'coauthor') {
10837:24): $prefix = 'cacanmodify';
14(raebu 10838:23): }
1.160.6.35 raeburn 10839: $output .= '<label>'.
1.160.6.118.2 14(raebu 10840:23): '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.160.6.35 raeburn 10841: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10842: '</label>';
10843: }
10844: $output .= '</span></td>';
1.33 raeburn 10845: }
1.160.6.93 raeburn 10846: $rem = $total%$numinrow;
10847: my $colsleft;
10848: if ($rem) {
10849: $colsleft = $numinrow - $rem;
10850: }
10851: if ($colsleft > 1) {
1.33 raeburn 10852: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10853: ' </td>';
10854: } elsif ($colsleft == 1) {
10855: $output .= '<td class="LC_left_item"> </td>';
10856: }
10857: $output .= '</tr></table></td></tr>';
10858: return $output;
10859: }
1.28 raeburn 10860:
1.93 raeburn 10861: sub insttypes_row {
1.160.6.93 raeburn 10862: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10863: $customcss,$rowstyle) = @_;
1.93 raeburn 10864: my %lt = &Apache::lonlocal::texthash (
1.160.6.118.2 20(raebu 10865:24): cansearch => 'Users allowed to search',
1.93 raeburn 10866: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.160.6.118.2 20(raebu 10867:24): lockablenames => 'User preference to lock name',
10868:24): selfassign => 'Self-reportable affiliations',
10869:24): overrides => "Override domain's helpdesk settings based on requester's affiliation",
10870:24): webdav => 'WebDAV access available',
10871:24): authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 10872: );
1.160.6.118.2 20(raebu 10873:24): my ($showdom,$defaultquota);
1.93 raeburn 10874: if ($context eq 'cansearch') {
10875: $showdom = ' ('.$dom.')';
1.160.6.118.2 20(raebu 10876:24): } elsif ($context eq 'authorquota') {
10877:24): $defaultquota = 500;
1.93 raeburn 10878: }
1.160.6.5 raeburn 10879: my $class = 'LC_left_item';
10880: if ($context eq 'statustocreate') {
10881: $class = 'LC_right_item';
10882: }
1.160.6.93 raeburn 10883: my $css_class;
10884: if ($$rowtotal%2) {
10885: $css_class = 'LC_odd_row';
10886: }
10887: if ($customcss) {
10888: $css_class .= ' '.$customcss;
10889: }
10890: $css_class =~ s/^\s+//;
10891: if ($css_class) {
10892: $css_class = ' class="'.$css_class.'"';
10893: }
10894: if ($rowstyle) {
10895: $css_class .= ' style="'.$rowstyle.'"';
10896: }
10897: if ($onclick) {
10898: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 10899: }
10900: my $output = '<tr'.$css_class.'>'.
10901: '<td>'.$lt{$context}.$showdom.
10902: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10903: my $rem;
10904: if (ref($types) eq 'ARRAY') {
10905: for (my $i=0; $i<@{$types}; $i++) {
10906: if (defined($usertypes->{$types->[$i]})) {
10907: my $rem = $i%($numinrow);
10908: if ($rem == 0) {
10909: if ($i > 0) {
10910: $output .= '</tr>';
10911: }
10912: $output .= '<tr>';
1.23 raeburn 10913: }
1.160.6.118.2 20(raebu 10914:24): if ($context eq 'authorquota') {
10915:24): my $currquota;
10916:24): if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
10917:24): $currquota = $settings->{$context}->{$types->[$i]};
10918:24): } else {
10919:24): $currquota = $defaultquota;
10920:24): }
10921:24): $output .= '<td class="LC_left_item">'."\n".
10922:24): '<label><span class="LC_nobreak">'."\n".
10923:24): $usertypes->{$types->[$i]}.'</span><br />'."\n".
10924:24): '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
10925:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
10926:24): '</label></td>';
10927:24): } else {
10928:24): my $check = ' ';
10929:24): if (ref($settings) eq 'HASH') {
10930:24): if (ref($settings->{$context}) eq 'ARRAY') {
10931:24): if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10932:24): $check = ' checked="checked" ';
10933:24): }
10934:24): } elsif (ref($settings->{$context}) eq 'HASH') {
10935:24): if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10936:24): $check = ' checked="checked" ';
10937:24): } elsif ($context eq 'webdav') {
10938:24): if ($settings->{$context}->{$types->[$i]}) {
10939:24): $check = ' checked="checked" ';
10940:24): }
10941:24): }
10942:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 10943: $check = ' checked="checked" ';
10944: }
1.26 raeburn 10945: }
1.160.6.118.2 20(raebu 10946:24): $output .= '<td class="LC_left_item">'.
10947:24): '<span class="LC_nobreak"><label>'.
10948:24): '<input type="checkbox" name="'.$context.'" '.
10949:24): 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
10950:24): $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10951: }
10952: }
10953: }
1.26 raeburn 10954: $rem = @{$types}%($numinrow);
1.23 raeburn 10955: }
10956: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 10957: if ($context eq 'overrides') {
10958: if ($colsleft > 1) {
10959: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10960: } else {
10961: $output .= '<td class="LC_left_item">';
10962: }
10963: $output .= ' ';
1.23 raeburn 10964: } else {
1.160.6.101 raeburn 10965: if ($rem == 0) {
10966: $output .= '<tr>';
10967: }
10968: if ($colsleft > 1) {
10969: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
10970: } else {
10971: $output .= '<td class="LC_left_item">';
10972: }
1.160.6.118.2 20(raebu 10973:24): if ($context eq 'authorquota') {
10974:24): my $currquota = 500;
10975:24): if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
10976:24): if ($settings->{$context}{'default'} =~ /^\d+$/) {
10977:24): $currquota = $settings->{$context}{'default'};
10978:24): }
10979:24): }
10980:24): $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
10981:24): '<input type="text" name="'.$context.'_default" '.
10982:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
10983:24): '</label>';
10984:24): } else {
10985:24): my $defcheck = ' ';
10986:24): if (ref($settings) eq 'HASH') {
10987:24): if (ref($settings->{$context}) eq 'ARRAY') {
10988:24): if (grep(/^default$/,@{$settings->{$context}})) {
10989:24): $defcheck = ' checked="checked" ';
10990:24): }
10991:24): } elsif (ref($settings->{$context}) eq 'HASH') {
10992:24): if (ref($settings->{$context}->{'default'}) eq 'HASH') {
10993:24): $defcheck = ' checked="checked" ';
10994:24): } elsif ($context eq 'webdav') {
10995:24): if ($settings->{$context}->{'default'}) {
10996:24): $defcheck = ' checked="checked" ';
10997:24): }
10998:24): }
10999:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 11000: $defcheck = ' checked="checked" ';
11001: }
1.99 raeburn 11002: }
1.160.6.118.2 20(raebu 11003:24): $output .= '<span class="LC_nobreak"><label>'.
11004:24): '<input type="checkbox" name="'.$context.'" '.
11005:24): 'value="default"'.$defcheck.$onclick.'/>'.
11006:24): $othertitle.'</label></span>';
1.26 raeburn 11007: }
1.23 raeburn 11008: }
1.160.6.101 raeburn 11009: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11010: return $output;
1.23 raeburn 11011: }
11012:
11013: sub sorted_searchtitles {
11014: my %searchtitles = &Apache::lonlocal::texthash(
11015: 'uname' => 'username',
11016: 'lastname' => 'last name',
11017: 'lastfirst' => 'last name, first name',
11018: );
11019: my @titleorder = ('uname','lastname','lastfirst');
11020: return (\%searchtitles,\@titleorder);
11021: }
11022:
1.25 raeburn 11023: sub sorted_searchtypes {
11024: my %srchtypes_desc = (
11025: exact => 'is exact match',
11026: contains => 'contains ..',
11027: begins => 'begins with ..',
11028: );
11029: my @srchtypeorder = ('exact','begins','contains');
11030: return (\%srchtypes_desc,\@srchtypeorder);
11031: }
11032:
1.3 raeburn 11033: sub usertype_update_row {
11034: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11035: my $datatable;
11036: my $numinrow = 4;
11037: foreach my $type (@{$types}) {
11038: if (defined($usertypes->{$type})) {
11039: $$rownums ++;
11040: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11041: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11042: '</td><td class="LC_left_item"><table>';
11043: for (my $i=0; $i<@{$fields}; $i++) {
11044: my $rem = $i%($numinrow);
11045: if ($rem == 0) {
11046: if ($i > 0) {
11047: $datatable .= '</tr>';
11048: }
11049: $datatable .= '<tr>';
11050: }
11051: my $check = ' ';
1.39 raeburn 11052: if (ref($settings) eq 'HASH') {
11053: if (ref($settings->{'fields'}) eq 'HASH') {
11054: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11055: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11056: $check = ' checked="checked" ';
11057: }
1.3 raeburn 11058: }
11059: }
11060: }
11061:
11062: if ($i == @{$fields}-1) {
11063: my $colsleft = $numinrow - $rem;
11064: if ($colsleft > 1) {
11065: $datatable .= '<td colspan="'.$colsleft.'">';
11066: } else {
11067: $datatable .= '<td>';
11068: }
11069: } else {
11070: $datatable .= '<td>';
11071: }
1.8 raeburn 11072: $datatable .= '<span class="LC_nobreak"><label>'.
11073: '<input type="checkbox" name="updateable_'.$type.
11074: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11075: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11076: }
11077: $datatable .= '</tr></table></td></tr>';
11078: }
11079: }
11080: return $datatable;
1.1 raeburn 11081: }
11082:
11083: sub modify_login {
1.160.6.24 raeburn 11084: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11085: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 11086: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 11087:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 11088: %title = ( coursecatalog => 'Display course catalog',
11089: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 11090: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 11091: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 11092: loginheader => 'Log-in box header',
11093: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 11094: @offon = ('off','on');
1.112 raeburn 11095: if (ref($domconfig{login}) eq 'HASH') {
11096: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11097: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11098: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11099: }
11100: }
1.160.6.113 raeburn 11101: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11102: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11103: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11104: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11105: $saml{$lonhost} = 1;
11106: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11107: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11108: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11109: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11110: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 11111:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 11112: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11113: }
11114: }
11115: }
1.112 raeburn 11116: }
1.9 raeburn 11117: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11118: \%domconfig,\%loginhash);
1.160.6.14 raeburn 11119: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11120: foreach my $item (@toggles) {
11121: $loginhash{login}{$item} = $env{'form.'.$item};
11122: }
1.41 raeburn 11123: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11124: if (ref($colchanges{'login'}) eq 'HASH') {
11125: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11126: \%loginhash);
11127: }
1.110 raeburn 11128:
1.149 raeburn 11129: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 11130: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11131: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11132: if (keys(%servers) > 1) {
11133: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11134: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11135: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11136: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11137: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11138: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11139: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11140: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11141: $changes{'loginvia'}{$lonhost} = 1;
11142: } else {
11143: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11144: $changes{'loginvia'}{$lonhost} = 1;
11145: }
11146: } else {
11147: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11148: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11149: $changes{'loginvia'}{$lonhost} = 1;
11150: }
11151: }
11152: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11153: foreach my $item (@loginvia_attribs) {
11154: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11155: }
11156: } else {
11157: foreach my $item (@loginvia_attribs) {
11158: my $new = $env{'form.'.$lonhost.'_'.$item};
11159: if (($item eq 'serverpath') && ($new eq 'custom')) {
11160: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11161: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11162: $new = '/';
11163: }
11164: }
11165: if (($item eq 'custompath') &&
11166: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11167: $new = '';
11168: }
11169: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11170: $changes{'loginvia'}{$lonhost} = 1;
11171: }
11172: if ($item eq 'exempt') {
1.160.6.56 raeburn 11173: $new = &check_exempt_addresses($new);
1.128 raeburn 11174: }
11175: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11176: }
11177: }
1.112 raeburn 11178: } else {
1.128 raeburn 11179: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11180: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11181: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11182: foreach my $item (@loginvia_attribs) {
11183: my $new = $env{'form.'.$lonhost.'_'.$item};
11184: if (($item eq 'serverpath') && ($new eq 'custom')) {
11185: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11186: $new = '/';
11187: }
11188: }
11189: if (($item eq 'custompath') &&
11190: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11191: $new = '';
11192: }
11193: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11194: }
1.110 raeburn 11195: }
11196: }
11197: }
11198: }
1.119 raeburn 11199:
1.160.6.5 raeburn 11200: my $servadm = $r->dir_config('lonAdmEMail');
11201: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11202: if (ref($domconfig{'login'}) eq 'HASH') {
11203: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11204: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11205: if ($lang eq 'nolang') {
11206: push(@currlangs,$lang);
11207: } elsif (defined($langchoices{$lang})) {
11208: push(@currlangs,$lang);
11209: } else {
11210: next;
11211: }
11212: }
11213: }
11214: }
11215: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11216: if (@currlangs > 0) {
11217: foreach my $lang (@currlangs) {
11218: if (grep(/^\Q$lang\E$/,@delurls)) {
11219: $changes{'helpurl'}{$lang} = 1;
11220: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11221: $changes{'helpurl'}{$lang} = 1;
11222: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11223: push(@newlangs,$lang);
11224: } else {
11225: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11226: }
11227: }
11228: }
11229: unless (grep(/^nolang$/,@currlangs)) {
11230: if ($env{'form.loginhelpurl_nolang.filename'}) {
11231: $changes{'helpurl'}{'nolang'} = 1;
11232: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11233: push(@newlangs,'nolang');
11234: }
11235: }
11236: if ($env{'form.loginhelpurl_add_lang'}) {
11237: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11238: ($env{'form.loginhelpurl_add_file.filename'})) {
11239: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11240: $addedfile = $env{'form.loginhelpurl_add_lang'};
11241: }
11242: }
11243: if ((@newlangs > 0) || ($addedfile)) {
11244: my $error;
11245: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11246: if ($configuserok eq 'ok') {
11247: if ($switchserver) {
11248: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11249: } elsif ($author_ok eq 'ok') {
11250: my @allnew = @newlangs;
11251: if ($addedfile ne '') {
11252: push(@allnew,$addedfile);
11253: }
1.160.6.118.2 14(raebu 11254:23): my $modified = [];
1.160.6.5 raeburn 11255: foreach my $lang (@allnew) {
11256: my $formelem = 'loginhelpurl_'.$lang;
11257: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11258: $formelem = 'loginhelpurl_add_file';
11259: }
1.160.6.118.2 14(raebu 11260:23): (my $result,$newurl{$lang}) =
11261:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11262:23): "help/$lang",'','',$newfile{$lang},
11263:23): $modified);
1.160.6.5 raeburn 11264: if ($result eq 'ok') {
11265: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11266: $changes{'helpurl'}{$lang} = 1;
11267: } else {
11268: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11269: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11270: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
11271: (!grep(/^\Q$lang\E$/,@delurls))) {
11272: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11273: }
11274: }
11275: }
1.160.6.118.2 14(raebu 11276:23): &update_modify_urls($r,$modified);
1.160.6.5 raeburn 11277: } else {
11278: $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);
11279: }
11280: } else {
11281: $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);
11282: }
11283: if ($error) {
11284: &Apache::lonnet::logthis($error);
11285: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11286: }
11287: }
1.160.6.56 raeburn 11288:
11289: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11290: if (ref($domconfig{'login'}) eq 'HASH') {
11291: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11292: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11293: if ($domservers{$lonhost}) {
11294: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11295: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 11296: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 11297: }
11298: }
11299: }
11300: }
11301: }
11302: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11303: foreach my $lonhost (sort(keys(%domservers))) {
11304: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11305: $changes{'headtag'}{$lonhost} = 1;
11306: } else {
11307: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11308: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11309: }
11310: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11311: push(@newhosts,$lonhost);
11312: } elsif ($currheadtagurls{$lonhost}) {
11313: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11314: if ($currexempt{$lonhost}) {
11315: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
11316: $changes{'headtag'}{$lonhost} = 1;
11317: }
11318: } elsif ($possexempt{$lonhost}) {
11319: $changes{'headtag'}{$lonhost} = 1;
11320: }
11321: if ($possexempt{$lonhost}) {
11322: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11323: }
11324: }
11325: }
11326: }
11327: if (@newhosts) {
11328: my $error;
11329: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11330: if ($configuserok eq 'ok') {
11331: if ($switchserver) {
11332: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11333: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11334:23): my $modified = [];
1.160.6.56 raeburn 11335: foreach my $lonhost (@newhosts) {
11336: my $formelem = 'loginheadtag_'.$lonhost;
1.160.6.118.2 14(raebu 11337:23): (my $result,$newheadtagurls{$lonhost}) =
11338:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11339:23): "login/headtag/$lonhost",'','',
11340:23): $env{'form.loginheadtag_'.$lonhost.'.filename'},
11341:23): $modified);
1.160.6.56 raeburn 11342: if ($result eq 'ok') {
1.160.6.113 raeburn 11343: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11344: $changes{'headtag'}{$lonhost} = 1;
11345: if ($possexempt{$lonhost}) {
11346: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11347: }
11348: } else {
11349: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11350: $newheadtagurls{$lonhost},$result);
11351: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11352: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11353: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11354: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11355: }
11356: }
11357: }
1.160.6.118.2 14(raebu 11358:23): &update_modify_urls($r,$modified);
1.160.6.113 raeburn 11359: } else {
11360: $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);
11361: }
11362: } else {
11363: $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);
11364: }
11365: if ($error) {
11366: &Apache::lonnet::logthis($error);
11367: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11368: }
11369: }
11370: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11371: my @newsamlimgs;
11372: foreach my $lonhost (keys(%domservers)) {
11373: if ($env{'form.saml_'.$lonhost}) {
11374: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11375: push(@newsamlimgs,$lonhost);
11376: }
1.160.6.118.2 9(raebur 11377:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11378: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11379: }
11380: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 11381:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
11382:2): $env{'form.saml_window_'.$lonhost} = '';
11383:2): }
1.160.6.113 raeburn 11384: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11385: #FIXME Need to obsolete published image
11386: delete($currsaml{$lonhost}{'img'});
11387: $changes{'saml'}{$lonhost} = 1;
11388: }
11389: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11390: $changes{'saml'}{$lonhost} = 1;
11391: }
11392: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11393: $changes{'saml'}{$lonhost} = 1;
11394: }
11395: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11396: $changes{'saml'}{$lonhost} = 1;
11397: }
11398: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11399: $changes{'saml'}{$lonhost} = 1;
11400: }
1.160.6.118.2 9(raebur 11401:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11402:2): $changes{'saml'}{$lonhost} = 1;
11403:2): }
1.160.6.113 raeburn 11404: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11405: $changes{'saml'}{$lonhost} = 1;
11406: }
11407: } else {
11408: $changes{'saml'}{$lonhost} = 1;
11409: }
1.160.6.118.2 9(raebur 11410:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11411: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11412: }
11413: } else {
11414: if ($saml{$lonhost}) {
11415: $changes{'saml'}{$lonhost} = 1;
11416: delete($currsaml{$lonhost});
11417: }
11418: }
11419: }
11420: foreach my $posshost (keys(%currsaml)) {
11421: unless (exists($domservers{$posshost})) {
11422: delete($currsaml{$posshost});
11423: }
11424: }
11425: %{$loginhash{'login'}{'saml'}} = %currsaml;
11426: if (@newsamlimgs) {
11427: my $error;
11428: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11429: if ($configuserok eq 'ok') {
11430: if ($switchserver) {
11431: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11432: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11433:23): my $modified = [];
1.160.6.113 raeburn 11434: foreach my $lonhost (@newsamlimgs) {
11435: my $formelem = 'saml_img_'.$lonhost;
1.160.6.118.2 14(raebu 11436:23): my ($result,$imgurl) =
11437:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11438:23): "login/saml/$lonhost",'','',
11439:23): $env{'form.saml_img_'.$lonhost.'.filename'},
11440:23): $modified);
1.160.6.113 raeburn 11441: if ($result eq 'ok') {
11442: $currsaml{$lonhost}{'img'} = $imgurl;
11443: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11444: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 11445: } else {
1.160.6.113 raeburn 11446: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11447: $lonhost,$result);
1.160.6.56 raeburn 11448: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11449: }
11450: }
1.160.6.118.2 14(raebu 11451:23): &update_modify_urls($r,$modified);
1.160.6.56 raeburn 11452: } else {
1.160.6.113 raeburn 11453: $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 11454: }
11455: } else {
1.160.6.113 raeburn 11456: $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 11457: }
11458: if ($error) {
11459: &Apache::lonnet::logthis($error);
11460: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11461: }
11462: }
1.160.6.5 raeburn 11463: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11464:
11465: my $defaulthelpfile = '/adm/loginproblems.html';
11466: my $defaulttext = &mt('Default in use');
11467:
1.1 raeburn 11468: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11469: $dom);
11470: if ($putresult eq 'ok') {
1.160.6.14 raeburn 11471: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11472: my %defaultchecked = (
11473: 'coursecatalog' => 'on',
1.160.6.14 raeburn 11474: 'helpdesk' => 'on',
1.42 raeburn 11475: 'adminmail' => 'off',
1.43 raeburn 11476: 'newuser' => 'off',
1.42 raeburn 11477: );
1.55 raeburn 11478: if (ref($domconfig{'login'}) eq 'HASH') {
11479: foreach my $item (@toggles) {
11480: if ($defaultchecked{$item} eq 'on') {
11481: if (($domconfig{'login'}{$item} eq '0') &&
11482: ($env{'form.'.$item} eq '1')) {
11483: $changes{$item} = 1;
11484: } elsif (($domconfig{'login'}{$item} eq '' ||
11485: $domconfig{'login'}{$item} eq '1') &&
11486: ($env{'form.'.$item} eq '0')) {
11487: $changes{$item} = 1;
11488: }
11489: } elsif ($defaultchecked{$item} eq 'off') {
11490: if (($domconfig{'login'}{$item} eq '1') &&
11491: ($env{'form.'.$item} eq '0')) {
11492: $changes{$item} = 1;
11493: } elsif (($domconfig{'login'}{$item} eq '' ||
11494: $domconfig{'login'}{$item} eq '0') &&
11495: ($env{'form.'.$item} eq '1')) {
11496: $changes{$item} = 1;
11497: }
1.42 raeburn 11498: }
11499: }
1.41 raeburn 11500: }
1.6 raeburn 11501: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11502: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 11503: if (exists($changes{'saml'})) {
11504: my $hostid_in_use;
11505: my @hosts = &Apache::lonnet::current_machine_ids();
11506: if (@hosts > 1) {
11507: foreach my $hostid (@hosts) {
11508: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11509: $hostid_in_use = $hostid;
11510: last;
11511: }
11512: }
11513: } else {
11514: $hostid_in_use = $r->dir_config('lonHostID');
11515: }
11516: if (($hostid_in_use) &&
11517: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11518: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11519: }
11520: if (ref($lastactref) eq 'HASH') {
11521: if (ref($changes{'saml'}) eq 'HASH') {
11522: my %updates;
11523: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11524: $lastactref->{'samllanding'} = \%updates;
11525: }
11526: }
11527: }
1.160.6.27 raeburn 11528: if (ref($lastactref) eq 'HASH') {
11529: $lastactref->{'domainconfig'} = 1;
11530: }
1.1 raeburn 11531: $resulttext = &mt('Changes made:').'<ul>';
11532: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11533: if ($item eq 'loginvia') {
1.112 raeburn 11534: if (ref($changes{$item}) eq 'HASH') {
11535: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11536: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11537: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11538: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11539: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11540: $protocol = 'http' if ($protocol ne 'https');
11541: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11542:
11543: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11544: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11545: } else {
11546: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11547: }
11548: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11549: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11550: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11551: }
11552: $resulttext .= '</li>';
11553: } else {
11554: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11555: }
1.112 raeburn 11556: } else {
1.128 raeburn 11557: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11558: }
11559: }
1.128 raeburn 11560: $resulttext .= '</ul></li>';
1.112 raeburn 11561: }
1.160.6.5 raeburn 11562: } elsif ($item eq 'helpurl') {
11563: if (ref($changes{$item}) eq 'HASH') {
11564: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11565: if (grep(/^\Q$lang\E$/,@delurls)) {
11566: my ($chg,$link);
11567: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11568: if ($lang eq 'nolang') {
11569: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11570: } else {
11571: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11572: }
11573: $resulttext .= '<li>'.$chg.'</li>';
11574: } else {
11575: my $chg;
11576: if ($lang eq 'nolang') {
11577: $chg = &mt('custom log-in help file for no preferred language');
11578: } else {
11579: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11580: }
11581: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11582: $loginhash{'login'}{'helpurl'}{$lang}.
11583: '?inhibitmenu=yes',$chg,600,500).
11584: '</li>';
11585: }
11586: }
11587: }
1.160.6.56 raeburn 11588: } elsif ($item eq 'headtag') {
11589: if (ref($changes{$item}) eq 'HASH') {
11590: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11591: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11592: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11593: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11594: $resulttext .= '<li><a href="'.
11595: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11596: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11597: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11598: if ($possexempt{$lonhost}) {
11599: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11600: } else {
11601: $resulttext .= &mt('included for any client IP');
11602: }
11603: $resulttext .= '</li>';
11604: }
11605: }
11606: }
1.160.6.113 raeburn 11607: } elsif ($item eq 'saml') {
11608: if (ref($changes{$item}) eq 'HASH') {
11609: my %notlt = (
11610: text => 'Text for log-in by SSO',
11611: img => 'SSO button image',
11612: alt => 'Alt text for button image',
11613: url => 'SSO URL',
11614: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 11615:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 11616: notsso => 'Text for non-SSO log-in',
11617: );
11618: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11619: if (ref($currsaml{$lonhost}) eq 'HASH') {
11620: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11621: '<ul>';
1.160.6.118.2 9(raebur 11622:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11623: if ($currsaml{$lonhost}{$key} eq '') {
11624: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11625: } else {
11626: my $value = "'$currsaml{$lonhost}{$key}'";
11627: if ($key eq 'img') {
11628: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 11629:2): } elsif ($key eq 'window') {
11630:2): $value = 'On';
1.160.6.113 raeburn 11631: }
11632: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11633: $value).'</li>';
11634: }
11635: }
11636: $resulttext .= '</ul></li>';
11637: } else {
11638: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11639: }
11640: }
11641: }
1.160.6.5 raeburn 11642: } elsif ($item eq 'captcha') {
11643: if (ref($loginhash{'login'}) eq 'HASH') {
11644: my $chgtxt;
11645: if ($loginhash{'login'}{$item} eq 'notused') {
11646: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11647: } else {
11648: my %captchas = &captcha_phrases();
11649: if ($captchas{$loginhash{'login'}{$item}}) {
11650: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11651: } else {
11652: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11653: }
11654: }
11655: $resulttext .= '<li>'.$chgtxt.'</li>';
11656: }
11657: } elsif ($item eq 'recaptchakeys') {
11658: if (ref($loginhash{'login'}) eq 'HASH') {
11659: my ($privkey,$pubkey);
11660: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11661: $pubkey = $loginhash{'login'}{$item}{'public'};
11662: $privkey = $loginhash{'login'}{$item}{'private'};
11663: }
11664: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11665: if (!$pubkey) {
11666: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11667: } else {
11668: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11669: }
11670: if (!$privkey) {
11671: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11672: } else {
1.160.6.53 raeburn 11673: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 11674: }
11675: $chgtxt .= '</ul>';
11676: $resulttext .= '<li>'.$chgtxt.'</li>';
11677: }
1.160.6.69 raeburn 11678: } elsif ($item eq 'recaptchaversion') {
11679: if (ref($loginhash{'login'}) eq 'HASH') {
11680: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11681: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11682: '</li>';
11683: }
11684: }
1.41 raeburn 11685: } else {
11686: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11687: }
1.1 raeburn 11688: }
1.6 raeburn 11689: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11690: } else {
11691: $resulttext = &mt('No changes made to log-in page settings');
11692: }
11693: } else {
1.11 albertel 11694: $resulttext = '<span class="LC_error">'.
11695: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11696: }
1.6 raeburn 11697: if ($errors) {
1.9 raeburn 11698: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11699: $errors.'</ul>';
11700: }
11701: return $resulttext;
11702: }
11703:
1.160.6.56 raeburn 11704: sub check_exempt_addresses {
11705: my ($iplist) = @_;
11706: $iplist =~ s/^\s+//;
11707: $iplist =~ s/\s+$//;
11708: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11709: my (@okips,$new);
11710: foreach my $ip (@poss_ips) {
11711: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11712: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11713: push(@okips,$ip);
11714: }
11715: }
11716: }
11717: if (@okips > 0) {
11718: $new = join(',',@okips);
11719: } else {
11720: $new = '';
11721: }
11722: return $new;
11723: }
11724:
1.6 raeburn 11725: sub color_font_choices {
11726: my %choices =
11727: &Apache::lonlocal::texthash (
11728: bgs => "Background colors",
11729: links => "Link colors",
1.55 raeburn 11730: images => "Images",
1.6 raeburn 11731: font => "Font color",
1.160.6.22 raeburn 11732: fontmenu => "Font menu",
1.76 raeburn 11733: pgbg => "Page",
1.6 raeburn 11734: tabbg => "Header",
11735: sidebg => "Border",
11736: link => "Link",
11737: alink => "Active link",
11738: vlink => "Visited link",
11739: );
11740: return %choices;
11741: }
11742:
1.160.6.113 raeburn 11743: sub modify_ipaccess {
11744: my ($dom,$lastactref,%domconfig) = @_;
11745: my (@allpos,%changes,%confhash,$errors,$resulttext);
11746: my (@items,%deletions,%itemids,@warnings);
11747: my ($typeorder,$types) = &commblocktype_text();
11748: if ($env{'form.ipaccess_add'}) {
11749: my $name = $env{'form.ipaccess_name_add'};
11750: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11751: if ($newid) {
11752: $itemids{'add'} = $newid;
11753: push(@items,'add');
11754: $changes{$newid} = 1;
11755: } else {
11756: $error = &mt('Failed to acquire unique ID for new IP access control item');
11757: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11758: }
11759: }
11760: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11761: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11762: if (@todelete) {
11763: map { $deletions{$_} = 1; } @todelete;
11764: }
11765: my $maxnum = $env{'form.ipaccess_maxnum'};
11766: for (my $i=0; $i<$maxnum; $i++) {
11767: my $itemid = $env{'form.ipaccess_id_'.$i};
11768: $itemid =~ s/\D+//g;
11769: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11770: if ($deletions{$itemid}) {
11771: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11772: } else {
11773: push(@items,$i);
11774: $itemids{$i} = $itemid;
11775: }
11776: }
11777: }
11778: }
11779: foreach my $idx (@items) {
11780: my $itemid = $itemids{$idx};
11781: next unless ($itemid);
1.160.6.118.2 26(raebu 11782:25): my ($position,%current);
11783:25): if ($idx eq 'add') {
11784:25): $position = $env{'form.ipaccess_pos_add'};
11785:25): } else {
11786:25): $position = $env{'form.ipaccess_pos_'.$itemid};
1.160.6.113 raeburn 11787: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11788: %current = %{$domconfig{'ipaccess'}{$itemid}};
11789: }
11790: }
11791: $position =~ s/\D+//g;
11792: if ($position ne '') {
11793: $allpos[$position] = $itemid;
11794: }
11795: my $name = $env{'form.ipaccess_name_'.$idx};
11796: $name =~ s/^\s+|\s+$//g;
11797: $confhash{$itemid}{'name'} = $name;
11798: my $possrange = $env{'form.ipaccess_range_'.$idx};
11799: $possrange =~ s/^\s+|\s+$//g;
11800: unless ($possrange eq '') {
11801: $possrange =~ s/[\r\n]+/\s/g;
11802: $possrange =~ s/\s*-\s*/-/g;
11803: $possrange =~ s/\s+/,/g;
11804: $possrange =~ s/,+/,/g;
11805: if ($possrange ne '') {
11806: my (@ok,$count);
11807: $count = 0;
11808: foreach my $poss (split(/\,/,$possrange)) {
11809: $count ++;
11810: $poss = &validate_ip_pattern($poss);
11811: if ($poss ne '') {
11812: push(@ok,$poss);
11813: }
11814: }
11815: my $diff = $count - scalar(@ok);
11816: if ($diff) {
11817: $errors .= '<li><span class="LC_error">'.
11818: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11819: $diff,$name).
11820: '</span></li>';
11821: }
11822: if (@ok) {
11823: my @cidr_list;
11824: foreach my $item (@ok) {
11825: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11826: }
11827: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11828: }
11829: }
11830: }
11831: foreach my $field ('name','ip') {
11832: unless (($idx eq 'add') || ($changes{$itemid})) {
11833: if ($current{$field} ne $confhash{$itemid}{$field}) {
11834: $changes{$itemid} = 1;
11835: last;
11836: }
11837: }
11838: }
11839: $confhash{$itemid}{'commblocks'} = {};
11840:
11841: my %commblocks;
11842: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11843: foreach my $type (@{$typeorder}) {
11844: if ($commblocks{$type}) {
11845: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11846: }
11847: unless (($idx eq 'add') || ($changes{$itemid})) {
11848: if (ref($current{'commblocks'}) eq 'HASH') {
11849: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11850: $changes{$itemid} = 1;
11851: }
11852: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11853: $changes{$itemid} = 1;
11854: }
11855: }
11856: }
11857: $confhash{$itemid}{'courses'} = {};
11858: my %crsdeletions;
11859: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11860: if (@delcrs) {
11861: map { $crsdeletions{$_} = 1; } @delcrs;
11862: }
11863: if (ref($current{'courses'}) eq 'HASH') {
11864: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11865: if ($crsdeletions{$cid}) {
11866: $changes{$itemid} = 1;
11867: } else {
11868: $confhash{$itemid}{'courses'}{$cid} = 1;
11869: }
11870: }
11871: }
11872: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11873: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11874: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11875: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11876: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11877: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11878: $errors .= '<li><span class="LC_error">'.
11879: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11880: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11881: '</span></li>';
11882: } else {
11883: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11884: $changes{$itemid} = 1;
11885: }
11886: }
11887: }
11888: if (@allpos > 0) {
11889: my $idx = 0;
11890: foreach my $itemid (@allpos) {
11891: if ($itemid ne '') {
11892: $confhash{$itemid}{'order'} = $idx;
11893: unless ($changes{$itemid}) {
11894: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11895: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11896: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11897: $changes{$itemid} = 1;
11898: }
11899: }
11900: }
11901: }
11902: $idx ++;
11903: }
11904: }
11905: }
11906: if (keys(%changes)) {
11907: my %defaultshash = (
11908: ipaccess => \%confhash,
11909: );
11910: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11911: $dom);
11912: if ($putresult eq 'ok') {
11913: my $cachetime = 1800;
11914: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11915: if (ref($lastactref) eq 'HASH') {
11916: $lastactref->{'ipaccess'} = 1;
11917: }
11918: $resulttext = &mt('Changes made:').'<ul>';
11919: my %bynum;
11920: foreach my $itemid (sort(keys(%changes))) {
11921: if (ref($confhash{$itemid}) eq 'HASH') {
11922: my $position = $confhash{$itemid}{'order'};
11923: if ($position =~ /^\d+$/) {
11924: $bynum{$position} = $itemid;
11925: }
11926: }
11927: }
11928: if (keys(%deletions)) {
11929: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11930: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11931: }
11932: }
11933: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11934: my $itemid = $bynum{$pos};
11935: if (ref($confhash{$itemid}) eq 'HASH') {
11936: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11937: my $position = $pos + 1;
11938: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11939: if ($confhash{$itemid}{'ip'} eq '') {
11940: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11941: } else {
11942: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11943: }
11944: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11945: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11946: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11947: '</li>';
11948: } else {
11949: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11950: }
11951: if (keys(%{$confhash{$itemid}{'courses'}})) {
11952: my @courses;
11953: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11954: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11955: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
11956: }
11957: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
11958: join('</li><li>',@courses).'</li></ul>';
11959: } else {
11960: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
11961: }
11962: $resulttext .= '</ul></li>';
11963: }
11964: }
11965: $resulttext .= '</ul>';
11966: } else {
11967: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
11968: }
11969: } else {
11970: $resulttext = &mt('No changes made');
11971: }
11972: if ($errors) {
11973: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
11974: $errors.'</ul></p>';
11975: }
11976: return $resulttext;
11977: }
11978:
11979: sub get_ipaccess_id {
11980: my ($domain,$location) = @_;
11981: # get lock on ipaccess db
11982: my $lockhash = {
11983: lock => $env{'user.name'}.
11984: ':'.$env{'user.domain'},
11985: };
11986: my $tries = 0;
11987: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11988: my ($id,$error);
11989:
11990: while (($gotlock ne 'ok') && ($tries<10)) {
11991: $tries ++;
11992: sleep (0.1);
11993: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
11994: }
11995: if ($gotlock eq 'ok') {
11996: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
11997: if ($currids{'lock'}) {
11998: delete($currids{'lock'});
11999: if (keys(%currids)) {
12000: my @curr = sort { $a <=> $b } keys(%currids);
12001: if ($curr[-1] =~ /^\d+$/) {
12002: $id = 1 + $curr[-1];
12003: }
12004: } else {
12005: $id = 1;
12006: }
12007: if ($id) {
12008: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12009: $error = 'nostore';
12010: }
12011: } else {
12012: $error = 'nonumber';
12013: }
12014: }
12015: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12016: } else {
12017: $error = 'nolock';
12018: }
12019: return ($id,$error);
12020: }
12021:
1.160.6.118.2 20(raebu 12022:24): sub modify_authordefaults {
12023:24): my ($dom,$lastactref,%domconfig) = @_;
12024:24): #
12025:24): # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
12026:24): #
12027:24): my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
12028:24): if (ref($domconfig{'quotas'}) eq 'HASH') {
12029:24): foreach my $key (keys(%{$domconfig{'quotas'}})) {
12030:24): if ($key =~ /^webdav|authorquota$/) {
12031:24): $curr_quotas{$key} = $domconfig{'quotas'}{$key};
12032:24): } else {
12033:24): $save_quotas{$key} = $domconfig{'quotas'}{$key};
12034:24): }
12035:24): }
12036:24): }
12037:24): my %staticdefaults = (
12038:24): 'copyright' => 'default',
12039:24): 'sourceavail' => 'closed',
12040:24): 'nocodemirror' => 'off',
21(raebu 12041:24): 'daxecollapse' => 'off',
20(raebu 12042:24): 'domcoordacc' => 'on',
22(raebu 12043:24): 'editors' => ['edit','xml'],
20(raebu 12044:24): 'authorquota' => 500,
12045:24): 'webdav' => 0,
22(raebu 12046:24): 'archive' => 'off',
20(raebu 12047:24): );
12048:24): my %titles = &authordefaults_titles();
22(raebu 12049:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12050:24): if ($env{'form.'.$item} =~ /^(0|1)$/) {
12051:24): $confhash{$item} = $env{'form.'.$item};
12052:24): }
12053:24): }
12054:24): if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
12055:24): $confhash{'copyright'} = $1;
12056:24): }
12057:24): if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
12058:24): $confhash{'sourceavail'} = $1;
12059:24): }
12060:24): my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
12061:24): my @okeditors = ('edit','xml','daxe');
12062:24): my @editors;
12063:24): foreach my $item (@posseditors) {
12064:24): if (grep(/^\Q$item\E$/,@okeditors)) {
12065:24): push(@editors,$item);
12066:24): }
12067:24): }
12068:24): $confhash{'editors'} = \@editors;
12069:24):
12070:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12071:24): my @insttypes;
12072:24): if (ref($types) eq 'ARRAY') {
12073:24): @insttypes = @{$types};
12074:24): }
12075:24): my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
12076:24): my %webdav;
12077:24): map { $webdav{$_} = 1; } @webdavon;
12078:24): foreach my $type (@insttypes,'default') {
12079:24): my $possquota = $env{'form.authorquota_'.$type};
12080:24): if ($possquota =~ /^\d+$/) {
12081:24): $save_quotas{'authorquota'}{$type} = $possquota;
12082:24): }
12083:24): if ($webdav{$type}) {
12084:24): $save_quotas{'webdav'}{$type} = 1;
12085:24): } else {
12086:24): $save_quotas{'webdav'}{$type} = 0;
12087:24): }
12088:24): }
12089:24): if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
12090:24): $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
12091:24): }
12092:24): if (ref($domconfig{'authordefaults'}) eq 'HASH') {
22(raebu 12093:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
20(raebu 12094:24): if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
12095:24): $changes{$item} = 1;
12096:24): }
12097:24): }
12098:24): if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
12099:24): my @diffs =
12100:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12101:24): $domconfig{'authordefaults'}{'editors'});
12102:24): unless (@diffs == 0) {
12103:24): $changes{'editors'} = 1;
12104:24): }
12105:24): } else {
12106:24): my @diffs =
12107:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12108:24): $staticdefaults{'editors'});
12109:24): unless (@diffs == 0) {
12110:24): $changes{'editors'} = 1;
12111:24): }
12112:24): }
12113:24): } else {
12114:24): my @offon = ('off','on');
22(raebu 12115:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12116:24): if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
12117:24): $changes{$item} = 1;
12118:24): }
12119:24): }
12120:24): foreach my $item ('copyright','sourceavail') {
12121:24): if ($confhash{$item} ne $staticdefaults{$item}) {
12122:24): $changes{$item} = 1;
12123:24): }
12124:24): }
22(raebu 12125:24): my @diffs =
12126:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12127:24): $staticdefaults{'editors'});
12128:24): unless (@diffs == 0) {
12129:24): $changes{'editors'} = 1;
12130:24): }
20(raebu 12131:24): }
12132:24): foreach my $key ('authorquota','webdav') {
12133:24): if (ref($curr_quotas{$key}) eq 'HASH') {
12134:24): foreach my $type (@insttypes,'default') {
12135:24): if (exists($save_quotas{$key}{$type})) {
12136:24): if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
12137:24): $changes{$key}{$type} = 1;
12138:24): }
12139:24): } elsif (exists($curr_quotas{$key}{$type})) {
12140:24): $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
12141:24): } else {
12142:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12143:24): }
12144:24): }
12145:24): } else {
12146:24): foreach my $type (@insttypes,'default') {
12147:24): if (exists($save_quotas{$key}{$type})) {
12148:24): unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
12149:24): $changes{$key}{$type} = 1;
12150:24): }
12151:24): } else {
12152:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12153:24): }
12154:24): }
12155:24): }
12156:24): }
12157:24): if (ref($curr_quotas{'webdav'}) eq 'HASH') {
12158:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12159:24): if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
12160:24): $changes{'webdav_LC_adv'} = 1;
12161:24): }
12162:24): } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
12163:24): $changes{'webdav_LC_adv'} = 1;
12164:24): }
12165:24): } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12166:24): $changes{'webdav_LC_adv'} = 1;
12167:24): }
12168:24): my %confighash = (
12169:24): quotas => \%save_quotas,
12170:24): authordefaults => \%confhash,
12171:24): );
12172:24): my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
12173:24): $dom);
12174:24): my $resulttext;
12175:24): if ($putresult eq 'ok') {
12176:24): if (keys(%changes)) {
12177:24): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12178:24): if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
12179:24): ($changes{'webdav_LC_adv'})) {
12180:24): if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
12181:24): $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
12182:24): }
12183:24): if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
12184:24): (ref($save_quotas{'webdav'}) eq 'HASH')) {
12185:24): $domdefaults{'webdav'} = $save_quotas{'webdav'};
12186:24): }
12187:24): }
12188:24): $resulttext = &mt('Changes made:').'<ul>';
12189:24): my $authoroverride;
21(raebu 12190:24): foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
20(raebu 12191:24): if (exists($changes{$key})) {
12192:24): $domdefaults{$key} = $confhash{$key};
12193:24): my $shown;
12194:24): unless ($authoroverride) {
12195:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
12196:24): $authoroverride = 1;
12197:24): }
21(raebu 12198:24): if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
20(raebu 12199:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
12200:24): } elsif ($key eq 'copyright') {
12201:24): $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
12202:24): } elsif ($key eq 'sourceavail') {
12203:24): $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
12204:24): }
12205:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12206:24): }
12207:24): }
12208:24): if ($authoroverride) {
12209:24): $resulttext .= '</ul></li>';
12210:24): }
12211:24): my $domcoordoverride;
22(raebu 12212:24): foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
20(raebu 12213:24): if (exists($changes{$key})) {
12214:24): my $shown;
12215:24): unless ($domcoordoverride) {
12216:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
12217:24): $domcoordoverride = 1;
12218:24): }
12219:24): if ($key eq 'editors') {
12220:24): if (ref($confhash{'editors'}) eq 'ARRAY') {
12221:24): $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
12222:24): if (@{$confhash{'editors'}}) {
12223:24): $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
12224:24): } else {
12225:24): $shown = &mt('None');
12226:24): }
12227:24): }
12228:24): } elsif ($key eq 'authorquota') {
12229:24): foreach my $type (@insttypes) {
12230:24): $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
12231:24): }
12232:24): $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
12233:24): } elsif ($key eq 'webdav') {
12234:24): foreach my $type (@insttypes) {
12235:24): $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
12236:24): }
12237:24): $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
12238:24): } elsif ($key eq 'webdav_LC_adv') {
12239:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12240:24): $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
12241:24): } else {
12242:24): $shown = $titles{'none'};
12243:24): }
22(raebu 12244:24): } elsif ($key eq 'archive') {
12245:24): $domdefaults{$key} = $confhash{$key};
12246:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
20(raebu 12247:24): }
12248:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12249:24): }
12250:24): }
12251:24): if ($domcoordoverride) {
12252:24): $resulttext .= '</ul></li>';
12253:24): }
22(raebu 12254:24): $resulttext .= '</ul>';
20(raebu 12255:24): my $cachetime = 24*60*60;
12256:24): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12257:24): if (ref($lastactref) eq 'HASH') {
12258:24): $lastactref->{'domdefaults'} = 1;
12259:24): }
12260:24): } else {
12261:24): $resulttext = &mt('No changes made to Authoring Space defaults');
12262:24): }
12263:24): }
12264:24): return $resulttext;
12265:24): }
12266:24):
1.6 raeburn 12267: sub modify_rolecolors {
1.160.6.24 raeburn 12268: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12269: my ($resulttext,%rolehash);
12270: $rolehash{'rolecolors'} = {};
1.55 raeburn 12271: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12272: if ($domconfig{'rolecolors'} eq '') {
12273: $domconfig{'rolecolors'} = {};
12274: }
12275: }
1.9 raeburn 12276: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12277: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12278: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12279: $dom);
12280: if ($putresult eq 'ok') {
12281: if (keys(%changes) > 0) {
1.41 raeburn 12282: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12283: if (ref($lastactref) eq 'HASH') {
12284: $lastactref->{'domainconfig'} = 1;
12285: }
1.6 raeburn 12286: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12287: $rolehash{'rolecolors'});
12288: } else {
12289: $resulttext = &mt('No changes made to default color schemes');
12290: }
12291: } else {
1.11 albertel 12292: $resulttext = '<span class="LC_error">'.
12293: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12294: }
12295: if ($errors) {
12296: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12297: $errors.'</ul>';
12298: }
12299: return $resulttext;
12300: }
12301:
12302: sub modify_colors {
1.9 raeburn 12303: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12304: my (%changes,%choices);
1.51 raeburn 12305: my @bgs;
1.6 raeburn 12306: my @links = ('link','alink','vlink');
1.41 raeburn 12307: my @logintext;
1.6 raeburn 12308: my @images;
12309: my $servadm = $r->dir_config('lonAdmEMail');
12310: my $errors;
1.160.6.22 raeburn 12311: my %defaults;
1.6 raeburn 12312: foreach my $role (@{$roles}) {
12313: if ($role eq 'login') {
1.12 raeburn 12314: %choices = &login_choices();
1.41 raeburn 12315: @logintext = ('textcol','bgcol');
1.12 raeburn 12316: } else {
12317: %choices = &color_font_choices();
12318: }
12319: if ($role eq 'login') {
1.41 raeburn 12320: @images = ('img','logo','domlogo','login');
1.51 raeburn 12321: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12322: } else {
1.160.6.118.2 26(raebu 12323:25): @images = ();
1.160.6.22 raeburn 12324: @bgs = ('pgbg','tabbg','sidebg');
12325: }
12326: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
1.160.6.118.2 26(raebu 12327:25): $env{'form.'.$role.'_font'} = lc($env{'form.'.$role.'_font'});
12328:25): if ($env{'form.'.$role.'_font'} =~ /^\w+/) {
12329:25): $env{'form.'.$role.'_font'} = '#'.$env{'form.'.$role.'_font'};
12330:25): }
12331:25): unless ($env{'form.'.$role.'_font'} eq lc($defaults{'font'})) {
1.160.6.22 raeburn 12332: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12333: }
12334: if ($role eq 'login') {
12335: foreach my $item (@logintext) {
1.160.6.39 raeburn 12336: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12337: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12338: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12339: }
12340: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 12341: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12342: }
12343: }
12344: } else {
1.160.6.39 raeburn 12345: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12346: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12347: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12348: }
1.160.6.118.2 26(raebu 12349:25): unless ($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 12350: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12351: }
1.6 raeburn 12352: }
1.160.6.22 raeburn 12353: foreach my $item (@bgs) {
1.160.6.39 raeburn 12354: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12355: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12356: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12357: }
12358: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 12359: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12360: }
12361: }
12362: foreach my $item (@links) {
1.160.6.39 raeburn 12363: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12364: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12365: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12366: }
12367: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 12368: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12369: }
1.6 raeburn 12370: }
1.46 raeburn 12371: my ($configuserok,$author_ok,$switchserver) =
12372: &config_check($dom,$confname,$servadm);
1.9 raeburn 12373: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12374: if (ref($domconfig->{$role}) ne 'HASH') {
12375: $domconfig->{$role} = {};
12376: }
1.8 raeburn 12377: foreach my $img (@images) {
1.160.6.118.2 2(raebur 12378:2): if ($role eq 'login') {
12379:2): if (($img eq 'img') || ($img eq 'logo')) {
12380:2): if (defined($env{'form.login_showlogo_'.$img})) {
12381:2): $confhash->{$role}{'showlogo'}{$img} = 1;
12382:2): } else {
12383:2): $confhash->{$role}{'showlogo'}{$img} = 0;
12384:2): }
1.70 raeburn 12385: }
1.160.6.118.2 2(raebur 12386:2): if ($env{'form.login_alt_'.$img} ne '') {
12387:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
12388:2): }
12389:2): }
1.18 albertel 12390: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12391: && !defined($domconfig->{$role}{$img})
12392: && !$env{'form.'.$role.'_del_'.$img}
12393: && $env{'form.'.$role.'_import_'.$img}) {
12394: # import the old configured image from the .tab setting
12395: # if they haven't provided a new one
12396: $domconfig->{$role}{$img} =
12397: $env{'form.'.$role.'_import_'.$img};
12398: }
1.6 raeburn 12399: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12400: my $error;
1.6 raeburn 12401: if ($configuserok eq 'ok') {
1.9 raeburn 12402: if ($switchserver) {
1.12 raeburn 12403: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12404: } else {
12405: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12406:23): my $modified = [];
1.9 raeburn 12407: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12408:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
12409:23): $dom,$confname,$img,$width,$height,
12410:23): '',$modified);
1.9 raeburn 12411: if ($result eq 'ok') {
12412: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12413: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12414:23): &update_modify_urls($r,$modified);
1.9 raeburn 12415: } else {
1.12 raeburn 12416: $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 12417: }
12418: } else {
1.46 raeburn 12419: $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 12420: }
12421: }
12422: } else {
1.46 raeburn 12423: $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 12424: }
12425: if ($error) {
1.8 raeburn 12426: &Apache::lonnet::logthis($error);
1.11 albertel 12427: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12428: }
12429: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12430: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12431: my $error;
12432: if ($configuserok eq 'ok') {
12433: # is confname an author?
12434: if ($switchserver eq '') {
12435: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12436:23): my $modified = [];
1.9 raeburn 12437: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12438:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
12439:23): $dom,$confname,$img,$width,$height,
12440:23): '',$modified);
1.9 raeburn 12441: if ($result eq 'ok') {
12442: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12443: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12444:23): &update_modify_urls($r,$modified);
1.9 raeburn 12445: }
12446: }
12447: }
12448: }
1.6 raeburn 12449: }
12450: }
12451: }
12452: if (ref($domconfig) eq 'HASH') {
12453: if (ref($domconfig->{$role}) eq 'HASH') {
12454: foreach my $img (@images) {
12455: if ($domconfig->{$role}{$img} ne '') {
12456: if ($env{'form.'.$role.'_del_'.$img}) {
12457: $confhash->{$role}{$img} = '';
1.12 raeburn 12458: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12459: } else {
1.9 raeburn 12460: if ($confhash->{$role}{$img} eq '') {
12461: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12462: }
1.6 raeburn 12463: }
12464: } else {
12465: if ($env{'form.'.$role.'_del_'.$img}) {
12466: $confhash->{$role}{$img} = '';
1.12 raeburn 12467: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12468: }
12469: }
1.160.6.118.2 2(raebur 12470:2): if ($role eq 'login') {
12471:2): if (($img eq 'logo') || ($img eq 'img')) {
12472:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12473:2): if ($confhash->{$role}{'showlogo'}{$img} ne
12474:2): $domconfig->{$role}{'showlogo'}{$img}) {
12475:2): $changes{$role}{'showlogo'}{$img} = 1;
12476:2): }
12477:2): } else {
12478:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12479:2): $changes{$role}{'showlogo'}{$img} = 1;
12480:2): }
1.70 raeburn 12481: }
1.160.6.118.2 2(raebur 12482:2): }
12483:2): if ($img ne 'login') {
12484:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
12485:2): if ($confhash->{$role}{'alttext'}{$img} ne
12486:2): $domconfig->{$role}{'alttext'}{$img}) {
12487:2): $changes{$role}{'alttext'}{$img} = 1;
12488:2): }
12489:2): } else {
12490:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12491:2): $changes{$role}{'alttext'}{$img} = 1;
12492:2): }
1.70 raeburn 12493: }
12494: }
12495: }
12496: }
1.6 raeburn 12497: if ($domconfig->{$role}{'font'} ne '') {
12498: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12499: $changes{$role}{'font'} = 1;
12500: }
12501: } else {
12502: if ($confhash->{$role}{'font'}) {
12503: $changes{$role}{'font'} = 1;
12504: }
12505: }
1.107 raeburn 12506: if ($role ne 'login') {
12507: if ($domconfig->{$role}{'fontmenu'} ne '') {
12508: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12509: $changes{$role}{'fontmenu'} = 1;
12510: }
12511: } else {
12512: if ($confhash->{$role}{'fontmenu'}) {
12513: $changes{$role}{'fontmenu'} = 1;
12514: }
1.97 tempelho 12515: }
12516: }
1.6 raeburn 12517: foreach my $item (@bgs) {
12518: if ($domconfig->{$role}{$item} ne '') {
12519: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12520: $changes{$role}{'bgs'}{$item} = 1;
12521: }
12522: } else {
12523: if ($confhash->{$role}{$item}) {
12524: $changes{$role}{'bgs'}{$item} = 1;
12525: }
12526: }
12527: }
12528: foreach my $item (@links) {
12529: if ($domconfig->{$role}{$item} ne '') {
12530: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12531: $changes{$role}{'links'}{$item} = 1;
12532: }
12533: } else {
12534: if ($confhash->{$role}{$item}) {
12535: $changes{$role}{'links'}{$item} = 1;
12536: }
12537: }
12538: }
1.41 raeburn 12539: foreach my $item (@logintext) {
12540: if ($domconfig->{$role}{$item} ne '') {
12541: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12542: $changes{$role}{'logintext'}{$item} = 1;
12543: }
12544: } else {
12545: if ($confhash->{$role}{$item}) {
12546: $changes{$role}{'logintext'}{$item} = 1;
12547: }
12548: }
12549: }
1.6 raeburn 12550: } else {
12551: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12552: \@logintext,$confhash,\%changes);
1.6 raeburn 12553: }
12554: } else {
12555: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12556: \@logintext,$confhash,\%changes);
1.6 raeburn 12557: }
12558: }
12559: return ($errors,%changes);
12560: }
12561:
1.46 raeburn 12562: sub config_check {
12563: my ($dom,$confname,$servadm) = @_;
12564: my ($configuserok,$author_ok,$switchserver,%currroles);
12565: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12566: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12567: $confname,$servadm);
12568: if ($configuserok eq 'ok') {
12569: $switchserver = &check_switchserver($dom,$confname);
12570: if ($switchserver eq '') {
12571: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12572: }
12573: }
12574: return ($configuserok,$author_ok,$switchserver);
12575: }
12576:
1.6 raeburn 12577: sub default_change_checker {
1.41 raeburn 12578: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12579: foreach my $item (@{$links}) {
12580: if ($confhash->{$role}{$item}) {
12581: $changes->{$role}{'links'}{$item} = 1;
12582: }
12583: }
12584: foreach my $item (@{$bgs}) {
12585: if ($confhash->{$role}{$item}) {
12586: $changes->{$role}{'bgs'}{$item} = 1;
12587: }
12588: }
1.41 raeburn 12589: foreach my $item (@{$logintext}) {
12590: if ($confhash->{$role}{$item}) {
12591: $changes->{$role}{'logintext'}{$item} = 1;
12592: }
12593: }
1.6 raeburn 12594: foreach my $img (@{$images}) {
12595: if ($env{'form.'.$role.'_del_'.$img}) {
12596: $confhash->{$role}{$img} = '';
1.12 raeburn 12597: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12598: }
1.70 raeburn 12599: if ($role eq 'login') {
12600: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12601: $changes->{$role}{'showlogo'}{$img} = 1;
12602: }
1.160.6.118.2 2(raebur 12603:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
12604:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12605:2): $changes->{$role}{'alttext'}{$img} = 1;
12606:2): }
12607:2): }
1.70 raeburn 12608: }
1.6 raeburn 12609: }
12610: if ($confhash->{$role}{'font'}) {
12611: $changes->{$role}{'font'} = 1;
12612: }
1.48 raeburn 12613: }
1.6 raeburn 12614:
12615: sub display_colorchgs {
12616: my ($dom,$changes,$roles,$confhash) = @_;
12617: my (%choices,$resulttext);
12618: if (!grep(/^login$/,@{$roles})) {
12619: $resulttext = &mt('Changes made:').'<br />';
12620: }
12621: foreach my $role (@{$roles}) {
12622: if ($role eq 'login') {
12623: %choices = &login_choices();
12624: } else {
12625: %choices = &color_font_choices();
12626: }
12627: if (ref($changes->{$role}) eq 'HASH') {
12628: if ($role ne 'login') {
12629: $resulttext .= '<h4>'.&mt($role).'</h4>';
12630: }
12631: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12632: if ($role ne 'login') {
12633: $resulttext .= '<ul>';
12634: }
12635: if (ref($changes->{$role}{$key}) eq 'HASH') {
12636: if ($role ne 'login') {
12637: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12638: }
12639: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12640: if (($role eq 'login') && ($key eq 'showlogo')) {
12641: if ($confhash->{$role}{$key}{$item}) {
12642: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12643: } else {
12644: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12645: }
1.160.6.118.2 2(raebur 12646:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
12647:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 12648:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 12649:2): $confhash->{$role}{$key}{$item}).'</li>';
12650:2): } else {
12651:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12652:2): }
1.70 raeburn 12653: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12654: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12655: } else {
1.12 raeburn 12656: my $newitem = $confhash->{$role}{$item};
12657: if ($key eq 'images') {
12658: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12659: }
12660: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12661: }
12662: }
12663: if ($role ne 'login') {
12664: $resulttext .= '</ul></li>';
12665: }
12666: } else {
12667: if ($confhash->{$role}{$key} eq '') {
12668: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12669: } else {
12670: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12671: }
12672: }
12673: if ($role ne 'login') {
12674: $resulttext .= '</ul>';
12675: }
12676: }
12677: }
12678: }
1.3 raeburn 12679: return $resulttext;
1.1 raeburn 12680: }
12681:
1.9 raeburn 12682: sub thumb_dimensions {
12683: return ('200','50');
12684: }
12685:
1.16 raeburn 12686: sub check_dimensions {
12687: my ($inputfile) = @_;
12688: my ($fullwidth,$fullheight);
12689: if ($inputfile =~ m|^[/\w.\-]+$|) {
12690: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12691: my $imageinfo = <PIPE>;
12692: if (!close(PIPE)) {
12693: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12694: }
12695: chomp($imageinfo);
12696: my ($fullsize) =
1.21 raeburn 12697: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12698: if ($fullsize) {
12699: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12700: }
12701: }
12702: }
12703: return ($fullwidth,$fullheight);
12704: }
12705:
1.9 raeburn 12706: sub check_configuser {
12707: my ($uhome,$dom,$confname,$servadm) = @_;
12708: my ($configuserok,%currroles);
12709: if ($uhome eq 'no_host') {
12710: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 12711: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12712: $configuserok =
12713: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12714: $configpass,'','','','','',undef,$servadm);
12715: } else {
12716: $configuserok = 'ok';
12717: %currroles =
12718: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12719: }
12720: return ($configuserok,%currroles);
12721: }
12722:
12723: sub check_authorstatus {
12724: my ($dom,$confname,%currroles) = @_;
12725: my $author_ok;
1.40 raeburn 12726: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12727: my $start = time;
12728: my $end = 0;
12729: $author_ok =
12730: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12731: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12732: } else {
12733: $author_ok = 'ok';
12734: }
12735: return $author_ok;
12736: }
12737:
1.160.6.118.2 14(raebu 12738:23): sub update_modify_urls {
12739:23): my ($r,$modified) = @_;
12740:23): if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12741:23): push(@{$modified_urls},$modified);
12742:23): unless ($registered_cleanup) {
12743:23): my $handlers = $r->get_handlers('PerlCleanupHandler');
12744:23): $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12745:23): $registered_cleanup=1;
1.9 raeburn 12746: }
12747: }
1.155 raeburn 12748: }
12749:
12750: sub notifysubscribed {
12751: foreach my $targetsource (@{$modified_urls}){
12752: next unless (ref($targetsource) eq 'ARRAY');
12753: my ($target,$source)=@{$targetsource};
12754: if ($source ne '') {
1.160.6.88 raeburn 12755: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12756: print $logfh "\nCleanup phase: Notifications\n";
12757: my @subscribed=&subscribed_hosts($target);
12758: foreach my $subhost (@subscribed) {
12759: print $logfh "\nNotifying host ".$subhost.':';
12760: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12761: print $logfh $reply;
12762: }
12763: my @subscribedmeta=&subscribed_hosts("$target.meta");
12764: foreach my $subhost (@subscribedmeta) {
12765: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12766: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12767: $subhost);
12768: print $logfh $reply;
12769: }
12770: print $logfh "\n============ Done ============\n";
1.160 raeburn 12771: close($logfh);
1.155 raeburn 12772: }
12773: }
12774: }
12775: return OK;
12776: }
12777:
12778: sub subscribed_hosts {
12779: my ($target) = @_;
12780: my @subscribed;
1.160.6.88 raeburn 12781: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12782: while (my $subline=<$fh>) {
12783: if ($subline =~ /^($match_lonid):/) {
12784: my $host = $1;
12785: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12786: unless (grep(/^\Q$host\E$/,@subscribed)) {
12787: push(@subscribed,$host);
12788: }
12789: }
12790: }
12791: }
12792: }
12793: return @subscribed;
1.9 raeburn 12794: }
12795:
12796: sub check_switchserver {
12797: my ($dom,$confname) = @_;
1.160.6.118.2 14(raebu 12798:23): my ($allowed,$switchserver,$home);
12799:23): if ($confname eq '') {
1.9 raeburn 12800: $home = &Apache::lonnet::domain($dom,'primary');
1.160.6.118.2 14(raebu 12801:23): } else {
12802:23): $home = &Apache::lonnet::homeserver($confname,$dom);
12803:23): if ($home eq 'no_host') {
12804:23): $home = &Apache::lonnet::domain($dom,'primary');
12805:23): }
1.9 raeburn 12806: }
12807: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12808: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12809: if (!$allowed) {
1.160.6.118.2 14(raebu 12810:23): $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12811:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12812:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12813: }
12814: return $switchserver;
12815: }
12816:
1.1 raeburn 12817: sub modify_quotas {
1.160.6.30 raeburn 12818: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12819: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 12820: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 12821: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12822: $validationfieldsref);
1.86 raeburn 12823: if ($action eq 'quotas') {
1.160.6.118.2 20(raebu 12824:24): $context = 'tools';
1.160.6.26 raeburn 12825: } else {
1.86 raeburn 12826: $context = $action;
12827: }
12828: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 12829:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 12830: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12831: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12832: %titles = &courserequest_titles();
12833: $toolregexp = join('|',@usertools);
12834: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 12835: $confname = $dom.'-domainconfig';
12836: my $servadm = $r->dir_config('lonAdmEMail');
12837: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 12838: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12839: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 12840: } elsif ($context eq 'requestauthor') {
12841: @usertools = ('author');
12842: %titles = &authorrequest_titles();
1.86 raeburn 12843: } else {
1.160.6.118.2 23(raebu 12844:24): @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 12845: %titles = &tool_titles();
1.86 raeburn 12846: }
1.160.6.27 raeburn 12847: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12848: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12849: foreach my $key (keys(%env)) {
1.101 raeburn 12850: if ($context eq 'requestcourses') {
12851: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12852: my $item = $1;
12853: my $type = $2;
12854: if ($type =~ /^limit_(.+)/) {
12855: $limithash{$item}{$1} = $env{$key};
12856: } else {
12857: $confhash{$item}{$type} = $env{$key};
12858: }
12859: }
1.160.6.5 raeburn 12860: } elsif ($context eq 'requestauthor') {
12861: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12862: $confhash{$1} = $env{$key};
12863: }
1.101 raeburn 12864: } else {
1.86 raeburn 12865: if ($key =~ /^form\.quota_(.+)$/) {
12866: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 12867: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12868: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12869: }
1.72 raeburn 12870: }
12871: }
1.160.6.5 raeburn 12872: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 12873: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12874: @approvalnotify = sort(@approvalnotify);
12875: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.118.2 14(raebu 12876:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.30 raeburn 12877: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12878: foreach my $type (@hasuniquecode) {
12879: if (grep(/^\Q$type\E$/,@crstypes)) {
12880: $confhash{'uniquecode'}{$type} = 1;
12881: }
12882: }
1.160.6.46 raeburn 12883: my (%newbook,%allpos);
1.160.6.30 raeburn 12884: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12885: foreach my $type ('textbooks','templates') {
12886: @{$allpos{$type}} = ();
12887: my $invalid;
12888: if ($type eq 'textbooks') {
12889: $invalid = &mt('Invalid LON-CAPA course for textbook');
12890: } else {
12891: $invalid = &mt('Invalid LON-CAPA course for template');
12892: }
12893: if ($env{'form.'.$type.'_addbook'}) {
12894: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12895: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12896: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12897: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12898: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12899: } else {
12900: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12901: my $position = $env{'form.'.$type.'_addbook_pos'};
12902: $position =~ s/\D+//g;
12903: if ($position ne '') {
12904: $allpos{$type}[$position] = $newbook{$type};
12905: }
1.160.6.30 raeburn 12906: }
1.160.6.46 raeburn 12907: } else {
12908: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 12909: }
12910: }
1.160.6.46 raeburn 12911: }
1.160.6.30 raeburn 12912: }
1.102 raeburn 12913: if (ref($domconfig{$action}) eq 'HASH') {
12914: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12915: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12916: $changes{'notify'}{'approval'} = 1;
12917: }
12918: } else {
1.144 raeburn 12919: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12920: $changes{'notify'}{'approval'} = 1;
12921: }
12922: }
1.160.6.30 raeburn 12923: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12924: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12925: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12926: unless ($confhash{'uniquecode'}{$crstype}) {
12927: $changes{'uniquecode'} = 1;
12928: }
12929: }
12930: unless ($changes{'uniquecode'}) {
12931: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12932: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12933: $changes{'uniquecode'} = 1;
12934: }
12935: }
12936: }
12937: } else {
12938: $changes{'uniquecode'} = 1;
12939: }
12940: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12941: $changes{'uniquecode'} = 1;
12942: }
12943: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12944: foreach my $type ('textbooks','templates') {
12945: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12946: my %deletions;
12947: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12948: if (@todelete) {
12949: map { $deletions{$_} = 1; } @todelete;
12950: }
12951: my %imgdeletions;
12952: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12953: if (@todeleteimages) {
12954: map { $imgdeletions{$_} = 1; } @todeleteimages;
12955: }
12956: my $maxnum = $env{'form.'.$type.'_maxnum'};
12957: for (my $i=0; $i<=$maxnum; $i++) {
12958: my $itemid = $env{'form.'.$type.'_id_'.$i};
12959: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
12960: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
12961: if ($deletions{$key}) {
12962: if ($domconfig{$action}{$type}{$key}{'image'}) {
12963: #FIXME need to obsolete item in RES space
12964: }
12965: next;
12966: } else {
12967: my $newpos = $env{'form.'.$itemid};
12968: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 12969: foreach my $item ('subject','title','publisher','author') {
12970: next if ((($item eq 'author') || ($item eq 'publisher')) &&
12971: ($type eq 'templates'));
1.160.6.46 raeburn 12972: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
12973: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
12974: $changes{$type}{$key} = 1;
12975: }
12976: }
12977: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 12978: }
1.160.6.46 raeburn 12979: if ($imgdeletions{$key}) {
12980: $changes{$type}{$key} = 1;
12981: #FIXME need to obsolete item in RES space
12982: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
12983: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 12984: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
12985: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
12986: } else {
12987: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
12988: $cdom,$cnum,$type,$configuserok,
12989: $switchserver,$author_ok);
12990: if ($imgurl) {
12991: $confhash{$type}{$key}{'image'} = $imgurl;
12992: $changes{$type}{$key} = 1;
12993: }
12994: if ($error) {
12995: &Apache::lonnet::logthis($error);
12996: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
12997: }
1.160.6.118.2 14(raebu 12998:23): }
1.160.6.46 raeburn 12999: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13000: $confhash{$type}{$key}{'image'} =
13001: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 13002: }
13003: }
13004: }
13005: }
13006: }
13007: }
1.102 raeburn 13008: } else {
1.144 raeburn 13009: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13010: $changes{'notify'}{'approval'} = 1;
13011: }
1.160.6.30 raeburn 13012: if (ref($confhash{'uniquecode'} eq 'HASH')) {
13013: $changes{'uniquecode'} = 1;
13014: }
13015: }
13016: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 13017: foreach my $type ('textbooks','templates') {
13018: if ($newbook{$type}) {
13019: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 13020: foreach my $item ('subject','title','publisher','author') {
13021: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13022: ($type eq 'template'));
1.160.6.46 raeburn 13023: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13024: if ($env{'form.'.$type.'_addbook_'.$item}) {
13025: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13026: }
13027: }
13028: if ($type eq 'textbooks') {
13029: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13030: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 13031: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13032: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13033: } else {
13034: my ($imageurl,$error) =
13035: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13036: $configuserok,$switchserver,$author_ok);
13037: if ($imageurl) {
13038: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13039: }
13040: if ($error) {
13041: &Apache::lonnet::logthis($error);
13042: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13043: }
1.160.6.46 raeburn 13044: }
13045: }
1.160.6.30 raeburn 13046: }
13047: }
1.160.6.46 raeburn 13048: if (@{$allpos{$type}} > 0) {
13049: my $idx = 0;
13050: foreach my $item (@{$allpos{$type}}) {
13051: if ($item ne '') {
13052: $confhash{$type}{$item}{'order'} = $idx;
13053: if (ref($domconfig{$action}) eq 'HASH') {
13054: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13055: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13056: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13057: $changes{$type}{$item} = 1;
13058: }
1.160.6.30 raeburn 13059: }
13060: }
13061: }
1.160.6.46 raeburn 13062: $idx ++;
1.160.6.30 raeburn 13063: }
13064: }
13065: }
13066: }
1.160.6.39 raeburn 13067: if (ref($validationitemsref) eq 'ARRAY') {
13068: foreach my $item (@{$validationitemsref}) {
13069: if ($item eq 'fields') {
13070: my @changed;
13071: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13072: if (@{$confhash{'validation'}{$item}} > 0) {
13073: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13074: }
1.160.6.65 raeburn 13075: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13076: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13077: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13078: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13079: $domconfig{'requestcourses'}{'validation'}{$item});
13080: } else {
13081: @changed = @{$confhash{'validation'}{$item}};
13082: }
1.160.6.39 raeburn 13083: } else {
13084: @changed = @{$confhash{'validation'}{$item}};
13085: }
13086: } else {
13087: @changed = @{$confhash{'validation'}{$item}};
13088: }
13089: if (@changed) {
13090: if ($confhash{'validation'}{$item}) {
13091: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13092: } else {
13093: $changes{'validation'}{$item} = &mt('None');
13094: }
13095: }
13096: } else {
13097: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13098: if ($item eq 'markup') {
13099: if ($env{'form.requestcourses_validation_'.$item}) {
13100: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13101: }
13102: }
1.160.6.65 raeburn 13103: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13104: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13105: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13106: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13107: }
13108: } else {
13109: if ($confhash{'validation'}{$item} ne '') {
13110: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13111: }
1.160.6.39 raeburn 13112: }
13113: } else {
13114: if ($confhash{'validation'}{$item} ne '') {
13115: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13116: }
13117: }
13118: }
13119: }
13120: }
13121: if ($env{'form.validationdc'}) {
13122: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 13123: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 13124: if (exists($domcoords{$newval})) {
13125: $confhash{'validation'}{'dc'} = $newval;
13126: }
13127: }
13128: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 13129: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13130: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13131: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13132: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13133: if ($confhash{'validation'}{'dc'} eq '') {
13134: $changes{'validation'}{'dc'} = &mt('None');
13135: } else {
13136: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13137: }
1.160.6.39 raeburn 13138: }
1.160.6.65 raeburn 13139: } elsif ($confhash{'validation'}{'dc'} ne '') {
13140: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 13141: }
13142: } elsif ($confhash{'validation'}{'dc'} ne '') {
13143: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13144: }
13145: } elsif ($confhash{'validation'}{'dc'} ne '') {
13146: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13147: }
1.160.6.65 raeburn 13148: } else {
13149: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13150: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13151: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13152: $changes{'validation'}{'dc'} = &mt('None');
13153: }
13154: }
1.160.6.39 raeburn 13155: }
13156: }
1.102 raeburn 13157: }
13158: } else {
1.86 raeburn 13159: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
13160: }
1.72 raeburn 13161: foreach my $item (@usertools) {
13162: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13163: my $unset;
1.101 raeburn 13164: if ($context eq 'requestcourses') {
1.104 raeburn 13165: $unset = '0';
13166: if ($type eq '_LC_adv') {
13167: $unset = '';
13168: }
1.101 raeburn 13169: if ($confhash{$item}{$type} eq 'autolimit') {
13170: $confhash{$item}{$type} .= '=';
13171: unless ($limithash{$item}{$type} =~ /\D/) {
13172: $confhash{$item}{$type} .= $limithash{$item}{$type};
13173: }
13174: }
1.160.6.5 raeburn 13175: } elsif ($context eq 'requestauthor') {
13176: $unset = '0';
13177: if ($type eq '_LC_adv') {
13178: $unset = '';
13179: }
1.72 raeburn 13180: } else {
1.101 raeburn 13181: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13182: $confhash{$item}{$type} = 1;
13183: } else {
13184: $confhash{$item}{$type} = 0;
13185: }
1.72 raeburn 13186: }
1.86 raeburn 13187: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 13188: if ($action eq 'requestauthor') {
13189: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13190: $changes{$type} = 1;
13191: }
13192: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13193: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13194: $changes{$item}{$type} = 1;
13195: }
13196: } else {
13197: if ($context eq 'requestcourses') {
1.104 raeburn 13198: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13199: $changes{$item}{$type} = 1;
13200: }
13201: } else {
13202: if (!$confhash{$item}{$type}) {
13203: $changes{$item}{$type} = 1;
13204: }
13205: }
13206: }
13207: } else {
13208: if ($context eq 'requestcourses') {
1.104 raeburn 13209: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13210: $changes{$item}{$type} = 1;
13211: }
1.160.6.5 raeburn 13212: } elsif ($context eq 'requestauthor') {
13213: if ($confhash{$type} ne $unset) {
13214: $changes{$type} = 1;
13215: }
1.72 raeburn 13216: } else {
13217: if (!$confhash{$item}{$type}) {
13218: $changes{$item}{$type} = 1;
13219: }
13220: }
13221: }
1.1 raeburn 13222: }
13223: }
1.160.6.5 raeburn 13224: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13225: if (ref($domconfig{'quotas'}) eq 'HASH') {
13226: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13227: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13228: if (exists($confhash{'defaultquota'}{$key})) {
13229: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13230: $changes{'defaultquota'}{$key} = 1;
13231: }
13232: } else {
13233: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13234: }
13235: }
1.86 raeburn 13236: } else {
13237: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13238: if (exists($confhash{'defaultquota'}{$key})) {
13239: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13240: $changes{'defaultquota'}{$key} = 1;
13241: }
13242: } else {
13243: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13244: }
1.1 raeburn 13245: }
13246: }
1.160.6.20 raeburn 13247: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.160.6.118.2 20(raebu 13248:24): $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
13249:24): }
13250:24): if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
13251:24): $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.160.6.20 raeburn 13252: }
1.1 raeburn 13253: }
1.86 raeburn 13254: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13255: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13256: if (ref($domconfig{'quotas'}) eq 'HASH') {
13257: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13258: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13259: $changes{'defaultquota'}{$key} = 1;
13260: }
13261: } else {
13262: if (!exists($domconfig{'quotas'}{$key})) {
13263: $changes{'defaultquota'}{$key} = 1;
13264: }
1.72 raeburn 13265: }
13266: } else {
1.86 raeburn 13267: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13268: }
1.1 raeburn 13269: }
13270: }
13271: }
1.72 raeburn 13272:
1.160.6.5 raeburn 13273: if ($context eq 'requestauthor') {
13274: $domdefaults{'requestauthor'} = \%confhash;
13275: } else {
13276: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 13277: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 13278: $domdefaults{$key} = $confhash{$key};
13279: }
1.160.6.5 raeburn 13280: }
1.72 raeburn 13281: }
1.160.6.5 raeburn 13282:
1.1 raeburn 13283: my %quotahash = (
1.86 raeburn 13284: $action => { %confhash }
1.1 raeburn 13285: );
13286: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13287: $dom);
13288: if ($putresult eq 'ok') {
13289: if (keys(%changes) > 0) {
1.72 raeburn 13290: my $cachetime = 24*60*60;
13291: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13292: if (ref($lastactref) eq 'HASH') {
13293: $lastactref->{'domdefaults'} = 1;
13294: }
1.1 raeburn 13295: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 13296: unless (($context eq 'requestcourses') ||
13297: ($context eq 'requestauthor')) {
1.86 raeburn 13298: if (ref($changes{'defaultquota'}) eq 'HASH') {
13299: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13300: foreach my $type (@{$types},'default') {
13301: if (defined($changes{'defaultquota'}{$type})) {
13302: my $typetitle = $usertypes->{$type};
13303: if ($type eq 'default') {
13304: $typetitle = $othertitle;
13305: }
1.160.6.28 raeburn 13306: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13307: }
13308: }
1.86 raeburn 13309: $resulttext .= '</ul></li>';
1.72 raeburn 13310: }
13311: }
1.80 raeburn 13312: my %newenv;
1.72 raeburn 13313: foreach my $item (@usertools) {
1.160.6.5 raeburn 13314: my (%haschgs,%inconf);
13315: if ($context eq 'requestauthor') {
13316: %haschgs = %changes;
13317: %inconf = %confhash;
13318: } else {
13319: if (ref($changes{$item}) eq 'HASH') {
13320: %haschgs = %{$changes{$item}};
13321: }
13322: if (ref($confhash{$item}) eq 'HASH') {
13323: %inconf = %{$confhash{$item}};
13324: }
13325: }
13326: if (keys(%haschgs) > 0) {
1.80 raeburn 13327: my $newacc =
13328: &Apache::lonnet::usertools_access($env{'user.name'},
13329: $env{'user.domain'},
1.86 raeburn 13330: $item,'reload',$context);
1.160.6.5 raeburn 13331: if (($context eq 'requestcourses') ||
13332: ($context eq 'requestauthor')) {
1.108 raeburn 13333: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13334: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13335: }
13336: } else {
13337: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13338: $newenv{'environment.availabletools.'.$item} = $newacc;
13339: }
1.80 raeburn 13340: }
1.160.6.5 raeburn 13341: unless ($context eq 'requestauthor') {
13342: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13343: }
1.72 raeburn 13344: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 13345: if ($haschgs{$type}) {
1.72 raeburn 13346: my $typetitle = $usertypes->{$type};
13347: if ($type eq 'default') {
13348: $typetitle = $othertitle;
13349: } elsif ($type eq '_LC_adv') {
13350: $typetitle = 'LON-CAPA Advanced Users';
13351: }
1.160.6.5 raeburn 13352: if ($inconf{$type}) {
1.101 raeburn 13353: if ($context eq 'requestcourses') {
13354: my $cond;
1.160.6.5 raeburn 13355: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13356: if ($1 eq '') {
13357: $cond = &mt('(Automatic processing of any request).');
13358: } else {
13359: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13360: }
13361: } else {
1.160.6.5 raeburn 13362: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13363: }
13364: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 13365: } elsif ($context eq 'requestauthor') {
13366: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13367: $titles{$inconf{$type}},$typetitle);
13368:
1.101 raeburn 13369: } else {
13370: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13371: }
1.72 raeburn 13372: } else {
1.104 raeburn 13373: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 13374: if ($inconf{$type} eq '0') {
1.104 raeburn 13375: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13376: } else {
13377: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13378: }
13379: } else {
13380: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13381: }
1.72 raeburn 13382: }
13383: }
1.26 raeburn 13384: }
1.160.6.5 raeburn 13385: unless ($context eq 'requestauthor') {
13386: $resulttext .= '</ul></li>';
13387: }
1.26 raeburn 13388: }
1.1 raeburn 13389: }
1.160.6.5 raeburn 13390: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13391: if (ref($changes{'notify'}) eq 'HASH') {
13392: if ($changes{'notify'}{'approval'}) {
13393: if (ref($confhash{'notify'}) eq 'HASH') {
13394: if ($confhash{'notify'}{'approval'}) {
13395: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13396: } else {
1.160.6.5 raeburn 13397: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13398: }
13399: }
13400: }
13401: }
13402: }
1.160.6.30 raeburn 13403: if ($action eq 'requestcourses') {
13404: my @offon = ('off','on');
13405: if ($changes{'uniquecode'}) {
13406: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13407: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13408: $resulttext .= '<li>'.
13409: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13410: '</li>';
13411: } else {
13412: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13413: '</li>';
13414: }
13415: }
1.160.6.46 raeburn 13416: foreach my $type ('textbooks','templates') {
13417: if (ref($changes{$type}) eq 'HASH') {
13418: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13419: foreach my $key (sort(keys(%{$changes{$type}}))) {
13420: my %coursehash = &Apache::lonnet::coursedescription($key);
13421: my $coursetitle = $coursehash{'description'};
13422: my $position = $confhash{$type}{$key}{'order'} + 1;
13423: $resulttext .= '<li>';
1.160.6.47 raeburn 13424: foreach my $item ('subject','title','publisher','author') {
13425: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13426: ($type eq 'templates'));
1.160.6.46 raeburn 13427: my $name = $item.':';
13428: $name =~ s/^(\w)/\U$1/;
13429: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13430: }
13431: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13432: if ($type eq 'textbooks') {
13433: if ($confhash{$type}{$key}{'image'}) {
13434: $resulttext .= ' '.&mt('Image: [_1]',
13435: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13436: ' alt="Textbook cover" />').'<br />';
13437: }
13438: }
13439: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 13440: }
1.160.6.46 raeburn 13441: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 13442: }
13443: }
1.160.6.39 raeburn 13444: if (ref($changes{'validation'}) eq 'HASH') {
13445: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13446: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13447: foreach my $item (@{$validationitemsref}) {
13448: if (exists($changes{'validation'}{$item})) {
13449: if ($item eq 'markup') {
13450: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13451: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13452: } else {
13453: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13454: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13455: }
13456: }
13457: }
13458: if (exists($changes{'validation'}{'dc'})) {
13459: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13460: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13461: }
1.160.6.118.2 24(raebu 13462:24): $resulttext .= '</ul></li>';
1.160.6.39 raeburn 13463: }
13464: }
1.160.6.30 raeburn 13465: }
1.1 raeburn 13466: $resulttext .= '</ul>';
1.80 raeburn 13467: if (keys(%newenv)) {
13468: &Apache::lonnet::appenv(\%newenv);
13469: }
1.1 raeburn 13470: } else {
1.86 raeburn 13471: if ($context eq 'requestcourses') {
13472: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 13473: } elsif ($context eq 'requestauthor') {
13474: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13475: } else {
1.90 weissno 13476: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13477: }
1.1 raeburn 13478: }
13479: } else {
1.11 albertel 13480: $resulttext = '<span class="LC_error">'.
13481: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13482: }
1.160.6.30 raeburn 13483: if ($errors) {
13484: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13485: '<ul>'.$errors.'</ul></p>';
13486: }
1.3 raeburn 13487: return $resulttext;
1.1 raeburn 13488: }
13489:
1.160.6.30 raeburn 13490: sub process_textbook_image {
1.160.6.46 raeburn 13491: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 13492: my $filename = $env{'form.'.$caller.'.filename'};
13493: my ($error,$url);
13494: my ($width,$height) = (50,50);
13495: if ($configuserok eq 'ok') {
13496: if ($switchserver) {
13497: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13498: $switchserver);
13499: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 13500:23): my $modified = [];
1.160.6.30 raeburn 13501: my ($result,$imageurl) =
1.160.6.118.2 14(raebu 13502:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
13503:23): "$type/$cdom/$cnum/cover",$width,$height,
13504:23): '',$modified);
1.160.6.30 raeburn 13505: if ($result eq 'ok') {
13506: $url = $imageurl;
1.160.6.118.2 14(raebu 13507:23): &update_modify_urls($r,$modified);
1.160.6.30 raeburn 13508: } else {
13509: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13510: }
13511: } else {
13512: $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);
13513: }
13514: } else {
13515: $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);
13516: }
13517: return ($url,$error);
13518: }
13519:
1.160.6.118.2 1(raebur 13520:1): sub modify_ltitools {
13521:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14(raebu 13522:23): my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
13523:23): &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
13524:23):
1(raebur 13525:1): my $confname = $dom.'-domainconfig';
13526:1): my $servadm = $r->dir_config('lonAdmEMail');
13527:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14(raebu 13528:23):
13529:23): my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
13530:23): my $toolserror =
13531:23): &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
13532:23): $lastactref,$configuserok,$switchserver,$author_ok);
13533:23):
13534:23): my $home = &Apache::lonnet::domain($dom,'primary');
13535:23): unless (($home eq 'no_host') || ($home eq '')) {
13536:23): my @ids=&Apache::lonnet::current_machine_ids();
13537:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
13538:23): }
13539:23):
13540:23): if (keys(%ltitoolschg)) {
13541:23): foreach my $id (keys(%ltitoolschg)) {
13542:23): if (ref($ltitoolschg{$id}) eq 'HASH') {
13543:23): foreach my $inner (keys(%{$ltitoolschg{$id}})) {
13544:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13545:23): if ($is_home) {
13546:23): $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
13547:23): }
13548:23): }
1(raebur 13549:1): }
14(raebu 13550:23): }
13551:23): }
13552:23): $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
13553:23): if (keys(%ltitoolschg)) {
13554:23): %newltitools = %ltitoolschg;
13555:23): }
13556:23): }
13557:23): if (ref($domconfig{'ltitools'}) eq 'HASH') {
13558:23): foreach my $id (%{$domconfig{'ltitools'}}) {
13559:23): next if ($id !~ /^\d+$/);
13560:23): unless (exists($ltitoolschg{$id})) {
13561:23): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
13562:23): foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
13563:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13564:23): if ($is_home) {
13565:23): $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13566:23): }
13567:23): } else {
13568:23): $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13569:23): }
1(raebur 13570:1): }
14(raebu 13571:23): } else {
13572:23): $newltitools{$id} = $domconfig{'ltitools'}{$id};
1(raebur 13573:1): }
13574:1): }
14(raebu 13575:23): }
13576:23): }
13577:23): if ($toolserror) {
13578:23): $errors = '<li>'.$toolserror.'</li>';
13579:23): }
13580:23): if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
13581:23): $resulttext = &mt('No changes made.');
13582:23): if ($errors) {
13583:23): $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13584:23): $errors.'</ul>';
13585:23): }
13586:23): return $resulttext;
13587:23): }
13588:23): my %ltitoolshash = (
13589:23): $action => { %newltitools }
13590:23): );
13591:23): if (keys(%secchanges)) {
13592:23): $ltitoolshash{'toolsec'} = \%newtoolsec;
13593:23): }
13594:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
13595:23): if ($putresult eq 'ok') {
13596:23): my %keystore;
13597:23): if ($is_home) {
13598:23): my %toolsenchash = (
13599:23): $action => { %newtoolsenc }
13600:23): );
13601:23): &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13602:23): my $cachetime = 24*60*60;
13603:23): &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13604:23): &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13605:23): }
13606:23): $resulttext = &mt('Changes made:').'<ul>';
13607:23): if (keys(%secchanges) > 0) {
13608:23): $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13609:23): }
13610:23): if (keys(%ltitoolschg) > 0) {
13611:23): $resulttext .= $ltitoolsoutput;
13612:23): }
13613:23): my $cachetime = 24*60*60;
13614:23): &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13615:23): if (ref($lastactref) eq 'HASH') {
13616:23): $lastactref->{'ltitools'} = 1;
13617:23): }
13618:23): } else {
13619:23): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13620:23): }
13621:23): if ($errors) {
13622:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13623:23): $errors.'</ul></p>';
13624:23): }
13625:23): return $resulttext;
13626:23): }
13627:23):
13628:23): sub fetch_secrets {
13629:23): my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13630:23): my %keyset;
13631:23): %{$currsec} = ();
13632:23): $newsec->{'private'}{'keys'} = [];
13633:23): $newsec->{'encrypt'} = {};
13634:23): $newsec->{'rules'} = {};
13635:23): if ($context eq 'ltisec') {
13636:23): $newsec->{'linkprot'} = {};
13637:23): }
13638:23): if (ref($domconfig->{$context}) eq 'HASH') {
13639:23): %{$currsec} = %{$domconfig->{$context}};
13640:23): if ($context eq 'ltisec') {
13641:23): if (ref($currsec->{'linkprot'}) eq 'HASH') {
13642:23): foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13643:23): unless ($id =~ /^\d+$/) {
13644:23): delete($currsec->{'linkprot'}{$id});
13645:23): }
13646:23): }
1(raebur 13647:1): }
14(raebu 13648:23): }
13649:23): if (ref($currsec->{'private'}) eq 'HASH') {
13650:23): if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13651:23): $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13652:23): map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1(raebur 13653:1): }
14(raebu 13654:23): }
13655:23): }
13656:23): my @items= ('crs','dom');
13657:23): if ($context eq 'ltisec') {
13658:23): push(@items,'consumers');
13659:23): }
13660:23): foreach my $item (@items) {
13661:23): my $formelement;
13662:23): if (($context eq 'toolsec') || ($item eq 'consumers')) {
13663:23): $formelement = 'form.'.$context.'_'.$item;
13664:23): } else {
13665:23): $formelement = 'form.'.$context.'_'.$item.'linkprot';
13666:23): }
13667:23): if ($env{$formelement}) {
13668:23): $newsec->{'encrypt'}{$item} = 1;
13669:23): if (ref($currsec->{'encrypt'}) eq 'HASH') {
13670:23): unless ($currsec->{'encrypt'}{$item}) {
13671:23): $secchanges->{'encrypt'} = 1;
13672:23): }
1(raebur 13673:1): } else {
14(raebu 13674:23): $secchanges->{'encrypt'} = 1;
13675:23): }
13676:23): } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13677:23): if ($currsec->{'encrypt'}{$item}) {
13678:23): $secchanges->{'encrypt'} = 1;
1(raebur 13679:1): }
14(raebu 13680:23): }
13681:23): }
13682:23): my $secrets;
13683:23): if ($context eq 'ltisec') {
13684:23): $secrets = 'ltisecrets';
13685:23): } else {
13686:23): $secrets = 'toolsecrets';
13687:23): }
13688:23): unless (exists($currsec->{'rules'})) {
13689:23): $currsec->{'rules'} = {};
13690:23): }
13691:23): &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13692:23):
13693:23): my @ids=&Apache::lonnet::current_machine_ids();
13694:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
13695:23):
13696:23): foreach my $hostid (keys(%servers)) {
13697:23): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13698:23): my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13699:23): if (exists($env{$keyitem})) {
13700:23): $env{$keyitem} =~ s/(`)/'/g;
13701:23): if ($keyset{$hostid}) {
13702:23): if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13703:23): if ($env{$keyitem} ne '') {
13704:23): $secchanges->{'private'} = 1;
13705:23): $newkeyset->{$hostid} = $env{$keyitem};
13706:23): }
1(raebur 13707:1): }
14(raebu 13708:23): } elsif ($env{$keyitem} ne '') {
13709:23): unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13710:23): push(@{$newsec->{'private'}{'keys'}},$hostid);
1(raebur 13711:1): }
14(raebu 13712:23): $secchanges->{'private'} = 1;
13713:23): $newkeyset->{$hostid} = $env{$keyitem};
1(raebur 13714:1): }
13715:1): }
14(raebu 13716:23): }
13717:23): }
13718:23): }
13719:23):
13720:23): sub store_security {
13721:23): my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13722:23): return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13723:23): (ref($keystore) eq 'HASH'));
13724:23): if (keys(%{$secchanges})) {
13725:23): if ($secchanges->{'private'}) {
13726:23): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13727:23): foreach my $hostid (keys(%{$newkeyset})) {
13728:23): my $storehash = {
13729:23): key => $newkeyset->{$hostid},
13730:23): who => $env{'user.name'}.':'.$env{'user.domain'},
13731:23): };
13732:23): $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13733:23): $dom,$hostid);
13734:23): }
13735:23): }
13736:23): }
13737:23): }
13738:23):
13739:23): sub lti_security_results {
13740:23): my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13741:23): my $output;
13742:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13743:23): my $needs_update;
13744:23): foreach my $item (keys(%{$secchanges})) {
13745:23): if ($item eq 'encrypt') {
13746:23): $needs_update = 1;
13747:23): my %encrypted;
13748:23): if ($context eq 'lti') {
13749:23): %encrypted = (
13750:23): crs => {
13751:23): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13752:23): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13753:23): },
13754:23): dom => {
13755:23): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13756:23): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13757:23): },
13758:23): consumers => {
13759:23): on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13760:23): off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13761:23): },
13762:23): );
1(raebur 13763:1): } else {
14(raebu 13764:23): %encrypted = (
13765:23): crs => {
13766:23): on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13767:23): off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13768:23): },
13769:23): dom => {
13770:23): on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13771:23): off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13772:23): },
13773:23): );
1(raebur 13774:1): }
14(raebu 13775:23): my @types= ('crs','dom');
13776:23): if ($context eq 'lti') {
13777:23): foreach my $type (@types) {
13778:23): undef($domdefaults{'linkprotenc_'.$type});
1(raebur 13779:1): }
14(raebu 13780:23): push(@types,'consumers');
13781:23): undef($domdefaults{'ltienc_consumers'});
13782:23): } elsif ($context eq 'ltitools') {
13783:23): foreach my $type (@types) {
13784:23): undef($domdefaults{'toolenc_'.$type});
1(raebur 13785:1): }
13786:1): }
14(raebu 13787:23): foreach my $type (@types) {
13788:23): my $shown = $encrypted{$type}{'off'};
13789:23): if (ref($newsec->{$item}) eq 'HASH') {
13790:23): if ($newsec->{$item}{$type}) {
13791:23): if ($context eq 'lti') {
13792:23): if ($type eq 'consumers') {
13793:23): $domdefaults{'ltienc_consumers'} = 1;
13794:23): } else {
13795:23): $domdefaults{'linkprotenc_'.$type} = 1;
1(raebur 13796:1): }
14(raebu 13797:23): } elsif ($context eq 'ltitools') {
13798:23): $domdefaults{'toolenc_'.$type} = 1;
1(raebur 13799:1): }
14(raebu 13800:23): $shown = $encrypted{$type}{'on'};
1(raebur 13801:1): }
13802:1): }
14(raebu 13803:23): $output .= '<li>'.$shown.'</li>';
13804:23): }
13805:23): } elsif ($item eq 'rules') {
13806:23): my %titles = &Apache::lonlocal::texthash(
13807:23): min => 'Minimum password length',
13808:23): max => 'Maximum password length',
13809:23): chars => 'Required characters',
13810:23): );
13811:23): foreach my $rule ('min','max') {
13812:23): if ($newsec->{rules}{$rule} eq '') {
13813:23): if ($rule eq 'min') {
13814:23): $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13815:23): ' '.&mt('Default of [_1] will be used',
13816:23): $Apache::lonnet::passwdmin).'</li>';
13817:23): } else {
13818:23): $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13819:23): }
13820:23): } else {
13821:23): $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13822:23): }
13823:23): }
13824:23): if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13825:23): if (@{$newsec->{'rules'}{'chars'}} > 0) {
13826:23): my %rulenames = &Apache::lonlocal::texthash(
13827:23): uc => 'At least one upper case letter',
13828:23): lc => 'At least one lower case letter',
13829:23): num => 'At least one number',
13830:23): spec => 'At least one non-alphanumeric',
13831:23): );
13832:23): my $needed = '<ul><li>'.
13833:23): join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13834:23): '</li></ul>';
13835:23): $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13836:23): } else {
13837:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13838:23): }
13839:23): } else {
13840:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1(raebur 13841:1): }
14(raebu 13842:23): } elsif ($item eq 'private') {
13843:23): $needs_update = 1;
13844:23): if ($context eq 'lti') {
13845:23): undef($domdefaults{'ltiprivhosts'});
13846:23): } elsif ($context eq 'ltitools') {
13847:23): undef($domdefaults{'toolprivhosts'});
13848:23): }
13849:23): if (keys(%{$newkeyset})) {
13850:23): my @privhosts;
13851:23): foreach my $hostid (sort(keys(%{$newkeyset}))) {
13852:23): if ($keystore->{$hostid} eq 'ok') {
13853:23): $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13854:23): unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13855:23): push(@privhosts,$hostid);
13856:23): }
13857:23): }
13858:23): }
13859:23): if (@privhosts) {
13860:23): if ($context eq 'lti') {
13861:23): $domdefaults{'ltiprivhosts'} = \@privhosts;
13862:23): } elsif ($context eq 'ltitools') {
13863:23): $domdefaults{'toolprivhosts'} = \@privhosts;
1(raebur 13864:1): }
13865:1): }
13866:1): }
14(raebu 13867:23): } elsif ($item eq 'linkprot') {
13868:23): next;
18(raebu 13869:24): } elsif ($item eq 'suggested') {
13870:24): if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
13871:24): (ref($newsec->{'suggested'}) eq 'HASH')) {
13872:24): my $suggestions;
13873:24): foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
13874:24): if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
13875:24): my $name = $newsec->{'suggested'}->{$id}->{'name'};
13876:24): my $info = $newsec->{'suggested'}->{$id}->{'info'};
13877:24): $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
13878:24): &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
13879:24): '</li>';
13880:24): } else {
13881:24): $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
13882:24): $newsec->{'suggested'}->{$id}).'</li>';
13883:24): }
13884:24): }
13885:24): if ($suggestions) {
13886:24): $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
13887:24): '<ul>'.$suggestions.'</ul>'.
13888:24): '</li>';
13889:24): }
13890:24): }
14(raebu 13891:23): }
13892:23): }
13893:23): if ($needs_update) {
13894:23): my $cachetime = 24*60*60;
13895:23): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13896:23): }
13897:23): return $output;
13898:23): }
13899:23):
13900:23): sub modify_lti {
13901:23): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13902:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13903:23): my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13904:23): my (%posslti,%posslticrs,%posscrstype);
13905:23): my @courseroles = ('cc','in','ta','ep','st');
13906:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13907:23): my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13908:23): my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13909:23): my %coursetypetitles = &Apache::lonlocal::texthash (
13910:23): official => 'Official',
13911:23): unofficial => 'Unofficial',
13912:23): community => 'Community',
13913:23): textbook => 'Textbook',
13914:23): placement => 'Placement Test',
13915:23): lti => 'LTI Provider',
13916:23): );
13917:23): my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13918:23): my %lt = <i_names();
13919:23): map { $posslti{$_} = 1; } @ltiroles;
13920:23): map { $posslticrs{$_} = 1; } @lticourseroles;
13921:23): map { $posscrstype{$_} = 1; } @coursetypes;
13922:23):
13923:23): my %menutitles = <imenu_titles();
13924:23): my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13925:23):
13926:23): &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13927:23):
13928:23): my (%linkprotchg,$linkprotoutput,$is_home);
13929:23): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13930:23): \%linkprotchg,'domain');
13931:23): my $home = &Apache::lonnet::domain($dom,'primary');
13932:23): unless (($home eq 'no_host') || ($home eq '')) {
13933:23): my @ids=&Apache::lonnet::current_machine_ids();
13934:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13935:23): }
13936:23):
13937:23): if (keys(%linkprotchg)) {
13938:23): $secchanges{'linkprot'} = 1;
13939:23): my %oldlinkprot;
13940:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13941:23): %oldlinkprot = %{$currltisec{'linkprot'}};
13942:23): }
13943:23): foreach my $id (keys(%linkprotchg)) {
13944:23): if (ref($linkprotchg{$id}) eq 'HASH') {
13945:23): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13946:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13947:23): if ($is_home) {
13948:23): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13949:23): }
13950:23): }
13951:23): }
13952:23): } else {
13953:23): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
1(raebur 13954:1): }
14(raebu 13955:23): }
13956:23): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13957:23): if (keys(%linkprotchg)) {
13958:23): %{$newltisec{'linkprot'}} = %linkprotchg;
13959:23): }
13960:23): }
13961:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
18(raebu 13962:24): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
14(raebu 13963:23): next if ($id !~ /^\d+$/);
13964:23): unless (exists($linkprotchg{$id})) {
13965:23): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
13966:23): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
13967:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13968:23): if ($is_home) {
13969:23): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13970:23): }
13971:23): } else {
13972:23): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
13973:23): }
13974:23): }
13975:23): } else {
13976:23): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
13977:23): }
1(raebur 13978:1): }
14(raebu 13979:23): }
13980:23): }
13981:23): if ($proterror) {
13982:23): $errors .= '<li>'.$proterror.'</li>';
13983:23): }
18(raebu 13984:24):
13985:24): my (%delsuggested,%suggids,@suggested);;
13986:24): if (ref($currltisec{'suggested'}) eq 'HASH') {
13987:24): my $maxnum = $env{'form.linkprot_suggested_maxnum'};
13988:24): my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
13989:24): for (my $i=0; $i<$maxnum; $i++) {
13990:24): my $itemid = $env{'form.linkprot_suggested_id_'.$i};
13991:24): $itemid =~ s/\D+//g;
13992:24): if ($itemid) {
13993:24): if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
13994:24): push(@suggested,$i);
13995:24): $suggids{$i} = $itemid;
13996:24): if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
13997:24): if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
13998:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
13999:24): }
14000:24): } else {
14001:24): if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
14002:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14003:24): } else {
14004:24): $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
14005:24): $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
14006:24): $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
14007:24): $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
14008:24): if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
14009:24): ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
14010:24): $secchanges{'suggested'}{$itemid} = 1;
14011:24): }
14012:24): }
14013:24): }
14014:24): }
14015:24): }
14016:24): }
14017:24): }
14018:24): foreach my $key (keys(%delsuggested)) {
14019:24): $newltisec{'suggested'}{$key} = $delsuggested{$key};
14020:24): $secchanges{'suggested'}{$key} = 1;
14021:24): }
14022:24): if (($env{'form.linkprot_suggested_add'}) &&
14023:24): ($env{'form.linkprot_suggested_name_add'} ne '')) {
14024:24): $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
14025:24): $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
14026:24): my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
14027:24): if ($newsuggid) {
14028:24): $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
14029:24): $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
14030:24): $secchanges{'suggested'}{$newsuggid} = 1;
14031:24): } else {
14032:24): my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
14033:24): if ($errormsg) {
14034:24): $error .= ' ('.$errormsg.')';
14035:24): }
14036:24): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14037:24): }
14038:24): }
14(raebu 14039:23): my (@items,%deletions,%itemids);
14040:23): if ($env{'form.lti_add'}) {
14041:23): my $consumer = $env{'form.lti_consumer_add'};
14042:23): $consumer =~ s/(`)/'/g;
19(raebu 14043:24): ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
14(raebu 14044:23): if ($newid) {
14045:23): $itemids{'add'} = $newid;
14046:23): push(@items,'add');
14047:23): $changes{$newid} = 1;
1(raebur 14048:1): } else {
14(raebu 14049:23): my $error = &mt('Failed to acquire unique ID for new LTI configuration');
18(raebu 14050:24): if ($errormsg) {
14051:24): $error .= ' ('.$errormsg.')';
14052:24): }
1(raebur 14053:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14054:1): }
14055:1): }
14056:1): if (ref($domconfig{$action}) eq 'HASH') {
14(raebu 14057:23): my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
1(raebur 14058:1): if (@todelete) {
14059:1): map { $deletions{$_} = 1; } @todelete;
14060:1): }
14(raebu 14061:23): my $maxnum = $env{'form.lti_maxnum'};
14062:23): for (my $i=0; $i<$maxnum; $i++) {
14063:23): my $itemid = $env{'form.lti_id_'.$i};
1(raebur 14064:1): $itemid =~ s/\D+//g;
14065:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14066:1): if ($deletions{$itemid}) {
14(raebu 14067:23): $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
1(raebur 14068:1): } else {
14(raebu 14069:23): push(@items,$i);
14070:23): $itemids{$i} = $itemid;
14071:23): }
14072:23): }
14073:23): }
14074:23): }
14075:23): my (%keystore,$secstored);
14076:23): if ($is_home) {
14077:23): &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
14078:23): }
14079:23):
14080:23): my ($cipher,$privnum);
14081:23): if ((@items > 0) && ($is_home)) {
14082:23): ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
14083:23): $newltisec{'encrypt'},$keystore{$home});
14084:23): }
14085:23): foreach my $idx (@items) {
14086:23): my $itemid = $itemids{$idx};
14087:23): next unless ($itemid);
14088:23): my %currlti;
14089:23): unless ($idx eq 'add') {
14090:23): if (ref($domconfig{$action}) eq 'HASH') {
14091:23): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14092:23): %currlti = %{$domconfig{$action}{$itemid}};
14093:23): }
14094:23): }
14095:23): }
14096:23): my $position = $env{'form.lti_pos_'.$itemid};
14097:23): $position =~ s/\D+//g;
14098:23): if ($position ne '') {
14099:23): $allpos[$position] = $itemid;
14100:23): }
14101:23): foreach my $item ('consumer','lifetime','requser','crsinc') {
14102:23): my $formitem = 'form.lti_'.$item.'_'.$idx;
14103:23): $env{$formitem} =~ s/(`)/'/g;
14104:23): if ($item eq 'lifetime') {
14105:23): $env{$formitem} =~ s/[^\d.]//g;
14106:23): }
14107:23): if ($env{$formitem} ne '') {
14108:23): $confhash{$itemid}{$item} = $env{$formitem};
14109:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14110:23): if ($currlti{$item} ne $confhash{$itemid}{$item}) {
14111:23): $changes{$itemid} = 1;
14112:23): }
14113:23): }
14114:23): }
14115:23): }
14116:23): if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14117:23): $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14118:23): }
14119:23): if ($confhash{$itemid}{'requser'}) {
14120:23): if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14121:23): $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14122:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14123:23): $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14124:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14125:23): my $mapuser = $env{'form.lti_customuser_'.$idx};
14126:23): $mapuser =~ s/(`)/'/g;
14127:23): $mapuser =~ s/^\s+|\s+$//g;
14128:23): $confhash{$itemid}{'mapuser'} = $mapuser;
14129:23): }
14130:23): my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14131:23): my @makeuser;
14132:23): foreach my $ltirole (sort(@possmakeuser)) {
14133:23): if ($posslti{$ltirole}) {
14134:23): push(@makeuser,$ltirole);
14135:23): }
14136:23): }
14137:23): $confhash{$itemid}{'makeuser'} = \@makeuser;
14138:23): if (@makeuser) {
14139:23): my $lcauth = $env{'form.lti_lcauth_'.$idx};
14140:23): if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14141:23): $confhash{$itemid}{'lcauth'} = $lcauth;
14142:23): if ($lcauth ne 'internal') {
14143:23): my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14144:23): $lcauthparm =~ s/^(\s+|\s+)$//g;
14145:23): $lcauthparm =~ s/`//g;
14146:23): if ($lcauthparm ne '') {
14147:23): $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
1(raebur 14148:1): }
14149:1): }
14(raebu 14150:23): } else {
14151:23): $confhash{$itemid}{'lcauth'} = 'lti';
14152:23): }
14153:23): }
14154:23): my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14155:23): if (@possinstdata) {
14156:23): foreach my $field (@possinstdata) {
14157:23): if (exists($fieldtitles{$field})) {
14158:23): push(@{$confhash{$itemid}{'instdata'}});
14159:23): }
14160:23): }
14161:23): }
14162:23): if ($env{'form.lti_callback_'.$idx}) {
14163:23): if ($env{'form.lti_callbackparam_'.$idx}) {
14164:23): my $callback = $env{'form.lti_callbackparam_'.$idx};
14165:23): $callback =~ s/^\s+|\s+$//g;
14166:23): $confhash{$itemid}{'callback'} = $callback;
14167:23): }
14168:23): }
14169:23): foreach my $field ('topmenu','inlinemenu') {
14170:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14171:23): $confhash{$itemid}{$field} = 1;
14172:23): }
14173:23): }
14174:23): if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14175:23): $confhash{$itemid}{lcmenu} = [];
14176:23): my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14177:23): foreach my $field (@possmenu) {
14178:23): if (exists($menutitles{$field})) {
14179:23): if ($field eq 'grades') {
14180:23): next unless ($env{'form.lti_inlinemenu_'.$idx});
1(raebur 14181:1): }
14(raebu 14182:23): push(@{$confhash{$itemid}{lcmenu}},$field);
14183:23): }
14184:23): }
14185:23): }
14186:23): if ($confhash{$itemid}{'crsinc'}) {
14187:23): if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14188:23): ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14189:23): $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14190:23): } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14191:23): my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14192:23): $mapcrs =~ s/(`)/'/g;
14193:23): $mapcrs =~ s/^\s+|\s+$//g;
14194:23): $confhash{$itemid}{'mapcrs'} = $mapcrs;
14195:23): }
14196:23): my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14197:23): my @crstypes;
14198:23): foreach my $type (sort(@posstypes)) {
14199:23): if ($posscrstype{$type}) {
14200:23): push(@crstypes,$type);
14201:23): }
14202:23): }
14203:23): $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14204:23): if ($env{'form.lti_storecrs_'.$idx}) {
14205:23): $confhash{$itemid}{'storecrs'} = 1;
14206:23): }
14207:23): if ($env{'form.lti_makecrs_'.$idx}) {
14208:23): $confhash{$itemid}{'makecrs'} = 1;
14209:23): }
14210:23): foreach my $ltirole (@lticourseroles) {
14211:23): my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14212:23): if (grep(/^\Q$possrole\E$/,@courseroles)) {
14213:23): $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
1(raebur 14214:1): }
14(raebu 14215:23): }
14216:23): my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14217:23): my @selfenroll;
14218:23): foreach my $type (sort(@possenroll)) {
14219:23): if ($posslticrs{$type}) {
14220:23): push(@selfenroll,$type);
14221:23): }
14222:23): }
14223:23): $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14224:23): if ($env{'form.lti_crssec_'.$idx}) {
14225:23): if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14226:23): $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14227:23): } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14228:23): my $section = $env{'form.lti_customsection_'.$idx};
14229:23): $section =~ s/(`)/'/g;
14230:23): $section =~ s/^\s+|\s+$//g;
14231:23): if ($section ne '') {
14232:23): $confhash{$itemid}{'section'} = $section;
14233:23): }
1(raebur 14234:1): }
14(raebu 14235:23): }
14236:23): foreach my $field ('passback','roster') {
14237:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14238:23): $confhash{$itemid}{$field} = 1;
1(raebur 14239:1): }
14(raebu 14240:23): }
14241:23): if ($env{'form.lti_passback_'.$idx}) {
14242:23): if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14243:23): $confhash{$itemid}{'passbackformat'} = '1.0';
1(raebur 14244:1): } else {
14(raebu 14245:23): $confhash{$itemid}{'passbackformat'} = '1.1';
1(raebur 14246:1): }
14(raebu 14247:23): }
14248:23): }
14249:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14250:23): if ($confhash{$itemid}{'crsinc'}) {
14251:23): foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
14252:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1(raebur 14253:1): $changes{$itemid} = 1;
14254:1): }
14255:1): }
14(raebu 14256:23): unless ($changes{$itemid}) {
14257:23): if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
14258:23): if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1(raebur 14259:1): $changes{$itemid} = 1;
14260:1): }
14261:1): }
14262:1): }
14(raebu 14263:23): foreach my $field ('mapcrstype','selfenroll') {
14264:23): unless ($changes{$itemid}) {
14265:23): if (ref($currlti{$field}) eq 'ARRAY') {
14266:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14267:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14268:23): $confhash{$itemid}{$field});
14269:23): if (@diffs) {
14270:23): $changes{$itemid} = 1;
14271:23): }
14272:23): } elsif (@{$currlti{$field}} > 0) {
1(raebur 14273:1): $changes{$itemid} = 1;
14274:1): }
14(raebu 14275:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14276:23): if (@{$confhash{$itemid}{$field}} > 0) {
1(raebur 14277:1): $changes{$itemid} = 1;
14278:1): }
14279:1): }
14280:1): }
14281:1): }
14(raebu 14282:23): unless ($changes{$itemid}) {
14283:23): if (ref($currlti{'maproles'}) eq 'HASH') {
14284:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14285:23): foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
14286:23): if ($currlti{'maproles'}{$ltirole} ne
14287:23): $confhash{$itemid}{'maproles'}{$ltirole}) {
14288:23): $changes{$itemid} = 1;
14289:23): last;
1(raebur 14290:1): }
14(raebu 14291:23): }
14292:23): unless ($changes{$itemid}) {
14293:23): foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14294:23): if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14295:23): $currlti{'maproles'}{$ltirole}) {
1(raebur 14296:1): $changes{$itemid} = 1;
14(raebu 14297:23): last;
1(raebur 14298:1): }
14299:1): }
14300:1): }
14(raebu 14301:23): } elsif (keys(%{$currlti{'maproles'}}) > 0) {
14302:23): $changes{$itemid} = 1;
14303:23): }
14304:23): } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14305:23): unless ($changes{$itemid}) {
14306:23): if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
1(raebur 14307:1): $changes{$itemid} = 1;
14308:1): }
14309:1): }
14310:1): }
14311:1): }
14(raebu 14312:23): }
14313:23): unless ($changes{$itemid}) {
14314:23): foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
14315:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
14316:23): $changes{$itemid} = 1;
14317:23): }
14318:23): }
14319:23): unless ($changes{$itemid}) {
14320:23): foreach my $field ('makeuser','lcmenu') {
14321:23): if (ref($currlti{$field}) eq 'ARRAY') {
14322:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14323:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14324:23): $confhash{$itemid}{$field});
14325:23): if (@diffs) {
14326:23): $changes{$itemid} = 1;
14327:23): }
14328:23): } elsif (@{$currlti{$field}} > 0) {
14329:23): $changes{$itemid} = 1;
14330:23): }
14331:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14332:23): if (@{$confhash{$itemid}{$field}} > 0) {
14333:23): $changes{$itemid} = 1;
14334:23): }
1(raebur 14335:1): }
14336:1): }
14337:1): }
14338:1): }
14(raebu 14339:23): }
14340:23): }
14341:23): if ($is_home) {
14342:23): my $keyitem = 'form.lti_key_'.$idx;
14343:23): $env{$keyitem} =~ s/(`)/'/g;
14344:23): if ($env{$keyitem} ne '') {
14345:23): $ltienc{$itemid}{'key'} = $env{$keyitem};
14346:23): unless ($changes{$itemid}) {
14347:23): if ($currlti{'key'} ne $env{$keyitem}) {
1(raebur 14348:1): $changes{$itemid} = 1;
14349:1): }
14(raebu 14350:23): }
14351:23): }
14352:23): my $secretitem = 'form.lti_secret_'.$idx;
14353:23): $env{$secretitem} =~ s/(`)/'/g;
14354:23): if ($currlti{'usable'}) {
14355:23): if ($env{'form.lti_changesecret_'.$idx}) {
14356:23): if ($env{$secretitem} ne '') {
14357:23): if ($privnum && $cipher) {
14358:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14359:23): $confhash{$itemid}{'cipher'} = $privnum;
14360:23): } else {
14361:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14362:23): }
1(raebur 14363:1): $changes{$itemid} = 1;
14364:1): }
14(raebu 14365:23): } else {
14366:23): $ltienc{$itemid}{'secret'} = $currlti{'secret'};
14367:23): $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
1(raebur 14368:1): }
14(raebu 14369:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14370:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
14371:23): $confhash{$itemid}{'usable'} = 1;
14372:23): }
1(raebur 14373:1): }
14(raebu 14374:23): } elsif ($env{$secretitem} ne '') {
14375:23): if ($privnum && $cipher) {
14376:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14377:23): $confhash{$itemid}{'cipher'} = $privnum;
14378:23): } else {
14379:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14380:23): }
14381:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14382:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
14383:23): $confhash{$itemid}{'usable'} = 1;
1(raebur 14384:1): }
14385:1): }
14(raebu 14386:23): $changes{$itemid} = 1;
14387:23): }
14388:23): }
14389:23): unless ($changes{$itemid}) {
14390:23): foreach my $key (keys(%currlti)) {
14391:23): if (ref($currlti{$key}) eq 'HASH') {
14392:23): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
14393:23): foreach my $innerkey (keys(%{$currlti{$key}})) {
14394:23): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
1(raebur 14395:1): $changes{$itemid} = 1;
14(raebu 14396:23): last;
1(raebur 14397:1): }
14398:1): }
14(raebu 14399:23): } elsif (keys(%{$currlti{$key}}) > 0) {
14400:23): $changes{$itemid} = 1;
1(raebur 14401:1): }
14402:1): }
14(raebu 14403:23): last if ($changes{$itemid});
1(raebur 14404:1): }
14405:1): }
14406:1): }
14407:1): if (@allpos > 0) {
14408:1): my $idx = 0;
14409:1): foreach my $itemid (@allpos) {
14410:1): if ($itemid ne '') {
14411:1): $confhash{$itemid}{'order'} = $idx;
14412:1): if (ref($domconfig{$action}) eq 'HASH') {
14413:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14414:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14415:1): $changes{$itemid} = 1;
14416:1): }
14417:1): }
14418:1): }
14419:1): $idx ++;
14420:1): }
14421:1): }
14422:1): }
14(raebu 14423:23):
14424:23): if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
14425:23): return &mt('No changes made.');
14426:23): }
14427:23):
14428:23): my %ltihash = (
14429:23): $action => { %confhash }
14430:23): );
14431:23): my %ltienchash;
14432:23):
14433:23): if ($is_home) {
14434:23): %ltienchash = (
14435:23): $action => { %ltienc }
14436:23): );
14437:23): }
14438:23): if (keys(%secchanges)) {
14439:23): $ltihash{'ltisec'} = \%newltisec;
14440:23): if ($secchanges{'linkprot'}) {
14441:23): if ($is_home) {
14442:23): $ltienchash{'linkprot'} = \%newltienc;
14443:23): }
14444:23): }
14445:23): }
14446:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1(raebur 14447:1): if ($putresult eq 'ok') {
14(raebu 14448:23): if (keys(%ltienchash)) {
14449:23): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
14450:23): }
14451:23): $resulttext = &mt('Changes made:').'<ul>';
14452:23): if (keys(%secchanges) > 0) {
14453:23): $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
14454:23): if (exists($secchanges{'linkprot'})) {
14455:23): $resulttext .= $linkprotoutput;
14456:23): }
14457:23): }
1(raebur 14458:1): if (keys(%changes) > 0) {
14459:1): my $cachetime = 24*60*60;
14(raebu 14460:23): &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1(raebur 14461:1): if (ref($lastactref) eq 'HASH') {
14(raebu 14462:23): $lastactref->{'lti'} = 1;
1(raebur 14463:1): }
14464:1): my %bynum;
14465:1): foreach my $itemid (sort(keys(%changes))) {
14(raebu 14466:23): if (ref($confhash{$itemid}) eq 'HASH') {
14467:23): my $position = $confhash{$itemid}{'order'};
14468:23): $bynum{$position} = $itemid;
14469:23): }
1(raebur 14470:1): }
14471:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14472:1): my $itemid = $bynum{$pos};
14(raebu 14473:23): if (ref($confhash{$itemid}) eq 'HASH') {
14474:23): $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1(raebur 14475:1): my $position = $pos + 1;
14476:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14(raebu 14477:23): foreach my $item ('version','lifetime') {
1(raebur 14478:1): if ($confhash{$itemid}{$item} ne '') {
14479:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14480:1): }
14481:1): }
14(raebu 14482:23): if ($ltienc{$itemid}{'key'} ne '') {
14483:23): $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
14484:23): }
14485:23): if ($ltienc{$itemid}{'secret'} ne '') {
14486:23): $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1(raebur 14487:1): }
14(raebu 14488:23): if ($confhash{$itemid}{'requser'}) {
14489:23): if ($confhash{$itemid}{'callback'}) {
14490:23): $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14491:23): } else {
14492:23): $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
14493:23): }
14494:23): if ($confhash{$itemid}{'mapuser'}) {
14495:23): my $shownmapuser;
14496:23): if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14497:23): $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14498:23): } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14499:23): $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14500:23): } else {
14501:23): $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
14502:23): }
14503:23): $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
14504:23): }
14505:23): if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14506:23): if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14507:23): $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14508:23): join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14509:23): if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14510:23): $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14511:23): } else {
14512:23): $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14513:23): $confhash{$itemid}{'lcauth'});
14514:23): if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14515:23): $resulttext .= '; '.&mt('a randomly generated password will be created');
14516:23): } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14517:23): if ($confhash{$itemid}{'lcauthparm'} ne '') {
14518:23): $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14519:23): }
14520:23): } else {
14521:23): $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14522:23): }
14523:23): }
14524:23): $resulttext .= '</li>';
14525:23): } else {
14526:23): $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
1(raebur 14527:1): }
14528:1): }
14(raebu 14529:23): if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14530:23): if (@{$confhash{$itemid}{'instdata'}} > 0) {
14531:23): $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14532:23): join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
14533:23): } else {
14534:23): $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1(raebur 14535:1): }
14536:1): }
14(raebu 14537:23): foreach my $item ('topmenu','inlinemenu') {
14538:23): $resulttext .= '<li>'.$lt{$item}.': ';
14539:23): if ($confhash{$itemid}{$item}) {
14540:23): $resulttext .= &mt('Yes');
14541:23): } else {
14542:23): $resulttext .= &mt('No');
1(raebur 14543:1): }
14(raebu 14544:23): $resulttext .= '</li>';
1(raebur 14545:1): }
14(raebu 14546:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14547:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14548:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14549:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14550:23): } else {
14551:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
1(raebur 14552:1): }
14553:1): }
14(raebu 14554:23): if ($confhash{$itemid}{'crsinc'}) {
14555:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14556:23): my $rolemaps;
14557:23): foreach my $role (@ltiroles) {
14558:23): if ($confhash{$itemid}{'maproles'}{$role}) {
14559:23): $rolemaps .= (' 'x2).$role.'='.
14560:23): &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14561:23): 'Course').',';
14562:23): }
14563:23): }
14564:23): if ($rolemaps) {
14565:23): $rolemaps =~ s/,$//;
14566:23): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14567:23): }
14568:23): }
14569:23): if ($confhash{$itemid}{'mapcrs'}) {
14570:23): $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14571:23): }
14572:23): if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14573:23): if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14574:23): $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14575:23): join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14576:23): '</li>';
1(raebur 14577:1): } else {
14(raebu 14578:23): $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
1(raebur 14579:1): }
14580:1): }
14(raebu 14581:23): if ($confhash{$itemid}{'storecrs'}) {
14582:23): $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
1(raebur 14583:1): }
14(raebu 14584:23): if ($confhash{$itemid}{'makecrs'}) {
14585:23): $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
14586:23): } else {
14587:23): $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
14588:23): }
14589:23): if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14590:23): if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14591:23): $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14592:23): join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14593:23): '</li>';
14594:23): } else {
14595:23): $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14596:23): }
14597:23): }
14598:23): if ($confhash{$itemid}{'section'}) {
14599:23): if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14600:23): $resulttext .= '<li>'.&mt('User section from standard field:').
14601:23): ' (course_section_sourcedid)'.'</li>';
14602:23): } else {
14603:23): $resulttext .= '<li>'.&mt('User section from:').' '.
14604:23): $confhash{$itemid}{'section'}.'</li>';
14605:23): }
14606:23): } else {
14607:23): $resulttext .= '<li>'.&mt('No section assignment').'</li>';
14608:23): }
14609:23): foreach my $item ('passback','roster','topmenu','inlinemenu') {
14610:23): $resulttext .= '<li>'.$lt{$item}.': ';
14611:23): if ($confhash{$itemid}{$item}) {
14612:23): $resulttext .= &mt('Yes');
14613:23): if ($item eq 'passback') {
14614:23): if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14615:23): $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14616:23): } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14617:23): $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14618:23): }
14619:23): }
14620:23): } else {
14621:23): $resulttext .= &mt('No');
14622:23): }
14623:23): $resulttext .= '</li>';
14624:23): }
14625:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14626:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14627:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14628:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14629:23): } else {
14630:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14631:23): }
1(raebur 14632:1): }
14633:1): }
14634:1): }
14635:1): $resulttext .= '</ul></li>';
14636:1): }
14637:1): }
14(raebu 14638:23): if (keys(%deletions)) {
14639:23): foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
14640:23): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14641:23): }
14642:23): }
14643:23): }
14644:23): $resulttext .= '</ul>';
14645:23): if (ref($lastactref) eq 'HASH') {
18(raebu 14646:24): if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
14647:24): &Apache::lonnet::get_domain_defaults($dom,1);
14(raebu 14648:23): $lastactref->{'domdefaults'} = 1;
14649:23): }
1(raebur 14650:1): }
14651:1): } else {
14652:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14653:1): }
14654:1): if ($errors) {
14655:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14656:1): $errors.'</ul>';
14657:1): }
14658:1): return $resulttext;
14659:1): }
14660:1):
14(raebu 14661:23): sub get_priv_creds {
14662:23): my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
14663:23): my ($needenc,$cipher,$privnum);
14664:23): my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
14665:23): if (($encchg) && (ref($encrypt) eq 'HASH')) {
14666:23): $needenc = $encrypt->{'consumers'}
14667:23): } else {
14668:23): $needenc = $domdefs{'ltienc_consumers'};
14669:23): }
14670:23): if ($needenc) {
14671:23): if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
14672:23): (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
14673:23): my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
14674:23): my $privkey = $privhash{'key'};
14675:23): $privnum = $privhash{'version'};
14676:23): if (($privnum) && ($privkey ne '')) {
14677:23): $cipher = Crypt::CBC->new({'key' => $privkey,
14678:23): 'cipher' => 'DES'});
1(raebur 14679:1): }
14680:1): }
14681:1): }
14(raebu 14682:23): return ($cipher,$privnum);
1(raebur 14683:1): }
14684:1):
14(raebu 14685:23): sub get_lti_id {
18(raebu 14686:24): my ($domain,$consumer,$dbname) = @_;
14687:24): unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
14688:24): return ('','invalid db');
14689:24): }
14690:24): # get lock on db
1(raebur 14691:1): my $lockhash = {
14692:1): lock => $env{'user.name'}.
14693:1): ':'.$env{'user.domain'},
14694:1): };
14695:1): my $tries = 0;
18(raebu 14696:24): my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14697:1): my ($id,$error);
14698:1):
14699:1): while (($gotlock ne 'ok') && ($tries<10)) {
14700:1): $tries ++;
14701:1): sleep (0.1);
18(raebu 14702:24): $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14703:1): }
14704:1): if ($gotlock eq 'ok') {
18(raebu 14705:24): my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1(raebur 14706:1): if ($currids{'lock'}) {
14707:1): delete($currids{'lock'});
14708:1): if (keys(%currids)) {
14709:1): my @curr = sort { $a <=> $b } keys(%currids);
14710:1): if ($curr[-1] =~ /^\d+$/) {
14711:1): $id = 1 + $curr[-1];
14712:1): }
14713:1): } else {
14714:1): $id = 1;
14715:1): }
14716:1): if ($id) {
18(raebu 14717:24): unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1(raebur 14718:1): $error = 'nostore';
14719:1): }
14720:1): } else {
14721:1): $error = 'nonumber';
14722:1): }
14723:1): }
18(raebu 14724:24): my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1(raebur 14725:1): } else {
14726:1): $error = 'nolock';
14727:1): }
14728:1): return ($id,$error);
14729:1): }
14730:1):
1.3 raeburn 14731: sub modify_autoenroll {
1.160.6.24 raeburn 14732: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14733: my ($resulttext,%changes);
14734: my %currautoenroll;
14735: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14736: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14737: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14738: }
14739: }
14740: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14741: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14742: sender => 'Sender for notification messages',
1.160.6.68 raeburn 14743: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 14744: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14745: my @offon = ('off','on');
1.17 raeburn 14746: my $sender_uname = $env{'form.sender_uname'};
14747: my $sender_domain = $env{'form.sender_domain'};
14748: if ($sender_domain eq '') {
14749: $sender_uname = '';
14750: } elsif ($sender_uname eq '') {
14751: $sender_domain = '';
14752: }
1.129 raeburn 14753: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 14754: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14755: $autofailsafe =~ s{^\s+|\s+$}{}g;
14756: if ($autofailsafe =~ /\D/) {
14757: undef($autofailsafe);
14758: }
1.160.6.68 raeburn 14759: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 14760: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14761: $failsafe = 'off';
14762: undef($autofailsafe);
1.160.6.68 raeburn 14763: }
1.1 raeburn 14764: my %autoenrollhash = (
1.129 raeburn 14765: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14766: 'sender_uname' => $sender_uname,
14767: 'sender_domain' => $sender_domain,
14768: 'co-owners' => $coowners,
1.160.6.116 raeburn 14769: 'autofailsafe' => $autofailsafe,
14770: 'failsafe' => $failsafe,
1.1 raeburn 14771: }
14772: );
1.4 raeburn 14773: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14774: $dom);
1.1 raeburn 14775: if ($putresult eq 'ok') {
14776: if (exists($currautoenroll{'run'})) {
14777: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14778: $changes{'run'} = 1;
14779: }
14780: } elsif ($autorun) {
14781: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14782: $changes{'run'} = 1;
1.1 raeburn 14783: }
14784: }
1.17 raeburn 14785: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14786: $changes{'sender'} = 1;
14787: }
1.17 raeburn 14788: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14789: $changes{'sender'} = 1;
14790: }
1.129 raeburn 14791: if ($currautoenroll{'co-owners'} ne '') {
14792: if ($currautoenroll{'co-owners'} ne $coowners) {
14793: $changes{'coowners'} = 1;
14794: }
14795: } elsif ($coowners) {
14796: $changes{'coowners'} = 1;
1.160.6.68 raeburn 14797: }
1.160.6.116 raeburn 14798: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 14799: $changes{'autofailsafe'} = 1;
14800: }
1.160.6.116 raeburn 14801: if ($currautoenroll{'failsafe'} ne $failsafe) {
14802: $changes{'failsafe'} = 1;
14803: }
1.1 raeburn 14804: if (keys(%changes) > 0) {
14805: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14806: if ($changes{'run'}) {
1.1 raeburn 14807: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14808: }
14809: if ($changes{'sender'}) {
1.17 raeburn 14810: if ($sender_uname eq '' || $sender_domain eq '') {
14811: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14812: } else {
14813: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14814: }
1.1 raeburn 14815: }
1.129 raeburn 14816: if ($changes{'coowners'}) {
14817: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14818: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14819: if (ref($lastactref) eq 'HASH') {
14820: $lastactref->{'domainconfig'} = 1;
14821: }
1.129 raeburn 14822: }
1.160.6.68 raeburn 14823: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 14824: if ($autofailsafe ne '') {
14825: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 14826: } else {
1.160.6.116 raeburn 14827: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 14828: }
1.160.6.116 raeburn 14829: }
14830: if ($changes{'failsafe'}) {
14831: if ($failsafe eq 'off') {
14832: unless ($changes{'autofailsafe'}) {
14833: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14834: }
14835: } elsif ($failsafe eq 'zero') {
14836: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14837: } else {
14838: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14839: }
14840: }
14841: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 14842: &Apache::lonnet::get_domain_defaults($dom,1);
14843: if (ref($lastactref) eq 'HASH') {
14844: $lastactref->{'domdefaults'} = 1;
14845: }
14846: }
1.1 raeburn 14847: $resulttext .= '</ul>';
14848: } else {
14849: $resulttext = &mt('No changes made to auto-enrollment settings');
14850: }
14851: } else {
1.11 albertel 14852: $resulttext = '<span class="LC_error">'.
14853: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14854: }
1.3 raeburn 14855: return $resulttext;
1.1 raeburn 14856: }
14857:
14858: sub modify_autoupdate {
1.3 raeburn 14859: my ($dom,%domconfig) = @_;
1.1 raeburn 14860: my ($resulttext,%currautoupdate,%fields,%changes);
14861: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14862: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14863: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14864: }
14865: }
14866: my @offon = ('off','on');
14867: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 14868: run => 'Auto-update:',
14869: classlists => 'Updates to user information in classlists?',
14870: unexpired => 'Skip updates for users without active or future roles?',
14871: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 14872: );
1.44 raeburn 14873: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14874: my %fieldtitles = &Apache::lonlocal::texthash (
14875: id => 'Student/Employee ID',
1.20 raeburn 14876: permanentemail => 'E-mail address',
1.1 raeburn 14877: lastname => 'Last Name',
14878: firstname => 'First Name',
14879: middlename => 'Middle Name',
1.132 raeburn 14880: generation => 'Generation',
1.1 raeburn 14881: );
1.142 raeburn 14882: $othertitle = &mt('All users');
1.1 raeburn 14883: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14884: $othertitle = &mt('Other users');
1.1 raeburn 14885: }
14886: foreach my $key (keys(%env)) {
14887: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14888: my ($usertype,$item) = ($1,$2);
14889: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14890: if ($usertype eq 'default') {
14891: push(@{$fields{$1}},$2);
14892: } elsif (ref($types) eq 'ARRAY') {
14893: if (grep(/^\Q$usertype\E$/,@{$types})) {
14894: push(@{$fields{$1}},$2);
14895: }
14896: }
14897: }
1.1 raeburn 14898: }
14899: }
1.131 raeburn 14900: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14901: @lockablenames = sort(@lockablenames);
14902: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14903: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14904: if (@changed) {
14905: $changes{'lockablenames'} = 1;
14906: }
14907: } else {
14908: if (@lockablenames) {
14909: $changes{'lockablenames'} = 1;
14910: }
14911: }
1.1 raeburn 14912: my %updatehash = (
14913: autoupdate => { run => $env{'form.autoupdate_run'},
14914: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 14915: unexpired => $env{'form.unexpired'},
1.1 raeburn 14916: fields => {%fields},
1.131 raeburn 14917: lockablenames => \@lockablenames,
1.1 raeburn 14918: }
14919: );
1.160.6.113 raeburn 14920: my $lastactivedays;
14921: if ($env{'form.lastactive'}) {
14922: $lastactivedays = $env{'form.lastactivedays'};
14923: $lastactivedays =~ s/^\s+|\s+$//g;
14924: unless ($lastactivedays =~ /^\d+$/) {
14925: undef($lastactivedays);
14926: $env{'form.lastactive'} = 0;
14927: }
14928: }
14929: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 14930: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 14931: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 14932: if (exists($updatehash{autoupdate}{$key})) {
14933: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14934: $changes{$key} = 1;
14935: }
14936: }
14937: } elsif ($key eq 'fields') {
14938: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14939: foreach my $item (@{$types},'default') {
1.1 raeburn 14940: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14941: my $change = 0;
14942: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14943: if (!exists($fields{$item})) {
14944: $change = 1;
1.132 raeburn 14945: last;
1.1 raeburn 14946: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14947: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14948: $change = 1;
1.132 raeburn 14949: last;
1.1 raeburn 14950: }
14951: }
14952: }
14953: if ($change) {
14954: push(@{$changes{$key}},$item);
14955: }
1.26 raeburn 14956: }
1.1 raeburn 14957: }
14958: }
1.131 raeburn 14959: } elsif ($key eq 'lockablenames') {
14960: if (ref($currautoupdate{$key}) eq 'ARRAY') {
14961: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14962: if (@changed) {
14963: $changes{'lockablenames'} = 1;
14964: }
14965: } else {
14966: if (@lockablenames) {
14967: $changes{'lockablenames'} = 1;
14968: }
14969: }
14970: }
14971: }
14972: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
14973: if (@lockablenames) {
14974: $changes{'lockablenames'} = 1;
1.1 raeburn 14975: }
14976: }
1.160.6.113 raeburn 14977: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
14978: if ($updatehash{'autoupdate'}{'unexpired'}) {
14979: $changes{'unexpired'} = 1;
14980: }
14981: }
14982: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
14983: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
14984: $changes{'lastactive'} = 1;
14985: }
14986: }
1.26 raeburn 14987: foreach my $item (@{$types},'default') {
14988: if (defined($fields{$item})) {
14989: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 14990: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
14991: my $change = 0;
14992: if (ref($fields{$item}) eq 'ARRAY') {
14993: foreach my $type (@{$fields{$item}}) {
14994: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
14995: $change = 1;
14996: last;
14997: }
14998: }
14999: }
15000: if ($change) {
15001: push(@{$changes{'fields'}},$item);
15002: }
15003: } else {
1.26 raeburn 15004: push(@{$changes{'fields'}},$item);
15005: }
15006: } else {
15007: push(@{$changes{'fields'}},$item);
1.1 raeburn 15008: }
15009: }
15010: }
15011: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15012: $dom);
15013: if ($putresult eq 'ok') {
15014: if (keys(%changes) > 0) {
15015: $resulttext = &mt('Changes made:').'<ul>';
15016: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15017: if ($key eq 'lockablenames') {
15018: $resulttext .= '<li>';
15019: if (@lockablenames) {
15020: $usertypes->{'default'} = $othertitle;
15021: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15022: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15023: } else {
15024: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15025: }
15026: $resulttext .= '</li>';
15027: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15028: foreach my $item (@{$changes{$key}}) {
15029: my @newvalues;
15030: foreach my $type (@{$fields{$item}}) {
15031: push(@newvalues,$fieldtitles{$type});
15032: }
1.3 raeburn 15033: my $newvaluestr;
15034: if (@newvalues > 0) {
15035: $newvaluestr = join(', ',@newvalues);
15036: } else {
15037: $newvaluestr = &mt('none');
1.6 raeburn 15038: }
1.1 raeburn 15039: if ($item eq 'default') {
1.26 raeburn 15040: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15041: } else {
1.26 raeburn 15042: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15043: }
15044: }
15045: } else {
15046: my $newvalue;
15047: if ($key eq 'run') {
15048: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 15049: } elsif ($key eq 'lastactive') {
15050: $newvalue = $offon[$env{'form.lastactive'}];
15051: unless ($lastactivedays eq '') {
15052: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15053: }
1.1 raeburn 15054: } else {
15055: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15056: }
1.1 raeburn 15057: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15058: }
15059: }
15060: $resulttext .= '</ul>';
15061: } else {
1.3 raeburn 15062: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15063: }
15064: } else {
1.11 albertel 15065: $resulttext = '<span class="LC_error">'.
15066: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15067: }
1.3 raeburn 15068: return $resulttext;
1.1 raeburn 15069: }
15070:
1.125 raeburn 15071: sub modify_autocreate {
15072: my ($dom,%domconfig) = @_;
15073: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15074: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15075: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15076: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15077: }
15078: }
15079: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15080: req => 'Auto-creation of validated requests for official courses',
15081: xmldc => 'Identity of course creator of courses from XML files',
15082: );
15083: my @types = ('xml','req');
15084: foreach my $item (@types) {
15085: $newvals{$item} = $env{'form.autocreate_'.$item};
15086: $newvals{$item} =~ s/\D//g;
15087: $newvals{$item} = 0 if ($newvals{$item} eq '');
15088: }
15089: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 15090: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15091: unless (exists($domcoords{$newvals{'xmldc'}})) {
15092: $newvals{'xmldc'} = '';
15093: }
15094: %autocreatehash = (
15095: autocreate => { xml => $newvals{'xml'},
15096: req => $newvals{'req'},
15097: }
15098: );
15099: if ($newvals{'xmldc'} ne '') {
15100: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15101: }
15102: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15103: $dom);
15104: if ($putresult eq 'ok') {
15105: my @items = @types;
15106: if ($newvals{'xml'}) {
15107: push(@items,'xmldc');
15108: }
15109: foreach my $item (@items) {
15110: if (exists($currautocreate{$item})) {
15111: if ($currautocreate{$item} ne $newvals{$item}) {
15112: $changes{$item} = 1;
15113: }
15114: } elsif ($newvals{$item}) {
15115: $changes{$item} = 1;
15116: }
15117: }
15118: if (keys(%changes) > 0) {
15119: my @offon = ('off','on');
15120: $resulttext = &mt('Changes made:').'<ul>';
15121: foreach my $item (@types) {
15122: if ($changes{$item}) {
15123: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 15124: $resulttext .= '<li>'.
15125: &mt("$title{$item} set to [_1]$newtxt [_2]",
15126: '<b>','</b>').
15127: '</li>';
1.125 raeburn 15128: }
15129: }
15130: if ($changes{'xmldc'}) {
15131: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15132: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 15133: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15134: }
15135: $resulttext .= '</ul>';
15136: } else {
15137: $resulttext = &mt('No changes made to auto-creation settings');
15138: }
15139: } else {
15140: $resulttext = '<span class="LC_error">'.
15141: &mt('An error occurred: [_1]',$putresult).'</span>';
15142: }
15143: return $resulttext;
15144: }
15145:
1.23 raeburn 15146: sub modify_directorysrch {
1.160.6.81 raeburn 15147: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15148: my ($resulttext,%changes);
15149: my %currdirsrch;
15150: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15151: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15152: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15153: }
15154: }
1.160.6.72 raeburn 15155: my %title = ( available => 'Institutional directory search available',
15156: localonly => 'Other domains can search institution',
15157: lcavailable => 'LON-CAPA directory search available',
15158: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15159: searchby => 'Search types',
15160: searchtypes => 'Search latitude');
15161: my @offon = ('off','on');
1.24 raeburn 15162: my @otherdoms = ('Yes','No');
1.23 raeburn 15163:
1.25 raeburn 15164: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15165: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15166: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15167:
1.44 raeburn 15168: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15169: if (keys(%{$usertypes}) == 0) {
15170: @cansearch = ('default');
15171: } else {
15172: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15173: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15174: if (!grep(/^\Q$type\E$/,@cansearch)) {
15175: push(@{$changes{'cansearch'}},$type);
15176: }
1.23 raeburn 15177: }
1.26 raeburn 15178: foreach my $type (@cansearch) {
15179: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15180: push(@{$changes{'cansearch'}},$type);
15181: }
1.23 raeburn 15182: }
1.26 raeburn 15183: } else {
15184: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15185: }
15186: }
15187:
15188: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15189: foreach my $by (@{$currdirsrch{'searchby'}}) {
15190: if (!grep(/^\Q$by\E$/,@searchby)) {
15191: push(@{$changes{'searchby'}},$by);
15192: }
15193: }
15194: foreach my $by (@searchby) {
15195: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15196: push(@{$changes{'searchby'}},$by);
15197: }
15198: }
15199: } else {
15200: push(@{$changes{'searchby'}},@searchby);
15201: }
1.25 raeburn 15202:
15203: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15204: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15205: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15206: push(@{$changes{'searchtypes'}},$type);
15207: }
15208: }
15209: foreach my $type (@searchtypes) {
15210: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15211: push(@{$changes{'searchtypes'}},$type);
15212: }
15213: }
15214: } else {
15215: if (exists($currdirsrch{'searchtypes'})) {
15216: foreach my $type (@searchtypes) {
15217: if ($type ne $currdirsrch{'searchtypes'}) {
15218: push(@{$changes{'searchtypes'}},$type);
15219: }
15220: }
15221: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15222: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15223: }
15224: } else {
15225: push(@{$changes{'searchtypes'}},@searchtypes);
15226: }
15227: }
15228:
1.23 raeburn 15229: my %dirsrch_hash = (
15230: directorysrch => { available => $env{'form.dirsrch_available'},
15231: cansearch => \@cansearch,
1.160.6.72 raeburn 15232: localonly => $env{'form.dirsrch_instlocalonly'},
15233: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15234: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15235: searchby => \@searchby,
1.25 raeburn 15236: searchtypes => \@searchtypes,
1.23 raeburn 15237: }
15238: );
15239: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15240: $dom);
15241: if ($putresult eq 'ok') {
15242: if (exists($currdirsrch{'available'})) {
15243: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15244: $changes{'available'} = 1;
15245: }
15246: } else {
15247: if ($env{'form.dirsrch_available'} eq '1') {
15248: $changes{'available'} = 1;
15249: }
15250: }
1.160.6.72 raeburn 15251: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 15252: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15253: $changes{'lcavailable'} = 1;
15254: }
1.24 raeburn 15255: } else {
1.160.6.72 raeburn 15256: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15257: $changes{'lcavailable'} = 1;
15258: }
15259: }
15260: if (exists($currdirsrch{'localonly'})) {
15261: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 15262: $changes{'localonly'} = 1;
15263: }
1.160.6.72 raeburn 15264: } else {
15265: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
15266: $changes{'localonly'} = 1;
15267: }
15268: }
15269: if (exists($currdirsrch{'lclocalonly'})) {
15270: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15271: $changes{'lclocalonly'} = 1;
15272: }
15273: } else {
15274: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15275: $changes{'lclocalonly'} = 1;
15276: }
1.24 raeburn 15277: }
1.23 raeburn 15278: if (keys(%changes) > 0) {
15279: $resulttext = &mt('Changes made:').'<ul>';
15280: if ($changes{'available'}) {
15281: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15282: }
1.160.6.72 raeburn 15283: if ($changes{'lcavailable'}) {
15284: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15285: }
1.24 raeburn 15286: if ($changes{'localonly'}) {
1.160.6.72 raeburn 15287: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
15288: }
15289: if ($changes{'lclocalonly'}) {
15290: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 15291: }
1.23 raeburn 15292: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15293: my $chgtext;
1.26 raeburn 15294: if (ref($usertypes) eq 'HASH') {
15295: if (keys(%{$usertypes}) > 0) {
15296: foreach my $type (@{$types}) {
15297: if (grep(/^\Q$type\E$/,@cansearch)) {
15298: $chgtext .= $usertypes->{$type}.'; ';
15299: }
15300: }
15301: if (grep(/^default$/,@cansearch)) {
15302: $chgtext .= $othertitle;
15303: } else {
15304: $chgtext =~ s/\; $//;
15305: }
1.160.6.13 raeburn 15306: $resulttext .=
15307: '<li>'.
15308: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15309: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15310: '</li>';
1.23 raeburn 15311: }
15312: }
15313: }
15314: if (ref($changes{'searchby'}) eq 'ARRAY') {
15315: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15316: my $chgtext;
15317: foreach my $type (@{$titleorder}) {
15318: if (grep(/^\Q$type\E$/,@searchby)) {
15319: if (defined($searchtitles->{$type})) {
15320: $chgtext .= $searchtitles->{$type}.'; ';
15321: }
15322: }
15323: }
15324: $chgtext =~ s/\; $//;
15325: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15326: }
1.25 raeburn 15327: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15328: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15329: my $chgtext;
15330: foreach my $type (@{$srchtypeorder}) {
15331: if (grep(/^\Q$type\E$/,@searchtypes)) {
15332: if (defined($srchtypes_desc->{$type})) {
15333: $chgtext .= $srchtypes_desc->{$type}.'; ';
15334: }
15335: }
15336: }
15337: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 15338: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15339: }
15340: $resulttext .= '</ul>';
1.160.6.81 raeburn 15341: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15342: if (ref($lastactref) eq 'HASH') {
15343: $lastactref->{'directorysrch'} = 1;
15344: }
1.23 raeburn 15345: } else {
1.160.6.72 raeburn 15346: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15347: }
15348: } else {
15349: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15350: &mt('An error occurred: [_1]',$putresult).'</span>';
15351: }
15352: return $resulttext;
15353: }
15354:
1.28 raeburn 15355: sub modify_contacts {
1.160.6.24 raeburn 15356: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15357: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15358: if (ref($domconfig{'contacts'}) eq 'HASH') {
15359: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15360: $currsetting{$key} = $domconfig{'contacts'}{$key};
15361: }
15362: }
1.160.6.78 raeburn 15363: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15364: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 15365: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 15366: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 15367: my @toggles = ('reporterrors','reportupdates','reportstatus');
15368: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 15369: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15370: foreach my $type (@mailings) {
15371: @{$newsetting{$type}} =
15372: &Apache::loncommon::get_env_multiple('form.'.$type);
15373: foreach my $item (@contacts) {
15374: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15375: $contacts_hash{contacts}{$type}{$item} = 1;
15376: } else {
15377: $contacts_hash{contacts}{$type}{$item} = 0;
15378: }
1.160.6.78 raeburn 15379: }
1.28 raeburn 15380: $others{$type} = $env{'form.'.$type.'_others'};
15381: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 15382: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15383: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15384: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 15385: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15386: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15387: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15388: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15389: }
1.134 raeburn 15390: }
1.28 raeburn 15391: }
15392: foreach my $item (@contacts) {
15393: $to{$item} = $env{'form.'.$item};
15394: $contacts_hash{'contacts'}{$item} = $to{$item};
15395: }
1.160.6.23 raeburn 15396: foreach my $item (@toggles) {
15397: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15398: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15399: }
15400: }
1.160.6.107 raeburn 15401: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15402: foreach my $item (@lonstatus) {
15403: if ($item eq 'excluded') {
15404: my (%serverhomes,@excluded);
15405: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15406: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15407: if (@possexcluded) {
15408: foreach my $id (sort(@possexcluded)) {
15409: if ($serverhomes{$id}) {
15410: push(@excluded,$id);
15411: }
15412: }
15413: }
15414: if (@excluded) {
15415: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15416: }
15417: } elsif ($item eq 'weights') {
15418: foreach my $type ('E','W','N','U') {
15419: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15420: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15421: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15422: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15423: $env{'form.error'.$item.'_'.$type};
15424: }
15425: }
15426: }
15427: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15428: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15429: if ($env{'form.error'.$item} =~ /^\d+$/) {
15430: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15431: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15432: }
15433: }
15434: }
15435: }
1.160.6.78 raeburn 15436: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15437: foreach my $field (@{$fields}) {
15438: if (ref($possoptions->{$field}) eq 'ARRAY') {
15439: my $value = $env{'form.helpform_'.$field};
15440: $value =~ s/^\s+|\s+$//g;
15441: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 15442: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 15443: if ($field eq 'screenshot') {
15444: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15445: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 15446: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 15447: }
15448: }
15449: }
15450: }
15451: }
15452: }
1.160.6.101 raeburn 15453: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15454: my (@statuses,%usertypeshash,@overrides);
15455: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15456: @statuses = @{$types};
15457: if (ref($usertypes) eq 'HASH') {
15458: %usertypeshash = %{$usertypes};
15459: }
15460: }
15461: if (@statuses) {
15462: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15463: foreach my $type (@possoverrides) {
15464: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15465: push(@overrides,$type);
15466: }
15467: }
15468: if (@overrides) {
15469: foreach my $type (@overrides) {
15470: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15471: foreach my $item (@contacts) {
15472: if (grep(/^\Q$item\E$/,@standard)) {
15473: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15474: $newsetting{'override_'.$type}{$item} = 1;
15475: } else {
15476: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15477: $newsetting{'override_'.$type}{$item} = 0;
15478: }
15479: }
15480: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15481: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15482: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15483: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15484: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15485: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15486: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15487: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15488: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15489: }
1.160.6.118.2 14(raebu 15490:23): }
1.160.6.101 raeburn 15491: }
15492: }
1.28 raeburn 15493: if (keys(%currsetting) > 0) {
15494: foreach my $item (@contacts) {
15495: if ($to{$item} ne $currsetting{$item}) {
15496: $changes{$item} = 1;
15497: }
15498: }
15499: foreach my $type (@mailings) {
15500: foreach my $item (@contacts) {
15501: if (ref($currsetting{$type}) eq 'HASH') {
15502: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15503: push(@{$changes{$type}},$item);
15504: }
15505: } else {
15506: push(@{$changes{$type}},@{$newsetting{$type}});
15507: }
15508: }
15509: if ($others{$type} ne $currsetting{$type}{'others'}) {
15510: push(@{$changes{$type}},'others');
15511: }
1.160.6.78 raeburn 15512: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15513: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15514: push(@{$changes{$type}},'bcc');
15515: }
1.160.6.78 raeburn 15516: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15517: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15518: push(@{$changes{$type}},'include');
15519: }
15520: }
15521: }
15522: if (ref($fields) eq 'ARRAY') {
15523: if (ref($currsetting{'helpform'}) eq 'HASH') {
15524: foreach my $field (@{$fields}) {
15525: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15526: push(@{$changes{'helpform'}},$field);
15527: }
15528: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15529: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15530: push(@{$changes{'helpform'}},'maxsize');
15531: }
15532: }
15533: }
15534: } else {
15535: foreach my $field (@{$fields}) {
15536: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15537: push(@{$changes{'helpform'}},$field);
15538: }
15539: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15540: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15541: push(@{$changes{'helpform'}},'maxsize');
15542: }
15543: }
15544: }
1.134 raeburn 15545: }
1.28 raeburn 15546: }
1.160.6.101 raeburn 15547: if (@statuses) {
15548: if (ref($currsetting{'overrides'}) eq 'HASH') {
15549: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15550: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15551: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15552: foreach my $item (@contacts,'bcc','others','include') {
15553: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15554: push(@{$changes{'overrides'}},$key);
15555: last;
15556: }
15557: }
15558: } else {
15559: push(@{$changes{'overrides'}},$key);
15560: }
15561: }
15562: }
15563: foreach my $key (@overrides) {
15564: unless (exists($currsetting{'overrides'}{$key})) {
15565: push(@{$changes{'overrides'}},$key);
15566: }
15567: }
15568: } else {
15569: foreach my $key (@overrides) {
15570: push(@{$changes{'overrides'}},$key);
15571: }
15572: }
15573: }
1.160.6.107 raeburn 15574: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15575: foreach my $key ('excluded','weights','threshold','sysmail') {
15576: if ($key eq 'excluded') {
15577: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15578: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15579: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15580: (@{$currsetting{'lonstatus'}{$key}})) {
15581: my @diffs =
15582: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15583: $currsetting{'lonstatus'}{$key});
15584: if (@diffs) {
15585: push(@{$changes{'lonstatus'}},$key);
15586: }
15587: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15588: push(@{$changes{'lonstatus'}},$key);
15589: }
15590: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15591: (@{$currsetting{'lonstatus'}{$key}})) {
15592: push(@{$changes{'lonstatus'}},$key);
15593: }
15594: } elsif ($key eq 'weights') {
15595: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15596: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15597: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15598: foreach my $type ('E','W','N','U') {
15599: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15600: $currsetting{'lonstatus'}{$key}{$type}) {
15601: push(@{$changes{'lonstatus'}},$key);
15602: last;
15603: }
15604: }
15605: } else {
15606: foreach my $type ('E','W','N','U') {
15607: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15608: push(@{$changes{'lonstatus'}},$key);
15609: last;
15610: }
15611: }
15612: }
15613: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15614: foreach my $type ('E','W','N','U') {
15615: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15616: push(@{$changes{'lonstatus'}},$key);
15617: last;
15618: }
15619: }
15620: }
15621: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15622: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15623: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15624: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15625: push(@{$changes{'lonstatus'}},$key);
15626: }
15627: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15628: push(@{$changes{'lonstatus'}},$key);
15629: }
15630: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15631: push(@{$changes{'lonstatus'}},$key);
15632: }
15633: }
15634: }
15635: } else {
15636: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15637: foreach my $key ('excluded','weights','threshold','sysmail') {
15638: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15639: push(@{$changes{'lonstatus'}},$key);
15640: }
15641: }
15642: }
15643: }
1.28 raeburn 15644: } else {
15645: my %default;
15646: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15647: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15648: $default{'errormail'} = 'adminemail';
15649: $default{'packagesmail'} = 'adminemail';
15650: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 15651: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15652: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15653: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 15654: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 15655: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15656: foreach my $item (@contacts) {
15657: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 15658: $changes{$item} = 1;
1.160.6.23 raeburn 15659: }
1.28 raeburn 15660: }
15661: foreach my $type (@mailings) {
15662: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15663: push(@{$changes{$type}},@{$newsetting{$type}});
15664: }
15665: if ($others{$type} ne '') {
15666: push(@{$changes{$type}},'others');
1.134 raeburn 15667: }
1.160.6.78 raeburn 15668: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15669: if ($bcc{$type} ne '') {
15670: push(@{$changes{$type}},'bcc');
15671: }
1.160.6.78 raeburn 15672: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15673: push(@{$changes{$type}},'include');
15674: }
15675: }
15676: }
15677: if (ref($fields) eq 'ARRAY') {
15678: foreach my $field (@{$fields}) {
15679: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15680: push(@{$changes{'helpform'}},$field);
15681: }
15682: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15683: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15684: push(@{$changes{'helpform'}},'maxsize');
15685: }
15686: }
1.134 raeburn 15687: }
1.28 raeburn 15688: }
1.160.6.107 raeburn 15689: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15690: foreach my $key ('excluded','weights','threshold','sysmail') {
15691: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15692: push(@{$changes{'lonstatus'}},$key);
15693: }
15694: }
15695: }
1.28 raeburn 15696: }
1.160.6.23 raeburn 15697: foreach my $item (@toggles) {
15698: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15699: $changes{$item} = 1;
15700: } elsif ((!$env{'form.'.$item}) &&
15701: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15702: $changes{$item} = 1;
15703: }
15704: }
1.28 raeburn 15705: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15706: $dom);
15707: if ($putresult eq 'ok') {
15708: if (keys(%changes) > 0) {
1.160.6.24 raeburn 15709: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 15710: if (ref($lastactref) eq 'HASH') {
15711: $lastactref->{'domainconfig'} = 1;
15712: }
1.28 raeburn 15713: my ($titles,$short_titles) = &contact_titles();
15714: $resulttext = &mt('Changes made:').'<ul>';
15715: foreach my $item (@contacts) {
15716: if ($changes{$item}) {
15717: $resulttext .= '<li>'.$titles->{$item}.
15718: &mt(' set to: ').
15719: '<span class="LC_cusr_emph">'.
15720: $to{$item}.'</span></li>';
15721: }
15722: }
15723: foreach my $type (@mailings) {
15724: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 15725: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15726: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15727: } else {
15728: $resulttext .= '<li>'.$titles->{$type}.': ';
15729: }
1.28 raeburn 15730: my @text;
15731: foreach my $item (@{$newsetting{$type}}) {
15732: push(@text,$short_titles->{$item});
15733: }
15734: if ($others{$type} ne '') {
15735: push(@text,$others{$type});
15736: }
1.160.6.78 raeburn 15737: if (@text) {
15738: $resulttext .= '<span class="LC_cusr_emph">'.
15739: join(', ',@text).'</span>';
15740: }
15741: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15742: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 15743: my $bcctext;
15744: if (@text) {
15745: $bcctext = ' '.&mt('with Bcc to');
15746: } else {
15747: $bcctext = '(Bcc)';
15748: }
15749: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15750: } elsif (!@text) {
15751: $resulttext .= &mt('No one');
1.134 raeburn 15752: }
1.160.6.78 raeburn 15753: if ($includestr{$type} ne '') {
15754: if ($includeloc{$type} eq 'b') {
15755: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15756: } elsif ($includeloc{$type} eq 's') {
15757: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15758: }
15759: }
15760: } elsif (!@text) {
15761: $resulttext .= &mt('No recipients');
1.134 raeburn 15762: }
15763: $resulttext .= '</li>';
1.28 raeburn 15764: }
15765: }
1.160.6.101 raeburn 15766: if (ref($changes{'overrides'}) eq 'ARRAY') {
15767: my @deletions;
15768: foreach my $type (@{$changes{'overrides'}}) {
15769: if ($usertypeshash{$type}) {
15770: if (grep(/^\Q$type\E/,@overrides)) {
15771: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15772: $usertypeshash{$type}).'<ul><li>';
15773: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15774: my @text;
15775: foreach my $item (@contacts) {
15776: if ($newsetting{'override_'.$type}{$item}) {
15777: push(@text,$short_titles->{$item});
15778: }
15779: }
15780: if ($newsetting{'override_'.$type}{'others'} ne '') {
15781: push(@text,$newsetting{'override_'.$type}{'others'});
15782: }
15783:
15784: if (@text) {
15785: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15786: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15787: }
15788: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15789: my $bcctext;
15790: if (@text) {
15791: $bcctext = ' '.&mt('with Bcc to');
15792: } else {
15793: $bcctext = '(Bcc)';
15794: }
15795: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15796: } elsif (!@text) {
15797: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15798: }
15799: $resulttext .= '</li>';
15800: if ($newsetting{'override_'.$type}{'include'} ne '') {
15801: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15802: if ($loc eq 'b') {
15803: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15804: } elsif ($loc eq 's') {
15805: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15806: }
15807: }
15808: }
15809: $resulttext .= '</li></ul></li>';
15810: } else {
15811: push(@deletions,$usertypeshash{$type});
15812: }
15813: }
15814: }
15815: if (@deletions) {
15816: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15817: join(', ',@deletions)).'</li>';
15818: }
15819: }
1.160.6.23 raeburn 15820: my @offon = ('off','on');
1.160.6.107 raeburn 15821: my $corelink = &core_link_msu();
1.160.6.23 raeburn 15822: if ($changes{'reporterrors'}) {
15823: $resulttext .= '<li>'.
15824: &mt('E-mail error reports to [_1] set to "'.
15825: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 15826: $corelink).
1.160.6.23 raeburn 15827: '</li>';
15828: }
15829: if ($changes{'reportupdates'}) {
15830: $resulttext .= '<li>'.
15831: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15832: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 15833: $corelink).
1.160.6.23 raeburn 15834: '</li>';
15835: }
1.160.6.107 raeburn 15836: if ($changes{'reportstatus'}) {
15837: $resulttext .= '<li>'.
15838: &mt('E-mail status if errors above threshold to [_1] set to "'.
15839: $offon[$env{'form.reportstatus'}].'".',
15840: $corelink).
15841: '</li>';
15842: }
15843: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15844: $resulttext .= '<li>'.
15845: &mt('Nightly status check e-mail settings').':<ul>';
15846: my (%defval,%use_def,%shown);
15847: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15848: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15849: $defval{'weights'} =
15850: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15851: $defval{'excluded'} = &mt('None');
15852: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15853: foreach my $item ('threshold','sysmail','weights','excluded') {
15854: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15855: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15856: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15857: } elsif ($item eq 'weights') {
15858: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15859: foreach my $type ('E','W','N','U') {
15860: $shown{$item} .= $lonstatus_names->{$type}.'=';
15861: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15862: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15863: } else {
15864: $shown{$item} .= $lonstatus_defs->{$type};
15865: }
15866: $shown{$item} .= ', ';
15867: }
15868: $shown{$item} =~ s/, $//;
15869: } else {
15870: $shown{$item} = $defval{$item};
15871: }
15872: } elsif ($item eq 'excluded') {
15873: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15874: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15875: } else {
15876: $shown{$item} = $defval{$item};
15877: }
15878: }
15879: } else {
15880: $shown{$item} = $defval{$item};
15881: }
15882: }
15883: } else {
15884: foreach my $item ('threshold','weights','excluded','sysmail') {
15885: $shown{$item} = $defval{$item};
15886: }
15887: }
15888: foreach my $item ('threshold','weights','excluded','sysmail') {
15889: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15890: $shown{$item}).'</li>';
15891: }
15892: $resulttext .= '</ul></li>';
15893: }
1.160.6.78 raeburn 15894: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15895: my (@optional,@required,@unused,$maxsizechg);
15896: foreach my $field (@{$changes{'helpform'}}) {
15897: if ($field eq 'maxsize') {
15898: $maxsizechg = 1;
15899: next;
15900: }
15901: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15902: push(@optional,$field);
15903: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15904: push(@unused,$field);
15905: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15906: push(@required,$field);
15907: }
15908: }
15909: if (@optional) {
15910: $resulttext .= '<li>'.
15911: &mt('Help form fields changed to "Optional": [_1].',
15912: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15913: '</li>';
15914: }
15915: if (@required) {
15916: $resulttext .= '<li>'.
15917: &mt('Help form fields changed to "Required": [_1].',
15918: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15919: '</li>';
15920: }
15921: if (@unused) {
15922: $resulttext .= '<li>'.
15923: &mt('Help form fields changed to "Not shown": [_1].',
15924: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15925: '</li>';
15926: }
15927: if ($maxsizechg) {
15928: $resulttext .= '<li>'.
15929: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15930: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15931: '</li>';
15932: }
15933: }
1.28 raeburn 15934: $resulttext .= '</ul>';
15935: } else {
1.160.6.78 raeburn 15936: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15937: }
15938: } else {
15939: $resulttext = '<span class="LC_error">'.
1.160.6.118.2 14(raebu 15940:23): &mt('An error occurred: [_1]',$putresult).'</span>';
1.28 raeburn 15941: }
15942: return $resulttext;
15943: }
15944:
1.160.6.98 raeburn 15945: sub modify_passwords {
15946: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15947: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15948: $updatedefaults,$updateconf);
15949: my $customfn = 'resetpw.html';
15950: if (ref($domconfig{'passwords'}) eq 'HASH') {
15951: %current = %{$domconfig{'passwords'}};
15952: }
15953: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15954: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15955: if (ref($types) eq 'ARRAY') {
15956: @oktypes = @{$types};
15957: }
15958: push(@oktypes,'default');
15959:
15960: my %titles = &Apache::lonlocal::texthash (
15961: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
15962: intauth_check => 'Check bcrypt cost if authenticated',
15963: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
15964: permanent => 'Permanent e-mail address',
15965: critical => 'Critical notification address',
15966: notify => 'Notification address',
15967: min => 'Minimum password length',
15968: max => 'Maximum password length',
15969: chars => 'Required characters',
15970: numsaved => 'Number of previous passwords to save',
15971: reset => 'Resetting Forgotten Password',
15972: intauth => 'Encryption of Stored Passwords (Internal Auth)',
15973: rules => 'Rules for LON-CAPA Passwords',
15974: crsownerchg => 'Course Owner Changing Student Passwords',
15975: username => 'Username',
15976: email => 'E-mail address',
15977: );
15978:
15979: #
15980: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
15981: #
15982: my (%curr_defaults,%save_defaults);
15983: if (ref($domconfig{'defaults'}) eq 'HASH') {
15984: foreach my $key (keys(%{$domconfig{'defaults'}})) {
15985: if ($key =~ /^intauth_(cost|check|switch)$/) {
15986: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
15987: } else {
15988: $save_defaults{$key} = $domconfig{'defaults'}{$key};
15989: }
15990: }
15991: }
15992: my %staticdefaults = (
15993: 'resetlink' => 2,
15994: 'resetcase' => \@oktypes,
15995: 'resetprelink' => 'both',
15996: 'resetemail' => ['critical','notify','permanent'],
15997: 'intauth_cost' => 10,
15998: 'intauth_check' => 0,
15999: 'intauth_switch' => 0,
16000: );
1.160.6.99 raeburn 16001: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 16002: foreach my $type (@oktypes) {
16003: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16004: }
16005: my $linklife = $env{'form.passwords_link'};
16006: $linklife =~ s/^\s+|\s+$//g;
16007: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16008: $newvalues{'resetlink'} = $linklife;
16009: if ($current{'resetlink'}) {
16010: if ($current{'resetlink'} ne $linklife) {
16011: $changes{'reset'} = 1;
16012: }
1.160.6.102 raeburn 16013: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16014: if ($staticdefaults{'resetlink'} ne $linklife) {
16015: $changes{'reset'} = 1;
16016: }
16017: }
16018: } elsif ($current{'resetlink'}) {
16019: $changes{'reset'} = 1;
16020: }
16021: my @casesens;
16022: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16023: foreach my $case (sort(@posscase)) {
16024: if (grep(/^\Q$case\E$/,@oktypes)) {
16025: push(@casesens,$case);
16026: }
16027: }
16028: $newvalues{'resetcase'} = \@casesens;
16029: if (ref($current{'resetcase'}) eq 'ARRAY') {
16030: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16031: if (@diffs > 0) {
16032: $changes{'reset'} = 1;
16033: }
1.160.6.102 raeburn 16034: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16035: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16036: if (@diffs > 0) {
16037: $changes{'reset'} = 1;
16038: }
16039: }
16040: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16041: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16042: if (exists($current{'resetprelink'})) {
16043: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16044: $changes{'reset'} = 1;
16045: }
1.160.6.102 raeburn 16046: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16047: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16048: $changes{'reset'} = 1;
16049: }
16050: }
16051: } elsif ($current{'resetprelink'}) {
16052: $changes{'reset'} = 1;
16053: }
16054: foreach my $type (@oktypes) {
16055: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16056: my @postlink;
16057: foreach my $item (sort(@possplink)) {
16058: if ($item =~ /^(email|username)$/) {
16059: push(@postlink,$item);
16060: }
16061: }
16062: $newvalues{'resetpostlink'}{$type} = \@postlink;
16063: unless ($changes{'reset'}) {
16064: if (ref($current{'resetpostlink'}) eq 'HASH') {
16065: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16066: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16067: if (@diffs > 0) {
16068: $changes{'reset'} = 1;
16069: }
16070: } else {
16071: $changes{'reset'} = 1;
16072: }
1.160.6.102 raeburn 16073: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16074: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16075: if (@diffs > 0) {
16076: $changes{'reset'} = 1;
16077: }
16078: }
16079: }
16080: }
16081: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16082: my @resetemail;
16083: foreach my $item (sort(@possemailsrc)) {
16084: if ($item =~ /^(permanent|critical|notify)$/) {
16085: push(@resetemail,$item);
16086: }
16087: }
16088: $newvalues{'resetemail'} = \@resetemail;
16089: unless ($changes{'reset'}) {
16090: if (ref($current{'resetemail'}) eq 'ARRAY') {
16091: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16092: if (@diffs > 0) {
16093: $changes{'reset'} = 1;
16094: }
1.160.6.102 raeburn 16095: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16096: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16097: if (@diffs > 0) {
16098: $changes{'reset'} = 1;
16099: }
16100: }
16101: }
16102: if ($env{'form.passwords_stdtext'} == 0) {
16103: $newvalues{'resetremove'} = 1;
16104: unless ($current{'resetremove'}) {
16105: $changes{'reset'} = 1;
16106: }
16107: } elsif ($current{'resetremove'}) {
16108: $changes{'reset'} = 1;
16109: }
16110: if ($env{'form.passwords_customfile.filename'} ne '') {
16111: my $servadm = $r->dir_config('lonAdmEMail');
16112: my ($configuserok,$author_ok,$switchserver) =
16113: &config_check($dom,$confname,$servadm);
16114: my $error;
16115: if ($configuserok eq 'ok') {
16116: if ($switchserver) {
16117: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16118: } else {
16119: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 16120:23): my $modified = [];
1.160.6.98 raeburn 16121: my ($result,$customurl) =
1.160.6.118.2 14(raebu 16122:23): &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
16123:23): $confname,'customtext/resetpw','','',$customfn,
16124:23): $modified);
1.160.6.98 raeburn 16125: if ($result eq 'ok') {
16126: $newvalues{'resetcustom'} = $customurl;
16127: $changes{'reset'} = 1;
1.160.6.118.2 14(raebu 16128:23): &update_modify_urls($r,$modified);
1.160.6.98 raeburn 16129: } else {
16130: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16131: }
16132: } else {
16133: $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);
16134: }
16135: }
16136: } else {
16137: $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);
16138: }
16139: if ($error) {
16140: &Apache::lonnet::logthis($error);
16141: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16142: }
16143: } elsif ($current{'resetcustom'}) {
16144: if ($env{'form.passwords_custom_del'}) {
16145: $changes{'reset'} = 1;
16146: } else {
16147: $newvalues{'resetcustom'} = $current{'resetcustom'};
16148: }
16149: }
16150: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16151: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16152: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16153: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16154: $changes{'intauth'} = 1;
16155: }
16156: } else {
16157: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16158: }
16159: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16160: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16161: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16162: $changes{'intauth'} = 1;
16163: }
16164: } else {
16165: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16166: }
16167: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16168: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16169: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16170: $changes{'intauth'} = 1;
16171: }
16172: } else {
16173: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16174: }
16175: foreach my $item ('cost','check','switch') {
16176: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16177: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16178: $updatedefaults = 1;
16179: }
16180: }
1.160.6.118.2 5(raebur 16181:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 16182: my %crsownerchg = (
16183: by => [],
16184: for => [],
16185: );
16186: foreach my $item ('by','for') {
16187: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16188: foreach my $type (sort(@posstypes)) {
16189: if (grep(/^\Q$type\E$/,@oktypes)) {
16190: push(@{$crsownerchg{$item}},$type);
16191: }
16192: }
16193: }
16194: $newvalues{'crsownerchg'} = \%crsownerchg;
16195: if (ref($current{'crsownerchg'}) eq 'HASH') {
16196: foreach my $item ('by','for') {
16197: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16198: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16199: if (@diffs > 0) {
16200: $changes{'crsownerchg'} = 1;
16201: last;
16202: }
16203: }
16204: }
1.160.6.102 raeburn 16205: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 16206: foreach my $item ('by','for') {
16207: if (@{$crsownerchg{$item}} > 0) {
16208: $changes{'crsownerchg'} = 1;
16209: last;
16210: }
16211: }
16212: }
16213:
16214: my %confighash = (
16215: defaults => \%save_defaults,
16216: passwords => \%newvalues,
16217: );
16218: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16219:
16220: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16221: if ($putresult eq 'ok') {
16222: if (keys(%changes) > 0) {
16223: $resulttext = &mt('Changes made: ').'<ul>';
16224: foreach my $key ('reset','intauth','rules','crsownerchg') {
16225: if ($changes{$key}) {
16226: unless ($key eq 'intauth') {
16227: $updateconf = 1;
16228: }
16229: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16230: if ($key eq 'reset') {
16231: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16232: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16233: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16234: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 16235: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16236: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16237: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16238: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16239: }
1.160.6.98 raeburn 16240: } else {
16241: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16242: }
16243: if ($confighash{'passwords'}{'resetlink'}) {
16244: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16245: } else {
16246: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16247: &mt('Will default to 2 hours').'</li>';
16248: }
16249: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16250: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16251: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16252: } else {
16253: my $casesens;
16254: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16255: if ($type eq 'default') {
16256: $casesens .= $othertitle.', ';
16257: } elsif ($usertypes->{$type} ne '') {
16258: $casesens .= $usertypes->{$type}.', ';
16259: }
16260: }
16261: $casesens =~ s/\Q, \E$//;
16262: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16263: }
16264: } else {
16265: $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>';
16266: }
16267: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16268: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16269: } else {
16270: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16271: }
16272: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16273: my $output;
16274: if (ref($types) eq 'ARRAY') {
16275: foreach my $type (@{$types}) {
16276: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16277: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16278: $output .= $usertypes->{$type}.' -- '.&mt('none');
16279: } else {
16280: $output .= $usertypes->{$type}.' -- '.
16281: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16282: }
16283: }
16284: }
16285: }
16286: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16287: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16288: $output .= $othertitle.' -- '.&mt('none');
16289: } else {
16290: $output .= $othertitle.' -- '.
16291: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16292: }
16293: }
16294: if ($output) {
16295: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16296: } else {
16297: $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>';
16298: }
16299: } else {
16300: $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>';
16301: }
16302: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16303: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16304: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16305: } else {
16306: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16307: }
16308: } else {
1.160.6.110 raeburn 16309: $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 16310: }
16311: if ($confighash{'passwords'}{'resetremove'}) {
16312: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16313: } else {
16314: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16315: }
16316: if ($confighash{'passwords'}{'resetcustom'}) {
16317: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 16318: &mt('custom text'),600,500,undef,undef,
16319: undef,undef,'background-color:#ffffff');
16320: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 16321: } else {
16322: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16323: }
16324: } elsif ($key eq 'intauth') {
16325: foreach my $item ('cost','switch','check') {
16326: my $value = $save_defaults{$key.'_'.$item};
16327: if ($item eq 'switch') {
16328: my %optiondesc = &Apache::lonlocal::texthash (
16329: 0 => 'No',
16330: 1 => 'Yes',
16331: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16332: );
16333: if ($value =~ /^(0|1|2)$/) {
16334: $value = $optiondesc{$value};
16335: } else {
16336: $value = &mt('none -- defaults to No');
16337: }
16338: } elsif ($item eq 'check') {
16339: my %optiondesc = &Apache::lonlocal::texthash (
16340: 0 => 'No',
16341: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16342: 2 => 'Yes, disallow login if stored cost is less than domain default',
16343: );
16344: if ($value =~ /^(0|1|2)$/) {
16345: $value = $optiondesc{$value};
16346: } else {
16347: $value = &mt('none -- defaults to No');
16348: }
16349: }
16350: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16351: }
16352: } elsif ($key eq 'rules') {
16353: foreach my $rule ('min','max','numsaved') {
16354: if ($confighash{'passwords'}{$rule} eq '') {
16355: if ($rule eq 'min') {
16356: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 16357: ' '.&mt('Default of [_1] will be used',
16358: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 16359: } else {
16360: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
16361: }
16362: } else {
16363: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16364: }
16365: }
1.160.6.104 raeburn 16366: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16367: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16368: my %rulenames = &Apache::lonlocal::texthash(
16369: uc => 'At least one upper case letter',
16370: lc => 'At least one lower case letter',
16371: num => 'At least one number',
16372: spec => 'At least one non-alphanumeric',
16373: );
16374: my $needed = '<ul><li>'.
16375: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16376: '</li></ul>';
16377: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16378: } else {
16379: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16380: }
16381: } else {
16382: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16383: }
1.160.6.98 raeburn 16384: } elsif ($key eq 'crsownerchg') {
16385: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16386: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16387: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16388: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16389: } else {
16390: my %crsownerstr;
16391: foreach my $item ('by','for') {
16392: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16393: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16394: if ($type eq 'default') {
16395: $crsownerstr{$item} .= $othertitle.', ';
16396: } elsif ($usertypes->{$type} ne '') {
16397: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16398: }
16399: }
16400: $crsownerstr{$item} =~ s/\Q, \E$//;
16401: }
16402: }
16403: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16404: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16405: }
16406: } else {
16407: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16408: }
16409: }
16410: $resulttext .= '</ul></li>';
16411: }
16412: }
16413: $resulttext .= '</ul>';
16414: } else {
16415: $resulttext = &mt('No changes made to password settings');
16416: }
16417: my $cachetime = 24*60*60;
16418: if ($updatedefaults) {
16419: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16420: if (ref($lastactref) eq 'HASH') {
16421: $lastactref->{'domdefaults'} = 1;
16422: }
16423: }
16424: if ($updateconf) {
16425: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16426: if (ref($lastactref) eq 'HASH') {
16427: $lastactref->{'passwdconf'} = 1;
16428: }
16429: }
16430: } else {
16431: $resulttext = '<span class="LC_error">'.
16432: &mt('An error occurred: [_1]',$putresult).'</span>';
16433: }
16434: if ($errors) {
16435: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16436: $errors.'</ul></p>';
16437: }
16438: return $resulttext;
16439: }
16440:
1.160.6.118.2 5(raebur 16441:2): sub password_rule_changes {
16442:2): my ($prefix,$newvalues,$current,$changes) = @_;
16443:2): return unless ((ref($newvalues) eq 'HASH') &&
16444:2): (ref($current) eq 'HASH') &&
16445:2): (ref($changes) eq 'HASH'));
16446:2): my (@rules,%staticdefaults);
16447:2): if ($prefix eq 'passwords') {
16448:2): @rules = ('min','max','numsaved');
14(raebu 16449:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 16450:2): @rules = ('min','max');
16451:2): }
16452:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
16453:2): foreach my $rule (@rules) {
16454:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
16455:2): my $ruleok;
16456:2): if ($rule eq 'min') {
16457:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
16458:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
16459:2): $ruleok = 1;
16460:2): }
16461:2): }
16462:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
16463:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
16464:2): $ruleok = 1;
16465:2): }
16466:2): if ($ruleok) {
16467:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
16468:2): if (exists($current->{$rule})) {
16469:2): if ($newvalues->{$rule} ne $current->{$rule}) {
16470:2): $changes->{'rules'} = 1;
16471:2): }
16472:2): } elsif ($rule eq 'min') {
16473:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
16474:2): $changes->{'rules'} = 1;
16475:2): }
16476:2): } else {
16477:2): $changes->{'rules'} = 1;
16478:2): }
16479:2): } elsif (exists($current->{$rule})) {
16480:2): $changes->{'rules'} = 1;
16481:2): }
16482:2): }
16483:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
16484:2): my @chars;
16485:2): foreach my $item (sort(@posschars)) {
16486:2): if ($item =~ /^(uc|lc|num|spec)$/) {
16487:2): push(@chars,$item);
16488:2): }
16489:2): }
16490:2): $newvalues->{'chars'} = \@chars;
16491:2): unless ($changes->{'rules'}) {
16492:2): if (ref($current->{'chars'}) eq 'ARRAY') {
16493:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
16494:2): if (@diffs > 0) {
16495:2): $changes->{'rules'} = 1;
16496:2): }
16497:2): } else {
16498:2): if (@chars > 0) {
16499:2): $changes->{'rules'} = 1;
16500:2): }
16501:2): }
16502:2): }
16503:2): return;
16504:2): }
16505:2):
1.28 raeburn 16506: sub modify_usercreation {
1.27 raeburn 16507: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16508: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16509: my $warningmsg;
1.27 raeburn 16510: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16511: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 16512: if ($key eq 'cancreate') {
16513: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16514: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 16515: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 16516: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 16517: } else {
16518: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 16519: }
1.50 raeburn 16520: }
1.43 raeburn 16521: }
1.160.6.34 raeburn 16522: } elsif ($key eq 'email_rule') {
16523: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16524: } else {
16525: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 16526: }
16527: }
1.34 raeburn 16528: }
1.160.6.34 raeburn 16529: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
16530: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
16531: my @contexts = ('author','course','requestcrs');
16532: foreach my $item(@contexts) {
16533: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16534: }
1.34 raeburn 16535: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16536: foreach my $item (@contexts) {
1.160.6.34 raeburn 16537: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16538: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16539: }
1.27 raeburn 16540: }
1.34 raeburn 16541: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16542: foreach my $item (@contexts) {
1.43 raeburn 16543: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16544: if ($cancreate{$item} ne 'any') {
16545: push(@{$changes{'cancreate'}},$item);
16546: }
16547: } else {
16548: if ($cancreate{$item} ne 'none') {
16549: push(@{$changes{'cancreate'}},$item);
16550: }
1.27 raeburn 16551: }
16552: }
16553: } else {
1.43 raeburn 16554: foreach my $item (@contexts) {
1.34 raeburn 16555: push(@{$changes{'cancreate'}},$item);
16556: }
1.27 raeburn 16557: }
1.34 raeburn 16558:
1.27 raeburn 16559: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16560: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16561: if (!grep(/^\Q$type\E$/,@username_rule)) {
16562: push(@{$changes{'username_rule'}},$type);
16563: }
16564: }
16565: foreach my $type (@username_rule) {
16566: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16567: push(@{$changes{'username_rule'}},$type);
16568: }
16569: }
16570: } else {
16571: push(@{$changes{'username_rule'}},@username_rule);
16572: }
16573:
1.32 raeburn 16574: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16575: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16576: if (!grep(/^\Q$type\E$/,@id_rule)) {
16577: push(@{$changes{'id_rule'}},$type);
16578: }
16579: }
16580: foreach my $type (@id_rule) {
16581: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16582: push(@{$changes{'id_rule'}},$type);
16583: }
16584: }
16585: } else {
16586: push(@{$changes{'id_rule'}},@id_rule);
16587: }
16588:
1.43 raeburn 16589: my @authen_contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 16590:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16591: my %authhash;
1.43 raeburn 16592: foreach my $item (@authen_contexts) {
1.28 raeburn 16593: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16594: foreach my $auth (@authtypes) {
16595: if (grep(/^\Q$auth\E$/,@authallowed)) {
16596: $authhash{$item}{$auth} = 1;
16597: } else {
16598: $authhash{$item}{$auth} = 0;
16599: }
16600: }
16601: }
16602: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16603: foreach my $item (@authen_contexts) {
1.28 raeburn 16604: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16605: foreach my $auth (@authtypes) {
16606: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16607: push(@{$changes{'authtypes'}},$item);
16608: last;
16609: }
16610: }
16611: }
16612: }
16613: } else {
1.43 raeburn 16614: foreach my $item (@authen_contexts) {
1.28 raeburn 16615: push(@{$changes{'authtypes'}},$item);
16616: }
16617: }
16618:
1.160.6.34 raeburn 16619: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16620: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16621: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16622: $save_usercreate{'id_rule'} = \@id_rule;
16623: $save_usercreate{'username_rule'} = \@username_rule,
16624: $save_usercreate{'authtypes'} = \%authhash;
16625:
1.27 raeburn 16626: my %usercreation_hash = (
1.160.6.34 raeburn 16627: usercreation => \%save_usercreate,
16628: );
1.27 raeburn 16629:
16630: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16631: $dom);
1.50 raeburn 16632:
1.160.6.34 raeburn 16633: if ($putresult eq 'ok') {
16634: if (keys(%changes) > 0) {
16635: $resulttext = &mt('Changes made:').'<ul>';
16636: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16637: my %lt = &usercreation_types();
16638: foreach my $type (@{$changes{'cancreate'}}) {
16639: my $chgtext = $lt{$type}.', ';
16640: if ($cancreate{$type} eq 'none') {
16641: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16642: } elsif ($cancreate{$type} eq 'any') {
16643: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16644: } elsif ($cancreate{$type} eq 'official') {
16645: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16646: } elsif ($cancreate{$type} eq 'unofficial') {
16647: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16648: }
16649: $resulttext .= '<li>'.$chgtext.'</li>';
16650: }
16651: }
16652: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16653: my ($rules,$ruleorder) =
16654: &Apache::lonnet::inst_userrules($dom,'username');
16655: my $chgtext = '<ul>';
16656: foreach my $type (@username_rule) {
16657: if (ref($rules->{$type}) eq 'HASH') {
16658: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16659: }
16660: }
16661: $chgtext .= '</ul>';
16662: if (@username_rule > 0) {
16663: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16664: } else {
16665: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16666: }
16667: }
16668: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16669: my ($idrules,$idruleorder) =
16670: &Apache::lonnet::inst_userrules($dom,'id');
16671: my $chgtext = '<ul>';
16672: foreach my $type (@id_rule) {
16673: if (ref($idrules->{$type}) eq 'HASH') {
16674: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16675: }
16676: }
16677: $chgtext .= '</ul>';
16678: if (@id_rule > 0) {
16679: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16680: } else {
16681: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16682: }
16683: }
16684: my %authname = &authtype_names();
16685: my %context_title = &context_names();
16686: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16687: my $chgtext = '<ul>';
16688: foreach my $type (@{$changes{'authtypes'}}) {
16689: my @allowed;
16690: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16691: foreach my $auth (@authtypes) {
16692: if ($authhash{$type}{$auth}) {
16693: push(@allowed,$authname{$auth});
16694: }
16695: }
16696: if (@allowed > 0) {
16697: $chgtext .= join(', ',@allowed).'</li>';
16698: } else {
16699: $chgtext .= &mt('none').'</li>';
16700: }
16701: }
16702: $chgtext .= '</ul>';
16703: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16704: $resulttext .= '</li>';
16705: }
16706: $resulttext .= '</ul>';
16707: } else {
16708: $resulttext = &mt('No changes made to user creation settings');
16709: }
16710: } else {
16711: $resulttext = '<span class="LC_error">'.
16712: &mt('An error occurred: [_1]',$putresult).'</span>';
16713: }
16714: if ($warningmsg ne '') {
16715: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16716: }
16717: return $resulttext;
16718: }
16719:
16720: sub modify_selfcreation {
1.160.6.93 raeburn 16721: my ($dom,$lastactref,%domconfig) = @_;
16722: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16723: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16724: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16725: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16726: if (ref($typesref) eq 'ARRAY') {
16727: @types = @{$typesref};
16728: }
16729: if (ref($usertypesref) eq 'HASH') {
16730: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 16731: }
1.160.6.93 raeburn 16732: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 16733: #
16734: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16735: #
16736: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16737: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16738: if ($key eq 'cancreate') {
16739: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16740: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16741: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 16742: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16743: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16744: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16745: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16746: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 16747: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16748: } else {
16749: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16750: }
16751: }
16752: }
16753: } elsif ($key eq 'email_rule') {
16754: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16755: } else {
16756: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16757: }
16758: }
16759: }
16760: #
16761: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16762: #
16763: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16764: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16765: if ($key eq 'selfcreate') {
16766: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16767: } else {
16768: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16769: }
16770: }
16771: }
1.160.6.93 raeburn 16772: #
16773: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16774: #
16775: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16776: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16777: if ($key eq 'inststatusguest') {
16778: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16779: } else {
16780: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16781: }
16782: }
16783: }
1.160.6.34 raeburn 16784:
16785: my @contexts = ('selfcreate');
16786: @{$cancreate{'selfcreate'}} = ();
16787: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 16788: if (@types) {
16789: @{$cancreate{'statustocreate'}} = ();
16790: }
1.160.6.40 raeburn 16791: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 16792: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 16793: %{$cancreate{'emailverified'}} = ();
16794: %{$cancreate{'emailoptions'}} = ();
16795: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16796: my %selfcreatetypes = (
16797: sso => 'users authenticated by institutional single sign on',
16798: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 16799: email => 'users verified by e-mail',
1.50 raeburn 16800: );
1.160.6.34 raeburn 16801: #
16802: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16803: # is permitted.
16804: #
1.160.6.93 raeburn 16805: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 16806:
1.160.6.93 raeburn 16807: my (@statuses,%email_rule);
1.160.6.35 raeburn 16808: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 16809: if ($item eq 'email') {
1.160.6.40 raeburn 16810: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 16811: if (@types) {
16812: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16813: foreach my $status (@poss_statuses) {
16814: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16815: push(@statuses,$status);
16816: }
16817: }
16818: $save_inststatus{'inststatusguest'} = \@statuses;
16819: } else {
16820: push(@statuses,'default');
16821: }
16822: if (@statuses) {
16823: my %curr_rule;
16824: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16825: foreach my $type (@statuses) {
16826: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16827: }
16828: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16829: foreach my $type (@statuses) {
16830: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16831: }
16832: }
16833: push(@{$cancreate{'selfcreate'}},'email');
16834: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16835: my %curremaildom;
16836: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16837: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16838: }
16839: foreach my $type (@statuses) {
16840: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16841: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16842: }
16843: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16844: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16845: }
16846: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16847: #
16848: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16849: #
16850: my $chosen = $1;
16851: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16852: my $emaildom;
16853: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16854: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16855: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16856: if (ref($curremaildom{$type}) eq 'HASH') {
16857: if (exists($curremaildom{$type}{$chosen})) {
16858: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16859: push(@{$changes{'cancreate'}},'emaildomain');
16860: }
16861: } elsif ($emaildom ne '') {
16862: push(@{$changes{'cancreate'}},'emaildomain');
16863: }
16864: } elsif ($emaildom ne '') {
16865: push(@{$changes{'cancreate'}},'emaildomain');
16866: }
16867: }
16868: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16869: } elsif ($chosen eq 'custom') {
16870: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16871: $email_rule{$type} = [];
16872: if (ref($emailrules) eq 'HASH') {
16873: foreach my $rule (@possemail_rules) {
16874: if (exists($emailrules->{$rule})) {
16875: push(@{$email_rule{$type}},$rule);
16876: }
16877: }
16878: }
16879: if (@{$email_rule{$type}}) {
16880: $cancreate{'emailoptions'}{$type} = 'custom';
16881: if (ref($curr_rule{$type}) eq 'ARRAY') {
16882: if (@{$curr_rule{$type}} > 0) {
16883: foreach my $rule (@{$curr_rule{$type}}) {
16884: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16885: push(@{$changes{'email_rule'}},$type);
16886: }
16887: }
16888: }
16889: foreach my $type (@{$email_rule{$type}}) {
16890: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16891: push(@{$changes{'email_rule'}},$type);
16892: }
16893: }
16894: } else {
16895: push(@{$changes{'email_rule'}},$type);
16896: }
16897: }
16898: } else {
16899: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16900: }
16901: }
16902: }
16903: if (@types) {
16904: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16905: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16906: if (@changed) {
16907: push(@{$changes{'inststatus'}},'inststatusguest');
16908: }
16909: } else {
16910: push(@{$changes{'inststatus'}},'inststatusguest');
16911: }
16912: }
16913: } else {
16914: delete($env{'form.cancreate_email'});
16915: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16916: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16917: push(@{$changes{'inststatus'}},'inststatusguest');
16918: }
16919: }
16920: }
16921: } else {
16922: $save_inststatus{'inststatusguest'} = [];
16923: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16924: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16925: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 16926: }
16927: }
1.160.6.34 raeburn 16928: }
16929: } else {
16930: if ($env{'form.cancreate_'.$item}) {
16931: push(@{$cancreate{'selfcreate'}},$item);
16932: }
16933: }
16934: }
1.160.6.93 raeburn 16935: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 16936: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16937: #
1.160.6.35 raeburn 16938: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16939: # 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 16940: #
1.160.6.40 raeburn 16941:
1.160.6.48 raeburn 16942: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 16943: push(@contexts,'emailusername');
1.160.6.93 raeburn 16944: if (@statuses) {
16945: foreach my $type (@statuses) {
1.160.6.35 raeburn 16946: if (ref($infofields) eq 'ARRAY') {
16947: foreach my $field (@{$infofields}) {
16948: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16949: $cancreate{'emailusername'}{$type}{$field} = $1;
16950: }
16951: }
1.160.6.34 raeburn 16952: }
16953: }
16954: }
16955: #
16956: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 16957: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 16958: #
16959:
16960: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
16961: @approvalnotify = sort(@approvalnotify);
16962: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
16963: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16964: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
16965: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
16966: push(@{$changes{'cancreate'}},'notify');
16967: }
16968: } else {
16969: if ($cancreate{'notify'}{'approval'}) {
16970: push(@{$changes{'cancreate'}},'notify');
16971: }
16972: }
16973: } elsif ($cancreate{'notify'}{'approval'}) {
16974: push(@{$changes{'cancreate'}},'notify');
16975: }
16976:
16977: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
16978: }
16979: #
1.160.6.40 raeburn 16980: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 16981: # institutional log-in.
16982: #
16983: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
16984: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
16985: ($domdefaults{'auth_def'} eq 'localauth'))) {
16986: $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.').' '.
16987: &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.');
16988: }
16989: }
16990: my @fields = ('lastname','firstname','middlename','generation',
16991: 'permanentemail','id');
1.160.6.44 raeburn 16992: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 16993: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
16994: #
16995: # Where usernames may created for institutional log-in and/or institutional single sign on:
16996: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
16997: # may self-create accounts
16998: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
16999: # which the user may supply, if institutional data is unavailable.
17000: #
17001: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 17002: if (@types) {
17003: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17004: push(@contexts,'statustocreate');
17005: foreach my $type (@types) {
1.160.6.34 raeburn 17006: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17007: foreach my $field (@fields) {
17008: if (grep(/^\Q$field\E$/,@modifiable)) {
17009: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17010: } else {
17011: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17012: }
17013: }
17014: }
17015: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 17016: foreach my $type (@types) {
1.160.6.34 raeburn 17017: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17018: foreach my $field (@fields) {
17019: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17020: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17021: push(@{$changes{'selfcreate'}},$type);
17022: last;
17023: }
17024: }
17025: }
17026: }
17027: } else {
1.160.6.93 raeburn 17028: foreach my $type (@types) {
1.160.6.34 raeburn 17029: push(@{$changes{'selfcreate'}},$type);
17030: }
17031: }
17032: }
1.160.6.44 raeburn 17033: foreach my $field (@shibfields) {
17034: if ($env{'form.shibenv_'.$field} ne '') {
17035: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17036: }
17037: }
17038: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17039: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17040: foreach my $field (@shibfields) {
17041: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17042: push(@{$changes{'cancreate'}},'shibenv');
17043: }
17044: }
17045: } else {
17046: foreach my $field (@shibfields) {
17047: if ($env{'form.shibenv_'.$field}) {
17048: push(@{$changes{'cancreate'}},'shibenv');
17049: last;
17050: }
17051: }
17052: }
17053: }
1.160.6.34 raeburn 17054: }
17055: foreach my $item (@contexts) {
17056: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17057: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17058: if (ref($cancreate{$item}) eq 'ARRAY') {
17059: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17060: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17061: push(@{$changes{'cancreate'}},$item);
17062: }
17063: }
17064: }
17065: }
17066: if (ref($cancreate{$item}) eq 'ARRAY') {
17067: foreach my $type (@{$cancreate{$item}}) {
17068: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17069: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17070: push(@{$changes{'cancreate'}},$item);
17071: }
17072: }
17073: }
17074: }
17075: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17076: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 17077: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17078: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17079: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17080: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17081: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17082: push(@{$changes{'cancreate'}},$item);
17083: }
17084: }
17085: }
1.160.6.93 raeburn 17086: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17087: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17088: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17089: push(@{$changes{'cancreate'}},$item);
17090: }
1.160.6.34 raeburn 17091: }
17092: }
17093: }
1.160.6.93 raeburn 17094: foreach my $type (keys(%{$cancreate{$item}})) {
17095: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17096: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17097: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17098: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17099: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17100: push(@{$changes{'cancreate'}},$item);
17101: }
17102: }
17103: } else {
17104: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17105: push(@{$changes{'cancreate'}},$item);
17106: }
17107: }
17108: }
1.160.6.93 raeburn 17109: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17110: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17111: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17112: push(@{$changes{'cancreate'}},$item);
17113: }
1.160.6.34 raeburn 17114: }
17115: }
17116: }
17117: }
17118: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17119: if (ref($cancreate{$item}) eq 'ARRAY') {
17120: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17121: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17122: push(@{$changes{'cancreate'}},$item);
17123: }
17124: }
1.160.6.93 raeburn 17125: }
17126: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17127: if (ref($cancreate{$item}) eq 'HASH') {
17128: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17129: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 17130: }
17131: }
17132: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 17133: if (ref($cancreate{$item}) eq 'HASH') {
17134: foreach my $type (keys(%{$cancreate{$item}})) {
17135: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17136: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17137: if ($cancreate{$item}{$type}{$field}) {
17138: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17139: push(@{$changes{'cancreate'}},$item);
17140: }
17141: last;
17142: }
17143: }
17144: }
17145: }
1.160.6.34 raeburn 17146: }
17147: }
17148: }
17149: #
17150: # Populate %save_usercreate hash with updates to self-creation configuration.
17151: #
17152: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17153: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 17154: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 17155: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17156: if (ref($cancreate{'notify'}) eq 'HASH') {
17157: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17158: }
1.160.6.40 raeburn 17159: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17160: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17161: }
1.160.6.93 raeburn 17162: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17163: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17164: }
17165: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17166: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17167: }
17168: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17169: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17170: }
1.160.6.34 raeburn 17171: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17172: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17173: }
1.160.6.44 raeburn 17174: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17175: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17176: }
1.160.6.34 raeburn 17177: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 17178: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 17179:
17180: my %userconfig_hash = (
17181: usercreation => \%save_usercreate,
17182: usermodification => \%save_usermodify,
1.160.6.93 raeburn 17183: inststatus => \%save_inststatus,
1.160.6.34 raeburn 17184: );
1.160.6.93 raeburn 17185:
1.160.6.34 raeburn 17186: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17187: $dom);
17188: #
1.160.6.93 raeburn 17189: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 17190: #
1.27 raeburn 17191: if ($putresult eq 'ok') {
17192: if (keys(%changes) > 0) {
17193: $resulttext = &mt('Changes made:').'<ul>';
17194: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 17195: my %lt = &selfcreation_types();
1.34 raeburn 17196: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 17197: my $chgtext = '';
1.45 raeburn 17198: if ($type eq 'selfcreate') {
1.50 raeburn 17199: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 17200: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17201: } else {
1.160.6.34 raeburn 17202: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17203: '<ul>';
1.50 raeburn 17204: foreach my $case (@{$cancreate{$type}}) {
17205: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17206: }
17207: $chgtext .= '</ul>';
1.100 raeburn 17208: if (ref($cancreate{$type}) eq 'ARRAY') {
17209: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17210: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17211: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 17212: $chgtext .= '<span class="LC_warning">'.
17213: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17214: '</span><br />';
1.100 raeburn 17215: }
17216: }
17217: }
1.160.6.93 raeburn 17218: if (grep(/^email$/,@{$cancreate{$type}})) {
17219: if (!@statuses) {
17220: $chgtext .= '<span class="LC_warning">'.
17221: &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.").
17222: '</span><br />';
17223:
17224: }
17225: }
1.100 raeburn 17226: }
1.43 raeburn 17227: }
1.160.6.44 raeburn 17228: } elsif ($type eq 'shibenv') {
17229: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 17230: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 17231: } else {
17232: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17233: '<ul>';
17234: foreach my $field (@shibfields) {
17235: next if ($cancreate{$type}{$field} eq '');
17236: if ($field eq 'inststatus') {
17237: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17238: } else {
17239: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17240: }
17241: }
17242: $chgtext .= '</ul>';
1.160.6.93 raeburn 17243: }
1.93 raeburn 17244: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17245: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17246: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17247: if (@{$cancreate{'selfcreate'}} > 0) {
17248: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17249: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17250: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 17251: $chgtext .= '<br />'.
17252: '<span class="LC_warning">'.
17253: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17254: '</span>';
17255: }
1.160.6.93 raeburn 17256: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17257: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17258: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17259: } else {
17260: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17261: }
17262: $chgtext .= '<ul>';
17263: foreach my $case (@{$cancreate{$type}}) {
17264: if ($case eq 'default') {
17265: $chgtext .= '<li>'.$othertitle.'</li>';
17266: } else {
1.160.6.93 raeburn 17267: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17268: }
17269: }
1.100 raeburn 17270: $chgtext .= '</ul>';
17271: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 17272: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 17273: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17274: '</span>';
1.100 raeburn 17275: }
17276: }
17277: } else {
17278: if (@{$cancreate{$type}} == 0) {
17279: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17280: } else {
17281: $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 17282: }
17283: }
1.160.6.93 raeburn 17284: $chgtext .= '<br />';
1.93 raeburn 17285: }
1.160.6.40 raeburn 17286: } elsif ($type eq 'selfcreateprocessing') {
17287: my %choices = &Apache::lonlocal::texthash (
17288: automatic => 'Automatic approval',
17289: approval => 'Queued for approval',
17290: );
1.160.6.93 raeburn 17291: if (@types) {
17292: if (@statuses) {
17293: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
17294: '<ul>';
17295: foreach my $status (@statuses) {
17296: if ($status eq 'default') {
17297: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17298: } else {
17299: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17300: }
17301: }
17302: $chgtext .= '</ul>';
17303: }
17304: } else {
17305: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17306: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17307: }
17308: } elsif ($type eq 'emailverified') {
17309: my %options = &Apache::lonlocal::texthash (
17310: all => 'Same as e-mail',
17311: first => 'Omit @domain',
17312: free => 'Free to choose',
17313: );
17314: if (@types) {
17315: if (@statuses) {
17316: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17317: '<ul>';
17318: foreach my $status (@statuses) {
17319: if ($status eq 'default') {
17320: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17321: } else {
17322: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17323: }
17324: }
17325: $chgtext .= '</ul>';
17326: }
1.160.6.40 raeburn 17327: } else {
1.160.6.93 raeburn 17328: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
17329: $options{$cancreate{'emailverified'}{'default'}});
17330: }
17331: } elsif ($type eq 'emailoptions') {
17332: my %options = &Apache::lonlocal::texthash (
17333: any => 'Any e-mail',
17334: inst => 'Institutional only',
17335: noninst => 'Non-institutional only',
17336: custom => 'Custom restrictions',
17337: );
17338: if (@types) {
17339: if (@statuses) {
17340: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17341: '<ul>';
17342: foreach my $status (@statuses) {
17343: if ($type eq 'default') {
17344: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17345: } else {
17346: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17347: }
17348: }
17349: $chgtext .= '</ul>';
17350: }
17351: } else {
17352: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17353: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17354: } else {
17355: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17356: $options{$cancreate{'emailoptions'}{'default'}});
17357: }
17358: }
17359: } elsif ($type eq 'emaildomain') {
17360: my $output;
17361: if (@statuses) {
17362: foreach my $type (@statuses) {
17363: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17364: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17365: if ($type eq 'default') {
17366: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17367: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17368: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17369: } else {
17370: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17371: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17372: }
17373: } else {
17374: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17375: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17376: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17377: } else {
17378: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17379: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17380: }
17381: }
17382: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17383: if ($type eq 'default') {
17384: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17385: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17386: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17387: } else {
17388: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17389: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17390: }
17391: } else {
17392: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17393: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17394: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17395: } else {
17396: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17397: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17398: }
17399: }
17400: }
17401: }
17402: }
17403: }
17404: if ($output ne '') {
17405: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17406: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 17407: }
1.160.6.5 raeburn 17408: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 17409: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 17410: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17411: } else {
17412: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 17413: if ($captchas{$savecaptcha{$type}}) {
17414: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 17415: } else {
17416: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
17417: }
17418: }
17419: } elsif ($type eq 'recaptchakeys') {
17420: my ($privkey,$pubkey);
1.160.6.34 raeburn 17421: if (ref($savecaptcha{$type}) eq 'HASH') {
17422: $pubkey = $savecaptcha{$type}{'public'};
17423: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 17424: }
17425: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17426: if (!$pubkey) {
17427: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17428: } else {
17429: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17430: }
17431: if (!$privkey) {
17432: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17433: } else {
17434: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17435: }
17436: $chgtext .= '</ul>';
1.160.6.69 raeburn 17437: } elsif ($type eq 'recaptchaversion') {
17438: if ($savecaptcha{'captcha'} eq 'recaptcha') {
17439: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
17440: }
1.160.6.34 raeburn 17441: } elsif ($type eq 'emailusername') {
17442: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 17443: if (@statuses) {
17444: foreach my $type (@statuses) {
1.160.6.35 raeburn 17445: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17446: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 17447: $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 17448: '<ul>';
17449: foreach my $field (@{$infofields}) {
17450: if ($cancreate{'emailusername'}{$type}{$field}) {
17451: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17452: }
17453: }
1.160.6.50 raeburn 17454: $chgtext .= '</ul>';
17455: } else {
1.160.6.93 raeburn 17456: $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 17457: }
17458: } else {
1.160.6.93 raeburn 17459: $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 17460: }
17461: }
17462: }
17463: }
17464: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 17465: my $numapprove = 0;
1.160.6.34 raeburn 17466: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17467: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17468: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 17469: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17470: $numapprove ++;
1.160.6.34 raeburn 17471: }
17472: }
1.43 raeburn 17473: }
1.160.6.93 raeburn 17474: unless ($numapprove) {
17475: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17476: }
1.34 raeburn 17477: }
1.160.6.34 raeburn 17478: if ($chgtext) {
17479: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17480: }
17481: }
17482: }
1.160.6.93 raeburn 17483: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17484: my ($emailrules,$emailruleorder) =
17485: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 17486: foreach my $type (@{$changes{'email_rule'}}) {
17487: if (ref($email_rule{$type}) eq 'ARRAY') {
17488: my $chgtext = '<ul>';
17489: foreach my $rule (@{$email_rule{$type}}) {
17490: if (ref($emailrules->{$rule}) eq 'HASH') {
17491: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17492: }
17493: }
17494: $chgtext .= '</ul>';
17495: my $typename;
17496: if (@types) {
17497: if ($type eq 'default') {
17498: $typename = $othertitle;
17499: } else {
17500: $typename = $usertypes{$type};
17501: }
17502: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17503: }
17504: if (@{$email_rule{$type}} > 0) {
17505: $resulttext .= '<li>'.
17506: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17507: $usertypes{$type}).
17508: $chgtext.
17509: '</li>';
17510: } else {
17511: $resulttext .= '<li>'.
17512: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
17513: '</li>'.
17514: &mt('(Affiliation: [_1])',$typename);
17515: }
1.43 raeburn 17516: }
17517: }
1.160.6.93 raeburn 17518: }
17519: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17520: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17521: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17522: my $chgtext = '<ul>';
17523: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17524: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17525: }
17526: $chgtext .= '</ul>';
17527: $resulttext .= '<li>'.
17528: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17529: $chgtext.
17530: '</li>';
17531: } else {
17532: $resulttext .= '<li>'.
17533: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17534: '</li>';
17535: }
1.43 raeburn 17536: }
17537: }
1.160.6.34 raeburn 17538: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17539: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17540: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17541: foreach my $type (@{$changes{'selfcreate'}}) {
17542: my $typename = $type;
1.160.6.93 raeburn 17543: if (keys(%usertypes) > 0) {
17544: if ($usertypes{$type} ne '') {
17545: $typename = $usertypes{$type};
1.28 raeburn 17546: }
17547: }
1.160.6.34 raeburn 17548: my @modifiable;
17549: $resulttext .= '<li>'.
17550: &mt('Self-creation of account by users with status: [_1]',
17551: '<span class="LC_cusr_emph">'.$typename.'</span>').
17552: ' - '.&mt('modifiable fields (if institutional data blank): ');
17553: foreach my $field (@fields) {
17554: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17555: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
17556: }
17557: }
17558: if (@modifiable > 0) {
17559: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17560: } else {
1.160.6.34 raeburn 17561: $resulttext .= &mt('none');
1.43 raeburn 17562: }
1.160.6.34 raeburn 17563: $resulttext .= '</li>';
1.28 raeburn 17564: }
1.160.6.34 raeburn 17565: $resulttext .= '</ul></li>';
1.28 raeburn 17566: }
1.27 raeburn 17567: $resulttext .= '</ul>';
1.160.6.93 raeburn 17568: my $cachetime = 24*60*60;
17569: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17570: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17571: if (ref($lastactref) eq 'HASH') {
17572: $lastactref->{'domdefaults'} = 1;
17573: }
1.27 raeburn 17574: } else {
1.160.6.34 raeburn 17575: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17576: }
17577: } else {
17578: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17579: &mt('An error occurred: [_1]',$putresult).'</span>';
17580: }
1.43 raeburn 17581: if ($warningmsg ne '') {
17582: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17583: }
1.23 raeburn 17584: return $resulttext;
17585: }
17586:
1.160.6.5 raeburn 17587: sub process_captcha {
1.160.6.104 raeburn 17588: my ($container,$changes,$newsettings,$currsettings) = @_;
17589: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 17590: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17591: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17592: $newsettings->{'captcha'} = 'original';
17593: }
1.160.6.104 raeburn 17594: my %current;
17595: if (ref($currsettings) eq 'HASH') {
17596: %current = %{$currsettings};
17597: }
17598: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 17599: if ($container eq 'cancreate') {
17600: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17601: push(@{$changes->{'cancreate'}},'captcha');
17602: } elsif (!defined($changes->{'cancreate'})) {
17603: $changes->{'cancreate'} = ['captcha'];
17604: }
1.160.6.102 raeburn 17605: } elsif ($container eq 'passwords') {
17606: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17607: } else {
17608: $changes->{'captcha'} = 1;
17609: }
17610: }
1.160.6.69 raeburn 17611: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 17612: if ($newsettings->{'captcha'} eq 'recaptcha') {
17613: $newpub = $env{'form.'.$container.'_recaptchapub'};
17614: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 17615: $newpub =~ s/[^\w\-]//g;
17616: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 17617: $newsettings->{'recaptchakeys'} = {
17618: public => $newpub,
17619: private => $newpriv,
17620: };
1.160.6.69 raeburn 17621: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17622: $newversion =~ s/\D//g;
17623: if ($newversion ne '2') {
17624: $newversion = 1;
17625: }
17626: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 17627: }
1.160.6.104 raeburn 17628: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17629: $currpub = $current{'recaptchakeys'}{'public'};
17630: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 17631: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17632: $newsettings->{'recaptchakeys'} = {
17633: public => '',
17634: private => '',
17635: }
17636: }
1.160.6.5 raeburn 17637: }
1.160.6.104 raeburn 17638: if ($current{'captcha'} eq 'recaptcha') {
17639: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 17640: if ($currversion ne '2') {
17641: $currversion = 1;
17642: }
17643: }
17644: if ($currversion ne $newversion) {
17645: if ($container eq 'cancreate') {
17646: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17647: push(@{$changes->{'cancreate'}},'recaptchaversion');
17648: } elsif (!defined($changes->{'cancreate'})) {
17649: $changes->{'cancreate'} = ['recaptchaversion'];
17650: }
1.160.6.102 raeburn 17651: } elsif ($container eq 'passwords') {
17652: $changes->{'reset'} = 1;
1.160.6.69 raeburn 17653: } else {
17654: $changes->{'recaptchaversion'} = 1;
17655: }
17656: }
1.160.6.5 raeburn 17657: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
17658: if ($container eq 'cancreate') {
17659: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17660: push(@{$changes->{'cancreate'}},'recaptchakeys');
17661: } elsif (!defined($changes->{'cancreate'})) {
17662: $changes->{'cancreate'} = ['recaptchakeys'];
17663: }
1.160.6.102 raeburn 17664: } elsif ($container eq 'passwords') {
17665: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17666: } else {
17667: $changes->{'recaptchakeys'} = 1;
17668: }
17669: }
17670: return;
17671: }
17672:
1.33 raeburn 17673: sub modify_usermodification {
17674: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 17675: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17676: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17677: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 17678: if ($key eq 'selfcreate') {
17679: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17680: } else {
17681: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17682: }
1.33 raeburn 17683: }
17684: }
1.160.6.118.2 25(raebu 17685:24): my @contexts = ('author','coauthor','course');
1.33 raeburn 17686: my %context_title = (
17687: author => 'In author context',
1.160.6.118.2 25(raebu 17688:24): coauthor => 'As co-author manager',
1.33 raeburn 17689: course => 'In course context',
17690: );
17691: my @fields = ('lastname','firstname','middlename','generation',
17692: 'permanentemail','id');
17693: my %roles = (
17694: author => ['ca','aa'],
1.160.6.118.2 25(raebu 17695:24): coauthor => ['ca','aa'],
1.33 raeburn 17696: course => ['st','ep','ta','in','cr'],
17697: );
17698: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17699: foreach my $context (@contexts) {
1.160.6.118.2 25(raebu 17700:24): my $prefix = 'canmodify';
17701:24): if ($context eq 'coauthor') {
17702:24): $prefix = 'cacanmodify';
17703:24): }
1.33 raeburn 17704: foreach my $role (@{$roles{$context}}) {
1.160.6.118.2 25(raebu 17705:24): my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 17706: foreach my $item (@fields) {
17707: if (grep(/^\Q$item\E$/,@modifiable)) {
17708: $modifyhash{$context}{$role}{$item} = 1;
17709: } else {
17710: $modifyhash{$context}{$role}{$item} = 0;
17711: }
17712: }
17713: }
17714: if (ref($curr_usermodification{$context}) eq 'HASH') {
17715: foreach my $role (@{$roles{$context}}) {
17716: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17717: foreach my $field (@fields) {
17718: if ($modifyhash{$context}{$role}{$field} ne
17719: $curr_usermodification{$context}{$role}{$field}) {
17720: push(@{$changes{$context}},$role);
17721: last;
17722: }
17723: }
17724: }
17725: }
17726: } else {
17727: foreach my $context (@contexts) {
17728: foreach my $role (@{$roles{$context}}) {
17729: push(@{$changes{$context}},$role);
17730: }
17731: }
17732: }
17733: }
17734: my %usermodification_hash = (
17735: usermodification => \%modifyhash,
17736: );
17737: my $putresult = &Apache::lonnet::put_dom('configuration',
17738: \%usermodification_hash,$dom);
17739: if ($putresult eq 'ok') {
17740: if (keys(%changes) > 0) {
17741: $resulttext = &mt('Changes made: ').'<ul>';
17742: foreach my $context (@contexts) {
17743: if (ref($changes{$context}) eq 'ARRAY') {
17744: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17745: if (ref($changes{$context}) eq 'ARRAY') {
17746: foreach my $role (@{$changes{$context}}) {
17747: my $rolename;
1.160.6.34 raeburn 17748: if ($role eq 'cr') {
17749: $rolename = &mt('Custom');
1.33 raeburn 17750: } else {
1.160.6.34 raeburn 17751: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17752: }
17753: my @modifiable;
1.160.6.34 raeburn 17754: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17755: foreach my $field (@fields) {
17756: if ($modifyhash{$context}{$role}{$field}) {
17757: push(@modifiable,$fieldtitles{$field});
17758: }
17759: }
17760: if (@modifiable > 0) {
17761: $resulttext .= join(', ',@modifiable);
17762: } else {
17763: $resulttext .= &mt('none');
17764: }
17765: $resulttext .= '</li>';
17766: }
17767: $resulttext .= '</ul></li>';
17768: }
17769: }
17770: }
17771: $resulttext .= '</ul>';
17772: } else {
17773: $resulttext = &mt('No changes made to user modification settings');
17774: }
17775: } else {
17776: $resulttext = '<span class="LC_error">'.
17777: &mt('An error occurred: [_1]',$putresult).'</span>';
17778: }
17779: return $resulttext;
17780: }
17781:
1.43 raeburn 17782: sub modify_defaults {
1.160.6.27 raeburn 17783: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17784: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 17785: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 17786: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 17787: 'portal_def');
1.160.6.118.2 14(raebu 17788:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17789: foreach my $item (@items) {
17790: $newvalues{$item} = $env{'form.'.$item};
17791: if ($item eq 'auth_def') {
17792: if ($newvalues{$item} ne '') {
17793: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17794: push(@errors,$item);
17795: }
17796: }
17797: } elsif ($item eq 'lang_def') {
17798: if ($newvalues{$item} ne '') {
17799: if ($newvalues{$item} =~ /^(\w+)/) {
17800: my $langcode = $1;
1.103 raeburn 17801: if ($langcode ne 'x_chef') {
17802: if (code2language($langcode) eq '') {
17803: push(@errors,$item);
17804: }
1.43 raeburn 17805: }
17806: } else {
17807: push(@errors,$item);
17808: }
17809: }
1.54 raeburn 17810: } elsif ($item eq 'timezone_def') {
17811: if ($newvalues{$item} ne '') {
1.62 raeburn 17812: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17813: push(@errors,$item);
17814: }
17815: }
1.68 raeburn 17816: } elsif ($item eq 'datelocale_def') {
17817: if ($newvalues{$item} ne '') {
17818: my @datelocale_ids = DateTime::Locale->ids();
17819: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17820: push(@errors,$item);
17821: }
17822: }
1.141 raeburn 17823: } elsif ($item eq 'portal_def') {
17824: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 17825: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])\/?$/) {
17826:23): foreach my $field ('email','web') {
17827:23): if ($env{'form.'.$item.'_'.$field}) {
17828:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17829:23): }
17830:23): }
17831:23): } else {
1.141 raeburn 17832: push(@errors,$item);
17833: }
17834: }
1.43 raeburn 17835: }
17836: if (grep(/^\Q$item\E$/,@errors)) {
17837: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 17838:23): if ($item eq 'portal_def') {
17839:23): if ($domdefaults{$item}) {
17840:23): foreach my $field ('email','web') {
17841:23): if (exists($domdefaults{$item.'_'.$field})) {
17842:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17843:23): }
17844:23): }
17845:23): }
17846:23): }
1.43 raeburn 17847: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17848: $changes{$item} = 1;
17849: }
1.160.6.118.2 12(raebu 17850:23): if ($item eq 'portal_def') {
17851:23): unless (grep(/^\Q$item\E$/,@errors)) {
17852:23): if ($newvalues{$item} eq '') {
17853:23): foreach my $field ('email','web') {
17854:23): if (exists($domdefaults{$item.'_'.$field})) {
17855:23): delete($domdefaults{$item.'_'.$field});
17856:23): }
17857:23): }
17858:23): } else {
17859:23): unless ($changes{$item}) {
17860:23): foreach my $field ('email','web') {
17861:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17862:23): $changes{$item} = 1;
17863:23): last;
17864:23): }
17865:23): }
17866:23): }
17867:23): foreach my $field ('email','web') {
17868:23): if ($newvalues{$item.'_'.$field}) {
17869:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17870:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
17871:23): delete($domdefaults{$item.'_'.$field});
17872:23): }
17873:23): }
17874:23): }
17875:23): }
17876:23): }
1.72 raeburn 17877: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17878: }
1.160.6.98 raeburn 17879: my %staticdefaults = (
17880: 'intauth_cost' => 10,
17881: 'intauth_check' => 0,
17882: 'intauth_switch' => 0,
17883: );
17884: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17885: if (exists($domdefaults{$item})) {
17886: $newvalues{$item} = $domdefaults{$item};
17887: } else {
17888: $newvalues{$item} = $staticdefaults{$item};
17889: }
17890: }
1.160.6.118.2 8(raebur 17891:2): my ($unamemaprules,$ruleorder);
17892:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17893:2): if (@possunamemaprules) {
17894:2): ($unamemaprules,$ruleorder) =
17895:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
17896:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17897:2): if (@{$ruleorder} > 0) {
17898:2): my %possrules;
17899:2): map { $possrules{$_} = 1; } @possunamemaprules;
17900:2): foreach my $rule (@{$ruleorder}) {
17901:2): if ($possrules{$rule}) {
17902:2): push(@{$newvalues{'unamemap_rule'}},$rule);
17903:2): }
17904:2): }
17905:2): }
17906:2): }
17907:2): }
17908:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17909:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17910:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17911:2): $newvalues{'unamemap_rule'});
17912:2): if (@rulediffs) {
17913:2): $changes{'unamemap_rule'} = 1;
17914:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17915:2): }
17916:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17917:2): $changes{'unamemap_rule'} = 1;
17918:2): delete($domdefaults{'unamemap_rule'});
17919:2): }
17920:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17921:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
17922:2): $changes{'unamemap_rule'} = 1;
17923:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17924:2): }
17925:2): }
1.43 raeburn 17926: my %defaults_hash = (
1.72 raeburn 17927: defaults => \%newvalues,
17928: );
1.43 raeburn 17929: my $title = &defaults_titles();
1.160.6.40 raeburn 17930:
17931: my $currinststatus;
17932: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17933: $currinststatus = $domconfig{'inststatus'};
17934: } else {
17935: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17936: $currinststatus = {
17937: inststatustypes => $usertypes,
17938: inststatusorder => $types,
17939: inststatusguest => [],
17940: };
17941: }
17942: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17943: my @allpos;
17944: my %alltypes;
1.160.6.93 raeburn 17945: my @inststatusguest;
17946: if (ref($currinststatus) eq 'HASH') {
17947: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17948: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17949: unless (grep(/^\Q$type\E$/,@todelete)) {
17950: push(@inststatusguest,$type);
17951: }
17952: }
17953: }
17954: }
17955: my ($currtitles,$currorder);
1.160.6.40 raeburn 17956: if (ref($currinststatus) eq 'HASH') {
17957: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17958: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17959: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
17960: if ($currinststatus->{inststatustypes}->{$type} ne '') {
17961: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
17962: }
17963: }
17964: unless (grep(/^\Q$type\E$/,@todelete)) {
17965: my $position = $env{'form.inststatus_pos_'.$type};
17966: $position =~ s/\D+//g;
17967: $allpos[$position] = $type;
17968: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
17969: $alltypes{$type} =~ s/`//g;
17970: }
17971: }
17972: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
17973: $currtitles =~ s/,$//;
17974: }
17975: }
17976: if ($env{'form.addinststatus'}) {
17977: my $newtype = $env{'form.addinststatus'};
17978: $newtype =~ s/\W//g;
17979: unless (exists($alltypes{$newtype})) {
17980: $alltypes{$newtype} = $env{'form.addinststatus_title'};
17981: $alltypes{$newtype} =~ s/`//g;
17982: my $position = $env{'form.addinststatus_pos'};
17983: $position =~ s/\D+//g;
17984: if ($position ne '') {
17985: $allpos[$position] = $newtype;
17986: }
17987: }
17988: }
1.160.6.93 raeburn 17989: my @orderedstatus;
1.160.6.40 raeburn 17990: foreach my $type (@allpos) {
17991: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
17992: push(@orderedstatus,$type);
17993: }
17994: }
17995: foreach my $type (keys(%alltypes)) {
17996: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
17997: delete($alltypes{$type});
17998: }
17999: }
18000: $defaults_hash{'inststatus'} = {
18001: inststatustypes => \%alltypes,
18002: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 18003: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 18004: };
18005: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18006: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18007: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18008: }
18009: }
18010: if ($currorder ne join(',',@orderedstatus)) {
18011: $changes{'inststatus'}{'inststatusorder'} = 1;
18012: }
18013: my $newtitles;
18014: foreach my $item (@orderedstatus) {
18015: $newtitles .= $alltypes{$item}.',';
18016: }
18017: $newtitles =~ s/,$//;
18018: if ($currtitles ne $newtitles) {
18019: $changes{'inststatus'}{'inststatustypes'} = 1;
18020: }
1.43 raeburn 18021: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18022: $dom);
18023: if ($putresult eq 'ok') {
18024: if (keys(%changes) > 0) {
18025: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 18026: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18027: 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";
18028: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 18029: if ($item eq 'inststatus') {
18030: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 18031: if (@orderedstatus) {
1.160.6.40 raeburn 18032: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18033: foreach my $type (@orderedstatus) {
18034: $resulttext .= $alltypes{$type}.', ';
18035: }
18036: $resulttext =~ s/, $//;
18037: $resulttext .= '</li>';
1.160.6.93 raeburn 18038: } else {
18039: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 18040: }
18041: }
1.160.6.118.2 8(raebur 18042:2): } elsif ($item eq 'unamemap_rule') {
18043:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
18044:2): my @rulenames;
18045:2): if (ref($unamemaprules) eq 'HASH') {
18046:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
18047:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
18048:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
18049:2): }
18050:2): }
18051:2): }
18052:2): if (@rulenames) {
18053:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
18054:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
18055:2): '</li>';
18056:2): } else {
14(raebu 18057:23): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
18058:23): }
8(raebur 18059:2): } else {
18060:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
18061:2): }
1.160.6.40 raeburn 18062: } else {
18063: my $value = $env{'form.'.$item};
18064: if ($value eq '') {
18065: $value = &mt('none');
18066: } elsif ($item eq 'auth_def') {
18067: my %authnames = &authtype_names();
18068: my %shortauth = (
18069: internal => 'int',
18070: krb4 => 'krb4',
18071: krb5 => 'krb5',
18072: localauth => 'loc',
1.160.6.118.2 14(raebu 18073:23): lti => 'lti',
1.160.6.40 raeburn 18074: );
18075: $value = $authnames{$shortauth{$value}};
18076: }
18077: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 18078:23): $mailmsgtext .= "$title->{$item} set to $value\n";
18079:23): if ($item eq 'portal_def') {
18080:23): if ($env{'form.'.$item} ne '') {
18081:23): foreach my $field ('email','web') {
18082:23): $value = $env{'form.'.$item.'_'.$field};
18083:23): if ($value) {
18084:23): $value = &mt('Yes');
18085:23): } else {
18086:23): $value = &mt('No');
18087:23): }
18088:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
18089:23): }
18090:23): }
18091:23): }
1.43 raeburn 18092: }
18093: }
18094: $resulttext .= '</ul>';
18095: $mailmsgtext .= "\n";
18096: my $cachetime = 24*60*60;
1.72 raeburn 18097: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 18098: if (ref($lastactref) eq 'HASH') {
18099: $lastactref->{'domdefaults'} = 1;
18100: }
1.68 raeburn 18101: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 18102: my $notify = 1;
18103: if (ref($domconfig{'contacts'}) eq 'HASH') {
18104: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18105: $notify = 0;
18106: }
18107: }
18108: if ($notify) {
18109: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18110: "LON-CAPA Domain Settings Change - $dom",
18111: $mailmsgtext);
18112: }
1.54 raeburn 18113: }
1.43 raeburn 18114: } else {
1.54 raeburn 18115: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18116: }
18117: } else {
18118: $resulttext = '<span class="LC_error">'.
18119: &mt('An error occurred: [_1]',$putresult).'</span>';
18120: }
18121: if (@errors > 0) {
18122: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18123: foreach my $item (@errors) {
18124: $resulttext .= ' "'.$title->{$item}.'",';
18125: }
18126: $resulttext =~ s/,$//;
18127: }
18128: return $resulttext;
18129: }
18130:
1.46 raeburn 18131: sub modify_scantron {
1.160.6.24 raeburn 18132: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18133: my ($resulttext,%confhash,%changes,$errors);
18134: my $custom = 'custom.tab';
18135: my $default = 'default.tab';
18136: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 18137: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18138: &config_check($dom,$confname,$servadm);
18139: if ($env{'form.scantronformat.filename'} ne '') {
18140: my $error;
18141: if ($configuserok eq 'ok') {
18142: if ($switchserver) {
1.130 raeburn 18143: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18144: } else {
18145: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 18146:23): my $modified = [];
1.46 raeburn 18147: my ($result,$scantronurl) =
1.160.6.118.2 14(raebu 18148:23): &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
18149:23): $confname,'scantron','','',$custom,
18150:23): $modified);
1.46 raeburn 18151: if ($result eq 'ok') {
18152: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18153: $changes{'scantronformat'} = 1;
1.160.6.118.2 14(raebu 18154:23): &update_modify_urls($r,$modified);
1.46 raeburn 18155: } else {
18156: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18157: }
18158: } else {
18159: $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);
18160: }
18161: }
18162: } else {
18163: $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);
18164: }
18165: if ($error) {
18166: &Apache::lonnet::logthis($error);
18167: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18168: }
18169: }
1.48 raeburn 18170: if (ref($domconfig{'scantron'}) eq 'HASH') {
18171: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18172: if ($env{'form.scantronformat_del'}) {
18173: $confhash{'scantron'}{'scantronformat'} = '';
18174: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 18175: } else {
18176: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
18177: }
18178: }
18179: }
18180: my @options = ('hdr','pad','rem');
18181: my @fields = &scantroncsv_fields();
18182: my %titles = &scantronconfig_titles();
18183: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
18184: my ($newdat,$currdat,%newcol,%currcol);
18185: if (grep(/^dat$/,@formats)) {
18186: $confhash{'scantron'}{config}{dat} = 1;
18187: $newdat = 1;
18188: } else {
18189: $newdat = 0;
18190: }
18191: if (grep(/^csv$/,@formats)) {
18192: my %bynum;
18193: foreach my $field (@fields) {
18194: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18195: my $posscol = $1;
18196: if (($posscol < 20) && (!$bynum{$posscol})) {
18197: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
18198: $bynum{$posscol} = $field;
18199: $newcol{$field} = $posscol;
18200: }
18201: }
18202: }
18203: if (keys(%newcol)) {
18204: foreach my $option (@options) {
18205: if ($env{'form.scantroncsv_'.$option}) {
18206: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18207: }
18208: }
18209: }
18210: }
18211: $currdat = 1;
18212: if (ref($domconfig{'scantron'}) eq 'HASH') {
18213: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
18214: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
18215: $currdat = 0;
18216: }
18217: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18218: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18219: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18220: }
18221: }
18222: }
18223: }
18224: if ($currdat != $newdat) {
18225: $changes{'config'} = 1;
18226: } else {
18227: foreach my $field (@fields) {
18228: if ($currcol{$field} ne '') {
18229: if ($currcol{$field} ne $newcol{$field}) {
18230: $changes{'config'} = 1;
18231: last;
18232: }
18233: } elsif ($newcol{$field} ne '') {
18234: $changes{'config'} = 1;
18235: last;
1.46 raeburn 18236: }
18237: }
18238: }
18239: if (keys(%confhash) > 0) {
18240: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18241: $dom);
18242: if ($putresult eq 'ok') {
18243: if (keys(%changes) > 0) {
1.48 raeburn 18244: if (ref($confhash{'scantron'}) eq 'HASH') {
18245: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 18246: if ($changes{'scantronformat'}) {
18247: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18248: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18249: } else {
18250: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18251: }
18252: }
18253: if ($changes{'config'}) {
18254: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18255: if ($confhash{'scantron'}{'config'}{'dat'}) {
18256: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18257: }
18258: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18259: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18260: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18261: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18262: foreach my $field (@fields) {
18263: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18264: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18265: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18266: }
18267: }
18268: $resulttext .= '</ul></li>';
18269: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18270: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18271: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18272: foreach my $option (@options) {
18273: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18274: $resulttext .= '<li>'.$titles{$option}.'</li>';
18275: }
18276: }
18277: $resulttext .= '</ul></li>';
18278: }
18279: }
18280: }
18281: }
18282: }
18283: } else {
18284: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18285: }
1.46 raeburn 18286: }
1.48 raeburn 18287: $resulttext .= '</ul>';
18288: } else {
1.130 raeburn 18289: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18290: }
18291: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 18292: if (ref($lastactref) eq 'HASH') {
18293: $lastactref->{'domainconfig'} = 1;
18294: }
1.46 raeburn 18295: } else {
1.160.6.97 raeburn 18296: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18297: }
18298: } else {
18299: $resulttext = '<span class="LC_error">'.
18300: &mt('An error occurred: [_1]',$putresult).'</span>';
18301: }
18302: } else {
1.160.6.97 raeburn 18303: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18304: }
18305: if ($errors) {
1.160.6.118.2 14(raebu 18306:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18307:23): $errors.'</ul></p>';
1.46 raeburn 18308: }
18309: return $resulttext;
18310: }
18311:
1.48 raeburn 18312: sub modify_coursecategories {
1.160.6.43 raeburn 18313: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18314: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18315: $cathash);
1.48 raeburn 18316: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 18317: my @catitems = ('unauth','auth');
18318: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18319: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18320: $cathash = $domconfig{'coursecategories'}{'cats'};
18321: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18322: $changes{'togglecats'} = 1;
18323: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18324: }
18325: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18326: $changes{'categorize'} = 1;
18327: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18328: }
1.120 raeburn 18329: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18330: $changes{'togglecatscomm'} = 1;
18331: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18332: }
18333: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18334: $changes{'categorizecomm'} = 1;
18335: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
18336: }
1.160.6.42 raeburn 18337: foreach my $item (@catitems) {
18338: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18339: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18340: $changes{$item} = 1;
18341: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18342: }
18343: }
18344: }
1.57 raeburn 18345: } else {
18346: $changes{'togglecats'} = 1;
18347: $changes{'categorize'} = 1;
1.124 raeburn 18348: $changes{'togglecatscomm'} = 1;
18349: $changes{'categorizecomm'} = 1;
1.87 raeburn 18350: $domconfig{'coursecategories'} = {
18351: togglecats => $env{'form.togglecats'},
18352: categorize => $env{'form.categorize'},
1.124 raeburn 18353: togglecatscomm => $env{'form.togglecatscomm'},
18354: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 18355: };
1.160.6.42 raeburn 18356: foreach my $item (@catitems) {
18357: if ($env{'form.coursecat_'.$item} ne 'std') {
18358: $changes{$item} = 1;
18359: }
18360: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18361: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18362: }
18363: }
1.57 raeburn 18364: }
18365: if (ref($cathash) eq 'HASH') {
18366: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18367: push (@deletecategory,'instcode::0');
18368: }
1.120 raeburn 18369: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18370: push(@deletecategory,'communities::0');
18371: }
1.48 raeburn 18372: }
1.57 raeburn 18373: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18374: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18375: if (@deletecategory > 0) {
18376: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18377: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18378: foreach my $item (@deletecategory) {
1.57 raeburn 18379: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18380: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18381: $deletions{$item} = 1;
1.57 raeburn 18382: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18383: }
18384: }
18385: }
1.57 raeburn 18386: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18387: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18388: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18389: $reorderings{$item} = 1;
1.57 raeburn 18390: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18391: }
18392: if ($env{'form.addcategory_name_'.$item} ne '') {
18393: my $newcat = $env{'form.addcategory_name_'.$item};
18394: my $newdepth = $depth+1;
18395: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18396: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18397: $adds{$newitem} = 1;
18398: }
18399: if ($env{'form.subcat_'.$item} ne '') {
18400: my $newcat = $env{'form.subcat_'.$item};
18401: my $newdepth = $depth+1;
18402: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18403: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18404: $adds{$newitem} = 1;
18405: }
18406: }
18407: }
18408: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18409: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18410: my $newitem = 'instcode::0';
1.57 raeburn 18411: if ($cathash->{$newitem} eq '') {
18412: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18413: $adds{$newitem} = 1;
18414: }
18415: } else {
18416: my $newitem = 'instcode::0';
1.57 raeburn 18417: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18418: $adds{$newitem} = 1;
18419: }
18420: }
1.120 raeburn 18421: if ($env{'form.communities'} eq '1') {
18422: if (ref($cathash) eq 'HASH') {
18423: my $newitem = 'communities::0';
18424: if ($cathash->{$newitem} eq '') {
18425: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18426: $adds{$newitem} = 1;
18427: }
18428: } else {
18429: my $newitem = 'communities::0';
18430: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18431: $adds{$newitem} = 1;
18432: }
18433: }
1.48 raeburn 18434: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18435: if (($env{'form.addcategory_name'} ne 'instcode') &&
18436: ($env{'form.addcategory_name'} ne 'communities')) {
18437: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18438: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18439: $adds{$newitem} = 1;
18440: }
1.48 raeburn 18441: }
1.57 raeburn 18442: my $putresult;
1.48 raeburn 18443: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18444: if (keys(%deletions) > 0) {
18445: foreach my $key (keys(%deletions)) {
18446: if ($predelallitems{$key} ne '') {
18447: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18448: }
18449: }
18450: }
18451: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18452: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18453: if (ref($chkcats[0]) eq 'ARRAY') {
18454: my $depth = 0;
18455: my $chg = 0;
18456: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18457: my $name = $chkcats[0][$i];
18458: my $item;
18459: if ($name eq '') {
18460: $chg ++;
18461: } else {
18462: $item = &escape($name).'::0';
18463: if ($chg) {
1.57 raeburn 18464: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18465: }
18466: $depth ++;
1.57 raeburn 18467: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18468: $depth --;
18469: }
18470: }
18471: }
1.57 raeburn 18472: }
18473: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18474: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18475: if ($putresult eq 'ok') {
1.57 raeburn 18476: my %title = (
1.120 raeburn 18477: togglecats => 'Show/Hide a course in catalog',
18478: categorize => 'Assign a category to a course',
18479: togglecatscomm => 'Show/Hide a community in catalog',
18480: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18481: );
18482: my %level = (
1.120 raeburn 18483: dom => 'set in Domain ("Modify Course/Community")',
18484: crs => 'set in Course ("Course Configuration")',
18485: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 18486: none => 'No catalog',
18487: std => 'Standard catalog',
18488: domonly => 'Domain-only catalog',
18489: codesrch => 'Code search form',
1.57 raeburn 18490: );
1.48 raeburn 18491: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18492: if ($changes{'togglecats'}) {
18493: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18494: }
18495: if ($changes{'categorize'}) {
18496: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18497: }
1.120 raeburn 18498: if ($changes{'togglecatscomm'}) {
18499: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18500: }
18501: if ($changes{'categorizecomm'}) {
18502: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18503: }
1.160.6.42 raeburn 18504: if ($changes{'unauth'}) {
18505: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18506: }
18507: if ($changes{'auth'}) {
18508: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18509: }
1.57 raeburn 18510: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18511: my $cathash;
18512: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18513: $cathash = $domconfig{'coursecategories'}{'cats'};
18514: } else {
18515: $cathash = {};
18516: }
18517: my (@cats,@trails,%allitems);
18518: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18519: if (keys(%deletions) > 0) {
18520: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18521: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18522: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18523: }
18524: $resulttext .= '</ul></li>';
18525: }
18526: if (keys(%reorderings) > 0) {
18527: my %sort_by_trail;
18528: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18529: foreach my $key (keys(%reorderings)) {
18530: if ($allitems{$key} ne '') {
18531: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18532: }
1.48 raeburn 18533: }
1.57 raeburn 18534: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18535: $resulttext .= '<li>'.$trails[$trail].'</li>';
18536: }
18537: $resulttext .= '</ul></li>';
1.48 raeburn 18538: }
1.57 raeburn 18539: if (keys(%adds) > 0) {
18540: my %sort_by_trail;
18541: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18542: foreach my $key (keys(%adds)) {
18543: if ($allitems{$key} ne '') {
18544: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18545: }
18546: }
18547: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18548: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18549: }
1.57 raeburn 18550: $resulttext .= '</ul></li>';
1.48 raeburn 18551: }
1.160.6.92 raeburn 18552: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18553: if (ref($lastactref) eq 'HASH') {
18554: $lastactref->{'cats'} = 1;
18555: }
1.48 raeburn 18556: }
18557: $resulttext .= '</ul>';
1.160.6.43 raeburn 18558: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 18559: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18560: if ($changes{'auth'}) {
18561: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18562: }
18563: if ($changes{'unauth'}) {
18564: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18565: }
18566: my $cachetime = 24*60*60;
18567: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 18568: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 18569: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 18570: }
18571: }
1.48 raeburn 18572: } else {
18573: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18574: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18575: }
18576: } else {
1.120 raeburn 18577: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18578: }
18579: return $resulttext;
18580: }
18581:
1.69 raeburn 18582: sub modify_serverstatuses {
18583: my ($dom,%domconfig) = @_;
18584: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18585: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18586: %currserverstatus = %{$domconfig{'serverstatuses'}};
18587: }
18588: my @pages = &serverstatus_pages();
18589: foreach my $type (@pages) {
18590: $newserverstatus{$type}{'namedusers'} = '';
18591: $newserverstatus{$type}{'machines'} = '';
18592: if (defined($env{'form.'.$type.'_namedusers'})) {
18593: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18594: my @okusers;
18595: foreach my $user (@users) {
18596: my ($uname,$udom) = split(/:/,$user);
18597: if (($udom =~ /^$match_domain$/) &&
18598: (&Apache::lonnet::domain($udom)) &&
18599: ($uname =~ /^$match_username$/)) {
18600: if (!grep(/^\Q$user\E/,@okusers)) {
18601: push(@okusers,$user);
18602: }
18603: }
18604: }
18605: if (@okusers > 0) {
18606: @okusers = sort(@okusers);
18607: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18608: }
18609: }
18610: if (defined($env{'form.'.$type.'_machines'})) {
18611: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18612: my @okmachines;
18613: foreach my $ip (@machines) {
18614: my @parts = split(/\./,$ip);
18615: next if (@parts < 4);
18616: my $badip = 0;
18617: for (my $i=0; $i<4; $i++) {
18618: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18619: $badip = 1;
18620: last;
18621: }
18622: }
18623: if (!$badip) {
18624: push(@okmachines,$ip);
18625: }
18626: }
18627: @okmachines = sort(@okmachines);
18628: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18629: }
18630: }
18631: my %serverstatushash = (
18632: serverstatuses => \%newserverstatus,
18633: );
18634: foreach my $type (@pages) {
1.83 raeburn 18635: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18636: my (@current,@new);
1.83 raeburn 18637: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18638: if ($currserverstatus{$type}{$setting} ne '') {
18639: @current = split(/,/,$currserverstatus{$type}{$setting});
18640: }
18641: }
18642: if ($newserverstatus{$type}{$setting} ne '') {
18643: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18644: }
18645: if (@current > 0) {
18646: if (@new > 0) {
18647: foreach my $item (@current) {
18648: if (!grep(/^\Q$item\E$/,@new)) {
18649: $changes{$type}{$setting} = 1;
1.82 raeburn 18650: last;
18651: }
18652: }
1.84 raeburn 18653: foreach my $item (@new) {
18654: if (!grep(/^\Q$item\E$/,@current)) {
18655: $changes{$type}{$setting} = 1;
18656: last;
1.82 raeburn 18657: }
18658: }
18659: } else {
1.83 raeburn 18660: $changes{$type}{$setting} = 1;
1.69 raeburn 18661: }
1.83 raeburn 18662: } elsif (@new > 0) {
18663: $changes{$type}{$setting} = 1;
1.69 raeburn 18664: }
18665: }
18666: }
18667: if (keys(%changes) > 0) {
1.81 raeburn 18668: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18669: my $putresult = &Apache::lonnet::put_dom('configuration',
18670: \%serverstatushash,$dom);
18671: if ($putresult eq 'ok') {
18672: $resulttext .= &mt('Changes made:').'<ul>';
18673: foreach my $type (@pages) {
1.84 raeburn 18674: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18675: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18676: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18677: if ($newserverstatus{$type}{'namedusers'} eq '') {
18678: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18679: } else {
18680: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18681: }
1.84 raeburn 18682: }
18683: if ($changes{$type}{'machines'}) {
1.69 raeburn 18684: if ($newserverstatus{$type}{'machines'} eq '') {
18685: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18686: } else {
18687: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18688: }
18689:
18690: }
18691: $resulttext .= '</ul></li>';
18692: }
18693: }
18694: $resulttext .= '</ul>';
18695: } else {
18696: $resulttext = '<span class="LC_error">'.
18697: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18698:
18699: }
18700: } else {
18701: $resulttext = &mt('No changes made to access to server status pages');
18702: }
18703: return $resulttext;
18704: }
18705:
1.118 jms 18706: sub modify_helpsettings {
1.160.6.77 raeburn 18707: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 18708: my ($resulttext,$errors,%changes,%helphash);
18709: my %defaultchecked = ('submitbugs' => 'on');
18710: my @offon = ('off','on');
1.118 jms 18711: my @toggles = ('submitbugs');
1.160.6.77 raeburn 18712: my %current = ('submitbugs' => '',
18713: 'adhoc' => {},
18714: );
1.118 jms 18715: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 18716: %current = %{$domconfig{'helpsettings'}};
18717: }
1.160.6.77 raeburn 18718: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 18719: foreach my $item (@toggles) {
18720: if ($defaultchecked{$item} eq 'on') {
18721: if ($current{$item} eq '') {
18722: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 18723: $changes{$item} = 1;
18724: }
1.160.6.73 raeburn 18725: } elsif ($current{$item} ne $env{'form.'.$item}) {
18726: $changes{$item} = 1;
18727: }
18728: } elsif ($defaultchecked{$item} eq 'off') {
18729: if ($current{$item} eq '') {
18730: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 18731: $changes{$item} = 1;
18732: }
1.160.6.73 raeburn 18733: } elsif ($current{$item} ne $env{'form.'.$item}) {
18734: $changes{$item} = 1;
18735: }
18736: }
18737: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18738: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18739: }
18740: }
1.160.6.77 raeburn 18741: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 18742: my $confname = $dom.'-domainconfig';
18743: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 18744: my (@allpos,%newsettings,%changedprivs,$newrole);
18745: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 18746: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18747: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 18748: my %lt = &Apache::lonlocal::texthash(
18749: s => 'system',
18750: d => 'domain',
18751: order => 'Display order',
18752: access => 'Role usage',
1.160.6.79 raeburn 18753: all => 'All with domain helpdesk or helpdesk assistant role',
18754: dh => 'All with domain helpdesk role',
18755: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 18756: none => 'None',
18757: status => 'Determined based on institutional status',
18758: inc => 'Include all, but exclude specific personnel',
18759: exc => 'Exclude all, but include specific personnel',
18760: );
18761: for (my $num=0; $num<=$maxnum; $num++) {
18762: my ($prefix,$identifier,$rolename,%curr);
18763: if ($num == $maxnum) {
18764: next unless ($env{'form.newcusthelp'} == $maxnum);
18765: $identifier = 'custhelp'.$num;
18766: $prefix = 'helproles_'.$num;
18767: $rolename = $env{'form.custhelpname'.$num};
18768: $rolename=~s/[^A-Za-z0-9]//gs;
18769: next if ($rolename eq '');
18770: next if (exists($existing{'rolesdef_'.$rolename}));
18771: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18772: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18773: $newprivs{'c'},$confname,$dom);
18774: if ($result ne 'ok') {
18775: $errors .= '<li><span class="LC_error">'.
18776: &mt('An error occurred storing the new custom role: [_1]',
18777: $result).'</span></li>';
18778: next;
18779: } else {
18780: $changedprivs{$rolename} = \%newprivs;
18781: $newrole = $rolename;
18782: }
18783: } else {
18784: $prefix = 'helproles_'.$num;
18785: $rolename = $env{'form.'.$prefix};
18786: next if ($rolename eq '');
18787: next unless (exists($existing{'rolesdef_'.$rolename}));
18788: $identifier = 'custhelp'.$num;
18789: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18790: my %currprivs;
18791: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18792: split(/\_/,$existing{'rolesdef_'.$rolename});
18793: foreach my $level ('c','d','s') {
18794: if ($newprivs{$level} ne $currprivs{$level}) {
18795: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18796: $newprivs{'c'},$confname,$dom);
18797: if ($result ne 'ok') {
18798: $errors .= '<li><span class="LC_error">'.
18799: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18800: $rolename,$result).'</span></li>';
18801: } else {
18802: $changedprivs{$rolename} = \%newprivs;
18803: }
18804: last;
18805: }
18806: }
18807: if (ref($current{'adhoc'}) eq 'HASH') {
18808: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18809: %curr = %{$current{'adhoc'}{$rolename}};
18810: }
18811: }
18812: }
18813: my $newpos = $env{'form.'.$prefix.'_pos'};
18814: $newpos =~ s/\D+//g;
18815: $allpos[$newpos] = $rolename;
18816: my $newdesc = $env{'form.'.$prefix.'_desc'};
18817: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18818: if ($curr{'desc'}) {
18819: if ($curr{'desc'} ne $newdesc) {
18820: $changes{'customrole'}{$rolename}{'desc'} = 1;
18821: $newsettings{$rolename}{'desc'} = $newdesc;
18822: }
18823: } elsif ($newdesc ne '') {
18824: $changes{'customrole'}{$rolename}{'desc'} = 1;
18825: $newsettings{$rolename}{'desc'} = $newdesc;
18826: }
18827: my $access = $env{'form.'.$prefix.'_access'};
18828: if (grep(/^\Q$access\E$/,@accesstypes)) {
18829: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18830: if ($access eq 'status') {
18831: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18832: if (scalar(@statuses) == 0) {
18833: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18834: } else {
18835: my (@shownstatus,$numtypes);
18836: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18837: if (ref($types) eq 'ARRAY') {
18838: $numtypes = scalar(@{$types});
18839: foreach my $type (sort(@statuses)) {
18840: if ($type eq 'default') {
18841: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18842: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18843: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18844: push(@shownstatus,$usertypes->{$type});
18845: }
1.160.6.73 raeburn 18846: }
18847: }
1.160.6.77 raeburn 18848: if (grep(/^default$/,@statuses)) {
18849: push(@shownstatus,$othertitle);
18850: }
18851: if (scalar(@shownstatus) == 1+$numtypes) {
18852: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18853: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18854: } else {
18855: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18856: if (ref($curr{'status'}) eq 'ARRAY') {
18857: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18858: if (@diffs) {
18859: $changes{'customrole'}{$rolename}{$access} = 1;
18860: }
18861: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18862: $changes{'customrole'}{$rolename}{$access} = 1;
18863: }
18864: }
18865: }
18866: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18867: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18868: my @newspecstaff;
18869: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18870: foreach my $person (sort(@personnel)) {
18871: if ($domhelpdesk{$person}) {
18872: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18873: }
18874: }
18875: if (ref($curr{$access}) eq 'ARRAY') {
18876: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18877: if (@diffs) {
18878: $changes{'customrole'}{$rolename}{$access} = 1;
18879: }
18880: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18881: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 18882: }
1.160.6.77 raeburn 18883: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18884: my ($uname,$udom) = split(/:/,$person);
18885: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18886: }
18887: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 18888: }
1.160.6.77 raeburn 18889: } else {
18890: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18891: }
18892: unless ($curr{'access'} eq $access) {
18893: $changes{'customrole'}{$rolename}{'access'} = 1;
18894: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 18895: }
18896: }
1.160.6.77 raeburn 18897: if (@allpos > 0) {
18898: my $idx = 0;
18899: foreach my $rolename (@allpos) {
18900: if ($rolename ne '') {
18901: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18902: if (ref($current{'adhoc'}) eq 'HASH') {
18903: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18904: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18905: $changes{'customrole'}{$rolename}{'order'} = 1;
18906: $newsettings{$rolename}{'order'} = $idx+1;
18907: }
18908: }
1.160.6.73 raeburn 18909: }
1.160.6.77 raeburn 18910: $idx ++;
1.122 jms 18911: }
18912: }
1.118 jms 18913: }
1.123 jms 18914: my $putresult;
18915: if (keys(%changes) > 0) {
1.160.6.5 raeburn 18916: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18917: if ($putresult eq 'ok') {
1.160.6.77 raeburn 18918: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18919: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18920: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18921: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18922: }
18923: }
18924: my $cachetime = 24*60*60;
18925: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18926: if (ref($lastactref) eq 'HASH') {
18927: $lastactref->{'domdefaults'} = 1;
18928: }
18929: } else {
18930: $errors .= '<li><span class="LC_error">'.
18931: &mt('An error occurred storing the settings: [_1]',
18932: $putresult).'</span></li>';
18933: }
18934: }
18935: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18936: $resulttext = &mt('Changes made:').'<ul>';
18937: my (%shownprivs,@levelorder);
18938: @levelorder = ('c','d','s');
18939: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 18940: foreach my $item (sort(keys(%changes))) {
18941: if ($item eq 'submitbugs') {
18942: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18943: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18944: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 18945: } elsif ($item eq 'customrole') {
18946: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 18947: my @keyorder = ('order','desc','access','status','exc','inc');
18948: my %keytext = &Apache::lonlocal::texthash(
18949: order => 'Order',
18950: desc => 'Role description',
18951: access => 'Role usage',
1.160.6.83 raeburn 18952: status => 'Allowed institutional types',
1.160.6.77 raeburn 18953: exc => 'Allowed personnel',
18954: inc => 'Disallowed personnel',
18955: );
1.160.6.73 raeburn 18956: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 18957: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18958: if ($role eq $newrole) {
18959: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
18960: $role).'<ul>';
18961: } else {
18962: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
18963: $role).'<ul>';
18964: }
18965: foreach my $key (@keyorder) {
18966: if ($changes{'customrole'}{$role}{$key}) {
18967: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
18968: $keytext{$key},$newsettings{$role}{$key}).
18969: '</li>';
18970: }
18971: }
18972: if (ref($changedprivs{$role}) eq 'HASH') {
18973: $shownprivs{$role} = 1;
18974: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
18975: foreach my $level (@levelorder) {
18976: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
18977: next if ($item eq '');
18978: my ($priv) = split(/\&/,$item,2);
18979: if (&Apache::lonnet::plaintext($priv)) {
18980: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
18981: unless ($level eq 'c') {
18982: $resulttext .= ' ('.$lt{$level}.')';
18983: }
18984: $resulttext .= '</li>';
18985: }
18986: }
18987: }
18988: $resulttext .= '</ul>';
18989: }
18990: $resulttext .= '</ul></li>';
18991: }
1.160.6.73 raeburn 18992: }
18993: }
1.160.6.5 raeburn 18994: }
18995: }
18996: }
1.160.6.77 raeburn 18997: if (keys(%changedprivs)) {
18998: foreach my $role (sort(keys(%changedprivs))) {
18999: unless ($shownprivs{$role}) {
19000: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19001: $role).'<ul>'.
19002: '<li>'.&mt('Privileges set to :').'<ul>';
19003: foreach my $level (@levelorder) {
19004: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19005: next if ($item eq '');
19006: my ($priv) = split(/\&/,$item,2);
19007: if (&Apache::lonnet::plaintext($priv)) {
19008: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19009: unless ($level eq 'c') {
19010: $resulttext .= ' ('.$lt{$level}.')';
19011: }
19012: $resulttext .= '</li>';
19013: }
19014: }
19015: }
19016: $resulttext .= '</ul></li></ul></li>';
19017: }
19018: }
19019: }
19020: $resulttext .= '</ul>';
19021: } else {
19022: $resulttext = &mt('No changes made to help settings');
1.118 jms 19023: }
19024: if ($errors) {
1.160.6.5 raeburn 19025: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 19026: $errors.'</ul>';
1.118 jms 19027: }
19028: return $resulttext;
19029: }
19030:
1.121 raeburn 19031: sub modify_coursedefaults {
1.160.6.27 raeburn 19032: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19033: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 19034: my %defaultchecked = (
19035: 'uselcmath' => 'on',
1.160.6.115 raeburn 19036: 'usejsme' => 'on',
19037: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 19038:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 19039: );
1.160.6.118.2 4(raebur 19040:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 19041: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.118.2 15(raebu 19042:23): 'uploadquota_community','uploadquota_textbook','coursequota_official',
19043:23): 'coursequota_unofficial','coursequota_community','coursequota_textbook',
19044:23): 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19045:23): 'mysqltables_textbook');
1.160.6.30 raeburn 19046: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 19047: my %staticdefaults = (
19048: anonsurvey_threshold => 10,
19049: uploadquota => 500,
1.160.6.118.2 15(raebu 19050:23): coursequota => 20,
1.160.6.57 raeburn 19051: postsubmit => 60,
1.160.6.70 raeburn 19052: mysqltables => 172800,
1.160.6.118.2 14(raebu 19053:23): domexttool => 1,
22(raebu 19054:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 19055: );
1.160.6.90 raeburn 19056: my %texoptions = (
19057: MathJax => 'MathJax',
19058: mimetex => &mt('Convert to Images'),
19059: tth => &mt('TeX to HTML'),
19060: );
1.160.6.118.2 22(raebu 19061:24):
19062:24): my @editors = ('edit','xml','daxe');
19063:24): my %editornames = &crseditor_titles();
19064:24):
1.121 raeburn 19065: $defaultshash{'coursedefaults'} = {};
19066:
19067: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19068: if ($domconfig{'coursedefaults'} eq '') {
19069: $domconfig{'coursedefaults'} = {};
19070: }
19071: }
19072:
19073: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19074: foreach my $item (@toggles) {
19075: if ($defaultchecked{$item} eq 'on') {
19076: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19077: ($env{'form.'.$item} eq '0')) {
19078: $changes{$item} = 1;
1.160.6.16 raeburn 19079: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19080: $changes{$item} = 1;
19081: }
19082: } elsif ($defaultchecked{$item} eq 'off') {
19083: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19084: ($env{'form.'.$item} eq '1')) {
19085: $changes{$item} = 1;
19086: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19087: $changes{$item} = 1;
19088: }
19089: }
19090: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19091: }
1.160.6.21 raeburn 19092: foreach my $item (@numbers) {
19093: my ($currdef,$newdef);
1.160.6.26 raeburn 19094: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 19095: if ($item eq 'anonsurvey_threshold') {
19096: $currdef = $domconfig{'coursedefaults'}{$item};
19097: $newdef =~ s/\D//g;
19098: if ($newdef eq '' || $newdef < 1) {
19099: $newdef = 1;
19100: }
19101: $defaultshash{'coursedefaults'}{$item} = $newdef;
19102: } else {
1.160.6.118.2 15(raebu 19103:23): my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.160.6.70 raeburn 19104: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19105: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 19106: }
19107: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 19108: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 19109: }
19110: if ($currdef ne $newdef) {
19111: if ($item eq 'anonsurvey_threshold') {
19112: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19113: $changes{$item} = 1;
19114: }
1.160.6.118.2 15(raebu 19115:23): } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.160.6.70 raeburn 19116: my $setting = $1;
19117: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19118: $changes{$setting} = 1;
1.160.6.21 raeburn 19119: }
19120: }
1.139 raeburn 19121: }
19122: }
1.160.6.90 raeburn 19123: my $texengine;
19124: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19125: $texengine = $env{'form.texengine'};
19126: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19127: if ($currdef eq '') {
19128: unless ($texengine eq $Apache::lonnet::deftex) {
19129: $changes{'texengine'} = 1;
19130: }
19131: } elsif ($currdef ne $texengine) {
19132: $changes{'texengine'} = 1;
19133: }
19134: }
19135: if ($texengine ne '') {
19136: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19137: }
1.160.6.64 raeburn 19138: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19139: my @currclonecode;
19140: if (ref($currclone) eq 'HASH') {
19141: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19142: @currclonecode = @{$currclone->{'instcode'}};
19143: }
19144: }
19145: my $newclone;
19146: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
19147: $newclone = $env{'form.canclone'};
19148: }
19149: if ($newclone eq 'instcode') {
19150: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19151: my (%codedefaults,@code_order,@clonecode);
19152: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19153: \@code_order);
19154: foreach my $item (@code_order) {
19155: if (grep(/^\Q$item\E$/,@newcodes)) {
19156: push(@clonecode,$item);
19157: }
19158: }
19159: if (@clonecode) {
19160: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19161: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19162: if (@diffs) {
19163: $changes{'canclone'} = 1;
19164: }
19165: } else {
19166: $newclone eq '';
19167: }
19168: } elsif ($newclone ne '') {
19169: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19170: }
19171: if ($newclone ne $currclone) {
19172: $changes{'canclone'} = 1;
19173: }
1.160.6.57 raeburn 19174: my %credits;
19175: foreach my $type (@types) {
19176: unless ($type eq 'community') {
19177: $credits{$type} = $env{'form.'.$type.'_credits'};
19178: $credits{$type} =~ s/[^\d.]+//g;
19179: }
19180: }
19181: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19182: ($env{'form.coursecredits'} eq '1')) {
19183: $changes{'coursecredits'} = 1;
19184: foreach my $type (keys(%credits)) {
19185: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19186: }
19187: } else {
19188: if ($env{'form.coursecredits'} eq '1') {
19189: foreach my $type (@types) {
19190: unless ($type eq 'community') {
19191: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
19192: $changes{'coursecredits'} = 1;
19193: }
19194: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19195: }
19196: }
19197: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19198: foreach my $type (@types) {
19199: unless ($type eq 'community') {
19200: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19201: $changes{'coursecredits'} = 1;
19202: last;
19203: }
19204: }
19205: }
19206: }
19207: }
19208: if ($env{'form.postsubmit'} eq '1') {
19209: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19210: my %currtimeout;
19211: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19212: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19213: $changes{'postsubmit'} = 1;
19214: }
19215: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19216: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19217: }
19218: } else {
19219: $changes{'postsubmit'} = 1;
19220: }
19221: foreach my $type (@types) {
19222: my $timeout = $env{'form.'.$type.'_timeout'};
19223: $timeout =~ s/\D//g;
19224: if ($timeout == $staticdefaults{'postsubmit'}) {
19225: $timeout = '';
19226: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19227: $timeout = '0';
19228: }
19229: unless ($timeout eq '') {
19230: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19231: }
19232: if (exists($currtimeout{$type})) {
19233: if ($timeout ne $currtimeout{$type}) {
19234: $changes{'postsubmit'} = 1;
19235: }
19236: } elsif ($timeout ne '') {
19237: $changes{'postsubmit'} = 1;
19238: }
19239: }
19240: } else {
19241: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19242: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19243: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19244: $changes{'postsubmit'} = 1;
19245: }
19246: } else {
19247: $changes{'postsubmit'} = 1;
19248: }
1.160.6.16 raeburn 19249: }
1.160.6.118.2 22(raebu 19250:24): my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool,%posscrseditors);
14(raebu 19251:23): map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
19252:23): map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
22(raebu 19253:24): map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
14(raebu 19254:23): if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19255:23): %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
19256:23): } else {
19257:23): foreach my $type (@types) {
19258:23): if ($staticdefaults{'domexttool'}) {
19259:23): $olddomexttool{$type} = 1;
19260:23): } else {
19261:23): $olddomexttool{$type} = 0;
19262:23): }
19263:23): }
19264:23): }
19265:23): if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
19266:23): %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
19267:23): } else {
19268:23): foreach my $type (@types) {
19269:23): if ($staticdefaults{'exttool'}) {
19270:23): $oldexttool{$type} = 1;
19271:23): } else {
19272:23): $oldexttool{$type} = 0;
19273:23): }
19274:23): }
19275:23): }
22(raebu 19276:24): my @newcrseditors = ();
19277:24): foreach my $editor (@editors) {
19278:24): if ($posscrseditors{$editor}) {
19279:24): push(@newcrseditors,$editor);
19280:24): }
19281:24): }
19282:24): if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19283:24): my @diffs =
19284:24): &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
19285:24): \@newcrseditors);
19286:24): if (@diffs) {
19287:24): $changes{'crseditors'} = 1;
19288:24): }
19289:24): } else {
19290:24): my @diffs =
19291:24): &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
19292:24): \@newcrseditors);
19293:24): unless (@diffs == 0) {
19294:24): $changes{'crseditors'} = 1;
19295:24): }
19296:24): }
14(raebu 19297:23): foreach my $type (@types) {
19298:23): unless ($newdomexttool{$type}) {
19299:23): $newdomexttool{$type} = 0;
19300:23): }
19301:23): unless ($newexttool{$type}) {
19302:23): $newexttool{$type} = 0;
19303:23): }
19304:23): if ($newdomexttool{$type} != $olddomexttool{$type}) {
19305:23): $changes{'domexttool'} = 1;
19306:23): }
19307:23): if ($newexttool{$type} != $oldexttool{$type}) {
19308:23): $changes{'exttool'} = 1;
19309:23): }
19310:23): }
19311:23): $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
19312:23): $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
22(raebu 19313:24): $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 19314: }
19315: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19316: $dom);
19317: if ($putresult eq 'ok') {
19318: if (keys(%changes) > 0) {
1.160.6.27 raeburn 19319: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 19320: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 19321: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 19322: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 14(raebu 19323:23): ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
15(raebu 19324:23): ($changes{'exttool'}) || ($changes{'coursequota'})) {
4(raebur 19325:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 19326: if ($changes{$item}) {
19327: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19328: }
1.160.6.16 raeburn 19329: }
19330: if ($changes{'coursecredits'}) {
19331: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 19332: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19333: $domdefaults{$type.'credits'} =
19334: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19335: }
19336: }
19337: }
19338: if ($changes{'postsubmit'}) {
19339: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19340: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19341: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19342: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19343: $domdefaults{$type.'postsubtimeout'} =
19344: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19345: }
19346: }
1.160.6.16 raeburn 19347: }
19348: }
1.160.6.21 raeburn 19349: if ($changes{'uploadquota'}) {
19350: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19351: foreach my $type (@types) {
19352: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19353: }
19354: }
19355: }
1.160.6.118.2 15(raebu 19356:23): if ($changes{'coursequota'}) {
19357:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19358:23): foreach my $type (@types) {
19359:23): $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
19360:23): }
19361:23): }
19362:23): }
1.160.6.64 raeburn 19363: if ($changes{'canclone'}) {
19364: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19365: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19366: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19367: if (@clonecodes) {
19368: $domdefaults{'canclone'} = join('+',@clonecodes);
19369: }
19370: }
19371: } else {
19372: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19373: }
19374: }
1.160.6.118.2 14(raebu 19375:23): if ($changes{'domexttool'}) {
19376:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19377:23): foreach my $type (@types) {
19378:23): $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
19379:23): }
19380:23): }
19381:23): }
19382:23): if ($changes{'exttool'}) {
19383:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19384:23): foreach my $type (@types) {
19385:23): $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
19386:23): }
19387:23): }
19388:23): }
22(raebu 19389:24): if ($changes{'crseditors'}) {
19390:24): if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19391:24): $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
19392:24): }
19393:24): }
1.121 raeburn 19394: my $cachetime = 24*60*60;
19395: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 19396: if (ref($lastactref) eq 'HASH') {
19397: $lastactref->{'domdefaults'} = 1;
19398: }
1.121 raeburn 19399: }
19400: $resulttext = &mt('Changes made:').'<ul>';
19401: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 19402: if ($item eq 'uselcmath') {
1.121 raeburn 19403: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 19404: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 19405: } else {
1.160.6.57 raeburn 19406: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19407: }
19408: } elsif ($item eq 'usejsme') {
19409: if ($env{'form.'.$item} eq '1') {
19410: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19411: } else {
19412: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 19413: }
1.160.6.115 raeburn 19414: } elsif ($item eq 'inline_chem') {
19415: if ($env{'form.'.$item} eq '1') {
19416: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
19417: } else {
19418: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
19419: }
1.160.6.90 raeburn 19420: } elsif ($item eq 'texengine') {
19421: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19422: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19423: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19424: }
1.139 raeburn 19425: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 19426: $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 19427: } elsif ($item eq 'uploadquota') {
19428: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19429: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19430: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19431: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 19432: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.160.6.21 raeburn 19433: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19434: '</ul>'.
19435: '</li>';
19436: } else {
19437: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19438: }
1.160.6.118.2 15(raebu 19439:23): } elsif ($item eq 'coursequota') {
19440:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19441:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
19442:23): '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
19443:23): '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
19444:23): '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
19445:23): '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
19446:23): '</ul>'.
19447:23): '</li>';
19448:23): } else {
19449:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
19450:23): }
1.160.6.70 raeburn 19451: } elsif ($item eq 'mysqltables') {
19452: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19453: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19454: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19455: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19456: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19457: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19458: '</ul>'.
19459: '</li>';
19460: } else {
19461: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19462: }
1.160.6.57 raeburn 19463: } elsif ($item eq 'postsubmit') {
19464: if ($domdefaults{'postsubmit'} eq 'off') {
19465: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19466: } else {
19467: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
19468: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19469: $resulttext .= &mt('durations:').'<ul>';
19470: foreach my $type (@types) {
19471: $resulttext .= '<li>';
19472: my $timeout;
19473: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19474: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19475: }
19476: my $display;
19477: if ($timeout eq '0') {
19478: $display = &mt('unlimited');
19479: } elsif ($timeout eq '') {
19480: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19481: } else {
19482: $display = &mt('[quant,_1,second]',$timeout);
19483: }
19484: if ($type eq 'community') {
19485: $resulttext .= &mt('Communities');
19486: } elsif ($type eq 'official') {
19487: $resulttext .= &mt('Official courses');
19488: } elsif ($type eq 'unofficial') {
19489: $resulttext .= &mt('Unofficial courses');
19490: } elsif ($type eq 'textbook') {
19491: $resulttext .= &mt('Textbook courses');
19492: }
19493: $resulttext .= ' -- '.$display.'</li>';
19494: }
19495: $resulttext .= '</ul>';
19496: }
19497: $resulttext .= '</li>';
19498: }
1.160.6.16 raeburn 19499: } elsif ($item eq 'coursecredits') {
19500: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19501: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 19502: ($domdefaults{'unofficialcredits'} eq '') &&
19503: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 19504: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19505: } else {
19506: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19507: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19508: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 19509: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 19510: '</ul>'.
19511: '</li>';
19512: }
19513: } else {
19514: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19515: }
1.160.6.64 raeburn 19516: } elsif ($item eq 'canclone') {
19517: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19518: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19519: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19520: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19521: }
19522: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19523: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19524: } else {
19525: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
19526: }
1.160.6.118.2 4(raebur 19527:2): } elsif ($item eq 'ltiauth') {
19528:2): if ($env{'form.'.$item} eq '1') {
19529:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
19530:2): } else {
19531:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
19532:2): }
14(raebu 19533:23): } elsif ($item eq 'domexttool') {
19534:23): my @noyes = (&mt('no'),&mt('yes'));
19535:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19536:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
19537:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
19538:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
19539:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
19540:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
19541:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
19542:23): '</ul>'.
19543:23): '</li>';
19544:23): } else {
19545:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
19546:23): }
19547:23): } elsif ($item eq 'exttool') {
19548:23): my @noyes = (&mt('no'),&mt('yes'));
19549:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19550:23): $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
19551:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
19552:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
19553:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
19554:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
19555:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
19556:23): '</ul>'.
19557:23): '</li>';
19558:23): } else {
19559:23): $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
19560:23): }
22(raebu 19561:24): } elsif ($item eq 'crseditors') {
19562:24): if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
19563:24): my $shown;
19564:24): if (@{$defaultshash{'coursedefaults'}{$item}}) {
19565:24): $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
19566:24): } else {
19567:24): $shown = &mt('None');
19568:24): }
19569:24): $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
19570:24): }
1.140 raeburn 19571: }
1.121 raeburn 19572: }
19573: $resulttext .= '</ul>';
19574: } else {
19575: $resulttext = &mt('No changes made to course defaults');
19576: }
19577: } else {
19578: $resulttext = '<span class="LC_error">'.
19579: &mt('An error occurred: [_1]',$putresult).'</span>';
19580: }
19581: return $resulttext;
19582: }
19583:
1.160.6.37 raeburn 19584: sub modify_selfenrollment {
19585: my ($dom,$lastactref,%domconfig) = @_;
19586: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
19587: my @types = ('official','unofficial','community','textbook');
19588: my %titles = &tool_titles();
19589: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19590: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
19591: $ordered{'default'} = ['types','registered','approval','limit'];
19592:
19593: my (%roles,%shown,%toplevel);
19594: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19595:
19596: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19597: if ($domconfig{'selfenrollment'} eq '') {
19598: $domconfig{'selfenrollment'} = {};
19599: }
19600: }
19601: %toplevel = (
19602: admin => 'Configuration Rights',
19603: default => 'Default settings',
19604: validation => 'Validation of self-enrollment requests',
19605: );
19606: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
19607:
19608: if (ref($ordered{'admin'}) eq 'ARRAY') {
19609: foreach my $item (@{$ordered{'admin'}}) {
19610: foreach my $type (@types) {
19611: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19612: $selfenrollhash{'admin'}{$type}{$item} = 1;
19613: } else {
19614: $selfenrollhash{'admin'}{$type}{$item} = 0;
19615: }
19616: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19617: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19618: if ($selfenrollhash{'admin'}{$type}{$item} ne
19619: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19620: push(@{$changes{'admin'}{$type}},$item);
19621: }
19622: } else {
19623: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19624: push(@{$changes{'admin'}{$type}},$item);
19625: }
19626: }
19627: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19628: push(@{$changes{'admin'}{$type}},$item);
19629: }
19630: }
19631: }
19632: }
19633:
19634: foreach my $item (@{$ordered{'default'}}) {
19635: foreach my $type (@types) {
19636: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19637: if ($item eq 'types') {
19638: unless (($value eq 'all') || ($value eq 'dom')) {
19639: $value = '';
19640: }
19641: } elsif ($item eq 'registered') {
19642: unless ($value eq '1') {
19643: $value = 0;
19644: }
19645: } elsif ($item eq 'approval') {
19646: unless ($value =~ /^[012]$/) {
19647: $value = 0;
19648: }
19649: } else {
19650: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19651: $value = 'none';
19652: }
19653: }
19654: $selfenrollhash{'default'}{$type}{$item} = $value;
19655: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19656: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19657: if ($selfenrollhash{'default'}{$type}{$item} ne
19658: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19659: push(@{$changes{'default'}{$type}},$item);
19660: }
19661: } else {
19662: push(@{$changes{'default'}{$type}},$item);
19663: }
19664: } else {
19665: push(@{$changes{'default'}{$type}},$item);
19666: }
19667: if ($item eq 'limit') {
19668: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19669: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19670: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19671: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19672: }
19673: } else {
19674: $selfenrollhash{'default'}{$type}{'cap'} = '';
19675: }
19676: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19677: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19678: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19679: push(@{$changes{'default'}{$type}},'cap');
19680: }
19681: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19682: push(@{$changes{'default'}{$type}},'cap');
19683: }
19684: }
19685: }
19686: }
19687:
19688: foreach my $item (@{$itemsref}) {
19689: if ($item eq 'fields') {
19690: my @changed;
19691: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19692: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19693: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19694: }
19695: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19696: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19697: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19698: $domconfig{'selfenrollment'}{'validation'}{$item});
19699: } else {
19700: @changed = @{$selfenrollhash{'validation'}{$item}};
19701: }
19702: } else {
19703: @changed = @{$selfenrollhash{'validation'}{$item}};
19704: }
19705: if (@changed) {
19706: if ($selfenrollhash{'validation'}{$item}) {
19707: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19708: } else {
19709: $changes{'validation'}{$item} = &mt('None');
19710: }
19711: }
19712: } else {
19713: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19714: if ($item eq 'markup') {
19715: if ($env{'form.selfenroll_validation_'.$item}) {
19716: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19717: }
19718: }
19719: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19720: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19721: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19722: }
19723: }
19724: }
19725: }
19726:
19727: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19728: $dom);
19729: if ($putresult eq 'ok') {
19730: if (keys(%changes) > 0) {
19731: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19732: $resulttext = &mt('Changes made:').'<ul>';
19733: foreach my $key ('admin','default','validation') {
19734: if (ref($changes{$key}) eq 'HASH') {
19735: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19736: if ($key eq 'validation') {
19737: foreach my $item (@{$itemsref}) {
19738: if (exists($changes{$key}{$item})) {
19739: if ($item eq 'markup') {
19740: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19741: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19742: } else {
19743: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19744: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19745: }
19746: }
19747: }
19748: } else {
19749: foreach my $type (@types) {
19750: if ($type eq 'community') {
19751: $roles{'1'} = &mt('Community personnel');
19752: } else {
19753: $roles{'1'} = &mt('Course personnel');
19754: }
19755: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19756: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19757: if ($key eq 'admin') {
19758: my @mgrdc = ();
19759: if (ref($ordered{$key}) eq 'ARRAY') {
19760: foreach my $item (@{$ordered{'admin'}}) {
19761: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19762: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19763: push(@mgrdc,$item);
19764: }
19765: }
19766: }
19767: if (@mgrdc) {
19768: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19769: } else {
19770: delete($domdefaults{$type.'selfenrolladmdc'});
19771: }
19772: }
19773: } else {
19774: if (ref($ordered{$key}) eq 'ARRAY') {
19775: foreach my $item (@{$ordered{$key}}) {
19776: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19777: $domdefaults{$type.'selfenroll'.$item} =
19778: $selfenrollhash{$key}{$type}{$item};
19779: }
19780: }
19781: }
19782: }
19783: }
19784: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19785: foreach my $item (@{$ordered{$key}}) {
19786: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19787: $resulttext .= '<li>';
19788: if ($key eq 'admin') {
19789: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19790: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19791: } else {
19792: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19793: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19794: }
19795: $resulttext .= '</li>';
19796: }
19797: }
19798: $resulttext .= '</ul></li>';
19799: }
19800: }
19801: $resulttext .= '</ul></li>';
19802: }
19803: }
1.160.6.93 raeburn 19804: }
19805: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19806: my $cachetime = 24*60*60;
19807: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19808: if (ref($lastactref) eq 'HASH') {
19809: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 19810: }
19811: }
19812: $resulttext .= '</ul>';
19813: } else {
19814: $resulttext = &mt('No changes made to self-enrollment settings');
19815: }
19816: } else {
19817: $resulttext = '<span class="LC_error">'.
19818: &mt('An error occurred: [_1]',$putresult).'</span>';
19819: }
19820: return $resulttext;
19821: }
19822:
1.160.6.113 raeburn 19823: sub modify_wafproxy {
19824: my ($dom,$action,$lastactref,%domconfig) = @_;
19825: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19826: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19827: %wafproxy,%changes,%expirecache,%expiresaml);
19828: foreach my $server (sort(keys(%servers))) {
19829: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19830: if ($serverhome eq $server) {
19831: my $serverdom = &Apache::lonnet::host_domain($server);
19832: if ($serverdom eq $dom) {
19833: $canset{$server} = 1;
19834: }
19835: }
19836: }
19837: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19838: %{$values{$dom}} = ();
19839: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19840: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19841: }
19842: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19843: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19844: }
19845: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19846: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19847: }
19848: }
19849: my $output;
19850: if (keys(%canset)) {
19851: %{$wafproxy{'alias'}} = ();
19852: %{$wafproxy{'saml'}} = ();
19853: foreach my $key (sort(keys(%canset))) {
19854: if ($env{'form.wafproxy_'.$dom}) {
19855: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19856: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19857: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19858: $changes{'alias'} = 1;
19859: }
19860: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19861: $wafproxy{'saml'}{$key} = 1;
19862: }
19863: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19864: $changes{'saml'} = 1;
19865: }
19866: } else {
19867: $wafproxy{'alias'}{$key} = '';
19868: $wafproxy{'saml'}{$key} = '';
19869: if ($curralias{$key}) {
19870: $changes{'alias'} = 1;
19871: }
19872: if ($currsaml{$key}) {
19873: $changes{'saml'} = 1;
19874: }
19875: }
19876: if ($wafproxy{'alias'}{$key} eq '') {
19877: if ($curralias{$key}) {
19878: $expirecache{$key} = 1;
19879: }
19880: delete($wafproxy{'alias'}{$key});
19881: }
19882: if ($wafproxy{'saml'}{$key} eq '') {
19883: if ($currsaml{$key}) {
19884: $expiresaml{$key} = 1;
19885: }
19886: delete($wafproxy{'saml'}{$key});
19887: }
19888: }
19889: unless (keys(%{$wafproxy{'alias'}})) {
19890: delete($wafproxy{'alias'});
19891: }
19892: unless (keys(%{$wafproxy{'saml'}})) {
19893: delete($wafproxy{'saml'});
19894: }
19895: # Localization for values in %warn occurs in &mt() calls separately.
19896: my %warn = (
19897: trusted => 'trusted IP range(s)',
19898: vpnint => 'internal IP range(s) for VPN sessions(s)',
19899: vpnext => 'IP range(s) for backend WAF connections',
19900: );
19901: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19902: my $possible = $env{'form.wafproxy_'.$item};
19903: $possible =~ s/^\s+|\s+$//g;
19904: if ($possible ne '') {
19905: if ($item eq 'remoteip') {
19906: if ($possible =~ /^[mhn]$/) {
19907: $wafproxy{$item} = $possible;
19908: }
19909: } elsif ($item eq 'ipheader') {
19910: if ($wafproxy{'remoteip'} eq 'h') {
19911: $wafproxy{$item} = $possible;
19912: }
19913: } elsif ($item eq 'sslopt') {
19914: if ($possible =~ /^0|1$/) {
19915: $wafproxy{$item} = $possible;
19916: }
19917: } else {
19918: my (@ok,$count);
19919: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19920: unless ($env{'form.wafproxy_vpnaccess'}) {
19921: $possible = '';
19922: }
19923: } elsif ($item eq 'trusted') {
19924: unless ($wafproxy{'remoteip'} eq 'h') {
19925: $possible = '';
19926: }
19927: }
19928: unless ($possible eq '') {
19929: $possible =~ s/[\r\n]+/\s/g;
19930: $possible =~ s/\s*-\s*/-/g;
19931: $possible =~ s/\s+/,/g;
19932: $possible =~ s/,+/,/g;
19933: }
19934: $count = 0;
19935: if ($possible ne '') {
19936: foreach my $poss (split(/\,/,$possible)) {
19937: $count ++;
19938: $poss = &validate_ip_pattern($poss);
19939: if ($poss ne '') {
19940: push(@ok,$poss);
19941: }
19942: }
19943: my $diff = $count - scalar(@ok);
19944: if ($diff) {
19945: push(@warnings,'<li>'.
19946: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19947: $diff,$warn{$item}).
19948: '</li>');
19949: }
19950: if (@ok) {
19951: my @cidr_list;
19952: foreach my $item (@ok) {
19953: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19954: }
19955: $wafproxy{$item} = join(',',@cidr_list);
19956: }
19957: }
19958: }
19959: if ($wafproxy{$item} ne $currvalue{$item}) {
19960: $changes{$item} = 1;
19961: }
19962: } elsif ($currvalue{$item}) {
19963: $changes{$item} = 1;
19964: }
19965: }
19966: } else {
19967: if (keys(%curralias)) {
19968: $changes{'alias'} = 1;
19969: }
19970: if (keys(%currsaml)) {
19971: $changes{'saml'} = 1;
19972: }
19973: if (keys(%currvalue)) {
19974: foreach my $key (keys(%currvalue)) {
19975: $changes{$key} = 1;
19976: }
19977: }
19978: }
19979: if (keys(%changes)) {
19980: my %defaultshash = (
19981: wafproxy => \%wafproxy,
19982: );
19983: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19984: $dom);
19985: if ($putresult eq 'ok') {
19986: my $cachetime = 24*60*60;
19987: my (%domdefaults,$updatedomdefs);
19988: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
19989: if ($changes{$item}) {
19990: unless ($updatedomdefs) {
19991: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
19992: $updatedomdefs = 1;
19993: }
19994: if ($wafproxy{$item}) {
19995: $domdefaults{'waf_'.$item} = $wafproxy{$item};
19996: } elsif (exists($domdefaults{'waf_'.$item})) {
19997: delete($domdefaults{'waf_'.$item});
19998: }
19999: }
20000: }
20001: if ($updatedomdefs) {
20002: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20003: if (ref($lastactref) eq 'HASH') {
20004: $lastactref->{'domdefaults'} = 1;
20005: }
20006: }
20007: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20008: my %updates = %expirecache;
20009: foreach my $key (keys(%expirecache)) {
20010: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20011: }
20012: if (ref($wafproxy{'alias'}) eq 'HASH') {
20013: my $cachetime = 24*60*60;
20014: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20015: $updates{$key} = 1;
20016: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20017: $cachetime);
20018: }
20019: }
20020: if (ref($lastactref) eq 'HASH') {
20021: $lastactref->{'proxyalias'} = \%updates;
20022: }
20023: }
20024: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20025: my %samlupdates = %expiresaml;
20026: foreach my $key (keys(%expiresaml)) {
20027: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20028: }
20029: if (ref($wafproxy{'saml'}) eq 'HASH') {
20030: my $cachetime = 24*60*60;
20031: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20032: $samlupdates{$key} = 1;
20033: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20034: $cachetime);
20035: }
20036: }
20037: if (ref($lastactref) eq 'HASH') {
20038: $lastactref->{'proxysaml'} = \%samlupdates;
20039: }
20040: }
20041: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 20042: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 20043: if ($changes{$item}) {
20044: if ($item eq 'alias') {
20045: my $numaliased = 0;
20046: if (ref($wafproxy{'alias'}) eq 'HASH') {
20047: my $shown;
20048: if (keys(%{$wafproxy{'alias'}})) {
20049: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20050: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20051: &Apache::lonnet::hostname($server),
20052: $wafproxy{'alias'}{$server}).'</li>';
20053: $numaliased ++;
20054: }
20055: if ($numaliased) {
20056: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20057: '<ul>'.$shown.'</ul>').'</li>';
20058: }
20059: }
20060: }
20061: unless ($numaliased) {
20062: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20063: }
20064: } elsif ($item eq 'saml') {
20065: my $shown;
20066: if (ref($wafproxy{'saml'}) eq 'HASH') {
20067: if (keys(%{$wafproxy{'saml'}})) {
20068: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20069: }
20070: }
20071: if ($shown) {
20072: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
20073: $shown).'</li>';
20074: } else {
20075: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
20076: }
20077: } else {
20078: if ($item eq 'remoteip') {
20079: my %ip_methods = &remoteip_methods();
20080: if ($wafproxy{$item} =~ /^[mh]$/) {
20081: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20082: $ip_methods{$wafproxy{$item}}).'</li>';
20083: } else {
20084: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20085: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20086: '</li>';
20087: } else {
20088: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20089: }
20090: }
20091: } elsif ($item eq 'ipheader') {
20092: if ($wafproxy{$item}) {
20093: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
20094: $wafproxy{$item}).'</li>';
20095: } else {
20096: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
20097: }
20098: } elsif ($item eq 'trusted') {
20099: if ($wafproxy{$item}) {
20100: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
20101: $wafproxy{$item}).'</li>';
20102: } else {
20103: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20104: }
20105: } elsif ($item eq 'vpnint') {
20106: if ($wafproxy{$item}) {
20107: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20108: $wafproxy{$item}).'</li>';
20109: } else {
20110: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20111: }
20112: } elsif ($item eq 'vpnext') {
20113: if ($wafproxy{$item}) {
20114: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
20115: $wafproxy{$item}).'</li>';
20116: } else {
20117: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
20118: }
20119: } elsif ($item eq 'sslopt') {
20120: if ($wafproxy{$item}) {
20121: $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>';
20122: } else {
20123: $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>';
20124: }
20125: }
20126: }
20127: }
20128: }
1.160.6.118.2 14(raebu 20129:23): $output .= '</ul>';
1.160.6.113 raeburn 20130: } else {
20131: $output = '<span class="LC_error">'.
20132: &mt('An error occurred: [_1]',$putresult).'</span>';
20133: }
20134: } elsif (keys(%canset)) {
20135: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20136: }
20137: if (@warnings) {
20138: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20139: join("\n",@warnings).'</ul>';
20140: }
20141: return $output;
20142: }
20143:
20144: sub validate_ip_pattern {
20145: my ($pattern) = @_;
20146: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20147: my ($start,$end) = ($1,$2);
20148: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20149: if (($start !~ m{/}) && ($end !~ m{/})) {
20150: return $start.'-'.$end;
20151: }
20152: }
20153: } elsif ($pattern ne '') {
20154: $pattern = &Net::CIDR::cidrvalidate($pattern);
20155: if ($pattern ne '') {
20156: return $pattern;
20157: }
20158: }
20159: return;
20160: }
20161:
1.137 raeburn 20162: sub modify_usersessions {
1.160.6.27 raeburn 20163: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20164: my @hostingtypes = ('version','excludedomain','includedomain');
20165: my @offloadtypes = ('primary','default');
20166: my %types = (
20167: remote => \@hostingtypes,
20168: hosted => \@hostingtypes,
20169: spares => \@offloadtypes,
20170: );
20171: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20172: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 20173: my (%by_ip,%by_location,@intdoms);
20174: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
20175: my @locations = sort(keys(%by_location));
1.137 raeburn 20176: my (%defaultshash,%changes);
20177: foreach my $prefix (@prefixes) {
20178: $defaultshash{'usersessions'}{$prefix} = {};
20179: }
1.160.6.27 raeburn 20180: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20181: my $resulttext;
1.138 raeburn 20182: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20183: foreach my $prefix (@prefixes) {
1.145 raeburn 20184: next if ($prefix eq 'spares');
20185: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20186: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20187: if ($type eq 'version') {
20188: my $value = $env{'form.'.$prefix.'_'.$type};
20189: my $okvalue;
20190: if ($value ne '') {
20191: if (grep(/^\Q$value\E$/,@lcversions)) {
20192: $okvalue = $value;
20193: }
20194: }
20195: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20196: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20197: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20198: if ($inuse == 0) {
20199: $changes{$prefix}{$type} = 1;
20200: } else {
20201: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20202: $changes{$prefix}{$type} = 1;
20203: }
20204: if ($okvalue ne '') {
20205: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20206: }
20207: }
20208: } else {
20209: if (($inuse == 1) && ($okvalue ne '')) {
20210: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20211: $changes{$prefix}{$type} = 1;
20212: }
20213: }
20214: } else {
20215: if (($inuse == 1) && ($okvalue ne '')) {
20216: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20217: $changes{$prefix}{$type} = 1;
20218: }
20219: }
20220: } else {
20221: if (($inuse == 1) && ($okvalue ne '')) {
20222: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20223: $changes{$prefix}{$type} = 1;
20224: }
20225: }
20226: } else {
20227: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20228: my @okvals;
20229: foreach my $val (@vals) {
1.138 raeburn 20230: if ($val =~ /:/) {
20231: my @items = split(/:/,$val);
20232: foreach my $item (@items) {
20233: if (ref($by_location{$item}) eq 'ARRAY') {
20234: push(@okvals,$item);
20235: }
20236: }
20237: } else {
20238: if (ref($by_location{$val}) eq 'ARRAY') {
20239: push(@okvals,$val);
20240: }
1.137 raeburn 20241: }
20242: }
20243: @okvals = sort(@okvals);
20244: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20245: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20246: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20247: if ($inuse == 0) {
20248: $changes{$prefix}{$type} = 1;
20249: } else {
20250: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20251: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20252: if (@changed > 0) {
20253: $changes{$prefix}{$type} = 1;
20254: }
20255: }
20256: } else {
20257: if ($inuse == 1) {
20258: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20259: $changes{$prefix}{$type} = 1;
20260: }
20261: }
20262: } else {
20263: if ($inuse == 1) {
20264: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20265: $changes{$prefix}{$type} = 1;
20266: }
20267: }
20268: } else {
20269: if ($inuse == 1) {
20270: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20271: $changes{$prefix}{$type} = 1;
20272: }
20273: }
20274: }
20275: }
20276: }
1.145 raeburn 20277:
20278: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20279: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20280: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20281: my $savespares;
20282:
20283: foreach my $lonhost (sort(keys(%servers))) {
20284: my $serverhomeID =
20285: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20286: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20287: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20288: my %spareschg;
20289: foreach my $type (@{$types{'spares'}}) {
20290: my @okspares;
20291: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20292: foreach my $server (@checked) {
1.152 raeburn 20293: if (&Apache::lonnet::hostname($server) ne '') {
20294: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20295: unless (grep(/^\Q$server\E$/,@okspares)) {
20296: push(@okspares,$server);
20297: }
1.145 raeburn 20298: }
20299: }
20300: }
20301: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20302: my $newspare;
1.152 raeburn 20303: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20304: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20305: $newspare = $new;
20306: }
20307: }
1.152 raeburn 20308: my @spares;
20309: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20310: @spares = sort(@okspares,$newspare);
20311: } else {
20312: @spares = sort(@okspares);
20313: }
20314: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20315: if (ref($spareid{$lonhost}) eq 'HASH') {
20316: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20317: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20318: if (@diffs > 0) {
20319: $spareschg{$type} = 1;
20320: }
20321: }
20322: }
20323: }
20324: if (keys(%spareschg) > 0) {
20325: $changes{'spares'}{$lonhost} = \%spareschg;
20326: }
20327: }
1.160.6.61 raeburn 20328: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 20329: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 20330: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20331: my @okoffload;
20332: if (@offloadnow) {
20333: foreach my $server (@offloadnow) {
20334: if (&Apache::lonnet::hostname($server) ne '') {
20335: unless (grep(/^\Q$server\E$/,@okoffload)) {
20336: push(@okoffload,$server);
20337: }
20338: }
20339: }
20340: if (@okoffload) {
20341: foreach my $lonhost (@okoffload) {
20342: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20343: }
20344: }
20345: }
1.160.6.105 raeburn 20346: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20347: my @okoffloadoth;
20348: if (@offloadoth) {
20349: foreach my $server (@offloadoth) {
20350: if (&Apache::lonnet::hostname($server) ne '') {
20351: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20352: push(@okoffloadoth,$server);
20353: }
20354: }
20355: }
20356: if (@okoffloadoth) {
20357: foreach my $lonhost (@okoffloadoth) {
20358: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20359: }
20360: }
20361: }
1.145 raeburn 20362: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20363: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20364: if (ref($changes{'spares'}) eq 'HASH') {
20365: if (keys(%{$changes{'spares'}}) > 0) {
20366: $savespares = 1;
20367: }
20368: }
20369: } else {
20370: $savespares = 1;
20371: }
1.160.6.105 raeburn 20372: foreach my $offload ('offloadnow','offloadoth') {
20373: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20374: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20375: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20376: $changes{$offload} = 1;
1.160.6.61 raeburn 20377: last;
20378: }
20379: }
1.160.6.105 raeburn 20380: unless ($changes{$offload}) {
20381: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20382: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20383: $changes{$offload} = 1;
20384: last;
20385: }
20386: }
20387: }
20388: } else {
20389: if (($offload eq 'offloadnow') && (@okoffload)) {
20390: $changes{'offloadnow'} = 1;
20391: }
20392: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20393: $changes{'offloadoth'} = 1;
20394: }
1.160.6.61 raeburn 20395: }
1.160.6.105 raeburn 20396: }
20397: } else {
20398: if (@okoffload) {
1.160.6.61 raeburn 20399: $changes{'offloadnow'} = 1;
20400: }
1.160.6.105 raeburn 20401: if (@okoffloadoth) {
20402: $changes{'offloadoth'} = 1;
20403: }
1.145 raeburn 20404: }
1.147 raeburn 20405: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20406: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20407: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20408: $dom);
20409: if ($putresult eq 'ok') {
20410: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20411: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20412: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20413: }
20414: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20415: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20416: }
1.160.6.61 raeburn 20417: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20418: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20419: }
1.160.6.105 raeburn 20420: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20421: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20422: }
1.137 raeburn 20423: }
20424: my $cachetime = 24*60*60;
20425: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 20426: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 20427: if (ref($lastactref) eq 'HASH') {
20428: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 20429: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 20430: }
1.147 raeburn 20431: if (keys(%changes) > 0) {
20432: my %lt = &usersession_titles();
20433: $resulttext = &mt('Changes made:').'<ul>';
20434: foreach my $prefix (@prefixes) {
20435: if (ref($changes{$prefix}) eq 'HASH') {
20436: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20437: if ($prefix eq 'spares') {
20438: if (ref($changes{$prefix}) eq 'HASH') {
20439: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20440: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20441: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 20442: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20443: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20444: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20445: foreach my $type (@{$types{$prefix}}) {
20446: if ($changes{$prefix}{$lonhost}{$type}) {
20447: my $offloadto = &mt('None');
20448: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20449: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20450: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20451: }
1.145 raeburn 20452: }
1.147 raeburn 20453: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20454: }
1.137 raeburn 20455: }
20456: }
1.147 raeburn 20457: $resulttext .= '</li>';
1.137 raeburn 20458: }
20459: }
1.147 raeburn 20460: } else {
20461: foreach my $type (@{$types{$prefix}}) {
20462: if (defined($changes{$prefix}{$type})) {
20463: my $newvalue;
20464: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20465: if (ref($defaultshash{'usersessions'}{$prefix})) {
20466: if ($type eq 'version') {
20467: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
20468: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20469: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20470: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20471: }
1.145 raeburn 20472: }
20473: }
20474: }
1.147 raeburn 20475: if ($newvalue eq '') {
20476: if ($type eq 'version') {
20477: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
20478: } else {
20479: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20480: }
1.145 raeburn 20481: } else {
1.147 raeburn 20482: if ($type eq 'version') {
1.160.6.118.2 14(raebu 20483:23): $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20484: }
20485: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20486: }
1.137 raeburn 20487: }
20488: }
20489: }
1.147 raeburn 20490: $resulttext .= '</ul>';
1.137 raeburn 20491: }
20492: }
1.160.6.61 raeburn 20493: if ($changes{'offloadnow'}) {
20494: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20495: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 20496: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 20497: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20498: $resulttext .= '<li>'.$lonhost.'</li>';
20499: }
20500: $resulttext .= '</ul>';
20501: } else {
1.160.6.105 raeburn 20502: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20503: }
20504: } else {
20505: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20506: }
20507: }
20508: if ($changes{'offloadoth'}) {
20509: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20510: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20511: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20512: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20513: $resulttext .= '<li>'.$lonhost.'</li>';
20514: }
20515: $resulttext .= '</ul>';
20516: } else {
20517: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 20518: }
20519: } else {
1.160.6.105 raeburn 20520: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 20521: }
20522: }
1.147 raeburn 20523: $resulttext .= '</ul>';
20524: } else {
20525: $resulttext = $nochgmsg;
1.137 raeburn 20526: }
20527: } else {
20528: $resulttext = '<span class="LC_error">'.
20529: &mt('An error occurred: [_1]',$putresult).'</span>';
20530: }
20531: } else {
1.147 raeburn 20532: $resulttext = $nochgmsg;
1.137 raeburn 20533: }
20534: return $resulttext;
20535: }
20536:
1.150 raeburn 20537: sub modify_loadbalancing {
20538: my ($dom,%domconfig) = @_;
20539: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20540: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20541: my ($othertitle,$usertypes,$types) =
20542: &Apache::loncommon::sorted_inst_types($dom);
20543: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 20544: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20545: my @sparestypes = ('primary','default');
20546: my %typetitles = &sparestype_titles();
20547: my $resulttext;
1.160.6.94 raeburn 20548: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 20549: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20550: %existing = %{$domconfig{'loadbalancing'}};
20551: }
20552: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 20553: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 20554: my ($saveloadbalancing,%defaultshash,%changes);
20555: my ($alltypes,$othertypes,$titles) =
20556: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20557: my %ruletitles = &offloadtype_text();
20558: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20559: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20560: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20561: if ($balancer eq '') {
20562: next;
20563: }
20564: if (!exists($servers{$balancer})) {
20565: if (exists($currbalancer{$balancer})) {
20566: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20567: }
1.160.6.7 raeburn 20568: next;
20569: }
20570: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20571: push(@{$changes{'delete'}},$balancer);
20572: next;
20573: }
20574: if (!exists($currbalancer{$balancer})) {
20575: push(@{$changes{'add'}},$balancer);
20576: }
20577: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20578: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20579: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20580: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20581: $saveloadbalancing = 1;
20582: }
20583: foreach my $sparetype (@sparestypes) {
20584: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20585: my @offloadto;
20586: foreach my $target (@targets) {
20587: if (($servers{$target}) && ($target ne $balancer)) {
20588: if ($sparetype eq 'default') {
20589: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20590: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20591: }
20592: }
1.160.6.7 raeburn 20593: unless(grep(/^\Q$target\E$/,@offloadto)) {
20594: push(@offloadto,$target);
20595: }
1.150 raeburn 20596: }
20597: }
1.160.6.76 raeburn 20598: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20599: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20600: push(@offloadto,$balancer);
20601: }
20602: }
20603: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20604: }
1.160.6.94 raeburn 20605: if ($env{'form.loadbalancing_cookie_'.$i}) {
20606: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20607: if (exists($currbalancer{$balancer})) {
20608: unless ($currcookies{$balancer}) {
20609: $changes{'curr'}{$balancer}{'cookie'} = 1;
20610: }
20611: }
20612: } elsif (exists($currbalancer{$balancer})) {
20613: if ($currcookies{$balancer}) {
20614: $changes{'curr'}{$balancer}{'cookie'} = 1;
20615: }
20616: }
1.160.6.7 raeburn 20617: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20618: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 20619: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20620: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20621: if (@targetdiffs > 0) {
1.160.6.7 raeburn 20622: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20623: }
1.160.6.7 raeburn 20624: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20625: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20626: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20627: }
20628: }
20629: }
20630: } else {
1.160.6.7 raeburn 20631: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
20632: foreach my $sparetype (@sparestypes) {
20633: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20634: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20635: $changes{'curr'}{$balancer}{'targets'} = 1;
20636: }
1.150 raeburn 20637: }
20638: }
1.160.6.7 raeburn 20639: }
1.150 raeburn 20640: }
20641: my $ishomedom;
1.160.6.7 raeburn 20642: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20643: $ishomedom = 1;
1.150 raeburn 20644: }
20645: if (ref($alltypes) eq 'ARRAY') {
20646: foreach my $type (@{$alltypes}) {
20647: my $rule;
1.160.6.7 raeburn 20648: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20649: (!$ishomedom)) {
1.160.6.7 raeburn 20650: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20651: }
20652: if ($rule eq 'specific') {
1.160.6.55 raeburn 20653: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
20654: if (exists($servers{$specifiedhost})) {
20655: $rule = $specifiedhost;
20656: }
1.150 raeburn 20657: }
1.160.6.7 raeburn 20658: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20659: if (ref($currrules{$balancer}) eq 'HASH') {
20660: if ($rule ne $currrules{$balancer}{$type}) {
20661: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20662: }
20663: } elsif ($rule ne '') {
1.160.6.7 raeburn 20664: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20665: }
20666: }
20667: }
1.160.6.7 raeburn 20668: }
20669: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20670: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20671: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20672: $defaultshash{'loadbalancing'} = {};
20673: }
20674: my $putresult = &Apache::lonnet::put_dom('configuration',
20675: \%defaultshash,$dom);
20676: if ($putresult eq 'ok') {
20677: if (keys(%changes) > 0) {
1.160.6.54 raeburn 20678: my %toupdate;
1.160.6.7 raeburn 20679: if (ref($changes{'delete'}) eq 'ARRAY') {
20680: foreach my $balancer (sort(@{$changes{'delete'}})) {
20681: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 20682: $toupdate{$balancer} = 1;
1.150 raeburn 20683: }
1.160.6.7 raeburn 20684: }
20685: if (ref($changes{'add'}) eq 'ARRAY') {
20686: foreach my $balancer (sort(@{$changes{'add'}})) {
20687: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 20688: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20689: }
20690: }
20691: if (ref($changes{'curr'}) eq 'HASH') {
20692: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 20693: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20694: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20695: if ($changes{'curr'}{$balancer}{'targets'}) {
20696: my %offloadstr;
20697: foreach my $sparetype (@sparestypes) {
20698: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20699: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20700: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20701: }
20702: }
1.150 raeburn 20703: }
1.160.6.7 raeburn 20704: if (keys(%offloadstr) == 0) {
20705: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20706: } else {
1.160.6.7 raeburn 20707: my $showoffload;
20708: foreach my $sparetype (@sparestypes) {
20709: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20710: if (defined($offloadstr{$sparetype})) {
20711: $showoffload .= $offloadstr{$sparetype};
20712: } else {
20713: $showoffload .= &mt('None');
20714: }
20715: $showoffload .= (' 'x3);
20716: }
20717: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20718: }
20719: }
20720: }
1.160.6.7 raeburn 20721: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20722: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20723: foreach my $type (@{$alltypes}) {
20724: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20725: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20726: my $balancetext;
20727: if ($rule eq '') {
20728: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 20729: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 20730: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20731: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 20732: foreach my $sparetype (@sparestypes) {
20733: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20734: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20735: }
20736: }
1.160.6.55 raeburn 20737: foreach my $item (@{$alltypes}) {
20738: next if ($item =~ /^_LC_ipchange/);
20739: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20740: if ($hasrule eq 'homeserver') {
20741: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20742: } else {
20743: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20744: if ($servers{$hasrule}) {
20745: $toupdate{$hasrule} = 1;
20746: }
20747: }
20748: }
20749: }
20750: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20751: $balancetext = $ruletitles{$rule};
20752: } else {
20753: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20754: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20755: if ($receiver) {
20756: $toupdate{$receiver};
20757: }
20758: }
20759: } else {
20760: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 20761: }
1.160.6.7 raeburn 20762: } else {
20763: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20764: }
1.160.6.26 raeburn 20765: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20766: }
20767: }
20768: }
20769: }
1.160.6.94 raeburn 20770: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 20771: if ($currcookies{$balancer}) {
20772: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20773: $balancer).'</li>';
20774: } else {
20775: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20776: $balancer).'</li>';
20777: }
1.160.6.94 raeburn 20778: }
1.160.6.106 raeburn 20779: }
20780: }
20781: if (keys(%toupdate)) {
20782: my %thismachine;
20783: my $updatedhere;
20784: my $cachetime = 60*60*24;
20785: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20786: foreach my $lonhost (keys(%toupdate)) {
20787: if ($thismachine{$lonhost}) {
20788: unless ($updatedhere) {
20789: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20790: $defaultshash{'loadbalancing'},
20791: $cachetime);
20792: $updatedhere = 1;
1.160.6.54 raeburn 20793: }
1.160.6.106 raeburn 20794: } else {
20795: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20796: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 20797: }
1.150 raeburn 20798: }
1.160.6.7 raeburn 20799: }
20800: if ($resulttext ne '') {
20801: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20802: } else {
20803: $resulttext = $nochgmsg;
20804: }
20805: } else {
1.160.6.7 raeburn 20806: $resulttext = $nochgmsg;
1.150 raeburn 20807: }
20808: } else {
1.160.6.7 raeburn 20809: $resulttext = '<span class="LC_error">'.
20810: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20811: }
20812: } else {
1.160.6.7 raeburn 20813: $resulttext = $nochgmsg;
1.150 raeburn 20814: }
20815: return $resulttext;
20816: }
20817:
1.48 raeburn 20818: sub recurse_check {
20819: my ($chkcats,$categories,$depth,$name) = @_;
20820: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20821: my $chg = 0;
20822: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20823: my $category = $chkcats->[$depth]{$name}[$j];
20824: my $item;
20825: if ($category eq '') {
20826: $chg ++;
20827: } else {
20828: my $deeper = $depth + 1;
20829: $item = &escape($category).':'.&escape($name).':'.$depth;
20830: if ($chg) {
20831: $categories->{$item} -= $chg;
20832: }
20833: &recurse_check($chkcats,$categories,$deeper,$category);
20834: $deeper --;
20835: }
20836: }
20837: }
20838: return;
20839: }
20840:
20841: sub recurse_cat_deletes {
20842: my ($item,$coursecategories,$deletions) = @_;
20843: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20844: my $subdepth = $depth + 1;
20845: if (ref($coursecategories) eq 'HASH') {
20846: foreach my $subitem (keys(%{$coursecategories})) {
20847: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20848: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20849: delete($coursecategories->{$subitem});
20850: $deletions->{$subitem} = 1;
20851: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 20852: }
1.48 raeburn 20853: }
20854: }
20855: return;
20856: }
20857:
1.125 raeburn 20858: sub active_dc_picker {
1.160.6.16 raeburn 20859: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 20860: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 20861: my @domcoord = keys(%domcoords);
20862: if (keys(%currhash)) {
20863: foreach my $dc (keys(%currhash)) {
20864: unless (exists($domcoords{$dc})) {
20865: push(@domcoord,$dc);
20866: }
20867: }
20868: }
20869: @domcoord = sort(@domcoord);
20870: my $numdcs = scalar(@domcoord);
20871: my $rows = 0;
20872: my $table;
1.125 raeburn 20873: if ($numdcs > 1) {
1.160.6.16 raeburn 20874: $table = '<table>';
20875: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20876: my $rem = $i%($numinrow);
20877: if ($rem == 0) {
20878: if ($i > 0) {
1.160.6.16 raeburn 20879: $table .= '</tr>';
1.125 raeburn 20880: }
1.160.6.16 raeburn 20881: $table .= '<tr>';
20882: $rows ++;
1.125 raeburn 20883: }
1.160.6.16 raeburn 20884: my $check = '';
20885: if ($inputtype eq 'radio') {
20886: if (keys(%currhash) == 0) {
20887: if (!$i) {
20888: $check = ' checked="checked"';
20889: }
20890: } elsif (exists($currhash{$domcoord[$i]})) {
20891: $check = ' checked="checked"';
20892: }
20893: } else {
20894: if (exists($currhash{$domcoord[$i]})) {
20895: $check = ' checked="checked"';
1.125 raeburn 20896: }
20897: }
1.160.6.16 raeburn 20898: if ($i == @domcoord - 1) {
1.125 raeburn 20899: my $colsleft = $numinrow - $rem;
20900: if ($colsleft > 1) {
1.160.6.16 raeburn 20901: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20902: } else {
1.160.6.16 raeburn 20903: $table .= '<td class="LC_left_item">';
1.125 raeburn 20904: }
20905: } else {
1.160.6.16 raeburn 20906: $table .= '<td class="LC_left_item">';
20907: }
20908: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20909: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20910: $table .= '<span class="LC_nobreak"><label>'.
20911: '<input type="'.$inputtype.'" name="'.$name.'"'.
20912: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20913: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 20914: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 20915: }
1.160.6.33 raeburn 20916: $table .= '</label></span></td>';
1.125 raeburn 20917: }
1.160.6.16 raeburn 20918: $table .= '</tr></table>';
20919: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 20920: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20921: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 20922: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 20923: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 20924: if ($user ne $dcname.':'.$dcdom) {
20925: $table .= ' ('.$dcname.':'.$dcdom.')';
20926: }
1.160.6.16 raeburn 20927: } else {
20928: my $check;
20929: if (exists($currhash{$domcoord[0]})) {
20930: $check = ' checked="checked"';
20931: }
1.160.6.50 raeburn 20932: $table = '<span class="LC_nobreak"><label>'.
20933: '<input type="checkbox" name="'.$name.'" '.
20934: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 20935: if ($user ne $dcname.':'.$dcdom) {
20936: $table .= ' ('.$dcname.':'.$dcdom.')';
20937: }
20938: $table .= '</label></span>';
1.160.6.16 raeburn 20939: $rows ++;
20940: }
1.125 raeburn 20941: }
1.160.6.16 raeburn 20942: return ($numdcs,$table,$rows);
1.125 raeburn 20943: }
20944:
1.137 raeburn 20945: sub usersession_titles {
20946: return &Apache::lonlocal::texthash(
20947: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20948: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20949: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20950: version => 'LON-CAPA version requirement',
1.138 raeburn 20951: excludedomain => 'Allow all, but exclude specific domains',
20952: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20953: primary => 'Primary (checked first)',
1.154 raeburn 20954: default => 'Default',
1.137 raeburn 20955: );
20956: }
20957:
1.152 raeburn 20958: sub id_for_thisdom {
20959: my (%servers) = @_;
20960: my %altids;
20961: foreach my $server (keys(%servers)) {
20962: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
20963: if ($serverhome ne $server) {
20964: $altids{$serverhome} = $server;
20965: }
20966: }
20967: return %altids;
20968: }
20969:
1.150 raeburn 20970: sub count_servers {
20971: my ($currbalancer,%servers) = @_;
20972: my (@spares,$numspares);
20973: foreach my $lonhost (sort(keys(%servers))) {
20974: next if ($currbalancer eq $lonhost);
20975: push(@spares,$lonhost);
20976: }
20977: if ($currbalancer) {
20978: $numspares = scalar(@spares);
20979: } else {
20980: $numspares = scalar(@spares) - 1;
20981: }
20982: return ($numspares,@spares);
20983: }
20984:
20985: sub lonbalance_targets_js {
1.160.6.7 raeburn 20986: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 20987: my $select = &mt('Select');
20988: my ($alltargets,$allishome,$allinsttypes,@alltypes);
20989: if (ref($servers) eq 'HASH') {
20990: $alltargets = join("','",sort(keys(%{$servers})));
20991: my @homedoms;
20992: foreach my $server (sort(keys(%{$servers}))) {
20993: if (&Apache::lonnet::host_domain($server) eq $dom) {
20994: push(@homedoms,'1');
20995: } else {
20996: push(@homedoms,'0');
20997: }
20998: }
20999: $allishome = join("','",@homedoms);
21000: }
21001: if (ref($types) eq 'ARRAY') {
21002: if (@{$types} > 0) {
21003: @alltypes = @{$types};
21004: }
21005: }
21006: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21007: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 21008: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 21009: if (ref($settings) eq 'HASH') {
21010: %existing = %{$settings};
21011: }
21012: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 21013: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 21014: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21015: return <<"END";
21016:
21017: <script type="text/javascript">
21018: // <![CDATA[
21019:
1.160.6.7 raeburn 21020: currBalancers = new Array('$balancers');
21021:
21022: function toggleTargets(balnum) {
21023: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21024: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21025: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21026: var prevbalancer = prevhostitem.value;
21027: var baltotal = document.getElementById('loadbalancing_total').value;
21028: prevhostitem.value = balancer;
21029: if (prevbalancer != '') {
21030: var prevIdx = currBalancers.indexOf(prevbalancer);
21031: if (prevIdx != -1) {
21032: currBalancers.splice(prevIdx,1);
21033: }
21034: }
1.150 raeburn 21035: if (balancer == '') {
1.160.6.7 raeburn 21036: hideSpares(balnum);
1.150 raeburn 21037: } else {
1.160.6.7 raeburn 21038: var currIdx = currBalancers.indexOf(balancer);
21039: if (currIdx == -1) {
21040: currBalancers.push(balancer);
21041: }
1.150 raeburn 21042: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 21043: var ishomedom = homedoms[lonhostitem.selectedIndex];
21044: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21045: }
1.160.6.7 raeburn 21046: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21047: return;
21048: }
21049:
1.160.6.7 raeburn 21050: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21051: var alltargets = new Array('$alltargets');
21052: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21053: var offloadtypes = new Array('primary','default');
21054:
1.160.6.7 raeburn 21055: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21056: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21057:
1.151 raeburn 21058: for (var i=0; i<offloadtypes.length; i++) {
21059: var count = 0;
21060: for (var j=0; j<alltargets.length; j++) {
21061: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 21062: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21063: item.value = alltargets[j];
21064: item.style.textAlign='left';
21065: item.style.textFace='normal';
21066: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21067: if (currBalancers.indexOf(alltargets[j]) == -1) {
21068: item.disabled = '';
21069: } else {
21070: item.disabled = 'disabled';
21071: item.checked = false;
21072: }
1.151 raeburn 21073: count ++;
21074: }
1.150 raeburn 21075: }
21076: }
1.151 raeburn 21077: for (var k=0; k<insttypes.length; k++) {
21078: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21079: if (ishomedom == 1) {
1.160.6.7 raeburn 21080: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21081: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21082: } else {
1.160.6.7 raeburn 21083: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21084: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21085: }
21086: } else {
1.160.6.7 raeburn 21087: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21088: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21089: }
1.151 raeburn 21090: if ((insttypes[k] != '_LC_external') &&
21091: ((insttypes[k] != '_LC_internetdom') ||
21092: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 21093: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21094: item.options.length = 0;
21095: item.options[0] = new Option("","",true,true);
21096: var idx = 0;
1.151 raeburn 21097: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 21098: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21099: idx ++;
21100: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21101: }
21102: }
21103: }
21104: }
21105: return;
21106: }
21107:
1.160.6.7 raeburn 21108: function hideSpares(balnum) {
1.150 raeburn 21109: var alltargets = new Array('$alltargets');
21110: var insttypes = new Array('$allinsttypes');
21111: var offloadtypes = new Array('primary','default');
21112:
1.160.6.7 raeburn 21113: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21114: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21115:
21116: var total = alltargets.length - 1;
21117: for (var i=0; i<offloadtypes; i++) {
21118: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 21119: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21120: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21121: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21122: }
1.150 raeburn 21123: }
21124: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 21125: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21126: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21127: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 21128: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21129: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21130: }
21131: }
21132: return;
21133: }
21134:
1.160.6.7 raeburn 21135: function checkOffloads(item,balnum,type) {
1.150 raeburn 21136: var alltargets = new Array('$alltargets');
21137: var offloadtypes = new Array('primary','default');
21138: if (item.checked) {
21139: var total = alltargets.length - 1;
21140: var other;
21141: if (type == offloadtypes[0]) {
1.151 raeburn 21142: other = offloadtypes[1];
1.150 raeburn 21143: } else {
1.151 raeburn 21144: other = offloadtypes[0];
1.150 raeburn 21145: }
21146: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 21147: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21148: if (server == item.value) {
1.160.6.7 raeburn 21149: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21150: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21151: }
21152: }
21153: }
21154: }
21155: return;
21156: }
21157:
1.160.6.7 raeburn 21158: function singleServerToggle(balnum,type) {
21159: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21160: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 21161: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21162: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21163:
21164: } else {
1.160.6.7 raeburn 21165: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21166: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21167: }
21168: return;
21169: }
21170:
1.160.6.7 raeburn 21171: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21172: if (type == '_LC_external') {
1.160.6.26 raeburn 21173: return;
1.150 raeburn 21174: }
1.160.6.7 raeburn 21175: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21176: for (var i=0; i<typesRules.length; i++) {
21177: if (formname.elements[typesRules[i]].checked) {
21178: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 21179: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21180: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21181: } else {
1.160.6.7 raeburn 21182: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21183: }
21184: }
21185: }
21186: return;
21187: }
21188:
21189: function balancerDeleteChange(balnum) {
21190: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21191: var baltotal = document.getElementById('loadbalancing_total').value;
21192: var addtarget;
21193: var removetarget;
21194: var action = 'delete';
21195: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21196: var lonhost = hostitem.value;
21197: var currIdx = currBalancers.indexOf(lonhost);
21198: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21199: if (currIdx != -1) {
21200: currBalancers.splice(currIdx,1);
21201: }
21202: addtarget = lonhost;
21203: } else {
21204: if (currIdx == -1) {
21205: currBalancers.push(lonhost);
21206: }
21207: removetarget = lonhost;
21208: action = 'undelete';
21209: }
21210: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21211: }
21212: return;
21213: }
21214:
21215: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21216: if (baltotal > 1) {
21217: var offloadtypes = new Array('primary','default');
21218: var alltargets = new Array('$alltargets');
21219: var insttypes = new Array('$allinsttypes');
21220: for (var i=0; i<baltotal; i++) {
21221: if (i != balnum) {
21222: for (var j=0; j<offloadtypes.length; j++) {
21223: var total = alltargets.length - 1;
21224: for (var k=0; k<total; k++) {
21225: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21226: var server = serveritem.value;
21227: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21228: if (server == addtarget) {
21229: serveritem.disabled = '';
21230: }
21231: }
21232: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21233: if (server == removetarget) {
21234: serveritem.disabled = 'disabled';
21235: serveritem.checked = false;
21236: }
21237: }
21238: }
21239: }
21240: for (var j=0; j<insttypes.length; j++) {
21241: if (insttypes[j] != '_LC_external') {
21242: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21243: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21244: var currSel = singleserver.selectedIndex;
21245: var currVal = singleserver.options[currSel].value;
21246: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21247: var numoptions = singleserver.options.length;
21248: var needsnew = 1;
21249: for (var k=0; k<numoptions; k++) {
21250: if (singleserver.options[k] == addtarget) {
21251: needsnew = 0;
21252: break;
21253: }
21254: }
21255: if (needsnew == 1) {
21256: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21257: }
21258: }
21259: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21260: singleserver.options.length = 0;
21261: if ((currVal) && (currVal != removetarget)) {
21262: singleserver.options[0] = new Option("","",false,false);
21263: } else {
21264: singleserver.options[0] = new Option("","",true,true);
21265: }
21266: var idx = 0;
21267: for (var m=0; m<alltargets.length; m++) {
21268: if (currBalancers.indexOf(alltargets[m]) == -1) {
21269: idx ++;
21270: if (currVal == alltargets[m]) {
21271: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21272: } else {
21273: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21274: }
21275: }
21276: }
21277: }
21278: }
21279: }
21280: }
1.150 raeburn 21281: }
21282: }
21283: }
21284: return;
21285: }
21286:
1.152 raeburn 21287: // ]]>
21288: </script>
21289:
21290: END
21291: }
21292:
21293: sub new_spares_js {
21294: my @sparestypes = ('primary','default');
21295: my $types = join("','",@sparestypes);
21296: my $select = &mt('Select');
21297: return <<"END";
21298:
21299: <script type="text/javascript">
21300: // <![CDATA[
21301:
21302: function updateNewSpares(formname,lonhost) {
21303: var types = new Array('$types');
21304: var include = new Array();
21305: var exclude = new Array();
21306: for (var i=0; i<types.length; i++) {
21307: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21308: for (var j=0; j<spareboxes.length; j++) {
21309: if (formname.elements[spareboxes[j]].checked) {
21310: exclude.push(formname.elements[spareboxes[j]].value);
21311: } else {
21312: include.push(formname.elements[spareboxes[j]].value);
21313: }
21314: }
21315: }
21316: for (var i=0; i<types.length; i++) {
21317: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21318: var selIdx = newSpare.selectedIndex;
21319: var currnew = newSpare.options[selIdx].value;
21320: var okSpares = new Array();
21321: for (var j=0; j<newSpare.options.length; j++) {
21322: var possible = newSpare.options[j].value;
21323: if (possible != '') {
21324: if (exclude.indexOf(possible) == -1) {
21325: okSpares.push(possible);
21326: } else {
21327: if (currnew == possible) {
21328: selIdx = 0;
21329: }
21330: }
21331: }
21332: }
21333: for (var k=0; k<include.length; k++) {
21334: if (okSpares.indexOf(include[k]) == -1) {
21335: okSpares.push(include[k]);
21336: }
21337: }
21338: okSpares.sort();
21339: newSpare.options.length = 0;
21340: if (selIdx == 0) {
21341: newSpare.options[0] = new Option("$select","",true,true);
21342: } else {
21343: newSpare.options[0] = new Option("$select","",false,false);
21344: }
21345: for (var m=0; m<okSpares.length; m++) {
21346: var idx = m+1;
21347: var selThis = 0;
21348: if (selIdx != 0) {
21349: if (okSpares[m] == currnew) {
21350: selThis = 1;
21351: }
21352: }
21353: if (selThis == 1) {
21354: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21355: } else {
21356: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21357: }
21358: }
21359: }
21360: return;
21361: }
21362:
21363: function checkNewSpares(lonhost,type) {
21364: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21365: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.160.6.118.2 14(raebu 21366:23): if (chosen != '') {
1.152 raeburn 21367: var othertype;
21368: var othernewSpare;
21369: if (type == 'primary') {
21370: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21371: }
21372: if (type == 'default') {
21373: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21374: }
21375: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21376: othernewSpare.selectedIndex = 0;
21377: }
21378: }
21379: return;
21380: }
21381:
21382: // ]]>
21383: </script>
21384:
21385: END
21386:
21387: }
21388:
21389: sub common_domprefs_js {
21390: return <<"END";
21391:
21392: <script type="text/javascript">
21393: // <![CDATA[
21394:
1.150 raeburn 21395: function getIndicesByName(formname,item) {
1.152 raeburn 21396: var group = new Array();
1.150 raeburn 21397: for (var i=0;i<formname.elements.length;i++) {
21398: if (formname.elements[i].name == item) {
1.152 raeburn 21399: group.push(formname.elements[i].id);
1.150 raeburn 21400: }
21401: }
1.152 raeburn 21402: return group;
1.150 raeburn 21403: }
21404:
21405: // ]]>
21406: </script>
21407:
21408: END
1.152 raeburn 21409:
1.150 raeburn 21410: }
21411:
1.160.6.5 raeburn 21412: sub recaptcha_js {
21413: my %lt = &captcha_phrases();
21414: return <<"END";
21415:
21416: <script type="text/javascript">
21417: // <![CDATA[
21418:
21419: function updateCaptcha(caller,context) {
21420: var privitem;
21421: var pubitem;
21422: var privtext;
21423: var pubtext;
1.160.6.69 raeburn 21424: var versionitem;
21425: var versiontext;
1.160.6.5 raeburn 21426: if (document.getElementById(context+'_recaptchapub')) {
21427: pubitem = document.getElementById(context+'_recaptchapub');
21428: } else {
21429: return;
21430: }
21431: if (document.getElementById(context+'_recaptchapriv')) {
21432: privitem = document.getElementById(context+'_recaptchapriv');
21433: } else {
21434: return;
21435: }
21436: if (document.getElementById(context+'_recaptchapubtxt')) {
21437: pubtext = document.getElementById(context+'_recaptchapubtxt');
21438: } else {
21439: return;
21440: }
21441: if (document.getElementById(context+'_recaptchaprivtxt')) {
21442: privtext = document.getElementById(context+'_recaptchaprivtxt');
21443: } else {
21444: return;
21445: }
1.160.6.69 raeburn 21446: if (document.getElementById(context+'_recaptchaversion')) {
21447: versionitem = document.getElementById(context+'_recaptchaversion');
21448: } else {
21449: return;
21450: }
21451: if (document.getElementById(context+'_recaptchavertxt')) {
21452: versiontext = document.getElementById(context+'_recaptchavertxt');
21453: } else {
21454: return;
21455: }
1.160.6.5 raeburn 21456: if (caller.checked) {
21457: if (caller.value == 'recaptcha') {
21458: pubitem.type = 'text';
21459: privitem.type = 'text';
21460: pubitem.size = '40';
21461: privitem.size = '40';
21462: pubtext.innerHTML = "$lt{'pub'}";
21463: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 21464: versionitem.type = 'text';
21465: versionitem.size = '3';
21466: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 21467: } else {
21468: pubitem.type = 'hidden';
21469: privitem.type = 'hidden';
1.160.6.69 raeburn 21470: versionitem.type = 'hidden';
1.160.6.5 raeburn 21471: pubtext.innerHTML = '';
21472: privtext.innerHTML = '';
1.160.6.69 raeburn 21473: versiontext.innerHTML = '';
1.160.6.5 raeburn 21474: }
21475: }
21476: return;
21477: }
21478:
21479: // ]]>
21480: </script>
21481:
21482: END
21483:
21484: }
21485:
1.160.6.40 raeburn 21486: sub toggle_display_js {
1.160.6.16 raeburn 21487: return <<"END";
21488:
21489: <script type="text/javascript">
21490: // <![CDATA[
21491:
1.160.6.40 raeburn 21492: function toggleDisplay(domForm,caller) {
21493: if (document.getElementById(caller)) {
21494: var divitem = document.getElementById(caller);
21495: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 21496: var checkval = 1;
21497: var dispval = 'block';
1.160.6.93 raeburn 21498: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 21499: if (caller == 'emailoptions') {
1.160.6.118.2 14(raebu 21500:23): optionsElement = domForm.cancreate_email;
1.160.6.40 raeburn 21501: }
1.160.6.57 raeburn 21502: if (caller == 'studentsubmission') {
21503: optionsElement = domForm.postsubmit;
21504: }
1.160.6.64 raeburn 21505: if (caller == 'cloneinstcode') {
21506: optionsElement = domForm.canclone;
21507: checkval = 'instcode';
21508: }
1.160.6.93 raeburn 21509: if (selfcreateRegExp.test(caller)) {
21510: optionsElement = domForm.elements[caller];
21511: checkval = 'other';
21512: dispval = 'inline'
21513: }
1.160.6.40 raeburn 21514: if (optionsElement.length) {
1.160.6.16 raeburn 21515: var currval;
1.160.6.40 raeburn 21516: for (var i=0; i<optionsElement.length; i++) {
21517: if (optionsElement[i].checked) {
21518: currval = optionsElement[i].value;
1.160.6.16 raeburn 21519: }
21520: }
1.160.6.64 raeburn 21521: if (currval == checkval) {
21522: divitem.style.display = dispval;
1.160.6.16 raeburn 21523: } else {
1.160.6.40 raeburn 21524: divitem.style.display = 'none';
1.160.6.16 raeburn 21525: }
21526: }
21527: }
21528: return;
21529: }
21530:
21531: // ]]>
21532: </script>
21533:
21534: END
21535:
21536: }
21537:
1.160.6.5 raeburn 21538: sub captcha_phrases {
21539: return &Apache::lonlocal::texthash (
21540: priv => 'Private key',
21541: pub => 'Public key',
21542: original => 'original (CAPTCHA)',
21543: recaptcha => 'successor (ReCAPTCHA)',
21544: notused => 'unused',
1.160.6.69 raeburn 21545: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 21546: );
21547: }
21548:
1.160.6.24 raeburn 21549: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 21550: my ($dom,$cachekeys) = @_;
21551: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 21552: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21553: my %thismachine;
21554: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 21555:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 21556: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
21557: 'ipaccess');
21558: my %cache_by_lonhost;
21559: if (exists($cachekeys->{'samllanding'})) {
21560: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
21561: my %landing = %{$cachekeys->{'samllanding'}};
21562: my %domservers = &Apache::lonnet::get_servers($dom);
21563: if (keys(%domservers)) {
21564: foreach my $server (keys(%domservers)) {
21565: my @cached;
21566: next if ($thismachine{$server});
21567: if ($landing{$server}) {
21568: push(@cached,&escape('samllanding').':'.&escape($server));
21569: }
21570: if (@cached) {
21571: $cache_by_lonhost{$server} = \@cached;
21572: }
21573: }
21574: }
21575: }
21576: }
1.160.6.61 raeburn 21577: if (keys(%servers)) {
1.160.6.24 raeburn 21578: foreach my $server (keys(%servers)) {
21579: next if ($thismachine{$server});
1.160.6.27 raeburn 21580: my @cached;
21581: foreach my $name (@posscached) {
21582: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 21583: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
21584: if (ref($cachekeys->{$name}) eq 'HASH') {
21585: foreach my $key (keys(%{$cachekeys->{$name}})) {
21586: push(@cached,&escape($name).':'.&escape($key));
21587: }
21588: }
21589: } else {
21590: push(@cached,&escape($name).':'.&escape($dom));
21591: }
1.160.6.27 raeburn 21592: }
21593: }
1.160.6.113 raeburn 21594: if ((exists($cache_by_lonhost{$server})) &&
21595: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
21596: push(@cached,@{$cache_by_lonhost{$server}});
21597: }
1.160.6.27 raeburn 21598: if (@cached) {
21599: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21600: }
1.160.6.24 raeburn 21601: }
21602: }
21603: return;
21604: }
21605:
1.3 raeburn 21606: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>