Annotation of loncom/interface/domainprefs.pm, revision 1.160.6.118.2.25
1.1 raeburn 1: # The LearningOnline Network with CAPA
2: # Handler to set domain-wide configuration settings
3: #
1.160.6.118.2 25(raebu 4:24): # $Id: domainprefs.pm,v 1.160.6.118.2.24 2024/08/26 10:52:47 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');
1883: my @images = ('img');
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}->{'img'} ne '') {
1892: $designs{'img'} = $settings->{$role}->{'img'};
1893: $is_custom{'img'} = 1;
1894: }
1895: if ($settings->{$role}->{'font'} ne '') {
1896: $designs{'font'} = $settings->{$role}->{'font'};
1897: $is_custom{'font'} = 1;
1898: }
1.97 tempelho 1899: if ($settings->{$role}->{'fontmenu'} ne '') {
1900: $designs{'fontmenu'} = $settings->{$role}->{'fontmenu'};
1901: $is_custom{'fontmenu'} = 1;
1902: }
1.6 raeburn 1903: foreach my $item (@bgs) {
1904: if ($settings->{$role}->{$item} ne '') {
1905: $designs{'bgs'}{$item} = $settings->{$role}->{$item};
1906: $is_custom{$item} = 1;
1907: }
1908: }
1909: foreach my $item (@links) {
1910: if ($settings->{$role}->{$item} ne '') {
1911: $designs{'links'}{$item} = $settings->{$role}->{$item};
1912: $is_custom{$item} = 1;
1913: }
1914: }
1915: }
1916: } else {
1917: if ($designhash{$dom.'.'.$role.'.img'} ne '') {
1918: $designs{img} = $designhash{$dom.'.'.$role.'.img'};
1919: $is_custom{'img'} = 1;
1920: }
1.97 tempelho 1921: if ($designhash{$dom.'.'.$role.'.fontmenu'} ne '') {
1922: $designs{fontmenu} = $designhash{$dom.'.'.$role.'.fontmenu'};
1923: $is_custom{'fontmenu'} = 1;
1924: }
1.6 raeburn 1925: if ($designhash{$dom.'.'.$role.'.font'} ne '') {
1926: $designs{font} = $designhash{$dom.'.'.$role.'.font'};
1927: $is_custom{'font'} = 1;
1928: }
1929: foreach my $item (@bgs) {
1930: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1931: $designs{'bgs'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1932: $is_custom{$item} = 1;
1933:
1934: }
1935: }
1936: foreach my $item (@links) {
1937: if ($designhash{$dom.'.'.$role.'.'.$item} ne '') {
1938: $designs{'links'}{$item} = $designhash{$dom.'.'.$role.'.'.$item};
1939: $is_custom{$item} = 1;
1940: }
1941: }
1942: }
1943: my $itemcount = 1;
1.30 raeburn 1944: my $datatable = &display_color_options($dom,$confname,$phase,$role,$itemcount,\%choices,\%is_custom,\%defaults,\%designs,\@images,\@bgs,\@links,\%alt_text,$rowtotal);
1.6 raeburn 1945: $datatable .= '</tr></table></td></tr>';
1946: return $datatable;
1947: }
1948:
1.160.6.22 raeburn 1949: sub role_defaults {
1950: my ($role,$bgs,$links,$images,$logintext) = @_;
1951: my %defaults;
1952: unless ((ref($bgs) eq 'ARRAY') && (ref($links) eq 'ARRAY') && (ref($images) eq 'ARRAY')) {
1953: return %defaults;
1954: }
1955: my %defaultdesign = %Apache::loncommon::defaultdesign;
1956: if ($role eq 'login') {
1957: %defaults = (
1958: font => $defaultdesign{$role.'.font'},
1959: );
1960: if (ref($logintext) eq 'ARRAY') {
1961: foreach my $item (@{$logintext}) {
1962: $defaults{'logintext'}{$item} = $defaultdesign{$role.'.'.$item};
1963: }
1964: }
1965: foreach my $item (@{$images}) {
1966: $defaults{'showlogo'}{$item} = 1;
1967: }
1968: } else {
1969: %defaults = (
1970: img => $defaultdesign{$role.'.img'},
1971: font => $defaultdesign{$role.'.font'},
1972: fontmenu => $defaultdesign{$role.'.fontmenu'},
1973: );
1974: }
1975: foreach my $item (@{$bgs}) {
1976: $defaults{'bgs'}{$item} = $defaultdesign{$role.'.'.$item};
1977: }
1978: foreach my $item (@{$links}) {
1979: $defaults{'links'}{$item} = $defaultdesign{$role.'.'.$item};
1980: }
1981: foreach my $item (@{$images}) {
1982: $defaults{$item} = $defaultdesign{$role.'.'.$item};
1983: }
1984: return %defaults;
1985: }
1986:
1.6 raeburn 1987: sub display_color_options {
1.9 raeburn 1988: my ($dom,$confname,$phase,$role,$itemcount,$choices,$is_custom,$defaults,$designs,
1.135 bisitz 1989: $images,$bgs,$links,$alt_text,$rowtotal,$logintext) = @_;
1.159 raeburn 1990: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.6 raeburn 1991: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.134 raeburn 1992: my $datatable = '<tr'.$css_class.'>'.
1.6 raeburn 1993: '<td>'.$choices->{'font'}.'</td>';
1994: if (!$is_custom->{'font'}) {
1.160.6.87 raeburn 1995: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'font'}.';">'.$defaults->{'font'}.'</span></td>';
1.6 raeburn 1996: } else {
1997: $datatable .= '<td> </td>';
1998: }
1.160.6.9 raeburn 1999: my $current_color = $designs->{'font'} ? $designs->{'font'} : $defaults->{'font'};
2000:
1.8 raeburn 2001: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 2002: '<input type="text" class="colorchooser" size="10" name="'.$role.'_font"'.
2003: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 2004: ' </span></td></tr>';
1.107 raeburn 2005: unless ($role eq 'login') {
2006: $datatable .= '<tr'.$css_class.'>'.
2007: '<td>'.$choices->{'fontmenu'}.'</td>';
2008: if (!$is_custom->{'fontmenu'}) {
1.160.6.87 raeburn 2009: $datatable .= '<td>'.&mt('Default in use:').' <span class="css_default_'.$role.'_font" style="color: '.$defaults->{'fontmenu'}.';">'.$defaults->{'fontmenu'}.'</span></td>';
1.107 raeburn 2010: } else {
2011: $datatable .= '<td> </td>';
2012: }
1.160.6.22 raeburn 2013: $current_color = $designs->{'fontmenu'} ?
2014: $designs->{'fontmenu'} : $defaults->{'fontmenu'};
1.107 raeburn 2015: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.9 raeburn 2016: '<input class="colorchooser" type="text" size="10" name="'
1.160.6.22 raeburn 2017: .$role.'_fontmenu"'.
1.160.6.9 raeburn 2018: ' value="'.$current_color.'" /> '.
1.160.6.87 raeburn 2019: ' </span></td></tr>';
1.97 tempelho 2020: }
1.9 raeburn 2021: my $switchserver = &check_switchserver($dom,$confname);
1.6 raeburn 2022: foreach my $img (@{$images}) {
1.18 albertel 2023: $itemcount ++;
1.6 raeburn 2024: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.8 raeburn 2025: $datatable .= '<tr'.$css_class.'>'.
1.70 raeburn 2026: '<td>'.$choices->{$img};
1.160.6.118.2 2(raebur 2027:2): my ($imgfile,$img_import,$login_hdr_pick,$logincolors,$alttext);
1.70 raeburn 2028: if ($role eq 'login') {
2029: if ($img eq 'login') {
2030: $login_hdr_pick =
1.135 bisitz 2031: &login_header_options($img,$role,$defaults,$is_custom,$choices);
1.70 raeburn 2032: $logincolors =
2033: &login_text_colors($img,$role,$logintext,$phase,$choices,
1.160.6.22 raeburn 2034: $designs,$defaults);
1.160.6.118.2 2(raebur 2035:2): } else {
2036:2): if ($img ne 'domlogo') {
2037:2): $datatable.= &logo_display_options($img,$defaults,$designs);
2038:2): }
2039:2): if (ref($designs->{'alttext'}) eq 'HASH') {
2040:2): $alttext = $designs->{'alttext'}{$img};
2041:2): }
1.70 raeburn 2042: }
2043: }
2044: $datatable .= '</td>';
1.6 raeburn 2045: if ($designs->{$img} ne '') {
2046: $imgfile = $designs->{$img};
1.18 albertel 2047: $img_import = ($imgfile =~ m{^/adm/});
1.6 raeburn 2048: } else {
2049: $imgfile = $defaults->{$img};
2050: }
2051: if ($imgfile) {
1.9 raeburn 2052: my ($showfile,$fullsize);
2053: if ($imgfile =~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
1.6 raeburn 2054: my $urldir = $1;
2055: my $filename = $2;
2056: my @info = &Apache::lonnet::stat_file($designs->{$img});
2057: if (@info) {
2058: my $thumbfile = 'tn-'.$filename;
2059: my @thumb=&Apache::lonnet::stat_file($urldir.'/'.$thumbfile);
2060: if (@thumb) {
2061: $showfile = $urldir.'/'.$thumbfile;
2062: } else {
2063: $showfile = $imgfile;
2064: }
2065: } else {
2066: $showfile = '';
2067: }
2068: } elsif ($imgfile =~ m-^/(adm/[^/]+)/([^/]+)$-) {
1.16 raeburn 2069: $showfile = $imgfile;
1.6 raeburn 2070: my $imgdir = $1;
2071: my $filename = $2;
1.159 raeburn 2072: if (-e "$londocroot/$imgdir/tn-".$filename) {
1.6 raeburn 2073: $showfile = "/$imgdir/tn-".$filename;
2074: } else {
1.159 raeburn 2075: my $input = $londocroot.$imgfile;
2076: my $output = "$londocroot/$imgdir/tn-".$filename;
1.6 raeburn 2077: if (!-e $output) {
1.9 raeburn 2078: my ($width,$height) = &thumb_dimensions();
1.16 raeburn 2079: my ($fullwidth,$fullheight) = &check_dimensions($input);
2080: if ($fullwidth ne '' && $fullheight ne '') {
2081: if ($fullwidth > $width && $fullheight > $height) {
2082: my $size = $width.'x'.$height;
1.160.6.88 raeburn 2083: my @args = ('convert','-sample',$size,$input,$output);
2084: system({$args[0]} @args);
1.159 raeburn 2085: $showfile = "/$imgdir/tn-".$filename;
1.16 raeburn 2086: }
2087: }
1.6 raeburn 2088: }
2089: }
1.16 raeburn 2090: }
1.6 raeburn 2091: if ($showfile) {
1.40 raeburn 2092: if ($showfile =~ m{^/(adm|res)/}) {
2093: if ($showfile =~ m{^/res/}) {
2094: my $local_showfile =
2095: &Apache::lonnet::filelocation('',$showfile);
2096: &Apache::lonnet::repcopy($local_showfile);
2097: }
2098: $showfile = &Apache::loncommon::lonhttpdurl($showfile);
2099: }
2100: if ($imgfile) {
2101: if ($imgfile =~ m{^/(adm|res)/}) {
2102: if ($imgfile =~ m{^/res/}) {
2103: my $local_imgfile =
2104: &Apache::lonnet::filelocation('',$imgfile);
2105: &Apache::lonnet::repcopy($local_imgfile);
2106: }
2107: $fullsize = &Apache::loncommon::lonhttpdurl($imgfile);
2108: } else {
2109: $fullsize = $imgfile;
2110: }
2111: }
1.41 raeburn 2112: $datatable .= '<td>';
2113: if ($img eq 'login') {
1.135 bisitz 2114: $datatable .= $login_hdr_pick;
2115: }
1.41 raeburn 2116: $datatable .= &image_changes($is_custom->{$img},$alt_text->{$img},$img_import,
2117: $showfile,$fullsize,$role,$img,$imgfile,$logincolors);
1.6 raeburn 2118: } else {
1.160.6.22 raeburn 2119: $datatable .= '<td> </td><td class="LC_left_item">'.
2120: &mt('Upload:').'<br />';
1.6 raeburn 2121: }
2122: } else {
1.160.6.22 raeburn 2123: $datatable .= '<td> </td><td class="LC_left_item">'.
2124: &mt('Upload:').'<br />';
1.6 raeburn 2125: }
1.9 raeburn 2126: if ($switchserver) {
2127: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2128: } else {
1.135 bisitz 2129: if ($img ne 'login') { # suppress file selection for Log-in header
2130: $datatable .=' <input type="file" name="'.$role.'_'.$img.'" />';
2131: }
1.9 raeburn 2132: }
1.160.6.118.2 2(raebur 2133:2): if (($role eq 'login') && ($img ne 'login')) {
2134:2): $datatable .= (' ' x2).' <span class="LC_nobreak"><label>'.$choices->{'alttext'}.':'.
2135:2): '<input type="text" name="'.$role.'_alt_'.$img.'" size="10" value="'.$alttext.'" />'.
2136:2): '</label></span>';
2137:2): }
1.9 raeburn 2138: $datatable .= '</td></tr>';
1.6 raeburn 2139: }
2140: $itemcount ++;
2141: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2142: $datatable .= '<tr'.$css_class.'>'.
2143: '<td>'.$choices->{'bgs'}.'</td>';
2144: my $bgs_def;
2145: foreach my $item (@{$bgs}) {
2146: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2147: $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 2148: }
2149: }
2150: if ($bgs_def) {
1.8 raeburn 2151: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$bgs_def.'</tr></table></td>';
1.6 raeburn 2152: } else {
2153: $datatable .= '<td> </td>';
2154: }
2155: $datatable .= '<td class="LC_right_item">'.
2156: '<table border="0"><tr>';
1.160.6.13 raeburn 2157:
1.6 raeburn 2158: foreach my $item (@{$bgs}) {
1.160.6.22 raeburn 2159: $datatable .= '<td align="center">'.$choices->{$item};
2160: my $color = $designs->{'bgs'}{$item} ? $designs->{'bgs'}{$item} : $defaults->{'bgs'}{$item};
1.6 raeburn 2161: if ($designs->{'bgs'}{$item}) {
1.160.6.9 raeburn 2162: $datatable .= ' ';
1.6 raeburn 2163: }
1.160.6.9 raeburn 2164: $datatable .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
1.41 raeburn 2165: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.6 raeburn 2166: }
2167: $datatable .= '</tr></table></td></tr>';
2168: $itemcount ++;
2169: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2170: $datatable .= '<tr'.$css_class.'>'.
2171: '<td>'.$choices->{'links'}.'</td>';
2172: my $links_def;
2173: foreach my $item (@{$links}) {
2174: if (!$is_custom->{$item}) {
1.160.6.87 raeburn 2175: $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 2176: }
2177: }
2178: if ($links_def) {
1.8 raeburn 2179: $datatable .= '<td>'.&mt('Default(s) in use:').'<br /><table border="0"><tr>'.$links_def.'</tr></table></td>';
1.6 raeburn 2180: } else {
2181: $datatable .= '<td> </td>';
2182: }
2183: $datatable .= '<td class="LC_right_item">'.
2184: '<table border="0"><tr>';
2185: foreach my $item (@{$links}) {
1.160.6.39 raeburn 2186: my $color = $designs->{'links'}{$item} ? $designs->{'links'}{$item} : $defaults->{'links'}{$item};
1.160.6.22 raeburn 2187: $datatable .= '<td align="center">'.$choices->{$item}."\n";
1.6 raeburn 2188: if ($designs->{'links'}{$item}) {
1.160.6.9 raeburn 2189: $datatable.=' ';
1.6 raeburn 2190: }
1.160.6.9 raeburn 2191: $datatable .= '<br /><input type="text" size="8" class="colorchooser" name="'.$role.'_'.$item.'" value="'.$color.
1.6 raeburn 2192: '" /></td>';
2193: }
1.30 raeburn 2194: $$rowtotal += $itemcount;
1.3 raeburn 2195: return $datatable;
2196: }
2197:
1.70 raeburn 2198: sub logo_display_options {
2199: my ($img,$defaults,$designs) = @_;
2200: my $checkedon;
2201: if (ref($defaults) eq 'HASH') {
2202: if (ref($defaults->{'showlogo'}) eq 'HASH') {
2203: if ($defaults->{'showlogo'}{$img}) {
2204: $checkedon = 'checked="checked" ';
2205: }
2206: }
2207: }
2208: if (ref($designs) eq 'HASH') {
2209: if (ref($designs->{'showlogo'}) eq 'HASH') {
2210: if (defined($designs->{'showlogo'}{$img})) {
2211: if ($designs->{'showlogo'}{$img} == 0) {
2212: $checkedon = '';
2213: } elsif ($designs->{'showlogo'}{$img} == 1) {
2214: $checkedon = 'checked="checked" ';
2215: }
2216: }
2217: }
2218: }
2219: return '<br /><label> <input type="checkbox" name="'.
2220: 'login_showlogo_'.$img.'" value="1" '.$checkedon.'/>'.
2221: &mt('show').'</label>'."\n";
2222: }
2223:
1.41 raeburn 2224: sub login_header_options {
1.135 bisitz 2225: my ($img,$role,$defaults,$is_custom,$choices) = @_;
2226: my $output = '';
1.41 raeburn 2227: if ((!$is_custom->{'textcol'}) || (!$is_custom->{'bgcol'})) {
1.135 bisitz 2228: $output .= &mt('Text default(s):').'<br />';
1.41 raeburn 2229: if (!$is_custom->{'textcol'}) {
2230: $output .= $choices->{'textcol'}.': '.$defaults->{'logintext'}{'textcol'}.
2231: ' ';
2232: }
2233: if (!$is_custom->{'bgcol'}) {
2234: $output .= $choices->{'bgcol'}.': '.
2235: '<span id="css_'.$role.'_font" style="background-color: '.
2236: $defaults->{'logintext'}{'bgcol'}.';"> </span>';
2237: }
2238: $output .= '<br />';
2239: }
2240: $output .='<br />';
2241: return $output;
2242: }
2243:
2244: sub login_text_colors {
1.160.6.22 raeburn 2245: my ($img,$role,$logintext,$phase,$choices,$designs,$defaults) = @_;
1.41 raeburn 2246: my $color_menu = '<table border="0"><tr>';
2247: foreach my $item (@{$logintext}) {
1.160.6.22 raeburn 2248: $color_menu .= '<td align="center">'.$choices->{$item};
2249: my $color = $designs->{'logintext'}{$item} ? $designs->{'logintext'}{$item} : $defaults->{'logintext'}{$item};
2250: $color_menu .= '<br /><input type="text" class="colorchooser" size="8" name="'.$role.'_'.$item.'" value="'.$color.
2251: '" onblur = "javascript:colchg_span('."'css_".$role.'_'.$item."'".',this);" /></td>';
1.41 raeburn 2252: }
2253: $color_menu .= '</tr></table><br />';
2254: return $color_menu;
2255: }
2256:
2257: sub image_changes {
2258: my ($is_custom,$alt_text,$img_import,$showfile,$fullsize,$role,$img,$imgfile,$logincolors) = @_;
2259: my $output;
1.135 bisitz 2260: if ($img eq 'login') {
1.160.6.87 raeburn 2261: $output = '</td><td>'.$logincolors; # suppress image for Log-in header
1.135 bisitz 2262: } elsif (!$is_custom) {
1.70 raeburn 2263: if ($img ne 'domlogo') {
1.160.6.87 raeburn 2264: $output = &mt('Default image:').'<br />';
1.41 raeburn 2265: } else {
1.160.6.87 raeburn 2266: $output = &mt('Default in use:').'<br />';
1.41 raeburn 2267: }
2268: }
1.160.6.87 raeburn 2269: if ($img ne 'login') {
1.135 bisitz 2270: if ($img_import) {
2271: $output .= '<input type="hidden" name="'.$role.'_import_'.$img.'" value="'.$imgfile.'" />';
2272: }
2273: $output .= '<a href="'.$fullsize.'" target="_blank"><img src="'.
2274: $showfile.'" alt="'.$alt_text.'" border="0" /></a></td>';
2275: if ($is_custom) {
2276: $output .= '<td>'.$logincolors.'<span class="LC_nobreak"><label>'.
2277: '<input type="checkbox" name="'.
2278: $role.'_del_'.$img.'" value="1" />'.&mt('Delete?').
2279: '</label> '.&mt('Replace:').'</span><br />';
2280: } else {
1.160.6.22 raeburn 2281: $output .= '<td valign="middle">'.$logincolors.&mt('Upload:').'<br />';
1.135 bisitz 2282: }
1.41 raeburn 2283: }
2284: return $output;
2285: }
2286:
1.3 raeburn 2287: sub print_quotas {
1.86 raeburn 2288: my ($dom,$settings,$rowtotal,$action) = @_;
2289: my $context;
2290: if ($action eq 'quotas') {
2291: $context = 'tools';
2292: } else {
2293: $context = $action;
2294: }
1.160.6.118.2 20(raebu 2295:24): my ($datatable,$defaultquota,@usertools,@options,%validations);
1.44 raeburn 2296: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.3 raeburn 2297: my $typecount = 0;
1.101 raeburn 2298: my ($css_class,%titles);
1.86 raeburn 2299: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 2300:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 2301: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 2302: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
2303: %titles = &courserequest_titles();
1.160.6.5 raeburn 2304: } elsif ($context eq 'requestauthor') {
2305: @usertools = ('author');
2306: @options = ('norequest','approval','automatic');
2307: %titles = &authorrequest_titles();
1.86 raeburn 2308: } else {
1.160.6.118.2 23(raebu 2309:24): @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 2310: %titles = &tool_titles();
1.86 raeburn 2311: }
1.26 raeburn 2312: if (ref($types) eq 'ARRAY') {
1.23 raeburn 2313: foreach my $type (@{$types}) {
1.160.6.118.2 20(raebu 2314:24): my $currdefquota;
1.160.6.5 raeburn 2315: unless (($context eq 'requestcourses') ||
2316: ($context eq 'requestauthor')) {
1.86 raeburn 2317: if (ref($settings) eq 'HASH') {
2318: if (ref($settings->{defaultquota}) eq 'HASH') {
1.160.6.20 raeburn 2319: $currdefquota = $settings->{defaultquota}->{$type};
1.86 raeburn 2320: } else {
2321: $currdefquota = $settings->{$type};
2322: }
1.78 raeburn 2323: }
1.72 raeburn 2324: }
1.3 raeburn 2325: if (defined($usertypes->{$type})) {
2326: $typecount ++;
2327: $css_class = $typecount%2?' class="LC_odd_row"':'';
1.72 raeburn 2328: $datatable .= '<tr'.$css_class.'>'.
1.3 raeburn 2329: '<td>'.$usertypes->{$type}.'</td>'.
1.72 raeburn 2330: '<td class="LC_left_item">';
1.101 raeburn 2331: if ($context eq 'requestcourses') {
2332: $datatable .= '<table><tr>';
2333: }
2334: my %cell;
1.72 raeburn 2335: foreach my $item (@usertools) {
1.101 raeburn 2336: if ($context eq 'requestcourses') {
2337: my ($curroption,$currlimit);
2338: if (ref($settings) eq 'HASH') {
2339: if (ref($settings->{$item}) eq 'HASH') {
2340: $curroption = $settings->{$item}->{$type};
2341: if ($curroption =~ /^autolimit=(\d*)$/) {
2342: $currlimit = $1;
2343: }
2344: }
2345: }
2346: if (!$curroption) {
2347: $curroption = 'norequest';
2348: }
2349: $datatable .= '<th>'.$titles{$item}.'</th>';
2350: foreach my $option (@options) {
2351: my $val = $option;
2352: if ($option eq 'norequest') {
2353: $val = 0;
2354: }
2355: if ($option eq 'validate') {
2356: my $canvalidate = 0;
2357: if (ref($validations{$item}) eq 'HASH') {
2358: if ($validations{$item}{$type}) {
2359: $canvalidate = 1;
2360: }
2361: }
2362: next if (!$canvalidate);
2363: }
2364: my $checked = '';
2365: if ($option eq $curroption) {
2366: $checked = ' checked="checked"';
2367: } elsif ($option eq 'autolimit') {
2368: if ($curroption =~ /^autolimit/) {
2369: $checked = ' checked="checked"';
2370: }
2371: }
2372: $cell{$item} .= '<span class="LC_nobreak"><label>'.
2373: '<input type="radio" name="crsreq_'.$item.
2374: '_'.$type.'" value="'.$val.'"'.$checked.' />'.
1.127 raeburn 2375: $titles{$option}.'</label>';
1.101 raeburn 2376: if ($option eq 'autolimit') {
1.127 raeburn 2377: $cell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2378: $item.'_limit_'.$type.'" size="1" '.
1.103 raeburn 2379: 'value="'.$currlimit.'" />';
1.101 raeburn 2380: }
1.127 raeburn 2381: $cell{$item} .= '</span> ';
1.103 raeburn 2382: if ($option eq 'autolimit') {
1.127 raeburn 2383: $cell{$item} .= $titles{'unlimited'};
1.103 raeburn 2384: }
1.101 raeburn 2385: }
1.160.6.5 raeburn 2386: } elsif ($context eq 'requestauthor') {
2387: my $curroption;
2388: if (ref($settings) eq 'HASH') {
2389: $curroption = $settings->{$type};
2390: }
2391: if (!$curroption) {
2392: $curroption = 'norequest';
2393: }
2394: foreach my $option (@options) {
2395: my $val = $option;
2396: if ($option eq 'norequest') {
2397: $val = 0;
2398: }
2399: my $checked = '';
2400: if ($option eq $curroption) {
2401: $checked = ' checked="checked"';
2402: }
2403: $datatable .= '<span class="LC_nobreak"><label>'.
2404: '<input type="radio" name="authorreq_'.$type.
2405: '" value="'.$val.'"'.$checked.' />'.
2406: $titles{$option}.'</label></span> ';
2407: }
1.101 raeburn 2408: } else {
2409: my $checked = 'checked="checked" ';
1.160.6.118.2 10(raebu 2410:22): if ($item eq 'timezone') {
2411:22): $checked = '';
2412:22): }
1.101 raeburn 2413: if (ref($settings) eq 'HASH') {
2414: if (ref($settings->{$item}) eq 'HASH') {
1.160.6.118.2 10(raebu 2415:22): if (!$settings->{$item}->{$type}) {
1.101 raeburn 2416: $checked = '';
2417: } elsif ($settings->{$item}->{$type} == 1) {
2418: $checked = 'checked="checked" ';
2419: }
1.78 raeburn 2420: }
1.72 raeburn 2421: }
1.101 raeburn 2422: $datatable .= '<span class="LC_nobreak"><label>'.
2423: '<input type="checkbox" name="'.$context.'_'.$item.
2424: '" value="'.$type.'" '.$checked.'/>'.$titles{$item}.
2425: '</label></span> ';
1.72 raeburn 2426: }
1.101 raeburn 2427: }
2428: if ($context eq 'requestcourses') {
2429: $datatable .= '</tr><tr>';
2430: foreach my $item (@usertools) {
1.106 raeburn 2431: $datatable .= '<td style="vertical-align: top">'.$cell{$item}.'</td>';
1.101 raeburn 2432: }
2433: $datatable .= '</tr></table>';
1.72 raeburn 2434: }
1.86 raeburn 2435: $datatable .= '</td>';
1.160.6.5 raeburn 2436: unless (($context eq 'requestcourses') ||
2437: ($context eq 'requestauthor')) {
1.86 raeburn 2438: $datatable .=
1.160.6.20 raeburn 2439: '<td class="LC_right_item">'.
1.160.6.118.2 20(raebu 2440:24): '<span class="LC_nobreak">'.
1.3 raeburn 2441: '<input type="text" name="quota_'.$type.
1.72 raeburn 2442: '" value="'.$currdefquota.
1.160.6.20 raeburn 2443: '" size="5" /></span></td>';
1.86 raeburn 2444: }
2445: $datatable .= '</tr>';
1.3 raeburn 2446: }
2447: }
2448: }
1.160.6.5 raeburn 2449: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 2450: $defaultquota = '20';
2451: if (ref($settings) eq 'HASH') {
2452: if (ref($settings->{'defaultquota'}) eq 'HASH') {
2453: $defaultquota = $settings->{'defaultquota'}->{'default'};
2454: } elsif (defined($settings->{'default'})) {
2455: $defaultquota = $settings->{'default'};
2456: }
1.3 raeburn 2457: }
2458: }
2459: $typecount ++;
2460: $css_class = $typecount%2?' class="LC_odd_row"':'';
2461: $datatable .= '<tr'.$css_class.'>'.
1.26 raeburn 2462: '<td>'.$othertitle.'</td>'.
1.72 raeburn 2463: '<td class="LC_left_item">';
1.101 raeburn 2464: if ($context eq 'requestcourses') {
2465: $datatable .= '<table><tr>';
2466: }
2467: my %defcell;
1.72 raeburn 2468: foreach my $item (@usertools) {
1.101 raeburn 2469: if ($context eq 'requestcourses') {
2470: my ($curroption,$currlimit);
2471: if (ref($settings) eq 'HASH') {
2472: if (ref($settings->{$item}) eq 'HASH') {
2473: $curroption = $settings->{$item}->{'default'};
2474: if ($curroption =~ /^autolimit=(\d*)$/) {
2475: $currlimit = $1;
2476: }
2477: }
2478: }
2479: if (!$curroption) {
2480: $curroption = 'norequest';
2481: }
2482: $datatable .= '<th>'.$titles{$item}.'</th>';
2483: foreach my $option (@options) {
2484: my $val = $option;
2485: if ($option eq 'norequest') {
2486: $val = 0;
2487: }
2488: if ($option eq 'validate') {
2489: my $canvalidate = 0;
2490: if (ref($validations{$item}) eq 'HASH') {
2491: if ($validations{$item}{'default'}) {
2492: $canvalidate = 1;
2493: }
2494: }
2495: next if (!$canvalidate);
2496: }
2497: my $checked = '';
2498: if ($option eq $curroption) {
2499: $checked = ' checked="checked"';
2500: } elsif ($option eq 'autolimit') {
2501: if ($curroption =~ /^autolimit/) {
2502: $checked = ' checked="checked"';
2503: }
2504: }
2505: $defcell{$item} .= '<span class="LC_nobreak"><label>'.
2506: '<input type="radio" name="crsreq_'.$item.
2507: '_default" value="'.$val.'"'.$checked.' />'.
2508: $titles{$option}.'</label>';
2509: if ($option eq 'autolimit') {
1.127 raeburn 2510: $defcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2511: $item.'_limit_default" size="1" '.
2512: 'value="'.$currlimit.'" />';
2513: }
1.127 raeburn 2514: $defcell{$item} .= '</span> ';
1.104 raeburn 2515: if ($option eq 'autolimit') {
1.127 raeburn 2516: $defcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2517: }
1.101 raeburn 2518: }
1.160.6.5 raeburn 2519: } elsif ($context eq 'requestauthor') {
2520: my $curroption;
2521: if (ref($settings) eq 'HASH') {
1.160.6.8 raeburn 2522: $curroption = $settings->{'default'};
1.160.6.5 raeburn 2523: }
2524: if (!$curroption) {
2525: $curroption = 'norequest';
2526: }
2527: foreach my $option (@options) {
2528: my $val = $option;
2529: if ($option eq 'norequest') {
2530: $val = 0;
2531: }
2532: my $checked = '';
2533: if ($option eq $curroption) {
2534: $checked = ' checked="checked"';
2535: }
2536: $datatable .= '<span class="LC_nobreak"><label>'.
2537: '<input type="radio" name="authorreq_default"'.
2538: ' value="'.$val.'"'.$checked.' />'.
2539: $titles{$option}.'</label></span> ';
2540: }
1.101 raeburn 2541: } else {
2542: my $checked = 'checked="checked" ';
2543: if (ref($settings) eq 'HASH') {
2544: if (ref($settings->{$item}) eq 'HASH') {
2545: if ($settings->{$item}->{'default'} == 0) {
2546: $checked = '';
2547: } elsif ($settings->{$item}->{'default'} == 1) {
2548: $checked = 'checked="checked" ';
2549: }
1.78 raeburn 2550: }
1.72 raeburn 2551: }
1.101 raeburn 2552: $datatable .= '<span class="LC_nobreak"><label>'.
2553: '<input type="checkbox" name="'.$context.'_'.$item.
2554: '" value="default" '.$checked.'/>'.$titles{$item}.
2555: '</label></span> ';
2556: }
2557: }
2558: if ($context eq 'requestcourses') {
2559: $datatable .= '</tr><tr>';
2560: foreach my $item (@usertools) {
1.106 raeburn 2561: $datatable .= '<td style="vertical-align: top">'.$defcell{$item}.'</td>';
1.72 raeburn 2562: }
1.101 raeburn 2563: $datatable .= '</tr></table>';
1.72 raeburn 2564: }
1.86 raeburn 2565: $datatable .= '</td>';
1.160.6.5 raeburn 2566: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.20 raeburn 2567: $datatable .= '<td class="LC_right_item">'.
1.160.6.118.2 20(raebu 2568:24): '<span class="LC_nobreak">'.
1.86 raeburn 2569: '<input type="text" name="defaultquota" value="'.
1.160.6.118.2 20(raebu 2570:24): $defaultquota.'" size="5" /></span></td>';
1.86 raeburn 2571: }
2572: $datatable .= '</tr>';
1.72 raeburn 2573: $typecount ++;
2574: $css_class = $typecount%2?' class="LC_odd_row"':'';
2575: $datatable .= '<tr'.$css_class.'>'.
1.160.6.20 raeburn 2576: '<td>'.&mt('LON-CAPA Advanced Users').'<br />';
1.104 raeburn 2577: if ($context eq 'requestcourses') {
1.109 raeburn 2578: $datatable .= &mt('(overrides affiliation, if set)').
2579: '</td>'.
2580: '<td class="LC_left_item">'.
2581: '<table><tr>';
1.101 raeburn 2582: } else {
1.109 raeburn 2583: $datatable .= &mt('(overrides affiliation, if checked)').
2584: '</td>'.
2585: '<td class="LC_left_item" colspan="2">'.
2586: '<br />';
1.101 raeburn 2587: }
2588: my %advcell;
1.72 raeburn 2589: foreach my $item (@usertools) {
1.101 raeburn 2590: if ($context eq 'requestcourses') {
2591: my ($curroption,$currlimit);
2592: if (ref($settings) eq 'HASH') {
2593: if (ref($settings->{$item}) eq 'HASH') {
2594: $curroption = $settings->{$item}->{'_LC_adv'};
2595: if ($curroption =~ /^autolimit=(\d*)$/) {
2596: $currlimit = $1;
2597: }
2598: }
2599: }
2600: $datatable .= '<th>'.$titles{$item}.'</th>';
1.104 raeburn 2601: my $checked = '';
2602: if ($curroption eq '') {
2603: $checked = ' checked="checked"';
2604: }
2605: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2606: '<input type="radio" name="crsreq_'.$item.
2607: '__LC_adv" value=""'.$checked.' />'.
2608: &mt('No override set').'</label></span> ';
1.101 raeburn 2609: foreach my $option (@options) {
2610: my $val = $option;
2611: if ($option eq 'norequest') {
2612: $val = 0;
2613: }
2614: if ($option eq 'validate') {
2615: my $canvalidate = 0;
2616: if (ref($validations{$item}) eq 'HASH') {
2617: if ($validations{$item}{'_LC_adv'}) {
2618: $canvalidate = 1;
2619: }
2620: }
2621: next if (!$canvalidate);
2622: }
2623: my $checked = '';
1.104 raeburn 2624: if ($val eq $curroption) {
1.101 raeburn 2625: $checked = ' checked="checked"';
2626: } elsif ($option eq 'autolimit') {
2627: if ($curroption =~ /^autolimit/) {
2628: $checked = ' checked="checked"';
2629: }
2630: }
2631: $advcell{$item} .= '<span class="LC_nobreak"><label>'.
2632: '<input type="radio" name="crsreq_'.$item.
2633: '__LC_adv" value="'.$val.'"'.$checked.' />'.
2634: $titles{$option}.'</label>';
2635: if ($option eq 'autolimit') {
1.127 raeburn 2636: $advcell{$item} .= ' <input type="text" name="crsreq_'.
1.101 raeburn 2637: $item.'_limit__LC_adv" size="1" '.
2638: 'value="'.$currlimit.'" />';
2639: }
1.127 raeburn 2640: $advcell{$item} .= '</span> ';
1.104 raeburn 2641: if ($option eq 'autolimit') {
1.127 raeburn 2642: $advcell{$item} .= $titles{'unlimited'};
1.104 raeburn 2643: }
1.101 raeburn 2644: }
1.160.6.5 raeburn 2645: } elsif ($context eq 'requestauthor') {
2646: my $curroption;
2647: if (ref($settings) eq 'HASH') {
2648: $curroption = $settings->{'_LC_adv'};
2649: }
2650: my $checked = '';
2651: if ($curroption eq '') {
2652: $checked = ' checked="checked"';
2653: }
2654: $datatable .= '<span class="LC_nobreak"><label>'.
2655: '<input type="radio" name="authorreq__LC_adv"'.
2656: ' value=""'.$checked.' />'.
2657: &mt('No override set').'</label></span> ';
2658: foreach my $option (@options) {
2659: my $val = $option;
2660: if ($option eq 'norequest') {
2661: $val = 0;
2662: }
2663: my $checked = '';
2664: if ($val eq $curroption) {
2665: $checked = ' checked="checked"';
2666: }
2667: $datatable .= '<span class="LC_nobreak"><label>'.
1.160.6.8 raeburn 2668: '<input type="radio" name="authorreq__LC_adv"'.
2669: ' value="'.$val.'"'.$checked.' />'.
1.160.6.5 raeburn 2670: $titles{$option}.'</label></span> ';
2671: }
1.101 raeburn 2672: } else {
2673: my $checked = 'checked="checked" ';
2674: if (ref($settings) eq 'HASH') {
2675: if (ref($settings->{$item}) eq 'HASH') {
2676: if ($settings->{$item}->{'_LC_adv'} == 0) {
2677: $checked = '';
2678: } elsif ($settings->{$item}->{'_LC_adv'} == 1) {
2679: $checked = 'checked="checked" ';
2680: }
1.79 raeburn 2681: }
1.72 raeburn 2682: }
1.101 raeburn 2683: $datatable .= '<span class="LC_nobreak"><label>'.
2684: '<input type="checkbox" name="'.$context.'_'.$item.
2685: '" value="_LC_adv" '.$checked.'/>'.$titles{$item}.
2686: '</label></span> ';
2687: }
2688: }
2689: if ($context eq 'requestcourses') {
2690: $datatable .= '</tr><tr>';
2691: foreach my $item (@usertools) {
1.106 raeburn 2692: $datatable .= '<td style="vertical-align: top">'.$advcell{$item}.'</td>';
1.72 raeburn 2693: }
1.101 raeburn 2694: $datatable .= '</tr></table>';
1.72 raeburn 2695: }
1.98 raeburn 2696: $datatable .= '</td></tr>';
1.30 raeburn 2697: $$rowtotal += $typecount;
1.3 raeburn 2698: return $datatable;
2699: }
2700:
1.160.6.5 raeburn 2701: sub print_requestmail {
1.160.6.93 raeburn 2702: my ($dom,$action,$settings,$rowtotal,$customcss,$rowstyle) = @_;
1.160.6.25 raeburn 2703: my ($now,$datatable,%currapp);
1.102 raeburn 2704: $now = time;
2705: if (ref($settings) eq 'HASH') {
2706: if (ref($settings->{'notify'}) eq 'HASH') {
2707: if ($settings->{'notify'}{'approval'} ne '') {
1.160.6.34 raeburn 2708: map {$currapp{$_}=1;} split(/,/,$settings->{'notify'}{'approval'});
1.102 raeburn 2709: }
2710: }
2711: }
1.160.6.16 raeburn 2712: my $numinrow = 2;
1.160.6.34 raeburn 2713: my $css_class;
1.160.6.93 raeburn 2714: if ($$rowtotal%2) {
2715: $css_class = 'LC_odd_row';
2716: }
2717: if ($customcss) {
2718: $css_class .= " $customcss";
2719: }
2720: $css_class =~ s/^\s+//;
2721: if ($css_class) {
2722: $css_class = ' class="'.$css_class.'"';
2723: }
2724: if ($rowstyle) {
2725: $css_class .= ' style="'.$rowstyle.'"';
2726: }
1.160.6.5 raeburn 2727: my $text;
2728: if ($action eq 'requestcourses') {
2729: $text = &mt('Receive notification of course requests requiring approval');
1.160.6.34 raeburn 2730: } elsif ($action eq 'requestauthor') {
2731: $text = &mt('Receive notification of Authoring Space requests requiring approval');
1.160.6.5 raeburn 2732: } else {
1.160.6.34 raeburn 2733: $text = &mt('Receive notification of queued requests for self-created user accounts requiring approval');
1.160.6.5 raeburn 2734: }
1.160.6.34 raeburn 2735: $datatable = '<tr'.$css_class.'>'.
1.160.6.5 raeburn 2736: ' <td>'.$text.'</td>'.
1.102 raeburn 2737: ' <td class="LC_left_item">';
1.160.6.16 raeburn 2738: my ($numdc,$table,$rows) = &active_dc_picker($dom,$numinrow,'checkbox',
1.160.6.34 raeburn 2739: $action.'notifyapproval',%currapp);
1.160.6.16 raeburn 2740: if ($numdc > 0) {
2741: $datatable .= $table;
1.102 raeburn 2742: } else {
2743: $datatable .= &mt('There are no active Domain Coordinators');
2744: }
2745: $datatable .='</td></tr>';
2746: return $datatable;
2747: }
2748:
1.160.6.30 raeburn 2749: sub print_studentcode {
2750: my ($settings,$rowtotal) = @_;
2751: my $rownum = 0;
2752: my ($output,%current);
1.160.6.118.2 14(raebu 2753:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.51 raeburn 2754: if (ref($settings) eq 'HASH') {
2755: if (ref($settings->{'uniquecode'}) eq 'HASH') {
2756: foreach my $type (@crstypes) {
2757: $current{$type} = $settings->{'uniquecode'}{$type};
2758: }
1.160.6.30 raeburn 2759: }
2760: }
2761: $output .= '<tr>'.
2762: '<td class="LC_left_item">'.&mt('Generate unique six character code as course identifier?').'</td>'.
2763: '<td class="LC_left_item">';
2764: foreach my $type (@crstypes) {
2765: my $check = ' ';
2766: if ($current{$type}) {
2767: $check = ' checked="checked" ';
2768: }
2769: $output .= '<span class="LC_nobreak"><label>'.
2770: '<input type="checkbox" name="uniquecode" value="'.$type.'"'.$check.'/>'.
2771: &mt($type).'</label></span>'.(' 'x2).' ';
2772: }
2773: $output .= '</td></tr>';
2774: $$rowtotal ++;
2775: return $output;
2776: }
2777:
2778: sub print_textbookcourses {
1.160.6.46 raeburn 2779: my ($dom,$type,$settings,$rowtotal) = @_;
1.160.6.30 raeburn 2780: my $rownum = 0;
2781: my $css_class;
2782: my $itemcount = 1;
2783: my $maxnum = 0;
2784: my $bookshash;
2785: if (ref($settings) eq 'HASH') {
1.160.6.46 raeburn 2786: $bookshash = $settings->{$type};
1.160.6.30 raeburn 2787: }
2788: my %ordered;
2789: if (ref($bookshash) eq 'HASH') {
2790: foreach my $item (keys(%{$bookshash})) {
2791: if (ref($bookshash->{$item}) eq 'HASH') {
2792: my $num = $bookshash->{$item}{'order'};
2793: $ordered{$num} = $item;
2794: }
2795: }
2796: }
2797: my $confname = $dom.'-domainconfig';
2798: my $switchserver = &check_switchserver($dom,$confname);
1.160.6.46 raeburn 2799: my $maxnum = scalar(keys(%ordered));
2800: my $datatable;
1.160.6.30 raeburn 2801: if (keys(%ordered)) {
2802: my @items = sort { $a <=> $b } keys(%ordered);
2803: for (my $i=0; $i<@items; $i++) {
2804: $css_class = $itemcount%2?' class="LC_odd_row"':'';
2805: my $key = $ordered{$items[$i]};
2806: my %coursehash=&Apache::lonnet::coursedescription($key);
2807: my $coursetitle = $coursehash{'description'};
1.160.6.47 raeburn 2808: my ($subject,$title,$author,$publisher,$image,$imgsrc,$cdom,$cnum);
1.160.6.30 raeburn 2809: if (ref($bookshash->{$key}) eq 'HASH') {
2810: $subject = $bookshash->{$key}->{'subject'};
2811: $title = $bookshash->{$key}->{'title'};
1.160.6.46 raeburn 2812: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2813: $publisher = $bookshash->{$key}->{'publisher'};
1.160.6.46 raeburn 2814: $author = $bookshash->{$key}->{'author'};
2815: $image = $bookshash->{$key}->{'image'};
2816: if ($image ne '') {
2817: my ($path,$imagefile) = ($image =~ m{^(.+)/([^/]+)$});
2818: my $imagethumb = "$path/tn-".$imagefile;
2819: $imgsrc = '<img src="'.$imagethumb.'" alt="'.&mt('Textbook image').'" />';
2820: }
1.160.6.30 raeburn 2821: }
2822: }
1.160.6.46 raeburn 2823: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type".'_'."$key','$type'".');"';
1.160.6.30 raeburn 2824: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.160.6.46 raeburn 2825: .'<select name="'.$type.'_'.$key.'"'.$chgstr.'>';
1.160.6.30 raeburn 2826: for (my $k=0; $k<=$maxnum; $k++) {
2827: my $vpos = $k+1;
2828: my $selstr;
2829: if ($k == $i) {
2830: $selstr = ' selected="selected" ';
2831: }
2832: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2833: }
2834: $datatable .= '</select>'.(' 'x2).
1.160.6.46 raeburn 2835: '<label><input type="checkbox" name="'.$type.'_del" value="'.$key.'" />'.
1.160.6.30 raeburn 2836: &mt('Delete?').'</label></span></td>'.
2837: '<td colspan="2">'.
1.160.6.46 raeburn 2838: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_subject_'.$i.'" value="'.$subject.'" /></span> '.
1.160.6.30 raeburn 2839: (' 'x2).
1.160.6.46 raeburn 2840: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_title_'.$i.'" value="'.$title.'" /></span> ';
2841: if ($type eq 'textbooks') {
2842: $datatable .= (' 'x2).
1.160.6.47 raeburn 2843: '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_publisher_'.$i.'" value="'.$publisher.'" /></span> '.
2844: (' 'x2).
1.160.6.46 raeburn 2845: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_author_'.$i.'" value="'.$author.'" /></span> '.
2846: (' 'x2).
2847: '<span class="LC_nobreak">'.&mt('Thumbnail:');
2848: if ($image) {
1.160.6.114 raeburn 2849: $datatable .= $imgsrc.
1.160.6.46 raeburn 2850: '<label><input type="checkbox" name="'.$type.'_image_del"'.
2851: ' value="'.$key.'" />'.&mt('Delete?').'</label></span> '.
2852: '<span class="LC_nobreak"> '.&mt('Replace:').' ';
2853: }
2854: if ($switchserver) {
2855: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2856: } else {
2857: $datatable .= '<input type="file" name="'.$type.'_image_'.$i.'" value="" />';
2858: }
1.160.6.30 raeburn 2859: }
1.160.6.46 raeburn 2860: $datatable .= '<input type="hidden" name="'.$type.'_id_'.$i.'" value="'.$type.'_'.$key.'" /></span> '.
1.160.6.30 raeburn 2861: '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
2862: $coursetitle.'</span></td></tr>'."\n";
2863: $itemcount ++;
2864: }
2865: }
2866: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.46 raeburn 2867: my $chgstr = ' onchange="javascript:reorderBooks(this.form,'."'$type"."_addbook_pos','$type'".');"';
1.160.6.30 raeburn 2868: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
1.160.6.46 raeburn 2869: '<input type="hidden" name="'.$type.'_maxnum" value="'.$maxnum.'" />'."\n".
2870: '<select name="'.$type.'_addbook_pos"'.$chgstr.'>';
1.160.6.30 raeburn 2871: for (my $k=0; $k<$maxnum+1; $k++) {
2872: my $vpos = $k+1;
2873: my $selstr;
2874: if ($k == $maxnum) {
2875: $selstr = ' selected="selected" ';
2876: }
2877: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
2878: }
2879: $datatable .= '</select> '."\n".
1.160.6.87 raeburn 2880: '<input type="checkbox" name="'.$type.'_addbook" value="1" />'.&mt('Add').'</span></td>'."\n".
1.160.6.30 raeburn 2881: '<td colspan="2">'.
1.160.6.46 raeburn 2882: '<span class="LC_nobreak">'.&mt('Subject:').'<input type="text" size="15" name="'.$type.'_addbook_subject" value="" /></span> '."\n".
1.160.6.30 raeburn 2883: (' 'x2).
1.160.6.46 raeburn 2884: '<span class="LC_nobreak">'.&mt('Title:').'<input type="text" size="30" name="'.$type.'_addbook_title" value="" /></span> '."\n".
2885: (' 'x2);
2886: if ($type eq 'textbooks') {
1.160.6.47 raeburn 2887: $datatable .= '<span class="LC_nobreak">'.&mt('Publisher:').'<input type="text" size="10" name="'.$type.'_addbook_publisher" value="" /></span> '."\n".
2888: (' 'x2).
2889: '<span class="LC_nobreak">'.&mt('Author(s):').'<input type="text" size="25" name="'.$type.'_addbook_author" value="" /></span> '."\n".
1.160.6.46 raeburn 2890: (' 'x2).
2891: '<span class="LC_nobreak">'.&mt('Image:').' ';
2892: if ($switchserver) {
2893: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
2894: } else {
2895: $datatable .= '<input type="file" name="'.$type.'_addbook_image" value="" />';
2896: }
1.160.6.87 raeburn 2897: $datatable .= '</span>'."\n";
1.160.6.30 raeburn 2898: }
1.160.6.87 raeburn 2899: $datatable .= '<span class="LC_nobreak">'.&mt('LON-CAPA course:').' '.
1.160.6.46 raeburn 2900: &Apache::loncommon::select_dom_form($env{'request.role.domain'},$type.'_addbook_cdom').
2901: '<input type="text" size="25" name="'.$type.'_addbook_cnum" value="" />'.
1.160.6.30 raeburn 2902: &Apache::loncommon::selectcourse_link
1.160.6.87 raeburn 2903: ('display',$type.'_addbook_cnum',$type.'_addbook_cdom',undef,undef,undef,'Course').
1.160.6.30 raeburn 2904: '</span></td>'."\n".
2905: '</tr>'."\n";
2906: $itemcount ++;
2907: return $datatable;
2908: }
2909:
2910: sub textbookcourses_javascript {
1.160.6.46 raeburn 2911: my ($settings) = @_;
2912: return unless(ref($settings) eq 'HASH');
2913: my (%ordered,%total,%jstext);
2914: foreach my $type ('textbooks','templates') {
2915: $total{$type} = 0;
2916: if (ref($settings->{$type}) eq 'HASH') {
2917: foreach my $item (keys(%{$settings->{$type}})) {
2918: if (ref($settings->{$type}->{$item}) eq 'HASH') {
2919: my $num = $settings->{$type}->{$item}{'order'};
2920: $ordered{$type}{$num} = $item;
2921: }
2922: }
2923: $total{$type} = scalar(keys(%{$settings->{$type}}));
2924: }
2925: my @jsarray = ();
2926: foreach my $item (sort {$a <=> $b } (keys(%{$ordered{$type}}))) {
2927: push(@jsarray,$ordered{$type}{$item});
2928: }
2929: $jstext{$type} = ' var '.$type.' = Array('."'".join("','",@jsarray)."'".');'."\n";
1.160.6.30 raeburn 2930: }
2931: return <<"ENDSCRIPT";
2932: <script type="text/javascript">
2933: // <![CDATA[
1.160.6.46 raeburn 2934: function reorderBooks(form,item,caller) {
1.160.6.30 raeburn 2935: var changedVal;
1.160.6.46 raeburn 2936: $jstext{'textbooks'};
2937: $jstext{'templates'};
2938: var newpos;
2939: var maxh;
2940: if (caller == 'textbooks') {
2941: newpos = 'textbooks_addbook_pos';
2942: maxh = 1 + $total{'textbooks'};
2943: } else {
2944: newpos = 'templates_addbook_pos';
2945: maxh = 1 + $total{'templates'};
2946: }
1.160.6.30 raeburn 2947: var current = new Array;
2948: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
2949: if (item == newpos) {
2950: changedVal = newitemVal;
2951: } else {
2952: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
2953: current[newitemVal] = newpos;
2954: }
1.160.6.46 raeburn 2955: if (caller == 'textbooks') {
2956: for (var i=0; i<textbooks.length; i++) {
2957: var elementName = 'textbooks_'+textbooks[i];
2958: if (elementName != item) {
2959: if (form.elements[elementName]) {
2960: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2961: current[currVal] = elementName;
2962: }
2963: }
2964: }
2965: }
2966: if (caller == 'templates') {
2967: for (var i=0; i<templates.length; i++) {
2968: var elementName = 'templates_'+templates[i];
2969: if (elementName != item) {
2970: if (form.elements[elementName]) {
2971: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
2972: current[currVal] = elementName;
2973: }
1.160.6.30 raeburn 2974: }
2975: }
2976: }
2977: var oldVal;
2978: for (var j=0; j<maxh; j++) {
2979: if (current[j] == undefined) {
2980: oldVal = j;
2981: }
2982: }
2983: if (oldVal < changedVal) {
2984: for (var k=oldVal+1; k<=changedVal ; k++) {
2985: var elementName = current[k];
2986: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
2987: }
2988: } else {
2989: for (var k=changedVal; k<oldVal; k++) {
2990: var elementName = current[k];
2991: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
2992: }
2993: }
2994: return;
2995: }
2996:
2997: // ]]>
2998: </script>
2999:
3000: ENDSCRIPT
3001: }
3002:
1.160.6.118.2 1(raebur 3003:1): sub ltitools_javascript {
3004:1): my ($settings) = @_;
3005:1): my $togglejs = <itools_toggle_js();
3006:1): unless (ref($settings) eq 'HASH') {
3007:1): return $togglejs;
3008:1): }
3009:1): my (%ordered,$total,%jstext);
3010:1): $total = 0;
3011:1): foreach my $item (keys(%{$settings})) {
3012:1): if (ref($settings->{$item}) eq 'HASH') {
3013:1): my $num = $settings->{$item}{'order'};
3014:1): $ordered{$num} = $item;
3015:1): }
3016:1): }
3017:1): $total = scalar(keys(%{$settings}));
3018:1): my @jsarray = ();
3019:1): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3020:1): push(@jsarray,$ordered{$item});
3021:1): }
3022:1): my $jstext = ' var ltitools = Array('."'".join("','",@jsarray)."'".');'."\n";
3023:1): return <<"ENDSCRIPT";
3024:1): <script type="text/javascript">
3025:1): // <![CDATA[
3026:1): function reorderLTITools(form,item) {
3027:1): var changedVal;
3028:1): $jstext
3029:1): var newpos = 'ltitools_add_pos';
3030:1): var maxh = 1 + $total;
3031:1): var current = new Array;
3032:1): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3033:1): if (item == newpos) {
3034:1): changedVal = newitemVal;
3035:1): } else {
3036:1): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3037:1): current[newitemVal] = newpos;
3038:1): }
3039:1): for (var i=0; i<ltitools.length; i++) {
3040:1): var elementName = 'ltitools_'+ltitools[i];
3041:1): if (elementName != item) {
3042:1): if (form.elements[elementName]) {
3043:1): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3044:1): current[currVal] = elementName;
3045:1): }
3046:1): }
3047:1): }
3048:1): var oldVal;
3049:1): for (var j=0; j<maxh; j++) {
3050:1): if (current[j] == undefined) {
3051:1): oldVal = j;
3052:1): }
3053:1): }
3054:1): if (oldVal < changedVal) {
3055:1): for (var k=oldVal+1; k<=changedVal ; k++) {
3056:1): var elementName = current[k];
3057:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3058:1): }
3059:1): } else {
3060:1): for (var k=changedVal; k<oldVal; k++) {
3061:1): var elementName = current[k];
3062:1): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3063:1): }
3064:1): }
3065:1): return;
3066:1): }
3067:1):
3068:1): // ]]>
3069:1): </script>
3070:1):
3071:1): $togglejs
3072:1):
3073:1): ENDSCRIPT
3074:1): }
3075:1):
3076:1): sub ltitools_toggle_js {
3077:1): return <<"ENDSCRIPT";
3078:1): <script type="text/javascript">
3079:1): // <![CDATA[
3080:1):
3081:1): function toggleLTITools(form,setting,item) {
3082:1): var radioname = '';
3083:1): var divid = '';
14(raebu 3084:23): if ((setting == 'passback') || (setting == 'roster')) {
3085:23): radioname = 'ltitools_'+setting+'_'+item;
3086:23): divid = 'ltitools_'+setting+'time_'+item;
3087:23): var num = form.elements[radioname].length;
3088:23): if (num) {
3089:23): var setvis = '';
3090:23): for (var i=0; i<num; i++) {
3091:23): if (form.elements[radioname][i].checked) {
3092:23): if (form.elements[radioname][i].value == '1') {
3093:23): if (document.getElementById(divid)) {
3094:23): document.getElementById(divid).style.display = 'inline-block';
3095:23): }
3096:23): setvis = 1;
3097:23): }
3098:23): break;
3099:23): }
3100:23): }
3101:23): }
3102:23): if (!setvis) {
3103:23): if (document.getElementById(divid)) {
3104:23): document.getElementById(divid).style.display = 'none';
3105:23): }
3106:23): }
3107:23): }
1(raebur 3108:1): if (setting == 'user') {
3109:1): divid = 'ltitools_'+setting+'_div_'+item;
3110:1): var checkid = 'ltitools_'+setting+'_field_'+item;
3111:1): if (document.getElementById(divid)) {
3112:1): if (document.getElementById(checkid)) {
3113:1): if (document.getElementById(checkid).checked) {
3114:1): document.getElementById(divid).style.display = 'inline-block';
3115:1): } else {
3116:1): document.getElementById(divid).style.display = 'none';
3117:1): }
3118:1): }
3119:1): }
3120:1): }
3121:1): return;
3122:1): }
3123:1): // ]]>
3124:1): </script>
3125:1):
3126:1): ENDSCRIPT
3127:1): }
3128:1):
1.160.6.113 raeburn 3129: sub wafproxy_javascript {
3130: my ($dom) = @_;
3131: return <<"ENDSCRIPT";
3132: <script type="text/javascript">
3133: // <![CDATA[
3134: function updateWAF() {
3135: if (document.getElementById('wafproxy_remoteip')) {
3136: var wafremote = 0;
3137: if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value == 'h') {
3138: wafremote = 1;
3139: }
3140: var fields = new Array('header','trust');
3141: for (var i=0; i<fields.length; i++) {
3142: if (document.getElementById('wafproxy_'+fields[i])) {
3143: if (wafremote == 1) {
3144: document.getElementById('wafproxy_'+fields[i]).style.display = 'table-row';
3145: }
3146: else {
3147: document.getElementById('wafproxy_'+fields[i]).style.display = 'none';
3148: }
3149: }
3150: }
3151: if (document.getElementById('wafproxyranges_$dom')) {
3152: if (wafremote == 1) {
3153: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3154: } else {
3155: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3156: if (document.display.wafproxy_vpnaccess[i].checked) {
3157: if (document.display.wafproxy_vpnaccess[i].value == 0) {
3158: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3159: }
3160: }
3161: }
3162: }
3163: }
3164: }
3165: return;
3166: }
3167:
3168: function checkWAF() {
3169: if (document.getElementById('wafproxy_remoteip')) {
3170: var wafvpn = 0;
3171: for (var i=0; i<document.display.wafproxy_vpnaccess.length; i++) {
3172: if (document.display.wafproxy_vpnaccess[i].checked) {
3173: if (document.display.wafproxy_vpnaccess[i].value == 1) {
3174: wafvpn = 1;
3175: }
3176: break;
3177: }
3178: }
3179: var vpn = new Array('vpnint','vpnext');
3180: for (var i=0; i<vpn.length; i++) {
3181: if (document.getElementById('wafproxy_show_'+vpn[i])) {
3182: if (wafvpn == 1) {
3183: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'table-row';
3184: }
3185: else {
3186: document.getElementById('wafproxy_show_'+vpn[i]).style.display = 'none';
3187: }
3188: }
3189: }
3190: if (document.getElementById('wafproxyranges_$dom')) {
3191: if (wafvpn == 1) {
3192: document.getElementById('wafproxyranges_$dom').style.display = 'inline-block';
3193: }
3194: else if (document.display.wafproxy_remoteip.options[document.display.wafproxy_remoteip.selectedIndex].value != 'h') {
3195: document.getElementById('wafproxyranges_$dom').style.display = 'none';
3196: }
3197: }
3198: }
3199: return;
3200: }
3201:
3202: function toggleWAF() {
3203: if (document.getElementById('wafproxy_table')) {
3204: var wafproxy = 0;
3205: for (var i=0; i<document.display.wafproxy_${dom}.length; i++) {
3206: if (document.display.wafproxy_${dom}[i].checked) {
3207: if (document.display.wafproxy_${dom}[i].value == 1) {
3208: wafproxy = 1;
3209: break;
3210: }
3211: }
3212: }
3213: if (wafproxy == 1) {
3214: document.getElementById('wafproxy_table').style.display='inline';
3215: }
3216: else {
3217: document.getElementById('wafproxy_table').style.display='none';
3218: }
3219: if (document.getElementById('wafproxyrow_${dom}')) {
3220: if (wafproxy == 1) {
3221: document.getElementById('wafproxyrow_${dom}').style.display = 'table-row';
3222: }
3223: else {
3224: document.getElementById('wafproxyrow_${dom}').style.display = 'none';
3225: }
3226: }
3227: if (document.getElementById('nowafproxyrow_$dom')) {
3228: if (wafproxy == 1) {
3229: document.getElementById('nowafproxyrow_${dom}').style.display = 'none';
3230: }
3231: else {
3232: document.getElementById('nowafproxyrow_${dom}').style.display = 'table-row';
3233: }
3234: }
3235: }
3236: return;
3237: }
3238: // ]]>
3239: </script>
3240:
3241: ENDSCRIPT
3242: }
3243:
1.160.6.118.2 5(raebur 3244:2): sub lti_javascript {
3245:2): my ($dom,$settings) = @_;
3246:2): my $togglejs = <i_toggle_js($dom);
3247:2): my $linkprot_js = &Apache::courseprefs::linkprot_javascript();
14(raebu 3248:23): unless (ref($settings) eq 'HASH') {
3249:23): return $togglejs.'
3250:23): <script type="text/javascript">
3251:23): // <![CDATA[
3252:23):
3253:23): '.$linkprot_js.'
3254:23):
3255:23): // ]]>
3256:23): </script>
3257:23): ';
3258:23): }
3259:23): my (%ordered,$total,%jstext);
3260:23): $total = scalar(keys(%{$settings}));
3261:23): foreach my $item (keys(%{$settings})) {
3262:23): if (ref($settings->{$item}) eq 'HASH') {
3263:23): my $num = $settings->{$item}{'order'};
3264:23): if ($num eq '') {
3265:23): $num = $total - 1;
3266:23): }
3267:23): $ordered{$num} = $item;
3268:23): }
3269:23): }
3270:23): my @jsarray = ();
3271:23): foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3272:23): push(@jsarray,$ordered{$item});
3273:23): }
3274:23): my $jstext = ' var lti = Array('."'".join("','",@jsarray)."'".');'."\n";
5(raebur 3275:2): return <<"ENDSCRIPT";
3276:2): <script type="text/javascript">
3277:2): // <![CDATA[
14(raebu 3278:23): function reorderLTI(form,item) {
3279:23): var changedVal;
3280:23): $jstext
3281:23): var newpos = 'lti_pos_add';
3282:23): var maxh = 1 + $total;
3283:23): var current = new Array;
3284:23): var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3285:23): if (item == newpos) {
3286:23): changedVal = newitemVal;
3287:23): } else {
3288:23): changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3289:23): current[newitemVal] = newpos;
3290:23): }
3291:23): for (var i=0; i<lti.length; i++) {
3292:23): var elementName = 'lti_pos_'+lti[i];
3293:23): if (elementName != item) {
3294:23): if (form.elements[elementName]) {
3295:23): var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3296:23): current[currVal] = elementName;
3297:23): }
3298:23): }
3299:23): }
3300:23): var oldVal;
3301:23): for (var j=0; j<maxh; j++) {
3302:23): if (current[j] == undefined) {
3303:23): oldVal = j;
3304:23): }
3305:23): }
3306:23): if (oldVal < changedVal) {
3307:23): for (var k=oldVal+1; k<=changedVal ; k++) {
3308:23): var elementName = current[k];
3309:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3310:23): }
3311:23): } else {
3312:23): for (var k=changedVal; k<oldVal; k++) {
3313:23): var elementName = current[k];
3314:23): form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3315:23): }
3316:23): }
3317:23): return;
3318:23): }
5(raebur 3319:2):
3320:2): $linkprot_js
3321:2):
3322:2): // ]]>
3323:2): </script>
3324:2):
3325:2): $togglejs
3326:2):
3327:2): ENDSCRIPT
3328:2): }
3329:2):
3330:2): sub lti_toggle_js {
3331:2): my ($dom) = @_;
14(raebu 3332:23): my %lcauthparmtext = &Apache::lonlocal::texthash (
3333:23): localauth => 'Local auth argument',
3334:23): krb => 'Kerberos domain',
3335:23): );
3336: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");
3337:23): &js_escape(\$crsincalert);
5(raebur 3338:2): my %servers = &Apache::lonnet::get_servers($dom,'library');
3339:2): my $primary = &Apache::lonnet::domain($dom,'primary');
3340:2): my $course_servers = "'".join("','",keys(%servers))."'";
6(raebur 3341:2): return <<"ENDSCRIPT";
3342:2): <script type="text/javascript">
3343:2): // <![CDATA[
14(raebu 3344:23):
3345:23): function toggleLTI(form,setting,item) {
3346:23): if ((setting == 'requser') || (setting == 'crsinc')) {
3347:23): var usrfieldsets = document.getElementsByClassName('ltioption_usr_'+item);
3348:23): var setvis = '';
3349:23): var radioname = 'lti_requser_'+item;
3350:23): var num = form.elements[radioname].length;
3351:23): if (num) {
3352:23): for (var i=0; i<num; i++) {
3353:23): if (form.elements[radioname][i].checked) {
3354:23): if (form.elements[radioname][i].value == '1') {
3355:23): setvis = 1;
3356:23): break;
5(raebur 3357:2): }
14(raebu 3358:23): }
3359:23): }
3360:23): }
3361:23): if (usrfieldsets.length) {
3362:23): for (var j=0; j<usrfieldsets.length; j++) {
3363:23): if (setvis) {
3364:23): usrfieldsets[j].style.display = 'block';
3365:23): } else {
3366:23): usrfieldsets[j].style.display = 'none';
3367:23): }
3368:23): }
3369:23): }
3370:23): var crsfieldsets = document.getElementsByClassName('ltioption_crs_'+item);
3371:23): if (crsfieldsets.length) {
3372:23): radioname = 'lti_crsinc_'+item;
3373:23): var num = form.elements[radioname].length;
3374:23): if (num) {
3375:23): var crsvis = '';
3376:23): for (var i=0; i<num; i++) {
3377:23): if (form.elements[radioname][i].checked) {
3378:23): if (form.elements[radioname][i].value == '1') {
3379:23): if (setvis == '') {
3380:23): if (setting == 'crsinc'){
3381:23): alert("$crsincalert");
3382:23): form.elements[radioname][0].checked = true;
3383:23): }
3384:23): } else {
3385:23): crsvis = 1;
5(raebur 3386:2): }
14(raebu 3387:23): break;
5(raebur 3388:2): }
3389:2): }
3390:2): }
14(raebu 3391:23): setvis = crsvis;
5(raebur 3392:2): }
14(raebu 3393:23): for (var j=0; j<crsfieldsets.length; j++) {
3394:23): if (setvis) {
3395:23): crsfieldsets[j].style.display = 'block';
3396:23): } else {
3397:23): crsfieldsets[j].style.display = 'none';
5(raebur 3398:2): }
3399:2): }
3400:2): }
14(raebu 3401:23): } else if ((setting == 'user') || (setting == 'crs') || (setting == 'passback') || (setting == 'callback')) {
3402:23): var radioname = '';
3403:23): var divid = '';
3404:23): if (setting == 'user') {
3405:23): radioname = 'lti_mapuser_'+item;
3406:23): divid = 'lti_userfield_'+item;
3407:23): } else if (setting == 'crs') {
3408:23): radioname = 'lti_mapcrs_'+item;
3409:23): divid = 'lti_crsfield_'+item;
3410:23): } else if (setting == 'callback') {
3411:23): radioname = 'lti_callback_'+item;
3412:23): divid = 'lti_callbackfield_'+item;
3413:23): } else {
3414:23): radioname = 'lti_passback_'+item;
3415:23): divid = 'lti_passback_'+item;
3416:23): }
3417:23): var num = form.elements[radioname].length;
3418:23): if (num) {
3419:23): var setvis = '';
3420:23): for (var i=0; i<num; i++) {
3421:23): if (form.elements[radioname][i].checked) {
3422:23): if ((setting == 'passback') || (setting == 'callback')) {
3423:23): if (form.elements[radioname][i].value == '1') {
3424:23): if (document.getElementById(divid)) {
3425:23): document.getElementById(divid).style.display = 'inline-block';
3426:23): }
3427:23): setvis = 1;
3428:23): break;
3429:23): }
3430:23): } else {
3431:23): if (form.elements[radioname][i].value == 'other') {
3432:23): if (document.getElementById(divid)) {
3433:23): document.getElementById(divid).style.display = 'inline-block';
3434:23): }
3435:23): setvis = 1;
3436:23): break;
3437:23): }
3438:23): }
3439:23): }
3440:23): }
3441:23): if (!setvis) {
3442:23): if (document.getElementById(divid)) {
3443:23): document.getElementById(divid).style.display = 'none';
3444:23): }
5(raebur 3445:2): }
3446:2): }
14(raebu 3447:23): } else if ((setting == 'sec') || (setting == 'secsrc')) {
3448:23): var numsec = form.elements['lti_crssec_'+item].length;
3449:23): if (numsec) {
3450:23): var setvis = '';
3451:23): for (var i=0; i<numsec; i++) {
3452:23): if (form.elements['lti_crssec_'+item][i].checked) {
3453:23): if (form.elements['lti_crssec_'+item][i].value == '1') {
3454:23): if (document.getElementById('lti_crssecfield_'+item)) {
3455:23): document.getElementById('lti_crssecfield_'+item).style.display = 'inline-block';
3456:23): setvis = 1;
3457:23): var numsrcsec = form.elements['lti_crssecsrc_'+item].length;
3458:23): if (numsrcsec) {
3459:23): var setsrcvis = '';
3460:23): for (var j=0; j<numsrcsec; j++) {
3461:23): if (form.elements['lti_crssecsrc_'+item][j].checked) {
3462:23): if (form.elements['lti_crssecsrc_'+item][j].value == 'other') {
3463:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3464:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'inline-block';
3465:23): setsrcvis = 1;
3466:23): }
3467:23): }
3468:23): }
3469:23): }
3470:23): if (!setsrcvis) {
3471:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3472:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3473:23): }
3474:23): }
3475:23): }
3476:23): }
3477:23): }
3478:23): }
3479:23): }
3480:23): if (!setvis) {
3481:23): if (document.getElementById('lti_crssecfield_'+item)) {
3482:23): document.getElementById('lti_crssecfield_'+item).style.display = 'none';
3483:23): }
3484:23): if (document.getElementById('lti_secsrcfield_'+item)) {
3485:23): document.getElementById('lti_secsrcfield_'+item).style.display = 'none';
3486:23): }
3487:23): }
5(raebur 3488:2): }
14(raebu 3489:23): } else if (setting == 'lcauth') {
3490:23): var numauth = form.elements['lti_lcauth_'+item].length;
3491:23): if (numauth) {
3492:23): for (var i=0; i<numauth; i++) {
3493:23): if (form.elements['lti_lcauth_'+item][i].checked) {
3494:23): if (document.getElementById('lti_'+setting+'_parmrow_'+item)) {
3495:23): if ((form.elements['lti_'+setting+'_'+item][i].value == 'internal') || (form.elements['lti_'+setting+'_'+item][i].value == 'lti')) {
3496:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'none';
3497:23): } else {
3498:23): document.getElementById('lti_'+setting+'_parmrow_'+item).style.display = 'table-row';
3499:23): if (document.getElementById('lti_'+setting+'_parmtext_'+item)) {
3500:23): if (form.elements['lti_'+setting+'_'+item][i].value == 'localauth') {
3501:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'localauth'}";
3502:23): } else {
3503:23): document.getElementById('lti_'+setting+'_parmtext_'+item).innerHTML = "$lcauthparmtext{'krb'}";
3504:23): }
3505:23): }
3506:23): }
3507:23): }
5(raebur 3508:2): }
3509:2): }
3510:2): }
14(raebu 3511:23): } else if (setting == 'lcmenu') {
3512:23): var menus = new Array('lti_topmenu_'+item,'lti_inlinemenu_'+item);
3513:23): var divid = 'lti_menufield_'+item;
3514:23): var setvis = '';
3515:23): for (var i=0; i<menus.length; i++) {
3516:23): var radioname = menus[i];
3517:23): var num = form.elements[radioname].length;
3518:23): if (num) {
3519:23): for (var j=0; j<num; j++) {
3520:23): if (form.elements[radioname][j].checked) {
3521:23): if (form.elements[radioname][j].value == '1') {
3522:23): if (document.getElementById(divid)) {
3523:23): document.getElementById(divid).style.display = 'inline-block';
3524:23): }
5(raebur 3525:2): setvis = 1;
14(raebu 3526:23): break;
5(raebur 3527:2): }
3528:2): }
3529:2): }
14(raebu 3530:23): }
3531:23): if (setvis == 1) {
3532:23): break;
3533:23): }
3534:23): }
3535:23): if (!setvis) {
3536:23): if (document.getElementById(divid)) {
3537:23): document.getElementById(divid).style.display = 'none';
5(raebur 3538:2): }
3539:2): }
3540:2): }
14(raebu 3541:23): return;
5(raebur 3542:2): }
3543:2):
3544:2): // ]]>
3545:2): </script>
3546:2):
3547:2): ENDSCRIPT
3548:2): }
3549:2):
1.160.6.113 raeburn 3550: sub autoupdate_javascript {
3551: return <<"ENDSCRIPT";
3552: <script type="text/javascript">
3553: // <![CDATA[
3554: function toggleLastActiveDays(form) {
3555: var radioname = 'lastactive';
3556: var divid = 'lastactive_div';
3557: var num = form.elements[radioname].length;
3558: if (num) {
3559: var setvis = '';
3560: for (var i=0; i<num; i++) {
3561: if (form.elements[radioname][i].checked) {
3562: if (form.elements[radioname][i].value == '1') {
3563: if (document.getElementById(divid)) {
3564: document.getElementById(divid).style.display = 'inline-block';
3565: }
3566: setvis = 1;
3567: }
3568: break;
3569: }
3570: }
3571: if (!setvis) {
3572: if (document.getElementById(divid)) {
3573: document.getElementById(divid).style.display = 'none';
3574: }
3575: }
3576: }
3577: return;
3578: }
3579: // ]]>
3580: </script>
3581:
3582: ENDSCRIPT
3583: }
3584:
1.160.6.116 raeburn 3585: sub autoenroll_javascript {
3586: return <<"ENDSCRIPT";
3587: <script type="text/javascript">
3588: // <![CDATA[
3589: function toggleFailsafe(form) {
3590: var radioname = 'autoenroll_failsafe';
3591: var divid = 'autoenroll_failsafe_div';
3592: var num = form.elements[radioname].length;
3593: if (num) {
3594: var setvis = '';
3595: for (var i=0; i<num; i++) {
3596: if (form.elements[radioname][i].checked) {
3597: if ((form.elements[radioname][i].value == 'zero') || (form.elements[radioname][i].value == 'any')) {
3598: if (document.getElementById(divid)) {
3599: document.getElementById(divid).style.display = 'inline-block';
3600: }
3601: setvis = 1;
3602: }
3603: break;
3604: }
3605: }
3606: if (!setvis) {
3607: if (document.getElementById(divid)) {
3608: document.getElementById(divid).style.display = 'none';
3609: }
3610: }
3611: }
3612: return;
3613: }
3614: // ]]>
3615: </script>
3616:
3617: ENDSCRIPT
3618: }
3619:
1.160.6.113 raeburn 3620: sub saml_javascript {
3621: return <<"ENDSCRIPT";
3622: <script type="text/javascript">
3623: // <![CDATA[
3624: function toggleSamlOptions(form,hostid) {
3625: var radioname = 'saml_'+hostid;
3626: var tablecellon = 'samloptionson_'+hostid;
3627: var tablecelloff = 'samloptionsoff_'+hostid;
3628: var num = form.elements[radioname].length;
3629: if (num) {
3630: var setvis = '';
3631: for (var i=0; i<num; i++) {
3632: if (form.elements[radioname][i].checked) {
3633: if (form.elements[radioname][i].value == '1') {
3634: if (document.getElementById(tablecellon)) {
3635: document.getElementById(tablecellon).style.display='';
3636: }
3637: if (document.getElementById(tablecelloff)) {
3638: document.getElementById(tablecelloff).style.display='none';
3639: }
3640: setvis = 1;
3641: }
3642: break;
3643: }
3644: }
3645: if (!setvis) {
3646: if (document.getElementById(tablecellon)) {
3647: document.getElementById(tablecellon).style.display='none';
3648: }
3649: if (document.getElementById(tablecelloff)) {
3650: document.getElementById(tablecelloff).style.display='';
3651: }
3652: }
3653: }
3654: return;
3655: }
3656: // ]]>
3657: </script>
3658:
3659: ENDSCRIPT
3660: }
3661:
3662: sub ipaccess_javascript {
3663: my ($settings) = @_;
3664: my (%ordered,$total,%jstext);
3665: $total = 0;
3666: if (ref($settings) eq 'HASH') {
3667: foreach my $item (keys(%{$settings})) {
3668: if (ref($settings->{$item}) eq 'HASH') {
3669: my $num = $settings->{$item}{'order'};
3670: $ordered{$num} = $item;
3671: }
3672: }
3673: $total = scalar(keys(%{$settings}));
3674: }
3675: my @jsarray = ();
3676: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
3677: push(@jsarray,$ordered{$item});
3678: }
3679: my $jstext = ' var ipaccess = Array('."'".join("','",@jsarray)."'".');'."\n";
3680: return <<"ENDSCRIPT";
3681: <script type="text/javascript">
3682: // <![CDATA[
3683: function reorderIPaccess(form,item) {
3684: var changedVal;
3685: $jstext
3686: var newpos = 'ipaccess_pos_add';
3687: var maxh = 1 + $total;
3688: var current = new Array;
3689: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
3690: if (item == newpos) {
3691: changedVal = newitemVal;
3692: } else {
3693: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
3694: current[newitemVal] = newpos;
3695: }
3696: for (var i=0; i<ipaccess.length; i++) {
3697: var elementName = 'ipaccess_pos_'+ipaccess[i];
3698: if (elementName != item) {
3699: if (form.elements[elementName]) {
3700: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
3701: current[currVal] = elementName;
3702: }
3703: }
3704: }
3705: var oldVal;
3706: for (var j=0; j<maxh; j++) {
3707: if (current[j] == undefined) {
3708: oldVal = j;
3709: }
3710: }
3711: if (oldVal < changedVal) {
3712: for (var k=oldVal+1; k<=changedVal ; k++) {
3713: var elementName = current[k];
3714: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
3715: }
3716: } else {
3717: for (var k=changedVal; k<oldVal; k++) {
3718: var elementName = current[k];
3719: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
3720: }
3721: }
3722: return;
3723: }
3724: // ]]>
3725: </script>
3726:
3727: ENDSCRIPT
3728: }
3729:
1.160.6.118.2 20(raebu 3730:24): sub authordefaults_javascript {
3731:24): my %alert = &Apache::lonlocal::texthash (
3732:24): reqd => 'Warning: at least one editor needs to be available.',
3733:24): rest => 'Unchecking this editor disallowed while others unchecked.',
3734:24): );
3735:24): &js_escape(\%alert);
3736:24): return <<"ENDSCRIPT";
3737:24): <script type="text/javascript">
3738:24): // <![CDATA[
3739:24):
3740:24): function checkEditors(form,checkbox,current) {
3741:24): if (form.elements[checkbox].length != undefined) {
3742:24): var count = 0;
3743:24): for (var i=0; i<form.elements[checkbox].length; i++) {
3744:24): if (form.elements[checkbox][i].checked) {
3745:24): count ++;
3746:24): }
3747:24): }
3748:24): if (count == 0) {
3749:24): if (current.type =='radio') {
3750:24): current.checked = true;
3751:24): alert('$alert{reqd}\\n$alert{rest}');
3752:24): }
3753:24): }
3754:24): }
3755:24): return;
3756:24): }
3757:24): // ]]>
3758:24): </script>
3759:24):
3760:24): ENDSCRIPT
3761:24): }
3762:24):
1.3 raeburn 3763: sub print_autoenroll {
1.30 raeburn 3764: my ($dom,$settings,$rowtotal) = @_;
1.3 raeburn 3765: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
1.160.6.116 raeburn 3766: my ($defdom,$runon,$runoff,$coownerson,$coownersoff,
3767: $failsafe,$autofailsafe,$failsafesty,%failsafechecked);
3768: $failsafesty = 'none';
3769: %failsafechecked = (
3770: off => ' checked="checked"',
3771: );
1.3 raeburn 3772: if (ref($settings) eq 'HASH') {
3773: if (exists($settings->{'run'})) {
3774: if ($settings->{'run'} eq '0') {
3775: $runoff = ' checked="checked" ';
3776: $runon = ' ';
3777: } else {
3778: $runon = ' checked="checked" ';
3779: $runoff = ' ';
3780: }
3781: } else {
3782: if ($autorun) {
3783: $runon = ' checked="checked" ';
3784: $runoff = ' ';
3785: } else {
3786: $runoff = ' checked="checked" ';
3787: $runon = ' ';
3788: }
3789: }
1.129 raeburn 3790: if (exists($settings->{'co-owners'})) {
3791: if ($settings->{'co-owners'} eq '0') {
3792: $coownersoff = ' checked="checked" ';
3793: $coownerson = ' ';
3794: } else {
3795: $coownerson = ' checked="checked" ';
3796: $coownersoff = ' ';
3797: }
3798: } else {
3799: $coownersoff = ' checked="checked" ';
3800: $coownerson = ' ';
3801: }
1.3 raeburn 3802: if (exists($settings->{'sender_domain'})) {
3803: $defdom = $settings->{'sender_domain'};
3804: }
1.160.6.116 raeburn 3805: if (exists($settings->{'failsafe'})) {
3806: $failsafe = $settings->{'failsafe'};
3807: if ($failsafe eq 'zero') {
3808: $failsafechecked{'zero'} = ' checked="checked"';
3809: $failsafechecked{'off'} = '';
3810: $failsafesty = 'inline-block';
3811: } elsif ($failsafe eq 'any') {
3812: $failsafechecked{'any'} = ' checked="checked"';
3813: $failsafechecked{'off'} = '';
3814: }
3815: $autofailsafe = $settings->{'autofailsafe'};
3816: } elsif (exists($settings->{'autofailsafe'})) {
3817: $autofailsafe = $settings->{'autofailsafe'};
3818: if ($autofailsafe ne '') {
3819: $failsafechecked{'zero'} = ' checked="checked"';
3820: $failsafe = 'zero';
3821: $failsafechecked{'off'} = '';
3822: }
1.160.6.68 raeburn 3823: }
1.14 raeburn 3824: } else {
3825: if ($autorun) {
3826: $runon = ' checked="checked" ';
3827: $runoff = ' ';
3828: } else {
3829: $runoff = ' checked="checked" ';
3830: $runon = ' ';
3831: }
1.3 raeburn 3832: }
3833: my $domform = &Apache::loncommon::select_dom_form($defdom,'sender_domain',1);
1.39 raeburn 3834: my $notif_sender;
3835: if (ref($settings) eq 'HASH') {
3836: $notif_sender = $settings->{'sender_uname'};
3837: }
1.3 raeburn 3838: my $datatable='<tr class="LC_odd_row">'.
3839: '<td>'.&mt('Auto-enrollment active?').'</td>'.
1.8 raeburn 3840: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3841: '<input type="radio" name="autoenroll_run"'.
1.8 raeburn 3842: $runon.' value="1" />'.&mt('Yes').'</label> '.
3843: '<label><input type="radio" name="autoenroll_run"'.
1.14 raeburn 3844: $runoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.3 raeburn 3845: '</tr><tr>'.
3846: '<td>'.&mt('Notification messages - sender').
1.8 raeburn 3847: '</td><td class="LC_right_item"><span class="LC_nobreak">'.
1.3 raeburn 3848: &mt('username').': '.
3849: '<input type="text" name="sender_uname" value="'.
1.39 raeburn 3850: $notif_sender.'" size="10" /> '.&mt('domain').
1.129 raeburn 3851: ': '.$domform.'</span></td></tr>'.
3852: '<tr class="LC_odd_row">'.
3853: '<td>'.&mt('Automatically assign co-ownership').'</td>'.
3854: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3855: '<input type="radio" name="autoassign_coowners"'.
3856: $coownerson.' value="1" />'.&mt('Yes').'</label> '.
3857: '<label><input type="radio" name="autoassign_coowners"'.
3858: $coownersoff.' value="0" />'.&mt('No').'</label></span></td>'.
1.160.6.68 raeburn 3859: '</tr><tr>'.
3860: '<td>'.&mt('Failsafe for no drops when institutional data missing').'</td>'.
1.160.6.116 raeburn 3861: '<td class="LC_left_item"><span class="LC_nobreak">'.
3862: '<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> '.
3863: '<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 />'.
3864: '<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>'.
3865: '<div class="LC_floatleft" style="display:'.$failsafesty.';" id="autoenroll_failsafe_div">'.
3866: '<span class="LC_nobreak">'.
3867: &mt('Threshold for number of students in section to drop: [_1]',
3868: '<input type="text" name="autoenroll_autofailsafe" value="'.$autofailsafe.'" size="4" />').
3869: '</span></div></td></tr>';
1.160.6.68 raeburn 3870: $$rowtotal += 4;
1.3 raeburn 3871: return $datatable;
3872: }
3873:
3874: sub print_autoupdate {
1.30 raeburn 3875: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.113 raeburn 3876: my ($enable,$datatable);
1.3 raeburn 3877: if ($position eq 'top') {
1.160.6.113 raeburn 3878: my %choices = &Apache::lonlocal::texthash (
3879: run => 'Auto-update active?',
3880: classlists => 'Update information in classlists?',
3881: unexpired => 'Skip updates for users without active or future roles?',
3882: lastactive => 'Skip updates for inactive users?',
3883: );
3884: my $itemcount = 0;
1.3 raeburn 3885: my $updateon = ' ';
3886: my $updateoff = ' checked="checked" ';
3887: if (ref($settings) eq 'HASH') {
3888: if ($settings->{'run'} eq '1') {
3889: $updateon = $updateoff;
3890: $updateoff = ' ';
3891: }
3892: }
1.160.6.118.2 14(raebu 3893:23): $enable = '<tr class="LC_odd_row">'.
3894:23): '<td>'.$choices{'run'}.'</td>'.
1.160.6.113 raeburn 3895: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
1.3 raeburn 3896: '<input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3897: $updateoff.'value="0" />'.&mt('No').'</label> '.
1.8 raeburn 3898: '<label><input type="radio" name="autoupdate_run"'.
1.160.6.113 raeburn 3899: $updateon.'value="1" />'.&mt('Yes').'</label></span></td>'.
1.3 raeburn 3900: '</tr>';
1.160.6.113 raeburn 3901: my @toggles = ('classlists','unexpired');
3902: my %defaultchecked = ('classlists' => 'off',
3903: 'unexpired' => 'off'
3904: );
3905: $$rowtotal ++;
3906: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
3907: \%choices,$itemcount,'','','left','no');
3908: $datatable = $enable.$datatable;
3909: $$rowtotal += $itemcount;
3910: my $lastactiveon = ' ';
3911: my $lastactiveoff = ' checked="checked" ';
3912: my $lastactivestyle = 'none';
3913: my $lastactivedays;
3914: my $onclick = ' onclick="javascript:toggleLastActiveDays(this.form);"';
3915: if (ref($settings) eq 'HASH') {
3916: if ($settings->{'lastactive'} =~ /^\d+$/) {
3917: $lastactiveon = $lastactiveoff;
3918: $lastactiveoff = ' ';
3919: $lastactivestyle = 'inline-block';
3920: $lastactivedays = $settings->{'lastactive'};
3921: }
3922: }
3923: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
3924: $datatable .= '<tr'.$css_class.'>'.
3925: '<td>'.$choices{'lastactive'}.'</td>'.
3926: '<td class="LC_left_item"><span class="LC_nobreak"><label>'.
3927: '<input type="radio" name="lastactive"'.
3928: $lastactiveoff.'value="0"'.$onclick.' />'.&mt('No').'</label>'.
3929: ' <label>'.
3930: '<input type="radio" name="lastactive"'.
3931: $lastactiveon.' value="1"'.$onclick.' />'.&mt('Yes').'</label>'.
3932: '<div id="lastactive_div" style="display:'.$lastactivestyle.';">'.
3933: ': '.&mt('inactive = no activity in last [_1] days',
3934: '<input type="text" size="5" name="lastactivedays" value="'.
3935: $lastactivedays.'" />').
3936: '</span></td>'.
3937: '</tr>';
3938: $$rowtotal ++;
1.131 raeburn 3939: } elsif ($position eq 'middle') {
3940: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
3941: my $numinrow = 3;
3942: my $locknamesettings;
3943: $datatable .= &insttypes_row($settings,$types,$usertypes,
3944: $dom,$numinrow,$othertitle,
1.160.6.93 raeburn 3945: 'lockablenames',$rowtotal);
1.131 raeburn 3946: $$rowtotal ++;
1.3 raeburn 3947: } else {
1.44 raeburn 3948: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.132 raeburn 3949: my @fields = ('lastname','firstname','middlename','generation',
1.20 raeburn 3950: 'permanentemail','id');
1.33 raeburn 3951: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
1.3 raeburn 3952: my $numrows = 0;
1.26 raeburn 3953: if (ref($types) eq 'ARRAY') {
3954: if (@{$types} > 0) {
3955: $datatable =
3956: &usertype_update_row($settings,$usertypes,\%fieldtitles,
3957: \@fields,$types,\$numrows);
1.30 raeburn 3958: $$rowtotal += @{$types};
1.26 raeburn 3959: }
1.3 raeburn 3960: }
3961: $datatable .=
3962: &usertype_update_row($settings,{'default' => $othertitle},
3963: \%fieldtitles,\@fields,['default'],
3964: \$numrows);
1.30 raeburn 3965: $$rowtotal ++;
1.3 raeburn 3966: }
3967: return $datatable;
3968: }
3969:
1.125 raeburn 3970: sub print_autocreate {
3971: my ($dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 3972: my (%createon,%createoff,%currhash);
1.125 raeburn 3973: my @types = ('xml','req');
3974: if (ref($settings) eq 'HASH') {
3975: foreach my $item (@types) {
3976: $createoff{$item} = ' checked="checked" ';
3977: $createon{$item} = ' ';
3978: if (exists($settings->{$item})) {
3979: if ($settings->{$item}) {
3980: $createon{$item} = ' checked="checked" ';
3981: $createoff{$item} = ' ';
3982: }
3983: }
3984: }
1.160.6.16 raeburn 3985: if ($settings->{'xmldc'} ne '') {
3986: $currhash{$settings->{'xmldc'}} = 1;
3987: }
1.125 raeburn 3988: } else {
3989: foreach my $item (@types) {
3990: $createoff{$item} = ' checked="checked" ';
3991: $createon{$item} = ' ';
3992: }
3993: }
3994: $$rowtotal += 2;
1.160.6.16 raeburn 3995: my $numinrow = 2;
1.125 raeburn 3996: my $datatable='<tr class="LC_odd_row">'.
3997: '<td>'.&mt('Create pending official courses from XML files').'</td>'.
3998: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
3999: '<input type="radio" name="autocreate_xml"'.
4000: $createon{'xml'}.' value="1" />'.&mt('Yes').'</label> '.
4001: '<label><input type="radio" name="autocreate_xml"'.
1.143 raeburn 4002: $createoff{'xml'}.' value="0" />'.&mt('No').'</label></span>'.
4003: '</td></tr><tr>'.
4004: '<td>'.&mt('Create pending requests for official courses (if validated)').'</td>'.
4005: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4006: '<input type="radio" name="autocreate_req"'.
4007: $createon{'req'}.' value="1" />'.&mt('Yes').'</label> '.
4008: '<label><input type="radio" name="autocreate_req"'.
4009: $createoff{'req'}.' value="0" />'.&mt('No').'</label></span>';
1.160.6.16 raeburn 4010: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
4011: 'autocreate_xmldc',%currhash);
1.160.6.50 raeburn 4012: $datatable .= '</td></tr><tr class="LC_odd_row"><td>';
1.125 raeburn 4013: if ($numdc > 1) {
1.160.6.50 raeburn 4014: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)').
4015: '</td><td class="LC_left_item">';
1.125 raeburn 4016: } else {
1.160.6.50 raeburn 4017: $datatable .= &mt('Course creation processed as:').
4018: '</td><td class="LC_right_item">';
1.125 raeburn 4019: }
1.160.6.50 raeburn 4020: $datatable .= $dctable.'</td></tr>';
1.160.6.16 raeburn 4021: $$rowtotal += $rows;
1.125 raeburn 4022: return $datatable;
4023: }
4024:
1.23 raeburn 4025: sub print_directorysrch {
1.160.6.72 raeburn 4026: my ($position,$dom,$settings,$rowtotal) = @_;
4027: my $datatable;
4028: if ($position eq 'top') {
4029: my $instsrchon = ' ';
4030: my $instsrchoff = ' checked="checked" ';
4031: my ($exacton,$containson,$beginson);
4032: my $instlocalon = ' ';
4033: my $instlocaloff = ' checked="checked" ';
4034: if (ref($settings) eq 'HASH') {
4035: if ($settings->{'available'} eq '1') {
4036: $instsrchon = $instsrchoff;
4037: $instsrchoff = ' ';
4038: }
4039: if ($settings->{'localonly'} eq '1') {
4040: $instlocalon = $instlocaloff;
4041: $instlocaloff = ' ';
4042: }
4043: if (ref($settings->{'searchtypes'}) eq 'ARRAY') {
4044: foreach my $type (@{$settings->{'searchtypes'}}) {
4045: if ($type eq 'exact') {
4046: $exacton = ' checked="checked" ';
4047: } elsif ($type eq 'contains') {
4048: $containson = ' checked="checked" ';
4049: } elsif ($type eq 'begins') {
4050: $beginson = ' checked="checked" ';
4051: }
4052: }
4053: } else {
4054: if ($settings->{'searchtypes'} eq 'exact') {
4055: $exacton = ' checked="checked" ';
4056: } elsif ($settings->{'searchtypes'} eq 'contains') {
4057: $containson = ' checked="checked" ';
4058: } elsif ($settings->{'searchtypes'} eq 'specify') {
1.25 raeburn 4059: $exacton = ' checked="checked" ';
4060: $containson = ' checked="checked" ';
4061: }
4062: }
1.23 raeburn 4063: }
1.160.6.72 raeburn 4064: my ($searchtitles,$titleorder) = &sorted_searchtitles();
4065: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.23 raeburn 4066:
1.160.6.72 raeburn 4067: my $numinrow = 4;
4068: my $cansrchrow = 0;
4069: $datatable='<tr class="LC_odd_row">'.
4070: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Institutional directory search available?').'</span></td>'.
4071: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4072: '<input type="radio" name="dirsrch_available"'.
4073: $instsrchon.' value="1" />'.&mt('Yes').'</label> '.
4074: '<label><input type="radio" name="dirsrch_available"'.
4075: $instsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4076: '</tr><tr>'.
4077: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search institution?').'</span></td>'.
4078: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4079: '<input type="radio" name="dirsrch_instlocalonly"'.
4080: $instlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4081: '<label><input type="radio" name="dirsrch_instlocalonly"'.
4082: $instlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4083: '</tr>';
4084: $$rowtotal += 2;
4085: if (ref($usertypes) eq 'HASH') {
4086: if (keys(%{$usertypes}) > 0) {
4087: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
1.160.6.93 raeburn 4088: $numinrow,$othertitle,'cansearch',
4089: $rowtotal);
1.160.6.72 raeburn 4090: $cansrchrow = 1;
4091: }
1.26 raeburn 4092: }
1.160.6.72 raeburn 4093: if ($cansrchrow) {
4094: $$rowtotal ++;
4095: $datatable .= '<tr>';
4096: } else {
4097: $datatable .= '<tr class="LC_odd_row">';
4098: }
4099: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Supported search methods').
4100: '</span></td><td class="LC_left_item" colspan="2"><table><tr>';
4101: foreach my $title (@{$titleorder}) {
4102: if (defined($searchtitles->{$title})) {
4103: my $check = ' ';
4104: if (ref($settings) eq 'HASH') {
4105: if (ref($settings->{'searchby'}) eq 'ARRAY') {
4106: if (grep(/^\Q$title\E$/,@{$settings->{'searchby'}})) {
4107: $check = ' checked="checked" ';
4108: }
1.39 raeburn 4109: }
1.25 raeburn 4110: }
1.160.6.72 raeburn 4111: $datatable .= '<td class="LC_left_item">'.
4112: '<span class="LC_nobreak"><label>'.
4113: '<input type="checkbox" name="searchby" '.
4114: 'value="'.$title.'"'.$check.'/>'.
4115: $searchtitles->{$title}.'</label></span></td>';
1.25 raeburn 4116: }
4117: }
1.160.6.72 raeburn 4118: $datatable .= '</tr></table></td></tr>';
4119: $$rowtotal ++;
4120: if ($cansrchrow) {
4121: $datatable .= '<tr class="LC_odd_row">';
4122: } else {
4123: $datatable .= '<tr>';
4124: }
4125: $datatable .= '<td><span class ="LC_nobreak">'.&mt('Search latitude').'</span></td>'.
4126: '<td class="LC_left_item" colspan="2">'.
4127: '<span class="LC_nobreak"><label>'.
4128: '<input type="checkbox" name="searchtypes" '.
4129: $exacton.' value="exact" />'.&mt('Exact match').
4130: '</label> '.
4131: '<label><input type="checkbox" name="searchtypes" '.
4132: $beginson.' value="begins" />'.&mt('Begins with').
4133: '</label> '.
4134: '<label><input type="checkbox" name="searchtypes" '.
4135: $containson.' value="contains" />'.&mt('Contains').
4136: '</label></span></td></tr>';
4137: $$rowtotal ++;
1.26 raeburn 4138: } else {
1.160.6.72 raeburn 4139: my $domsrchon = ' checked="checked" ';
4140: my $domsrchoff = ' ';
4141: my $domlocalon = ' ';
4142: my $domlocaloff = ' checked="checked" ';
4143: if (ref($settings) eq 'HASH') {
4144: if ($settings->{'lclocalonly'} eq '1') {
4145: $domlocalon = $domlocaloff;
4146: $domlocaloff = ' ';
4147: }
4148: if ($settings->{'lcavailable'} eq '0') {
4149: $domsrchoff = $domsrchon;
4150: $domsrchon = ' ';
4151: }
4152: }
4153: $datatable='<tr class="LC_odd_row">'.
4154: '<td colspan="2"><span class ="LC_nobreak">'.&mt('LON-CAPA directory search available?').'</span></td>'.
4155: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4156: '<input type="radio" name="dirsrch_domavailable"'.
4157: $domsrchon.' value="1" />'.&mt('Yes').'</label> '.
4158: '<label><input type="radio" name="dirsrch_domavailable"'.
4159: $domsrchoff.' value="0" />'.&mt('No').'</label></span></td>'.
4160: '</tr><tr>'.
4161: '<td colspan="2"><span class ="LC_nobreak">'.&mt('Other domains can search LON-CAPA domain?').'</span></td>'.
4162: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
4163: '<input type="radio" name="dirsrch_domlocalonly"'.
4164: $domlocaloff.' value="0" />'.&mt('Yes').'</label> '.
4165: '<label><input type="radio" name="dirsrch_domlocalonly"'.
4166: $domlocalon.' value="1" />'.&mt('No').'</label></span></td>'.
4167: '</tr>';
4168: $$rowtotal += 2;
1.26 raeburn 4169: }
1.25 raeburn 4170: return $datatable;
4171: }
4172:
1.28 raeburn 4173: sub print_contacts {
1.160.6.78 raeburn 4174: my ($position,$dom,$settings,$rowtotal) = @_;
1.28 raeburn 4175: my $datatable;
4176: my @contacts = ('adminemail','supportemail');
1.160.6.78 raeburn 4177: my (%checked,%to,%otheremails,%bccemails,%includestr,%includeloc,%currfield,
1.160.6.107 raeburn 4178: $maxsize,$fields,$fieldtitles,$fieldoptions,$possoptions,@mailings,%lonstatus);
1.160.6.78 raeburn 4179: if ($position eq 'top') {
4180: if (ref($settings) eq 'HASH') {
4181: foreach my $item (@contacts) {
4182: if (exists($settings->{$item})) {
4183: $to{$item} = $settings->{$item};
4184: }
1.28 raeburn 4185: }
4186: }
1.160.6.78 raeburn 4187: } elsif ($position eq 'middle') {
4188: @mailings = ('errormail','packagesmail','lonstatusmail','requestsmail',
1.160.6.91 raeburn 4189: 'updatesmail','idconflictsmail','hostipmail');
1.28 raeburn 4190: foreach my $type (@mailings) {
1.160.6.78 raeburn 4191: $otheremails{$type} = '';
4192: }
1.160.6.107 raeburn 4193: } elsif ($position eq 'lower') {
4194: if (ref($settings) eq 'HASH') {
4195: if (ref($settings->{'lonstatus'}) eq 'HASH') {
4196: %lonstatus = %{$settings->{'lonstatus'}};
4197: }
4198: }
1.160.6.78 raeburn 4199: } else {
4200: @mailings = ('helpdeskmail','otherdomsmail');
4201: foreach my $type (@mailings) {
4202: $otheremails{$type} = '';
4203: }
4204: $bccemails{'helpdeskmail'} = '';
4205: $bccemails{'otherdomsmail'} = '';
4206: $includestr{'helpdeskmail'} = '';
4207: $includestr{'otherdomsmail'} = '';
4208: ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
4209: }
4210: if (ref($settings) eq 'HASH') {
1.160.6.107 raeburn 4211: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4212: foreach my $type (@mailings) {
4213: if (exists($settings->{$type})) {
4214: if (ref($settings->{$type}) eq 'HASH') {
4215: foreach my $item (@contacts) {
4216: if ($settings->{$type}{$item}) {
4217: $checked{$type}{$item} = ' checked="checked" ';
4218: }
1.28 raeburn 4219: }
1.160.6.78 raeburn 4220: $otheremails{$type} = $settings->{$type}{'others'};
4221: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4222: $bccemails{$type} = $settings->{$type}{'bcc'};
4223: if ($settings->{$type}{'include'} ne '') {
4224: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4225: $includestr{$type} = &unescape($includestr{$type});
4226: }
4227: }
4228: }
4229: } elsif ($type eq 'lonstatusmail') {
4230: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4231: }
4232: }
4233: }
4234: if ($position eq 'bottom') {
4235: foreach my $type (@mailings) {
4236: $bccemails{$type} = $settings->{$type}{'bcc'};
4237: if ($settings->{$type}{'include'} ne '') {
4238: ($includeloc{$type},$includestr{$type}) = split(/:/,$settings->{$type}{'include'},2);
4239: $includestr{$type} = &unescape($includestr{$type});
4240: }
4241: }
4242: if (ref($settings->{'helpform'}) eq 'HASH') {
4243: if (ref($fields) eq 'ARRAY') {
4244: foreach my $field (@{$fields}) {
4245: $currfield{$field} = $settings->{'helpform'}{$field};
1.28 raeburn 4246: }
1.160.6.78 raeburn 4247: }
4248: if (exists($settings->{'helpform'}{'maxsize'})) {
4249: $maxsize = $settings->{'helpform'}{'maxsize'};
4250: } else {
4251: $maxsize = '1.0';
4252: }
4253: } else {
4254: if (ref($fields) eq 'ARRAY') {
4255: foreach my $field (@{$fields}) {
4256: $currfield{$field} = 'yes';
1.134 raeburn 4257: }
1.28 raeburn 4258: }
1.160.6.78 raeburn 4259: $maxsize = '1.0';
1.28 raeburn 4260: }
4261: }
4262: } else {
1.160.6.78 raeburn 4263: if ($position eq 'top') {
4264: $to{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
4265: $to{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
4266: $checked{'errormail'}{'adminemail'} = ' checked="checked" ';
4267: $checked{'packagesmail'}{'adminemail'} = ' checked="checked" ';
4268: $checked{'lonstatusmail'}{'adminemail'} = ' checked="checked" ';
4269: $checked{'requestsmail'}{'adminemail'} = ' checked="checked" ';
4270: $checked{'updatesmail'}{'adminemail'} = ' checked="checked" ';
4271: $checked{'idconflictsmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.91 raeburn 4272: $checked{'hostipmail'}{'adminemail'} = ' checked="checked" ';
1.160.6.78 raeburn 4273: } elsif ($position eq 'bottom') {
4274: $checked{'helpdeskmail'}{'supportemail'} = ' checked="checked" ';
4275: $checked{'otherdomsmail'}{'supportemail'} = ' checked="checked" ';
4276: if (ref($fields) eq 'ARRAY') {
4277: foreach my $field (@{$fields}) {
4278: $currfield{$field} = 'yes';
4279: }
4280: }
4281: $maxsize = '1.0';
4282: }
1.28 raeburn 4283: }
4284: my ($titles,$short_titles) = &contact_titles();
4285: my $rownum = 0;
4286: my $css_class;
1.160.6.78 raeburn 4287: if ($position eq 'top') {
4288: foreach my $item (@contacts) {
4289: $css_class = $rownum%2?' class="LC_odd_row"':'';
4290: $datatable .= '<tr'.$css_class.'>'.
4291: '<td><span class="LC_nobreak">'.$titles->{$item}.
4292: '</span></td><td class="LC_right_item">'.
4293: '<input type="text" name="'.$item.'" value="'.
4294: $to{$item}.'" /></td></tr>';
4295: $rownum ++;
4296: }
1.160.6.101 raeburn 4297: } elsif ($position eq 'bottom') {
4298: $css_class = $rownum%2?' class="LC_odd_row"':'';
4299: $datatable .= '<tr'.$css_class.'>'.
4300: '<td>'.&mt('Extra helpdesk form fields:').'<br />'.
4301: &mt('(e-mail, subject, and description always shown)').
4302: '</td><td class="LC_left_item">';
4303: if ((ref($fields) eq 'ARRAY') && (ref($fieldtitles) eq 'HASH') &&
4304: (ref($fieldoptions) eq 'HASH') && (ref($possoptions) eq 'HASH')) {
4305: $datatable .= '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Status').'</th></tr>';
4306: foreach my $field (@{$fields}) {
4307: $datatable .= '<tr><td>'.$fieldtitles->{$field};
4308: if (($field eq 'screenshot') || ($field eq 'cc')) {
4309: $datatable .= ' '.&mt('(logged-in users)');
4310: }
4311: $datatable .='</td><td>';
4312: my $clickaction;
4313: if ($field eq 'screenshot') {
4314: $clickaction = ' onclick="screenshotSize(this);"';
4315: }
4316: if (ref($possoptions->{$field}) eq 'ARRAY') {
4317: foreach my $option (@{$possoptions->{$field}}) {
4318: my $checked;
4319: if ($currfield{$field} eq $option) {
4320: $checked = ' checked="checked"';
4321: }
4322: $datatable .= '<span class="LC_nobreak"><label>'.
4323: '<input type="radio" name="helpform_'.$field.'" '.
4324: 'value="'.$option.'"'.$checked.$clickaction.' />'.$fieldoptions->{$option}.
4325: '</label></span>'.(' 'x2);
4326: }
4327: }
4328: if ($field eq 'screenshot') {
4329: my $display;
4330: if ($currfield{$field} eq 'no') {
4331: $display = ' style="display:none"';
4332: }
4333: $datatable .= '</td></tr><tr id="help_screenshotsize"'.$display.'>'.
4334: '<td>'.&mt('Maximum size for upload (MB)').'</td><td>'.
4335: '<input type="text" size="5" name="helpform_maxsize" value="'.$maxsize.'" />';
4336: }
4337: $datatable .= '</td></tr>';
4338: }
4339: $datatable .= '</table>';
4340: }
4341: $datatable .= '</td></tr>'."\n";
4342: $rownum ++;
4343: }
1.160.6.107 raeburn 4344: unless (($position eq 'top') || ($position eq 'lower')) {
1.160.6.78 raeburn 4345: foreach my $type (@mailings) {
4346: $css_class = $rownum%2?' class="LC_odd_row"':'';
4347: $datatable .= '<tr'.$css_class.'>'.
4348: '<td><span class="LC_nobreak">'.
4349: $titles->{$type}.': </span></td>'.
4350: '<td class="LC_left_item">';
4351: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4352: $datatable .= '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>';
4353: }
4354: $datatable .= '<span class="LC_nobreak">';
4355: foreach my $item (@contacts) {
4356: $datatable .= '<label>'.
4357: '<input type="checkbox" name="'.$type.'"'.
4358: $checked{$type}{$item}.
4359: ' value="'.$item.'" />'.$short_titles->{$item}.
4360: '</label> ';
4361: }
4362: $datatable .= '</span><br />'.&mt('Others').': '.
4363: '<input type="text" name="'.$type.'_others" '.
4364: 'value="'.$otheremails{$type}.'" />';
4365: my %locchecked;
4366: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
4367: foreach my $loc ('s','b') {
4368: if ($includeloc{$type} eq $loc) {
4369: $locchecked{$loc} = ' checked="checked"';
4370: last;
4371: }
4372: }
4373: $datatable .= '<br />'.&mt('Bcc:').(' 'x6).
4374: '<input type="text" name="'.$type.'_bcc" '.
4375: 'value="'.$bccemails{$type}.'" /></fieldset>'.
4376: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4377: &mt('Text automatically added to e-mail:').' '.
1.160.6.87 raeburn 4378: '<input type="text" name="'.$type.'_includestr" value="'.$includestr{$type}.'" /><br />'.
1.160.6.78 raeburn 4379: '<span class="LC_nobreak">'.&mt('Location:').' '.
4380: '<label><input type="radio" name="'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4381: (' 'x2).
4382: '<label><input type="radio" name="'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4383: '</span></fieldset>';
4384: }
4385: $datatable .= '</td></tr>'."\n";
4386: $rownum ++;
4387: }
1.28 raeburn 4388: }
1.160.6.78 raeburn 4389: if ($position eq 'middle') {
4390: my %choices;
1.160.6.107 raeburn 4391: my $corelink = &core_link_msu();
4392: $choices{'reporterrors'} = &mt('E-mail error reports to [_1]',$corelink);
1.160.6.78 raeburn 4393: $choices{'reportupdates'} = &mt('E-mail record of completed LON-CAPA updates to [_1]',
1.160.6.107 raeburn 4394: $corelink);
4395: $choices{'reportstatus'} = &mt('E-mail status if errors above threshold to [_1]',$corelink);
4396: my @toggles = ('reporterrors','reportupdates','reportstatus');
1.160.6.78 raeburn 4397: my %defaultchecked = ('reporterrors' => 'on',
1.160.6.107 raeburn 4398: 'reportupdates' => 'on',
4399: 'reportstatus' => 'on');
1.160.6.78 raeburn 4400: (my $reports,$rownum) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4401: \%choices,$rownum);
4402: $datatable .= $reports;
1.160.6.107 raeburn 4403: } elsif ($position eq 'lower') {
1.160.6.109 raeburn 4404: my (%current,%excluded,%weights);
1.160.6.107 raeburn 4405: my ($defaults,$names) = &Apache::loncommon::lon_status_items();
4406: if ($lonstatus{'threshold'} =~ /^\d+$/) {
1.160.6.109 raeburn 4407: $current{'errorthreshold'} = $lonstatus{'threshold'};
1.160.6.107 raeburn 4408: } else {
1.160.6.109 raeburn 4409: $current{'errorthreshold'} = $defaults->{'threshold'};
1.160.6.107 raeburn 4410: }
4411: if ($lonstatus{'sysmail'} =~ /^\d+$/) {
1.160.6.109 raeburn 4412: $current{'errorsysmail'} = $lonstatus{'sysmail'};
1.160.6.107 raeburn 4413: } else {
1.160.6.109 raeburn 4414: $current{'errorsysmail'} = $defaults->{'sysmail'};
1.160.6.107 raeburn 4415: }
4416: if (ref($lonstatus{'weights'}) eq 'HASH') {
4417: foreach my $type ('E','W','N','U') {
4418: if ($lonstatus{'weights'}{$type} =~ /^\d+$/) {
4419: $weights{$type} = $lonstatus{'weights'}{$type};
4420: } else {
4421: $weights{$type} = $defaults->{$type};
4422: }
4423: }
4424: } else {
4425: foreach my $type ('E','W','N','U') {
4426: $weights{$type} = $defaults->{$type};
4427: }
4428: }
4429: if (ref($lonstatus{'excluded'}) eq 'ARRAY') {
4430: if (@{$lonstatus{'excluded'}} > 0) {
4431: map {$excluded{$_} = 1; } @{$lonstatus{'excluded'}};
4432: }
4433: }
1.160.6.109 raeburn 4434: foreach my $item ('errorthreshold','errorsysmail') {
4435: $css_class = $rownum%2?' class="LC_odd_row"':'';
4436: $datatable .= '<tr'.$css_class.'>'.
4437: '<td class="LC_left_item"><span class="LC_nobreak">'.
4438: $titles->{$item}.
4439: '</span></td><td class="LC_left_item">'.
4440: '<input type="text" name="'.$item.'" value="'.
4441: $current{$item}.'" size="5" /></td></tr>';
4442: $rownum ++;
4443: }
1.160.6.107 raeburn 4444: $css_class = $rownum%2?' class="LC_odd_row"':'';
4445: $datatable .= '<tr'.$css_class.'>'.
4446: '<td class="LC_left_item">'.
4447: '<span class="LC_nobreak">'.$titles->{'errorweights'}.
4448: '</span></td><td class="LC_left_item"><table><tr>';
4449: foreach my $type ('E','W','N','U') {
4450: $datatable .= '<td>'.$names->{$type}.'<br />'.
4451: '<input type="text" name="errorweights_'.$type.'" value="'.
4452: $weights{$type}.'" size="5" /></td>';
4453: }
4454: $datatable .= '</tr></table></tr>';
4455: $rownum ++;
4456: $css_class = $rownum%2?' class="LC_odd_row"':'';
4457: $datatable .= '<tr'.$css_class.'><td class="LC_left_item">'.
4458: $titles->{'errorexcluded'}.'</td>'.
4459: '<td class="LC_left_item"><table>';
4460: my $numinrow = 4;
4461: my @ids = sort(values(%Apache::lonnet::serverhomeIDs));
4462: for (my $i=0; $i<@ids; $i++) {
4463: my $rem = $i%($numinrow);
4464: if ($rem == 0) {
4465: if ($i > 0) {
4466: $datatable .= '</tr>';
4467: }
4468: $datatable .= '<tr>';
4469: }
4470: my $check;
4471: if ($excluded{$ids[$i]}) {
4472: $check = ' checked="checked" ';
4473: }
4474: $datatable .= '<td class="LC_left_item">'.
4475: '<span class="LC_nobreak"><label>'.
4476: '<input type="checkbox" name="errorexcluded" '.
4477: 'value="'.$ids[$i].'"'.$check.' />'.
4478: $ids[$i].'</label></span></td>';
4479: }
4480: my $colsleft = $numinrow - @ids%($numinrow);
4481: if ($colsleft > 1 ) {
4482: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
4483: ' </td>';
4484: } elsif ($colsleft == 1) {
4485: $datatable .= '<td class="LC_left_item"> </td>';
4486: }
4487: $datatable .= '</tr></table></td></tr>';
4488: $rownum ++;
1.160.6.78 raeburn 4489: } elsif ($position eq 'bottom') {
1.160.6.101 raeburn 4490: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
4491: my (@posstypes,%usertypeshash);
4492: if (ref($types) eq 'ARRAY') {
4493: @posstypes = @{$types};
4494: }
4495: if (@posstypes) {
4496: if (ref($usertypes) eq 'HASH') {
4497: %usertypeshash = %{$usertypes};
4498: }
4499: my @overridden;
4500: my $numinrow = 4;
4501: if (ref($settings) eq 'HASH') {
4502: if (ref($settings->{'overrides'}) eq 'HASH') {
4503: foreach my $key (sort(keys(%{$settings->{'overrides'}}))) {
4504: if (ref($settings->{'overrides'}{$key}) eq 'HASH') {
4505: push(@overridden,$key);
4506: foreach my $item (@contacts) {
4507: if ($settings->{'overrides'}{$key}{$item}) {
4508: $checked{'override_'.$key}{$item} = ' checked="checked" ';
4509: }
4510: }
4511: $otheremails{'override_'.$key} = $settings->{'overrides'}{$key}{'others'};
4512: $bccemails{'override_'.$key} = $settings->{'overrides'}{$key}{'bcc'};
4513: $includeloc{'override_'.$key} = '';
4514: $includestr{'override_'.$key} = '';
4515: if ($settings->{'overrides'}{$key}{'include'} ne '') {
4516: ($includeloc{'override_'.$key},$includestr{'override_'.$key}) =
4517: split(/:/,$settings->{'overrides'}{$key}{'include'},2);
4518: $includestr{'override_'.$key} = &unescape($includestr{'override_'.$key});
4519: }
1.160.6.78 raeburn 4520: }
4521: }
4522: }
1.160.6.101 raeburn 4523: }
4524: my $customclass = 'LC_helpdesk_override';
4525: my $optionsprefix = 'LC_options_helpdesk_';
4526:
4527: my $onclicktypes = "toggleHelpdeskRow(this.form,'overrides','$customclass','$optionsprefix');";
4528: $datatable .= &insttypes_row($settings,$types,$usertypes,$dom,
4529: $numinrow,$othertitle,'overrides',
4530: \$rownum,$onclicktypes,$customclass);
4531: $rownum ++;
4532: $usertypeshash{'default'} = $othertitle;
4533: foreach my $status (@posstypes) {
4534: my $css_class;
4535: if ($rownum%2) {
4536: $css_class = 'LC_odd_row ';
4537: }
4538: $css_class .= $customclass;
4539: my $rowid = $optionsprefix.$status;
4540: my $hidden = 1;
4541: my $currstyle = 'display:none';
4542: if (grep(/^\Q$status\E$/,@overridden)) {
4543: $currstyle = 'display:table-row';
4544: $hidden = 0;
4545: }
4546: my $key = 'override_'.$status;
4547: $datatable .= &overridden_helpdesk($checked{$key},$otheremails{$key},$bccemails{$key},
4548: $includeloc{$key},$includestr{$key},$status,$rowid,
4549: $usertypeshash{$status},$css_class,$currstyle,
4550: \@contacts,$short_titles);
4551: unless ($hidden) {
4552: $rownum ++;
1.160.6.78 raeburn 4553: }
4554: }
1.134 raeburn 4555: }
1.28 raeburn 4556: }
1.30 raeburn 4557: $$rowtotal += $rownum;
1.28 raeburn 4558: return $datatable;
4559: }
4560:
1.160.6.107 raeburn 4561: sub core_link_msu {
4562: return &Apache::loncommon::modal_link('http://loncapa.org/core.html',
4563: &mt('LON-CAPA core group - MSU'),600,500);
4564: }
4565:
1.160.6.101 raeburn 4566: sub overridden_helpdesk {
4567: my ($checked,$otheremails,$bccemails,$includeloc,$includestr,$type,$rowid,
4568: $typetitle,$css_class,$rowstyle,$contacts,$short_titles) = @_;
4569: my $class = 'LC_left_item';
4570: if ($css_class) {
4571: $css_class = ' class="'.$css_class.'"';
4572: }
4573: if ($rowid) {
4574: $rowid = ' id="'.$rowid.'"';
4575: }
4576: if ($rowstyle) {
4577: $rowstyle = ' style="'.$rowstyle.'"';
4578: }
4579: my ($output,$description);
4580: $description = &mt('Helpdesk requests from: [_1] in this domain (overrides default)',"<b>$typetitle</b>");
4581: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
4582: "<td>$description</td>\n".
4583: '<td class="'.$class.'" colspan="2">'.
4584: '<fieldset><legend>'.&mt('E-mail recipient(s)').'</legend>'.
4585: '<span class="LC_nobreak">';
4586: if (ref($contacts) eq 'ARRAY') {
4587: foreach my $item (@{$contacts}) {
4588: my $check;
4589: if (ref($checked) eq 'HASH') {
4590: $check = $checked->{$item};
4591: }
4592: my $title;
4593: if (ref($short_titles) eq 'HASH') {
4594: $title = $short_titles->{$item};
4595: }
4596: $output .= '<label>'.
4597: '<input type="checkbox" name="override_'.$type.'"'.$check.
4598: ' value="'.$item.'" />'.$title.'</label> ';
4599: }
4600: }
4601: $output .= '</span><br />'.&mt('Others').': '.
4602: '<input type="text" name="override_'.$type.'_others" '.
4603: 'value="'.$otheremails.'" />';
4604: my %locchecked;
4605: foreach my $loc ('s','b') {
4606: if ($includeloc eq $loc) {
4607: $locchecked{$loc} = ' checked="checked"';
4608: last;
4609: }
4610: }
4611: $output .= '<br />'.&mt('Bcc:').(' 'x6).
4612: '<input type="text" name="override_'.$type.'_bcc" '.
4613: 'value="'.$bccemails.'" /></fieldset>'.
4614: '<fieldset><legend>'.&mt('Optional added text').'</legend>'.
4615: &mt('Text automatically added to e-mail:').' '.
4616: '<input type="text" name="override_'.$type.'_includestr" value="'.$includestr.'" /><br />'.
4617: '<span class="LC_nobreak">'.&mt('Location:').' '.
4618: '<label><input type="radio" name="override_'.$type.'_includeloc" value="s"'.$locchecked{'s'}.' />'.&mt('in subject').'</label>'.
4619: (' 'x2).
4620: '<label><input type="radio" name="override_'.$type.'_includeloc" value="b"'.$locchecked{'b'}.' />'.&mt('in body').'</label>'.
4621: '</span></fieldset>'.
4622: '</td></tr>'."\n";
4623: return $output;
4624: }
4625:
1.160.6.78 raeburn 4626: sub contacts_javascript {
4627: return <<"ENDSCRIPT";
4628:
4629: <script type="text/javascript">
4630: // <![CDATA[
4631:
4632: function screenshotSize(field) {
4633: if (document.getElementById('help_screenshotsize')) {
4634: if (field.value == 'no') {
4635: document.getElementById('help_screenshotsize').style.display="none";
4636: } else {
4637: document.getElementById('help_screenshotsize').style.display="";
4638: }
4639: }
4640: return;
4641: }
4642:
1.160.6.101 raeburn 4643: function toggleHelpdeskRow(form,checkbox,target,prefix,docount) {
4644: if (form.elements[checkbox].length != undefined) {
4645: var count = 0;
4646: if (docount) {
4647: for (var i=0; i<form.elements[checkbox].length; i++) {
4648: if (form.elements[checkbox][i].checked) {
4649: count ++;
4650: }
4651: }
4652: }
4653: for (var i=0; i<form.elements[checkbox].length; i++) {
4654: var type = form.elements[checkbox][i].value;
4655: if (document.getElementById(prefix+type)) {
4656: if (form.elements[checkbox][i].checked) {
4657: document.getElementById(prefix+type).style.display = 'table-row';
4658: if (count % 2 == 1) {
4659: document.getElementById(prefix+type).className = target+' LC_odd_row';
4660: } else {
4661: document.getElementById(prefix+type).className = target;
4662: }
4663: count ++;
4664: } else {
4665: document.getElementById(prefix+type).style.display = 'none';
4666: }
4667: }
4668: }
4669: }
4670: return;
4671: }
4672:
1.160.6.78 raeburn 4673: // ]]>
4674: </script>
4675:
4676: ENDSCRIPT
4677: }
4678:
1.118 jms 4679: sub print_helpsettings {
1.160.6.73 raeburn 4680: my ($position,$dom,$settings,$rowtotal) = @_;
4681: my $confname = $dom.'-domainconfig';
1.160.6.77 raeburn 4682: my $formname = 'display';
1.160.6.5 raeburn 4683: my ($datatable,$itemcount);
1.160.6.73 raeburn 4684: if ($position eq 'top') {
4685: $itemcount = 1;
4686: my (%choices,%defaultchecked,@toggles);
4687: $choices{'submitbugs'} = &mt('Display link to: [_1]?',
4688: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
4689: &mt('LON-CAPA bug tracker'),600,500));
4690: %defaultchecked = ('submitbugs' => 'on');
4691: @toggles = ('submitbugs');
4692: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
4693: \%choices,$itemcount);
4694: $$rowtotal ++;
4695: } else {
4696: my $css_class;
4697: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 4698: my (%customroles,%ordered,%current);
1.160.6.84 raeburn 4699: if (ref($settings) eq 'HASH') {
4700: if (ref($settings->{'adhoc'}) eq 'HASH') {
4701: %current = %{$settings->{'adhoc'}};
4702: }
1.160.6.77 raeburn 4703: }
4704: my $count = 0;
4705: foreach my $key (sort(keys(%existing))) {
1.160.6.73 raeburn 4706: if ($key=~/^rolesdef\_(\w+)$/) {
4707: my $rolename = $1;
1.160.6.77 raeburn 4708: my (%privs,$order);
1.160.6.73 raeburn 4709: ($privs{'system'},$privs{'domain'},$privs{'course'}) = split(/\_/,$existing{$key});
4710: $customroles{$rolename} = \%privs;
1.160.6.77 raeburn 4711: if (ref($current{$rolename}) eq 'HASH') {
4712: $order = $current{$rolename}{'order'};
4713: }
4714: if ($order eq '') {
4715: $order = $count;
4716: }
4717: $ordered{$order} = $rolename;
4718: $count++;
1.160.6.73 raeburn 4719: }
4720: }
1.160.6.77 raeburn 4721: my $maxnum = scalar(keys(%ordered));
4722: my @roles_by_num = ();
4723: foreach my $item (sort {$a <=> $b } (keys(%ordered))) {
4724: push(@roles_by_num,$item);
4725: }
4726: my $context = 'domprefs';
4727: my $crstype = 'Course';
4728: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 4729: my @accesstypes = ('all','dh','da','none');
1.160.6.77 raeburn 4730: my ($numstatustypes,@jsarray);
4731: if (ref($types) eq 'ARRAY') {
4732: if (@{$types} > 0) {
4733: $numstatustypes = scalar(@{$types});
4734: push(@accesstypes,'status');
4735: @jsarray = ('bystatus');
4736: }
4737: }
1.160.6.86 raeburn 4738: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 4739: if (keys(%domhelpdesk)) {
4740: push(@accesstypes,('inc','exc'));
4741: push(@jsarray,('notinc','notexc'));
4742: }
4743: my $hiddenstr = join("','",@jsarray);
1.160.6.73 raeburn 4744: my $context = 'domprefs';
4745: my $crstype = 'Course';
1.160.6.77 raeburn 4746: my $prefix = 'helproles_';
4747: my $add_class = 'LC_hidden';
4748: foreach my $num (@roles_by_num) {
4749: my $role = $ordered{$num};
4750: my ($desc,$access,@statuses);
4751: if (ref($current{$role}) eq 'HASH') {
4752: $desc = $current{$role}{'desc'};
4753: $access = $current{$role}{'access'};
4754: if (ref($current{$role}{'insttypes'}) eq 'ARRAY') {
4755: @statuses = @{$current{$role}{'insttypes'}};
4756: }
4757: }
4758: if ($desc eq '') {
4759: $desc = $role;
4760: }
4761: my $identifier = 'custhelp'.$num;
1.160.6.73 raeburn 4762: my %full=();
4763: my %levels= (
4764: course => {},
4765: domain => {},
4766: system => {},
4767: );
4768: my %levelscurrent=(
4769: course => {},
4770: domain => {},
4771: system => {},
4772: );
4773: &Apache::lonuserutils::custom_role_privs($customroles{$role},\%full,\%levels,\%levelscurrent);
4774: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
4775: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.77 raeburn 4776: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$num."_pos'".');"';
4777: $datatable .= '<tr '.$css_class.'><td valign="top"><b>'.$role.'</b><br />'.
4778: '<select name="helproles_'.$num.'_pos"'.$chgstr.'>';
4779: for (my $k=0; $k<=$maxnum; $k++) {
4780: my $vpos = $k+1;
4781: my $selstr;
4782: if ($k == $num) {
4783: $selstr = ' selected="selected" ';
4784: }
4785: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4786: }
4787: $datatable .= '</select>'.(' 'x2).
4788: '<input type="hidden" name="helproles_'.$num.'" value="'.$role.'" />'.
4789: '</td>'.
4790: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4791: &mt('Name shown to users:').
4792: '<input type="text" name="helproles_'.$num.'_desc" value="'.$desc.'" />'.
4793: '</fieldset>'.
4794: &helpdeskroles_access($dom,$prefix,$num,$add_class,$current{$role},\@accesstypes,
4795: $othertitle,$usertypes,$types,\%domhelpdesk).
4796: '<fieldset>'.
4797: '<legend>'.&mt('Role privileges').&adhocbutton($prefix,$num,'privs','show').'</legend>'.
1.160.6.73 raeburn 4798: &Apache::lonuserutils::custom_role_table($crstype,\%full,\%levels,
1.160.6.77 raeburn 4799: \%levelscurrent,$identifier,
4800: 'LC_hidden',$prefix.$num.'_privs').
4801: '</fieldset></td>';
1.160.6.73 raeburn 4802: $itemcount ++;
4803: }
4804: $css_class = $itemcount%2?' class="LC_odd_row"':'';
4805: my $newcust = 'custhelp'.$count;
4806: my (%privs,%levelscurrent);
4807: my %full=();
4808: my %levels= (
4809: course => {},
4810: domain => {},
4811: system => {},
4812: );
4813: &Apache::lonuserutils::custom_role_privs(\%privs,\%full,\%levels,\%levelscurrent);
4814: my @templateroles = &Apache::lonuserutils::custom_template_roles($context,$crstype);
1.160.6.77 raeburn 4815: my $chgstr = ' onchange="javascript:reorderHelpRoles(this.form,'."'helproles_".$count."_pos'".');"';
4816: $datatable .= '<tr '.$css_class.'><td valign="top"><span class="LC_nobreak"><label>'.
4817: '<input type="hidden" name="helproles_maxnum" value="'.$maxnum.'" />'."\n".
4818: '<select name="helproles_'.$count.'_pos"'.$chgstr.'>';
4819: for (my $k=0; $k<$maxnum+1; $k++) {
4820: my $vpos = $k+1;
4821: my $selstr;
4822: if ($k == $maxnum) {
4823: $selstr = ' selected="selected" ';
4824: }
4825: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
4826: }
4827: $datatable .= '</select> '."\n".
1.160.6.73 raeburn 4828: '<input type="checkbox" name="newcusthelp" value="'.$count.'" />'. &mt('Add').
4829: '</label></span></td>'.
1.160.6.77 raeburn 4830: '<td><fieldset><legend>'.&mt('Role name').'</legend>'.
4831: '<span class="LC_nobreak">'.
4832: &mt('Internal name:').
4833: '<input type="text" size="10" name="custhelpname'.$count.'" value="" />'.
4834: '</span>'.(' 'x4).
4835: '<span class="LC_nobreak">'.
4836: &mt('Name shown to users:').
4837: '<input type="text" size="20" name="helproles_'.$count.'_desc" value="" />'.
4838: '</span></fieldset>'.
4839: &helpdeskroles_access($dom,$prefix,$count,'',undef,\@accesstypes,$othertitle,
4840: $usertypes,$types,\%domhelpdesk).
4841: '<fieldset><legend>'.&mt('Role privileges').'</legend>'.
1.160.6.73 raeburn 4842: &Apache::lonuserutils::custom_role_header($context,$crstype,
4843: \@templateroles,$newcust).
4844: &Apache::lonuserutils::custom_role_table('Course',\%full,\%levels,
4845: \%levelscurrent,$newcust).
1.160.6.87 raeburn 4846: '</fieldset>'.
4847: &helpsettings_javascript(\@roles_by_num,$maxnum,$hiddenstr,$formname).
4848: '</td></tr>';
1.160.6.73 raeburn 4849: $count ++;
4850: $$rowtotal += $count;
4851: }
1.160.6.5 raeburn 4852: return $datatable;
1.121 raeburn 4853: }
4854:
1.160.6.77 raeburn 4855: sub adhocbutton {
4856: my ($prefix,$num,$field,$visibility) = @_;
4857: my %lt = &Apache::lonlocal::texthash(
4858: show => 'Show details',
4859: hide => 'Hide details',
4860: );
4861: return '<span style="text-decoration:line-through; font-weight: normal;">'.(' 'x10).
4862: '</span>'.(' 'x2).'<input type="button" id="'.$prefix.$num.'_'.$field.'_vis"'.
4863: ' value="'.$lt{$visibility}.'" style="height:20px;" '.
4864: 'onclick="toggleHelpdeskItem('."'$num','$field'".');" />'.(' 'x2);
4865: }
4866:
4867: sub helpsettings_javascript {
4868: my ($roles_by_num,$total,$hiddenstr,$formname) = @_;
4869: return unless(ref($roles_by_num) eq 'ARRAY');
4870: my %html_js_lt = &Apache::lonlocal::texthash(
4871: show => 'Show details',
4872: hide => 'Hide details',
4873: );
4874: &html_escape(\%html_js_lt);
4875: my $jstext = ' var helproles = Array('."'".join("','",@{$roles_by_num})."'".');'."\n";
4876: return <<"ENDSCRIPT";
4877: <script type="text/javascript">
4878: // <![CDATA[
4879:
4880: function reorderHelpRoles(form,item) {
4881: var changedVal;
4882: $jstext
4883: var newpos = 'helproles_${total}_pos';
4884: var maxh = 1 + $total;
4885: var current = new Array();
4886: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
4887: if (item == newpos) {
4888: changedVal = newitemVal;
4889: } else {
4890: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
4891: current[newitemVal] = newpos;
4892: }
4893: for (var i=0; i<helproles.length; i++) {
4894: var elementName = 'helproles_'+helproles[i]+'_pos';
4895: if (elementName != item) {
4896: if (form.elements[elementName]) {
4897: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
4898: current[currVal] = elementName;
4899: }
4900: }
4901: }
4902: var oldVal;
4903: for (var j=0; j<maxh; j++) {
4904: if (current[j] == undefined) {
4905: oldVal = j;
4906: }
4907: }
4908: if (oldVal < changedVal) {
4909: for (var k=oldVal+1; k<=changedVal ; k++) {
4910: var elementName = current[k];
4911: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
4912: }
4913: } else {
4914: for (var k=changedVal; k<oldVal; k++) {
4915: var elementName = current[k];
4916: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
4917: }
4918: }
4919: return;
4920: }
4921:
4922: function helpdeskAccess(num) {
4923: var curraccess = null;
4924: if (document.$formname.elements['helproles_'+num+'_access'].length) {
4925: for (var i=0; i<document.$formname.elements['helproles_'+num+'_access'].length; i++) {
4926: if (document.$formname.elements['helproles_'+num+'_access'][i].checked) {
4927: curraccess = document.$formname.elements['helproles_'+num+'_access'][i].value;
4928: }
4929: }
4930: }
4931: var shown = Array();
4932: var hidden = Array();
4933: if (curraccess == 'none') {
4934: hidden = Array('$hiddenstr');
4935: } else {
4936: if (curraccess == 'status') {
4937: shown = Array('bystatus');
4938: hidden = Array('notinc','notexc');
4939: } else {
4940: if (curraccess == 'exc') {
4941: shown = Array('notexc');
4942: hidden = Array('notinc','bystatus');
4943: }
4944: if (curraccess == 'inc') {
4945: shown = Array('notinc');
4946: hidden = Array('notexc','bystatus');
4947: }
1.160.6.79 raeburn 4948: if ((curraccess == 'all') || (curraccess == 'dh') || (curraccess == 'da')) {
1.160.6.77 raeburn 4949: hidden = Array('notinc','notexc','bystatus');
4950: }
4951: }
4952: }
4953: if (hidden.length > 0) {
4954: for (var i=0; i<hidden.length; i++) {
4955: if (document.getElementById('helproles_'+num+'_'+hidden[i])) {
4956: document.getElementById('helproles_'+num+'_'+hidden[i]).style.display = 'none';
4957: }
4958: }
4959: }
4960: if (shown.length > 0) {
4961: for (var i=0; i<shown.length; i++) {
4962: if (document.getElementById('helproles_'+num+'_'+shown[i])) {
4963: if (shown[i] == 'privs') {
4964: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'block';
4965: } else {
4966: document.getElementById('helproles_'+num+'_'+shown[i]).style.display = 'inline-block';
4967: }
4968: }
4969: }
4970: }
4971: return;
4972: }
4973:
4974: function toggleHelpdeskItem(num,field) {
4975: if (document.getElementById('helproles_'+num+'_'+field)) {
4976: if (document.getElementById('helproles_'+num+'_'+field).className.match(/(?:^|\\s)LC_hidden(?!\\S)/)) {
4977: document.getElementById('helproles_'+num+'_'+field).className =
4978: document.getElementById('helproles_'+num+'_'+field).className.replace(/(?:^|\\s)LC_hidden(?!\\S)/g ,'');
4979: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4980: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{hide}';
4981: }
4982: } else {
4983: document.getElementById('helproles_'+num+'_'+field).className += ' LC_hidden';
4984: if (document.getElementById('helproles_'+num+'_'+field+'_vis')) {
4985: document.getElementById('helproles_'+num+'_'+field+'_vis').value = '$html_js_lt{show}';
4986: }
4987: }
4988: }
4989: return;
4990: }
4991:
4992: // ]]>
4993: </script>
4994:
4995: ENDSCRIPT
4996: }
4997:
4998: sub helpdeskroles_access {
4999: my ($dom,$prefix,$num,$add_class,$current,$accesstypes,$othertitle,
5000: $usertypes,$types,$domhelpdesk) = @_;
5001: return unless ((ref($accesstypes) eq 'ARRAY') && (ref($domhelpdesk) eq 'HASH'));
5002: my %lt = &Apache::lonlocal::texthash(
5003: 'rou' => 'Role usage',
5004: 'whi' => 'Which helpdesk personnel may use this role?',
1.160.6.79 raeburn 5005: 'all' => 'All with domain helpdesk or helpdesk assistant role',
5006: 'dh' => 'All with domain helpdesk role',
5007: 'da' => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 5008: 'none' => 'None',
5009: 'status' => 'Determined based on institutional status',
5010: 'inc' => 'Include all, but exclude specific personnel',
5011: 'exc' => 'Exclude all, but include specific personnel',
5012: );
5013: my %usecheck = (
5014: all => ' checked="checked"',
5015: );
5016: my %displaydiv = (
5017: status => 'none',
5018: inc => 'none',
5019: exc => 'none',
5020: priv => 'block',
5021: );
5022: my $output;
5023: if (ref($current) eq 'HASH') {
5024: if (($current->{'access'} ne '') && ($current->{'access'} ne 'all')) {
5025: if (grep(/^\Q$current->{access}\E$/,@{$accesstypes})) {
5026: $usecheck{$current->{access}} = $usecheck{'all'};
5027: delete($usecheck{'all'});
5028: if ($current->{access} =~ /^(status|inc|exc)$/) {
5029: my $access = $1;
5030: $displaydiv{$access} = 'inline';
5031: } elsif ($current->{access} eq 'none') {
5032: $displaydiv{'priv'} = 'none';
5033: }
5034: }
5035: }
5036: }
5037: $output = '<fieldset id="'.$prefix.$num.'_usage"><legend>'.$lt{'rou'}.'</legend>'.
5038: '<p>'.$lt{'whi'}.'</p>';
5039: foreach my $access (@{$accesstypes}) {
5040: $output .= '<p><label><input type="radio" name="'.$prefix.$num.'_access" value="'.$access.'" '.$usecheck{$access}.
5041: ' onclick="helpdeskAccess('."'$num'".');" />'.
5042: $lt{$access}.'</label>';
5043: if ($access eq 'status') {
5044: $output .= '<div id="'.$prefix.$num.'_bystatus" style="display:'.$displaydiv{$access}.'">'.
5045: &Apache::lonuserutils::adhoc_status_types($dom,$prefix,$num,$current->{$access},
5046: $othertitle,$usertypes,$types).
5047: '</div>';
5048: } elsif (($access eq 'inc') && (keys(%{$domhelpdesk}) > 0)) {
5049: $output .= '<div id="'.$prefix.$num.'_notinc" style="display:'.$displaydiv{$access}.'">'.
5050: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5051: '</div>';
5052: } elsif (($access eq 'exc') && (keys(%{$domhelpdesk}) > 0)) {
5053: $output .= '<div id="'.$prefix.$num.'_notexc" style="display:'.$displaydiv{$access}.'">'.
5054: &Apache::lonuserutils::adhoc_staff($access,$prefix,$num,$current->{$access},$domhelpdesk).
5055: '</div>';
5056: }
5057: $output .= '</p>';
5058: }
5059: $output .= '</fieldset>';
5060: return $output;
5061: }
5062:
1.121 raeburn 5063: sub radiobutton_prefs {
1.160.6.16 raeburn 5064: my ($settings,$toggles,$defaultchecked,$choices,$itemcount,$onclick,
1.160.6.113 raeburn 5065: $additional,$align,$firstval) = @_;
1.121 raeburn 5066: return unless ((ref($toggles) eq 'ARRAY') && (ref($defaultchecked) eq 'HASH') &&
5067: (ref($choices) eq 'HASH'));
5068:
5069: my (%checkedon,%checkedoff,$datatable,$css_class);
5070:
5071: foreach my $item (@{$toggles}) {
5072: if ($defaultchecked->{$item} eq 'on') {
1.118 jms 5073: $checkedon{$item} = ' checked="checked" ';
5074: $checkedoff{$item} = ' ';
1.121 raeburn 5075: } elsif ($defaultchecked->{$item} eq 'off') {
1.118 jms 5076: $checkedoff{$item} = ' checked="checked" ';
5077: $checkedon{$item} = ' ';
5078: }
5079: }
5080: if (ref($settings) eq 'HASH') {
1.121 raeburn 5081: foreach my $item (@{$toggles}) {
1.118 jms 5082: if ($settings->{$item} eq '1') {
5083: $checkedon{$item} = ' checked="checked" ';
5084: $checkedoff{$item} = ' ';
5085: } elsif ($settings->{$item} eq '0') {
5086: $checkedoff{$item} = ' checked="checked" ';
5087: $checkedon{$item} = ' ';
5088: }
5089: }
1.121 raeburn 5090: }
1.160.6.16 raeburn 5091: if ($onclick) {
5092: $onclick = ' onclick="'.$onclick.'"';
5093: }
1.121 raeburn 5094: foreach my $item (@{$toggles}) {
1.118 jms 5095: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.121 raeburn 5096: $datatable .=
1.160.6.16 raeburn 5097: '<tr'.$css_class.'><td valign="top">'.
5098: '<span class="LC_nobreak">'.$choices->{$item}.
1.160.6.57 raeburn 5099: '</span></td>';
5100: if ($align eq 'left') {
5101: $datatable .= '<td class="LC_left_item">';
5102: } else {
5103: $datatable .= '<td class="LC_right_item">';
5104: }
1.160.6.113 raeburn 5105: $datatable .= '<span class="LC_nobreak">';
5106: if ($firstval eq 'no') {
5107: $datatable .=
5108: '<label><input type="radio" name="'.
5109: $item.'" '.$checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').
5110: '</label> <label><input type="radio" name="'.$item.'" '.
5111: $checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').'</label>';
5112: } else {
5113: $datatable .=
1.160.6.118.2 14(raebu 5114:23): '<label><input type="radio" name="'.
5115:23): $item.'" '.$checkedon{$item}.' value="1"'.$onclick.' />'.&mt('Yes').
5116:23): '</label> <label><input type="radio" name="'.$item.'" '.
5117:23): $checkedoff{$item}.' value="0"'.$onclick.' />'.&mt('No').'</label>';
1.160.6.113 raeburn 5118: }
5119: $datatable .= '</span>'.$additional.'</td></tr>';
1.118 jms 5120: $itemcount ++;
1.121 raeburn 5121: }
5122: return ($datatable,$itemcount);
5123: }
5124:
1.160.6.118.2 1(raebur 5125:1): sub print_ltitools {
14(raebu 5126:23): my ($position,$dom,$settings,$rowtotal) = @_;
5127:23): my (%rules,%encrypt,%privkeys,%linkprot);
1(raebur 5128:1): if (ref($settings) eq 'HASH') {
14(raebu 5129:23): if ($position eq 'top') {
5130:23): if (exists($settings->{'encrypt'})) {
5131:23): if (ref($settings->{'encrypt'}) eq 'HASH') {
5132:23): foreach my $key (keys(%{$settings->{'encrypt'}})) {
5133:23): $encrypt{'toolsec_'.$key} = $settings->{'encrypt'}{$key};
1(raebur 5134:1): }
5135:1): }
5136:1): }
14(raebu 5137:23): if (exists($settings->{'private'})) {
5138:23): if (ref($settings->{'private'}) eq 'HASH') {
5139:23): if (ref($settings->{'private'}) eq 'HASH') {
5140:23): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5141:23): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
1(raebur 5142:1): }
5143:1): }
5144:1): }
5145:1): }
14(raebu 5146:23): } elsif ($position eq 'middle') {
5147:23): if (exists($settings->{'rules'})) {
5148:23): if (ref($settings->{'rules'}) eq 'HASH') {
5149:23): %rules = %{$settings->{'rules'}};
1(raebur 5150:1): }
5151:1): }
14(raebu 5152:23): } else {
5153:23): foreach my $key ('encrypt','private','rules') {
5154:23): if (exists($settings->{$key})) {
5155:23): delete($settings->{$key});
1(raebur 5156:1): }
5157:1): }
5158:1): }
5159:1): }
14(raebu 5160:23): my $datatable;
5161:23): my $itemcount = 1;
5162:23): if ($position eq 'top') {
5163:23): $datatable = &secrets_form($dom,'toolsec',\%encrypt,\%privkeys,$rowtotal);
5164:23): } elsif ($position eq 'middle') {
5165:23): $datatable = &password_rules('toolsecrets',\$itemcount,\%rules);
5166:23): $$rowtotal += $itemcount;
5167:23): } else {
5168:23): $datatable = &Apache::courseprefs::print_ltitools($dom,'',$settings,\$rowtotal,'','','domain');
1(raebur 5169:1): }
5170:1): return $datatable;
5171:1): }
5172:1):
5173:1): sub ltitools_names {
5174:1): my %lt = &Apache::lonlocal::texthash(
5175:1): 'title' => 'Title',
5176:1): 'version' => 'Version',
5177:1): 'msgtype' => 'Message Type',
5178:1): 'sigmethod' => 'Signature Method',
5179:1): 'url' => 'URL',
5180:1): 'key' => 'Key',
5181:1): 'lifetime' => 'Nonce lifetime (s)',
5182:1): 'secret' => 'Secret',
5183:1): 'icon' => 'Icon',
5184:1): 'user' => 'User',
5185:1): 'fullname' => 'Full Name',
5186:1): 'firstname' => 'First Name',
5187:1): 'lastname' => 'Last Name',
5188:1): 'email' => 'E-mail',
5189:1): 'roles' => 'Role',
5190:1): 'window' => 'Window',
5191:1): 'tab' => 'Tab',
5192:1): 'iframe' => 'iFrame',
5193:1): 'height' => 'Height',
5194:1): 'width' => 'Width',
5195:1): 'linktext' => 'Default Link Text',
5196:1): 'explanation' => 'Default Explanation',
14(raebu 5197:23): 'passback' => 'Tool can return grades:',
5198:23): 'roster' => 'Tool can retrieve roster:',
1(raebur 5199:1): 'crstarget' => 'Display target',
5200:1): 'crslabel' => 'Course label',
5201:1): 'crstitle' => 'Course title',
5202:1): 'crslinktext' => 'Link Text',
5203:1): 'crsexplanation' => 'Explanation',
5204:1): 'crsappend' => 'Provider URL',
5205:1): );
5206:1): return %lt;
5207:1): }
5208:1):
14(raebu 5209:23): sub secrets_form {
5210:23): my ($dom,$context,$encrypt,$privkeys,$rowtotal) = @_;
5211:23): my @ids=&Apache::lonnet::current_machine_ids();
5212:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
5213:23): my $primary = &Apache::lonnet::domain($dom,'primary');
5214:23): my ($css_class,$extra,$numshown,$itemcount,$output);
5215:23): $itemcount = 0;
5216:23): foreach my $hostid (sort(keys(%servers))) {
5217:23): my ($showextra,$divsty,$switch);
5218:23): if ($hostid eq $primary) {
5219:23): if ($context eq 'ltisec') {
5220:23): if (($encrypt->{'ltisec_consumers'}) || ($encrypt->{'ltisec_domlinkprot'})) {
5221:23): $showextra = 1;
5222:23): }
5223:23): if ($encrypt->{'ltisec_crslinkprot'}) {
5224:23): $showextra = 1;
5225:23): }
5226:23): } else {
5227:23): if (($encrypt->{'toolsec_crs'}) || ($encrypt->{'toolsec_dom'})) {
5228:23): $showextra = 1;
5229:23): }
5230:23): }
5231:23): unless (grep(/^\Q$hostid\E$/,@ids)) {
5232:23): $switch = 1;
5233:23): }
5234:23): if ($showextra) {
5235:23): $numshown ++;
5236:23): $divsty = 'display:inline-block';
5237:23): } else {
5238:23): $divsty = 'display:none';
5239:23): }
5240:23): $extra .= '<fieldset id="'.$context.'_info_'.$hostid.'" style="'.$divsty.'">'.
5241:23): '<legend>'.$hostid.'</legend>';
5242:23): if ($switch) {
5243:23): my $switchserver = '<a href="/adm/switchserver?otherserver='.$hostid.'&role='.
5244:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
5245:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
5246:23): if (exists($privkeys->{$hostid})) {
5247:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" />'.
5248:23): '<span class="LC_nobreak">'.
5249:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5250:23): '<span class="LC_nobreak">'.&mt('Change?').
5251:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5252:23): (' 'x2).
5253:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5254:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5255:23): '<span class="LC_nobreak"> - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5256:23): '</span></div>';
5257:23): } else {
5258:23): $extra .= '<span class="LC_nobreak">'.
5259:23): &mt('Key required').' - '.&mt('submit from server ([_1]): [_2].',$hostid,$switchserver).
5260:23): '</span>'."\n";
5261:23): }
5262:23): } elsif (exists($privkeys->{$hostid})) {
5263:23): $extra .= '<div id="'.$context.'_divcurrprivkey_'.$hostid.'" style="display:inline-block" /><span class="LC_nobreak">'.
5264:23): &mt('Encryption Key').': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5265:23): '<span class="LC_nobreak">'.&mt('Change?').
5266:23): '<label><input type="radio" value="0" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" checked="checked" />'.&mt('No').'</label>'.
5267:23): (' 'x2).
5268:23): '<label><input type="radio" value="1" name="'.$context.'_changeprivkey_'.$hostid.'" onclick="javascript:togglePrivKey(this.form,'."'$context','$hostid'".');" />'.&mt('Yes').
5269:23): '</label> </span><div id="'.$context.'_divchgprivkey_'.$hostid.'" style="display:none" />'.
5270:23): '<span class="LC_nobreak">'.&mt('New Key').':'.
5271:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5272: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>'.
5273:23): '</span></div>';
5274:23): } else {
5275:23): $extra .= '<span class="LC_nobreak">'.&mt('Encryption Key').':'.
5276:23): '<input type="password" size="20" name="'.$context.'_privkey_'.$hostid.'" value="" autocomplete="new-password" />'.
5277: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>';
5278:23): }
5279:23): $extra .= '</fieldset>';
5280:23): }
5281:23): }
5282:23): my (%choices,@toggles,%defaultchecked);
5283:23): if ($context eq 'ltisec') {
5284:23): %choices = &Apache::lonlocal::texthash (
5285:23): ltisec_crslinkprot => 'Encrypt stored link protection secrets defined in courses',
5286:23): ltisec_domlinkprot => 'Encrypt stored link protection secrets defined in domain',
5287:23): ltisec_consumers => 'Encrypt stored consumer secrets defined in domain',
5288:23): );
5289:23): @toggles = qw(ltisec_crslinkprot ltisec_domlinkprot ltisec_consumers);
5290:23): %defaultchecked = (
5291:23): 'ltisec_crslinkprot' => 'off',
5292:23): 'ltisec_domlinkprot' => 'off',
5293:23): 'ltisec_consumers' => 'off',
5294:23): );
5295:23): } else {
5296:23): %choices = &Apache::lonlocal::texthash (
5297:23): toolsec_crs => 'Encrypt stored external tool secrets defined in courses',
5298:23): toolsec_dom => 'Encrypt stored external tool secrets defined in domain',
5299:23): );
5300:23): @toggles = qw(toolsec_crs toolsec_dom);
5301:23): %defaultchecked = (
5302:23): 'toolsec_crs' => 'off',
5303:23): 'toolsec_dom' => 'off',
5304:23): );
5305:23): }
5306:23): my ($onclick,$itemcount);
5307:23): $onclick = 'javascript:toggleLTIEncKey(this.form,'."'$context'".');';
5308:23): ($output,$itemcount) = &radiobutton_prefs($encrypt,\@toggles,\%defaultchecked,
5309:23): \%choices,$itemcount,$onclick,'','left','no');
5310:23):
5311:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5312:23): my $noprivkeysty = 'display:inline-block';
5313:23): if ($numshown) {
5314:23): $noprivkeysty = 'display:none';
5315:23): }
5316:23): $output .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.&mt('Encryption Key(s)').'</td>'.
5317:23): '<td><div id="'.$context.'_noprivkey" style="'.$noprivkeysty.'" >'.
5318:23): '<span class="LC_nobreak">'.&mt('Not in use').'</span></div>'.
5319:23): $extra.
5320:23): '</td></tr>';
5321:23): $itemcount ++;
5322:23): $$rowtotal += $itemcount;
5323:23): return $output;
5324:23): }
5325:23):
5(raebur 5326:2): sub print_lti {
5327:2): my ($position,$dom,$settings,$rowtotal) = @_;
5328:2): my $itemcount = 1;
5329:2): my ($datatable,$css_class);
18(raebu 5330:24): my (%rules,%encrypt,%privkeys,%linkprot,%suggestions);
5(raebur 5331:2): if (ref($settings) eq 'HASH') {
5332:2): if ($position eq 'top') {
5333:2): if (exists($settings->{'encrypt'})) {
5334:2): if (ref($settings->{'encrypt'}) eq 'HASH') {
5335:2): foreach my $key (keys(%{$settings->{'encrypt'}})) {
14(raebu 5336:23): if ($key eq 'consumers') {
5337:23): $encrypt{'ltisec_'.$key} = $settings->{'encrypt'}{$key};
5338:23): } else {
5339:23): $encrypt{'ltisec_'.$key.'linkprot'} = $settings->{'encrypt'}{$key};
5340:23): }
5(raebur 5341:2): }
5342:2): }
5343:2): }
5344:2): if (exists($settings->{'private'})) {
5345:2): if (ref($settings->{'private'}) eq 'HASH') {
5346:2): if (ref($settings->{'private'}) eq 'HASH') {
5347:2): if (ref($settings->{'private'}{'keys'}) eq 'ARRAY') {
5348:2): map { $privkeys{$_} = 1; } (@{$settings->{'private'}{'keys'}});
5349:2): }
5350:2): }
5351:2): }
5352:2): }
18(raebu 5353:24): } elsif ($position eq 'upper') {
5(raebur 5354:2): if (exists($settings->{'rules'})) {
5355:2): if (ref($settings->{'rules'}) eq 'HASH') {
5356:2): %rules = %{$settings->{'rules'}};
5357:2): }
5358:2): }
18(raebu 5359:24): } elsif ($position eq 'middle') {
5360:24): if (exists($settings->{'suggested'})) {
5361:24): if (ref($settings->{'suggested'}) eq 'HASH') {
5362:24): %suggestions = %{$settings->{'suggested'}};
5363:24): }
5364:24): }
14(raebu 5365:23): } elsif ($position eq 'lower') {
5(raebur 5366:2): if (exists($settings->{'linkprot'})) {
5367:2): if (ref($settings->{'linkprot'}) eq 'HASH') {
5368:2): %linkprot = %{$settings->{'linkprot'}};
5369:2): if ($linkprot{'lock'}) {
5370:2): delete($linkprot{'lock'});
5371:2): }
5372:2): }
5373:2): }
14(raebu 5374:23): } else {
18(raebu 5375:24): foreach my $key ('encrypt','private','rules','linkprot','suggestions') {
14(raebu 5376:23): if (exists($settings->{$key})) {
5377:23): delete($settings->{$key});
5378:23): }
5379:23): }
5(raebur 5380:2): }
5381:2): }
5382:2): if ($position eq 'top') {
14(raebu 5383:23): $datatable = &secrets_form($dom,'ltisec',\%encrypt,\%privkeys,$rowtotal);
18(raebu 5384:24): } elsif ($position eq 'upper') {
14(raebu 5385:23): $datatable = &password_rules('ltisecrets',\$itemcount,\%rules);
5386:23): $$rowtotal += $itemcount;
18(raebu 5387:24): } elsif ($position eq 'middle') {
5388:24): $datatable = &linkprot_suggestions(\%suggestions,\$itemcount);
5389:24): $$rowtotal += $itemcount;
14(raebu 5390:23): } elsif ($position eq 'lower') {
18(raebu 5391:24): $datatable .= &Apache::courseprefs::print_linkprotection($dom,'',$settings,$rowtotal,'','','domain');
14(raebu 5392:23): } else {
5393:23): my ($switchserver,$switchmessage);
5394:23): $switchserver = &check_switchserver($dom);
5395:23): $switchmessage = &mt("submit from domain's primary library server: [_1].",$switchserver);
5396:23): my $maxnum = 0;
5397:23): my %ordered;
5398:23): if (ref($settings) eq 'HASH') {
5399:23): foreach my $item (keys(%{$settings})) {
5400:23): if (ref($settings->{$item}) eq 'HASH') {
5401:23): my $num = $settings->{$item}{'order'};
5402:23): if ($num eq '') {
5403:23): $num = scalar(keys(%{$settings}));
5404:23): }
5405:23): $ordered{$num} = $item;
5(raebur 5406:2): }
5407:2): }
14(raebu 5408:23): }
5409:23): $maxnum = scalar(keys(%ordered));
5410:23): my %lt = <i_names();
5411:23): if (keys(%ordered)) {
5412:23): my @items = sort { $a <=> $b } keys(%ordered);
5413:23): for (my $i=0; $i<@items; $i++) {
5414:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5415:23): my $item = $ordered{$items[$i]};
5416:23): my ($key,$secret,$usable,$lifetime,$consumer,$requser,$crsinc,$current);
5417:23): if (ref($settings->{$item}) eq 'HASH') {
5418:23): $key = $settings->{$item}->{'key'};
5419:23): $usable = $settings->{$item}->{'usable'};
5420:23): $lifetime = $settings->{$item}->{'lifetime'};
5421:23): $consumer = $settings->{$item}->{'consumer'};
5422:23): $requser = $settings->{$item}->{'requser'};
5423:23): $crsinc = $settings->{$item}->{'crsinc'};
5424:23): $current = $settings->{$item};
5425:23): }
5426:23): my $onclickrequser = ' onclick="toggleLTI(this.form,'."'requser','$i'".');"';
5427:23): my %checkedrequser = (
5428:23): yes => ' checked="checked"',
5429:23): no => '',
5430:23): );
5431:23): if (!$requser) {
5432:23): $checkedrequser{'no'} = $checkedrequser{'yes'};
5433:23): $checkedrequser{'yes'} = '';
5434:23): }
5435:23): my $onclickcrsinc = ' onclick="toggleLTI(this.form,'."'crsinc','$i'".');"';
5436:23): my %checkedcrsinc = (
5437:23): yes => ' checked="checked"',
5438:23): no => '',
5439:23): );
5440:23): if (!$crsinc) {
5441:23): $checkedcrsinc{'no'} = $checkedcrsinc{'yes'};
5442:23): $checkedcrsinc{'yes'} = '';
5443:23): }
5444:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_".$item."'".');"';
5445:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
5446:23): .'<select name="lti_pos_'.$item.'"'.$chgstr.'>';
5447:23): for (my $k=0; $k<=$maxnum; $k++) {
5448:23): my $vpos = $k+1;
5449:23): my $selstr;
5450:23): if ($k == $i) {
5451:23): $selstr = ' selected="selected" ';
5452:23): }
5453:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5454:23): }
5455:23): $datatable .= '</select>'.(' 'x2).
5456:23): '<label><input type="checkbox" name="lti_del" value="'.$item.'" />'.
5457:23): &mt('Delete?').'</label></span></td>'.
5458:23): '<td colspan="2">'.
5459:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5460:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5461:23): ':<input type="text" size="15" name="lti_consumer_'.$i.'" value="'.$consumer.'" /></span> '.
5462:23): (' 'x2).
5463:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_'.$i.'">'.
5464:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '.
5465:23): (' 'x2).
5466:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" name="lti_lifetime_'.$i.'"'.
5467:23): 'value="'.$lifetime.'" size="3" /></span><br /><br />';
5468:23): if ($key ne '') {
5469:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'};
5470:23): if ($switchserver) {
5471:23): $datatable .= ': ['.&mt('[_1] to view/edit',$switchserver).']';
5472:23): } else {
5473:23): $datatable .= ':<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />';
5474:23): }
5475:23): $datatable .= '</span> '.(' 'x2);
5476:23): } elsif (!$switchserver) {
5477:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':'.
5478:23): '<input type="text" size="25" name="lti_key_'.$i.'" value="'.$key.'" autocomplete="off" />'.
5479:23): '</span> '.(' 'x2);
5480:23): }
5481:23): if ($switchserver) {
5482:23): if ($usable ne '') {
5483:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5484:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5485:23): '<span class="LC_nobreak">'.&mt('Change secret?').
5486:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5487:23): (' 'x2).
5488:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').'</label>'.(' 'x2).
5489:23): '</span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5490:23): '<span class="LC_nobreak"> - '.$switchmessage.'</span>'.
5491:23): '</div>';
5492:23): } elsif ($key eq '') {
5493:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5494:23): } else {
5495:23): $datatable .= '<span class="LC_nobreak">'.&mt('Secret required').' - '.$switchmessage.'</span>'."\n";
5496:23): }
5497:23): } else {
5498:23): if ($usable ne '') {
5499:23): $datatable .= '<div id="lti_divcurrsecret_'.$i.'" style="display:inline-block" /><span class="LC_nobreak">'.
5500:23): $lt{'secret'}.': ['.&mt('not shown').'] '.(' 'x2).'</span></div>'.
5501:23): '<span class="LC_nobreak">'.&mt('Change?').
5502:23): '<label><input type="radio" value="0" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" checked="checked" />'.&mt('No').'</label>'.
5503:23): (' 'x2).
5504:23): '<label><input type="radio" value="1" name="lti_changesecret_'.$i.'" onclick="javascript:toggleChgSecret(this.form,'."'$i','secret','lti'".');" />'.&mt('Yes').
5505:23): '</label> </span><div id="lti_divchgsecret_'.$i.'" style="display:none" />'.
5506:23): '<span class="LC_nobreak">'.&mt('New Secret').':'.
5507:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5508: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>';
5509:23): } else {
5510:23): $datatable .=
5511:23): '<span class="LC_nobreak">'.$lt{'secret'}.':'.
5512:23): '<input type="password" size="20" name="lti_secret_'.$i.'" value="" autocomplete="new-password" />'.
5513: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>';
5514:23): }
5515:23): }
5516:23): $datatable .= '<br /><br />'.
5517:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5518:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="1"'.$onclickrequser.$checkedrequser{yes}.' />'.&mt('Yes').'</label> '."\n".
5519:23): '<label><input type="radio" name="lti_requser_'.$i.'" value="0"'.$onclickrequser.$checkedrequser{no}.' />'.&mt('No').'</label></span>'."\n".
5520:23): '<br /><br />'.
5521:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5522:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="1"'.$onclickcrsinc.$checkedcrsinc{yes}.' />'.&mt('Yes').'</label> '."\n".
5523:23): '<label><input type="radio" name="lti_crsinc_'.$i.'" value="0"'.$onclickcrsinc.$checkedcrsinc{no}.' />'.&mt('No').'</label></span>'."\n".
5524:23): (' 'x4).
5525:23): '<input type="hidden" name="lti_id_'.$i.'" value="'.$item.'" /></span>'.
5526:23): '</fieldset>'.<i_options($i,$current,$itemcount,%lt).'</td></tr>';
5527:23): $itemcount ++;
5(raebur 5528:2): }
14(raebu 5529:23): }
5530:23): $css_class = $itemcount%2?' class="LC_odd_row"':'';
5531:23): my $chgstr = ' onchange="javascript:reorderLTI(this.form,'."'lti_pos_add'".');"';
5532:23): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
5533:23): '<input type="hidden" name="lti_maxnum" value="'.$maxnum.'" />'."\n".
5534:23): '<select name="lti_pos_add"'.$chgstr.'>';
5535:23): for (my $k=0; $k<$maxnum+1; $k++) {
5536:23): my $vpos = $k+1;
5537:23): my $selstr;
5538:23): if ($k == $maxnum) {
5539:23): $selstr = ' selected="selected" ';
5(raebur 5540:2): }
14(raebu 5541:23): $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
5542:23): }
5543:23): $datatable .= '</select> '."\n".
5544:23): '<input type="checkbox" name="lti_add" value="1" />'.&mt('Add').'</span></td>'."\n".
5545:23): '<td colspan="2">'.
5546:23): '<fieldset><legend>'.&mt('Required settings').'</legend>'.
5547:23): '<span class="LC_nobreak">'.$lt{'consumer'}.
5548:23): ':<input type="text" size="15" name="lti_consumer_add" value="" /></span> '."\n".
5549:23): (' 'x2).
5550:23): '<span class="LC_nobreak">'.$lt{'version'}.':<select name="lti_version_add">'.
5551:23): '<option value="LTI-1p0" selected="selected">1.1</option></select></span> '."\n".
5552:23): (' 'x2).
5553:23): '<span class="LC_nobreak">'.$lt{'lifetime'}.':<input type="text" size="3" name="lti_lifetime_add" value="300" /></span><br /><br />'."\n";
5554:23): if ($switchserver) {
5555:23): $datatable .= '<span class="LC_nobreak">'.&mt('Key and Secret are required').' - '.$switchmessage.'</span>'."\n";
5556:23): } else {
5557:23): $datatable .= '<span class="LC_nobreak">'.$lt{'key'}.':<input type="text" size="25" name="lti_key_add" value="" autocomplete="off" /></span> '."\n".
5558:23): (' 'x2).
5559:23): '<span class="LC_nobreak">'.$lt{'secret'}.':<input type="password" size="20" name="lti_secret_add" value="" autocomplete="new-password" />'.
5560: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";
5561:23): }
5562:23): $datatable .= '<br /><br />'.
5563:23): '<span class="LC_nobreak">'.$lt{'requser'}.':'.
5564:23): '<label><input type="radio" name="lti_requser_add" value="1" onclick="toggleLTI(this.form,'."'requser','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5565:23): '<label><input type="radio" name="lti_requser_add" value="0" onclick="toggleLTI(this.form,'."'requser','add'".');" />'.&mt('No').'</label></span>'."\n".
5566:23): '<br /><br />'.
5567:23): '<span class="LC_nobreak">'.$lt{'crsinc'}.':'.
5568:23): '<label><input type="radio" name="lti_crsinc_add" value="1" onclick="toggleLTI(this.form,'."'crsinc','add'".');" checked="checked" />'.&mt('Yes').'</label> '."\n".
5569:23): '<label><input type="radio" name="lti_crsinc_add" value="0" onclick="toggleLTI(this.form,'."'crsinc','add'".');" />'.&mt('No').'</label></span>'."\n".
5570:23): '</fieldset>'.<i_options('add',undef,$itemcount,%lt).
5571:23): '</td>'."\n".
5572:23): '</tr>'."\n";
5573:23): $itemcount ++;
5574:23): }
5575:23): $$rowtotal += $itemcount;
5576:23): return $datatable;
5577:23): }
5578:23):
5579:23): sub lti_names {
5580:23): my %lt = &Apache::lonlocal::texthash(
5581:23): 'version' => 'LTI Version',
5582:23): 'url' => 'URL',
5583:23): 'key' => 'Key',
5584:23): 'lifetime' => 'Nonce lifetime (s)',
5585:23): 'consumer' => 'Consumer',
5586:23): 'secret' => 'Secret',
5587:23): 'requser' => "User's identity sent",
5588:23): 'crsinc' => "Course's identity sent",
5589:23): 'email' => 'Email address',
5590:23): 'sourcedid' => 'User ID',
5591:23): 'other' => 'Other',
5592:23): 'passback' => 'Can return grades to Consumer:',
5593:23): 'roster' => 'Can retrieve roster from Consumer:',
5594:23): 'topmenu' => 'Display LON-CAPA page header',
5595:23): 'inlinemenu'=> 'Display LON-CAPA inline menu',
5596:23): );
5597:23): return %lt;
5598:23): }
5599:23):
5600:23): sub lti_options {
5601:23): my ($num,$current,$itemcount,%lt) = @_;
5602:23): my (%checked,%rolemaps,$crssecsrc,$userfield,$cidfield,$callback);
5603:23): $checked{'mapuser'}{'sourcedid'} = ' checked="checked"';
5604:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = ' checked="checked"';
5605:23): $checked{'storecrs'}{'Y'} = ' checked="checked"';
5606:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5607:23): $checked{'mapcrstype'} = {};
5608:23): $checked{'makeuser'} = {};
5609:23): $checked{'selfenroll'} = {};
5610:23): $checked{'crssec'} = {};
5611:23): $checked{'crssecsrc'} = {};
5612:23): $checked{'lcauth'} = {};
5613:23): $checked{'menuitem'} = {};
5614:23): if ($num eq 'add') {
5615:23): $checked{'lcauth'}{'lti'} = ' checked="checked"';
5616:23): }
5617:23): my $userfieldsty = 'none';
5618:23): my $crsfieldsty = 'none';
5619:23): my $crssecfieldsty = 'none';
5620:23): my $secsrcfieldsty = 'none';
5621:23): my $callbacksty = 'none';
5622:23): my $passbacksty = 'none';
5623:23): my $optionsty = 'block';
5624:23): my $crssty = 'block';
5625:23): my $lcauthparm;
5626:23): my $lcauthparmstyle = 'display:none';
5627:23): my $lcauthparmtext;
5628:23): my $menusty;
5629:23): my $numinrow = 4;
5630:23): my %menutitles = <imenu_titles();
5631:23):
5632:23): if (ref($current) eq 'HASH') {
5633:23): if (!$current->{'requser'}) {
5634:23): $optionsty = 'none';
5635:23): $crssty = 'none';
5636:23): } elsif (!$current->{'crsinc'}) {
5637:23): $crssty = 'none';
5638:23): }
5639:23): if (($current->{'mapuser'} ne '') && ($current->{'mapuser'} ne 'lis_person_sourcedid')) {
5640:23): $checked{'mapuser'}{'sourcedid'} = '';
5641:23): if ($current->{'mapuser'} eq 'lis_person_contact_email_primary') {
5642:23): $checked{'mapuser'}{'email'} = ' checked="checked"';
5(raebur 5643:2): } else {
14(raebu 5644:23): $checked{'mapuser'}{'other'} = ' checked="checked"';
5645:23): $userfield = $current->{'mapuser'};
5646:23): $userfieldsty = 'inline-block';
5(raebur 5647:2): }
14(raebu 5648:23): }
5649:23): if (($current->{'mapcrs'} ne '') && ($current->{'mapcrs'} ne 'course_offering_sourcedid')) {
5650:23): $checked{'mapcrs'}{'course_offering_sourcedid'} = '';
5651:23): if ($current->{'mapcrs'} eq 'context_id') {
5652:23): $checked{'mapcrs'}{'context_id'} = ' checked="checked"';
5653:23): } else {
5654:23): $checked{'mapcrs'}{'other'} = ' checked="checked"';
5655:23): $cidfield = $current->{'mapcrs'};
5656:23): $crsfieldsty = 'inline-block';
5657:23): }
5658:23): }
5659:23): if (ref($current->{'mapcrstype'}) eq 'ARRAY') {
5660:23): foreach my $type (@{$current->{'mapcrstype'}}) {
5661:23): $checked{'mapcrstype'}{$type} = ' checked="checked"';
5662:23): }
5663:23): }
5664:23): if (!$current->{'storecrs'}) {
5665:23): $checked{'storecrs'}{'N'} = $checked{'storecrs'}{'Y'};
5666:23): $checked{'storecrs'}{'Y'} = '';
5667:23): }
5668:23): if ($current->{'makecrs'}) {
5669:23): $checked{'makecrs'}{'Y'} = ' checked="checked"';
5670:23): }
5671:23): if (ref($current->{'makeuser'}) eq 'ARRAY') {
5672:23): foreach my $role (@{$current->{'makeuser'}}) {
5673:23): $checked{'makeuser'}{$role} = ' checked="checked"';
5674:23): }
5675:23): }
5676:23): if ($current->{'lcauth'} =~ /^(internal|localauth|krb4|krb5|lti)$/) {
5677:23): $checked{'lcauth'}{$1} = ' checked="checked"';
5678:23): unless (($current->{'lcauth'} eq 'lti') || ($current->{'lcauth'} eq 'internal')) {
5679:23): $lcauthparm = $current->{'lcauthparm'};
5680:23): $lcauthparmstyle = 'display:table-row';
5681:23): if ($current->{'lcauth'} eq 'localauth') {
5682:23): $lcauthparmtext = &mt('Local auth argument');
5(raebur 5683:2): } else {
14(raebu 5684:23): $lcauthparmtext = &mt('Kerberos domain');
5(raebur 5685:2): }
14(raebu 5686:23): }
5687:23): }
5688:23): if (ref($current->{'selfenroll'}) eq 'ARRAY') {
5689:23): foreach my $role (@{$current->{'selfenroll'}}) {
5690:23): $checked{'selfenroll'}{$role} = ' checked="checked"';
5691:23): }
5692:23): }
5693:23): if (ref($current->{'maproles'}) eq 'HASH') {
5694:23): %rolemaps = %{$current->{'maproles'}};
5695:23): }
5696:23): if ($current->{'section'} ne '') {
5697:23): $checked{'crssec'}{'Y'} = ' checked="checked"';
5698:23): $crssecfieldsty = 'inline-block';
5699:23): if ($current->{'section'} eq 'course_section_sourcedid') {
5700:23): $checked{'crssecsrc'}{'sourcedid'} = ' checked="checked"';
5(raebur 5701:2): } else {
14(raebu 5702:23): $checked{'crssecsrc'}{'other'} = ' checked="checked"';
5703:23): $crssecsrc = $current->{'section'};
5704:23): $secsrcfieldsty = 'inline-block';
5(raebur 5705:2): }
14(raebu 5706:23): } else {
5707:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5(raebur 5708:2): }
14(raebu 5709:23): if ($current->{'callback'} ne '') {
5710:23): $callback = $current->{'callback'};
5711:23): $checked{'callback'}{'Y'} = ' checked="checked"';
5712:23): $callbacksty = 'inline-block';
5713:23): } else {
5714:23): $checked{'callback'}{'N'} = ' checked="checked"';
5715:23): }
5716:23): if ($current->{'topmenu'}) {
5717:23): $checked{'topmenu'}{'Y'} = ' checked="checked"';
5718:23): } else {
5719:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5720:23): }
5721:23): if ($current->{'inlinemenu'}) {
5722:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5723:23): } else {
5724:23): $checked{'inlinemenu'}{'N'} = ' checked="checked"';
5725:23): }
5726:23): if (($current->{'topmenu'}) || ($current->{'inlinemenu'})) {
5727:23): $menusty = 'inline-block';
5728:23): if (ref($current->{'lcmenu'}) eq 'ARRAY') {
5729:23): foreach my $item (@{$current->{'lcmenu'}}) {
5730:23): if (exists($menutitles{$item})) {
5731:23): $checked{'menuitem'}{$item} = ' checked="checked"';
5732:23): }
5733:23): }
5734:23): }
5735:23): } else {
5736:23): $menusty = 'none';
5737:23): }
5738:23): } else {
5739:23): $checked{'makecrs'}{'N'} = ' checked="checked"';
5740:23): $checked{'crssec'}{'N'} = ' checked="checked"';
5741:23): $checked{'callback'}{'N'} = ' checked="checked"';
5742:23): $checked{'topmenu'}{'N'} = ' checked="checked"';
5743:23): $checked{'inlinemenu'}{'Y'} = ' checked="checked"';
5744:23): $checked{'menuitem'}{'grades'} = ' checked="checked"';
5745:23): $menusty = 'inline-block';
5(raebur 5746:2): }
14(raebu 5747:23): my @coursetypes = ('official','unofficial','community','textbook','lti');
5748:23): my %coursetypetitles = &Apache::lonlocal::texthash (
5749:23): official => 'Official',
5750:23): unofficial => 'Unofficial',
5751:23): community => 'Community',
5752:23): textbook => 'Textbook',
5753:23): lti => 'LTI Provider',
5754:23): );
5755:23): my @authtypes = ('internal','krb4','krb5','localauth');
5756:23): my %shortauth = (
5757:23): internal => 'int',
5758:23): krb4 => 'krb4',
5759:23): krb5 => 'krb5',
5760:23): localauth => 'loc'
5761:23): );
5762:23): my %authnames = &authtype_names();
5763:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
5764:23): my @lticourseroles = qw(Learner Instructor TeachingAssistant Mentor);
5765:23): my @courseroles = ('cc','in','ta','ep','st');
5766:23): my $onclickuser = ' onclick="toggleLTI(this.form,'."'user','$num'".');"';
5767:23): my $onclickcrs = ' onclick="toggleLTI(this.form,'."'crs','$num'".');"';
5768:23): my $onclicksec = ' onclick="toggleLTI(this.form,'."'sec','$num'".');"';
5769:23): my $onclickcallback = ' onclick="toggleLTI(this.form,'."'callback','$num'".');"';
5770:23): my $onclicksecsrc = ' onclick="toggleLTI(this.form,'."'secsrc','$num'".')"';
5771:23): my $onclicklcauth = ' onclick="toggleLTI(this.form,'."'lcauth','$num'".')"';
5772:23): my $onclickmenu = ' onclick="toggleLTI(this.form,'."'lcmenu','$num'".');"';
5773:23): my $output = '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Logout options').'</legend>'.
5774:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Callback to logout LON-CAPA on log out from Consumer').': '.
5775:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="0"'.
5776:23): $checked{'callback'}{'N'}.$onclickcallback.' />'.&mt('No').'</label>'.(' 'x2).
5777:23): '<label><input type="radio" name="lti_callback_'.$num.'" value="1"'.
5778:23): $checked{'callback'}{'Y'}.$onclickcallback.' />'.&mt('Yes').'</label></span></div>'.
5779:23): '<div class="LC_floatleft" style="display:'.$callbacksty.';" id="lti_callbackfield_'.$num.'">'.
5780:23): '<span class="LC_nobreak">'.&mt('Parameter').': '.
5781:23): '<input type="text" name="lti_callbackparam_'.$num.'" value="'.$callback.'" /></span>'.
5782:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>'.
5783:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Mapping users').'</legend>'.
5784:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('LON-CAPA username').': ';
5785:23): foreach my $option ('sourcedid','email','other') {
5786:23): $output .= '<label><input type="radio" name="lti_mapuser_'.$num.'" value="'.$option.'"'.
5787:23): $checked{'mapuser'}{$option}.$onclickuser.' />'.$lt{$option}.'</label>'.
5788:23): ($option eq 'other' ? '' : (' 'x2) );
5789:23): }
5790:23): $output .= '</span></div>'.
5791:23): '<div class="LC_floatleft" style="display:'.$userfieldsty.';" id="lti_userfield_'.$num.'">'.
5792:23): '<input type="text" name="lti_customuser_'.$num.'" '.
5793:23): 'value="'.$userfield.'" /></div></fieldset>'.
5794:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('Roles which may create user accounts').'</legend>';
5795:23): foreach my $ltirole (@ltiroles) {
5796:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_makeuser_'.$num.'" value="'.$ltirole.'"'.
5797:23): $checked{'makeuser'}{$ltirole}.' />'.$ltirole.'</label> </span> ';
5798:23): }
5799:23): $output .= '</fieldset>'.
5800:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.&mt('New user accounts created for LTI users').'</legend>'.
5801:23): '<table>'.
5802:23): &modifiable_userdata_row('lti','instdata_'.$num,$current,$numinrow,$itemcount).
5803:23): '</table>'.
5804:23): '<table class="LC_nested"><tr><td class="LC_left_item">LON-CAPA Authentication</td>'.
5805:23): '<td class="LC_left_item">';
5806:23): foreach my $auth ('lti',@authtypes) {
5807:23): my $authtext;
5808:23): if ($auth eq 'lti') {
5809:23): $authtext = &mt('None');
5810:23): } else {
5811:23): $authtext = $authnames{$shortauth{$auth}};
5812:23): }
5813:23): $output .= '<span class="LC_nobreak"><label><input type="radio" name="lti_lcauth_'.$num.
5814:23): '" value="'.$auth.'"'.$checked{'lcauth'}{$auth}.$onclicklcauth.' />'.
5815:23): $authtext.'</label></span> ';
5816:23): }
5817:23): $output .= '</td></tr>'.
5818:23): '<tr id="lti_lcauth_parmrow_'.$num.'" style="'.$lcauthparmstyle.'">'.
5819:23): '<td class="LC_right_item" colspan="2"><span class="LC_nobreak">'.
5820:23): '<span id="lti_lcauth_parmtext_'.$num.'">'.$lcauthparmtext.'</span>'.
5821:23): '<input type="text" name="lti_lcauthparm_'.$num.'" value="" /></span></td></tr>'.
5822:23): '</table></fieldset>'.
5823:23): '<fieldset class="ltioption_usr_'.$num.'" style="display:'.$optionsty.'"><legend>'.
5824:23): &mt('LON-CAPA menu items (Course Coordinator can override)').'</legend>'.
5825:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'topmenu'}.': '.
5826:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="0"'.
5827:23): $checked{'topmenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5828:23): '<label><input type="radio" name="lti_topmenu_'.$num.'" value="1"'.
5829:23): $checked{'topmenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>'.
5830:23): '<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5831:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.$lt{'inlinemenu'}.': '.
5832:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="0"'.
5833:23): $checked{'inlinemenu'}{'N'}.$onclickmenu.' />'.&mt('No').'</label>'.(' 'x2).
5834:23): '<label><input type="radio" name="lti_inlinemenu_'.$num.'" value="1"'.
5835:23): $checked{'inlinemenu'}{'Y'}.$onclickmenu.' />'.&mt('Yes').'</label></span></div>';
5836:23): $output .='<div style="padding:0;clear:both;margin:0;border:0"></div>'.
5837:23): '<div class="LC_floatleft" style="display:'.$menusty.';" id="lti_menufield_'.$num.'">'.
5838:23): '<span class="LC_nobreak">'.&mt('Menu items').': ';
5839:23): foreach my $type ('fullname','coursetitle','role','logout','grades') {
5840:23): $output .= '<label><input type="checkbox" name="lti_menuitem_'.$num.'" value="'.$type.'"'.
5841:23): $checked{'menuitem'}{$type}.' />'.$menutitles{$type}.'</label>'.
5842:23): (' 'x2);
5843:23): }
5844:23): $output .= '</span></div></fieldset>'.
5845:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping courses').'</legend>'.
5846:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.
5847:23): &mt('Unique course identifier').': ';
5848:23): foreach my $option ('course_offering_sourcedid','context_id','other') {
5849:23): $output .= '<label><input type="radio" name="lti_mapcrs_'.$num.'" value="'.$option.'"'.
5850:23): $checked{'mapcrs'}{$option}.$onclickcrs.' />'.$option.'</label>'.
5851:23): ($option eq 'other' ? '' : (' 'x2) );
5852:23): }
5853:23): $output .= '</span></div><div class="LC_floatleft" style="display:'.$crsfieldsty.';" id="lti_crsfield_'.$num.'">'.
5854:23): '<input type="text" name="lti_mapcrsfield_'.$num.'" value="'.$cidfield.'" />'.
5855:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>'.
5856:23): '<span class="LC_nobreak">'.&mt('LON-CAPA course type(s)').': ';
5857:23): foreach my $type (@coursetypes) {
5858:23): $output .= '<label><input type="checkbox" name="lti_mapcrstype_'.$num.'" value="'.$type.'"'.
5859:23): $checked{'mapcrstype'}{$type}.' />'.$coursetypetitles{$type}.'</label>'.
5860:23): (' 'x2);
5861:23): }
5862:23): $output .= '</span><br /><br />'.
5863:23): '<span class="LC_nobreak">'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.
5864:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="0"'.
5865:23): $checked{'storecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5866:23): '<label><input type="radio" name="lti_storecrs_'.$num.'" value="1"'.
5867:23): $checked{'storecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5868:23): '</fieldset>'.
5869:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Mapping course roles').'</legend><table><tr>';
5870:23): foreach my $ltirole (@lticourseroles) {
5871:23): my ($selected,$selectnone);
5872:23): if ($rolemaps{$ltirole} eq '') {
5873:23): $selectnone = ' selected="selected"';
5874:23): }
5875:23): $output .= '<td style="text-align: center">'.$ltirole.'<br />'.
5876:23): '<select name="lti_maprole_'.$ltirole.'_'.$num.'">'.
5877:23): '<option value=""'.$selectnone.'>'.&mt('Select').'</option>';
5878:23): foreach my $role (@courseroles) {
5879:23): unless ($selectnone) {
5880:23): if ($rolemaps{$ltirole} eq $role) {
5881:23): $selected = ' selected="selected"';
5882:23): } else {
5883:23): $selected = '';
5884:23): }
5885:23): }
5886:23): $output .= '<option value="'.$role.'"'.$selected.'>'.
5887:23): &Apache::lonnet::plaintext($role,'Course').
5888:23): '</option>';
5889:23): }
5890:23): $output .= '</select></td>';
5891:23): }
5892:23): $output .= '</tr></table></fieldset>'.
5893:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Creating courses').'</legend>'.
5894:23): '<span class="LC_nobreak">'.&mt('Course created (if absent) on Instructor access').': '.
5895:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="0"'.
5896:23): $checked{'makecrs'}{'N'}.' />'.&mt('No').'</label>'.(' 'x2).
5897:23): '<label><input type="radio" name="lti_makecrs_'.$num.'" value="1"'.
5898:23): $checked{'makecrs'}{'Y'}.' />'.&mt('Yes').'</label></span>'.
5899:23): '</fieldset>'.
5900:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Roles which may self-enroll').'</legend>';
5901:23): foreach my $lticrsrole (@lticourseroles) {
5902:23): $output .= '<span class="LC_nobreak"><label><input type="checkbox" name="lti_selfenroll_'.$num.'" value="'.$lticrsrole.'"'.
5903:23): $checked{'selfenroll'}{$lticrsrole}.' />'.$lticrsrole.'</label> </span> ';
5904:23): }
5905:23): $output .= '</fieldset>'.
5906:23): '<fieldset class="ltioption_crs_'.$num.'" style="display:'.$crssty.'"><legend>'.&mt('Course options').'</legend>'.
5907:23): '<div class="LC_floatleft"><span class="LC_nobreak">'.&mt('Assign users to sections').': '.
5908:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="0"'.
5909:23): $checked{'crssec'}{'N'}.$onclicksec.' />'.&mt('No').'</label>'.(' 'x2).
5910:23): '<label><input type="radio" name="lti_crssec_'.$num.'" value="1"'.
5911:23): $checked{'crssec'}{'Y'}.$onclicksec.' />'.&mt('Yes').'</label></span></div>'.
5912:23): '<div class="LC_floatleft" style="display:'.$crssecfieldsty.';" id="lti_crssecfield_'.$num.'">'.
5913:23): '<span class="LC_nobreak">'.&mt('From').':<label>'.
5914:23): '<input type="radio" name="lti_crssecsrc_'.$num.'" value="course_section_sourcedid"'.
5915:23): $checked{'crssecsrc'}{'sourcedid'}.$onclicksecsrc.' />'.
5916:23): &mt('Standard field').'</label>'.(' 'x2).
5917:23): '<label><input type="radio" name="lti_crssecsrc_'.$num.'" value="other"'.
5918:23): $checked{'crssecsrc'}{'other'}.$onclicksecsrc.' />'.&mt('Other').
5919:23): '</label></span></div><div class="LC_floatleft" style="display:'.$secsrcfieldsty.';" id="lti_secsrcfield_'.$num.'">'.
5920:23): '<input type="text" name="lti_customsection_'.$num.'" value="'.$crssecsrc.'" />'.
5921:23): '</div><div style="padding:0;clear:both;margin:0;border:0"></div>';
5922:23): my ($pb1p1chk,$pb1p0chk,$onclickpb);
5923:23): foreach my $extra ('roster','passback') {
5924:23): my $checkedon = '';
5925:23): my $checkedoff = ' checked="checked"';
5926:23): if ($extra eq 'passback') {
5927:23): $pb1p1chk = ' checked="checked"';
5928:23): $pb1p0chk = '';
5929:23): $onclickpb = ' onclick="toggleLTI(this.form,'."'passback','$num'".');"';
5930:23): } else {
5931:23): $onclickpb = '';
5932:23): }
5933:23): if (ref($current) eq 'HASH') {
5934:23): if (($current->{$extra})) {
5935:23): $checkedon = $checkedoff;
5936:23): $checkedoff = '';
5937:23): if ($extra eq 'passback') {
5938:23): $passbacksty = 'inline-block';
5939:23): }
5940:23): if ($current->{'passbackformat'} eq '1.0') {
5941:23): $pb1p0chk = ' checked="checked"';
5942:23): $pb1p1chk = '';
5943:23): }
5944:23): }
5945:23): }
5946:23): $output .= $lt{$extra}.' '.
5947:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="0"'.$checkedoff.$onclickpb.' />'.
5948:23): &mt('No').'</label>'.(' 'x2).
5949:23): '<label><input type="radio" name="lti_'.$extra.'_'.$num.'" value="1"'.$checkedon.$onclickpb.' />'.
5950:23): &mt('Yes').'</label><br />';
5951:23): }
5952:23): $output .= '<div class="LC_floatleft" style="display:'.$passbacksty.';" id="lti_passback_'.$num.'">'.
5953:23): '<span class="LC_nobreak">'.&mt('Grade format').
5954:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.1"'.$pb1p1chk.' />'.
5955:23): &mt('Outcomes Service (1.1)').'</label>'.(' 'x2).
5956:23): '<label><input type="radio" name="lti_passbackformat_'.$num.'" value="1.0"'.$pb1p0chk.'/>'.
5957:23): &mt('Outcomes Extension (1.0)').'</label></span></div>'.
5958:23): '<div style="padding:0;clear:both;margin:0;border:0"></div></fieldset>';
5959:23): $output .= '</span></div></fieldset>';
5960:23): # '<fieldset><legend>'.&mt('Assigning author roles').'</legend>';
5961:23): #
5962:23): # $output .= '</fieldset>'.
5963:23): # '<fieldset><legend>'.&mt('Assigning domain roles').'</legend>';
5964:23): return $output;
5965:23): }
5966:23):
5967:23): sub ltimenu_titles {
5968:23): return &Apache::lonlocal::texthash(
5969:23): fullname => 'Full name',
5970:23): coursetitle => 'Course title',
5971:23): role => 'Role',
5972:23): logout => 'Logout',
5973:23): grades => 'Grades',
5974:23): );
5(raebur 5975:2): }
5976:2):
18(raebu 5977:24): sub linkprot_suggestions {
5978:24): my ($suggested,$itemcount) = @_;
5979:24): my $count = 0;
5980:24): my $next = 1;
5981:24): my %lt = &Apache::lonlocal::texthash(
5982:24): 'name' => 'Suggested Launcher',
5983:24): 'info' => 'Recommendations',
5984:24): );
5985:24): my ($datatable,$css_class,$dest);
5986:24): if (ref($suggested) eq 'HASH') {
5987:24): my @current = sort { $a <=> $b } keys(%{$suggested});
5988:24): $next += $current[-1];
5989:24): for (my $i=0; $i<@current; $i++) {
5990:24): my $num = $current[$i];
5991:24): my %values;
5992:24): if (ref($suggested->{$num}) eq 'HASH') {
5993:24): %values = %{$suggested->{$num}};
5994:24): } else {
5995:24): next;
5996:24): }
5997:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
5998:24): $datatable .=
5999:24): '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6000:24): '<label><input type="checkbox" name="linkprot_suggested_del" value="'.$i.'" />'."\n".
6001:24): &mt('Delete?').'</label></span></td><td>'."\n".
6002:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6003:24): '<input type="text" size="15" name="linkprot_suggested_name_'.$i.'" value="'.$values{'name'}.'" autocomplete="off" />'."\n".
6004:24): '</fieldset></div>'.
6005:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6006:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_'.$i.'">'.$values{'info'}.'</textarea>'.
6007:24): '</fieldset></div>'.
6008:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6009:24): '<input type="hidden" name="linkprot_suggested_id_'.$i.'" value="'.$num.'" /></td></tr>'."\n";
6010:24): $$itemcount ++;
6011:24): }
6012:24): }
6013:24): $css_class = $$itemcount%2?' class="LC_odd_row"':'';
6014:24): $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'."\n".
6015:24): '<input type="hidden" name="linkprot_suggested_maxnum" value="'.$next.'" />'."\n".
6016:24): '<input type="checkbox" name="linkprot_suggested_add" value="1" />'.&mt('Add').'</span></td>'."\n".
6017:24): '<td>'."\n".
6018:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'name'}.'</legend>'."\n".
6019:24): '<input type="text" size="15" name="linkprot_suggested_name_add" value="" autocomplete="off" />'."\n".
6020:24): '</fieldset></div>'.
6021:24): '<div class="LC_floatleft"><fieldset><legend>'.$lt{'info'}.'</legend>'."\n".
6022:24): '<textarea cols="55" rows="5" name="linkprot_suggested_info_add"></textarea>'.
6023:24): '</fieldset></div>'.
6024:24): '<div style="padding:0;clear:both;margin:0;border:0"></div>'."\n".
6025:24): '</td></tr>'."\n";
6026:24): return $datatable;
6027:24): }
14(raebu 6028:23):
1.121 raeburn 6029: sub print_coursedefaults {
1.139 raeburn 6030: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.16 raeburn 6031: my ($css_class,$datatable,%checkedon,%checkedoff,%defaultchecked,@toggles);
1.121 raeburn 6032: my $itemcount = 1;
1.160.6.16 raeburn 6033: my %choices = &Apache::lonlocal::texthash (
1.160.6.21 raeburn 6034: uploadquota => 'Default quota for files uploaded directly to course/community using Course Editor (MB)',
1.160.6.118.2 20(raebu 6035:24): coursequota => 'Default cumulative quota for all group portfolio spaces in course (MB)',
1.160.6.16 raeburn 6036: anonsurvey_threshold => 'Responder count needed before showing submissions for anonymous surveys',
6037: coursecredits => 'Credits can be specified for courses',
1.160.6.57 raeburn 6038: uselcmath => 'Math preview uses LON-CAPA previewer (javascript) in place of DragMath (Java)',
6039: usejsme => 'Molecule editor uses JSME (HTML5) in place of JME (Java)',
1.160.6.115 raeburn 6040: inline_chem => 'Use inline previewer for chemical reaction response in place of pop-up',
1.160.6.90 raeburn 6041: texengine => 'Default method to display mathematics',
1.160.6.57 raeburn 6042: postsubmit => 'Disable submit button/keypress following student submission',
1.160.6.64 raeburn 6043: canclone => "People who may clone a course (besides course's owner and coordinators)",
1.160.6.70 raeburn 6044: mysqltables => 'Lifetime (s) of "Temporary" MySQL tables (student performance data) on homeserver',
1.160.6.118.2 5(raebur 6045:2): ltiauth => 'Student username in LTI launch of deep-linked URL can be accepted without re-authentication',
14(raebu 6046:23): domexttool => 'External Tools defined in the domain may be used in courses/communities (by type)',
6047:23): exttool => 'External Tools can be defined and configured in courses/communities (by type)',
22(raebu 6048:24): crseditors => 'Available editors for web pages and/or problems created in a course/community',
7(raebur 6049:2): );
1.160.6.21 raeburn 6050: my %staticdefaults = (
6051: anonsurvey_threshold => 10,
6052: uploadquota => 500,
1.160.6.118.2 15(raebu 6053:23): coursequota => 20,
1.160.6.57 raeburn 6054: postsubmit => 60,
1.160.6.70 raeburn 6055: mysqltables => 172800,
1.160.6.118.2 14(raebu 6056:23): domexttool => 1,
6057:23): exttool => 0,
22(raebu 6058:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 6059: );
1.139 raeburn 6060: if ($position eq 'top') {
1.160.6.57 raeburn 6061: %defaultchecked = (
6062: 'uselcmath' => 'on',
6063: 'usejsme' => 'on',
1.160.6.115 raeburn 6064: 'inline_chem' => 'on',
1.160.6.64 raeburn 6065: 'canclone' => 'none',
1.160.6.57 raeburn 6066: );
1.160.6.115 raeburn 6067: @toggles = ('uselcmath','usejsme','inline_chem');
1.160.6.90 raeburn 6068: my $deftex = $Apache::lonnet::deftex;
6069: if (ref($settings) eq 'HASH') {
6070: if ($settings->{'texengine'}) {
6071: if ($settings->{'texengine'} =~ /^(MathJax|mimetex|tth)$/) {
6072: $deftex = $settings->{'texengine'};
6073: }
6074: }
6075: }
6076: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6077: my $mathdisp = '<tr'.$css_class.'><td style="vertical-align: top">'.
6078: '<span class="LC_nobreak">'.$choices{'texengine'}.
6079: '</span></td><td class="LC_right_item">'.
6080: '<select name="texengine">'."\n";
6081: my %texoptions = (
6082: MathJax => 'MathJax',
6083: mimetex => &mt('Convert to Images'),
6084: tth => &mt('TeX to HTML'),
6085: );
6086: foreach my $renderer ('MathJax','mimetex','tth') {
6087: my $selected = '';
6088: if ($renderer eq $deftex) {
6089: $selected = ' selected="selected"';
6090: }
6091: $mathdisp .= '<option value="'.$renderer.'"'.$selected.'>'.$texoptions{$renderer}.'</option>'."\n";
6092: }
6093: $mathdisp .= '</select></td></tr>'."\n";
6094: $itemcount ++;
1.139 raeburn 6095: ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6096: \%choices,$itemcount);
1.160.6.90 raeburn 6097: $datatable = $mathdisp.$datatable;
1.160.6.64 raeburn 6098: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6099: $datatable .=
6100: '<tr'.$css_class.'><td valign="top">'.
6101: '<span class="LC_nobreak">'.$choices{'canclone'}.
6102: '</span></td><td class="LC_left_item">';
6103: my $currcanclone = 'none';
6104: my $onclick;
6105: my @cloneoptions = ('none','domain');
1.160.6.111 raeburn 6106: my %clonetitles = &Apache::lonlocal::texthash (
1.160.6.64 raeburn 6107: none => 'No additional course requesters',
6108: domain => "Any course requester in course's domain",
6109: instcode => 'Course requests for official courses ...',
6110: );
6111: my (%codedefaults,@code_order,@posscodes);
6112: if (&Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
6113: \@code_order) eq 'ok') {
6114: if (@code_order > 0) {
6115: push(@cloneoptions,'instcode');
6116: $onclick = ' onclick="toggleDisplay(this.form,'."'cloneinstcode'".');"';
6117: }
6118: }
6119: if (ref($settings) eq 'HASH') {
6120: if ($settings->{'canclone'}) {
6121: if (ref($settings->{'canclone'}) eq 'HASH') {
6122: if (ref($settings->{'canclone'}{'instcode'}) eq 'ARRAY') {
6123: if (@code_order > 0) {
6124: $currcanclone = 'instcode';
6125: @posscodes = @{$settings->{'canclone'}{'instcode'}};
6126: }
6127: }
6128: } elsif ($settings->{'canclone'} eq 'domain') {
6129: $currcanclone = $settings->{'canclone'};
6130: }
6131: }
6132: }
6133: foreach my $option (@cloneoptions) {
6134: my ($checked,$additional);
6135: if ($currcanclone eq $option) {
6136: $checked = ' checked="checked"';
6137: }
6138: if ($option eq 'instcode') {
6139: if (@code_order) {
6140: my $show = 'none';
6141: if ($checked) {
6142: $show = 'block';
6143: }
1.160.6.118.2 14(raebu 6144:23): $additional = '<div id="cloneinstcode" style="display:'.$show.';" />'.
1.160.6.64 raeburn 6145: &mt('Institutional codes for new and cloned course have identical:').
6146: '<br />';
6147: foreach my $item (@code_order) {
6148: my $codechk;
6149: if ($checked) {
6150: if (grep(/^\Q$item\E$/,@posscodes)) {
6151: $codechk = ' checked="checked"';
6152: }
6153: }
6154: $additional .= '<label>'.
6155: '<input type="checkbox" name="clonecode" value="'.$item.'"'.$codechk.' />'.
6156: $item.'</label>';
6157: }
6158: $additional .= (' 'x2).'('.&mt('check as many as needed').')</div>';
6159: }
6160: }
6161: $datatable .=
6162: '<span class="LC_nobreak"><label><input type="radio" name="canclone"'.$checked.
6163: ' value="'.$option.'"'.$onclick.' />'.$clonetitles{$option}.
6164: '</label> '.$additional.'</span><br />';
6165: }
6166: $datatable .= '</td>'.
6167: '</tr>';
6168: $itemcount ++;
1.139 raeburn 6169: } else {
6170: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.118.2 15(raebu 6171:23): my ($currdefresponder,%defcredits,%curruploadquota,%currcoursequota,
6172:23): %deftimeout,%currmysql);
1.160.6.16 raeburn 6173: my $currusecredits = 0;
1.160.6.57 raeburn 6174: my $postsubmitclient = 1;
1.160.6.118.2 4(raebur 6175:2): my $ltiauth = 0;
14(raebu 6176:23): my %domexttool;
6177:23): my %exttool;
22(raebu 6178:24): my %crseditors;
1.160.6.30 raeburn 6179: my @types = ('official','unofficial','community','textbook');
1.139 raeburn 6180: if (ref($settings) eq 'HASH') {
1.160.6.118.2 4(raebur 6181:2): if ($settings->{'ltiauth'}) {
6182:2): $ltiauth = 1;
6183:2): }
14(raebu 6184:23): if (ref($settings->{'domexttool'}) eq 'HASH') {
6185:23): foreach my $type (@types) {
6186:23): if ($settings->{'domexttool'}->{$type}) {
6187:23): $domexttool{$type} = ' checked="checked"';
6188:23): }
6189:23): }
6190:23): } else {
6191:23): foreach my $type (@types) {
6192:23): if ($staticdefaults{'domexttool'}) {
6193:23): $domexttool{$type} = ' checked="checked"';
6194:23): }
6195:23): }
6196:23): }
6197:23): if (ref($settings->{'exttool'}) eq 'HASH') {
6198:23): foreach my $type (@types) {
6199:23): if ($settings->{'exttool'}->{$type}) {
6200:23): $exttool{$type} = ' checked="checked"';
6201:23): }
6202:23): }
6203:23): }
22(raebu 6204:24): if (ref($settings->{'crseditors'}) eq 'ARRAY') {
6205:24): foreach my $editor (@{$settings->{'crseditors'}}) {
6206:24): $crseditors{$editor} = ' checked="checked"';
6207:24): }
6208:24): } else {
6209:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6210:24): $crseditors{$editor} = ' checked="checked"';
6211:24): }
6212:24): }
1.139 raeburn 6213: $currdefresponder = $settings->{'anonsurvey_threshold'};
1.160.6.21 raeburn 6214: if (ref($settings->{'uploadquota'}) eq 'HASH') {
6215: foreach my $type (keys(%{$settings->{'uploadquota'}})) {
6216: $curruploadquota{$type} = $settings->{'uploadquota'}{$type};
6217: }
6218: }
1.160.6.118.2 15(raebu 6219:23): if (ref($settings->{'coursequota'}) eq 'HASH') {
6220:23): foreach my $type (keys(%{$settings->{'coursequota'}})) {
6221:23): $currcoursequota{$type} = $settings->{'coursequota'}{$type};
6222:23): }
6223:23): }
1.160.6.16 raeburn 6224: if (ref($settings->{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 6225: foreach my $type (@types) {
6226: next if ($type eq 'community');
6227: $defcredits{$type} = $settings->{'coursecredits'}->{$type};
6228: if ($defcredits{$type} ne '') {
6229: $currusecredits = 1;
6230: }
6231: }
6232: }
6233: if (ref($settings->{'postsubmit'}) eq 'HASH') {
6234: if ($settings->{'postsubmit'}->{'client'} eq 'off') {
6235: $postsubmitclient = 0;
6236: foreach my $type (@types) {
6237: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6238: }
6239: } else {
6240: foreach my $type (@types) {
6241: if (ref($settings->{'postsubmit'}->{'timeout'}) eq 'HASH') {
6242: if ($settings->{'postsubmit'}->{'timeout'}->{$type} =~ /^\d+$/) {
6243: $deftimeout{$type} = $settings->{'postsubmit'}->{'timeout'}->{$type};
6244: } else {
6245: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6246: }
6247: } else {
6248: $deftimeout{$type} = $staticdefaults{'postsubmit'};
6249: }
6250: }
6251: }
6252: } else {
6253: foreach my $type (@types) {
6254: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.16 raeburn 6255: }
6256: }
1.160.6.70 raeburn 6257: if (ref($settings->{'mysqltables'}) eq 'HASH') {
6258: foreach my $type (keys(%{$settings->{'mysqltables'}})) {
6259: $currmysql{$type} = $settings->{'mysqltables'}{$type};
6260: }
6261: } else {
6262: foreach my $type (@types) {
6263: $currmysql{$type} = $staticdefaults{'mysqltables'};
6264: }
6265: }
1.160.6.58 raeburn 6266: } else {
6267: foreach my $type (@types) {
6268: $deftimeout{$type} = $staticdefaults{'postsubmit'};
1.160.6.118.2 14(raebu 6269:23): if ($staticdefaults{'domexttool'}) {
6270:23): $domexttool{$type} = ' checked="checked"';
6271:23): }
1.160.6.58 raeburn 6272: }
1.160.6.118.2 22(raebu 6273:24): foreach my $editor (@{$staticdefaults{'crseditors'}}) {
6274:24): $crseditors{$editor} = ' checked="checked"';
6275:24): }
1.139 raeburn 6276: }
6277: if (!$currdefresponder) {
1.160.6.21 raeburn 6278: $currdefresponder = $staticdefaults{'anonsurvey_threshold'};
1.139 raeburn 6279: } elsif ($currdefresponder < 1) {
6280: $currdefresponder = 1;
6281: }
1.160.6.21 raeburn 6282: foreach my $type (@types) {
6283: if ($curruploadquota{$type} eq '') {
6284: $curruploadquota{$type} = $staticdefaults{'uploadquota'};
6285: }
1.160.6.118.2 15(raebu 6286:23): if ($currcoursequota{$type} eq '') {
6287:23): $currcoursequota{$type} = $staticdefaults{'coursequota'};
6288:23): }
1.160.6.21 raeburn 6289: }
1.139 raeburn 6290: $datatable .=
1.160.6.16 raeburn 6291: '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6292: $choices{'anonsurvey_threshold'}.
1.139 raeburn 6293: '</span></td>'.
6294: '<td class="LC_right_item"><span class="LC_nobreak">'.
6295: '<input type="text" name="anonsurvey_threshold"'.
6296: ' value="'.$currdefresponder.'" size="5" /></span>'.
1.160.6.37 raeburn 6297: '</td></tr>'."\n";
6298: $itemcount ++;
6299: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6300: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6301: $choices{'uploadquota'}.
6302: '</span></td>'.
6303: '<td align="right" class="LC_right_item">'.
6304: '<table><tr>';
1.160.6.21 raeburn 6305: foreach my $type (@types) {
6306: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6307: '<input type="text" name="uploadquota_'.$type.'"'.
6308: ' value="'.$curruploadquota{$type}.'" size="5" /></td>';
6309: }
6310: $datatable .= '</tr></table></td></tr>'."\n";
1.160.6.37 raeburn 6311: $itemcount ++;
1.160.6.118.2 15(raebu 6312:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6313:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6314:23): $choices{'coursequota'}.
6315:23): '</span></td>'.
6316:23): '<td style="text-align: right" class="LC_right_item">'.
6317:23): '<table><tr>';
6318:23): foreach my $type (@types) {
6319:23): $datatable .= '<td style="text-align: center">'.&mt($type).'<br />'.
6320:23): '<input type="text" name="coursequota_'.$type.'"'.
6321:23): ' value="'.$currcoursequota{$type}.'" size="5" /></td>';
6322:23): }
6323:23): $datatable .= '</tr></table></td></tr>'."\n";
6324:23): $itemcount ++;
1.160.6.40 raeburn 6325: my $onclick = "toggleDisplay(this.form,'credits');";
1.160.6.16 raeburn 6326: my $display = 'none';
6327: if ($currusecredits) {
6328: $display = 'block';
6329: }
6330: my $additional = '<div id="credits" style="display: '.$display.'">'.
1.160.6.57 raeburn 6331: '<i>'.&mt('Default credits').'</i><br /><table><tr>';
6332: foreach my $type (@types) {
6333: next if ($type eq 'community');
6334: $additional .= '<td align="center">'.&mt($type).'<br />'.
6335: '<input type="text" name="'.$type.'_credits"'.
6336: ' value="'.$defcredits{$type}.'" size="3" /></td>';
6337: }
6338: $additional .= '</tr></table></div>'."\n";
1.160.6.16 raeburn 6339: %defaultchecked = ('coursecredits' => 'off');
6340: @toggles = ('coursecredits');
6341: my $current = {
6342: 'coursecredits' => $currusecredits,
6343: };
6344: (my $table,$itemcount) =
6345: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
1.160.6.57 raeburn 6346: \%choices,$itemcount,$onclick,$additional,'left');
6347: $datatable .= $table;
6348: $onclick = "toggleDisplay(this.form,'studentsubmission');";
6349: my $display = 'none';
6350: if ($postsubmitclient) {
6351: $display = 'block';
6352: }
6353: $additional = '<div id="studentsubmission" style="display: '.$display.'">'.
1.160.6.59 raeburn 6354: &mt('Number of seconds submit is disabled').'<br />'.
6355: '<i>'.&mt('Enter 0 to remain disabled until page reload.').'</i><br />'.
6356: '<table><tr>';
1.160.6.57 raeburn 6357: foreach my $type (@types) {
6358: $additional .= '<td align="center">'.&mt($type).'<br />'.
6359: '<input type="text" name="'.$type.'_timeout" value="'.
6360: $deftimeout{$type}.'" size="5" /></td>';
6361: }
6362: $additional .= '</tr></table></div>'."\n";
6363: %defaultchecked = ('postsubmit' => 'on');
6364: @toggles = ('postsubmit');
1.160.6.70 raeburn 6365: $current = {
6366: 'postsubmit' => $postsubmitclient,
6367: };
1.160.6.57 raeburn 6368: ($table,$itemcount) =
6369: &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6370: \%choices,$itemcount,$onclick,$additional,'left');
1.160.6.16 raeburn 6371: $datatable .= $table;
1.160.6.70 raeburn 6372: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6373: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6374: $choices{'mysqltables'}.
6375: '</span></td>'.
6376: '<td align="right" class="LC_right_item">'.
6377: '<table><tr>';
6378: foreach my $type (@types) {
6379: $datatable .= '<td align="center">'.&mt($type).'<br />'.
6380: '<input type="text" name="mysqltables_'.$type.'"'.
1.160.6.81 raeburn 6381: ' value="'.$currmysql{$type}.'" size="8" /></td>';
1.160.6.70 raeburn 6382: }
6383: $datatable .= '</tr></table></td></tr>'."\n";
6384: $itemcount ++;
1.160.6.118.2 4(raebur 6385:2): %defaultchecked = ('ltiauth' => 'off');
6386:2): @toggles = ('ltiauth');
6387:2): $current = {
6388:2): 'ltiauth' => $ltiauth,
6389:2): };
6390:2): ($table,$itemcount) =
6391:2): &radiobutton_prefs($current,\@toggles,\%defaultchecked,
6392:2): \%choices,$itemcount,undef,undef,'left');
6393:2): $datatable .= $table;
14(raebu 6394:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6395:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6396:23): $choices{'domexttool'}.
6397:23): '</span></td>'.
6398:23): '<td style="text-align: right" class="LC_right_item">'.
6399:23): '<table><tr>';
6400:23): foreach my $type (@types) {
6401:23): $datatable .= '<td style="text-align: left">'.
6402:23): '<span class="LC_nobreak">'.
22(raebu 6403:24): '<label><input type="checkbox" name="domexttool"'.
14(raebu 6404:23): ' value="'.$type.'"'.$domexttool{$type}.' />'.
22(raebu 6405:24): &mt($type).'</label></span></td>'."\n";
14(raebu 6406:23): }
6407:23): $datatable .= '</tr></table></td></tr>'."\n";
4(raebur 6408:2): $itemcount ++;
14(raebu 6409:23): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6410:23): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6411:23): $choices{'exttool'}.
6412:23): '</span></td>'.
6413:23): '<td style="text-align: right" class="LC_right_item">'.
6414:23): '<table><tr>';
6415:23): foreach my $type (@types) {
6416:23): $datatable .= '<td style="text-align: left">'.
6417:23): '<span class="LC_nobreak">'.
22(raebu 6418:24): '<label><input type="checkbox" name="exttool"'.
14(raebu 6419:23): ' value="'.$type.'"'.$exttool{$type}.' />'.
22(raebu 6420:24): &mt($type).'</label></span></td>'."\n";
6421:24): }
6422:24): $datatable .= '</tr></table></td></tr>'."\n";
6423:24): $itemcount ++;
6424:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6425:24): $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6426:24): $choices{'crseditors'}.
6427:24): '</span></td>'.
6428:24): '<td style="text-align: right" class="LC_right_item">'.
6429:24): '<table><tr>';
6430:24): my @editors = ('edit','xml','daxe');
6431:24): my %editornames = &crseditor_titles();
6432:24): foreach my $editor (@editors) {
6433:24): $datatable .= '<td style="text-align: left">'.
6434:24): '<span class="LC_nobreak">'.
6435:24): '<label><input type="checkbox" name="crseditors"'.
6436:24): ' value="'.$editor.'"'.$crseditors{$editor}.' />'.
6437:24): $editornames{$editor}.'</label></span></td>'."\n";
14(raebu 6438:23): }
6439:23): $datatable .= '</tr></table></td></tr>'."\n";
6440:23): }
6441:23): $$rowtotal += $itemcount;
6442:23): return $datatable;
6443:23): }
6444:23):
22(raebu 6445:24): sub crseditor_titles {
6446:24): return &Apache::lonlocal::texthash(
6447:24): edit => 'Standard editor (Edit)',
6448:24): xml => 'Text editor (EditXML)',
6449:24): daxe => 'Daxe editor (Daxe)',
6450:24): );
6451:24): }
6452:24):
20(raebu 6453:24): sub print_authordefaults {
6454:24): my ($position,$dom,$settings,$rowtotal) = @_;
6455:24): my ($css_class,$datatable,%checkedon,%checkedoff);
6456:24): my $itemcount = 1;
6457:24): my %titles = &authordefaults_titles();
6458:24): if ($position eq 'top') {
6459:24): my %defaultchecked = (
6460:24): 'nocodemirror' => 'off',
21(raebu 6461:24): 'daxecollapse' => 'off',
20(raebu 6462:24): 'domcoordacc' => 'on',
6463:24): );
21(raebu 6464:24): my @toggles = ('nocodemirror','daxecollapse','domcoordacc');
20(raebu 6465:24): ($datatable,$itemcount) = &radiobutton_prefs($settings,\@toggles,\%defaultchecked,
6466:24): \%titles,$itemcount);
6467:24): my %staticdefaults = (
6468:24): 'copyright' => 'default',
6469:24): 'sourceavail' => 'closed',
6470:24): );
6471:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6472:24): my %currrights;
6473:24): foreach my $item ('copyright','sourceavail') {
6474:24): $currrights{$item} = $staticdefaults{$item};
6475:24): if (ref($settings) eq 'HASH') {
6476:24): if (exists($settings->{$item})) {
6477:24): $currrights{$item} = $settings->{$item};
6478:24): }
6479:24): }
6480:24): }
6481:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6482:24): '<span class="LC_nobreak">'.$titles{'copyright'}.
6483:24): '</span></td><td class="LC_right_item">'.
6484:24): &selectbox('copyright',$currrights{'copyright'},'',
6485:24): \&Apache::loncommon::copyrightdescription,
6486:24): (grep !/^priv|custom$/,(&Apache::loncommon::copyrightids))).
6487:24): '</td></tr>'."\n";
6488:24): $itemcount ++;
6489:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6490:24): $datatable .= '<tr'.$css_class.'><td style="vertical-align: top">'.
6491:24): '<span class="LC_nobreak">'.$titles{'sourceavail'}.
6492:24): '</span></td><td class="LC_right_item">'.
6493:24): &selectbox('sourceavail',$currrights{'sourceavail'},'',
6494:24): \&Apache::loncommon::source_copyrightdescription,
6495:24): (&Apache::loncommon::source_copyrightids)).
6496:24): '</td></tr>'."\n";
6497:24): } else {
6498:24): $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6499:24): my $curreditors;
6500:24): my %staticdefaults = (
6501:24): editors => ['edit','xml'],
6502:24): authorquota => 500,
6503:24): webdav => 0,
6504:24): );
6505:24): my $curreditors = $staticdefaults{'editors'};
6506:24): if ((ref($settings) eq 'HASH') &&
6507:24): (ref($settings->{'editors'}) eq 'ARRAY')) {
6508:24): $curreditors = $settings->{'editors'};
6509:24): } else {
6510:24): $curreditors = $staticdefaults{'editors'};
6511:24): }
6512:24): my @editors = ('edit','xml','daxe');
6513:24): $datatable = '<tr'.$css_class.'>'."\n".
6514:24): '<td>'.$titles{'editors'}.'</td>'."\n".
6515:24): '<td class="LC_left_item">'."\n".
6516:24): '<span class="LC_nobreak">';
6517:24): foreach my $editor (@editors) {
6518:24): my $checked;
6519:24): if (grep(/^\Q$editor\E$/,@{$curreditors})) {
6520:24): $checked = ' checked="checked"';
6521:24): }
6522:24): $datatable .= '<label>'.
6523:24): '<input type="checkbox" name="author_editors" '.
6524:24): $checked.' value="'.$editor.'" '.
6525:24): 'onclick="javascript:checkEditors(this.form,'."'author_editors'".',this);" />'.
6526:24): $titles{$editor}.'</label> ';
6527:24): }
6528:24): $datatable .= '</span>'."\n".'</td>'."\n".'</tr>'."\n";
6529:24): $itemcount ++;
6530:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6531:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6532:24): my @insttypes;
6533:24): if (ref($types) eq 'ARRAY') {
6534:24): @insttypes = @{$types};
6535:24): }
6536:24): my $typecount = 0;
6537:24): my %domconf = &Apache::lonnet::get_dom('configuration',['quotas'],$dom);
6538:24): my @items = ('webdav','authorquota');
6539:24): my %quotas;
6540:24): if (ref($domconf{'quotas'}) eq 'HASH') {
6541:24): %quotas = %{$domconf{'quotas'}};
6542:24): foreach my $item (@items) {
6543:24): if (ref($quotas{$item}) eq 'HASH') {
6544:24): foreach my $type (@insttypes,'default') {
6545:24): if ($item eq 'authorquota') {
6546:24): if ($quotas{$item}{$type} !~ /^\d+$/) {
6547:24): $quotas{$item}{$type} = $staticdefaults{$item};
6548:24): }
6549:24): } elsif ($item eq 'webdav') {
6550:24): if ($quotas{$item}{$type} !~ /^(0|1)$/) {
6551:24): $quotas{$item}{$type} = $staticdefaults{$item};
6552:24): }
6553:24): }
6554:24): }
6555:24): } else {
6556:24): foreach my $type (@insttypes,'default') {
6557:24): $quotas{$item}{$type} = $staticdefaults{$item};
6558:24): }
6559:24): }
6560:24): }
6561:24): } else {
6562:24): foreach my $item (@items) {
6563:24): foreach my $type (@insttypes,'default') {
6564:24): $quotas{$item}{$type} = $staticdefaults{$item};
6565:24): }
6566:24): }
6567:24): }
6568:24): if (ref($usertypes) eq 'HASH') {
6569:24): my $numinrow = 4;
6570:24): my $onclick = '';
6571:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6572:24): $numinrow,$othertitle,'authorquota',
6573:24): \$itemcount,$onclick);
6574:24): $itemcount ++;
6575:24): $datatable .= &insttypes_row(\%quotas,$types,$usertypes,$dom,
6576:24): $numinrow,$othertitle,'webdav',
6577:24): \$itemcount);
6578:24): $itemcount ++;
6579:24): }
6580:24): my $checkedno = ' checked="checked"';
6581:24): my ($checkedon,$checkedoff);
6582:24): if (ref($quotas{'webdav'}) eq 'HASH') {
6583:24): if ($quotas{'webdav'}{'_LC_adv'} =~ /^0|1$/) {
6584:24): if ($quotas{'webdav'}{'_LC_adv'}) {
6585:24): $checkedon = $checkedno;
6586:24): } else {
6587:24): $checkedoff = $checkedno;
6588:24): }
6589:24): undef($checkedno);
6590:24): }
6591:24): }
6592:24): $css_class = $itemcount%2?' class="LC_odd_row"':'';
6593:24): $datatable .= '<tr'.$css_class.'>'.
6594:24): '<td>'.$titles{'webdav_LC_adv'}.'<br />'.
6595:24): $titles{'webdav_LC_adv_over'}.
6596:24): '</td>'.
6597:24): '<td class="LC_left_item">';
6598:24): foreach my $option ('none','off','on') {
6599:24): my ($text,$val,$checked);
6600:24): if ($option eq 'none') {
6601:24): $text = $titles{'none'};
6602:24): $val = '';
6603:24): $checked = $checkedno;
6604:24): } elsif ($option eq 'off') {
6605:24): $text = $titles{'overoff'};
6606:24): $val = 0;
6607:24): $checked = $checkedoff;
6608:24): } elsif ($option eq 'on') {
6609:24): $text = $titles{'overon'};
6610:24): $val = 1;
6611:24): $checked = $checkedon;
6612:24): }
6613:24): $datatable .= '<span class="LC_nobreak"><label>'.
6614:24): '<input type="radio" name="webdav_LC_adv"'.
6615:24): ' value="'.$val.'"'.$checked.' />'.
6616:24): $text.'</label></span> ';
6617:24): }
6618:24): $datatable .= '</td></tr>';
6619:24): $itemcount ++;
22(raebu 6620:24): my %defchecked = (
6621:24): 'archive' => 'off',
6622:24): );
6623:24): my @toggles = ('archive');
6624:24): (my $archive,$itemcount) = &radiobutton_prefs($settings,['archive'],
6625:24): {'archive' => 'off'},
6626:24): \%titles,$itemcount);
6627:24): $datatable .= $archive."\n";
6628:24): $itemcount ++;
20(raebu 6629:24): }
6630:24): $$rowtotal += $itemcount;
6631:24): return $datatable;
6632:24): }
6633:24):
6634:24): sub authordefaults_titles {
6635:24): return &Apache::lonlocal::texthash(
6636:24): copyright => 'Copyright/Distribution',
6637:24): sourceavail => ' Source Available',
6638:24): editors => 'Available Editors',
6639:24): webdav => 'WebDAV',
6640:24): authorquota => 'Authoring Space quotas (MB)',
6641:24): nocodemirror => 'Deactivate CodeMirror for EditXML editor',
21(raebu 6642:24): daxecollapse => 'Daxe editor: LON-CAPA standard menus start collapsed',
20(raebu 6643:24): domcoordacc => 'Dom. Coords. can enter Authoring Spaces in domain',
6644:24): edit => 'Standard editor (Edit)',
6645:24): xml => 'Text editor (EditXML)',
6646:24): daxe => 'Daxe editor (Daxe)',
6647:24): webdav_LC_adv => 'WebDAV access for LON-CAPA "advanced" users',
6648:24): webdav_LC_adv_over => '(overrides access based on affiliation, if set)',
6649:24): none => 'No override set',
6650:24): overon => 'Override -- webDAV on',
6651:24): overoff => 'Override -- webDAV off',
22(raebu 6652:24): archive => 'Authors can download tar.gz file of Authoring Space',
20(raebu 6653:24): );
6654:24): }
6655:24):
6656:24): sub selectbox {
6657:24): my ($name,$value,$readonly,$functionref,@idlist)=@_;
6658:24): my $selout = '<select name="'.$name.'">';
6659:24): foreach my $id (@idlist) {
6660:24): $selout.='<option value="'.$id.'"';
6661:24): if ($id eq $value) {
6662:24): $selout.=' selected="selected"';
6663:24): }
6664:24): if ($readonly) {
6665:24): $selout .= ' disabled="disabled"';
6666:24): }
6667:24): $selout.='>'.&{$functionref}($id).'</option>';
6668:24): }
6669:24): $selout.='</select>';
6670:24): return $selout;
6671:24): }
6672:24):
14(raebu 6673:23): sub print_selfenrollment {
1.160.6.37 raeburn 6674: my ($position,$dom,$settings,$rowtotal) = @_;
6675: my ($css_class,$datatable);
6676: my $itemcount = 1;
6677: my @types = ('official','unofficial','community','textbook');
6678: if (($position eq 'top') || ($position eq 'middle')) {
6679: my ($rowsref,$titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
6680: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
6681: my @rows;
6682: my $key;
6683: if ($position eq 'top') {
6684: $key = 'admin';
6685: if (ref($rowsref) eq 'ARRAY') {
6686: @rows = @{$rowsref};
6687: }
6688: } elsif ($position eq 'middle') {
6689: $key = 'default';
6690: @rows = ('types','registered','approval','limit');
6691: }
6692: foreach my $row (@rows) {
6693: if (defined($titlesref->{$row})) {
6694: $itemcount ++;
6695: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6696: $datatable .= '<tr'.$css_class.'>'.
6697: '<td>'.$titlesref->{$row}.'</td>'.
6698: '<td class="LC_left_item">'.
6699: '<table><tr>';
6700: my (%current,%currentcap);
6701: if (ref($settings) eq 'HASH') {
6702: if (ref($settings->{$key}) eq 'HASH') {
6703: foreach my $type (@types) {
6704: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6705: $current{$type} = $settings->{$key}->{$type}->{$row};
6706: }
6707: if (($row eq 'limit') && ($key eq 'default')) {
6708: if (ref($settings->{$key}->{$type}) eq 'HASH') {
6709: $currentcap{$type} = $settings->{$key}->{$type}->{'cap'};
6710: }
6711: }
6712: }
6713: }
6714: }
6715: my %roles = (
6716: '0' => &Apache::lonnet::plaintext('dc'),
6717: );
6718:
6719: foreach my $type (@types) {
6720: unless (($row eq 'registered') && ($key eq 'default')) {
6721: $datatable .= '<th>'.&mt($type).'</th>';
6722: }
6723: }
6724: unless (($row eq 'registered') && ($key eq 'default')) {
6725: $datatable .= '</tr><tr>';
6726: }
6727: foreach my $type (@types) {
6728: if ($type eq 'community') {
6729: $roles{'1'} = &mt('Community personnel');
6730: } else {
6731: $roles{'1'} = &mt('Course personnel');
6732: }
6733: $datatable .= '<td style="vertical-align: top">';
6734: if ($position eq 'top') {
6735: my %checked;
6736: if ($current{$type} eq '0') {
6737: $checked{'0'} = ' checked="checked"';
6738: } else {
6739: $checked{'1'} = ' checked="checked"';
6740: }
6741: foreach my $role ('1','0') {
6742: $datatable .= '<span class="LC_nobreak"><label>'.
6743: '<input type="radio" name="selfenrolladmin_'.$row.'_'.$type.'" '.
6744: 'value="'.$role.'"'.$checked{$role}.' />'.
6745: $roles{$role}.'</label></span> ';
6746: }
6747: } else {
6748: if ($row eq 'types') {
6749: my %checked;
6750: if ($current{$type} =~ /^(all|dom)$/) {
6751: $checked{$1} = ' checked="checked"';
6752: } else {
6753: $checked{''} = ' checked="checked"';
6754: }
6755: foreach my $val ('','dom','all') {
6756: $datatable .= '<span class="LC_nobreak"><label>'.
6757: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6758: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6759: }
6760: } elsif ($row eq 'registered') {
6761: my %checked;
6762: if ($current{$type} eq '1') {
6763: $checked{'1'} = ' checked="checked"';
6764: } else {
6765: $checked{'0'} = ' checked="checked"';
6766: }
6767: foreach my $val ('0','1') {
6768: $datatable .= '<span class="LC_nobreak"><label>'.
6769: '<input type ="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6770: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6771: }
6772: } elsif ($row eq 'approval') {
6773: my %checked;
6774: if ($current{$type} =~ /^([12])$/) {
6775: $checked{$1} = ' checked="checked"';
6776: } else {
6777: $checked{'0'} = ' checked="checked"';
6778: }
6779: for my $val (0..2) {
6780: $datatable .= '<span class="LC_nobreak"><label>'.
6781: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6782: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6783: }
6784: } elsif ($row eq 'limit') {
6785: my %checked;
6786: if ($current{$type} =~ /^(allstudents|selfenrolled)$/) {
6787: $checked{$1} = ' checked="checked"';
6788: } else {
6789: $checked{'none'} = ' checked="checked"';
6790: }
6791: my $cap;
6792: if ($currentcap{$type} =~ /^\d+$/) {
6793: $cap = $currentcap{$type};
6794: }
6795: foreach my $val ('none','allstudents','selfenrolled') {
6796: $datatable .= '<span class="LC_nobreak"><label>'.
6797: '<input type="radio" name="selfenrolldefault_'.$row.'_'.$type.'" '.
6798: 'value="'.$val.'"'.$checked{$val}.' />'.$descs{$row}{$val}.'</label></span> ';
6799: }
6800: $datatable .= '<br />'.
6801: '<span class="LC_nobreak">'.&mt('Maximum allowed: ').
6802: '<input type="text" name="selfenrolldefault_cap_'.$type.'" size = "5" value="'.$cap.'" />'.
6803: '</span>';
6804: }
6805: }
6806: $datatable .= '</td>';
6807: }
6808: $datatable .= '</tr>';
6809: }
6810: $datatable .= '</table></td></tr>';
6811: }
6812: } elsif ($position eq 'bottom') {
1.160.6.39 raeburn 6813: $datatable .= &print_validation_rows('selfenroll',$dom,$settings,\$itemcount);
6814: }
6815: $$rowtotal += $itemcount;
6816: return $datatable;
6817: }
6818:
6819: sub print_validation_rows {
6820: my ($caller,$dom,$settings,$rowtotal) = @_;
6821: my ($itemsref,$namesref,$fieldsref);
6822: if ($caller eq 'selfenroll') {
6823: ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
6824: } elsif ($caller eq 'requestcourses') {
6825: ($itemsref,$namesref,$fieldsref) = &Apache::loncoursequeueadmin::requestcourses_validation_types();
6826: }
6827: my %currvalidation;
6828: if (ref($settings) eq 'HASH') {
6829: if (ref($settings->{'validation'}) eq 'HASH') {
6830: %currvalidation = %{$settings->{'validation'}};
1.160.6.37 raeburn 6831: }
1.160.6.39 raeburn 6832: }
6833: my $datatable;
6834: my $itemcount = 0;
6835: foreach my $item (@{$itemsref}) {
6836: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
6837: $datatable .= '<tr'.$css_class.'><td><span class="LC_nobreak">'.
6838: $namesref->{$item}.
6839: '</span></td>'.
6840: '<td class="LC_left_item">';
6841: if (($item eq 'url') || ($item eq 'button')) {
6842: $datatable .= '<span class="LC_nobreak">'.
6843: '<input type="text" name="'.$caller.'_validation_'.$item.'"'.
6844: ' value="'.$currvalidation{$item}.'" size="50" /></span>';
6845: } elsif ($item eq 'fields') {
6846: my @currfields;
6847: if (ref($currvalidation{$item}) eq 'ARRAY') {
6848: @currfields = @{$currvalidation{$item}};
6849: }
6850: foreach my $field (@{$fieldsref}) {
6851: my $check = '';
6852: if (grep(/^\Q$field\E$/,@currfields)) {
6853: $check = ' checked="checked"';
6854: }
6855: $datatable .= '<span class="LC_nobreak"><label>'.
6856: '<input type="checkbox" name="'.$caller.'_validation_fields"'.
6857: ' value="'.$field.'"'.$check.' />'.$field.
6858: '</label></span> ';
6859: }
6860: } elsif ($item eq 'markup') {
1.160.6.87 raeburn 6861: $datatable .= '<textarea name="'.$caller.'_validation_markup" cols="50" rows="5">'.
1.160.6.39 raeburn 6862: $currvalidation{$item}.
1.160.6.37 raeburn 6863: '</textarea>';
1.160.6.39 raeburn 6864: }
6865: $datatable .= '</td></tr>'."\n";
6866: if (ref($rowtotal)) {
1.160.6.37 raeburn 6867: $itemcount ++;
6868: }
1.139 raeburn 6869: }
1.160.6.39 raeburn 6870: if ($caller eq 'requestcourses') {
6871: my %currhash;
1.160.6.51 raeburn 6872: if (ref($settings) eq 'HASH') {
6873: if (ref($settings->{'validation'}) eq 'HASH') {
6874: if ($settings->{'validation'}{'dc'} ne '') {
6875: $currhash{$settings->{'validation'}{'dc'}} = 1;
6876: }
1.160.6.39 raeburn 6877: }
6878: }
6879: my $numinrow = 2;
6880: my ($numdc,$dctable,$rows) = &active_dc_picker($dom,$numinrow,'radio',
6881: 'validationdc',%currhash);
1.160.6.50 raeburn 6882: my $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
1.160.6.87 raeburn 6883: $datatable .= '<tr'.$css_class.'><td>';
1.160.6.39 raeburn 6884: if ($numdc > 1) {
1.160.6.50 raeburn 6885: $datatable .= &mt('Course creation processed as: (choose Dom. Coord.)');
1.160.6.39 raeburn 6886: } else {
1.160.6.50 raeburn 6887: $datatable .= &mt('Course creation processed as: ');
1.160.6.39 raeburn 6888: }
1.160.6.50 raeburn 6889: $datatable .= '</td><td class="LC_left_item">'.$dctable.'</td></tr>';
1.160.6.39 raeburn 6890: $itemcount ++;
6891: }
6892: if (ref($rowtotal)) {
6893: $$rowtotal += $itemcount;
6894: }
1.121 raeburn 6895: return $datatable;
1.118 jms 6896: }
6897:
1.160.6.98 raeburn 6898: sub print_passwords {
6899: my ($position,$dom,$confname,$settings,$rowtotal) = @_;
6900: my ($datatable,$css_class);
6901: my $itemcount = 0;
6902: my %titles = &Apache::lonlocal::texthash (
6903: captcha => '"Forgot Password" CAPTCHA validation',
6904: link => 'Reset link expiration (hours)',
6905: case => 'Case-sensitive usernames/e-mail',
6906: prelink => 'Information required (form 1)',
6907: postlink => 'Information required (form 2)',
6908: emailsrc => 'LON-CAPA e-mail address type(s)',
6909: customtext => 'Domain specific text (HTML)',
6910: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
6911: intauth_check => 'Check bcrypt cost if authenticated',
6912: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
6913: permanent => 'Permanent e-mail address',
6914: critical => 'Critical notification address',
6915: notify => 'Notification address',
6916: min => 'Minimum password length',
6917: max => 'Maximum password length',
6918: chars => 'Required characters',
6919: numsaved => 'Number of previous passwords to save and disallow reuse',
6920: );
6921: if ($position eq 'top') {
6922: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
6923: my $shownlinklife = 2;
6924: my $prelink = 'both';
6925: my (%casesens,%postlink,%emailsrc,$nostdtext,$customurl);
6926: if (ref($settings) eq 'HASH') {
6927: if ($settings->{resetlink} =~ /^\d+(|\.\d*)$/) {
6928: $shownlinklife = $settings->{resetlink};
6929: }
6930: if (ref($settings->{resetcase}) eq 'ARRAY') {
6931: map { $casesens{$_} = 1; } (@{$settings->{resetcase}});
6932: }
6933: if ($settings->{resetprelink} =~ /^(both|either)$/) {
6934: $prelink = $settings->{resetprelink};
6935: }
6936: if (ref($settings->{resetpostlink}) eq 'HASH') {
6937: %postlink = %{$settings->{resetpostlink}};
6938: }
6939: if (ref($settings->{resetemail}) eq 'ARRAY') {
6940: map { $emailsrc{$_} = 1; } (@{$settings->{resetemail}});
6941: }
6942: if ($settings->{resetremove}) {
6943: $nostdtext = 1;
6944: }
6945: if ($settings->{resetcustom}) {
6946: $customurl = $settings->{resetcustom};
6947: }
6948: } else {
6949: if (ref($types) eq 'ARRAY') {
6950: foreach my $item (@{$types}) {
6951: $casesens{$item} = 1;
6952: $postlink{$item} = ['username','email'];
6953: }
6954: }
6955: $casesens{'default'} = 1;
6956: $postlink{'default'} = ['username','email'];
6957: $prelink = 'both';
6958: %emailsrc = (
6959: permanent => 1,
6960: critical => 1,
6961: notify => 1,
6962: );
6963: }
6964: $datatable = &captcha_choice('passwords',$settings,$$rowtotal);
6965: $itemcount ++;
6966: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6967: $datatable .= '<tr'.$css_class.'><td>'.$titles{'link'}.'</td>'.
6968: '<td class="LC_left_item">'.
6969: '<input type="textbox" value="'.$shownlinklife.'" '.
6970: 'name="passwords_link" size="3" /></td></tr>';
6971: $itemcount ++;
6972: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6973: $datatable .= '<tr'.$css_class.'><td>'.$titles{'case'}.'</td>'.
6974: '<td class="LC_left_item">';
6975: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
6976: foreach my $item (@{$types}) {
6977: my $checkedcase;
6978: if ($casesens{$item}) {
6979: $checkedcase = ' checked="checked"';
6980: }
6981: $datatable .= '<span class="LC_nobreak"><label>'.
6982: '<input type="checkbox" name="passwords_case_sensitive" value="'.
6983: $item.'"'.$checkedcase.' />'.$usertypes->{$item}.'</label>'.
1.160.6.104 raeburn 6984: '</span> ';
1.160.6.98 raeburn 6985: }
6986: }
6987: my $checkedcase;
6988: if ($casesens{'default'}) {
6989: $checkedcase = ' checked="checked"';
6990: }
6991: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
6992: 'name="passwords_case_sensitive" value="default"'.$checkedcase.' />'.
6993: $othertitle.'</label></span></td>';
6994: $itemcount ++;
6995: $css_class = $itemcount%2?' class="LC_odd_row"':'';
6996: my %checkedpre = (
6997: both => ' checked="checked"',
6998: either => '',
6999: );
7000: if ($prelink eq 'either') {
7001: $checkedpre{either} = ' checked="checked"';
7002: $checkedpre{both} = '';
7003: }
7004: $datatable .= '<tr'.$css_class.'><td>'.$titles{'prelink'}.'</td>'.
7005: '<td class="LC_left_item"><span class="LC_nobreak">'.
7006: '<label><input type="radio" name="passwords_prelink" value="both"'.$checkedpre{'both'}.' />'.
7007: &mt('Both username and e-mail address').'</label></span> '.
7008: '<span class="LC_nobreak"><label>'.
7009: '<input type="radio" name="passwords_prelink" value="either"'.$checkedpre{'either'}.' />'.
7010: &mt('Either username or e-mail address').'</label></span></td></tr>';
7011: $itemcount ++;
7012: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7013: $datatable .= '<tr'.$css_class.'><td>'.$titles{'postlink'}.'</td>'.
7014: '<td class="LC_left_item">';
7015: my %postlinked;
7016: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7017: foreach my $item (@{$types}) {
7018: undef(%postlinked);
7019: $datatable .= '<fieldset style="display: inline-block;">'.
7020: '<legend>'.$usertypes->{$item}.'</legend>';
7021: if (ref($postlink{$item}) eq 'ARRAY') {
7022: map { $postlinked{$_} = 1; } (@{$postlink{$item}});
7023: }
7024: foreach my $field ('email','username') {
7025: my $checked;
7026: if ($postlinked{$field}) {
7027: $checked = ' checked="checked"';
7028: }
7029: $datatable .= '<span class="LC_nobreak"><label>'.
7030: '<input type="checkbox" name="passwords_postlink_'.$item.'" value="'.
7031: $field.'"'.$checked.' />'.$field.'</label>'.
7032: '<span> ';
7033: }
7034: $datatable .= '</fieldset>';
7035: }
7036: }
7037: if (ref($postlink{'default'}) eq 'ARRAY') {
7038: map { $postlinked{$_} = 1; } (@{$postlink{'default'}});
7039: }
7040: $datatable .= '<fieldset style="display: inline-block;">'.
7041: '<legend>'.$othertitle.'</legend>';
7042: foreach my $field ('email','username') {
7043: my $checked;
7044: if ($postlinked{$field}) {
7045: $checked = ' checked="checked"';
7046: }
7047: $datatable .= '<span class="LC_nobreak"><label>'.
7048: '<input type="checkbox" name="passwords_postlink_default" value="'.
7049: $field.'"'.$checked.' />'.$field.'</label>'.
7050: '<span> ';
7051: }
7052: $datatable .= '</fieldset></td></tr>';
7053: $itemcount ++;
7054: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7055: $datatable .= '<tr'.$css_class.'><td>'.$titles{'emailsrc'}.'</td>'.
7056: '<td class="LC_left_item">';
7057: foreach my $type ('permanent','critical','notify') {
7058: my $checkedemail;
7059: if ($emailsrc{$type}) {
7060: $checkedemail = ' checked="checked"';
7061: }
7062: $datatable .= '<span class="LC_nobreak"><label>'.
7063: '<input type="checkbox" name="passwords_emailsrc" value="'.
7064: $type.'"'.$checkedemail.' />'.$titles{$type}.'</label>'.
7065: '<span> ';
7066: }
7067: $datatable .= '</td></tr>';
7068: $itemcount ++;
7069: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7070: my $switchserver = &check_switchserver($dom,$confname);
7071: my ($showstd,$noshowstd);
7072: if ($nostdtext) {
7073: $noshowstd = ' checked="checked"';
7074: } else {
7075: $showstd = ' checked="checked"';
7076: }
7077: $datatable .= '<tr'.$css_class.'><td>'.$titles{'customtext'}.'</td>'.
7078: '<td class="LC_left_item"><span class="LC_nobreak">'.
7079: &mt('Retain standard text:').
7080: '<label><input type="radio" name="passwords_stdtext" value="1"'.$showstd.' />'.
7081: &mt('Yes').'</label>'.' '.
7082: '<label><input type="radio" name="passwords_stdtext" value="0"'.$noshowstd.' />'.
7083: &mt('No').'</label></span><br />'.
7084: '<span class="LC_fontsize_small">'.
7085: &mt('(If you use the same account ... reset a password from this page.)').'</span><br /><br />'.
7086: &mt('Include custom text:');
7087: if ($customurl) {
1.160.6.104 raeburn 7088: my $link = &Apache::loncommon::modal_link($customurl,&mt('custom text'),600,500,
1.160.6.98 raeburn 7089: undef,undef,undef,undef,'background-color:#ffffff');
7090: $datatable .= '<span class="LC_nobreak"> '.$link.
7091: '<label><input type="checkbox" name="passwords_custom_del"'.
7092: ' value="1" />'.&mt('Delete?').'</label></span>'.
7093: ' <span class="LC_nobreak"> '.&mt('Replace:').'</span>';
7094: }
7095: if ($switchserver) {
7096: $datatable .= '<span class="LC_nobreak"> '.&mt('Upload to library server: [_1]',$switchserver).'</span>';
7097: } else {
7098: $datatable .='<span class="LC_nobreak"> '.
7099: '<input type="file" name="passwords_customfile" /></span>';
7100: }
7101: $datatable .= '</td></tr>';
7102: } elsif ($position eq 'middle') {
7103: my %domconf = &Apache::lonnet::get_dom('configuration',['defaults'],$dom);
7104: my @items = ('intauth_cost','intauth_check','intauth_switch');
7105: my %defaults;
7106: if (ref($domconf{'defaults'}) eq 'HASH') {
7107: %defaults = %{$domconf{'defaults'}};
7108: if ($defaults{'intauth_cost'} !~ /^\d+$/) {
7109: $defaults{'intauth_cost'} = 10;
7110: }
7111: if ($defaults{'intauth_check'} !~ /^(0|1|2)$/) {
7112: $defaults{'intauth_check'} = 0;
7113: }
7114: if ($defaults{'intauth_switch'} !~ /^(0|1|2)$/) {
7115: $defaults{'intauth_switch'} = 0;
7116: }
7117: } else {
7118: %defaults = (
7119: 'intauth_cost' => 10,
7120: 'intauth_check' => 0,
7121: 'intauth_switch' => 0,
7122: );
7123: }
7124: foreach my $item (@items) {
7125: if ($itemcount%2) {
7126: $css_class = '';
7127: } else {
7128: $css_class = ' class="LC_odd_row" ';
7129: }
7130: $datatable .= '<tr'.$css_class.'>'.
7131: '<td><span class="LC_nobreak">'.$titles{$item}.
7132: '</span></td><td class="LC_left_item" colspan="3">';
7133: if ($item eq 'intauth_switch') {
7134: my @options = (0,1,2);
7135: my %optiondesc = &Apache::lonlocal::texthash (
7136: 0 => 'No',
7137: 1 => 'Yes',
7138: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
7139: );
7140: $datatable .= '<table width="100%">';
7141: foreach my $option (@options) {
7142: my $checked = ' ';
7143: if ($defaults{$item} eq $option) {
7144: $checked = ' checked="checked"';
7145: }
7146: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7147: '<label><input type="radio" name="'.$item.
7148: '" value="'.$option.'"'.$checked.' />'.
7149: $optiondesc{$option}.'</label></span></td></tr>';
7150: }
7151: $datatable .= '</table>';
7152: } elsif ($item eq 'intauth_check') {
7153: my @options = (0,1,2);
7154: my %optiondesc = &Apache::lonlocal::texthash (
7155: 0 => 'No',
7156: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
7157: 2 => 'Yes, disallow login if stored cost is less than domain default',
7158: );
7159: $datatable .= '<table width="100%">';
7160: foreach my $option (@options) {
7161: my $checked = ' ';
7162: my $onclick;
7163: if ($defaults{$item} eq $option) {
7164: $checked = ' checked="checked"';
7165: }
7166: if ($option == 2) {
7167: $onclick = ' onclick="javascript:warnIntAuth(this);"';
7168: }
7169: $datatable .= '<tr><td class="LC_left_item"><span class="LC_nobreak">'.
7170: '<label><input type="radio" name="'.$item.
7171: '" value="'.$option.'"'.$checked.$onclick.' />'.
7172: $optiondesc{$option}.'</label></span></td></tr>';
7173: }
7174: $datatable .= '</table>';
7175: } else {
7176: $datatable .= '<input type="text" name="'.$item.'" value="'.
7177: $defaults{$item}.'" size="3" onblur="javascript:warnIntAuth(this);" />';
7178: }
7179: $datatable .= '</td></tr>';
7180: $itemcount ++;
7181: }
7182: } elsif ($position eq 'lower') {
1.160.6.118.2 5(raebur 7183:2): $datatable .= &password_rules('passwords',\$itemcount,$settings);
1.160.6.98 raeburn 7184: } else {
7185: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
7186: my %ownerchg = (
7187: by => {},
7188: for => {},
7189: );
7190: my %ownertitles = &Apache::lonlocal::texthash (
7191: by => 'Course owner status(es) allowed',
7192: for => 'Student status(es) allowed',
7193: );
7194: if (ref($settings) eq 'HASH') {
7195: if (ref($settings->{crsownerchg}) eq 'HASH') {
7196: if (ref($settings->{crsownerchg}{'by'}) eq 'ARRAY') {
7197: map { $ownerchg{by}{$_} = 1; } (@{$settings->{crsownerchg}{'by'}});
7198: }
7199: if (ref($settings->{crsownerchg}{'for'}) eq 'ARRAY') {
7200: map { $ownerchg{for}{$_} = 1; } (@{$settings->{crsownerchg}{'for'}});
7201: }
7202: }
7203: }
7204: $css_class = $itemcount%2?' class="LC_odd_row"':'';
7205: $datatable .= '<tr '.$css_class.'>'.
7206: '<td>'.
7207: &mt('Requirements').'<ul>'.
7208: '<li>'.&mt("Course 'type' is not a Community").'</li>'.
7209: '<li>'.&mt('User is Course Coordinator and also course owner').'</li>'.
7210: '<li>'.&mt("Student's only active roles are student role(s) in course(s) owned by this user").'</li>'.
7211: '<li>'.&mt('User, course, and student share same domain').'</li>'.
7212: '</ul>'.
7213: '</td>'.
7214: '<td class="LC_left_item">';
7215: foreach my $item ('by','for') {
7216: $datatable .= '<fieldset style="display: inline-block;">'.
7217: '<legend>'.$ownertitles{$item}.'</legend>';
7218: if ((ref($types) eq 'ARRAY') && (ref($usertypes) eq 'HASH')) {
7219: foreach my $type (@{$types}) {
7220: my $checked;
7221: if ($ownerchg{$item}{$type}) {
7222: $checked = ' checked="checked"';
7223: }
7224: $datatable .= '<span class="LC_nobreak"><label>'.
7225: '<input type="checkbox" name="passwords_crsowner_'.$item.'" value="'.
7226: $type.'"'.$checked.' />'.$usertypes->{$type}.'</label>'.
1.160.6.104 raeburn 7227: '</span> ';
1.160.6.98 raeburn 7228: }
7229: }
7230: my $checked;
7231: if ($ownerchg{$item}{'default'}) {
7232: $checked = ' checked="checked"';
7233: }
7234: $datatable .= '<span class="LC_nobreak"><label><input type="checkbox" '.
7235: 'name="passwords_crsowner_'.$item.'" value="default"'.$checked.' />'.
7236: $othertitle.'</label></span></fieldset>';
7237: }
7238: $datatable .= '</td></tr>';
7239: }
7240: return $datatable;
7241: }
7242:
1.160.6.118.2 5(raebur 7243:2): sub password_rules {
7244:2): my ($prefix,$itemcountref,$settings) = @_;
7245:2): my ($min,$max,%chars,$numsaved,$numinrow);
7246:2): my %titles;
7247:2): if ($prefix eq 'passwords') {
7248:2): %titles = &Apache::lonlocal::texthash (
7249:2): min => 'Minimum password length',
7250:2): max => 'Maximum password length',
7251:2): chars => 'Required characters',
7252:2): );
14(raebu 7253:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 7254:2): %titles = &Apache::lonlocal::texthash (
7255:2): min => 'Minimum secret length',
7256:2): max => 'Maximum secret length',
7257:2): chars => 'Required characters',
7258:2): );
7259:2): }
7260:2): $min = $Apache::lonnet::passwdmin;
7261:2): my $datatable;
7262:2): my $itemcount;
7263:2): if (ref($itemcountref)) {
7264:2): $itemcount = $$itemcountref;
7265:2): }
7266:2): if (ref($settings) eq 'HASH') {
7267:2): if ($settings->{min}) {
7268:2): $min = $settings->{min};
7269:2): }
7270:2): if ($settings->{max}) {
7271:2): $max = $settings->{max};
7272:2): }
7273:2): if (ref($settings->{chars}) eq 'ARRAY') {
7274:2): map { $chars{$_} = 1; } (@{$settings->{chars}});
7275:2): }
7276:2): if ($prefix eq 'passwords') {
7277:2): if ($settings->{numsaved}) {
7278:2): $numsaved = $settings->{numsaved};
7279:2): }
7280:2): }
7281:2): }
7282:2): my %rulenames = &Apache::lonlocal::texthash(
7283:2): uc => 'At least one upper case letter',
7284:2): lc => 'At least one lower case letter',
7285:2): num => 'At least one number',
7286:2): spec => 'At least one non-alphanumeric',
7287:2): );
7288:2): my $css_class = $itemcount%2?' class="LC_odd_row"':'';
7289:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'min'}.'</td>'.
7290:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7291:2): '<input type="text" name="'.$prefix.'_min" value="'.$min.'" size="3" '.
7292:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7293:2): '<span class="LC_fontsize_small"> '.&mt('(Enter an integer: 7 or larger)').'</span>'.
7294:2): '</span></td></tr>';
7295:2): $itemcount ++;
7296:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7297:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'max'}.'</td>'.
7298:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7299:2): '<input type="text" name="'.$prefix.'_max" value="'.$max.'" size="3" '.
7300:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7301:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank for no maximum)').'</span>'.
7302:2): '</span></td></tr>';
7303:2): $itemcount ++;
7304:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7305:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'chars'}.'<br />'.
7306:2): '<span class="LC_nobreak LC_fontsize_small">'.&mt('(Leave unchecked if not required)').
7307:2): '</span></td>';
7308:2): my $numinrow = 2;
7309:2): my @possrules = ('uc','lc','num','spec');
7310:2): $datatable .= '<td class="LC_left_item"><table>';
7311:2): for (my $i=0; $i<@possrules; $i++) {
7312:2): my ($rem,$checked);
7313:2): if ($chars{$possrules[$i]}) {
7314:2): $checked = ' checked="checked"';
7315:2): }
7316:2): $rem = $i%($numinrow);
7317:2): if ($rem == 0) {
7318:2): if ($i > 0) {
7319:2): $datatable .= '</tr>';
7320:2): }
7321:2): $datatable .= '<tr>';
7322:2): }
7323:2): $datatable .= '<td><span class="LC_nobreak"><label>'.
7324:2): '<input type="checkbox" name="'.$prefix.'_chars" value="'.$possrules[$i].'"'.$checked.' />'.
7325:2): $rulenames{$possrules[$i]}.'</label></span></td>';
7326:2): }
7327:2): my $rem = @possrules%($numinrow);
7328:2): my $colsleft = $numinrow - $rem;
7329:2): if ($colsleft > 1 ) {
7330:2): $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7331:2): ' </td>';
7332:2): } elsif ($colsleft == 1) {
7333:2): $datatable .= '<td class="LC_left_item"> </td>';
7334:2): }
7335:2): $datatable .='</table></td></tr>';
7336:2): $itemcount ++;
7337:2): if ($prefix eq 'passwords') {
7338:2): $titles{'numsaved'} = &mt('Number of previous passwords to save and disallow reuse');
7339:2): $css_class = $itemcount%2?' class="LC_odd_row"':'';
7340:2): $datatable .= '<tr'.$css_class.'><td>'.$titles{'numsaved'}.'</td>'.
7341:2): '<td class="LC_left_item"><span class="LC_nobreak">'.
7342:2): '<input type="text" name="'.$prefix.'_numsaved" value="'.$numsaved.'" size="3" '.
7343:2): 'onblur="javascript:warnInt'.$prefix.'(this);" />'.
7344:2): '<span class="LC_fontsize_small"> '.&mt('(Leave blank to not save previous passwords)').'</span>'.
7345:2): '</span></td></tr>';
7346:2): $itemcount ++;
7347:2): }
7348:2): if (ref($itemcountref)) {
7349:2): $$itemcountref += $itemcount;
7350:2): }
7351:2): return $datatable;
7352:2): }
7353:2):
1.160.6.113 raeburn 7354: sub print_wafproxy {
7355: my ($position,$dom,$settings,$rowtotal) = @_;
7356: my $css_class;
7357: my $itemcount = 0;
7358: my $datatable;
7359: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7360: my (%othercontrol,%otherdoms,%aliases,%saml,%values,$setdom,$showdom);
7361: my %lt = &wafproxy_titles();
7362: foreach my $server (sort(keys(%servers))) {
7363: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
7364: next if ($serverhome eq '');
7365: my $serverdom;
7366: if ($serverhome ne $server) {
7367: $serverdom = &Apache::lonnet::host_domain($serverhome);
7368: if (($serverdom ne '') && (&Apache::lonnet::domain($serverdom) ne '')) {
7369: $othercontrol{$server} = $serverdom;
7370: }
7371: } else {
7372: $serverdom = &Apache::lonnet::host_domain($server);
7373: next if (($serverdom eq '') || (&Apache::lonnet::domain($serverdom) eq ''));
7374: if ($serverdom ne $dom) {
7375: $othercontrol{$server} = $serverdom;
7376: } else {
7377: $setdom = 1;
7378: if (ref($settings) eq 'HASH') {
7379: if (ref($settings->{'alias'}) eq 'HASH') {
7380: $aliases{$dom} = $settings->{'alias'};
7381: if ($aliases{$dom} ne '') {
7382: $showdom = 1;
7383: }
7384: }
7385: if (ref($settings->{'saml'}) eq 'HASH') {
7386: $saml{$dom} = $settings->{'saml'};
7387: }
7388: }
7389: }
7390: }
7391: }
7392: if ($setdom) {
7393: %{$values{$dom}} = ();
7394: if (ref($settings) eq 'HASH') {
7395: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7396: $values{$dom}{$item} = $settings->{$item};
7397: }
7398: }
7399: }
7400: if (keys(%othercontrol)) {
7401: %otherdoms = reverse(%othercontrol);
7402: foreach my $domain (keys(%otherdoms)) {
7403: %{$values{$domain}} = ();
7404: my %config = &Apache::lonnet::get_dom('configuration',['wafproxy'],$domain);
7405: if (ref($config{'wafproxy'}) eq 'HASH') {
7406: $aliases{$domain} = $config{'wafproxy'}{'alias'};
7407: if (exists($config{'wafproxy'}{'saml'})) {
7408: $saml{$domain} = $config{'wafproxy'}{'saml'};
7409: }
7410: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext') {
7411: $values{$domain}{$item} = $config{'wafproxy'}{$item};
7412: }
7413: }
7414: }
7415: }
7416: if ($position eq 'top') {
7417: my %servers = &Apache::lonnet::internet_dom_servers($dom);
7418: my %aliasinfo;
7419: foreach my $server (sort(keys(%servers))) {
7420: $itemcount ++;
7421: my $dom_in_effect;
7422: my $aliasrows = '<tr>'.
7423: '<td class="LC_left_item" style="vertical-align: baseline;">'.
1.160.6.118.2 17(raebu 7424:24): &mt('Hostname').': '.
16(raebu 7425:24): '<span class="LC_nobreak LC_cusr_emph">'.
7426:24): &Apache::lonnet::hostname($server).'</span></td><td> </td>';
1.160.6.113 raeburn 7427: if ($othercontrol{$server}) {
7428: $dom_in_effect = $othercontrol{$server};
7429: my ($current,$forsaml);
7430: if (ref($aliases{$dom_in_effect}) eq 'HASH') {
7431: $current = $aliases{$dom_in_effect}{$server};
7432: }
7433: if (ref($saml{$dom_in_effect}) eq 'HASH') {
7434: if ($saml{$dom_in_effect}{$server}) {
7435: $forsaml = 1;
7436: }
7437: }
7438: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7439: &mt('Alias').': ';
7440: if ($current) {
7441: $aliasrows .= $current;
7442: if ($forsaml) {
7443: $aliasrows .= ' ('.&mt('also for SSO Auth').')';
7444: }
7445: } else {
7446: $aliasrows .= &mt('None');
7447: }
7448: $aliasrows .= ' <span class="LC_small">('.
7449: &mt('controlled by domain: [_1]',
7450: '<b>'.$dom_in_effect.'</b>').')</span></td>';
7451: } else {
7452: $dom_in_effect = $dom;
7453: my ($current,$samlon,$samloff);
7454: $samloff = ' checked="checked"';
7455: if (ref($aliases{$dom}) eq 'HASH') {
7456: if ($aliases{$dom}{$server}) {
7457: $current = $aliases{$dom}{$server};
7458: }
7459: }
7460: if (ref($saml{$dom}) eq 'HASH') {
7461: if ($saml{$dom}{$server}) {
7462: $samlon = $samloff;
7463: undef($samloff);
7464: }
7465: }
7466: $aliasrows .= '<td class="LC_left_item" style="vertical-align: baseline;">'.
7467: &mt('Alias').': '.
7468: '<input type="text" name="wafproxy_alias_'.$server.'" '.
7469: 'value="'.$current.'" size="30" />'.
7470: (' 'x2).'<span class="LC_nobreak">'.
7471: &mt('Alias used for SSO Auth').': <label>'.
7472: '<input type="radio" value="0"'.$samloff.' name="wafproxy_alias_saml_'.$server.'" />'.
7473: &mt('No').'</label> <label>'.
7474: '<input type="radio" value="1"'.$samlon.' name="wafproxy_alias_saml_'.$server.'" />'.
7475: &mt('Yes').'</label></span>'.
7476: '</td>';
7477: }
7478: $aliasrows .= '</tr>';
7479: $aliasinfo{$dom_in_effect} .= $aliasrows;
7480: }
7481: if ($aliasinfo{$dom}) {
7482: my ($onclick,$wafon,$wafoff,$showtable);
7483: $onclick = ' onclick="javascript:toggleWAF();"';
7484: $wafoff = ' checked="checked"';
7485: $showtable = ' style="display:none";';
7486: if ($showdom) {
7487: $wafon = $wafoff;
7488: $wafoff = '';
7489: $showtable = ' style="display:inline;"';
7490: }
7491: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7492: $datatable = '<tr'.$css_class.'>'.
7493: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br />'.
7494: '<span class="LC_nobreak">'.&mt('WAF in use?').' <label>'.
7495: '<input type="radio" name="wafproxy_'.$dom.'" value="1"'.$wafon.$onclick.' />'.
7496: &mt('Yes').'</label>'.(' 'x2).'<label>'.
7497: '<input type="radio" name="wafproxy_'.$dom.'" value="0"'.$wafoff.$onclick.' />'.
7498: &mt('No').'</label></span></td>'.
7499: '<td class="LC_left_item">'.
7500: '<table id="wafproxy_table"'.$showtable.'>'.$aliasinfo{$dom}.
7501: '</table></td></tr>';
7502: $itemcount++;
7503: }
7504: if (keys(%otherdoms)) {
7505: foreach my $key (sort(keys(%otherdoms))) {
7506: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7507: $datatable .= '<tr'.$css_class.'>'.
7508: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$key.'</b>').'</td>'.
7509: '<td class="LC_left_item"><table>'.$aliasinfo{$key}.
7510: '</table></td></tr>';
7511: $itemcount++;
7512: }
7513: }
7514: } else {
7515: my %ip_methods = &remoteip_methods();
7516: if ($setdom) {
7517: $itemcount ++;
7518: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7519: my ($nowafstyle,$wafstyle,$curr_remotip,$currwafdisplay,$vpndircheck,$vpnaliascheck,
7520: $currwafvpn,$wafrangestyle,$alltossl,$ssltossl);
7521: $wafstyle = ' style="display:none;"';
7522: $nowafstyle = ' style="display:table-row;"';
7523: $currwafdisplay = ' style="display: none"';
7524: $wafrangestyle = ' style="display: none"';
7525: $curr_remotip = 'n';
7526: $ssltossl = ' checked="checked"';
7527: if ($showdom) {
7528: $wafstyle = ' style="display:table-row;"';
7529: $nowafstyle = ' style="display:none;"';
7530: if (keys(%{$values{$dom}})) {
7531: if ($values{$dom}{remoteip} =~ /^[nmh]$/) {
7532: $curr_remotip = $values{$dom}{remoteip};
7533: }
7534: if ($curr_remotip eq 'h') {
7535: $currwafdisplay = ' style="display:table-row"';
7536: $wafrangestyle = ' style="display:inline-block;"';
7537: }
7538: if ($values{$dom}{'sslopt'}) {
7539: $alltossl = ' checked="checked"';
7540: $ssltossl = '';
7541: }
7542: }
7543: if (($values{$dom}{'vpnint'} ne '') || ($values{$dom}{'vpnext'} ne '')) {
7544: $vpndircheck = ' checked="checked"';
7545: $currwafvpn = ' style="display:table-row;"';
7546: $wafrangestyle = ' style="display:inline-block;"';
7547: } else {
7548: $vpnaliascheck = ' checked="checked"';
7549: $currwafvpn = ' style="display:none;"';
7550: }
7551: }
7552: $datatable .= '<tr'.$css_class.' id="nowafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7553: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'</td>'.
7554: '<td class="LC_right_item">'.&mt('WAF not in use, nothing to set').'</td>'.
7555: '</tr>'.
7556: '<tr'.$css_class.' id="wafproxyrow_'.$dom.'"'.$wafstyle.'>'.
7557: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$dom.'</b>').'<br /><br />'.
7558: '<div id="wafproxyranges_'.$dom.'">'.&mt('Format for comma separated IP ranges').':<br />'.
7559: &mt('A.B.C.D/N or A.B.C.D-E.F.G.H').'<br />'.
7560: &mt('Range(s) stored in CIDR notation').'</div></td>'.
7561: '<td class="LC_left_item"><table>'.
7562: '<tr>'.
7563: '<td valign="top">'.$lt{'remoteip'}.': '.
7564: '<select name="wafproxy_remoteip" id="wafproxy_remoteip" onchange="javascript:updateWAF();">';
7565: foreach my $option ('m','h','n') {
7566: my $sel;
1.160.6.114 raeburn 7567: if ($option eq $curr_remotip) {
7568: $sel = ' selected="selected"';
7569: }
7570: $datatable .= '<option value="'.$option.'"'.$sel.'>'.
7571: $ip_methods{$option}.'</option>';
7572: }
7573: $datatable .= '</select></td></tr>'."\n".
7574: '<tr id="wafproxy_header"'.$currwafdisplay.'><td>'.
7575: $lt{'ipheader'}.': '.
7576: '<input type="text" value="'.$values{$dom}{'ipheader'}.'" '.
7577: 'name="wafproxy_ipheader" />'.
7578: '</td></tr>'."\n".
7579: '<tr id="wafproxy_trust"'.$currwafdisplay.'><td>'.
7580: $lt{'trusted'}.':<br />'.
7581: '<textarea name="wafproxy_trusted" rows="3" cols="80">'.
7582: $values{$dom}{'trusted'}.'</textarea>'.
7583: '</td></tr>'."\n".
7584: '<tr><td><hr /></td></tr>'."\n".
7585: '<tr>'.
1.160.6.113 raeburn 7586: '<td valign="top">'.$lt{'vpnaccess'}.':<br /><span class="LC_nobreak">'.
7587: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpndircheck.' value="1" onclick="javascript:checkWAF();" />'.
7588: $lt{'vpndirect'}.'</label>'.(' 'x2).
7589: '<label><input type="radio" name="wafproxy_vpnaccess"'.$vpnaliascheck.' value="0" onclick="javascript:checkWAF();" />'.
7590: $lt{'vpnaliased'}.'</label></span></td></tr>';
7591: foreach my $item ('vpnint','vpnext') {
7592: $datatable .= '<tr id="wafproxy_show_'.$item.'"'.$currwafvpn.'>'.
7593: '<td valign="top">'.$lt{$item}.':<br />'.
7594: '<textarea name="wafproxy_'.$item.'" rows="3" cols="80">'.
7595: $values{$dom}{$item}.'</textarea>'.
7596: '</td></tr>'."\n";
7597: }
7598: $datatable .= '<tr><td><hr /></td></tr>'."\n".
7599: '<tr>'.
7600: '<td valign="top">'.$lt{'sslopt'}.':<br /><span class="LC_nobreak">'.
7601: '<label><input type="radio" name="wafproxy_sslopt"'.$alltossl.' value="1" />'.
7602: $lt{'alltossl'}.'</label>'.(' 'x2).
7603: '<label><input type="radio" name="wafproxy_sslopt"'.$ssltossl.' value="0" />'.
7604: $lt{'ssltossl'}.'</label></span></td></tr>'."\n".
7605: '</table></td></tr>';
7606: }
7607: if (keys(%otherdoms)) {
7608: foreach my $domain (sort(keys(%otherdoms))) {
7609: $itemcount ++;
7610: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7611: $datatable .= '<tr'.$css_class.'>'.
7612: '<td class="LC_left_item">'.&mt('Domain: [_1]','<b>'.$domain.'</b>').'</td>'.
7613: '<td class="LC_left_item"><table>';
7614: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
7615: my $showval = &mt('None');
7616: if ($item eq 'ssl') {
7617: $showval = $lt{'ssltossl'};
7618: }
7619: if ($values{$domain}{$item}) {
7620: $showval = $values{$domain}{$item};
7621: if ($item eq 'ssl') {
7622: $showval = $lt{'alltossl'};
7623: } elsif ($item eq 'remoteip') {
7624: $showval = $ip_methods{$values{$domain}{$item}};
7625: }
7626: }
7627: $datatable .= '<tr>'.
7628: '<td>'.$lt{$item}.': '.$showval.'</td></tr>';
7629: }
7630: $datatable .= '</table></td></tr>';
7631: }
7632: }
7633: }
7634: $$rowtotal += $itemcount;
7635: return $datatable;
7636: }
7637:
7638: sub wafproxy_titles {
7639: return &Apache::lonlocal::texthash(
7640: remoteip => "Method for determining user's IP",
7641: ipheader => 'Request header containing remote IP',
7642: trusted => 'Trusted IP range(s)',
7643: vpnaccess => 'Access from institutional VPN',
7644: vpndirect => 'via regular hostname (no WAF)',
7645: vpnaliased => 'via aliased hostname (WAF)',
7646: vpnint => 'Internal IP Range(s) for VPN sessions',
7647: vpnext => 'IP Range(s) for backend WAF connections',
7648: sslopt => 'Forwarding http/https',
7649: alltossl => 'WAF forwards both http and https requests to https',
7650: ssltossl => 'WAF forwards http requests to http and https to https',
7651: );
7652: }
7653:
7654: sub remoteip_methods {
7655: return &Apache::lonlocal::texthash(
7656: m => 'Use Apache mod_remoteip',
7657: h => 'Use headers parsed by LON-CAPA',
7658: n => 'Not in use',
7659: );
7660: }
7661:
1.137 raeburn 7662: sub print_usersessions {
7663: my ($position,$dom,$settings,$rowtotal) = @_;
7664: my ($css_class,$datatable,%checked,%choices);
1.140 raeburn 7665: my (%by_ip,%by_location,@intdoms);
7666: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
1.145 raeburn 7667:
7668: my @alldoms = &Apache::lonnet::all_domains();
1.152 raeburn 7669: my %serverhomes = %Apache::lonnet::serverhomeIDs;
1.149 raeburn 7670: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.152 raeburn 7671: my %altids = &id_for_thisdom(%servers);
1.145 raeburn 7672: my $itemcount = 1;
7673: if ($position eq 'top') {
1.152 raeburn 7674: if (keys(%serverhomes) > 1) {
1.145 raeburn 7675: my %spareid = ¤t_offloads_to($dom,$settings,\%servers);
1.160.6.105 raeburn 7676: my ($curroffloadnow,$curroffloadoth);
1.160.6.61 raeburn 7677: if (ref($settings) eq 'HASH') {
7678: if (ref($settings->{'offloadnow'}) eq 'HASH') {
7679: $curroffloadnow = $settings->{'offloadnow'};
7680: }
1.160.6.105 raeburn 7681: if (ref($settings->{'offloadoth'}) eq 'HASH') {
7682: $curroffloadoth = $settings->{'offloadoth'};
7683: }
1.160.6.61 raeburn 7684: }
1.160.6.105 raeburn 7685: my $other_insts = scalar(keys(%by_location));
7686: $datatable .= &spares_row($dom,\%servers,\%spareid,\%serverhomes,\%altids,
7687: $other_insts,$curroffloadnow,$curroffloadoth,$rowtotal);
1.145 raeburn 7688: } else {
1.140 raeburn 7689: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7690:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one server.').
7691:23): '</td></tr>';
1.140 raeburn 7692: }
1.137 raeburn 7693: } else {
1.145 raeburn 7694: if (keys(%by_location) == 0) {
7695: $datatable .= '<tr'.$css_class.'><td colspan="2">'.
1.160.6.118.2 14(raebu 7696:23): &mt('Nothing to set here, as the cluster to which this domain belongs only contains one institution.').
7697:23): '</td></tr>';
1.145 raeburn 7698: } else {
7699: my %lt = &usersession_titles();
7700: my $numinrow = 5;
7701: my $prefix;
7702: my @types;
7703: if ($position eq 'bottom') {
7704: $prefix = 'remote';
7705: @types = ('version','excludedomain','includedomain');
7706: } else {
7707: $prefix = 'hosted';
7708: @types = ('excludedomain','includedomain');
7709: }
7710: my (%current,%checkedon,%checkedoff);
7711: my @lcversions = &Apache::lonnet::all_loncaparevs();
7712: my @locations = sort(keys(%by_location));
7713: foreach my $type (@types) {
7714: $checkedon{$type} = '';
7715: $checkedoff{$type} = ' checked="checked"';
7716: }
7717: if (ref($settings) eq 'HASH') {
7718: if (ref($settings->{$prefix}) eq 'HASH') {
7719: foreach my $key (keys(%{$settings->{$prefix}})) {
7720: $current{$key} = $settings->{$prefix}{$key};
7721: if ($key eq 'version') {
7722: if ($current{$key} ne '') {
7723: $checkedon{$key} = ' checked="checked"';
7724: $checkedoff{$key} = '';
7725: }
7726: } elsif (ref($current{$key}) eq 'ARRAY') {
7727: $checkedon{$key} = ' checked="checked"';
7728: $checkedoff{$key} = '';
7729: }
1.137 raeburn 7730: }
7731: }
7732: }
1.145 raeburn 7733: foreach my $type (@types) {
7734: next if ($type ne 'version' && !@locations);
7735: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7736: $datatable .= '<tr'.$css_class.'>
7737: <td><span class="LC_nobreak">'.$lt{$type}.'</span><br />
7738: <span class="LC_nobreak">
7739: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedoff{$type}.' value="0" />'.&mt('Not in use').'</label>
7740: <label><input type="radio" name="'.$prefix.'_'.$type.'_inuse" '.$checkedon{$type}.' value="1" />'.&mt('In use').'</label></span></td><td>';
7741: if ($type eq 'version') {
7742: my $selector = '<select name="'.$prefix.'_version">';
7743: foreach my $version (@lcversions) {
7744: my $selected = '';
7745: if ($current{'version'} eq $version) {
7746: $selected = ' selected="selected"';
7747: }
7748: $selector .= ' <option value="'.$version.'"'.
7749: $selected.'>'.$version.'</option>';
7750: }
7751: $selector .= '</select> ';
7752: $datatable .= &mt('remote server must be version: [_1] or later',$selector);
7753: } else {
7754: $datatable.= '<div><input type="button" value="'.&mt('check all').'" '.
7755: 'onclick="javascript:checkAll(document.display.'.$prefix.'_'.$type.')"'.
7756: ' />'.(' 'x2).
7757: '<input type="button" value="'.&mt('uncheck all').'" '.
7758: 'onclick="javascript:uncheckAll(document.display.'.$prefix.'_'.$type.')" />'.
7759: "\n".
7760: '</div><div><table>';
7761: my $rem;
7762: for (my $i=0; $i<@locations; $i++) {
7763: my ($showloc,$value,$checkedtype);
7764: if (ref($by_location{$locations[$i]}) eq 'ARRAY') {
7765: my $ip = $by_location{$locations[$i]}->[0];
7766: if (ref($by_ip{$ip}) eq 'ARRAY') {
7767: $value = join(':',@{$by_ip{$ip}});
7768: $showloc = join(', ',@{$by_ip{$ip}});
7769: if (ref($current{$type}) eq 'ARRAY') {
7770: foreach my $loc (@{$by_ip{$ip}}) {
7771: if (grep(/^\Q$loc\E$/,@{$current{$type}})) {
7772: $checkedtype = ' checked="checked"';
7773: last;
7774: }
7775: }
1.138 raeburn 7776: }
7777: }
7778: }
1.145 raeburn 7779: $rem = $i%($numinrow);
7780: if ($rem == 0) {
7781: if ($i > 0) {
7782: $datatable .= '</tr>';
7783: }
7784: $datatable .= '<tr>';
7785: }
7786: $datatable .= '<td class="LC_left_item">'.
7787: '<span class="LC_nobreak"><label>'.
7788: '<input type="checkbox" name="'.$prefix.'_'.$type.
7789: '" value="'.$value.'"'.$checkedtype.' />'.$showloc.
7790: '</label></span></td>';
1.137 raeburn 7791: }
1.145 raeburn 7792: $rem = @locations%($numinrow);
7793: my $colsleft = $numinrow - $rem;
7794: if ($colsleft > 1 ) {
7795: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
7796: ' </td>';
7797: } elsif ($colsleft == 1) {
7798: $datatable .= '<td class="LC_left_item"> </td>';
1.137 raeburn 7799: }
1.145 raeburn 7800: $datatable .= '</tr></table>';
1.137 raeburn 7801: }
1.145 raeburn 7802: $datatable .= '</td></tr>';
7803: $itemcount ++;
1.137 raeburn 7804: }
7805: }
7806: }
7807: $$rowtotal += $itemcount;
7808: return $datatable;
7809: }
7810:
1.138 raeburn 7811: sub build_location_hashes {
7812: my ($intdoms,$by_ip,$by_location) = @_;
7813: return unless((ref($intdoms) eq 'ARRAY') && (ref($by_ip) eq 'HASH') &&
7814: (ref($by_location) eq 'HASH'));
7815: my %iphost = &Apache::lonnet::get_iphost();
7816: my $primary_id = &Apache::lonnet::domain($env{'request.role.domain'},'primary');
7817: my $primary_ip = &Apache::lonnet::get_host_ip($primary_id);
7818: if (ref($iphost{$primary_ip}) eq 'ARRAY') {
7819: foreach my $id (@{$iphost{$primary_ip}}) {
7820: my $intdom = &Apache::lonnet::internet_dom($id);
7821: unless(grep(/^\Q$intdom\E$/,@{$intdoms})) {
7822: push(@{$intdoms},$intdom);
7823: }
7824: }
7825: }
7826: foreach my $ip (keys(%iphost)) {
7827: if (ref($iphost{$ip}) eq 'ARRAY') {
7828: foreach my $id (@{$iphost{$ip}}) {
7829: my $location = &Apache::lonnet::internet_dom($id);
7830: if ($location) {
7831: next if (grep(/^\Q$location\E$/,@{$intdoms}));
7832: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7833: unless(grep(/^\Q$location\E$/,@{$by_ip->{$ip}})) {
7834: push(@{$by_ip->{$ip}},$location);
7835: }
7836: } else {
7837: $by_ip->{$ip} = [$location];
7838: }
7839: }
7840: }
7841: }
7842: }
7843: foreach my $ip (sort(keys(%{$by_ip}))) {
7844: if (ref($by_ip->{$ip}) eq 'ARRAY') {
7845: @{$by_ip->{$ip}} = sort(@{$by_ip->{$ip}});
7846: my $first = $by_ip->{$ip}->[0];
7847: if (ref($by_location->{$first}) eq 'ARRAY') {
7848: unless (grep(/^\Q$ip\E$/,@{$by_location->{$first}})) {
7849: push(@{$by_location->{$first}},$ip);
7850: }
7851: } else {
7852: $by_location->{$first} = [$ip];
7853: }
7854: }
7855: }
7856: return;
7857: }
7858:
1.145 raeburn 7859: sub current_offloads_to {
7860: my ($dom,$settings,$servers) = @_;
7861: my (%spareid,%otherdomconfigs);
1.152 raeburn 7862: if (ref($servers) eq 'HASH') {
1.145 raeburn 7863: foreach my $lonhost (sort(keys(%{$servers}))) {
7864: my $gotspares;
1.152 raeburn 7865: if (ref($settings) eq 'HASH') {
7866: if (ref($settings->{'spares'}) eq 'HASH') {
7867: if (ref($settings->{'spares'}{$lonhost}) eq 'HASH') {
7868: $spareid{$lonhost}{'primary'} = $settings->{'spares'}{$lonhost}{'primary'};
7869: $spareid{$lonhost}{'default'} = $settings->{'spares'}{$lonhost}{'default'};
7870: $gotspares = 1;
7871: }
1.145 raeburn 7872: }
7873: }
7874: unless ($gotspares) {
7875: my $gotspares;
7876: my $serverhomeID =
7877: &Apache::lonnet::get_server_homeID($servers->{$lonhost});
7878: my $serverhomedom =
7879: &Apache::lonnet::host_domain($serverhomeID);
7880: if ($serverhomedom ne $dom) {
7881: if (ref($otherdomconfigs{$serverhomedom} eq 'HASH')) {
7882: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7883: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7884: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7885: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7886: $gotspares = 1;
7887: }
7888: }
7889: } else {
7890: $otherdomconfigs{$serverhomedom} =
7891: &Apache::lonnet::get_dom('configuration',['usersessions'],$serverhomedom);
7892: if (ref($otherdomconfigs{$serverhomedom}) eq 'HASH') {
7893: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}) eq 'HASH') {
7894: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}) eq 'HASH') {
7895: if (ref($otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{$lonhost}) eq 'HASH') {
7896: $spareid{$lonhost}{'primary'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'primary'};
7897: $spareid{$lonhost}{'default'} = $otherdomconfigs{$serverhomedom}{'usersessions'}{'spares'}{'default'};
7898: $gotspares = 1;
7899: }
7900: }
7901: }
7902: }
7903: }
7904: }
7905: }
7906: unless ($gotspares) {
7907: if ($lonhost eq $Apache::lonnet::perlvar{'lonHostID'}) {
7908: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7909: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7910: } else {
7911: my $server_hostname = &Apache::lonnet::hostname($lonhost);
7912: my $server_homeID = &Apache::lonnet::get_server_homeID($server_hostname);
7913: if ($server_homeID eq $Apache::lonnet::perlvar{'lonHostID'}) {
7914: $spareid{$lonhost}{'primary'} = $Apache::lonnet::spareid{'primary'};
7915: $spareid{$lonhost}{'default'} = $Apache::lonnet::spareid{'default'};
7916: } else {
1.150 raeburn 7917: my %what = (
7918: spareid => 1,
7919: );
7920: my ($result,$returnhash) =
7921: &Apache::lonnet::get_remote_globals($lonhost,\%what);
7922: if ($result eq 'ok') {
7923: if (ref($returnhash) eq 'HASH') {
7924: if (ref($returnhash->{'spareid'}) eq 'HASH') {
7925: $spareid{$lonhost}{'primary'} = $returnhash->{'spareid'}->{'primary'};
7926: $spareid{$lonhost}{'default'} = $returnhash->{'spareid'}->{'default'};
7927: }
7928: }
1.145 raeburn 7929: }
7930: }
7931: }
7932: }
7933: }
7934: }
7935: return %spareid;
7936: }
7937:
7938: sub spares_row {
1.160.6.105 raeburn 7939: my ($dom,$servers,$spareid,$serverhomes,$altids,$other_insts,
7940: $curroffloadnow,$curroffloadoth,$rowtotal) = @_;
1.145 raeburn 7941: my $css_class;
7942: my $numinrow = 4;
7943: my $itemcount = 1;
7944: my $datatable;
1.152 raeburn 7945: my %typetitles = &sparestype_titles();
7946: if ((ref($servers) eq 'HASH') && (ref($spareid) eq 'HASH') && (ref($altids) eq 'HASH')) {
1.145 raeburn 7947: foreach my $server (sort(keys(%{$servers}))) {
1.152 raeburn 7948: my $serverhome = &Apache::lonnet::get_server_homeID($servers->{$server});
7949: my ($othercontrol,$serverdom);
7950: if ($serverhome ne $server) {
7951: $serverdom = &Apache::lonnet::host_domain($serverhome);
7952: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7953: } else {
7954: $serverdom = &Apache::lonnet::host_domain($server);
7955: if ($serverdom ne $dom) {
7956: $othercontrol = &mt('Session offloading controlled by domain: [_1]','<b>'.$serverdom.'</b>');
7957: }
7958: }
7959: next unless (ref($spareid->{$server}) eq 'HASH');
1.160.6.105 raeburn 7960: my ($checkednow,$checkedoth);
1.160.6.61 raeburn 7961: if (ref($curroffloadnow) eq 'HASH') {
7962: if ($curroffloadnow->{$server}) {
7963: $checkednow = ' checked="checked"';
7964: }
7965: }
1.160.6.105 raeburn 7966: if (ref($curroffloadoth) eq 'HASH') {
7967: if ($curroffloadoth->{$server}) {
7968: $checkedoth = ' checked="checked"';
7969: }
7970: }
1.145 raeburn 7971: $css_class = $itemcount%2 ? ' class="LC_odd_row"' : '';
7972: $datatable .= '<tr'.$css_class.'>
7973: <td rowspan="2">
1.160.6.13 raeburn 7974: <span class="LC_nobreak">'.
7975: &mt('[_1] when busy, offloads to:'
1.160.6.61 raeburn 7976: ,'<b>'.$server.'</b>').'</span><br />'.
7977: '<span class="LC_nobreak">'."\n".
7978: '<label><input type="checkbox" name="offloadnow" value="'.$server.'"'.$checkednow.' />'.
1.160.6.105 raeburn 7979: ' '.&mt('Switch any active user on next access').'</label></span>'.
1.160.6.13 raeburn 7980: "\n";
1.160.6.105 raeburn 7981: if ($other_insts) {
7982: $datatable .= '<br />'.
7983: '<span class="LC_nobreak">'."\n".
7984: '<label><input type="checkbox" name="offloadoth" value="'.$server.'"'.$checkedoth.' />'.
7985: ' '.&mt('Switch other institutions on next access').'</label></span>'.
7986: "\n";
7987: }
1.145 raeburn 7988: my (%current,%canselect);
1.152 raeburn 7989: my @choices =
7990: &possible_newspares($server,$spareid->{$server},$serverhomes,$altids);
7991: foreach my $type ('primary','default') {
7992: if (ref($spareid->{$server}) eq 'HASH') {
1.145 raeburn 7993: if (ref($spareid->{$server}{$type}) eq 'ARRAY') {
7994: my @spares = @{$spareid->{$server}{$type}};
7995: if (@spares > 0) {
1.152 raeburn 7996: if ($othercontrol) {
7997: $current{$type} = join(', ',@spares);
7998: } else {
7999: $current{$type} .= '<table>';
8000: my $numspares = scalar(@spares);
8001: for (my $i=0; $i<@spares; $i++) {
8002: my $rem = $i%($numinrow);
8003: if ($rem == 0) {
8004: if ($i > 0) {
8005: $current{$type} .= '</tr>';
8006: }
8007: $current{$type} .= '<tr>';
1.145 raeburn 8008: }
1.152 raeburn 8009: $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'".');" /> '.
8010: $spareid->{$server}{$type}[$i].
8011: '</label></td>'."\n";
8012: }
8013: my $rem = @spares%($numinrow);
8014: my $colsleft = $numinrow - $rem;
8015: if ($colsleft > 1 ) {
8016: $current{$type} .= '<td colspan="'.$colsleft.
8017: '" class="LC_left_item">'.
8018: ' </td>';
8019: } elsif ($colsleft == 1) {
8020: $current{$type} .= '<td class="LC_left_item"> </td>'."\n";
1.145 raeburn 8021: }
1.152 raeburn 8022: $current{$type} .= '</tr></table>';
1.150 raeburn 8023: }
1.145 raeburn 8024: }
8025: }
8026: if ($current{$type} eq '') {
8027: $current{$type} = &mt('None specified');
8028: }
1.152 raeburn 8029: if ($othercontrol) {
8030: if ($type eq 'primary') {
8031: $canselect{$type} = $othercontrol;
8032: }
8033: } else {
8034: $canselect{$type} =
8035: &mt('Add new [_1]'.$type.'[_2]:','<i>','</i>').' '.
8036: '<select name="newspare_'.$type.'_'.$server.'" '.
8037: 'id="newspare_'.$type.'_'.$server.'" onchange="checkNewSpares('."'$server','$type'".');">'."\n".
8038: '<option value="" selected ="selected">'.&mt('Select').'</option>'."\n";
8039: if (@choices > 0) {
8040: foreach my $lonhost (@choices) {
8041: $canselect{$type} .= '<option value="'.$lonhost.'">'.$lonhost.'</option>'."\n";
8042: }
8043: }
8044: $canselect{$type} .= '</select>'."\n";
8045: }
8046: } else {
8047: $current{$type} = &mt('Could not be determined');
8048: if ($type eq 'primary') {
8049: $canselect{$type} = $othercontrol;
8050: }
1.145 raeburn 8051: }
1.152 raeburn 8052: if ($type eq 'default') {
8053: $datatable .= '<tr'.$css_class.'>';
8054: }
8055: $datatable .= '<td><i>'.$typetitles{$type}.'</i></td>'."\n".
8056: '<td>'.$current{$type}.'</td>'."\n".
8057: '<td>'.$canselect{$type}.'</td></tr>'."\n";
1.145 raeburn 8058: }
8059: $itemcount ++;
8060: }
8061: }
8062: $$rowtotal += $itemcount;
8063: return $datatable;
8064: }
8065:
1.152 raeburn 8066: sub possible_newspares {
8067: my ($server,$currspares,$serverhomes,$altids) = @_;
8068: my $serverhostname = &Apache::lonnet::hostname($server);
8069: my %excluded;
8070: if ($serverhostname ne '') {
8071: %excluded = (
8072: $serverhostname => 1,
8073: );
8074: }
8075: if (ref($currspares) eq 'HASH') {
8076: foreach my $type (keys(%{$currspares})) {
8077: if (ref($currspares->{$type}) eq 'ARRAY') {
8078: if (@{$currspares->{$type}} > 0) {
8079: foreach my $curr (@{$currspares->{$type}}) {
8080: my $hostname = &Apache::lonnet::hostname($curr);
8081: $excluded{$hostname} = 1;
8082: }
8083: }
8084: }
8085: }
8086: }
8087: my @choices;
8088: if ((ref($serverhomes) eq 'HASH') && (ref($altids) eq 'HASH')) {
8089: if (keys(%{$serverhomes}) > 1) {
8090: foreach my $name (sort(keys(%{$serverhomes}))) {
8091: unless ($excluded{$name}) {
8092: if (exists($altids->{$serverhomes->{$name}})) {
8093: push(@choices,$altids->{$serverhomes->{$name}});
8094: } else {
8095: push(@choices,$serverhomes->{$name});
1.145 raeburn 8096: }
8097: }
8098: }
8099: }
8100: }
1.152 raeburn 8101: return sort(@choices);
1.145 raeburn 8102: }
8103:
1.150 raeburn 8104: sub print_loadbalancing {
8105: my ($dom,$settings,$rowtotal) = @_;
8106: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8107: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8108: my $numinrow = 1;
8109: my $datatable;
8110: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.94 raeburn 8111: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 8112: if (ref($settings) eq 'HASH') {
8113: %existing = %{$settings};
8114: }
8115: if ((keys(%servers) > 1) || (keys(%existing) > 0)) {
8116: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 8117: \%currtargets,\%currrules,\%currcookies);
1.150 raeburn 8118: } else {
8119: return;
8120: }
8121: my ($othertitle,$usertypes,$types) =
8122: &Apache::loncommon::sorted_inst_types($dom);
1.160.6.26 raeburn 8123: my $rownum = 8;
1.150 raeburn 8124: if (ref($types) eq 'ARRAY') {
8125: $rownum += scalar(@{$types});
8126: }
1.160.6.7 raeburn 8127: my @css_class = ('LC_odd_row','LC_even_row');
8128: my $balnum = 0;
8129: my $islast;
8130: my (@toshow,$disabledtext);
8131: if (keys(%currbalancer) > 0) {
8132: @toshow = sort(keys(%currbalancer));
8133: if (scalar(@toshow) < scalar(keys(%servers)) + 1) {
8134: push(@toshow,'');
8135: }
8136: } else {
8137: @toshow = ('');
8138: $disabledtext = &mt('No existing load balancer');
8139: }
8140: foreach my $lonhost (@toshow) {
8141: if ($balnum == scalar(@toshow)-1) {
8142: $islast = 1;
8143: } else {
8144: $islast = 0;
8145: }
8146: my $cssidx = $balnum%2;
8147: my $targets_div_style = 'display: none';
8148: my $disabled_div_style = 'display: block';
8149: my $homedom_div_style = 'display: none';
8150: $datatable .= '<tr class="'.$css_class[$cssidx].'">'.
8151: '<td rowspan="'.$rownum.'" valign="top">'.
8152: '<p>';
8153: if ($lonhost eq '') {
8154: $datatable .= '<span class="LC_nobreak">';
8155: if (keys(%currbalancer) > 0) {
8156: $datatable .= &mt('Add balancer:');
8157: } else {
8158: $datatable .= &mt('Enable balancer:');
8159: }
8160: $datatable .= ' '.
8161: '<select name="loadbalancing_lonhost_'.$balnum.'"'.
8162: ' id="loadbalancing_lonhost_'.$balnum.'"'.
8163: ' onchange="toggleTargets('."'$balnum'".');">'."\n".
8164: '<option value="" selected="selected">'.&mt('None').
8165: '</option>'."\n";
8166: foreach my $server (sort(keys(%servers))) {
8167: next if ($currbalancer{$server});
8168: $datatable .= '<option value="'.$server.'">'.$server.'</option>'."\n";
8169: }
8170: $datatable .=
8171: '</select>'."\n".
8172: '<input type="hidden" name="loadbalancing_prevlonhost_'.$balnum.'" id="loadbalancing_prevlonhost_'.$balnum.'" value="" /> </span>'."\n";
8173: } else {
8174: $datatable .= '<i>'.$lonhost.'</i><br /><span class="LC_nobreak">'.
8175: '<label><input type="checkbox" name="loadbalancing_delete" value="'.$balnum.'" id="loadbalancing_delete_'.$balnum.'" onclick="javascript:balancerDeleteChange('."'$balnum'".');" /> '.
8176: &mt('Stop balancing').'</label>'.
8177: '<input type="hidden" name="loadbalancing_lonhost_'.$balnum.'" value="'.$lonhost.'" id="loadbalancing_lonhost_'.$balnum.'" /></span>';
8178: $targets_div_style = 'display: block';
8179: $disabled_div_style = 'display: none';
8180: if ($dom eq &Apache::lonnet::host_domain($lonhost)) {
8181: $homedom_div_style = 'display: block';
8182: }
8183: }
8184: $datatable .= '</p></td><td rowspan="'.$rownum.'" valign="top">'.
8185: '<div id="loadbalancing_disabled_'.$balnum.'" style="'.
8186: $disabled_div_style.'">'.$disabledtext.'</div>'."\n".
8187: '<div id="loadbalancing_targets_'.$balnum.'" style="'.$targets_div_style.'">'.&mt('Offloads to:').'<br />';
8188: my ($numspares,@spares) = &count_servers($lonhost,%servers);
8189: my @sparestypes = ('primary','default');
8190: my %typetitles = &sparestype_titles();
1.160.6.76 raeburn 8191: my %hostherechecked = (
8192: no => ' checked="checked"',
8193: );
1.160.6.94 raeburn 8194: my %balcookiechecked = (
8195: no => ' checked="checked"',
8196: );
1.160.6.7 raeburn 8197: foreach my $sparetype (@sparestypes) {
8198: my $targettable;
8199: for (my $i=0; $i<$numspares; $i++) {
8200: my $checked;
8201: if (ref($currtargets{$lonhost}) eq 'HASH') {
8202: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8203: if (grep(/^\Q$spares[$i]\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8204: $checked = ' checked="checked"';
8205: }
8206: }
8207: }
8208: my ($chkboxval,$disabled);
8209: if (($lonhost ne '') && (exists($servers{$lonhost}))) {
8210: $chkboxval = $spares[$i];
8211: }
8212: if (exists($currbalancer{$spares[$i]})) {
8213: $disabled = ' disabled="disabled"';
8214: }
8215: $targettable .=
1.160.6.55 raeburn 8216: '<td><span class="LC_nobreak"><label>'.
8217: '<input type="checkbox" name="loadbalancing_target_'.$balnum.'_'.$sparetype.'"'.
1.160.6.7 raeburn 8218: $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 8219: '</span></label></span></td>';
1.160.6.7 raeburn 8220: my $rem = $i%($numinrow);
8221: if ($rem == 0) {
8222: if (($i > 0) && ($i < $numspares-1)) {
8223: $targettable .= '</tr>';
8224: }
8225: if ($i < $numspares-1) {
8226: $targettable .= '<tr>';
1.150 raeburn 8227: }
8228: }
8229: }
1.160.6.7 raeburn 8230: if ($targettable ne '') {
8231: my $rem = $numspares%($numinrow);
8232: my $colsleft = $numinrow - $rem;
8233: if ($colsleft > 1 ) {
8234: $targettable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8235: ' </td>';
8236: } elsif ($colsleft == 1) {
8237: $targettable .= '<td class="LC_left_item"> </td>';
8238: }
8239: $datatable .= '<i>'.$typetitles{$sparetype}.'</i><br />'.
8240: '<table><tr>'.$targettable.'</tr></table><br />';
8241: }
1.160.6.76 raeburn 8242: $hostherechecked{$sparetype} = '';
8243: if (ref($currtargets{$lonhost}) eq 'HASH') {
8244: if (ref($currtargets{$lonhost}{$sparetype}) eq 'ARRAY') {
8245: if (grep(/^\Q$lonhost\E$/,@{$currtargets{$lonhost}{$sparetype}})) {
8246: $hostherechecked{$sparetype} = ' checked="checked"';
8247: $hostherechecked{'no'} = '';
8248: }
8249: }
8250: }
8251: }
1.160.6.94 raeburn 8252: if ($currcookies{$lonhost}) {
8253: %balcookiechecked = (
8254: yes => ' checked="checked"',
8255: );
8256: }
1.160.6.76 raeburn 8257: $datatable .= &mt('Hosting on balancer itself').'<br />'.
8258: '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" value="no"'.
8259: $hostherechecked{'no'}.' />'.&mt('No').'</label><br />';
8260: foreach my $sparetype (@sparestypes) {
8261: $datatable .= '<label><input type="radio" name="loadbalancing_target_'.$balnum.'_hosthere" '.
8262: 'value="'.$sparetype.'"'.$hostherechecked{$sparetype}.' /><i>'.$typetitles{$sparetype}.
8263: '</i></label><br />';
1.160.6.7 raeburn 8264: }
1.160.6.94 raeburn 8265: $datatable .= &mt('Use balancer cookie').'<br />'.
8266: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="1"'.
8267: $balcookiechecked{'yes'}.' />'.&mt('Yes').'</label><br />'.
8268: '<label><input type="radio" name="loadbalancing_cookie_'.$balnum.'" value="0"'.
8269: $balcookiechecked{'no'}.' />'.&mt('No').'</label><br />'.
8270: '</div></td></tr>'.
1.160.6.7 raeburn 8271: &loadbalancing_rules($dom,$intdom,$currrules{$lonhost},
8272: $othertitle,$usertypes,$types,\%servers,
8273: \%currbalancer,$lonhost,
8274: $targets_div_style,$homedom_div_style,
8275: $css_class[$cssidx],$balnum,$islast);
8276: $$rowtotal += $rownum;
8277: $balnum ++;
8278: }
8279: $datatable .= '<input type="hidden" name="loadbalancing_total" id="loadbalancing_total" value="'.$balnum.'" />';
8280: return $datatable;
8281: }
8282:
8283: sub get_loadbalancers_config {
1.160.6.94 raeburn 8284: my ($servers,$existing,$currbalancer,$currtargets,$currrules,$currcookies) = @_;
1.160.6.7 raeburn 8285: return unless ((ref($servers) eq 'HASH') &&
8286: (ref($existing) eq 'HASH') && (ref($currbalancer) eq 'HASH') &&
1.160.6.94 raeburn 8287: (ref($currtargets) eq 'HASH') && (ref($currrules) eq 'HASH') &&
8288: (ref($currcookies) eq 'HASH'));
1.160.6.7 raeburn 8289: if (keys(%{$existing}) > 0) {
8290: my $oldlonhost;
8291: foreach my $key (sort(keys(%{$existing}))) {
8292: if ($key eq 'lonhost') {
8293: $oldlonhost = $existing->{'lonhost'};
8294: $currbalancer->{$oldlonhost} = 1;
8295: } elsif ($key eq 'targets') {
8296: if ($oldlonhost) {
8297: $currtargets->{$oldlonhost} = $existing->{'targets'};
8298: }
8299: } elsif ($key eq 'rules') {
8300: if ($oldlonhost) {
8301: $currrules->{$oldlonhost} = $existing->{'rules'};
8302: }
8303: } elsif (ref($existing->{$key}) eq 'HASH') {
8304: $currbalancer->{$key} = 1;
8305: $currtargets->{$key} = $existing->{$key}{'targets'};
8306: $currrules->{$key} = $existing->{$key}{'rules'};
1.160.6.94 raeburn 8307: if ($existing->{$key}{'cookie'}) {
8308: $currcookies->{$key} = 1;
8309: }
1.150 raeburn 8310: }
8311: }
1.160.6.7 raeburn 8312: } else {
8313: my ($balancerref,$targetsref) =
8314: &Apache::lonnet::get_lonbalancer_config($servers);
8315: if ((ref($balancerref) eq 'HASH') && (ref($targetsref) eq 'HASH')) {
8316: foreach my $server (sort(keys(%{$balancerref}))) {
8317: $currbalancer->{$server} = 1;
8318: $currtargets->{$server} = $targetsref->{$server};
1.150 raeburn 8319: }
8320: }
8321: }
1.160.6.7 raeburn 8322: return;
1.150 raeburn 8323: }
8324:
8325: sub loadbalancing_rules {
8326: my ($dom,$intdom,$currrules,$othertitle,$usertypes,$types,$servers,
1.160.6.7 raeburn 8327: $currbalancer,$lonhost,$targets_div_style,$homedom_div_style,
8328: $css_class,$balnum,$islast) = @_;
1.150 raeburn 8329: my $output;
1.160.6.7 raeburn 8330: my $num = 0;
8331: my ($alltypes,$othertypes,$titles) =
1.150 raeburn 8332: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
8333: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
8334: foreach my $type (@{$alltypes}) {
1.160.6.7 raeburn 8335: $num ++;
1.150 raeburn 8336: my $current;
8337: if (ref($currrules) eq 'HASH') {
8338: $current = $currrules->{$type};
8339: }
1.160.6.55 raeburn 8340: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.160.6.7 raeburn 8341: if ($dom ne &Apache::lonnet::host_domain($lonhost)) {
1.150 raeburn 8342: $current = '';
8343: }
8344: }
8345: $output .= &loadbalance_rule_row($type,$titles->{$type},$current,
1.160.6.7 raeburn 8346: $servers,$currbalancer,$lonhost,$dom,
8347: $targets_div_style,$homedom_div_style,
8348: $css_class,$balnum,$num,$islast);
1.150 raeburn 8349: }
8350: }
8351: return $output;
8352: }
8353:
8354: sub loadbalancing_titles {
8355: my ($dom,$intdom,$usertypes,$types) = @_;
8356: my %othertypes = (
8357: '_LC_adv' => &mt('Advanced users from [_1]',$dom),
8358: '_LC_author' => &mt('Users from [_1] with author role',$dom),
8359: '_LC_internetdom' => &mt('Users not from [_1], but from [_2]',$dom,$intdom),
8360: '_LC_external' => &mt('Users not from [_1]',$intdom),
1.160.6.26 raeburn 8361: '_LC_ipchangesso' => &mt('SSO users from [_1], with IP mismatch',$dom),
8362: '_LC_ipchange' => &mt('Non-SSO users with IP mismatch'),
1.150 raeburn 8363: );
1.160.6.26 raeburn 8364: my @alltypes = ('_LC_adv','_LC_author','_LC_internetdom','_LC_external','_LC_ipchangesso','_LC_ipchange');
1.160.6.89 raeburn 8365: my @available;
1.150 raeburn 8366: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8367: @available = @{$types};
1.150 raeburn 8368: }
1.160.6.89 raeburn 8369: unless (grep(/^default$/,@available)) {
8370: push(@available,'default');
8371: }
8372: unshift(@alltypes,@available);
1.150 raeburn 8373: my %titles;
8374: foreach my $type (@alltypes) {
8375: if ($type =~ /^_LC_/) {
8376: $titles{$type} = $othertypes{$type};
8377: } elsif ($type eq 'default') {
8378: $titles{$type} = &mt('All users from [_1]',$dom);
8379: if (ref($types) eq 'ARRAY') {
8380: if (@{$types} > 0) {
8381: $titles{$type} = &mt('Other users from [_1]',$dom);
8382: }
8383: }
8384: } elsif (ref($usertypes) eq 'HASH') {
8385: $titles{$type} = $usertypes->{$type};
8386: }
8387: }
8388: return (\@alltypes,\%othertypes,\%titles);
8389: }
8390:
8391: sub loadbalance_rule_row {
1.160.6.7 raeburn 8392: my ($type,$title,$current,$servers,$currbalancer,$lonhost,$dom,
8393: $targets_div_style,$homedom_div_style,$css_class,$balnum,$num,$islast) = @_;
1.160.6.26 raeburn 8394: my @rulenames;
1.150 raeburn 8395: my %ruletitles = &offloadtype_text();
1.160.6.26 raeburn 8396: if (($type eq '_LC_ipchangesso') || ($type eq '_LC_ipchange')) {
1.160.6.55 raeburn 8397: @rulenames = ('balancer','offloadedto','specific');
1.150 raeburn 8398: } else {
1.160.6.26 raeburn 8399: @rulenames = ('default','homeserver');
8400: if ($type eq '_LC_external') {
8401: push(@rulenames,'externalbalancer');
8402: } else {
8403: push(@rulenames,'specific');
8404: }
8405: push(@rulenames,'none');
1.150 raeburn 8406: }
8407: my $style = $targets_div_style;
1.160.6.55 raeburn 8408: if (($type eq '_LC_external') || ($type eq '_LC_internetdom')) {
1.150 raeburn 8409: $style = $homedom_div_style;
8410: }
1.160.6.7 raeburn 8411: my $space;
8412: if ($islast && $num == 1) {
1.160.6.118.2 14(raebu 8413:23): $space = '<div style="display:inline-block;"> </div>';
1.160.6.7 raeburn 8414: }
8415: my $output =
8416: '<tr class="'.$css_class.'" id="balanceruletr_'.$balnum.'_'.$num.'"><td valign="top">'.$space.
8417: '<div id="balanceruletitle_'.$balnum.'_'.$type.'" style="'.$style.'">'.$title.'</div></td>'."\n".
8418: '<td valaign="top">'.$space.
8419: '<div id="balancerule_'.$balnum.'_'.$type.'" style="'.$style.'">'."\n";
1.150 raeburn 8420: for (my $i=0; $i<@rulenames; $i++) {
8421: my $rule = $rulenames[$i];
8422: my ($checked,$extra);
8423: if ($rulenames[$i] eq 'default') {
8424: $rule = '';
8425: }
8426: if ($rulenames[$i] eq 'specific') {
8427: if (ref($servers) eq 'HASH') {
8428: my $default;
8429: if (($current ne '') && (exists($servers->{$current}))) {
8430: $checked = ' checked="checked"';
8431: }
8432: unless ($checked) {
8433: $default = ' selected="selected"';
8434: }
1.160.6.7 raeburn 8435: $extra =
8436: ': <select name="loadbalancing_singleserver_'.$balnum.'_'.$type.
8437: '" id="loadbalancing_singleserver_'.$balnum.'_'.$type.
8438: '" onchange="singleServerToggle('."'$balnum','$type'".')">'."\n".
8439: '<option value=""'.$default.'></option>'."\n";
8440: foreach my $server (sort(keys(%{$servers}))) {
8441: if (ref($currbalancer) eq 'HASH') {
8442: next if (exists($currbalancer->{$server}));
8443: }
1.150 raeburn 8444: my $selected;
1.160.6.7 raeburn 8445: if ($server eq $current) {
1.150 raeburn 8446: $selected = ' selected="selected"';
8447: }
1.160.6.7 raeburn 8448: $extra .= '<option value="'.$server.'"'.$selected.'>'.$server.'</option>';
1.150 raeburn 8449: }
8450: $extra .= '</select>';
8451: }
8452: } elsif ($rule eq $current) {
8453: $checked = ' checked="checked"';
8454: }
8455: $output .= '<span class="LC_nobreak"><label>'.
1.160.6.7 raeburn 8456: '<input type="radio" name="loadbalancing_rules_'.$balnum.'_'.$type.
8457: '" id="loadbalancing_rules_'.$balnum.'_'.$type.'_'.$i.'" value="'.
8458: $rule.'" onclick="balanceruleChange('."this.form,'$balnum','$type'".
1.160.6.55 raeburn 8459: ')"'.$checked.' /> ';
1.160.6.56 raeburn 8460: if (($rulenames[$i] eq 'specific') && ($type =~ /^_LC_ipchange/)) {
1.160.6.55 raeburn 8461: $output .= $ruletitles{'particular'};
8462: } else {
8463: $output .= $ruletitles{$rulenames[$i]};
8464: }
8465: $output .= '</label>'.$extra.'</span><br />'."\n";
1.150 raeburn 8466: }
8467: $output .= '</div></td></tr>'."\n";
8468: return $output;
8469: }
8470:
8471: sub offloadtype_text {
8472: my %ruletitles = &Apache::lonlocal::texthash (
8473: 'default' => 'Offloads to default destinations',
8474: 'homeserver' => "Offloads to user's home server",
8475: 'externalbalancer' => "Offloads to Load Balancer in user's domain",
8476: 'specific' => 'Offloads to specific server',
1.160.6.3 raeburn 8477: 'none' => 'No offload',
1.160.6.26 raeburn 8478: 'balancer' => 'Session hosted on Load Balancer, after re-authentication',
8479: 'offloadedto' => 'Session hosted on offload server, after re-authentication',
1.160.6.55 raeburn 8480: 'particular' => 'Session hosted (after re-auth) on server:',
1.150 raeburn 8481: );
8482: return %ruletitles;
8483: }
8484:
8485: sub sparestype_titles {
8486: my %typestitles = &Apache::lonlocal::texthash (
8487: 'primary' => 'primary',
8488: 'default' => 'default',
8489: );
8490: return %typestitles;
8491: }
8492:
1.28 raeburn 8493: sub contact_titles {
8494: my %titles = &Apache::lonlocal::texthash (
1.160.6.78 raeburn 8495: 'supportemail' => 'Support E-mail address',
8496: 'adminemail' => 'Default Server Admin E-mail address',
8497: 'errormail' => 'Error reports to be e-mailed to',
8498: 'packagesmail' => 'Package update alerts to be e-mailed to',
1.160.6.101 raeburn 8499: 'helpdeskmail' => "Helpdesk requests from all users in this domain",
8500: 'otherdomsmail' => 'Helpdesk requests from users in other (unconfigured) domains',
1.160.6.78 raeburn 8501: 'lonstatusmail' => 'E-mail from nightly status check (warnings/errors)',
8502: 'requestsmail' => 'E-mail from course requests requiring approval',
8503: 'updatesmail' => 'E-mail from nightly check of LON-CAPA module integrity/updates',
1.160.6.23 raeburn 8504: 'idconflictsmail' => 'E-mail from bi-nightly check for multiple users sharing same student/employee ID',
1.160.6.91 raeburn 8505: 'hostipmail' => 'E-mail from nightly check of hostname/IP network changes',
1.160.6.109 raeburn 8506: 'errorthreshold' => 'Error count threshold for status e-mail to admin(s)',
8507: 'errorsysmail' => 'Error count threshold for e-mail to developer group',
1.160.6.107 raeburn 8508: 'errorweights' => 'Weights used to compute error count',
8509: 'errorexcluded' => 'Servers with unsent updates excluded from count',
1.28 raeburn 8510: );
8511: my %short_titles = &Apache::lonlocal::texthash (
8512: adminemail => 'Admin E-mail address',
8513: supportemail => 'Support E-mail',
8514: );
8515: return (\%titles,\%short_titles);
8516: }
8517:
1.160.6.78 raeburn 8518: sub helpform_fields {
8519: my %titles = &Apache::lonlocal::texthash (
8520: 'username' => 'Name',
8521: 'user' => 'Username/domain',
8522: 'phone' => 'Phone',
8523: 'cc' => 'Cc e-mail',
8524: 'course' => 'Course Details',
8525: 'section' => 'Sections',
8526: 'screenshot' => 'File upload',
8527: );
8528: my @fields = ('username','phone','user','course','section','cc','screenshot');
8529: my %possoptions = (
8530: username => ['yes','no','req'],
8531: phone => ['yes','no','req'],
8532: user => ['yes','no'],
8533: cc => ['yes','no'],
8534: course => ['yes','no'],
8535: section => ['yes','no'],
8536: screenshot => ['yes','no'],
8537: );
8538: my %fieldoptions = &Apache::lonlocal::texthash (
8539: 'yes' => 'Optional',
8540: 'req' => 'Required',
8541: 'no' => "Not shown",
8542: );
8543: return (\@fields,\%titles,\%fieldoptions,\%possoptions);
8544: }
8545:
1.72 raeburn 8546: sub tool_titles {
8547: my %titles = &Apache::lonlocal::texthash (
1.160.6.4 raeburn 8548: aboutme => 'Personal web page',
1.86 raeburn 8549: blog => 'Blog',
8550: portfolio => 'Portfolio',
1.160.6.118.2 23(raebu 8551:24): portaccess => 'Share portfolio files',
10(raebu 8552:22): timezone => 'Can set time zone',
1.88 bisitz 8553: official => 'Official courses (with institutional codes)',
8554: unofficial => 'Unofficial courses',
1.98 raeburn 8555: community => 'Communities',
1.160.6.30 raeburn 8556: textbook => 'Textbook courses',
1.86 raeburn 8557: );
1.72 raeburn 8558: return %titles;
8559: }
8560:
1.101 raeburn 8561: sub courserequest_titles {
8562: my %titles = &Apache::lonlocal::texthash (
8563: official => 'Official',
8564: unofficial => 'Unofficial',
8565: community => 'Communities',
1.160.6.30 raeburn 8566: textbook => 'Textbook',
1.160.6.118.2 14(raebu 8567:23): lti => 'LTI Provider',
1.101 raeburn 8568: norequest => 'Not allowed',
1.104 raeburn 8569: approval => 'Approval by Dom. Coord.',
1.101 raeburn 8570: validate => 'With validation',
8571: autolimit => 'Numerical limit',
1.103 raeburn 8572: unlimited => '(blank for unlimited)',
1.101 raeburn 8573: );
8574: return %titles;
8575: }
8576:
1.160.6.5 raeburn 8577: sub authorrequest_titles {
8578: my %titles = &Apache::lonlocal::texthash (
8579: norequest => 'Not allowed',
8580: approval => 'Approval by Dom. Coord.',
8581: automatic => 'Automatic approval',
8582: );
8583: return %titles;
8584: }
8585:
1.101 raeburn 8586: sub courserequest_conditions {
8587: my %conditions = &Apache::lonlocal::texthash (
1.104 raeburn 8588: approval => '(Processing of request subject to approval by Domain Coordinator).',
1.160.6.17 raeburn 8589: validate => '(Processing of request subject to institutional validation).',
1.101 raeburn 8590: );
8591: return %conditions;
8592: }
8593:
8594:
1.27 raeburn 8595: sub print_usercreation {
1.30 raeburn 8596: my ($position,$dom,$settings,$rowtotal) = @_;
1.27 raeburn 8597: my $numinrow = 4;
1.28 raeburn 8598: my $datatable;
8599: if ($position eq 'top') {
1.30 raeburn 8600: $$rowtotal ++;
1.34 raeburn 8601: my $rowcount = 0;
1.32 raeburn 8602: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($dom,'username');
1.28 raeburn 8603: if (ref($rules) eq 'HASH') {
8604: if (keys(%{$rules}) > 0) {
1.32 raeburn 8605: $datatable .= &user_formats_row('username',$settings,$rules,
8606: $ruleorder,$numinrow,$rowcount);
1.30 raeburn 8607: $$rowtotal ++;
1.32 raeburn 8608: $rowcount ++;
8609: }
8610: }
8611: my ($idrules,$idruleorder) = &Apache::lonnet::inst_userrules($dom,'id');
8612: if (ref($idrules) eq 'HASH') {
8613: if (keys(%{$idrules}) > 0) {
8614: $datatable .= &user_formats_row('id',$settings,$idrules,
8615: $idruleorder,$numinrow,$rowcount);
8616: $$rowtotal ++;
8617: $rowcount ++;
1.28 raeburn 8618: }
8619: }
1.39 raeburn 8620: if ($rowcount == 0) {
8621: $datatable .= '<tr><td colspan="2">'.&mt('No format rules have been defined for usernames or IDs in this domain.').'</td></tr>';
8622: $$rowtotal ++;
8623: $rowcount ++;
8624: }
1.34 raeburn 8625: } elsif ($position eq 'middle') {
1.160.6.34 raeburn 8626: my @creators = ('author','course','requestcrs');
1.37 raeburn 8627: my ($rules,$ruleorder) =
8628: &Apache::lonnet::inst_userrules($dom,'username');
1.34 raeburn 8629: my %lt = &usercreation_types();
8630: my %checked;
8631: if (ref($settings) eq 'HASH') {
8632: if (ref($settings->{'cancreate'}) eq 'HASH') {
8633: foreach my $item (@creators) {
8634: $checked{$item} = $settings->{'cancreate'}{$item};
8635: }
8636: } elsif (ref($settings->{'cancreate'}) eq 'ARRAY') {
8637: foreach my $item (@creators) {
8638: if (grep(/^\Q$item\E$/,@{$settings->{'cancreate'}})) {
8639: $checked{$item} = 'none';
8640: }
8641: }
8642: }
8643: }
8644: my $rownum = 0;
8645: foreach my $item (@creators) {
8646: $rownum ++;
1.160.6.34 raeburn 8647: if ($checked{$item} eq '') {
8648: $checked{$item} = 'any';
1.34 raeburn 8649: }
8650: my $css_class;
8651: if ($rownum%2) {
8652: $css_class = '';
8653: } else {
8654: $css_class = ' class="LC_odd_row" ';
8655: }
8656: $datatable .= '<tr'.$css_class.'>'.
8657: '<td><span class="LC_nobreak">'.$lt{$item}.
8658: '</span></td><td align="right">';
1.160.6.34 raeburn 8659: my @options = ('any');
8660: if (ref($rules) eq 'HASH') {
8661: if (keys(%{$rules}) > 0) {
8662: push(@options,('official','unofficial'));
1.37 raeburn 8663: }
8664: }
1.160.6.34 raeburn 8665: push(@options,'none');
1.37 raeburn 8666: foreach my $option (@options) {
1.50 raeburn 8667: my $type = 'radio';
1.34 raeburn 8668: my $check = ' ';
1.160.6.34 raeburn 8669: if ($checked{$item} eq $option) {
8670: $check = ' checked="checked" ';
1.34 raeburn 8671: }
8672: $datatable .= '<span class="LC_nobreak"><label>'.
1.50 raeburn 8673: '<input type="'.$type.'" name="can_createuser_'.
1.34 raeburn 8674: $item.'" value="'.$option.'"'.$check.'/> '.
8675: $lt{$option}.'</label> </span>';
8676: }
8677: $datatable .= '</td></tr>';
8678: }
1.28 raeburn 8679: } else {
8680: my @contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 8681:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 8682: my %checked;
8683: if (ref($settings) eq 'HASH') {
8684: if (ref($settings->{'authtypes'}) eq 'HASH') {
8685: foreach my $item (@contexts) {
8686: if (ref($settings->{'authtypes'}{$item}) eq 'HASH') {
8687: foreach my $auth (@authtypes) {
8688: if ($settings->{'authtypes'}{$item}{$auth}) {
8689: $checked{$item}{$auth} = ' checked="checked" ';
8690: }
8691: }
8692: }
8693: }
1.27 raeburn 8694: }
1.35 raeburn 8695: } else {
8696: foreach my $item (@contexts) {
1.36 raeburn 8697: foreach my $auth (@authtypes) {
1.35 raeburn 8698: $checked{$item}{$auth} = ' checked="checked" ';
8699: }
8700: }
1.27 raeburn 8701: }
1.28 raeburn 8702: my %title = &context_names();
8703: my %authname = &authtype_names();
8704: my $rownum = 0;
8705: my $css_class;
8706: foreach my $item (@contexts) {
8707: if ($rownum%2) {
8708: $css_class = '';
8709: } else {
8710: $css_class = ' class="LC_odd_row" ';
8711: }
1.30 raeburn 8712: $datatable .= '<tr'.$css_class.'>'.
1.28 raeburn 8713: '<td>'.$title{$item}.
8714: '</td><td class="LC_left_item">'.
8715: '<span class="LC_nobreak">';
8716: foreach my $auth (@authtypes) {
8717: $datatable .= '<label>'.
8718: '<input type="checkbox" name="'.$item.'_auth" '.
8719: $checked{$item}{$auth}.' value="'.$auth.'" />'.
8720: $authname{$auth}.'</label> ';
8721: }
8722: $datatable .= '</span></td></tr>';
8723: $rownum ++;
1.27 raeburn 8724: }
1.30 raeburn 8725: $$rowtotal += $rownum;
1.27 raeburn 8726: }
8727: return $datatable;
8728: }
8729:
1.160.6.34 raeburn 8730: sub print_selfcreation {
8731: my ($position,$dom,$settings,$rowtotal) = @_;
1.160.6.93 raeburn 8732: my (@selfcreate,$createsettings,$processing,$emailoptions,$emailverified,
8733: $emaildomain,$datatable);
1.160.6.34 raeburn 8734: if (ref($settings) eq 'HASH') {
8735: if (ref($settings->{'cancreate'}) eq 'HASH') {
8736: $createsettings = $settings->{'cancreate'};
1.160.6.40 raeburn 8737: if (ref($createsettings) eq 'HASH') {
8738: if (ref($createsettings->{'selfcreate'}) eq 'ARRAY') {
8739: @selfcreate = @{$createsettings->{'selfcreate'}};
8740: } elsif ($createsettings->{'selfcreate'} ne '') {
8741: if ($settings->{'cancreate'}{'selfcreate'} eq 'any') {
8742: @selfcreate = ('email','login','sso');
8743: } elsif ($createsettings->{'selfcreate'} ne 'none') {
8744: @selfcreate = ($createsettings->{'selfcreate'});
8745: }
8746: }
8747: if (ref($createsettings->{'selfcreateprocessing'}) eq 'HASH') {
8748: $processing = $createsettings->{'selfcreateprocessing'};
1.160.6.34 raeburn 8749: }
1.160.6.93 raeburn 8750: if (ref($createsettings->{'emailoptions'}) eq 'HASH') {
8751: $emailoptions = $createsettings->{'emailoptions'};
8752: }
8753: if (ref($createsettings->{'emailverified'}) eq 'HASH') {
8754: $emailverified = $createsettings->{'emailverified'};
8755: }
8756: if (ref($createsettings->{'emaildomain'}) eq 'HASH') {
8757: $emaildomain = $createsettings->{'emaildomain'};
8758: }
1.160.6.34 raeburn 8759: }
8760: }
8761: }
8762: my %radiohash;
8763: my $numinrow = 4;
8764: map { $radiohash{'cancreate_'.$_} = 1; } @selfcreate;
1.160.6.89 raeburn 8765: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.34 raeburn 8766: if ($position eq 'top') {
8767: my %choices = &Apache::lonlocal::texthash (
8768: cancreate_login => 'Institutional Login',
8769: cancreate_sso => 'Institutional Single Sign On',
8770: );
8771: my @toggles = sort(keys(%choices));
8772: my %defaultchecked = (
8773: 'cancreate_login' => 'off',
8774: 'cancreate_sso' => 'off',
8775: );
1.160.6.35 raeburn 8776: my ($onclick,$itemcount);
1.160.6.34 raeburn 8777: ($datatable,$itemcount) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8778: \%choices,$itemcount,$onclick);
1.160.6.35 raeburn 8779: $$rowtotal += $itemcount;
1.160.6.34 raeburn 8780:
8781: if (ref($usertypes) eq 'HASH') {
8782: if (keys(%{$usertypes}) > 0) {
8783: $datatable .= &insttypes_row($createsettings,$types,$usertypes,
8784: $dom,$numinrow,$othertitle,
1.160.6.89 raeburn 8785: 'statustocreate',$rowtotal);
1.160.6.34 raeburn 8786: $$rowtotal ++;
8787: }
8788: }
1.160.6.44 raeburn 8789: my @fields = ('lastname','firstname','middlename','permanentemail','id','inststatus');
8790: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
8791: $fieldtitles{'inststatus'} = &mt('Institutional status');
8792: my $rem;
8793: my $numperrow = 2;
8794: my $css_class = $$rowtotal%2?' class="LC_odd_row"':'';
8795: $datatable .= '<tr'.$css_class.'>'.
1.160.6.45 raeburn 8796: '<td class="LC_left_item">'.&mt('Mapping of Shibboleth environment variable names to user data fields (SSO auth)').'</td>'.
1.160.6.44 raeburn 8797: '<td class="LC_left_item">'."\n".
1.160.6.87 raeburn 8798: '<table>'."\n";
1.160.6.44 raeburn 8799: for (my $i=0; $i<@fields; $i++) {
8800: $rem = $i%($numperrow);
8801: if ($rem == 0) {
8802: if ($i > 0) {
8803: $datatable .= '</tr>';
8804: }
8805: $datatable .= '<tr>';
8806: }
8807: my $currval;
1.160.6.51 raeburn 8808: if (ref($createsettings) eq 'HASH') {
8809: if (ref($createsettings->{'shibenv'}) eq 'HASH') {
8810: $currval = $createsettings->{'shibenv'}{$fields[$i]};
8811: }
1.160.6.44 raeburn 8812: }
8813: $datatable .= '<td class="LC_left_item">'.
8814: '<span class="LC_nobreak">'.
8815: '<input type="text" name="shibenv_'.$fields[$i].'" '.
8816: 'value="'.$currval.'" size="10" /> '.
8817: $fieldtitles{$fields[$i]}.'</span></td>';
8818: }
8819: my $colsleft = $numperrow - $rem;
8820: if ($colsleft > 1 ) {
8821: $datatable .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
8822: ' </td>';
8823: } elsif ($colsleft == 1) {
8824: $datatable .= '<td class="LC_left_item"> </td>';
8825: }
8826: $datatable .= '</tr></table></td></tr>';
8827: $$rowtotal ++;
1.160.6.34 raeburn 8828: } elsif ($position eq 'middle') {
8829: my %domconf = &Apache::lonnet::get_dom('configuration',['usermodification'],$dom);
1.160.6.89 raeburn 8830: my @posstypes;
1.160.6.34 raeburn 8831: if (ref($types) eq 'ARRAY') {
1.160.6.89 raeburn 8832: @posstypes = @{$types};
8833: }
8834: unless (grep(/^default$/,@posstypes)) {
8835: push(@posstypes,'default');
8836: }
8837: my %usertypeshash;
8838: if (ref($usertypes) eq 'HASH') {
8839: %usertypeshash = %{$usertypes};
8840: }
8841: $usertypeshash{'default'} = $othertitle;
8842: foreach my $status (@posstypes) {
8843: $datatable .= &modifiable_userdata_row('selfcreate',$status,$domconf{'usermodification'},
8844: $numinrow,$$rowtotal,\%usertypeshash);
8845: $$rowtotal ++;
1.160.6.34 raeburn 8846: }
8847: } else {
1.160.6.40 raeburn 8848: my %choices = &Apache::lonlocal::texthash (
1.160.6.93 raeburn 8849: 'cancreate_email' => 'Non-institutional username (via e-mail verification)',
1.160.6.40 raeburn 8850: );
8851: my @toggles = sort(keys(%choices));
8852: my %defaultchecked = (
8853: 'cancreate_email' => 'off',
8854: );
1.160.6.93 raeburn 8855: my $customclass = 'LC_selfcreate_email';
8856: my $classprefix = 'LC_canmodify_emailusername_';
8857: my $optionsprefix = 'LC_options_emailusername_';
1.160.6.40 raeburn 8858: my $display = 'none';
1.160.6.93 raeburn 8859: my $rowstyle = 'display:none';
1.160.6.40 raeburn 8860: if (grep(/^\Qemail\E$/,@selfcreate)) {
8861: $display = 'block';
1.160.6.93 raeburn 8862: $rowstyle = 'display:table-row';
1.160.6.40 raeburn 8863: }
1.160.6.93 raeburn 8864: my $onclick = "toggleRows(this.form,'cancreate_email','selfassign','$customclass','$classprefix','$optionsprefix');";
8865: ($datatable,$$rowtotal) = &radiobutton_prefs(\%radiohash,\@toggles,\%defaultchecked,
8866: \%choices,$$rowtotal,$onclick);
8867: $datatable .= &print_requestmail($dom,'selfcreation',$createsettings,$rowtotal,$customclass,
8868: $rowstyle);
8869: $$rowtotal ++;
8870: $datatable .= &captcha_choice('cancreate',$createsettings,$$rowtotal,$customclass,
8871: $rowstyle);
8872: $$rowtotal ++;
8873: my (@ordered,@posstypes,%usertypeshash);
1.160.6.40 raeburn 8874: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
1.160.6.93 raeburn 8875: my ($emailrules,$emailruleorder) =
8876: &Apache::lonnet::inst_userrules($dom,'email');
8877: my $primary_id = &Apache::lonnet::domain($dom,'primary');
8878: my $intdom = &Apache::lonnet::internet_dom($primary_id);
8879: if (ref($types) eq 'ARRAY') {
8880: @posstypes = @{$types};
8881: }
8882: if (@posstypes) {
8883: unless (grep(/^default$/,@posstypes)) {
8884: push(@posstypes,'default');
1.160.6.89 raeburn 8885: }
8886: if (ref($usertypes) eq 'HASH') {
8887: %usertypeshash = %{$usertypes};
8888: }
1.160.6.93 raeburn 8889: my $currassign;
8890: if (ref($domdefaults{'inststatusguest'}) eq 'ARRAY') {
8891: $currassign = {
8892: selfassign => $domdefaults{'inststatusguest'},
8893: };
8894: @ordered = @{$domdefaults{'inststatusguest'}};
8895: } else {
8896: $currassign = { selfassign => [] };
8897: }
8898: my $onclicktypes = "toggleDataRow(this.form,'selfassign','$customclass','$optionsprefix',);".
8899: "toggleDataRow(this.form,'selfassign','$customclass','$classprefix',1);";
8900: $datatable .= &insttypes_row($currassign,$types,$usertypes,$dom,
8901: $numinrow,$othertitle,'selfassign',
8902: $rowtotal,$onclicktypes,$customclass,
8903: $rowstyle);
8904: $$rowtotal ++;
1.160.6.89 raeburn 8905: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8906: foreach my $status (@posstypes) {
8907: my $css_class;
8908: if ($$rowtotal%2) {
8909: $css_class = 'LC_odd_row ';
8910: }
8911: $css_class .= $customclass;
8912: my $rowid = $optionsprefix.$status;
8913: my $hidden = 1;
8914: my $currstyle = 'display:none';
8915: if (grep(/^\Q$status\E$/,@ordered)) {
8916: $currstyle = $rowstyle;
8917: $hidden = 0;
8918: }
8919: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8920: $emailrules,$emailruleorder,$settings,$status,$rowid,
8921: $usertypeshash{$status},$css_class,$currstyle,$intdom);
8922: unless ($hidden) {
8923: $$rowtotal ++;
8924: }
1.160.6.89 raeburn 8925: }
8926: } else {
1.160.6.93 raeburn 8927: my $css_class;
8928: if ($$rowtotal%2) {
8929: $css_class = 'LC_odd_row ';
8930: }
8931: $css_class .= $customclass;
1.160.6.89 raeburn 8932: $usertypeshash{'default'} = $othertitle;
1.160.6.93 raeburn 8933: $datatable .= &noninst_users($processing,$emailverified,$emailoptions,$emaildomain,
8934: $emailrules,$emailruleorder,$settings,'default','',
8935: $othertitle,$css_class,$rowstyle,$intdom);
8936: $$rowtotal ++;
1.160.6.34 raeburn 8937: }
1.160.6.35 raeburn 8938: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
8939: $numinrow = 1;
1.160.6.93 raeburn 8940: if (@posstypes) {
8941: foreach my $status (@posstypes) {
8942: my $rowid = $classprefix.$status;
8943: my $datarowstyle = 'display:none';
8944: if (grep(/^\Q$status\E$/,@ordered)) {
8945: $datarowstyle = $rowstyle;
8946: }
8947: $datatable .= &modifiable_userdata_row('cancreate','emailusername_'.$status,$settings,
8948: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8949: $infotitles,$rowid,$customclass,$datarowstyle);
8950: unless ($datarowstyle eq 'display:none') {
8951: $$rowtotal ++;
8952: }
1.160.6.34 raeburn 8953: }
1.160.6.93 raeburn 8954: } else {
8955: $datatable .= &modifiable_userdata_row('cancreate','emailusername_default',$settings,
8956: $numinrow,$$rowtotal,\%usertypeshash,$infofields,
8957: $infotitles,'',$customclass,$rowstyle);
1.160.6.34 raeburn 8958: }
8959: }
8960: return $datatable;
8961: }
8962:
1.160.6.93 raeburn 8963: sub selfcreate_javascript {
8964: return <<"ENDSCRIPT";
8965:
8966: <script type="text/javascript">
8967: // <![CDATA[
8968:
8969: function toggleRows(form,radio,checkbox,target,prefix,altprefix) {
8970: var x = document.getElementsByClassName(target);
8971: var insttypes = 0;
8972: var insttypeRegExp = new RegExp(prefix);
8973: if ((x.length != undefined) && (x.length > 0)) {
8974: if (form.elements[radio].length != undefined) {
8975: for (var i=0; i<form.elements[radio].length; i++) {
8976: if (form.elements[radio][i].checked) {
8977: if (form.elements[radio][i].value == 1) {
8978: for (var j=0; j<x.length; j++) {
8979: if (x[j].id == 'undefined') {
8980: x[j].style.display = 'table-row';
8981: } else if (insttypeRegExp.test(x[j].id)) {
8982: insttypes ++;
8983: } else {
8984: x[j].style.display = 'table-row';
8985: }
8986: }
8987: } else {
8988: for (var j=0; j<x.length; j++) {
8989: x[j].style.display = 'none';
8990: }
1.160.6.40 raeburn 8991: }
1.160.6.93 raeburn 8992: break;
8993: }
8994: }
8995: if (insttypes > 0) {
8996: toggleDataRow(form,checkbox,target,altprefix);
8997: toggleDataRow(form,checkbox,target,prefix,1);
8998: }
8999: }
9000: }
9001: return;
9002: }
9003:
9004: function toggleDataRow(form,checkbox,target,prefix,docount) {
9005: if (form.elements[checkbox].length != undefined) {
9006: var count = 0;
9007: if (docount) {
9008: for (var i=0; i<form.elements[checkbox].length; i++) {
9009: if (form.elements[checkbox][i].checked) {
9010: count ++;
9011: }
9012: }
9013: }
9014: for (var i=0; i<form.elements[checkbox].length; i++) {
9015: var type = form.elements[checkbox][i].value;
9016: if (document.getElementById(prefix+type)) {
9017: if (form.elements[checkbox][i].checked) {
9018: document.getElementById(prefix+type).style.display = 'table-row';
9019: if (count % 2 == 1) {
9020: document.getElementById(prefix+type).className = target+' LC_odd_row';
9021: } else {
9022: document.getElementById(prefix+type).className = target;
9023: }
9024: count ++;
1.160.6.40 raeburn 9025: } else {
1.160.6.93 raeburn 9026: document.getElementById(prefix+type).style.display = 'none';
9027: }
9028: }
9029: }
9030: }
9031: return;
9032: }
9033:
9034: function toggleEmailOptions(form,radio,prefix,altprefix,status) {
9035: var caller = radio+'_'+status;
9036: if (form.elements[caller].length != undefined) {
9037: for (var i=0; i<form.elements[caller].length; i++) {
9038: if (form.elements[caller][i].checked) {
9039: if (document.getElementById(altprefix+'_inst_'+status)) {
9040: var curr = form.elements[caller][i].value;
9041: if (prefix) {
9042: document.getElementById(prefix+'_'+status).style.display = 'none';
9043: }
9044: document.getElementById(altprefix+'_inst_'+status).style.display = 'none';
9045: document.getElementById(altprefix+'_noninst_'+status).style.display = 'none';
9046: if (curr == 'custom') {
9047: if (prefix) {
9048: document.getElementById(prefix+'_'+status).style.display = 'inline';
9049: }
9050: } else if (curr == 'inst') {
9051: document.getElementById(altprefix+'_inst_'+status).style.display = 'inline';
9052: } else if (curr == 'noninst') {
9053: document.getElementById(altprefix+'_noninst_'+status).style.display = 'inline';
1.160.6.40 raeburn 9054: }
1.160.6.93 raeburn 9055: break;
1.160.6.40 raeburn 9056: }
1.160.6.93 raeburn 9057: }
9058: }
9059: }
9060: }
9061:
9062: // ]]>
9063: </script>
9064:
9065: ENDSCRIPT
9066: }
9067:
9068: sub noninst_users {
9069: my ($processing,$emailverified,$emailoptions,$emaildomain,$emailrules,
9070: $emailruleorder,$settings,$type,$rowid,$typetitle,$css_class,$rowstyle,$intdom) = @_;
9071: my $class = 'LC_left_item';
9072: if ($css_class) {
9073: $css_class = ' class="'.$css_class.'"';
9074: }
9075: if ($rowid) {
9076: $rowid = ' id="'.$rowid.'"';
9077: }
9078: if ($rowstyle) {
9079: $rowstyle = ' style="'.$rowstyle.'"';
9080: }
9081: my ($output,$description);
9082: if ($type eq 'default') {
9083: $description = &mt('Requests for: [_1]',$typetitle);
9084: } else {
9085: $description = &mt('Requests for: [_1] (status self-reported)',$typetitle);
9086: }
9087: $output = '<tr'.$css_class.$rowid.$rowstyle.'>'.
9088: "<td>$description</td>\n".
9089: '<td class="'.$class.'" colspan="2">'.
9090: '<table><tr>';
9091: my %headers = &Apache::lonlocal::texthash(
9092: approve => 'Processing',
9093: email => 'E-mail',
9094: username => 'Username',
9095: );
9096: foreach my $item ('approve','email','username') {
9097: $output .= '<th>'.$headers{$item}.'</th>';
9098: }
9099: $output .= '</tr><tr>';
9100: foreach my $item ('approve','email','username') {
9101: $output .= '<td valign="top">';
9102: my (%choices,@options,$hashref,$defoption,$name,$onclick,$hascustom);
9103: if ($item eq 'approve') {
9104: %choices = &Apache::lonlocal::texthash (
9105: automatic => 'Automatically approved',
9106: approval => 'Queued for approval',
9107: );
9108: @options = ('automatic','approval');
9109: $hashref = $processing;
9110: $defoption = 'automatic';
9111: $name = 'cancreate_emailprocess_'.$type;
9112: } elsif ($item eq 'email') {
9113: %choices = &Apache::lonlocal::texthash (
9114: any => 'Any e-mail',
9115: inst => 'Institutional only',
9116: noninst => 'Non-institutional only',
9117: custom => 'Custom restrictions',
9118: );
9119: @options = ('any','inst','noninst');
9120: my $showcustom;
9121: if (ref($emailrules) eq 'HASH') {
9122: if (keys(%{$emailrules}) > 0) {
9123: push(@options,'custom');
9124: $showcustom = 'cancreate_emailrule';
9125: if (ref($settings) eq 'HASH') {
9126: if (ref($settings->{'email_rule'}) eq 'ARRAY') {
9127: foreach my $rule (@{$settings->{'email_rule'}}) {
9128: if (exists($emailrules->{$rule})) {
9129: $hascustom ++;
9130: }
9131: }
9132: } elsif (ref($settings->{'email_rule'}) eq 'HASH') {
9133: if (ref($settings->{'email_rule'}{$type}) eq 'ARRAY') {
9134: foreach my $rule (@{$settings->{'email_rule'}{$type}}) {
9135: if (exists($emailrules->{$rule})) {
9136: $hascustom ++;
9137: }
9138: }
9139: }
9140: }
9141: }
9142: }
9143: }
9144: $onclick = ' onclick="toggleEmailOptions(this.form,'."'cancreate_emailoptions','$showcustom',".
9145: "'cancreate_emaildomain','$type'".');"';
9146: $hashref = $emailoptions;
9147: $defoption = 'any';
9148: $name = 'cancreate_emailoptions_'.$type;
9149: } elsif ($item eq 'username') {
9150: %choices = &Apache::lonlocal::texthash (
9151: all => 'Same as e-mail',
9152: first => 'Omit @domain',
9153: free => 'Free to choose',
9154: );
9155: @options = ('all','first','free');
9156: $hashref = $emailverified;
9157: $defoption = 'all';
9158: $name = 'cancreate_usernameoptions_'.$type;
9159: }
9160: foreach my $option (@options) {
9161: my $checked;
9162: if (ref($hashref) eq 'HASH') {
9163: if ($type eq '') {
9164: if (!exists($hashref->{'default'})) {
9165: if ($option eq $defoption) {
9166: $checked = ' checked="checked"';
9167: }
9168: } else {
9169: if ($hashref->{'default'} eq $option) {
9170: $checked = ' checked="checked"';
9171: }
1.160.6.40 raeburn 9172: }
9173: } else {
1.160.6.93 raeburn 9174: if (!exists($hashref->{$type})) {
9175: if ($option eq $defoption) {
9176: $checked = ' checked="checked"';
9177: }
9178: } else {
9179: if ($hashref->{$type} eq $option) {
9180: $checked = ' checked="checked"';
9181: }
1.160.6.40 raeburn 9182: }
9183: }
1.160.6.93 raeburn 9184: } elsif (($item eq 'email') && ($hascustom)) {
9185: if ($option eq 'custom') {
9186: $checked = ' checked="checked"';
9187: }
9188: } elsif ($option eq $defoption) {
9189: $checked = ' checked="checked"';
9190: }
9191: $output .= '<span class="LC_nobreak"><label>'.
9192: '<input type="radio" name="'.$name.'"'.
9193: $checked.' value="'.$option.'"'.$onclick.' />'.
9194: $choices{$option}.'</label></span><br />';
9195: if ($item eq 'email') {
9196: if ($option eq 'custom') {
9197: my $id = 'cancreate_emailrule_'.$type;
9198: my $display = 'none';
9199: if ($checked) {
9200: $display = 'inline';
9201: }
9202: my $numinrow = 2;
9203: $output .= '<fieldset id="'.$id.'" style="display:'.$display.';">'.
9204: '<legend>'.&mt('Disallow').'</legend><table>'.
9205: &user_formats_row('email',$settings,$emailrules,
9206: $emailruleorder,$numinrow,'',$type);
9207: '</table></fieldset>';
9208: } elsif (($option eq 'inst') || ($option eq 'noninst')) {
9209: my %text = &Apache::lonlocal::texthash (
9210: inst => 'must end:',
9211: noninst => 'cannot end:',
9212: );
9213: my $value;
9214: if (ref($emaildomain) eq 'HASH') {
9215: if (ref($emaildomain->{$type}) eq 'HASH') {
9216: $value = $emaildomain->{$type}->{$option};
9217: }
9218: }
9219: if ($value eq '') {
9220: $value = '@'.$intdom;
9221: }
9222: my $condition = 'cancreate_emaildomain_'.$option.'_'.$type;
9223: my $display = 'none';
9224: if ($checked) {
9225: $display = 'inline';
9226: }
9227: $output .= '<div id="'.$condition.'" style="display:'.$display.';">'.
9228: '<span class="LC_domprefs_email">'.$text{$option}.'</span> '.
9229: '<input type="text" name="'.$condition.'" value="'.$value.'" size="10" />'.
9230: '</div>';
9231: }
1.160.6.40 raeburn 9232: }
9233: }
1.160.6.93 raeburn 9234: $output .= '</td>'."\n";
1.160.6.40 raeburn 9235: }
1.160.6.93 raeburn 9236: $output .= "</tr></table></td></tr>\n";
1.160.6.40 raeburn 9237: return $output;
9238: }
9239:
1.160.6.5 raeburn 9240: sub captcha_choice {
1.160.6.93 raeburn 9241: my ($context,$settings,$itemcount,$customcss,$rowstyle) = @_;
1.160.6.69 raeburn 9242: my ($keyentry,$currpub,$currpriv,%checked,$rowname,$pubtext,$privtext,
1.160.6.118.2 14(raebu 9243:23): $vertext,$currver);
1.160.6.5 raeburn 9244: my %lt = &captcha_phrases();
9245: $keyentry = 'hidden';
1.160.6.98 raeburn 9246: my $colspan=2;
1.160.6.5 raeburn 9247: if ($context eq 'cancreate') {
1.160.6.34 raeburn 9248: $rowname = &mt('CAPTCHA validation');
1.160.6.5 raeburn 9249: } elsif ($context eq 'login') {
9250: $rowname = &mt('"Contact helpdesk" CAPTCHA validation');
1.160.6.98 raeburn 9251: } elsif ($context eq 'passwords') {
9252: $rowname = &mt('"Forgot Password" CAPTCHA validation');
9253: $colspan=1;
1.160.6.5 raeburn 9254: }
9255: if (ref($settings) eq 'HASH') {
9256: if ($settings->{'captcha'}) {
9257: $checked{$settings->{'captcha'}} = ' checked="checked"';
9258: } else {
9259: $checked{'original'} = ' checked="checked"';
9260: }
9261: if ($settings->{'captcha'} eq 'recaptcha') {
9262: $pubtext = $lt{'pub'};
9263: $privtext = $lt{'priv'};
9264: $keyentry = 'text';
1.160.6.69 raeburn 9265: $vertext = $lt{'ver'};
9266: $currver = $settings->{'recaptchaversion'};
9267: if ($currver ne '2') {
9268: $currver = 1;
9269: }
1.160.6.5 raeburn 9270: }
9271: if (ref($settings->{'recaptchakeys'}) eq 'HASH') {
9272: $currpub = $settings->{'recaptchakeys'}{'public'};
9273: $currpriv = $settings->{'recaptchakeys'}{'private'};
9274: }
9275: } else {
9276: $checked{'original'} = ' checked="checked"';
9277: }
1.160.6.93 raeburn 9278: my $css_class;
9279: if ($itemcount%2) {
9280: $css_class = 'LC_odd_row';
9281: }
9282: if ($customcss) {
9283: $css_class .= " $customcss";
9284: }
9285: $css_class =~ s/^\s+//;
9286: if ($css_class) {
9287: $css_class = ' class="'.$css_class.'"';
9288: }
9289: if ($rowstyle) {
9290: $css_class .= ' style="'.$rowstyle.'"';
9291: }
1.160.6.5 raeburn 9292: my $output = '<tr'.$css_class.'>'.
1.160.6.98 raeburn 9293: '<td class="LC_left_item">'.$rowname.'</td><td class="LC_left_item" colspan="'.$colspan.'">'."\n".
1.160.6.5 raeburn 9294: '<table><tr><td>'."\n";
9295: foreach my $option ('original','recaptcha','notused') {
9296: $output .= '<span class="LC_nobreak"><label><input type="radio" name="'.$context.'_captcha" value="'.
9297: $option.'" '.$checked{$option}.' onchange="javascript:updateCaptcha('."this,'$context'".');" />'.
9298: $lt{$option}.'</label></span>';
9299: unless ($option eq 'notused') {
9300: $output .= (' 'x2)."\n";
9301: }
9302: }
9303: #
9304: # Note: If reCAPTCHA is to be used for LON-CAPA servers in a domain, a domain coordinator should visit:
9305: # https://www.google.com/recaptcha and generate a Public and Private key. For domains with multiple
9306: # servers a single key pair will be used for all servers, so the internet domain (e.g., yourcollege.edu)
9307: # specified for use with the key should be broad enough to accommodate all servers in the LON-CAPA domain.
9308: #
9309: $output .= '</td></tr>'."\n".
1.160.6.93 raeburn 9310: '<tr><td class="LC_zero_height">'."\n".
1.160.6.5 raeburn 9311: '<span class="LC_nobreak"><span id="'.$context.'_recaptchapubtxt">'.$pubtext.'</span> '."\n".
9312: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapub" name="'.$context.'_recaptchapub" value="'.
9313: $currpub.'" size="40" /></span><br />'."\n".
9314: '<span class="LC_nobreak"><span id="'.$context.'_recaptchaprivtxt">'.$privtext.'</span> '."\n".
9315: '<input type="'.$keyentry.'" id="'.$context.'_recaptchapriv" name="'.$context.'_recaptchapriv" value="'.
1.160.6.69 raeburn 9316: $currpriv.'" size="40" /></span><br />'.
9317: '<span class="LC_nobreak"><span id="'.$context.'_recaptchavertxt">'.$vertext.'</span> '."\n".
9318: '<input type="'.$keyentry.'" id="'.$context.'_recaptchaversion" name="'.$context.'_recaptchaversion" value="'.
9319: $currver.'" size="3" /></span><br />'.
9320: '</td></tr></table>'."\n".
1.160.6.5 raeburn 9321: '</td></tr>';
9322: return $output;
9323: }
9324:
1.32 raeburn 9325: sub user_formats_row {
1.160.6.93 raeburn 9326: my ($type,$settings,$rules,$ruleorder,$numinrow,$rowcount,$status) = @_;
1.32 raeburn 9327: my $output;
9328: my %text = (
9329: 'username' => 'new usernames',
9330: 'id' => 'IDs',
9331: );
1.160.6.118.2 8(raebur 9332:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
1.160.6.93 raeburn 9333: my $css_class = $rowcount%2?' class="LC_odd_row"':'';
9334: $output = '<tr '.$css_class.'>'.
9335: '<td><span class="LC_nobreak">'.
9336: &mt("Format rules to check for $text{$type}: ").
9337: '</td><td class="LC_left_item" colspan="2"><table>';
1.63 raeburn 9338: }
1.27 raeburn 9339: my $rem;
9340: if (ref($ruleorder) eq 'ARRAY') {
9341: for (my $i=0; $i<@{$ruleorder}; $i++) {
9342: if (ref($rules->{$ruleorder->[$i]}) eq 'HASH') {
9343: my $rem = $i%($numinrow);
9344: if ($rem == 0) {
9345: if ($i > 0) {
9346: $output .= '</tr>';
9347: }
9348: $output .= '<tr>';
9349: }
9350: my $check = ' ';
1.39 raeburn 9351: if (ref($settings) eq 'HASH') {
9352: if (ref($settings->{$type.'_rule'}) eq 'ARRAY') {
9353: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}})) {
9354: $check = ' checked="checked" ';
9355: }
1.160.6.93 raeburn 9356: } elsif ((ref($settings->{$type.'_rule'}) eq 'HASH') && ($status ne '')) {
9357: if (ref($settings->{$type.'_rule'}->{$status}) eq 'ARRAY') {
9358: if (grep(/^\Q$ruleorder->[$i]\E$/,@{$settings->{$type.'_rule'}->{$status}})) {
9359: $check = ' checked="checked" ';
9360: }
9361: }
1.27 raeburn 9362: }
9363: }
1.160.6.93 raeburn 9364: my $name = $type.'_rule';
9365: if ($type eq 'email') {
9366: $name .= '_'.$status;
9367: }
1.27 raeburn 9368: $output .= '<td class="LC_left_item">'.
9369: '<span class="LC_nobreak"><label>'.
1.160.6.93 raeburn 9370: '<input type="checkbox" name="'.$name.'" '.
1.27 raeburn 9371: 'value="'.$ruleorder->[$i].'"'.$check.'/>'.
9372: $rules->{$ruleorder->[$i]}{'name'}.'</label></span></td>';
9373: }
9374: }
9375: $rem = @{$ruleorder}%($numinrow);
9376: }
1.160.6.93 raeburn 9377: my $colsleft;
9378: if ($rem) {
9379: $colsleft = $numinrow - $rem;
9380: }
1.27 raeburn 9381: if ($colsleft > 1 ) {
9382: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
9383: ' </td>';
9384: } elsif ($colsleft == 1) {
9385: $output .= '<td class="LC_left_item"> </td>';
9386: }
1.160.6.118.2 8(raebur 9387:2): $output .= '</tr>';
9388:2): unless (($type eq 'email') || ($type eq 'unamemap')) {
9389:2): $output .= '</table></td></tr>';
1.160.6.93 raeburn 9390: }
1.27 raeburn 9391: return $output;
9392: }
9393:
1.34 raeburn 9394: sub usercreation_types {
9395: my %lt = &Apache::lonlocal::texthash (
9396: author => 'When adding a co-author',
9397: course => 'When adding a user to a course',
1.100 raeburn 9398: requestcrs => 'When requesting a course',
1.34 raeburn 9399: any => 'Any',
9400: official => 'Institutional only ',
9401: unofficial => 'Non-institutional only',
9402: none => 'None',
9403: );
9404: return %lt;
1.48 raeburn 9405: }
1.34 raeburn 9406:
1.160.6.34 raeburn 9407: sub selfcreation_types {
9408: my %lt = &Apache::lonlocal::texthash (
9409: selfcreate => 'User creates own account',
9410: any => 'Any',
9411: official => 'Institutional only ',
9412: unofficial => 'Non-institutional only',
9413: email => 'E-mail address',
9414: login => 'Institutional Login',
9415: sso => 'SSO',
9416: );
9417: }
9418:
1.28 raeburn 9419: sub authtype_names {
9420: my %lt = &Apache::lonlocal::texthash(
9421: int => 'Internal',
9422: krb4 => 'Kerberos 4',
9423: krb5 => 'Kerberos 5',
9424: loc => 'Local',
1.160.6.118.2 14(raebu 9425:23): lti => 'LTI',
1.28 raeburn 9426: );
9427: return %lt;
9428: }
9429:
9430: sub context_names {
9431: my %context_title = &Apache::lonlocal::texthash(
9432: author => 'Creating users when an Author',
9433: course => 'Creating users when in a course',
9434: domain => 'Creating users when a Domain Coordinator',
9435: );
9436: return %context_title;
9437: }
9438:
1.33 raeburn 9439: sub print_usermodification {
9440: my ($position,$dom,$settings,$rowtotal) = @_;
9441: my $numinrow = 4;
9442: my ($context,$datatable,$rowcount);
9443: if ($position eq 'top') {
9444: $rowcount = 0;
9445: $context = 'author';
9446: foreach my $role ('ca','aa') {
9447: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9448: $numinrow,$rowcount);
9449: $$rowtotal ++;
9450: $rowcount ++;
9451: }
1.160.6.118.2 25(raebu 9452:24): } elsif ($position eq 'middle') {
9453:24): $rowcount = 0;
9454:24): $context = 'coauthor';
9455:24): foreach my $role ('ca','aa') {
9456:24): $datatable .= &modifiable_userdata_row($context,$role,$settings,
9457:24): $numinrow,$rowcount);
9458:24): $$rowtotal ++;
9459:24): $rowcount ++;
9460:24): }
1.160.6.37 raeburn 9461: } elsif ($position eq 'bottom') {
1.33 raeburn 9462: $context = 'course';
9463: $rowcount = 0;
9464: foreach my $role ('st','ep','ta','in','cr') {
9465: $datatable .= &modifiable_userdata_row($context,$role,$settings,
9466: $numinrow,$rowcount);
9467: $$rowtotal ++;
9468: $rowcount ++;
9469: }
9470: }
9471: return $datatable;
9472: }
9473:
1.43 raeburn 9474: sub print_defaults {
1.160.6.40 raeburn 9475: my ($position,$dom,$settings,$rowtotal) = @_;
1.43 raeburn 9476: my $rownum = 0;
1.160.6.80 raeburn 9477: my ($datatable,$css_class,$titles);
9478: unless ($position eq 'bottom') {
9479: $titles = &defaults_titles($dom);
9480: }
1.160.6.40 raeburn 9481: if ($position eq 'top') {
9482: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def',
9483: 'datelocale_def','portal_def');
9484: my %defaults;
9485: if (ref($settings) eq 'HASH') {
9486: %defaults = %{$settings};
1.43 raeburn 9487: } else {
1.160.6.40 raeburn 9488: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
9489: foreach my $item (@items) {
9490: $defaults{$item} = $domdefaults{$item};
9491: }
1.43 raeburn 9492: }
1.160.6.40 raeburn 9493: foreach my $item (@items) {
9494: if ($rownum%2) {
9495: $css_class = '';
9496: } else {
9497: $css_class = ' class="LC_odd_row" ';
1.43 raeburn 9498: }
1.160.6.40 raeburn 9499: $datatable .= '<tr'.$css_class.'>'.
9500: '<td><span class="LC_nobreak">'.$titles->{$item}.
9501: '</span></td><td class="LC_right_item" colspan="3">';
9502: if ($item eq 'auth_def') {
1.160.6.118.2 14(raebu 9503:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.160.6.40 raeburn 9504: my %shortauth = (
9505: internal => 'int',
9506: krb4 => 'krb4',
9507: krb5 => 'krb5',
1.160.6.118.2 14(raebu 9508:23): localauth => 'loc',
9509:23): lti => 'lti',
1.160.6.40 raeburn 9510: );
9511: my %authnames = &authtype_names();
9512: foreach my $auth (@authtypes) {
9513: my $checked = ' ';
9514: if ($defaults{$item} eq $auth) {
9515: $checked = ' checked="checked" ';
9516: }
9517: $datatable .= '<label><input type="radio" name="'.$item.
9518: '" value="'.$auth.'"'.$checked.'/>'.
9519: $authnames{$shortauth{$auth}}.'</label> ';
9520: }
9521: } elsif ($item eq 'timezone_def') {
9522: my $includeempty = 1;
9523: $datatable .= &Apache::loncommon::select_timezone($item,$defaults{$item},undef,$includeempty);
9524: } elsif ($item eq 'datelocale_def') {
1.160.6.98 raeburn 9525: my $includeempty = 1;
9526: $datatable .= &Apache::loncommon::select_datelocale($item,$defaults{$item},undef,$includeempty);
9527: } elsif ($item eq 'lang_def') {
9528: my $includeempty = 1;
9529: $datatable .= &Apache::loncommon::select_language($item,$defaults{$item},$includeempty);
1.160.6.118.2 12(raebu 9530:23): } elsif ($item eq 'portal_def') {
1.160.6.80 raeburn 9531: $datatable .= '<input type="text" name="'.$item.'" value="'.
1.160.6.118.2 12(raebu 9532:23): $defaults{$item}.'" size="25" onkeyup="portalExtras(this);" />';
9533:23): my $portalsty = 'none';
9534:23): if ($defaults{$item}) {
9535:23): $portalsty = 'block';
9536:23): }
9537:23): foreach my $field ('email','web') {
9538:23): my $checkedoff = ' checked="checked"';
9539:23): my $checkedon;
9540:23): if ($defaults{$item.'_'.$field}) {
9541:23): $checkedon = $checkedoff;
9542:23): $checkedoff = '';
9543:23): }
9544:23): $datatable .= '<div id="'.$item.'_'.$field.'_div" style="display:'.$portalsty.'">'.
9545:23): '<span class="LC_nobreak">'.$titles->{$field}.' '.
9546:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="1"'.$checkedon.'/>'.&mt('Yes').'</label>'.
9547:23): (' 'x2).
9548:23): '<label><input type="radio" name="'.$item.'_'.$field.'" value="0"'.$checkedoff.'/>'.&mt('No').'</label>'.
9549:23): '</div>';
9550:23): }
9551:23): } else {
9552:23): $datatable .= '<input type="text" name="'.$item.'" value="'.$defaults{$item}.'" />';
1.160.6.80 raeburn 9553: }
9554: $datatable .= '</td></tr>';
9555: $rownum ++;
9556: }
1.160.6.118.2 8(raebur 9557:2): } elsif ($position eq 'middle') {
1.160.6.80 raeburn 9558: my %defaults;
1.160.6.40 raeburn 9559: if (ref($settings) eq 'HASH') {
1.160.6.93 raeburn 9560: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
1.160.6.40 raeburn 9561: my $maxnum = @{$settings->{'inststatusorder'}};
9562: for (my $i=0; $i<$maxnum; $i++) {
9563: $css_class = $rownum%2?' class="LC_odd_row"':'';
9564: my $item = $settings->{'inststatusorder'}->[$i];
9565: my $title = $settings->{'inststatustypes'}->{$item};
9566: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'$item'".');"';
9567: $datatable .= '<tr'.$css_class.'>'.
9568: '<td><span class="LC_nobreak">'.
9569: '<select name="inststatus_pos_'.$item.'"'.$chgstr.'>';
9570: for (my $k=0; $k<=$maxnum; $k++) {
9571: my $vpos = $k+1;
9572: my $selstr;
9573: if ($k == $i) {
9574: $selstr = ' selected="selected" ';
9575: }
9576: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9577: }
9578: $datatable .= '</select> '.&mt('Internal ID:').' <b>'.$item.'</b> '.
9579: '<input type="checkbox" name="inststatus_delete" value="'.$item.'" />'.
9580: &mt('delete').'</span></td>'.
1.160.6.112 raeburn 9581: '<td class="LC_left_item"><span class="LC_nobreak">'.&mt('Name displayed').':'.
1.160.6.40 raeburn 9582: '<input type="text" size="20" name="inststatus_title_'.$item.'" value="'.$title.'" />'.
1.160.6.93 raeburn 9583: '</span></td></tr>';
1.160.6.40 raeburn 9584: }
9585: $css_class = $rownum%2?' class="LC_odd_row"':'';
9586: my $chgstr = ' onchange="javascript:reorderTypes(this.form,'."'addinststatus_pos'".');"';
9587: $datatable .= '<tr '.$css_class.'>'.
9588: '<td><span class="LC_nobreak"><select name="addinststatus_pos"'.$chgstr.'>';
9589: for (my $k=0; $k<=$maxnum; $k++) {
9590: my $vpos = $k+1;
9591: my $selstr;
9592: if ($k == $maxnum) {
9593: $selstr = ' selected="selected" ';
9594: }
9595: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
9596: }
9597: $datatable .= '</select> '.&mt('Internal ID:').
1.160.6.63 raeburn 9598: '<input type="text" size="10" name="addinststatus" value="" />'.
1.160.6.40 raeburn 9599: ' '.&mt('(new)').
9600: '</span></td><td class="LC_left_item"><span class="LC_nobreak">'.
1.160.6.112 raeburn 9601: &mt('Name displayed').':'.
1.160.6.40 raeburn 9602: '<input type="text" size="20" name="addinststatus_title" value="" /></span></td>'.
9603: '</tr>'."\n";
9604: $rownum ++;
1.141 raeburn 9605: }
1.43 raeburn 9606: }
1.160.6.118.2 8(raebur 9607:2): } else {
9608:2): my ($unamemaprules,$ruleorder) =
9609:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
9610:2): $css_class = $rownum%2?' class="LC_odd_row"':'';
9611:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9612:2): my $numinrow = 2;
9613:2): $datatable .= '<tr'.$css_class.'><td>'.&mt('Available conversions').'</td><td><table>'.
9614:2): &user_formats_row('unamemap',$settings,$unamemaprules,
9615:2): $ruleorder,$numinrow).
9616:2): '</table></td></tr>';
9617:2): }
9618:2): if ($datatable eq '') {
9619:2): $datatable .= '<tr'.$css_class.'><td colspan="2">'.
9620:2): &mt('No rules set for domain in customized localenroll.pm').
9621:2): '</td></tr>';
9622:2): }
1.43 raeburn 9623: }
9624: $$rowtotal += $rownum;
9625: return $datatable;
9626: }
9627:
1.160.6.5 raeburn 9628: sub get_languages_hash {
9629: my %langchoices;
9630: foreach my $id (&Apache::loncommon::languageids()) {
9631: my $code = &Apache::loncommon::supportedlanguagecode($id);
9632: if ($code ne '') {
9633: $langchoices{$code} = &Apache::loncommon::plainlanguagedescription($id);
9634: }
9635: }
9636: return %langchoices;
9637: }
9638:
1.43 raeburn 9639: sub defaults_titles {
1.141 raeburn 9640: my ($dom) = @_;
1.43 raeburn 9641: my %titles = &Apache::lonlocal::texthash (
9642: 'auth_def' => 'Default authentication type',
9643: 'auth_arg_def' => 'Default authentication argument',
9644: 'lang_def' => 'Default language',
1.54 raeburn 9645: 'timezone_def' => 'Default timezone',
1.68 raeburn 9646: 'datelocale_def' => 'Default locale for dates',
1.141 raeburn 9647: 'portal_def' => 'Portal/Default URL',
1.160.6.118.2 12(raebu 9648:23): 'email' => 'Email links use portal URL',
9649:23): 'web' => 'Public web links use portal URL',
1.160.6.80 raeburn 9650: 'intauth_cost' => 'Encryption cost for bcrypt (positive integer)',
9651: 'intauth_check' => 'Check bcrypt cost if authenticated',
9652: 'intauth_switch' => 'Existing crypt-based switched to bcrypt on authentication',
1.43 raeburn 9653: );
1.141 raeburn 9654: if ($dom) {
9655: my $uprimary_id = &Apache::lonnet::domain($dom,'primary');
9656: my $uint_dom = &Apache::lonnet::internet_dom($uprimary_id);
9657: my $protocol = $Apache::lonnet::protocol{$uprimary_id};
9658: $protocol = 'http' if ($protocol ne 'https');
9659: if ($uint_dom) {
9660: $titles{'portal_def'} .= ' '.&mt('(for example: [_1])',$protocol.'://loncapa.'.
9661: $uint_dom);
9662: }
9663: }
1.43 raeburn 9664: return (\%titles);
9665: }
9666:
1.160.6.97 raeburn 9667: sub print_scantron {
9668: my ($r,$position,$dom,$confname,$settings,$rowtotal) = @_;
9669: if ($position eq 'top') {
9670: return &print_scantronformat($r,$dom,$confname,$settings,\$rowtotal);
9671: } else {
9672: return &print_scantronconfig($dom,$settings,\$rowtotal);
9673: }
9674: }
9675:
9676: sub scantron_javascript {
9677: return <<"ENDSCRIPT";
9678:
9679: <script type="text/javascript">
9680: // <![CDATA[
9681:
9682: function toggleScantron(form) {
9683: var csvfieldset = new Array();
9684: if (document.getElementById('scantroncsv_cols')) {
9685: csvfieldset.push(document.getElementById('scantroncsv_cols'));
9686: }
9687: if (document.getElementById('scantroncsv_options')) {
9688: csvfieldset.push(document.getElementById('scantroncsv_options'));
9689: }
9690: if (csvfieldset.length) {
9691: if (document.getElementById('scantronconfcsv')) {
9692: var scantroncsv = document.getElementById('scantronconfcsv');
9693: if (scantroncsv.checked) {
9694: for (var i=0; i<csvfieldset.length; i++) {
9695: csvfieldset[i].style.display = 'block';
9696: }
9697: } else {
9698: for (var i=0; i<csvfieldset.length; i++) {
9699: csvfieldset[i].style.display = 'none';
9700: }
9701: var csvselects = document.getElementsByClassName('scantronconfig_csv');
9702: if (csvselects.length) {
9703: for (var j=0; j<csvselects.length; j++) {
9704: csvselects[j].selectedIndex = 0;
9705: }
9706: }
9707: }
9708: }
9709: }
9710: return;
9711: }
9712: // ]]>
9713: </script>
9714:
9715: ENDSCRIPT
9716:
9717: }
9718:
1.46 raeburn 9719: sub print_scantronformat {
9720: my ($r,$dom,$confname,$settings,$rowtotal) = @_;
9721: my $itemcount = 1;
1.60 raeburn 9722: my ($datatable,$css_class,$scantronurl,$is_custom,%error,%scantronurls,
9723: %confhash);
1.46 raeburn 9724: my $switchserver = &check_switchserver($dom,$confname);
9725: my %lt = &Apache::lonlocal::texthash (
1.95 www 9726: default => 'Default bubblesheet format file error',
9727: custom => 'Custom bubblesheet format file error',
1.46 raeburn 9728: );
9729: my %scantronfiles = (
9730: default => 'default.tab',
9731: custom => 'custom.tab',
9732: );
9733: foreach my $key (keys(%scantronfiles)) {
9734: $scantronurls{$key} = '/res/'.$dom.'/'.$confname.'/scantron/'
9735: .$scantronfiles{$key};
9736: }
9737: my @defaultinfo = &Apache::lonnet::stat_file($scantronurls{'default'});
9738: if ((!@defaultinfo) || ($defaultinfo[0] eq 'no_such_dir')) {
9739: if (!$switchserver) {
9740: my $servadm = $r->dir_config('lonAdmEMail');
9741: my ($configuserok,$author_ok) = &config_check($dom,$confname,$servadm);
9742: if ($configuserok eq 'ok') {
9743: if ($author_ok eq 'ok') {
9744: my %legacyfile = (
1.160.6.97 raeburn 9745: default => $Apache::lonnet::perlvar{'lonTabDir'}.'/default_scantronformat.tab',
9746: custom => $Apache::lonnet::perlvar{'lonTabDir'}.'/scantronformat.tab',
1.46 raeburn 9747: );
9748: my %md5chk;
9749: foreach my $type (keys(%legacyfile)) {
1.60 raeburn 9750: ($md5chk{$type}) = split(/ /,`md5sum $legacyfile{$type}`);
9751: chomp($md5chk{$type});
1.46 raeburn 9752: }
9753: if ($md5chk{'default'} ne $md5chk{'custom'}) {
9754: foreach my $type (keys(%legacyfile)) {
1.160.6.97 raeburn 9755: ($scantronurls{$type},my $error) =
1.46 raeburn 9756: &legacy_scantronformat($r,$dom,$confname,
9757: $type,$legacyfile{$type},
9758: $scantronurls{$type},
9759: $scantronfiles{$type});
1.60 raeburn 9760: if ($error ne '') {
9761: $error{$type} = $error;
9762: }
9763: }
9764: if (keys(%error) == 0) {
9765: $is_custom = 1;
1.160.6.97 raeburn 9766: $confhash{'scantron'}{'scantronformat'} =
1.60 raeburn 9767: $scantronurls{'custom'};
1.160.6.97 raeburn 9768: my $putresult =
1.60 raeburn 9769: &Apache::lonnet::put_dom('configuration',
9770: \%confhash,$dom);
9771: if ($putresult ne 'ok') {
1.160.6.97 raeburn 9772: $error{'custom'} =
1.60 raeburn 9773: '<span class="LC_error">'.
9774: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9775: }
1.46 raeburn 9776: }
9777: } else {
1.60 raeburn 9778: ($scantronurls{'default'},my $error) =
1.46 raeburn 9779: &legacy_scantronformat($r,$dom,$confname,
9780: 'default',$legacyfile{'default'},
9781: $scantronurls{'default'},
9782: $scantronfiles{'default'});
1.60 raeburn 9783: if ($error eq '') {
9784: $confhash{'scantron'}{'scantronformat'} = '';
9785: my $putresult =
9786: &Apache::lonnet::put_dom('configuration',
9787: \%confhash,$dom);
9788: if ($putresult ne 'ok') {
9789: $error{'default'} =
9790: '<span class="LC_error">'.
9791: &mt('An error occurred updating the domain configuration: [_1]',$putresult).'</span>';
9792: }
9793: } else {
9794: $error{'default'} = $error;
9795: }
1.46 raeburn 9796: }
9797: }
9798: }
9799: } else {
1.95 www 9800: $error{'default'} = &mt("Unable to copy default bubblesheet formatfile to domain's RES space: [_1]",$switchserver);
1.46 raeburn 9801: }
9802: }
9803: if (ref($settings) eq 'HASH') {
9804: if ($settings->{'scantronformat'} eq "/res/$dom/$confname/scantron/custom.tab") {
9805: my @info = &Apache::lonnet::stat_file($settings->{'scantronformat'});
9806: if ((!@info) || ($info[0] eq 'no_such_dir')) {
9807: $scantronurl = '';
9808: } else {
9809: $scantronurl = $settings->{'scantronformat'};
9810: }
9811: $is_custom = 1;
9812: } else {
9813: $scantronurl = $scantronurls{'default'};
9814: }
9815: } else {
1.60 raeburn 9816: if ($is_custom) {
9817: $scantronurl = $scantronurls{'custom'};
9818: } else {
9819: $scantronurl = $scantronurls{'default'};
9820: }
1.46 raeburn 9821: }
9822: $css_class = $itemcount%2?' class="LC_odd_row"':'';
9823: $datatable .= '<tr'.$css_class.'>';
9824: if (!$is_custom) {
1.65 raeburn 9825: $datatable .= '<td>'.&mt('Default in use:').'<br />'.
9826: '<span class="LC_nobreak">';
1.46 raeburn 9827: if ($scantronurl) {
1.160.6.21 raeburn 9828: $datatable .= &Apache::loncommon::modal_link($scantronurl,&mt('Default bubblesheet format file'),600,500,
9829: undef,undef,undef,undef,'background-color:#ffffff');
1.46 raeburn 9830: } else {
9831: $datatable = &mt('File unavailable for display');
9832: }
1.65 raeburn 9833: $datatable .= '</span></td>';
1.60 raeburn 9834: if (keys(%error) == 0) {
9835: $datatable .= '<td valign="bottom">';
9836: if (!$switchserver) {
9837: $datatable .= &mt('Upload:').'<br />';
9838: }
9839: } else {
9840: my $errorstr;
9841: foreach my $key (sort(keys(%error))) {
9842: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9843: }
9844: $datatable .= '<td>'.$errorstr;
9845: }
1.46 raeburn 9846: } else {
9847: if (keys(%error) > 0) {
9848: my $errorstr;
9849: foreach my $key (sort(keys(%error))) {
9850: $errorstr .= $lt{$key}.': '.$error{$key}.'<br />';
9851: }
1.60 raeburn 9852: $datatable .= '<td>'.$errorstr.'</td><td> ';
1.46 raeburn 9853: } elsif ($scantronurl) {
1.160.6.26 raeburn 9854: my $link = &Apache::loncommon::modal_link($scantronurl,&mt('Custom bubblesheet format file'),600,500,
1.160.6.21 raeburn 9855: undef,undef,undef,undef,'background-color:#ffffff');
1.65 raeburn 9856: $datatable .= '<td><span class="LC_nobreak">'.
1.160.6.21 raeburn 9857: $link.
9858: '<label><input type="checkbox" name="scantronformat_del"'.
9859: ' value="1" />'.&mt('Delete?').'</label></span></td>'.
1.65 raeburn 9860: '<td><span class="LC_nobreak"> '.
9861: &mt('Replace:').'</span><br />';
1.46 raeburn 9862: }
9863: }
9864: if (keys(%error) == 0) {
9865: if ($switchserver) {
9866: $datatable .= &mt('Upload to library server: [_1]',$switchserver);
9867: } else {
1.65 raeburn 9868: $datatable .='<span class="LC_nobreak"> '.
9869: '<input type="file" name="scantronformat" /></span>';
1.46 raeburn 9870: }
9871: }
9872: $datatable .= '</td></tr>';
9873: $$rowtotal ++;
9874: return $datatable;
9875: }
9876:
9877: sub legacy_scantronformat {
9878: my ($r,$dom,$confname,$file,$legacyfile,$newurl,$newfile) = @_;
9879: my ($url,$error);
9880: my @statinfo = &Apache::lonnet::stat_file($newurl);
9881: if ((!@statinfo) || ($statinfo[0] eq 'no_such_dir')) {
1.160.6.118.2 14(raebu 9882:23): my $modified = [];
1.46 raeburn 9883: (my $result,$url) =
1.160.6.118.2 14(raebu 9884:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$legacyfile,$dom,$confname,
9885:23): 'scantron','','',$newfile,$modified);
9886:23): if ($result eq 'ok') {
9887:23): &update_modify_urls($r,$modified);
9888:23): } else {
1.130 raeburn 9889: $error = &mt("An error occurred publishing the [_1] bubblesheet format file in RES space. Error was: [_2].",$newfile,$result);
1.46 raeburn 9890: }
9891: }
9892: return ($url,$error);
9893: }
1.43 raeburn 9894:
1.160.6.97 raeburn 9895: sub print_scantronconfig {
9896: my ($dom,$settings,$rowtotal) = @_;
9897: my $itemcount = 2;
9898: my $is_checked = ' checked="checked"';
9899: my %optionson = (
9900: hdr => ' checked="checked"',
9901: pad => ' checked="checked"',
9902: rem => ' checked="checked"',
9903: );
9904: my %optionsoff = (
9905: hdr => '',
9906: pad => '',
9907: rem => '',
9908: );
9909: my $currcsvsty = 'none';
9910: my ($datatable,%csvfields,%checked,%onclick,%csvoptions);
9911: my @fields = &scantroncsv_fields();
9912: my %titles = &scantronconfig_titles();
9913: if (ref($settings) eq 'HASH') {
9914: if (ref($settings->{config}) eq 'HASH') {
9915: if ($settings->{config}->{dat}) {
9916: $checked{'dat'} = $is_checked;
9917: }
9918: if (ref($settings->{config}->{csv}) eq 'HASH') {
9919: if (ref($settings->{config}->{csv}->{fields}) eq 'HASH') {
9920: %csvfields = %{$settings->{config}->{csv}->{fields}};
9921: if (keys(%csvfields) > 0) {
9922: $checked{'csv'} = $is_checked;
9923: $currcsvsty = 'block';
9924: }
9925: }
9926: if (ref($settings->{config}->{csv}->{options}) eq 'HASH') {
9927: %csvoptions = %{$settings->{config}->{csv}->{options}};
9928: foreach my $option (keys(%optionson)) {
9929: unless ($csvoptions{$option}) {
9930: $optionsoff{$option} = $optionson{$option};
9931: $optionson{$option} = '';
9932: }
9933: }
9934: }
9935: }
9936: } else {
9937: $checked{'dat'} = $is_checked;
9938: }
9939: } else {
9940: $checked{'dat'} = $is_checked;
9941: }
9942: $onclick{'csv'} = ' onclick="toggleScantron(this.form);"';
9943: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
9944: $datatable = '<tr '.$css_class.'><td>'.&mt('Supported formats').'</td>'.
9945: '<td class="LC_left_item" valign="top"><span class="LC_nobreak">';
9946: foreach my $item ('dat','csv') {
9947: my $id;
9948: if ($item eq 'csv') {
9949: $id = 'id="scantronconfcsv" ';
9950: }
9951: $datatable .= '<label><input type="checkbox" name="scantronconfig" '.$id.'value="'.$item.'"'.$checked{$item}.$onclick{$item}.' />'.
9952: $titles{$item}.'</label>'.(' 'x3);
9953: if ($item eq 'csv') {
9954: $datatable .= '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_cols">'.
9955: '<legend>'.&mt('CSV Column Mapping').'</legend>'.
9956: '<table><tr><th>'.&mt('Field').'</th><th>'.&mt('Location').'</th></tr>'."\n";
9957: foreach my $col (@fields) {
9958: my $selnone;
9959: if ($csvfields{$col} eq '') {
9960: $selnone = ' selected="selected"';
9961: }
9962: $datatable .= '<tr><td>'.$titles{$col}.'</td>'.
9963: '<td><select name="scantronconfig_csv_'.$col.'" class="scantronconfig_csv">'.
9964: '<option value=""'.$selnone.'></option>';
9965: for (my $i=0; $i<20; $i++) {
9966: my $shown = $i+1;
9967: my $sel;
9968: unless ($selnone) {
9969: if (exists($csvfields{$col})) {
9970: if ($csvfields{$col} == $i) {
9971: $sel = ' selected="selected"';
9972: }
9973: }
9974: }
9975: $datatable .= '<option value="'.$i.'"'.$sel.'>'.$shown.'</option>';
9976: }
9977: $datatable .= '</select></td></tr>';
9978: }
9979: $datatable .= '</table></fieldset>'.
9980: '<fieldset style="display:'.$currcsvsty.'" id="scantroncsv_options">'.
9981: '<legend>'.&mt('CSV Options').'</legend>';
9982: foreach my $option ('hdr','pad','rem') {
9983: $datatable .= '<span class="LC_nobreak">'.$titles{$option}.':'.
9984: '<label><input type="radio" name="scantroncsv_'.$option.'" value="1"'.$optionson{$option}.' />'.
9985: &mt('Yes').'</label>'.(' 'x2)."\n".
9986: '<label><input type="radio" name="scantroncsv_'.$option.'" value="0"'.$optionsoff{$option}.' />'.&mt('No').'</label></span><br />';
9987: }
9988: $datatable .= '</fieldset>';
9989: $itemcount ++;
9990: }
9991: }
9992: $datatable .= '</td></tr>';
9993: $$rowtotal ++;
9994: return $datatable;
9995: }
9996:
9997: sub scantronconfig_titles {
9998: return &Apache::lonlocal::texthash(
9999: dat => 'Standard format (.dat)',
10000: csv => 'Comma separated values (.csv)',
10001: hdr => 'Remove first line in file (contains column titles)',
10002: pad => 'Prepend 0s to PaperID',
10003: rem => 'Remove leading spaces (except Question Response columns)',
10004: CODE => 'CODE',
10005: ID => 'Student ID',
10006: PaperID => 'Paper ID',
10007: FirstName => 'First Name',
10008: LastName => 'Last Name',
10009: FirstQuestion => 'First Question Response',
10010: Section => 'Section',
10011: );
10012: }
10013:
10014: sub scantroncsv_fields {
10015: return ('PaperID','LastName','FirstName','ID','Section','CODE','FirstQuestion');
10016: }
10017:
1.49 raeburn 10018: sub print_coursecategories {
1.57 raeburn 10019: my ($position,$dom,$hdritem,$settings,$rowtotal) = @_;
10020: my $datatable;
10021: if ($position eq 'top') {
1.160.6.42 raeburn 10022: my (%checked);
10023: my @catitems = ('unauth','auth');
10024: my @cattypes = ('std','domonly','codesrch','none');
10025: $checked{'unauth'} = 'std';
10026: $checked{'auth'} = 'std';
10027: if (ref($settings) eq 'HASH') {
10028: foreach my $type (@cattypes) {
10029: if ($type eq $settings->{'unauth'}) {
10030: $checked{'unauth'} = $type;
10031: }
10032: if ($type eq $settings->{'auth'}) {
10033: $checked{'auth'} = $type;
10034: }
10035: }
10036: }
10037: my %lt = &Apache::lonlocal::texthash (
10038: unauth => 'Catalog type for unauthenticated users',
10039: auth => 'Catalog type for authenticated users',
10040: none => 'No catalog',
10041: std => 'Standard catalog',
10042: domonly => 'Domain-only catalog',
10043: codesrch => "Code search form",
10044: );
10045: my $itemcount = 0;
10046: foreach my $item (@catitems) {
10047: my $css_class = $itemcount%2? ' class="LC_odd_row"':'';
10048: $datatable .= '<tr '.$css_class.'>'.
10049: '<td>'.$lt{$item}.'</td>'.
10050: '<td class="LC_right_item"><span class="LC_nobreak">';
10051: foreach my $type (@cattypes) {
10052: my $ischecked;
10053: if ($checked{$item} eq $type) {
10054: $ischecked=' checked="checked"';
10055: }
10056: $datatable .= '<label>'.
10057: '<input type="radio" name="coursecat_'.$item.'" value="'.$type.'"'.$ischecked.
10058: ' />'.$lt{$type}.'</label> ';
10059: }
1.160.6.87 raeburn 10060: $datatable .= '</span></td></tr>';
1.160.6.42 raeburn 10061: $itemcount ++;
10062: }
10063: $$rowtotal += $itemcount;
10064: } elsif ($position eq 'middle') {
1.57 raeburn 10065: my $toggle_cats_crs = ' ';
10066: my $toggle_cats_dom = ' checked="checked" ';
10067: my $can_cat_crs = ' ';
10068: my $can_cat_dom = ' checked="checked" ';
1.120 raeburn 10069: my $toggle_catscomm_comm = ' ';
10070: my $toggle_catscomm_dom = ' checked="checked" ';
10071: my $can_catcomm_comm = ' ';
10072: my $can_catcomm_dom = ' checked="checked" ';
10073:
1.57 raeburn 10074: if (ref($settings) eq 'HASH') {
10075: if ($settings->{'togglecats'} eq 'crs') {
10076: $toggle_cats_crs = $toggle_cats_dom;
10077: $toggle_cats_dom = ' ';
10078: }
10079: if ($settings->{'categorize'} eq 'crs') {
10080: $can_cat_crs = $can_cat_dom;
10081: $can_cat_dom = ' ';
10082: }
1.120 raeburn 10083: if ($settings->{'togglecatscomm'} eq 'comm') {
10084: $toggle_catscomm_comm = $toggle_catscomm_dom;
10085: $toggle_catscomm_dom = ' ';
10086: }
10087: if ($settings->{'categorizecomm'} eq 'comm') {
10088: $can_catcomm_comm = $can_catcomm_dom;
10089: $can_catcomm_dom = ' ';
10090: }
1.57 raeburn 10091: }
10092: my %title = &Apache::lonlocal::texthash (
1.120 raeburn 10093: togglecats => 'Show/Hide a course in catalog',
10094: togglecatscomm => 'Show/Hide a community in catalog',
10095: categorize => 'Assign a category to a course',
10096: categorizecomm => 'Assign a category to a community',
1.57 raeburn 10097: );
10098: my %level = &Apache::lonlocal::texthash (
1.120 raeburn 10099: dom => 'Set in Domain',
10100: crs => 'Set in Course',
10101: comm => 'Set in Community',
1.57 raeburn 10102: );
10103: $datatable = '<tr class="LC_odd_row">'.
10104: '<td>'.$title{'togglecats'}.'</td>'.
10105: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10106: '<input type="radio" name="togglecats"'.
10107: $toggle_cats_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10108: '<label><input type="radio" name="togglecats"'.
10109: $toggle_cats_crs.' value="crs" />'.$level{'crs'}.'</label></span></td>'.
10110: '</tr><tr>'.
10111: '<td>'.$title{'categorize'}.'</td>'.
10112: '<td class="LC_right_item"><span class="LC_nobreak">'.
10113: '<label><input type="radio" name="categorize"'.
10114: $can_cat_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10115: '<label><input type="radio" name="categorize"'.
10116: $can_cat_crs.'value="crs" />'.$level{'crs'}.'</label></span></td>'.
1.120 raeburn 10117: '</tr><tr class="LC_odd_row">'.
10118: '<td>'.$title{'togglecatscomm'}.'</td>'.
10119: '<td class="LC_right_item"><span class="LC_nobreak"><label>'.
10120: '<input type="radio" name="togglecatscomm"'.
10121: $toggle_catscomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10122: '<label><input type="radio" name="togglecatscomm"'.
10123: $toggle_catscomm_comm.' value="comm" />'.$level{'comm'}.'</label></span></td>'.
10124: '</tr><tr>'.
10125: '<td>'.$title{'categorizecomm'}.'</td>'.
10126: '<td class="LC_right_item"><span class="LC_nobreak">'.
10127: '<label><input type="radio" name="categorizecomm"'.
10128: $can_catcomm_dom.' value="dom" />'.$level{'dom'}.'</label> '.
10129: '<label><input type="radio" name="categorizecomm"'.
10130: $can_catcomm_comm.'value="comm" />'.$level{'comm'}.'</label></span></td>'.
1.57 raeburn 10131: '</tr>';
1.120 raeburn 10132: $$rowtotal += 4;
1.57 raeburn 10133: } else {
10134: my $css_class;
10135: my $itemcount = 1;
10136: my $cathash;
10137: if (ref($settings) eq 'HASH') {
10138: $cathash = $settings->{'cats'};
10139: }
10140: if (ref($cathash) eq 'HASH') {
10141: my (@cats,@trails,%allitems,%idx,@jsarray);
10142: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,
10143: \%allitems,\%idx,\@jsarray);
10144: my $maxdepth = scalar(@cats);
10145: my $colattrib = '';
10146: if ($maxdepth > 2) {
10147: $colattrib = ' colspan="2" ';
10148: }
10149: my @path;
10150: if (@cats > 0) {
10151: if (ref($cats[0]) eq 'ARRAY') {
10152: my $numtop = @{$cats[0]};
10153: my $maxnum = $numtop;
1.120 raeburn 10154: my %default_names = (
10155: instcode => &mt('Official courses'),
10156: communities => &mt('Communities'),
10157: );
10158:
10159: if ((!grep(/^instcode$/,@{$cats[0]})) ||
10160: ($cathash->{'instcode::0'} eq '') ||
10161: (!grep(/^communities$/,@{$cats[0]})) ||
10162: ($cathash->{'communities::0'} eq '')) {
1.57 raeburn 10163: $maxnum ++;
10164: }
10165: my $lastidx;
10166: for (my $i=0; $i<$numtop; $i++) {
10167: my $parent = $cats[0][$i];
10168: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10169: my $item = &escape($parent).'::0';
10170: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$item','$idx{$item}'".');"';
10171: $lastidx = $idx{$item};
10172: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10173: .'<select name="'.$item.'"'.$chgstr.'>';
10174: for (my $k=0; $k<=$maxnum; $k++) {
10175: my $vpos = $k+1;
10176: my $selstr;
10177: if ($k == $i) {
10178: $selstr = ' selected="selected" ';
10179: }
10180: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10181: }
1.160.6.29 raeburn 10182: $datatable .= '</select></span></td><td>';
1.120 raeburn 10183: if ($parent eq 'instcode' || $parent eq 'communities') {
10184: $datatable .= '<span class="LC_nobreak">'
10185: .$default_names{$parent}.'</span>';
10186: if ($parent eq 'instcode') {
10187: $datatable .= '<br /><span class="LC_nobreak">('
10188: .&mt('with institutional codes')
10189: .')</span></td><td'.$colattrib.'>';
10190: } else {
10191: $datatable .= '<table><tr><td>';
10192: }
10193: $datatable .= '<span class="LC_nobreak">'
10194: .'<label><input type="radio" name="'
10195: .$parent.'" value="1" checked="checked" />'
10196: .&mt('Display').'</label>';
10197: if ($parent eq 'instcode') {
10198: $datatable .= ' ';
10199: } else {
10200: $datatable .= '</span></td></tr><tr><td>'
10201: .'<span class="LC_nobreak">';
10202: }
10203: $datatable .= '<label><input type="radio" name="'
10204: .$parent.'" value="0" />'
10205: .&mt('Do not display').'</label></span>';
10206: if ($parent eq 'communities') {
10207: $datatable .= '</td></tr></table>';
10208: }
10209: $datatable .= '</td>';
1.57 raeburn 10210: } else {
10211: $datatable .= $parent
1.160.6.29 raeburn 10212: .' <span class="LC_nobreak"><label>'
10213: .'<input type="checkbox" name="deletecategory" '
1.57 raeburn 10214: .'value="'.$item.'" />'.&mt('Delete').'</label></span></td>';
10215: }
10216: my $depth = 1;
10217: push(@path,$parent);
10218: $datatable .= &build_category_rows($itemcount,\@cats,$depth,$parent,\@path,\%idx);
10219: pop(@path);
10220: $datatable .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
10221: $itemcount ++;
10222: }
1.48 raeburn 10223: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.57 raeburn 10224: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','$lastidx'".');"';
10225: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="addcategory_pos"'.$chgstr.'>';
1.48 raeburn 10226: for (my $k=0; $k<=$maxnum; $k++) {
10227: my $vpos = $k+1;
10228: my $selstr;
1.57 raeburn 10229: if ($k == $numtop) {
1.48 raeburn 10230: $selstr = ' selected="selected" ';
10231: }
10232: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
10233: }
1.59 bisitz 10234: $datatable .= '</select></span></td><td colspan="2">'.&mt('Add category:').' '
1.57 raeburn 10235: .'<input type="text" size="20" name="addcategory_name" value="" /></td>'
10236: .'</tr>'."\n";
1.48 raeburn 10237: $itemcount ++;
1.120 raeburn 10238: foreach my $default ('instcode','communities') {
10239: if ((!grep(/^\Q$default\E$/,@{$cats[0]})) || ($cathash->{$default.'::0'} eq '')) {
10240: $css_class = $itemcount%2?' class="LC_odd_row"':'';
10241: my $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','$lastidx'".');"';
10242: $datatable .= '<tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr><tr '.$css_class.'><td>'.
10243: '<span class="LC_nobreak"><select name="'.$default.'_pos"'.$chgstr.'>';
10244: for (my $k=0; $k<=$maxnum; $k++) {
10245: my $vpos = $k+1;
10246: my $selstr;
10247: if ($k == $maxnum) {
10248: $selstr = ' selected="selected" ';
10249: }
10250: $datatable .= '<option value="'.$k.'"'.$selstr.'>'.$vpos.'</option>';
1.57 raeburn 10251: }
1.120 raeburn 10252: $datatable .= '</select></span></td>'.
10253: '<td><span class="LC_nobreak">'.
10254: $default_names{$default}.'</span>';
10255: if ($default eq 'instcode') {
10256: $datatable .= '<br /><span class="LC_nobreak">('
10257: .&mt('with institutional codes').')</span>';
10258: }
10259: $datatable .= '</td>'
10260: .'<td><span class="LC_nobreak"><label><input type="radio" name="'.$default.'" value="1" />'
10261: .&mt('Display').'</label> '
10262: .'<label><input type="radio" name="'.$default.'" value="0" checked="checked"/>'
10263: .&mt('Do not display').'</label></span></td></tr>';
1.48 raeburn 10264: }
10265: }
10266: }
1.57 raeburn 10267: } else {
10268: $datatable .= &initialize_categories($itemcount);
1.48 raeburn 10269: }
10270: } else {
1.160.6.87 raeburn 10271: $datatable .= '<tr><td class="LC_right_item">'.$hdritem->{'header'}->[1]->{'col2'}.'</td></tr>'
1.57 raeburn 10272: .&initialize_categories($itemcount);
1.48 raeburn 10273: }
1.57 raeburn 10274: $$rowtotal += $itemcount;
1.48 raeburn 10275: }
10276: return $datatable;
10277: }
10278:
1.69 raeburn 10279: sub print_serverstatuses {
10280: my ($dom,$settings,$rowtotal) = @_;
10281: my $datatable;
10282: my @pages = &serverstatus_pages();
10283: my (%namedaccess,%machineaccess);
10284: foreach my $type (@pages) {
10285: $namedaccess{$type} = '';
10286: $machineaccess{$type}= '';
10287: }
10288: if (ref($settings) eq 'HASH') {
10289: foreach my $type (@pages) {
10290: if (exists($settings->{$type})) {
10291: if (ref($settings->{$type}) eq 'HASH') {
10292: foreach my $key (keys(%{$settings->{$type}})) {
10293: if ($key eq 'namedusers') {
10294: $namedaccess{$type} = $settings->{$type}->{$key};
10295: } elsif ($key eq 'machines') {
10296: $machineaccess{$type} = $settings->{$type}->{$key};
10297: }
10298: }
10299: }
10300: }
10301: }
10302: }
1.81 raeburn 10303: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 10304: my $rownum = 0;
10305: my $css_class;
10306: foreach my $type (@pages) {
10307: $rownum ++;
10308: $css_class = $rownum%2?' class="LC_odd_row"':'';
10309: $datatable .= '<tr'.$css_class.'>'.
10310: '<td><span class="LC_nobreak">'.
10311: $titles->{$type}.'</span></td>'.
10312: '<td class="LC_left_item">'.
10313: '<input type="text" name="'.$type.'_namedusers" '.
10314: 'value="'.$namedaccess{$type}.'" size="30" /></td>'.
10315: '<td class="LC_right_item">'.
10316: '<span class="LC_nobreak">'.
10317: '<input type="text" name="'.$type.'_machines" '.
10318: 'value="'.$machineaccess{$type}.'" size="10" />'.
1.160.6.87 raeburn 10319: '</span></td></tr>'."\n";
1.69 raeburn 10320: }
10321: $$rowtotal += $rownum;
10322: return $datatable;
10323: }
10324:
10325: sub serverstatus_pages {
10326: return ('userstatus','lonstatus','loncron','server-status','codeversions',
1.160.6.15 raeburn 10327: 'checksums','clusterstatus','metadata_keywords','metadata_harvest',
1.160.6.31 raeburn 10328: 'takeoffline','takeonline','showenv','toggledebug','ping','domconf',
1.160.6.62 raeburn 10329: 'uniquecodes','diskusage','coursecatalog');
1.69 raeburn 10330: }
10331:
1.160.6.40 raeburn 10332: sub defaults_javascript {
10333: my ($settings) = @_;
1.160.6.98 raeburn 10334: return unless (ref($settings) eq 'HASH');
1.160.6.118.2 12(raebu 10335:23): my $portal_js = <<"ENDPORTAL";
10336:23):
10337:23): function portalExtras(caller) {
10338:23): var x = caller.value;
10339:23): var y = new Array('email','web');
10340:23): for (var i=0; i<y.length; i++) {
10341:23): if (document.getElementById('portal_def_'+y[i]+'_div')) {
10342:23): var z = document.getElementById('portal_def_'+y[i]+'_div');
10343:23): if (x.length > 0) {
10344:23): z.style.display = 'block';
10345:23): } else {
10346:23): z.style.display = 'none';
10347:23): }
10348:23): }
10349:23): }
10350:23): }
10351:23): ENDPORTAL
1.160.6.40 raeburn 10352: if ((ref($settings->{'inststatusorder'}) eq 'ARRAY') && (ref($settings->{'inststatustypes'}) eq 'HASH')) {
10353: my $maxnum = scalar(@{$settings->{'inststatusorder'}});
10354: if ($maxnum eq '') {
10355: $maxnum = 0;
10356: }
10357: $maxnum ++;
1.160.6.51 raeburn 10358: my $jstext = ' var inststatuses = Array('."'".join("','",@{$settings->{'inststatusorder'}})."'".');';
1.160.6.40 raeburn 10359: return <<"ENDSCRIPT";
10360: <script type="text/javascript">
10361: // <![CDATA[
10362: function reorderTypes(form,caller) {
10363: var changedVal;
10364: $jstext
10365: var newpos = 'addinststatus_pos';
10366: var current = new Array;
10367: var maxh = $maxnum;
10368: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10369: var oldVal;
10370: if (caller == newpos) {
10371: changedVal = newitemVal;
10372: } else {
10373: var curritem = 'inststatus_pos_'+caller;
10374: changedVal = form.elements[curritem].options[form.elements[curritem].selectedIndex].value;
10375: current[newitemVal] = newpos;
10376: }
10377: for (var i=0; i<inststatuses.length; i++) {
10378: if (inststatuses[i] != caller) {
10379: var elementName = 'inststatus_pos_'+inststatuses[i];
10380: if (form.elements[elementName]) {
10381: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10382: current[currVal] = elementName;
10383: }
10384: }
10385: }
10386: for (var j=0; j<maxh; j++) {
10387: if (current[j] == undefined) {
10388: oldVal = j;
10389: }
10390: }
10391: if (oldVal < changedVal) {
10392: for (var k=oldVal+1; k<=changedVal ; k++) {
10393: var elementName = current[k];
10394: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10395: }
10396: } else {
10397: for (var k=changedVal; k<oldVal; k++) {
10398: var elementName = current[k];
10399: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10400: }
10401: }
10402: return;
10403: }
10404:
1.160.6.118.2 12(raebu 10405:23): $portal_js
10406:23):
10407:23): // ]]>
10408:23): </script>
10409:23):
10410:23): ENDSCRIPT
10411:23): } else {
10412:23): return <<"ENDSCRIPT";
10413:23): <script type="text/javascript">
10414:23): // <![CDATA[
10415:23): $portal_js
1.160.6.40 raeburn 10416: // ]]>
10417: </script>
10418:
10419: ENDSCRIPT
10420: }
1.160.6.118.2 14(raebu 10421:23): return;
1.160.6.40 raeburn 10422: }
10423:
1.160.6.98 raeburn 10424: sub passwords_javascript {
1.160.6.118.2 5(raebur 10425:2): my ($prefix) = @_;
10426:2): my %intalert;
10427:2): if ($prefix eq 'passwords') {
10428:2): %intalert = &Apache::lonlocal::texthash (
10429: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.',
10430:2): authcost => 'Warning: bcrypt encryption cost for internal authentication must be an integer.',
10431:2): passmin => 'Warning: minimum password length must be a positive integer greater than 6.',
10432:2): passmax => 'Warning: maximum password length must be a positive integer (or blank).',
10433:2): passnum => 'Warning: number of previous passwords to save must be a positive integer (or blank).',
10434:2): );
14(raebu 10435:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 10436:2): %intalert = &Apache::lonlocal::texthash (
10437:2): passmin => 'Warning: minimum secret length must be a positive integer greater than 6.',
10438:2): passmax => 'Warning: maximum secret length must be a positive integer (or blank).',
10439:2): );
10440:2): }
1.160.6.99 raeburn 10441: &js_escape(\%intalert);
10442: my $defmin = $Apache::lonnet::passwdmin;
1.160.6.118.2 5(raebur 10443:2): my $intauthjs;
10444:2): if ($prefix eq 'passwords') { $intauthjs = <<"ENDSCRIPT";
1.160.6.98 raeburn 10445:
10446: function warnIntAuth(field) {
10447: if (field.name == 'intauth_check') {
10448: if (field.value == '2') {
1.160.6.99 raeburn 10449: alert('$intalert{authcheck}');
1.160.6.98 raeburn 10450: }
10451: }
10452: if (field.name == 'intauth_cost') {
10453: field.value.replace(/\s/g,'');
10454: if (field.value != '') {
10455: var regexdigit=/^\\d+\$/;
10456: if (!regexdigit.test(field.value)) {
1.160.6.99 raeburn 10457: alert('$intalert{authcost}');
10458: }
10459: }
10460: }
10461: return;
10462: }
10463:
1.160.6.118.2 5(raebur 10464:2): ENDSCRIPT
10465:2):
10466:2): }
10467:2):
10468:2): $intauthjs .= <<"ENDSCRIPT";
10469:2):
10470:2): function warnInt$prefix(field) {
1.160.6.99 raeburn 10471: field.value.replace(/^\s+/,'');
10472: field.value.replace(/\s+\$/,'');
10473: var regexdigit=/^\\d+\$/;
1.160.6.118.2 5(raebur 10474:2): if (field.name == '${prefix}_min') {
1.160.6.99 raeburn 10475: if (field.value == '') {
10476: alert('$intalert{passmin}');
10477: field.value = '$defmin';
10478: } else {
10479: if (!regexdigit.test(field.value)) {
10480: alert('$intalert{passmin}');
10481: field.value = '$defmin';
10482: }
10483: var minval = parseInt(field.value,10);
10484: if (minval < $defmin) {
10485: alert('$intalert{passmin}');
10486: field.value = '$defmin';
10487: }
10488: }
10489: } else {
10490: if (field.value == '0') {
10491: field.value = '';
10492: }
10493: if (field.value != '') {
1.160.6.118.2 5(raebur 10494:2): if (!regexdigit.test(field.value)) {
10495:2): if (field.name == '${prefix}_max') {
10496:2): alert('$intalert{passmax}');
1.160.6.99 raeburn 10497: } else {
1.160.6.118.2 5(raebur 10498:2): if (field.name == '${prefix}_numsaved') {
10499:2): alert('$intalert{passnum}');
1.160.6.99 raeburn 10500: }
10501: }
1.160.6.118.2 5(raebur 10502:2): field.value = '';
1.160.6.98 raeburn 10503: }
10504: }
10505: }
10506: return;
10507: }
10508:
10509: ENDSCRIPT
10510: return &Apache::lonhtmlcommon::scripttag($intauthjs);
10511: }
10512:
1.49 raeburn 10513: sub coursecategories_javascript {
10514: my ($settings) = @_;
1.57 raeburn 10515: my ($output,$jstext,$cathash);
1.49 raeburn 10516: if (ref($settings) eq 'HASH') {
1.57 raeburn 10517: $cathash = $settings->{'cats'};
10518: }
10519: if (ref($cathash) eq 'HASH') {
1.49 raeburn 10520: my (@cats,@jsarray,%idx);
1.57 raeburn 10521: &Apache::loncommon::gather_categories($cathash,\@cats,\%idx,\@jsarray);
1.49 raeburn 10522: if (@jsarray > 0) {
10523: $jstext = ' var categories = Array('.scalar(@jsarray).');'."\n";
10524: for (my $i=0; $i<@jsarray; $i++) {
10525: if (ref($jsarray[$i]) eq 'ARRAY') {
10526: my $catstr = join('","',@{$jsarray[$i]});
10527: $jstext .= ' categories['.$i.'] = Array("'.$catstr.'");'."\n";
10528: }
10529: }
10530: }
10531: } else {
10532: $jstext = ' var categories = Array(1);'."\n".
10533: ' categories[0] = Array("instcode_pos");'."\n";
10534: }
1.160.6.42 raeburn 10535: my $instcode_reserved = &mt('The name: [_1] is a reserved category.','"instcode"');
10536: my $communities_reserved = &mt('The name: [_1] is a reserved category.','"communities"');
1.160.6.66 raeburn 10537: my $choose_again = "\n".&mt('Please use a different name for the new top level category.');
10538: &js_escape(\$instcode_reserved);
10539: &js_escape(\$communities_reserved);
10540: &js_escape(\$choose_again);
1.49 raeburn 10541: $output = <<"ENDSCRIPT";
10542: <script type="text/javascript">
1.109 raeburn 10543: // <![CDATA[
1.49 raeburn 10544: function reorderCats(form,parent,item,idx) {
10545: var changedVal;
10546: $jstext
10547: var newpos = 'addcategory_pos';
10548: if (parent == '') {
10549: var has_instcode = 0;
10550: var maxtop = categories[idx].length;
10551: for (var j=0; j<maxtop; j++) {
10552: if (categories[idx][j] == 'instcode::0') {
10553: has_instcode == 1;
10554: }
10555: }
10556: if (has_instcode == 0) {
10557: categories[idx][maxtop] = 'instcode_pos';
10558: }
10559: } else {
10560: newpos += '_'+parent;
10561: }
10562: var maxh = 1 + categories[idx].length;
10563: var current = new Array;
10564: var newitemVal = form.elements[newpos].options[form.elements[newpos].selectedIndex].value;
10565: if (item == newpos) {
10566: changedVal = newitemVal;
10567: } else {
10568: changedVal = form.elements[item].options[form.elements[item].selectedIndex].value;
10569: current[newitemVal] = newpos;
10570: }
10571: for (var i=0; i<categories[idx].length; i++) {
10572: var elementName = categories[idx][i];
10573: if (elementName != item) {
10574: if (form.elements[elementName]) {
10575: var currVal = form.elements[elementName].options[form.elements[elementName].selectedIndex].value;
10576: current[currVal] = elementName;
10577: }
10578: }
10579: }
10580: var oldVal;
10581: for (var j=0; j<maxh; j++) {
10582: if (current[j] == undefined) {
10583: oldVal = j;
10584: }
10585: }
10586: if (oldVal < changedVal) {
10587: for (var k=oldVal+1; k<=changedVal ; k++) {
10588: var elementName = current[k];
10589: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex - 1;
10590: }
10591: } else {
10592: for (var k=changedVal; k<oldVal; k++) {
10593: var elementName = current[k];
10594: form.elements[elementName].selectedIndex = form.elements[elementName].selectedIndex + 1;
10595: }
10596: }
10597: return;
10598: }
1.120 raeburn 10599:
10600: function categoryCheck(form) {
10601: if (form.elements['addcategory_name'].value == 'instcode') {
10602: alert('$instcode_reserved\\n$choose_again');
10603: return false;
10604: }
10605: if (form.elements['addcategory_name'].value == 'communities') {
10606: alert('$communities_reserved\\n$choose_again');
10607: return false;
10608: }
10609: return true;
10610: }
10611:
1.109 raeburn 10612: // ]]>
1.49 raeburn 10613: </script>
10614:
10615: ENDSCRIPT
10616: return $output;
10617: }
10618:
1.48 raeburn 10619: sub initialize_categories {
10620: my ($itemcount) = @_;
1.120 raeburn 10621: my ($datatable,$css_class,$chgstr);
1.160.6.111 raeburn 10622: my %default_names = &Apache::lonlocal::texthash (
1.120 raeburn 10623: instcode => 'Official courses (with institutional codes)',
10624: communities => 'Communities',
10625: );
10626: my $select0 = ' selected="selected"';
10627: my $select1 = '';
10628: foreach my $default ('instcode','communities') {
10629: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.87 raeburn 10630: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','$default"."_pos','0'".');"';
1.120 raeburn 10631: if ($default eq 'communities') {
10632: $select1 = $select0;
10633: $select0 = '';
10634: }
10635: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
10636: .'<select name="'.$default.'_pos">'
10637: .'<option value="0"'.$select0.'>1</option>'
10638: .'<option value="1"'.$select1.'>2</option>'
10639: .'<option value="2">3</option></select> '
10640: .$default_names{$default}
10641: .'</span></td><td><span class="LC_nobreak">'
10642: .'<label><input type="radio" name="'.$default.'" value="1" checked="checked" />'
10643: .&mt('Display').'</label> <label>'
10644: .'<input type="radio" name="'.$default.'" value="0" />'.&mt('Do not display')
1.48 raeburn 10645: .'</label></span></td></tr>';
1.120 raeburn 10646: $itemcount ++;
10647: }
1.48 raeburn 10648: $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.49 raeburn 10649: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'','addcategory_pos','0'".');"';
1.48 raeburn 10650: $datatable .= '<tr '.$css_class.'><td><span class="LC_nobreak">'
1.120 raeburn 10651: .'<select name="addcategory_pos"'.$chgstr.'>'
10652: .'<option value="0">1</option>'
10653: .'<option value="1">2</option>'
10654: .'<option value="2" selected="selected">3</option></select> '
1.160.6.103 raeburn 10655: .&mt('Add category').'</span></td><td><span class="LC_nobreak">'.&mt('Name:')
1.160.6.87 raeburn 10656: .' <input type="text" size="20" name="addcategory_name" value="" /></span>'
10657: .'</td></tr>';
1.48 raeburn 10658: return $datatable;
10659: }
10660:
10661: sub build_category_rows {
1.49 raeburn 10662: my ($itemcount,$cats,$depth,$parent,$path,$idx) = @_;
10663: my ($text,$name,$item,$chgstr);
1.48 raeburn 10664: if (ref($cats) eq 'ARRAY') {
10665: my $maxdepth = scalar(@{$cats});
10666: if (ref($cats->[$depth]) eq 'HASH') {
10667: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
10668: my $numchildren = @{$cats->[$depth]{$parent}};
10669: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.160.6.23 raeburn 10670: $text .= '<td><table class="LC_data_table">';
1.49 raeburn 10671: my ($idxnum,$parent_name,$parent_item);
10672: my $higher = $depth - 1;
10673: if ($higher == 0) {
10674: $parent_name = &escape($parent).'::'.$higher;
10675: } else {
10676: if (ref($path) eq 'ARRAY') {
10677: $parent_name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10678: }
10679: }
10680: $parent_item = 'addcategory_pos_'.$parent_name;
1.48 raeburn 10681: for (my $j=0; $j<=$numchildren; $j++) {
1.49 raeburn 10682: if ($j < $numchildren) {
1.48 raeburn 10683: $name = $cats->[$depth]{$parent}[$j];
10684: $item = &escape($name).':'.&escape($parent).':'.$depth;
1.49 raeburn 10685: $idxnum = $idx->{$item};
10686: } else {
10687: $name = $parent_name;
10688: $item = $parent_item;
1.48 raeburn 10689: }
1.49 raeburn 10690: $chgstr = ' onchange="javascript:reorderCats(this.form,'."'$parent_name','$item','$idxnum'".');"';
10691: $text .= '<tr '.$css_class.'><td><span class="LC_nobreak"><select name="'.$item.'"'.$chgstr.'>';
1.48 raeburn 10692: for (my $i=0; $i<=$numchildren; $i++) {
10693: my $vpos = $i+1;
10694: my $selstr;
10695: if ($j == $i) {
10696: $selstr = ' selected="selected" ';
10697: }
10698: $text .= '<option value="'.$i.'"'.$selstr.'>'.$vpos.'</option>';
10699: }
10700: $text .= '</select> ';
10701: if ($j < $numchildren) {
10702: my $deeper = $depth+1;
10703: $text .= $name.' '
10704: .'<label><input type="checkbox" name="deletecategory" value="'
10705: .$item.'" />'.&mt('Delete').'</label></span></td><td>';
10706: if(ref($path) eq 'ARRAY') {
10707: push(@{$path},$name);
1.49 raeburn 10708: $text .= &build_category_rows($itemcount,$cats,$deeper,$name,$path,$idx);
1.48 raeburn 10709: pop(@{$path});
10710: }
10711: } else {
1.160.6.87 raeburn 10712: $text .= &mt('Add subcategory:').' </span><input type="text" size="20" name="addcategory_name_';
1.48 raeburn 10713: if ($j == $numchildren) {
10714: $text .= $name;
10715: } else {
10716: $text .= $item;
10717: }
10718: $text .= '" value="" />';
10719: }
10720: $text .= '</td></tr>';
10721: }
10722: $text .= '</table></td>';
10723: } else {
10724: my $higher = $depth-1;
10725: if ($higher == 0) {
10726: $name = &escape($parent).'::'.$higher;
10727: } else {
10728: if (ref($path) eq 'ARRAY') {
10729: $name = &escape($parent).':'.&escape($path->[-2]).':'.$higher;
10730: }
10731: }
10732: my $colspan;
10733: if ($parent ne 'instcode') {
10734: $colspan = $maxdepth - $depth - 1;
1.160.6.87 raeburn 10735: $text .= '<td colspan="'.$colspan.'">'.&mt('Add subcategory:').'<input type="text" size="20" name="subcat_'.$name.'" value="" /></td>';
1.48 raeburn 10736: }
10737: }
10738: }
10739: }
10740: return $text;
10741: }
10742:
1.33 raeburn 10743: sub modifiable_userdata_row {
1.160.6.93 raeburn 10744: my ($context,$item,$settings,$numinrow,$rowcount,$usertypes,$fieldsref,$titlesref,
1.160.6.118.2 14(raebu 10745:23): $rowid,$customcss,$rowstyle,$itemdesc) = @_;
1.160.6.35 raeburn 10746: my ($role,$rolename,$statustype);
10747: $role = $item;
1.160.6.34 raeburn 10748: if ($context eq 'cancreate') {
1.160.6.93 raeburn 10749: if ($item =~ /^(emailusername)_(.+)$/) {
10750: $role = $1;
10751: $statustype = $2;
1.160.6.35 raeburn 10752: if (ref($usertypes) eq 'HASH') {
10753: if ($usertypes->{$statustype}) {
10754: $rolename = &mt('Data provided by [_1]',$usertypes->{$statustype});
10755: } else {
10756: $rolename = &mt('Data provided by user');
10757: }
10758: }
1.160.6.34 raeburn 10759: }
10760: } elsif ($context eq 'selfcreate') {
1.63 raeburn 10761: if (ref($usertypes) eq 'HASH') {
10762: $rolename = $usertypes->{$role};
10763: } else {
10764: $rolename = $role;
10765: }
1.160.6.118.2 14(raebu 10766:23): } elsif ($context eq 'lti') {
10767:23): $rolename = &mt('Institutional data used (if available)');
1.33 raeburn 10768: } else {
1.63 raeburn 10769: if ($role eq 'cr') {
10770: $rolename = &mt('Custom role');
10771: } else {
10772: $rolename = &Apache::lonnet::plaintext($role);
10773: }
1.33 raeburn 10774: }
1.160.6.34 raeburn 10775: my (@fields,%fieldtitles);
10776: if (ref($fieldsref) eq 'ARRAY') {
10777: @fields = @{$fieldsref};
10778: } else {
10779: @fields = ('lastname','firstname','middlename','generation',
10780: 'permanentemail','id');
10781: }
10782: if ((ref($titlesref) eq 'HASH')) {
10783: %fieldtitles = %{$titlesref};
10784: } else {
10785: %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
10786: }
1.33 raeburn 10787: my $output;
1.160.6.93 raeburn 10788: my $css_class;
10789: if ($rowcount%2) {
10790: $css_class = 'LC_odd_row';
10791: }
10792: if ($customcss) {
10793: $css_class .= " $customcss";
10794: }
10795: $css_class =~ s/^\s+//;
10796: if ($css_class) {
10797: $css_class = ' class="'.$css_class.'"';
10798: }
10799: if ($rowstyle) {
10800: $css_class .= ' style="'.$rowstyle.'"';
10801: }
10802: if ($rowid) {
10803: $rowid = ' id="'.$rowid.'"';
10804: }
10805: $output = '<tr '.$css_class.$rowid.'>'.
1.33 raeburn 10806: '<td><span class="LC_nobreak">'.$rolename.'</span></td>'.
10807: '<td class="LC_left_item" colspan="2"><table>';
10808: my $rem;
10809: my %checks;
10810: if (ref($settings) eq 'HASH') {
1.160.6.118.2 14(raebu 10811:23): my $hashref;
10812:23): if ($context eq 'lti') {
10813:23): if (ref($settings) eq 'HASH') {
10814:23): $hashref = $settings->{'instdata'};
10815:23): }
10816:23): } elsif (ref($settings->{$context}) eq 'HASH') {
1.33 raeburn 10817: if (ref($settings->{$context}->{$role}) eq 'HASH') {
1.160.6.118.2 14(raebu 10818:23): $hashref = $settings->{'lti_instdata'};
10819:23): }
10820:23): if ($role eq 'emailusername') {
10821:23): if ($statustype) {
10822:23): if (ref($settings->{$context}->{$role}->{$statustype}) eq 'HASH') {
10823:23): $hashref = $settings->{$context}->{$role}->{$statustype};
1.160.6.35 raeburn 10824: }
1.160.6.118.2 14(raebu 10825:23): }
10826:23): }
10827:23): }
10828:23): if (ref($hashref) eq 'HASH') {
10829:23): foreach my $field (@fields) {
10830:23): if ($hashref->{$field}) {
10831:23): if ($role eq 'emailusername') {
10832:23): $checks{$field} = $hashref->{$field};
10833:23): } else {
10834:23): $checks{$field} = ' checked="checked" ';
1.33 raeburn 10835: }
10836: }
10837: }
10838: }
10839: }
1.160.6.93 raeburn 10840: my $total = scalar(@fields);
10841: for (my $i=0; $i<$total; $i++) {
10842: $rem = $i%($numinrow);
1.33 raeburn 10843: if ($rem == 0) {
10844: if ($i > 0) {
10845: $output .= '</tr>';
10846: }
10847: $output .= '<tr>';
10848: }
10849: my $check = ' ';
1.160.6.35 raeburn 10850: unless ($role eq 'emailusername') {
10851: if (exists($checks{$fields[$i]})) {
1.160.6.98 raeburn 10852: $check = $checks{$fields[$i]};
1.160.6.118.2 14(raebu 10853:23): } elsif ($context ne 'lti') {
1.160.6.35 raeburn 10854: if ($role eq 'st') {
10855: if (ref($settings) ne 'HASH') {
1.160.6.39 raeburn 10856: $check = ' checked="checked" ';
1.160.6.35 raeburn 10857: }
1.33 raeburn 10858: }
10859: }
10860: }
10861: $output .= '<td class="LC_left_item">'.
1.160.6.35 raeburn 10862: '<span class="LC_nobreak">';
1.160.6.118.2 14(raebu 10863:23): my $prefix = 'canmodify';
1.160.6.35 raeburn 10864: if ($role eq 'emailusername') {
10865: unless ($checks{$fields[$i]} =~ /^(required|optional)$/) {
10866: $checks{$fields[$i]} = 'omit';
10867: }
10868: foreach my $option ('required','optional','omit') {
10869: my $checked='';
10870: if ($checks{$fields[$i]} eq $option) {
10871: $checked='checked="checked" ';
10872: }
10873: $output .= '<label>'.
1.160.6.118.2 14(raebu 10874:23): '<input type="radio" name="'.$prefix.'_'.$item.'_'.$fields[$i].'" value="'.$option.'" '.$checked.'/>'.
1.160.6.35 raeburn 10875: &mt($option).'</label>'.(' ' x2);
10876: }
10877: $output .= '<i>'.$fieldtitles{$fields[$i]}.'</i>';
10878: } else {
1.160.6.118.2 14(raebu 10879:23): if ($context eq 'lti') {
10880:23): $prefix = 'lti';
25(raebu 10881:24): } elsif ($context eq 'coauthor') {
10882:24): $prefix = 'cacanmodify';
14(raebu 10883:23): }
1.160.6.35 raeburn 10884: $output .= '<label>'.
1.160.6.118.2 14(raebu 10885:23): '<input type="checkbox" name="'.$prefix.'_'.$role.'" '.
1.160.6.35 raeburn 10886: 'value="'.$fields[$i].'"'.$check.'/>'.$fieldtitles{$fields[$i]}.
10887: '</label>';
10888: }
10889: $output .= '</span></td>';
1.33 raeburn 10890: }
1.160.6.93 raeburn 10891: $rem = $total%$numinrow;
10892: my $colsleft;
10893: if ($rem) {
10894: $colsleft = $numinrow - $rem;
10895: }
10896: if ($colsleft > 1) {
1.33 raeburn 10897: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">'.
10898: ' </td>';
10899: } elsif ($colsleft == 1) {
10900: $output .= '<td class="LC_left_item"> </td>';
10901: }
10902: $output .= '</tr></table></td></tr>';
10903: return $output;
10904: }
1.28 raeburn 10905:
1.93 raeburn 10906: sub insttypes_row {
1.160.6.93 raeburn 10907: my ($settings,$types,$usertypes,$dom,$numinrow,$othertitle,$context,$rowtotal,$onclick,
10908: $customcss,$rowstyle) = @_;
1.93 raeburn 10909: my %lt = &Apache::lonlocal::texthash (
1.160.6.118.2 20(raebu 10910:24): cansearch => 'Users allowed to search',
1.93 raeburn 10911: statustocreate => 'Institutional affiliation(s) able to create own account (login/SSO)',
1.160.6.118.2 20(raebu 10912:24): lockablenames => 'User preference to lock name',
10913:24): selfassign => 'Self-reportable affiliations',
10914:24): overrides => "Override domain's helpdesk settings based on requester's affiliation",
10915:24): webdav => 'WebDAV access available',
10916:24): authorquota => 'Authoring Space quota (MB)',
1.93 raeburn 10917: );
1.160.6.118.2 20(raebu 10918:24): my ($showdom,$defaultquota);
1.93 raeburn 10919: if ($context eq 'cansearch') {
10920: $showdom = ' ('.$dom.')';
1.160.6.118.2 20(raebu 10921:24): } elsif ($context eq 'authorquota') {
10922:24): $defaultquota = 500;
1.93 raeburn 10923: }
1.160.6.5 raeburn 10924: my $class = 'LC_left_item';
10925: if ($context eq 'statustocreate') {
10926: $class = 'LC_right_item';
10927: }
1.160.6.93 raeburn 10928: my $css_class;
10929: if ($$rowtotal%2) {
10930: $css_class = 'LC_odd_row';
10931: }
10932: if ($customcss) {
10933: $css_class .= ' '.$customcss;
10934: }
10935: $css_class =~ s/^\s+//;
10936: if ($css_class) {
10937: $css_class = ' class="'.$css_class.'"';
10938: }
10939: if ($rowstyle) {
10940: $css_class .= ' style="'.$rowstyle.'"';
10941: }
10942: if ($onclick) {
10943: $onclick = 'onclick="'.$onclick.'" ';
1.160.6.34 raeburn 10944: }
10945: my $output = '<tr'.$css_class.'>'.
10946: '<td>'.$lt{$context}.$showdom.
10947: '</td><td class="'.$class.'" colspan="2"><table>';
1.26 raeburn 10948: my $rem;
10949: if (ref($types) eq 'ARRAY') {
10950: for (my $i=0; $i<@{$types}; $i++) {
10951: if (defined($usertypes->{$types->[$i]})) {
10952: my $rem = $i%($numinrow);
10953: if ($rem == 0) {
10954: if ($i > 0) {
10955: $output .= '</tr>';
10956: }
10957: $output .= '<tr>';
1.23 raeburn 10958: }
1.160.6.118.2 20(raebu 10959:24): if ($context eq 'authorquota') {
10960:24): my $currquota;
10961:24): if ($settings->{$context}->{$types->[$i]} =~ /^\d+$/) {
10962:24): $currquota = $settings->{$context}->{$types->[$i]};
10963:24): } else {
10964:24): $currquota = $defaultquota;
10965:24): }
10966:24): $output .= '<td class="LC_left_item">'."\n".
10967:24): '<label><span class="LC_nobreak">'."\n".
10968:24): $usertypes->{$types->[$i]}.'</span><br />'."\n".
10969:24): '<input type="text" name="'.$context.'_'.$types->[$i].'" '.
10970:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
10971:24): '</label></td>';
10972:24): } else {
10973:24): my $check = ' ';
10974:24): if (ref($settings) eq 'HASH') {
10975:24): if (ref($settings->{$context}) eq 'ARRAY') {
10976:24): if (grep(/^\Q$types->[$i]\E$/,@{$settings->{$context}})) {
10977:24): $check = ' checked="checked" ';
10978:24): }
10979:24): } elsif (ref($settings->{$context}) eq 'HASH') {
10980:24): if (ref($settings->{$context}->{$types->[$i]}) eq 'HASH') {
10981:24): $check = ' checked="checked" ';
10982:24): } elsif ($context eq 'webdav') {
10983:24): if ($settings->{$context}->{$types->[$i]}) {
10984:24): $check = ' checked="checked" ';
10985:24): }
10986:24): }
10987:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 10988: $check = ' checked="checked" ';
10989: }
1.26 raeburn 10990: }
1.160.6.118.2 20(raebu 10991:24): $output .= '<td class="LC_left_item">'.
10992:24): '<span class="LC_nobreak"><label>'.
10993:24): '<input type="checkbox" name="'.$context.'" '.
10994:24): 'value="'.$types->[$i].'"'.$check.$onclick.'/>'.
10995:24): $usertypes->{$types->[$i]}.'</label></span></td>';
1.23 raeburn 10996: }
10997: }
10998: }
1.26 raeburn 10999: $rem = @{$types}%($numinrow);
1.23 raeburn 11000: }
11001: my $colsleft = $numinrow - $rem;
1.160.6.101 raeburn 11002: if ($context eq 'overrides') {
11003: if ($colsleft > 1) {
11004: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11005: } else {
11006: $output .= '<td class="LC_left_item">';
11007: }
11008: $output .= ' ';
1.23 raeburn 11009: } else {
1.160.6.101 raeburn 11010: if ($rem == 0) {
11011: $output .= '<tr>';
11012: }
11013: if ($colsleft > 1) {
11014: $output .= '<td colspan="'.$colsleft.'" class="LC_left_item">';
11015: } else {
11016: $output .= '<td class="LC_left_item">';
11017: }
1.160.6.118.2 20(raebu 11018:24): if ($context eq 'authorquota') {
11019:24): my $currquota = 500;
11020:24): if ((ref($settings) eq 'HASH') && (ref($settings->{$context}) eq 'HASH')) {
11021:24): if ($settings->{$context}{'default'} =~ /^\d+$/) {
11022:24): $currquota = $settings->{$context}{'default'};
11023:24): }
11024:24): }
11025:24): $output .= '<label><span class="LC_nobreak">'.$othertitle.'</span><br />'."\n".
11026:24): '<input type="text" name="'.$context.'_default" '.
11027:24): 'value="'.$currquota.'" size="5"'.$onclick.'/>'."\n".
11028:24): '</label>';
11029:24): } else {
11030:24): my $defcheck = ' ';
11031:24): if (ref($settings) eq 'HASH') {
11032:24): if (ref($settings->{$context}) eq 'ARRAY') {
11033:24): if (grep(/^default$/,@{$settings->{$context}})) {
11034:24): $defcheck = ' checked="checked" ';
11035:24): }
11036:24): } elsif (ref($settings->{$context}) eq 'HASH') {
11037:24): if (ref($settings->{$context}->{'default'}) eq 'HASH') {
11038:24): $defcheck = ' checked="checked" ';
11039:24): } elsif ($context eq 'webdav') {
11040:24): if ($settings->{$context}->{'default'}) {
11041:24): $defcheck = ' checked="checked" ';
11042:24): }
11043:24): }
11044:24): } elsif ($context eq 'statustocreate') {
1.160.6.101 raeburn 11045: $defcheck = ' checked="checked" ';
11046: }
1.99 raeburn 11047: }
1.160.6.118.2 20(raebu 11048:24): $output .= '<span class="LC_nobreak"><label>'.
11049:24): '<input type="checkbox" name="'.$context.'" '.
11050:24): 'value="default"'.$defcheck.$onclick.'/>'.
11051:24): $othertitle.'</label></span>';
1.26 raeburn 11052: }
1.23 raeburn 11053: }
1.160.6.101 raeburn 11054: $output .= '</td></tr></table></td></tr>';
1.25 raeburn 11055: return $output;
1.23 raeburn 11056: }
11057:
11058: sub sorted_searchtitles {
11059: my %searchtitles = &Apache::lonlocal::texthash(
11060: 'uname' => 'username',
11061: 'lastname' => 'last name',
11062: 'lastfirst' => 'last name, first name',
11063: );
11064: my @titleorder = ('uname','lastname','lastfirst');
11065: return (\%searchtitles,\@titleorder);
11066: }
11067:
1.25 raeburn 11068: sub sorted_searchtypes {
11069: my %srchtypes_desc = (
11070: exact => 'is exact match',
11071: contains => 'contains ..',
11072: begins => 'begins with ..',
11073: );
11074: my @srchtypeorder = ('exact','begins','contains');
11075: return (\%srchtypes_desc,\@srchtypeorder);
11076: }
11077:
1.3 raeburn 11078: sub usertype_update_row {
11079: my ($settings,$usertypes,$fieldtitles,$fields,$types,$rownums) = @_;
11080: my $datatable;
11081: my $numinrow = 4;
11082: foreach my $type (@{$types}) {
11083: if (defined($usertypes->{$type})) {
11084: $$rownums ++;
11085: my $css_class = $$rownums%2?' class="LC_odd_row"':'';
11086: $datatable .= '<tr'.$css_class.'><td>'.$usertypes->{$type}.
11087: '</td><td class="LC_left_item"><table>';
11088: for (my $i=0; $i<@{$fields}; $i++) {
11089: my $rem = $i%($numinrow);
11090: if ($rem == 0) {
11091: if ($i > 0) {
11092: $datatable .= '</tr>';
11093: }
11094: $datatable .= '<tr>';
11095: }
11096: my $check = ' ';
1.39 raeburn 11097: if (ref($settings) eq 'HASH') {
11098: if (ref($settings->{'fields'}) eq 'HASH') {
11099: if (ref($settings->{'fields'}{$type}) eq 'ARRAY') {
11100: if (grep(/^\Q$fields->[$i]\E$/,@{$settings->{'fields'}{$type}})) {
11101: $check = ' checked="checked" ';
11102: }
1.3 raeburn 11103: }
11104: }
11105: }
11106:
11107: if ($i == @{$fields}-1) {
11108: my $colsleft = $numinrow - $rem;
11109: if ($colsleft > 1) {
11110: $datatable .= '<td colspan="'.$colsleft.'">';
11111: } else {
11112: $datatable .= '<td>';
11113: }
11114: } else {
11115: $datatable .= '<td>';
11116: }
1.8 raeburn 11117: $datatable .= '<span class="LC_nobreak"><label>'.
11118: '<input type="checkbox" name="updateable_'.$type.
11119: '_'.$fields->[$i].'" value="1"'.$check.'/>'.
11120: $fieldtitles->{$fields->[$i]}.'</label></span></td>';
1.3 raeburn 11121: }
11122: $datatable .= '</tr></table></td></tr>';
11123: }
11124: }
11125: return $datatable;
1.1 raeburn 11126: }
11127:
11128: sub modify_login {
1.160.6.24 raeburn 11129: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 11130: my ($resulttext,$errors,$colchgtext,%changes,%colchanges,%newfile,%newurl,
1.160.6.113 raeburn 11131: %curr_loginvia,%loginhash,@currlangs,@newlangs,$addedfile,%title,@offon,
1.160.6.118.2 9(raebur 11132:2): %currsaml,%saml,%samltext,%samlimg,%samlalt,%samlurl,%samltitle,%samlwindow,%samlnotsso);
1.160.6.5 raeburn 11133: %title = ( coursecatalog => 'Display course catalog',
11134: adminmail => 'Display administrator E-mail address',
1.160.6.14 raeburn 11135: helpdesk => 'Display "Contact Helpdesk" link',
1.160.6.5 raeburn 11136: newuser => 'Link for visitors to create a user account',
1.160.6.113 raeburn 11137: loginheader => 'Log-in box header',
11138: saml => 'Dual SSO and non-SSO login');
1.160.6.5 raeburn 11139: @offon = ('off','on');
1.112 raeburn 11140: if (ref($domconfig{login}) eq 'HASH') {
11141: if (ref($domconfig{login}{loginvia}) eq 'HASH') {
11142: foreach my $lonhost (keys(%{$domconfig{login}{loginvia}})) {
11143: $curr_loginvia{$lonhost} = $domconfig{login}{loginvia}{$lonhost};
11144: }
11145: }
1.160.6.113 raeburn 11146: if (ref($domconfig{login}{'saml'}) eq 'HASH') {
11147: foreach my $lonhost (keys(%{$domconfig{login}{'saml'}})) {
11148: if (ref($domconfig{login}{'saml'}{$lonhost}) eq 'HASH') {
11149: $currsaml{$lonhost} = $domconfig{login}{'saml'}{$lonhost};
11150: $saml{$lonhost} = 1;
11151: $samltext{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'text'};
11152: $samlurl{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'url'};
11153: $samlalt{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'alt'};
11154: $samlimg{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'img'};
11155: $samltitle{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'title'};
1.160.6.118.2 9(raebur 11156:2): $samlwindow{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'window'};
1.160.6.113 raeburn 11157: $samlnotsso{$lonhost} = $domconfig{login}{'saml'}{$lonhost}{'notsso'};
11158: }
11159: }
11160: }
1.112 raeburn 11161: }
1.9 raeburn 11162: ($errors,%colchanges) = &modify_colors($r,$dom,$confname,['login'],
11163: \%domconfig,\%loginhash);
1.160.6.14 raeburn 11164: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11165: foreach my $item (@toggles) {
11166: $loginhash{login}{$item} = $env{'form.'.$item};
11167: }
1.41 raeburn 11168: $loginhash{login}{loginheader} = $env{'form.loginheader'};
1.6 raeburn 11169: if (ref($colchanges{'login'}) eq 'HASH') {
11170: $colchgtext = &display_colorchgs($dom,\%colchanges,['login'],
11171: \%loginhash);
11172: }
1.110 raeburn 11173:
1.149 raeburn 11174: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.56 raeburn 11175: my %domservers = &Apache::lonnet::get_servers($dom);
1.128 raeburn 11176: my @loginvia_attribs = ('serverpath','custompath','exempt');
1.110 raeburn 11177: if (keys(%servers) > 1) {
11178: foreach my $lonhost (keys(%servers)) {
1.128 raeburn 11179: next if ($env{'form.'.$lonhost.'_server'} eq $lonhost);
11180: if (ref($curr_loginvia{$lonhost}) eq 'HASH') {
11181: if ($env{'form.'.$lonhost.'_server'} eq $curr_loginvia{$lonhost}{'server'}) {
11182: $loginhash{login}{loginvia}{$lonhost}{'server'} = $curr_loginvia{$lonhost}{'server'};
11183: } elsif ($curr_loginvia{$lonhost}{'server'} ne '') {
11184: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11185: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11186: $changes{'loginvia'}{$lonhost} = 1;
11187: } else {
11188: $loginhash{login}{loginvia}{$lonhost}{'server'} = '';
11189: $changes{'loginvia'}{$lonhost} = 1;
11190: }
11191: } else {
11192: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11193: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
11194: $changes{'loginvia'}{$lonhost} = 1;
11195: }
11196: }
11197: if ($loginhash{login}{loginvia}{$lonhost}{'server'} eq '') {
11198: foreach my $item (@loginvia_attribs) {
11199: $loginhash{login}{loginvia}{$lonhost}{$item} = '';
11200: }
11201: } else {
11202: foreach my $item (@loginvia_attribs) {
11203: my $new = $env{'form.'.$lonhost.'_'.$item};
11204: if (($item eq 'serverpath') && ($new eq 'custom')) {
11205: $env{'form.'.$lonhost.'_custompath'} =~ s/\s+//g;
11206: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11207: $new = '/';
11208: }
11209: }
11210: if (($item eq 'custompath') &&
11211: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11212: $new = '';
11213: }
11214: if ($new ne $curr_loginvia{$lonhost}{$item}) {
11215: $changes{'loginvia'}{$lonhost} = 1;
11216: }
11217: if ($item eq 'exempt') {
1.160.6.56 raeburn 11218: $new = &check_exempt_addresses($new);
1.128 raeburn 11219: }
11220: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11221: }
11222: }
1.112 raeburn 11223: } else {
1.128 raeburn 11224: if (defined($servers{$env{'form.'.$lonhost.'_server'}})) {
11225: $loginhash{login}{loginvia}{$lonhost}{'server'} = $env{'form.'.$lonhost.'_server'};
1.112 raeburn 11226: $changes{'loginvia'}{$lonhost} = 1;
1.128 raeburn 11227: foreach my $item (@loginvia_attribs) {
11228: my $new = $env{'form.'.$lonhost.'_'.$item};
11229: if (($item eq 'serverpath') && ($new eq 'custom')) {
11230: if ($env{'form.'.$lonhost.'_custompath'} eq '') {
11231: $new = '/';
11232: }
11233: }
11234: if (($item eq 'custompath') &&
11235: ($env{'form.'.$lonhost.'_serverpath'} ne 'custom')) {
11236: $new = '';
11237: }
11238: $loginhash{login}{loginvia}{$lonhost}{$item} = $new;
11239: }
1.110 raeburn 11240: }
11241: }
11242: }
11243: }
1.119 raeburn 11244:
1.160.6.5 raeburn 11245: my $servadm = $r->dir_config('lonAdmEMail');
11246: my %langchoices = &Apache::lonlocal::texthash(&get_languages_hash());
11247: if (ref($domconfig{'login'}) eq 'HASH') {
11248: if (ref($domconfig{'login'}{'helpurl'}) eq 'HASH') {
11249: foreach my $lang (sort(keys(%{$domconfig{'login'}{'helpurl'}}))) {
11250: if ($lang eq 'nolang') {
11251: push(@currlangs,$lang);
11252: } elsif (defined($langchoices{$lang})) {
11253: push(@currlangs,$lang);
11254: } else {
11255: next;
11256: }
11257: }
11258: }
11259: }
11260: my @delurls = &Apache::loncommon::get_env_multiple('form.loginhelpurl_del');
11261: if (@currlangs > 0) {
11262: foreach my $lang (@currlangs) {
11263: if (grep(/^\Q$lang\E$/,@delurls)) {
11264: $changes{'helpurl'}{$lang} = 1;
11265: } elsif ($env{'form.loginhelpurl_'.$lang.'.filename'}) {
11266: $changes{'helpurl'}{$lang} = 1;
11267: $newfile{$lang} = $env{'form.loginhelpurl_'.$lang.'.filename'};
11268: push(@newlangs,$lang);
11269: } else {
11270: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11271: }
11272: }
11273: }
11274: unless (grep(/^nolang$/,@currlangs)) {
11275: if ($env{'form.loginhelpurl_nolang.filename'}) {
11276: $changes{'helpurl'}{'nolang'} = 1;
11277: $newfile{'nolang'} = $env{'form.loginhelpurl_nolang.filename'};
11278: push(@newlangs,'nolang');
11279: }
11280: }
11281: if ($env{'form.loginhelpurl_add_lang'}) {
11282: if ((defined($langchoices{$env{'form.loginhelpurl_add_lang'}})) &&
11283: ($env{'form.loginhelpurl_add_file.filename'})) {
11284: $newfile{$env{'form.loginhelpurl_add_lang'}} = $env{'form.loginhelpurl_add_file.filename'};
11285: $addedfile = $env{'form.loginhelpurl_add_lang'};
11286: }
11287: }
11288: if ((@newlangs > 0) || ($addedfile)) {
11289: my $error;
11290: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11291: if ($configuserok eq 'ok') {
11292: if ($switchserver) {
11293: $error = &mt("Upload of custom help file is not permitted to this server: [_1]",$switchserver);
11294: } elsif ($author_ok eq 'ok') {
11295: my @allnew = @newlangs;
11296: if ($addedfile ne '') {
11297: push(@allnew,$addedfile);
11298: }
1.160.6.118.2 14(raebu 11299:23): my $modified = [];
1.160.6.5 raeburn 11300: foreach my $lang (@allnew) {
11301: my $formelem = 'loginhelpurl_'.$lang;
11302: if ($lang eq $env{'form.loginhelpurl_add_lang'}) {
11303: $formelem = 'loginhelpurl_add_file';
11304: }
1.160.6.118.2 14(raebu 11305:23): (my $result,$newurl{$lang}) =
11306:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11307:23): "help/$lang",'','',$newfile{$lang},
11308:23): $modified);
1.160.6.5 raeburn 11309: if ($result eq 'ok') {
11310: $loginhash{'login'}{'helpurl'}{$lang} = $newurl{$lang};
11311: $changes{'helpurl'}{$lang} = 1;
11312: } else {
11313: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$newfile{$lang},$result);
11314: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11315: if ((grep(/^\Q$lang\E$/,@currlangs)) &&
11316: (!grep(/^\Q$lang\E$/,@delurls))) {
11317: $loginhash{'login'}{'helpurl'}{$lang} = $domconfig{'login'}{'helpurl'}{$lang};
11318: }
11319: }
11320: }
1.160.6.118.2 14(raebu 11321:23): &update_modify_urls($r,$modified);
1.160.6.5 raeburn 11322: } else {
11323: $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);
11324: }
11325: } else {
11326: $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);
11327: }
11328: if ($error) {
11329: &Apache::lonnet::logthis($error);
11330: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11331: }
11332: }
1.160.6.56 raeburn 11333:
11334: my (%currheadtagurls,%currexempt,@newhosts,%newheadtagurls,%possexempt);
11335: if (ref($domconfig{'login'}) eq 'HASH') {
11336: if (ref($domconfig{'login'}{'headtag'}) eq 'HASH') {
11337: foreach my $lonhost (keys(%{$domconfig{'login'}{'headtag'}})) {
11338: if ($domservers{$lonhost}) {
11339: if (ref($domconfig{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11340: $currheadtagurls{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'url'};
1.160.6.73 raeburn 11341: $currexempt{$lonhost} = $domconfig{'login'}{'headtag'}{$lonhost}{'exempt'};
1.160.6.56 raeburn 11342: }
11343: }
11344: }
11345: }
11346: }
11347: my @delheadtagurls = &Apache::loncommon::get_env_multiple('form.loginheadtag_del');
11348: foreach my $lonhost (sort(keys(%domservers))) {
11349: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11350: $changes{'headtag'}{$lonhost} = 1;
11351: } else {
11352: if ($env{'form.loginheadtagexempt_'.$lonhost}) {
11353: $possexempt{$lonhost} = &check_exempt_addresses($env{'form.loginheadtagexempt_'.$lonhost});
11354: }
11355: if ($env{'form.loginheadtag_'.$lonhost.'.filename'}) {
11356: push(@newhosts,$lonhost);
11357: } elsif ($currheadtagurls{$lonhost}) {
11358: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $currheadtagurls{$lonhost};
11359: if ($currexempt{$lonhost}) {
11360: if ((!exists($possexempt{$lonhost})) || ($possexempt{$lonhost} ne $currexempt{$lonhost})) {
11361: $changes{'headtag'}{$lonhost} = 1;
11362: }
11363: } elsif ($possexempt{$lonhost}) {
11364: $changes{'headtag'}{$lonhost} = 1;
11365: }
11366: if ($possexempt{$lonhost}) {
11367: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11368: }
11369: }
11370: }
11371: }
11372: if (@newhosts) {
11373: my $error;
11374: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11375: if ($configuserok eq 'ok') {
11376: if ($switchserver) {
11377: $error = &mt("Upload of custom markup is not permitted to this server: [_1]",$switchserver);
11378: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11379:23): my $modified = [];
1.160.6.56 raeburn 11380: foreach my $lonhost (@newhosts) {
11381: my $formelem = 'loginheadtag_'.$lonhost;
1.160.6.118.2 14(raebu 11382:23): (my $result,$newheadtagurls{$lonhost}) =
11383:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11384:23): "login/headtag/$lonhost",'','',
11385:23): $env{'form.loginheadtag_'.$lonhost.'.filename'},
11386:23): $modified);
1.160.6.56 raeburn 11387: if ($result eq 'ok') {
1.160.6.113 raeburn 11388: $loginhash{'login'}{'headtag'}{$lonhost}{'url'} = $newheadtagurls{$lonhost};
11389: $changes{'headtag'}{$lonhost} = 1;
11390: if ($possexempt{$lonhost}) {
11391: $loginhash{'login'}{'headtag'}{$lonhost}{'exempt'} = $possexempt{$lonhost};
11392: }
11393: } else {
11394: my $puberror = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",
11395: $newheadtagurls{$lonhost},$result);
11396: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11397: if ((grep(/^\Q$lonhost\E$/,keys(%currheadtagurls))) &&
11398: (!grep(/^\Q$lonhost\E$/,@delheadtagurls))) {
11399: $loginhash{'login'}{'headtag'}{$lonhost} = $currheadtagurls{$lonhost};
11400: }
11401: }
11402: }
1.160.6.118.2 14(raebu 11403:23): &update_modify_urls($r,$modified);
1.160.6.113 raeburn 11404: } else {
11405: $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);
11406: }
11407: } else {
11408: $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);
11409: }
11410: if ($error) {
11411: &Apache::lonnet::logthis($error);
11412: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11413: }
11414: }
11415: my @delsamlimg = &Apache::loncommon::get_env_multiple('form.saml_img_del');
11416: my @newsamlimgs;
11417: foreach my $lonhost (keys(%domservers)) {
11418: if ($env{'form.saml_'.$lonhost}) {
11419: if ($env{'form.saml_img_'.$lonhost.'.filename'}) {
11420: push(@newsamlimgs,$lonhost);
11421: }
1.160.6.118.2 9(raebur 11422:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11423: $env{'form.saml_'.$item.'_'.$lonhost} =~ s/^\s+|\s+$//g;
11424: }
11425: if ($saml{$lonhost}) {
1.160.6.118.2 9(raebur 11426:2): if ($env{'form.saml_window_'.$lonhost} ne '1') {
11427:2): $env{'form.saml_window_'.$lonhost} = '';
11428:2): }
1.160.6.113 raeburn 11429: if (grep(/^\Q$lonhost\E$/,@delsamlimg)) {
11430: #FIXME Need to obsolete published image
11431: delete($currsaml{$lonhost}{'img'});
11432: $changes{'saml'}{$lonhost} = 1;
11433: }
11434: if ($env{'form.saml_alt_'.$lonhost} ne $samlalt{$lonhost}) {
11435: $changes{'saml'}{$lonhost} = 1;
11436: }
11437: if ($env{'form.saml_text_'.$lonhost} ne $samltext{$lonhost}) {
11438: $changes{'saml'}{$lonhost} = 1;
11439: }
11440: if ($env{'form.saml_url_'.$lonhost} ne $samlurl{$lonhost}) {
11441: $changes{'saml'}{$lonhost} = 1;
11442: }
11443: if ($env{'form.saml_title_'.$lonhost} ne $samltitle{$lonhost}) {
11444: $changes{'saml'}{$lonhost} = 1;
11445: }
1.160.6.118.2 9(raebur 11446:2): if ($env{'form.saml_window_'.$lonhost} ne $samlwindow{$lonhost}) {
11447:2): $changes{'saml'}{$lonhost} = 1;
11448:2): }
1.160.6.113 raeburn 11449: if ($env{'form.saml_notsso_'.$lonhost} ne $samlnotsso{$lonhost}) {
11450: $changes{'saml'}{$lonhost} = 1;
11451: }
11452: } else {
11453: $changes{'saml'}{$lonhost} = 1;
11454: }
1.160.6.118.2 9(raebur 11455:2): foreach my $item ('text','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11456: $currsaml{$lonhost}{$item} = $env{'form.saml_'.$item.'_'.$lonhost};
11457: }
11458: } else {
11459: if ($saml{$lonhost}) {
11460: $changes{'saml'}{$lonhost} = 1;
11461: delete($currsaml{$lonhost});
11462: }
11463: }
11464: }
11465: foreach my $posshost (keys(%currsaml)) {
11466: unless (exists($domservers{$posshost})) {
11467: delete($currsaml{$posshost});
11468: }
11469: }
11470: %{$loginhash{'login'}{'saml'}} = %currsaml;
11471: if (@newsamlimgs) {
11472: my $error;
11473: my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
11474: if ($configuserok eq 'ok') {
11475: if ($switchserver) {
11476: $error = &mt("Upload of SSO Button Image is not permitted to this server: [_1].",$switchserver);
11477: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 11478:23): my $modified = [];
1.160.6.113 raeburn 11479: foreach my $lonhost (@newsamlimgs) {
11480: my $formelem = 'saml_img_'.$lonhost;
1.160.6.118.2 14(raebu 11481:23): my ($result,$imgurl) =
11482:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$formelem,$dom,$confname,
11483:23): "login/saml/$lonhost",'','',
11484:23): $env{'form.saml_img_'.$lonhost.'.filename'},
11485:23): $modified);
1.160.6.113 raeburn 11486: if ($result eq 'ok') {
11487: $currsaml{$lonhost}{'img'} = $imgurl;
11488: $loginhash{'login'}{'saml'}{$lonhost}{'img'} = $imgurl;
11489: $changes{'saml'}{$lonhost} = 1;
1.160.6.56 raeburn 11490: } else {
1.160.6.113 raeburn 11491: my $puberror = &mt("Upload of SSO button image failed for [_1] because an error occurred publishing the file in RES space. Error was: [_2].",
11492: $lonhost,$result);
1.160.6.56 raeburn 11493: $errors .= '<li><span class="LC_error">'.$puberror.'</span></li>';
11494: }
11495: }
1.160.6.118.2 14(raebu 11496:23): &update_modify_urls($r,$modified);
1.160.6.56 raeburn 11497: } else {
1.160.6.113 raeburn 11498: $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 11499: }
11500: } else {
1.160.6.113 raeburn 11501: $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 11502: }
11503: if ($error) {
11504: &Apache::lonnet::logthis($error);
11505: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11506: }
11507: }
1.160.6.5 raeburn 11508: &process_captcha('login',\%changes,$loginhash{'login'},$domconfig{'login'});
11509:
11510: my $defaulthelpfile = '/adm/loginproblems.html';
11511: my $defaulttext = &mt('Default in use');
11512:
1.1 raeburn 11513: my $putresult = &Apache::lonnet::put_dom('configuration',\%loginhash,
11514: $dom);
11515: if ($putresult eq 'ok') {
1.160.6.14 raeburn 11516: my @toggles = ('coursecatalog','adminmail','helpdesk','newuser');
1.42 raeburn 11517: my %defaultchecked = (
11518: 'coursecatalog' => 'on',
1.160.6.14 raeburn 11519: 'helpdesk' => 'on',
1.42 raeburn 11520: 'adminmail' => 'off',
1.43 raeburn 11521: 'newuser' => 'off',
1.42 raeburn 11522: );
1.55 raeburn 11523: if (ref($domconfig{'login'}) eq 'HASH') {
11524: foreach my $item (@toggles) {
11525: if ($defaultchecked{$item} eq 'on') {
11526: if (($domconfig{'login'}{$item} eq '0') &&
11527: ($env{'form.'.$item} eq '1')) {
11528: $changes{$item} = 1;
11529: } elsif (($domconfig{'login'}{$item} eq '' ||
11530: $domconfig{'login'}{$item} eq '1') &&
11531: ($env{'form.'.$item} eq '0')) {
11532: $changes{$item} = 1;
11533: }
11534: } elsif ($defaultchecked{$item} eq 'off') {
11535: if (($domconfig{'login'}{$item} eq '1') &&
11536: ($env{'form.'.$item} eq '0')) {
11537: $changes{$item} = 1;
11538: } elsif (($domconfig{'login'}{$item} eq '' ||
11539: $domconfig{'login'}{$item} eq '0') &&
11540: ($env{'form.'.$item} eq '1')) {
11541: $changes{$item} = 1;
11542: }
1.42 raeburn 11543: }
11544: }
1.41 raeburn 11545: }
1.6 raeburn 11546: if (keys(%changes) > 0 || $colchgtext) {
1.41 raeburn 11547: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.113 raeburn 11548: if (exists($changes{'saml'})) {
11549: my $hostid_in_use;
11550: my @hosts = &Apache::lonnet::current_machine_ids();
11551: if (@hosts > 1) {
11552: foreach my $hostid (@hosts) {
11553: if (&Apache::lonnet::host_domain($hostid) eq $dom) {
11554: $hostid_in_use = $hostid;
11555: last;
11556: }
11557: }
11558: } else {
11559: $hostid_in_use = $r->dir_config('lonHostID');
11560: }
11561: if (($hostid_in_use) &&
11562: (&Apache::lonnet::host_domain($hostid_in_use) eq $dom)) {
11563: &Apache::lonnet::devalidate_cache_new('samllanding',$hostid_in_use);
11564: }
11565: if (ref($lastactref) eq 'HASH') {
11566: if (ref($changes{'saml'}) eq 'HASH') {
11567: my %updates;
11568: map { $updates{$_} = 1; } keys(%{$changes{'saml'}});
11569: $lastactref->{'samllanding'} = \%updates;
11570: }
11571: }
11572: }
1.160.6.27 raeburn 11573: if (ref($lastactref) eq 'HASH') {
11574: $lastactref->{'domainconfig'} = 1;
11575: }
1.1 raeburn 11576: $resulttext = &mt('Changes made:').'<ul>';
11577: foreach my $item (sort(keys(%changes))) {
1.135 bisitz 11578: if ($item eq 'loginvia') {
1.112 raeburn 11579: if (ref($changes{$item}) eq 'HASH') {
11580: $resulttext .= '<li>'.&mt('Log-in page availability:').'<ul>';
11581: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
1.128 raeburn 11582: if (defined($servers{$loginhash{login}{loginvia}{$lonhost}{'server'}})) {
11583: if (ref($loginhash{login}{loginvia}{$lonhost}) eq 'HASH') {
11584: my $protocol = $Apache::lonnet::protocol{$env{'form.'.$lonhost.'_server'}};
11585: $protocol = 'http' if ($protocol ne 'https');
11586: my $target = $protocol.'://'.$servers{$env{'form.'.$lonhost.'_server'}};
11587:
11588: if ($loginhash{login}{loginvia}{$lonhost}{'serverpath'} eq 'custom') {
11589: $target .= $loginhash{login}{loginvia}{$lonhost}{'custompath'};
11590: } else {
11591: $target .= $loginhash{login}{loginvia}{$lonhost}{'serverpath'};
11592: }
11593: $resulttext .= '<li>'.&mt('Server: [_1] log-in page redirects to [_2].',$servers{$lonhost},'<a href="'.$target.'">'.$target.'</a>');
11594: if ($loginhash{login}{loginvia}{$lonhost}{'exempt'} ne '') {
11595: $resulttext .= ' '.&mt('No redirection for clients from following IPs:').' '.$loginhash{login}{loginvia}{$lonhost}{'exempt'};
11596: }
11597: $resulttext .= '</li>';
11598: } else {
11599: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$lonhost).'</li>';
11600: }
1.112 raeburn 11601: } else {
1.128 raeburn 11602: $resulttext .= '<li>'.&mt('Server: [_1] has standard log-in page.',$servers{$lonhost}).'</li>';
1.112 raeburn 11603: }
11604: }
1.128 raeburn 11605: $resulttext .= '</ul></li>';
1.112 raeburn 11606: }
1.160.6.5 raeburn 11607: } elsif ($item eq 'helpurl') {
11608: if (ref($changes{$item}) eq 'HASH') {
11609: foreach my $lang (sort(keys(%{$changes{$item}}))) {
11610: if (grep(/^\Q$lang\E$/,@delurls)) {
11611: my ($chg,$link);
11612: $link = &Apache::loncommon::modal_link($defaulthelpfile,$defaulttext,600,500);
11613: if ($lang eq 'nolang') {
11614: $chg = &mt('custom log-in help file removed for no preferred language; [_1]',$link);
11615: } else {
11616: $chg = &mt('custom log-in help file removed for specific language: [_1]; [_2]',$langchoices{$lang},$link);
11617: }
11618: $resulttext .= '<li>'.$chg.'</li>';
11619: } else {
11620: my $chg;
11621: if ($lang eq 'nolang') {
11622: $chg = &mt('custom log-in help file for no preferred language');
11623: } else {
11624: $chg = &mt('custom log-in help file for specific language: [_1]',$langchoices{$lang});
11625: }
11626: $resulttext .= '<li>'.&Apache::loncommon::modal_link(
11627: $loginhash{'login'}{'helpurl'}{$lang}.
11628: '?inhibitmenu=yes',$chg,600,500).
11629: '</li>';
11630: }
11631: }
11632: }
1.160.6.56 raeburn 11633: } elsif ($item eq 'headtag') {
11634: if (ref($changes{$item}) eq 'HASH') {
11635: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11636: if (grep(/^\Q$lonhost\E$/,@delheadtagurls)) {
11637: $resulttext .= '<li>'.&mt('custom markup file removed for [_1]',$domservers{$lonhost}).'</li>';
11638: } elsif (ref($loginhash{'login'}{'headtag'}{$lonhost}) eq 'HASH') {
11639: $resulttext .= '<li><a href="'.
11640: "javascript:void(open('$loginhash{'login'}{'headtag'}{$lonhost}{'url'}?inhibitmenu=yes','Custom_HeadTag',
11641: 'menubar=0,toolbar=1,scrollbars=1,width=600,height=500,resizable=yes'))".
11642: '">'.&mt('custom markup').'</a> '.&mt('(for [_1])',$servers{$lonhost}).' ';
11643: if ($possexempt{$lonhost}) {
11644: $resulttext .= &mt('not included for client IP(s): [_1]',$possexempt{$lonhost});
11645: } else {
11646: $resulttext .= &mt('included for any client IP');
11647: }
11648: $resulttext .= '</li>';
11649: }
11650: }
11651: }
1.160.6.113 raeburn 11652: } elsif ($item eq 'saml') {
11653: if (ref($changes{$item}) eq 'HASH') {
11654: my %notlt = (
11655: text => 'Text for log-in by SSO',
11656: img => 'SSO button image',
11657: alt => 'Alt text for button image',
11658: url => 'SSO URL',
11659: title => 'Tooltip for SSO link',
1.160.6.118.2 9(raebur 11660:2): window => 'Pop-up window if iframe',
1.160.6.113 raeburn 11661: notsso => 'Text for non-SSO log-in',
11662: );
11663: foreach my $lonhost (sort(keys(%{$changes{$item}}))) {
11664: if (ref($currsaml{$lonhost}) eq 'HASH') {
11665: $resulttext .= '<li>'.&mt("$title{$item} in use for [_1]","<b>$lonhost</b>").
11666: '<ul>';
1.160.6.118.2 9(raebur 11667:2): foreach my $key ('text','img','alt','url','title','window','notsso') {
1.160.6.113 raeburn 11668: if ($currsaml{$lonhost}{$key} eq '') {
11669: $resulttext .= '<li>'.&mt("$notlt{$key} not in use").'</li>';
11670: } else {
11671: my $value = "'$currsaml{$lonhost}{$key}'";
11672: if ($key eq 'img') {
11673: $value = '<img src="'.$currsaml{$lonhost}{$key}.'" />';
1.160.6.118.2 9(raebur 11674:2): } elsif ($key eq 'window') {
11675:2): $value = 'On';
1.160.6.113 raeburn 11676: }
11677: $resulttext .= '<li>'.&mt("$notlt{$key} set to: [_1]",
11678: $value).'</li>';
11679: }
11680: }
11681: $resulttext .= '</ul></li>';
11682: } else {
11683: $resulttext .= '<li>'.&mt("$title{$item} not in use for [_1]",$lonhost).'</li>';
11684: }
11685: }
11686: }
1.160.6.5 raeburn 11687: } elsif ($item eq 'captcha') {
11688: if (ref($loginhash{'login'}) eq 'HASH') {
11689: my $chgtxt;
11690: if ($loginhash{'login'}{$item} eq 'notused') {
11691: $chgtxt .= &mt('No CAPTCHA validation in use for helpdesk form.');
11692: } else {
11693: my %captchas = &captcha_phrases();
11694: if ($captchas{$loginhash{'login'}{$item}}) {
11695: $chgtxt .= &mt("Validation for helpdesk form set to $captchas{$loginhash{'login'}{$item}}.");
11696: } else {
11697: $chgtxt .= &mt('Validation for helpdesk form set to unknown type.');
11698: }
11699: }
11700: $resulttext .= '<li>'.$chgtxt.'</li>';
11701: }
11702: } elsif ($item eq 'recaptchakeys') {
11703: if (ref($loginhash{'login'}) eq 'HASH') {
11704: my ($privkey,$pubkey);
11705: if (ref($loginhash{'login'}{$item}) eq 'HASH') {
11706: $pubkey = $loginhash{'login'}{$item}{'public'};
11707: $privkey = $loginhash{'login'}{$item}{'private'};
11708: }
11709: my $chgtxt .= &mt('ReCAPTCHA keys changes').'<ul>';
11710: if (!$pubkey) {
11711: $chgtxt .= '<li>'.&mt('Public key deleted').'</li>';
11712: } else {
11713: $chgtxt .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
11714: }
11715: if (!$privkey) {
11716: $chgtxt .= '<li>'.&mt('Private key deleted').'</li>';
11717: } else {
1.160.6.53 raeburn 11718: $chgtxt .= '<li>'.&mt('Private key set to [_1]',$privkey).'</li>';
1.160.6.5 raeburn 11719: }
11720: $chgtxt .= '</ul>';
11721: $resulttext .= '<li>'.$chgtxt.'</li>';
11722: }
1.160.6.69 raeburn 11723: } elsif ($item eq 'recaptchaversion') {
11724: if (ref($loginhash{'login'}) eq 'HASH') {
11725: if ($loginhash{'login'}{'captcha'} eq 'recaptcha') {
11726: $resulttext .= '<li>'.&mt('ReCAPTCHA for helpdesk form set to version [_1]',$loginhash{'login'}{'recaptchaversion'}).
11727: '</li>';
11728: }
11729: }
1.41 raeburn 11730: } else {
11731: $resulttext .= '<li>'.&mt("$title{$item} set to $offon[$env{'form.'.$item}]").'</li>';
11732: }
1.1 raeburn 11733: }
1.6 raeburn 11734: $resulttext .= $colchgtext.'</ul>';
1.1 raeburn 11735: } else {
11736: $resulttext = &mt('No changes made to log-in page settings');
11737: }
11738: } else {
1.11 albertel 11739: $resulttext = '<span class="LC_error">'.
11740: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 11741: }
1.6 raeburn 11742: if ($errors) {
1.9 raeburn 11743: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.6 raeburn 11744: $errors.'</ul>';
11745: }
11746: return $resulttext;
11747: }
11748:
1.160.6.56 raeburn 11749: sub check_exempt_addresses {
11750: my ($iplist) = @_;
11751: $iplist =~ s/^\s+//;
11752: $iplist =~ s/\s+$//;
11753: my @poss_ips = split(/\s*[,:]\s*/,$iplist);
11754: my (@okips,$new);
11755: foreach my $ip (@poss_ips) {
11756: if ($ip =~ /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/) {
11757: if (($1 <= 255) && ($2 <= 255) && ($3 <= 255) && ($4 <= 255)) {
11758: push(@okips,$ip);
11759: }
11760: }
11761: }
11762: if (@okips > 0) {
11763: $new = join(',',@okips);
11764: } else {
11765: $new = '';
11766: }
11767: return $new;
11768: }
11769:
1.6 raeburn 11770: sub color_font_choices {
11771: my %choices =
11772: &Apache::lonlocal::texthash (
11773: img => "Header",
11774: bgs => "Background colors",
11775: links => "Link colors",
1.55 raeburn 11776: images => "Images",
1.6 raeburn 11777: font => "Font color",
1.160.6.22 raeburn 11778: fontmenu => "Font menu",
1.76 raeburn 11779: pgbg => "Page",
1.6 raeburn 11780: tabbg => "Header",
11781: sidebg => "Border",
11782: link => "Link",
11783: alink => "Active link",
11784: vlink => "Visited link",
11785: );
11786: return %choices;
11787: }
11788:
1.160.6.113 raeburn 11789: sub modify_ipaccess {
11790: my ($dom,$lastactref,%domconfig) = @_;
11791: my (@allpos,%changes,%confhash,$errors,$resulttext);
11792: my (@items,%deletions,%itemids,@warnings);
11793: my ($typeorder,$types) = &commblocktype_text();
11794: if ($env{'form.ipaccess_add'}) {
11795: my $name = $env{'form.ipaccess_name_add'};
11796: my ($newid,$error) = &get_ipaccess_id($dom,$name);
11797: if ($newid) {
11798: $itemids{'add'} = $newid;
11799: push(@items,'add');
11800: $changes{$newid} = 1;
11801: } else {
11802: $error = &mt('Failed to acquire unique ID for new IP access control item');
11803: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
11804: }
11805: }
11806: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11807: my @todelete = &Apache::loncommon::get_env_multiple('form.ipaccess_del');
11808: if (@todelete) {
11809: map { $deletions{$_} = 1; } @todelete;
11810: }
11811: my $maxnum = $env{'form.ipaccess_maxnum'};
11812: for (my $i=0; $i<$maxnum; $i++) {
11813: my $itemid = $env{'form.ipaccess_id_'.$i};
11814: $itemid =~ s/\D+//g;
11815: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11816: if ($deletions{$itemid}) {
11817: $changes{$itemid} = $domconfig{'ipaccess'}{$itemid}{'name'};
11818: } else {
11819: push(@items,$i);
11820: $itemids{$i} = $itemid;
11821: }
11822: }
11823: }
11824: }
11825: foreach my $idx (@items) {
11826: my $itemid = $itemids{$idx};
11827: next unless ($itemid);
11828: my %current;
11829: unless ($idx eq 'add') {
11830: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11831: %current = %{$domconfig{'ipaccess'}{$itemid}};
11832: }
11833: }
11834: my $position = $env{'form.ipaccess_pos_'.$itemid};
11835: $position =~ s/\D+//g;
11836: if ($position ne '') {
11837: $allpos[$position] = $itemid;
11838: }
11839: my $name = $env{'form.ipaccess_name_'.$idx};
11840: $name =~ s/^\s+|\s+$//g;
11841: $confhash{$itemid}{'name'} = $name;
11842: my $possrange = $env{'form.ipaccess_range_'.$idx};
11843: $possrange =~ s/^\s+|\s+$//g;
11844: unless ($possrange eq '') {
11845: $possrange =~ s/[\r\n]+/\s/g;
11846: $possrange =~ s/\s*-\s*/-/g;
11847: $possrange =~ s/\s+/,/g;
11848: $possrange =~ s/,+/,/g;
11849: if ($possrange ne '') {
11850: my (@ok,$count);
11851: $count = 0;
11852: foreach my $poss (split(/\,/,$possrange)) {
11853: $count ++;
11854: $poss = &validate_ip_pattern($poss);
11855: if ($poss ne '') {
11856: push(@ok,$poss);
11857: }
11858: }
11859: my $diff = $count - scalar(@ok);
11860: if ($diff) {
11861: $errors .= '<li><span class="LC_error">'.
11862: &mt('[quant,_1,IP] invalid and excluded from saved value for IP range(s) for [_2]',
11863: $diff,$name).
11864: '</span></li>';
11865: }
11866: if (@ok) {
11867: my @cidr_list;
11868: foreach my $item (@ok) {
11869: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
11870: }
11871: $confhash{$itemid}{'ip'} = join(',',@cidr_list);
11872: }
11873: }
11874: }
11875: foreach my $field ('name','ip') {
11876: unless (($idx eq 'add') || ($changes{$itemid})) {
11877: if ($current{$field} ne $confhash{$itemid}{$field}) {
11878: $changes{$itemid} = 1;
11879: last;
11880: }
11881: }
11882: }
11883: $confhash{$itemid}{'commblocks'} = {};
11884:
11885: my %commblocks;
11886: map { $commblocks{$_} = 1; } &Apache::loncommon::get_env_multiple('form.ipaccess_block_'.$idx);
11887: foreach my $type (@{$typeorder}) {
11888: if ($commblocks{$type}) {
11889: $confhash{$itemid}{'commblocks'}{$type} = 'on';
11890: }
11891: unless (($idx eq 'add') || ($changes{$itemid})) {
11892: if (ref($current{'commblocks'}) eq 'HASH') {
11893: if ($confhash{$itemid}{'commblocks'}{$type} ne $current{'commblocks'}{$type}) {
11894: $changes{$itemid} = 1;
11895: }
11896: } elsif ($confhash{$itemid}{'commblocks'}{$type}) {
11897: $changes{$itemid} = 1;
11898: }
11899: }
11900: }
11901: $confhash{$itemid}{'courses'} = {};
11902: my %crsdeletions;
11903: my @delcrs = &Apache::loncommon::get_env_multiple('form.ipaccess_course_delete_'.$idx);
11904: if (@delcrs) {
11905: map { $crsdeletions{$_} = 1; } @delcrs;
11906: }
11907: if (ref($current{'courses'}) eq 'HASH') {
11908: foreach my $cid (sort(keys(%{$current{'courses'}}))) {
11909: if ($crsdeletions{$cid}) {
11910: $changes{$itemid} = 1;
11911: } else {
11912: $confhash{$itemid}{'courses'}{$cid} = 1;
11913: }
11914: }
11915: }
11916: $env{'form.ipaccess_cnum_'.$idx} =~ s/^\s+|\s+$//g;
11917: $env{'form.ipaccess_cdom_'.$idx} =~ s/^\s+|\s+$//g;
11918: if (($env{'form.ipaccess_cnum_'.$idx} =~ /^$match_courseid$/) &&
11919: ($env{'form.ipaccess_cdom_'.$idx} =~ /^$match_domain$/)) {
11920: if (&Apache::lonnet::homeserver($env{'form.ipaccess_cnum_'.$idx},
11921: $env{'form.ipaccess_cdom_'.$idx}) eq 'no_host') {
11922: $errors .= '<li><span class="LC_error">'.
11923: &mt('Invalid courseID [_1] omitted from list of allowed courses',
11924: $env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}).
11925: '</span></li>';
11926: } else {
11927: $confhash{$itemid}{'courses'}{$env{'form.ipaccess_cdom_'.$idx}.'_'.$env{'form.ipaccess_cnum_'.$idx}} = 1;
11928: $changes{$itemid} = 1;
11929: }
11930: }
11931: }
11932: if (@allpos > 0) {
11933: my $idx = 0;
11934: foreach my $itemid (@allpos) {
11935: if ($itemid ne '') {
11936: $confhash{$itemid}{'order'} = $idx;
11937: unless ($changes{$itemid}) {
11938: if (ref($domconfig{'ipaccess'}) eq 'HASH') {
11939: if (ref($domconfig{'ipaccess'}{$itemid}) eq 'HASH') {
11940: if ($domconfig{'ipaccess'}{$itemid}{'order'} ne $idx) {
11941: $changes{$itemid} = 1;
11942: }
11943: }
11944: }
11945: }
11946: $idx ++;
11947: }
11948: }
11949: }
11950: if (keys(%changes)) {
11951: my %defaultshash = (
11952: ipaccess => \%confhash,
11953: );
11954: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
11955: $dom);
11956: if ($putresult eq 'ok') {
11957: my $cachetime = 1800;
11958: &Apache::lonnet::do_cache_new('ipaccess',$dom,\%confhash,$cachetime);
11959: if (ref($lastactref) eq 'HASH') {
11960: $lastactref->{'ipaccess'} = 1;
11961: }
11962: $resulttext = &mt('Changes made:').'<ul>';
11963: my %bynum;
11964: foreach my $itemid (sort(keys(%changes))) {
11965: if (ref($confhash{$itemid}) eq 'HASH') {
11966: my $position = $confhash{$itemid}{'order'};
11967: if ($position =~ /^\d+$/) {
11968: $bynum{$position} = $itemid;
11969: }
11970: }
11971: }
11972: if (keys(%deletions)) {
11973: foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
11974: $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
11975: }
11976: }
11977: foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
11978: my $itemid = $bynum{$pos};
11979: if (ref($confhash{$itemid}) eq 'HASH') {
11980: $resulttext .= '<li><b>'.$confhash{$itemid}{'name'}.'</b><ul>';
11981: my $position = $pos + 1;
11982: $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
11983: if ($confhash{$itemid}{'ip'} eq '') {
11984: $resulttext .= '<li>'.&mt('No IP Range(s) set').'</li>';
11985: } else {
11986: $resulttext .= '<li>'.&mt('IP Range(s): [_1]',$confhash{$itemid}{'ip'}).'</li>';
11987: }
11988: if (keys(%{$confhash{$itemid}{'commblocks'}})) {
11989: $resulttext .= '<li>'.&mt('Functionality Blocked: [_1]',
11990: join(', ', map { $types->{$_}; } sort(keys(%{$confhash{$itemid}{'commblocks'}})))).
11991: '</li>';
11992: } else {
11993: $resulttext .= '<li>'.&mt('No functionality blocked').'</li>';
11994: }
11995: if (keys(%{$confhash{$itemid}{'courses'}})) {
11996: my @courses;
11997: foreach my $cid (sort(keys(%{$confhash{$itemid}{'courses'}}))) {
11998: my %courseinfo = &Apache::lonnet::coursedescription($cid,{'one_time' => 1});
11999: push(@courses,$courseinfo{'description'}.' ('.$cid.')');
12000: }
12001: $resulttext .= '<li>'.&mt('Courses/Communities allowed').':<ul><li>'.
12002: join('</li><li>',@courses).'</li></ul>';
12003: } else {
12004: $resulttext .= '<li>'.&mt('No courses allowed').'</li>';
12005: }
12006: $resulttext .= '</ul></li>';
12007: }
12008: }
12009: $resulttext .= '</ul>';
12010: } else {
12011: $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
12012: }
12013: } else {
12014: $resulttext = &mt('No changes made');
12015: }
12016: if ($errors) {
12017: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
12018: $errors.'</ul></p>';
12019: }
12020: return $resulttext;
12021: }
12022:
12023: sub get_ipaccess_id {
12024: my ($domain,$location) = @_;
12025: # get lock on ipaccess db
12026: my $lockhash = {
12027: lock => $env{'user.name'}.
12028: ':'.$env{'user.domain'},
12029: };
12030: my $tries = 0;
12031: my $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12032: my ($id,$error);
12033:
12034: while (($gotlock ne 'ok') && ($tries<10)) {
12035: $tries ++;
12036: sleep (0.1);
12037: $gotlock = &Apache::lonnet::newput_dom('ipaccess',$lockhash,$domain);
12038: }
12039: if ($gotlock eq 'ok') {
12040: my %currids = &Apache::lonnet::dump_dom('ipaccess',$domain);
12041: if ($currids{'lock'}) {
12042: delete($currids{'lock'});
12043: if (keys(%currids)) {
12044: my @curr = sort { $a <=> $b } keys(%currids);
12045: if ($curr[-1] =~ /^\d+$/) {
12046: $id = 1 + $curr[-1];
12047: }
12048: } else {
12049: $id = 1;
12050: }
12051: if ($id) {
12052: unless (&Apache::lonnet::newput_dom('ipaccess',{ $id => $location },$domain) eq 'ok') {
12053: $error = 'nostore';
12054: }
12055: } else {
12056: $error = 'nonumber';
12057: }
12058: }
12059: my $dellockoutcome = &Apache::lonnet::del_dom('ipaccess',['lock'],$domain);
12060: } else {
12061: $error = 'nolock';
12062: }
12063: return ($id,$error);
12064: }
12065:
1.160.6.118.2 20(raebu 12066:24): sub modify_authordefaults {
12067:24): my ($dom,$lastactref,%domconfig) = @_;
12068:24): #
12069:24): # Retrieve current domain configuration for webDAV and Authoring Space quotas from $domconfig{'quotas'}.
12070:24): #
12071:24): my (%curr_quotas,%save_quotas,%confhash,%changes,%newvalues);
12072:24): if (ref($domconfig{'quotas'}) eq 'HASH') {
12073:24): foreach my $key (keys(%{$domconfig{'quotas'}})) {
12074:24): if ($key =~ /^webdav|authorquota$/) {
12075:24): $curr_quotas{$key} = $domconfig{'quotas'}{$key};
12076:24): } else {
12077:24): $save_quotas{$key} = $domconfig{'quotas'}{$key};
12078:24): }
12079:24): }
12080:24): }
12081:24): my %staticdefaults = (
12082:24): 'copyright' => 'default',
12083:24): 'sourceavail' => 'closed',
12084:24): 'nocodemirror' => 'off',
21(raebu 12085:24): 'daxecollapse' => 'off',
20(raebu 12086:24): 'domcoordacc' => 'on',
22(raebu 12087:24): 'editors' => ['edit','xml'],
20(raebu 12088:24): 'authorquota' => 500,
12089:24): 'webdav' => 0,
22(raebu 12090:24): 'archive' => 'off',
20(raebu 12091:24): );
12092:24): my %titles = &authordefaults_titles();
22(raebu 12093:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12094:24): if ($env{'form.'.$item} =~ /^(0|1)$/) {
12095:24): $confhash{$item} = $env{'form.'.$item};
12096:24): }
12097:24): }
12098:24): if ($env{'form.copyright'} =~ /^(default|domain|public)$/) {
12099:24): $confhash{'copyright'} = $1;
12100:24): }
12101:24): if ($env{'form.sourceavail'} =~ /^(closed|open)$/) {
12102:24): $confhash{'sourceavail'} = $1;
12103:24): }
12104:24): my @posseditors = &Apache::loncommon::get_env_multiple('form.author_editors');
12105:24): my @okeditors = ('edit','xml','daxe');
12106:24): my @editors;
12107:24): foreach my $item (@posseditors) {
12108:24): if (grep(/^\Q$item\E$/,@okeditors)) {
12109:24): push(@editors,$item);
12110:24): }
12111:24): }
12112:24): $confhash{'editors'} = \@editors;
12113:24):
12114:24): my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
12115:24): my @insttypes;
12116:24): if (ref($types) eq 'ARRAY') {
12117:24): @insttypes = @{$types};
12118:24): }
12119:24): my @webdavon = &Apache::loncommon::get_env_multiple('form.webdav');
12120:24): my %webdav;
12121:24): map { $webdav{$_} = 1; } @webdavon;
12122:24): foreach my $type (@insttypes,'default') {
12123:24): my $possquota = $env{'form.authorquota_'.$type};
12124:24): if ($possquota =~ /^\d+$/) {
12125:24): $save_quotas{'authorquota'}{$type} = $possquota;
12126:24): }
12127:24): if ($webdav{$type}) {
12128:24): $save_quotas{'webdav'}{$type} = 1;
12129:24): } else {
12130:24): $save_quotas{'webdav'}{$type} = 0;
12131:24): }
12132:24): }
12133:24): if ($env{'form.webdav_LC_adv'} =~ /^(0|1)$/) {
12134:24): $save_quotas{'webdav'}{'_LC_adv'} = $env{'form.webdav_LC_adv'};
12135:24): }
12136:24): if (ref($domconfig{'authordefaults'}) eq 'HASH') {
22(raebu 12137:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail','archive') {
20(raebu 12138:24): if ($domconfig{'authordefaults'}{$item} ne $confhash{$item}) {
12139:24): $changes{$item} = 1;
12140:24): }
12141:24): }
12142:24): if (ref($domconfig{'authordefaults'}{'editors'}) eq 'ARRAY') {
12143:24): my @diffs =
12144:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12145:24): $domconfig{'authordefaults'}{'editors'});
12146:24): unless (@diffs == 0) {
12147:24): $changes{'editors'} = 1;
12148:24): }
12149:24): } else {
12150:24): my @diffs =
12151:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12152:24): $staticdefaults{'editors'});
12153:24): unless (@diffs == 0) {
12154:24): $changes{'editors'} = 1;
12155:24): }
12156:24): }
12157:24): } else {
12158:24): my @offon = ('off','on');
22(raebu 12159:24): foreach my $item ('nocodemirror','daxecollapse','domcoordacc','archive') {
20(raebu 12160:24): if ($offon[$confhash{$item}] ne $staticdefaults{$item}) {
12161:24): $changes{$item} = 1;
12162:24): }
12163:24): }
12164:24): foreach my $item ('copyright','sourceavail') {
12165:24): if ($confhash{$item} ne $staticdefaults{$item}) {
12166:24): $changes{$item} = 1;
12167:24): }
12168:24): }
22(raebu 12169:24): my @diffs =
12170:24): &Apache::loncommon::compare_arrays($confhash{'editors'},
12171:24): $staticdefaults{'editors'});
12172:24): unless (@diffs == 0) {
12173:24): $changes{'editors'} = 1;
12174:24): }
20(raebu 12175:24): }
12176:24): foreach my $key ('authorquota','webdav') {
12177:24): if (ref($curr_quotas{$key}) eq 'HASH') {
12178:24): foreach my $type (@insttypes,'default') {
12179:24): if (exists($save_quotas{$key}{$type})) {
12180:24): if ($save_quotas{$key}{$type} ne $curr_quotas{$key}{$type}) {
12181:24): $changes{$key}{$type} = 1;
12182:24): }
12183:24): } elsif (exists($curr_quotas{$key}{$type})) {
12184:24): $save_quotas{$key}{$type} = $curr_quotas{$key}{$type};
12185:24): } else {
12186:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12187:24): }
12188:24): }
12189:24): } else {
12190:24): foreach my $type (@insttypes,'default') {
12191:24): if (exists($save_quotas{$key}{$type})) {
12192:24): unless ($save_quotas{$key}{$type} eq $staticdefaults{$key}) {
12193:24): $changes{$key}{$type} = 1;
12194:24): }
12195:24): } else {
12196:24): $save_quotas{$key}{$type} = $staticdefaults{$key};
12197:24): }
12198:24): }
12199:24): }
12200:24): }
12201:24): if (ref($curr_quotas{'webdav'}) eq 'HASH') {
12202:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12203:24): if ($save_quotas{'webdav'}{'_LC_adv'} ne $curr_quotas{'webdav'}{'_LC_adv'}) {
12204:24): $changes{'webdav_LC_adv'} = 1;
12205:24): }
12206:24): } elsif (exists($curr_quotas{'webdav'}{'_LC_adv'})) {
12207:24): $changes{'webdav_LC_adv'} = 1;
12208:24): }
12209:24): } elsif (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12210:24): $changes{'webdav_LC_adv'} = 1;
12211:24): }
12212:24): my %confighash = (
12213:24): quotas => \%save_quotas,
12214:24): authordefaults => \%confhash,
12215:24): );
12216:24): my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,
12217:24): $dom);
12218:24): my $resulttext;
12219:24): if ($putresult eq 'ok') {
12220:24): if (keys(%changes)) {
12221:24): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
12222:24): if ((exists($changes{'authorquota'})) || (exists($changes{'webdav'})) ||
12223:24): ($changes{'webdav_LC_adv'})) {
12224:24): if ((exists($changes{'authorquota'})) && (ref($save_quotas{'authorquota'}) eq 'HASH')) {
12225:24): $domdefaults{'authorquota'} = $save_quotas{'authorquota'};
12226:24): }
12227:24): if (((exists($changes{'webdav'})) || ($changes{'webdav_LC_adv'})) &&
12228:24): (ref($save_quotas{'webdav'}) eq 'HASH')) {
12229:24): $domdefaults{'webdav'} = $save_quotas{'webdav'};
12230:24): }
12231:24): }
12232:24): $resulttext = &mt('Changes made:').'<ul>';
12233:24): my $authoroverride;
21(raebu 12234:24): foreach my $key ('nocodemirror','daxecollapse','domcoordacc','copyright','sourceavail') {
20(raebu 12235:24): if (exists($changes{$key})) {
12236:24): $domdefaults{$key} = $confhash{$key};
12237:24): my $shown;
12238:24): unless ($authoroverride) {
12239:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by Author').'<ul>';
12240:24): $authoroverride = 1;
12241:24): }
21(raebu 12242:24): if (($key eq 'nocodemirror') || ($key eq 'daxecollapse') || ($key eq 'domcoordacc')) {
20(raebu 12243:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
12244:24): } elsif ($key eq 'copyright') {
12245:24): $shown = &Apache::loncommon::copyrightdescription($confhash{$key});
12246:24): } elsif ($key eq 'sourceavail') {
12247:24): $shown = &Apache::loncommon::source_copyrightdescription($confhash{$key});
12248:24): }
12249:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12250:24): }
12251:24): }
12252:24): if ($authoroverride) {
12253:24): $resulttext .= '</ul></li>';
12254:24): }
12255:24): my $domcoordoverride;
22(raebu 12256:24): foreach my $key ('editors','authorquota','webdav','webdav_LC_adv','archive') {
20(raebu 12257:24): if (exists($changes{$key})) {
12258:24): my $shown;
12259:24): unless ($domcoordoverride) {
12260:24): $resulttext .= '<li>'.&mt('Defaults which can be overridden by a Domain Coodinator').'<ul>';
12261:24): $domcoordoverride = 1;
12262:24): }
12263:24): if ($key eq 'editors') {
12264:24): if (ref($confhash{'editors'}) eq 'ARRAY') {
12265:24): $domdefaults{'editors'} = join(',',@{$confhash{'editors'}});
12266:24): if (@{$confhash{'editors'}}) {
12267:24): $shown = join(', ', map { $titles{$_} } @{$confhash{'editors'}});
12268:24): } else {
12269:24): $shown = &mt('None');
12270:24): }
12271:24): }
12272:24): } elsif ($key eq 'authorquota') {
12273:24): foreach my $type (@insttypes) {
12274:24): $shown .= $usertypes->{$type}.' -- '.$save_quotas{$key}{$type}.', ';
12275:24): }
12276:24): $shown .= $othertitle.' -- '.$save_quotas{$key}{'default'};
12277:24): } elsif ($key eq 'webdav') {
12278:24): foreach my $type (@insttypes) {
12279:24): $shown .= $usertypes->{$type}.' -- '. ($save_quotas{$key}{$type} ? &mt('Yes') : &mt('No')).', ';
12280:24): }
12281:24): $shown .= $othertitle.' -- '. ($save_quotas{$key}{'default'} ? &mt('Yes') : &mt('No'));
12282:24): } elsif ($key eq 'webdav_LC_adv') {
12283:24): if (exists($save_quotas{'webdav'}{'_LC_adv'})) {
12284:24): $shown = ($save_quotas{'webdav'}{'_LC_adv'} ? $titles{'overon'} : $titles{'overoff'});
12285:24): } else {
12286:24): $shown = $titles{'none'};
12287:24): }
22(raebu 12288:24): } elsif ($key eq 'archive') {
12289:24): $domdefaults{$key} = $confhash{$key};
12290:24): $shown = ($confhash{$key} ? &mt('Yes') : &mt('No'));
20(raebu 12291:24): }
12292:24): $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{$key},$shown).'</li>';
12293:24): }
12294:24): }
12295:24): if ($domcoordoverride) {
12296:24): $resulttext .= '</ul></li>';
12297:24): }
22(raebu 12298:24): $resulttext .= '</ul>';
20(raebu 12299:24): my $cachetime = 24*60*60;
12300:24): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
12301:24): if (ref($lastactref) eq 'HASH') {
12302:24): $lastactref->{'domdefaults'} = 1;
12303:24): }
12304:24): } else {
12305:24): $resulttext = &mt('No changes made to Authoring Space defaults');
12306:24): }
12307:24): }
12308:24): return $resulttext;
12309:24): }
12310:24):
1.6 raeburn 12311: sub modify_rolecolors {
1.160.6.24 raeburn 12312: my ($r,$dom,$confname,$roles,$lastactref,%domconfig) = @_;
1.6 raeburn 12313: my ($resulttext,%rolehash);
12314: $rolehash{'rolecolors'} = {};
1.55 raeburn 12315: if (ref($domconfig{'rolecolors'}) ne 'HASH') {
12316: if ($domconfig{'rolecolors'} eq '') {
12317: $domconfig{'rolecolors'} = {};
12318: }
12319: }
1.9 raeburn 12320: my ($errors,%changes) = &modify_colors($r,$dom,$confname,$roles,
1.6 raeburn 12321: $domconfig{'rolecolors'},$rolehash{'rolecolors'});
12322: my $putresult = &Apache::lonnet::put_dom('configuration',\%rolehash,
12323: $dom);
12324: if ($putresult eq 'ok') {
12325: if (keys(%changes) > 0) {
1.41 raeburn 12326: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 12327: if (ref($lastactref) eq 'HASH') {
12328: $lastactref->{'domainconfig'} = 1;
12329: }
1.6 raeburn 12330: $resulttext = &display_colorchgs($dom,\%changes,$roles,
12331: $rolehash{'rolecolors'});
12332: } else {
12333: $resulttext = &mt('No changes made to default color schemes');
12334: }
12335: } else {
1.11 albertel 12336: $resulttext = '<span class="LC_error">'.
12337: &mt('An error occurred: [_1]',$putresult).'</span>';
1.6 raeburn 12338: }
12339: if ($errors) {
12340: $resulttext .= &mt('The following errors occurred: ').'<ul>'.
12341: $errors.'</ul>';
12342: }
12343: return $resulttext;
12344: }
12345:
12346: sub modify_colors {
1.9 raeburn 12347: my ($r,$dom,$confname,$roles,$domconfig,$confhash) = @_;
1.12 raeburn 12348: my (%changes,%choices);
1.51 raeburn 12349: my @bgs;
1.6 raeburn 12350: my @links = ('link','alink','vlink');
1.41 raeburn 12351: my @logintext;
1.6 raeburn 12352: my @images;
12353: my $servadm = $r->dir_config('lonAdmEMail');
12354: my $errors;
1.160.6.22 raeburn 12355: my %defaults;
1.6 raeburn 12356: foreach my $role (@{$roles}) {
12357: if ($role eq 'login') {
1.12 raeburn 12358: %choices = &login_choices();
1.41 raeburn 12359: @logintext = ('textcol','bgcol');
1.12 raeburn 12360: } else {
12361: %choices = &color_font_choices();
12362: }
12363: if ($role eq 'login') {
1.41 raeburn 12364: @images = ('img','logo','domlogo','login');
1.51 raeburn 12365: @bgs = ('pgbg','mainbg','sidebg');
1.6 raeburn 12366: } else {
12367: @images = ('img');
1.160.6.22 raeburn 12368: @bgs = ('pgbg','tabbg','sidebg');
12369: }
12370: my %defaults = &role_defaults($role,\@bgs,\@links,\@images,\@logintext);
12371: unless ($env{'form.'.$role.'_font'} eq $defaults{'font'}) {
12372: $confhash->{$role}{'font'} = $env{'form.'.$role.'_font'};
12373: }
12374: if ($role eq 'login') {
12375: foreach my $item (@logintext) {
1.160.6.39 raeburn 12376: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12377: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12378: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12379: }
12380: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'logintext'}{$item})) {
1.160.6.22 raeburn 12381: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12382: }
12383: }
12384: } else {
1.160.6.39 raeburn 12385: $env{'form.'.$role.'_fontmenu'} = lc($env{'form.'.$role.'_fontmenu'});
12386: if ($env{'form.'.$role.'_fontmenu'} =~ /^\w+/) {
12387: $env{'form.'.$role.'_fontmenu'} = '#'.$env{'form.'.$role.'_fontmenu'};
12388: }
12389: unless($env{'form.'.$role.'_fontmenu'} eq lc($defaults{'fontmenu'})) {
1.160.6.22 raeburn 12390: $confhash->{$role}{'fontmenu'} = $env{'form.'.$role.'_fontmenu'};
12391: }
1.6 raeburn 12392: }
1.160.6.22 raeburn 12393: foreach my $item (@bgs) {
1.160.6.39 raeburn 12394: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12395: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12396: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12397: }
12398: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'bgs'}{$item})) {
1.160.6.22 raeburn 12399: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12400: }
12401: }
12402: foreach my $item (@links) {
1.160.6.39 raeburn 12403: $env{'form.'.$role.'_'.$item} = lc($env{'form.'.$role.'_'.$item});
12404: if ($env{'form.'.$role.'_'.$item} =~ /^\w+/) {
12405: $env{'form.'.$role.'_'.$item} = '#'.$env{'form.'.$role.'_'.$item};
12406: }
12407: unless ($env{'form.'.$role.'_'.$item} eq lc($defaults{'links'}{$item})) {
1.160.6.22 raeburn 12408: $confhash->{$role}{$item} = $env{'form.'.$role.'_'.$item};
12409: }
1.6 raeburn 12410: }
1.46 raeburn 12411: my ($configuserok,$author_ok,$switchserver) =
12412: &config_check($dom,$confname,$servadm);
1.9 raeburn 12413: my ($width,$height) = &thumb_dimensions();
1.40 raeburn 12414: if (ref($domconfig->{$role}) ne 'HASH') {
12415: $domconfig->{$role} = {};
12416: }
1.8 raeburn 12417: foreach my $img (@images) {
1.160.6.118.2 2(raebur 12418:2): if ($role eq 'login') {
12419:2): if (($img eq 'img') || ($img eq 'logo')) {
12420:2): if (defined($env{'form.login_showlogo_'.$img})) {
12421:2): $confhash->{$role}{'showlogo'}{$img} = 1;
12422:2): } else {
12423:2): $confhash->{$role}{'showlogo'}{$img} = 0;
12424:2): }
1.70 raeburn 12425: }
1.160.6.118.2 2(raebur 12426:2): if ($env{'form.login_alt_'.$img} ne '') {
12427:2): $confhash->{$role}{'alttext'}{$img} = $env{'form.login_alt_'.$img};
12428:2): }
12429:2): }
1.18 albertel 12430: if ( ! $env{'form.'.$role.'_'.$img.'.filename'}
12431: && !defined($domconfig->{$role}{$img})
12432: && !$env{'form.'.$role.'_del_'.$img}
12433: && $env{'form.'.$role.'_import_'.$img}) {
12434: # import the old configured image from the .tab setting
12435: # if they haven't provided a new one
12436: $domconfig->{$role}{$img} =
12437: $env{'form.'.$role.'_import_'.$img};
12438: }
1.6 raeburn 12439: if ($env{'form.'.$role.'_'.$img.'.filename'} ne '') {
1.9 raeburn 12440: my $error;
1.6 raeburn 12441: if ($configuserok eq 'ok') {
1.9 raeburn 12442: if ($switchserver) {
1.12 raeburn 12443: $error = &mt("Upload of [_1] image for $role page(s) is not permitted to this server: [_2]",$choices{$img},$switchserver);
1.9 raeburn 12444: } else {
12445: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12446:23): my $modified = [];
1.9 raeburn 12447: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12448:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$role.'_'.$img,
12449:23): $dom,$confname,$img,$width,$height,
12450:23): '',$modified);
1.9 raeburn 12451: if ($result eq 'ok') {
12452: $confhash->{$role}{$img} = $logourl;
1.12 raeburn 12453: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12454:23): &update_modify_urls($r,$modified);
1.9 raeburn 12455: } else {
1.12 raeburn 12456: $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 12457: }
12458: } else {
1.46 raeburn 12459: $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 12460: }
12461: }
12462: } else {
1.46 raeburn 12463: $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 12464: }
12465: if ($error) {
1.8 raeburn 12466: &Apache::lonnet::logthis($error);
1.11 albertel 12467: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
1.8 raeburn 12468: }
12469: } elsif ($domconfig->{$role}{$img} ne '') {
1.9 raeburn 12470: if ($domconfig->{$role}{$img} !~ m-^(/res/\Q$dom\E/\Q$confname\E/\Q$img\E)/([^/]+)$-) {
12471: my $error;
12472: if ($configuserok eq 'ok') {
12473: # is confname an author?
12474: if ($switchserver eq '') {
12475: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 12476:23): my $modified = [];
1.9 raeburn 12477: my ($result,$logourl) =
1.160.6.118.2 14(raebu 12478:23): &Apache::lonconfigsettings::publishlogo($r,'copy',$domconfig->{$role}{$img},
12479:23): $dom,$confname,$img,$width,$height,
12480:23): '',$modified);
1.9 raeburn 12481: if ($result eq 'ok') {
12482: $confhash->{$role}{$img} = $logourl;
1.18 albertel 12483: $changes{$role}{'images'}{$img} = 1;
1.160.6.118.2 14(raebu 12484:23): &update_modify_urls($r,$modified);
1.9 raeburn 12485: }
12486: }
12487: }
12488: }
1.6 raeburn 12489: }
12490: }
12491: }
12492: if (ref($domconfig) eq 'HASH') {
12493: if (ref($domconfig->{$role}) eq 'HASH') {
12494: foreach my $img (@images) {
12495: if ($domconfig->{$role}{$img} ne '') {
12496: if ($env{'form.'.$role.'_del_'.$img}) {
12497: $confhash->{$role}{$img} = '';
1.12 raeburn 12498: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12499: } else {
1.9 raeburn 12500: if ($confhash->{$role}{$img} eq '') {
12501: $confhash->{$role}{$img} = $domconfig->{$role}{$img};
12502: }
1.6 raeburn 12503: }
12504: } else {
12505: if ($env{'form.'.$role.'_del_'.$img}) {
12506: $confhash->{$role}{$img} = '';
1.12 raeburn 12507: $changes{$role}{'images'}{$img} = 1;
1.6 raeburn 12508: }
12509: }
1.160.6.118.2 2(raebur 12510:2): if ($role eq 'login') {
12511:2): if (($img eq 'logo') || ($img eq 'img')) {
12512:2): if (ref($domconfig->{'login'}{'showlogo'}) eq 'HASH') {
12513:2): if ($confhash->{$role}{'showlogo'}{$img} ne
12514:2): $domconfig->{$role}{'showlogo'}{$img}) {
12515:2): $changes{$role}{'showlogo'}{$img} = 1;
12516:2): }
12517:2): } else {
12518:2): if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12519:2): $changes{$role}{'showlogo'}{$img} = 1;
12520:2): }
1.70 raeburn 12521: }
1.160.6.118.2 2(raebur 12522:2): }
12523:2): if ($img ne 'login') {
12524:2): if (ref($domconfig->{$role}{'alttext'}) eq 'HASH') {
12525:2): if ($confhash->{$role}{'alttext'}{$img} ne
12526:2): $domconfig->{$role}{'alttext'}{$img}) {
12527:2): $changes{$role}{'alttext'}{$img} = 1;
12528:2): }
12529:2): } else {
12530:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12531:2): $changes{$role}{'alttext'}{$img} = 1;
12532:2): }
1.70 raeburn 12533: }
12534: }
12535: }
12536: }
1.6 raeburn 12537: if ($domconfig->{$role}{'font'} ne '') {
12538: if ($confhash->{$role}{'font'} ne $domconfig->{$role}{'font'}) {
12539: $changes{$role}{'font'} = 1;
12540: }
12541: } else {
12542: if ($confhash->{$role}{'font'}) {
12543: $changes{$role}{'font'} = 1;
12544: }
12545: }
1.107 raeburn 12546: if ($role ne 'login') {
12547: if ($domconfig->{$role}{'fontmenu'} ne '') {
12548: if ($confhash->{$role}{'fontmenu'} ne $domconfig->{$role}{'fontmenu'}) {
12549: $changes{$role}{'fontmenu'} = 1;
12550: }
12551: } else {
12552: if ($confhash->{$role}{'fontmenu'}) {
12553: $changes{$role}{'fontmenu'} = 1;
12554: }
1.97 tempelho 12555: }
12556: }
1.6 raeburn 12557: foreach my $item (@bgs) {
12558: if ($domconfig->{$role}{$item} ne '') {
12559: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12560: $changes{$role}{'bgs'}{$item} = 1;
12561: }
12562: } else {
12563: if ($confhash->{$role}{$item}) {
12564: $changes{$role}{'bgs'}{$item} = 1;
12565: }
12566: }
12567: }
12568: foreach my $item (@links) {
12569: if ($domconfig->{$role}{$item} ne '') {
12570: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12571: $changes{$role}{'links'}{$item} = 1;
12572: }
12573: } else {
12574: if ($confhash->{$role}{$item}) {
12575: $changes{$role}{'links'}{$item} = 1;
12576: }
12577: }
12578: }
1.41 raeburn 12579: foreach my $item (@logintext) {
12580: if ($domconfig->{$role}{$item} ne '') {
12581: if ($confhash->{$role}{$item} ne $domconfig->{$role}{$item}) {
12582: $changes{$role}{'logintext'}{$item} = 1;
12583: }
12584: } else {
12585: if ($confhash->{$role}{$item}) {
12586: $changes{$role}{'logintext'}{$item} = 1;
12587: }
12588: }
12589: }
1.6 raeburn 12590: } else {
12591: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12592: \@logintext,$confhash,\%changes);
1.6 raeburn 12593: }
12594: } else {
12595: &default_change_checker($role,\@images,\@links,\@bgs,
1.41 raeburn 12596: \@logintext,$confhash,\%changes);
1.6 raeburn 12597: }
12598: }
12599: return ($errors,%changes);
12600: }
12601:
1.46 raeburn 12602: sub config_check {
12603: my ($dom,$confname,$servadm) = @_;
12604: my ($configuserok,$author_ok,$switchserver,%currroles);
12605: my $uhome = &Apache::lonnet::homeserver($confname,$dom,1);
12606: ($configuserok,%currroles) = &check_configuser($uhome,$dom,
12607: $confname,$servadm);
12608: if ($configuserok eq 'ok') {
12609: $switchserver = &check_switchserver($dom,$confname);
12610: if ($switchserver eq '') {
12611: $author_ok = &check_authorstatus($dom,$confname,%currroles);
12612: }
12613: }
12614: return ($configuserok,$author_ok,$switchserver);
12615: }
12616:
1.6 raeburn 12617: sub default_change_checker {
1.41 raeburn 12618: my ($role,$images,$links,$bgs,$logintext,$confhash,$changes) = @_;
1.6 raeburn 12619: foreach my $item (@{$links}) {
12620: if ($confhash->{$role}{$item}) {
12621: $changes->{$role}{'links'}{$item} = 1;
12622: }
12623: }
12624: foreach my $item (@{$bgs}) {
12625: if ($confhash->{$role}{$item}) {
12626: $changes->{$role}{'bgs'}{$item} = 1;
12627: }
12628: }
1.41 raeburn 12629: foreach my $item (@{$logintext}) {
12630: if ($confhash->{$role}{$item}) {
12631: $changes->{$role}{'logintext'}{$item} = 1;
12632: }
12633: }
1.6 raeburn 12634: foreach my $img (@{$images}) {
12635: if ($env{'form.'.$role.'_del_'.$img}) {
12636: $confhash->{$role}{$img} = '';
1.12 raeburn 12637: $changes->{$role}{'images'}{$img} = 1;
1.6 raeburn 12638: }
1.70 raeburn 12639: if ($role eq 'login') {
12640: if ($confhash->{$role}{'showlogo'}{$img} == 0) {
12641: $changes->{$role}{'showlogo'}{$img} = 1;
12642: }
1.160.6.118.2 2(raebur 12643:2): if (ref($confhash->{$role}{'alttext'}) eq 'HASH') {
12644:2): if ($confhash->{$role}{'alttext'}{$img} ne '') {
12645:2): $changes->{$role}{'alttext'}{$img} = 1;
12646:2): }
12647:2): }
1.70 raeburn 12648: }
1.6 raeburn 12649: }
12650: if ($confhash->{$role}{'font'}) {
12651: $changes->{$role}{'font'} = 1;
12652: }
1.48 raeburn 12653: }
1.6 raeburn 12654:
12655: sub display_colorchgs {
12656: my ($dom,$changes,$roles,$confhash) = @_;
12657: my (%choices,$resulttext);
12658: if (!grep(/^login$/,@{$roles})) {
12659: $resulttext = &mt('Changes made:').'<br />';
12660: }
12661: foreach my $role (@{$roles}) {
12662: if ($role eq 'login') {
12663: %choices = &login_choices();
12664: } else {
12665: %choices = &color_font_choices();
12666: }
12667: if (ref($changes->{$role}) eq 'HASH') {
12668: if ($role ne 'login') {
12669: $resulttext .= '<h4>'.&mt($role).'</h4>';
12670: }
12671: foreach my $key (sort(keys(%{$changes->{$role}}))) {
12672: if ($role ne 'login') {
12673: $resulttext .= '<ul>';
12674: }
12675: if (ref($changes->{$role}{$key}) eq 'HASH') {
12676: if ($role ne 'login') {
12677: $resulttext .= '<li>'.&mt($choices{$key}).':<ul>';
12678: }
12679: foreach my $item (sort(keys(%{$changes->{$role}{$key}}))) {
1.70 raeburn 12680: if (($role eq 'login') && ($key eq 'showlogo')) {
12681: if ($confhash->{$role}{$key}{$item}) {
12682: $resulttext .= '<li>'.&mt("$choices{$item} set to be displayed").'</li>';
12683: } else {
12684: $resulttext .= '<li>'.&mt("$choices{$item} set to not be displayed").'</li>';
12685: }
1.160.6.118.2 2(raebur 12686:2): } elsif (($role eq 'login') && ($key eq 'alttext')) {
12687:2): if ($confhash->{$role}{$key}{$item} ne '') {
3(raebur 12688:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} set to [_1].",
2(raebur 12689:2): $confhash->{$role}{$key}{$item}).'</li>';
12690:2): } else {
12691:2): $resulttext .= '<li>'.&mt("$choices{$key} for $choices{$item} deleted.").'</li>';
12692:2): }
1.70 raeburn 12693: } elsif ($confhash->{$role}{$item} eq '') {
1.6 raeburn 12694: $resulttext .= '<li>'.&mt("$choices{$item} set to default").'</li>';
12695: } else {
1.12 raeburn 12696: my $newitem = $confhash->{$role}{$item};
12697: if ($key eq 'images') {
12698: $newitem = '<img src="'.$confhash->{$role}{$item}.'" alt="'.$choices{$item}.'" valign="bottom" />';
12699: }
12700: $resulttext .= '<li>'.&mt("$choices{$item} set to [_1]",$newitem).'</li>';
1.6 raeburn 12701: }
12702: }
12703: if ($role ne 'login') {
12704: $resulttext .= '</ul></li>';
12705: }
12706: } else {
12707: if ($confhash->{$role}{$key} eq '') {
12708: $resulttext .= '<li>'.&mt("$choices{$key} set to default").'</li>';
12709: } else {
12710: $resulttext .= '<li>'.&mt("$choices{$key} set to [_1]",$confhash->{$role}{$key}).'</li>';
12711: }
12712: }
12713: if ($role ne 'login') {
12714: $resulttext .= '</ul>';
12715: }
12716: }
12717: }
12718: }
1.3 raeburn 12719: return $resulttext;
1.1 raeburn 12720: }
12721:
1.9 raeburn 12722: sub thumb_dimensions {
12723: return ('200','50');
12724: }
12725:
1.16 raeburn 12726: sub check_dimensions {
12727: my ($inputfile) = @_;
12728: my ($fullwidth,$fullheight);
12729: if ($inputfile =~ m|^[/\w.\-]+$|) {
12730: if (open(PIPE,"identify $inputfile 2>&1 |")) {
12731: my $imageinfo = <PIPE>;
12732: if (!close(PIPE)) {
12733: &Apache::lonnet::logthis("Failed to close PIPE opened to retrieve image information for $inputfile");
12734: }
12735: chomp($imageinfo);
12736: my ($fullsize) =
1.21 raeburn 12737: ($imageinfo =~ /^\Q$inputfile\E\s+\w+\s+(\d+x\d+)/);
1.16 raeburn 12738: if ($fullsize) {
12739: ($fullwidth,$fullheight) = split(/x/,$fullsize);
12740: }
12741: }
12742: }
12743: return ($fullwidth,$fullheight);
12744: }
12745:
1.9 raeburn 12746: sub check_configuser {
12747: my ($uhome,$dom,$confname,$servadm) = @_;
12748: my ($configuserok,%currroles);
12749: if ($uhome eq 'no_host') {
12750: srand( time() ^ ($$ + ($$ << 15)) ); # Seed rand.
1.160.6.98 raeburn 12751: my $configpass = &LONCAPA::Enrollment::create_password($dom);
1.9 raeburn 12752: $configuserok =
12753: &Apache::lonnet::modifyuser($dom,$confname,'','internal',
12754: $configpass,'','','','','',undef,$servadm);
12755: } else {
12756: $configuserok = 'ok';
12757: %currroles =
12758: &Apache::lonnet::get_my_roles($confname,$dom,'userroles');
12759: }
12760: return ($configuserok,%currroles);
12761: }
12762:
12763: sub check_authorstatus {
12764: my ($dom,$confname,%currroles) = @_;
12765: my $author_ok;
1.40 raeburn 12766: if (!$currroles{':'.$dom.':au'}) {
1.9 raeburn 12767: my $start = time;
12768: my $end = 0;
12769: $author_ok =
12770: &Apache::lonnet::assignrole($dom,$confname,'/'.$dom.'/',
1.47 raeburn 12771: 'au',$end,$start,'','','domconfig');
1.9 raeburn 12772: } else {
12773: $author_ok = 'ok';
12774: }
12775: return $author_ok;
12776: }
12777:
1.160.6.118.2 14(raebu 12778:23): sub update_modify_urls {
12779:23): my ($r,$modified) = @_;
12780:23): if ((ref($modified) eq 'ARRAY') && (@{$modified})) {
12781:23): push(@{$modified_urls},$modified);
12782:23): unless ($registered_cleanup) {
12783:23): my $handlers = $r->get_handlers('PerlCleanupHandler');
12784:23): $r->set_handlers('PerlCleanupHandler' => [\¬ifysubscribed,@{$handlers}]);
12785:23): $registered_cleanup=1;
1.9 raeburn 12786: }
12787: }
1.155 raeburn 12788: }
12789:
12790: sub notifysubscribed {
12791: foreach my $targetsource (@{$modified_urls}){
12792: next unless (ref($targetsource) eq 'ARRAY');
12793: my ($target,$source)=@{$targetsource};
12794: if ($source ne '') {
1.160.6.88 raeburn 12795: if (open(my $logfh,">>",$source.'.log')) {
1.155 raeburn 12796: print $logfh "\nCleanup phase: Notifications\n";
12797: my @subscribed=&subscribed_hosts($target);
12798: foreach my $subhost (@subscribed) {
12799: print $logfh "\nNotifying host ".$subhost.':';
12800: my $reply=&Apache::lonnet::critical('update:'.$target,$subhost);
12801: print $logfh $reply;
12802: }
12803: my @subscribedmeta=&subscribed_hosts("$target.meta");
12804: foreach my $subhost (@subscribedmeta) {
12805: print $logfh "\nNotifying host for metadata only ".$subhost.':';
12806: my $reply=&Apache::lonnet::critical('update:'.$target.'.meta',
12807: $subhost);
12808: print $logfh $reply;
12809: }
12810: print $logfh "\n============ Done ============\n";
1.160 raeburn 12811: close($logfh);
1.155 raeburn 12812: }
12813: }
12814: }
12815: return OK;
12816: }
12817:
12818: sub subscribed_hosts {
12819: my ($target) = @_;
12820: my @subscribed;
1.160.6.88 raeburn 12821: if (open(my $fh,"<","$target.subscription")) {
1.155 raeburn 12822: while (my $subline=<$fh>) {
12823: if ($subline =~ /^($match_lonid):/) {
12824: my $host = $1;
12825: if ($host ne $Apache::lonnet::perlvar{'lonHostID'}) {
12826: unless (grep(/^\Q$host\E$/,@subscribed)) {
12827: push(@subscribed,$host);
12828: }
12829: }
12830: }
12831: }
12832: }
12833: return @subscribed;
1.9 raeburn 12834: }
12835:
12836: sub check_switchserver {
12837: my ($dom,$confname) = @_;
1.160.6.118.2 14(raebu 12838:23): my ($allowed,$switchserver,$home);
12839:23): if ($confname eq '') {
1.9 raeburn 12840: $home = &Apache::lonnet::domain($dom,'primary');
1.160.6.118.2 14(raebu 12841:23): } else {
12842:23): $home = &Apache::lonnet::homeserver($confname,$dom);
12843:23): if ($home eq 'no_host') {
12844:23): $home = &Apache::lonnet::domain($dom,'primary');
12845:23): }
1.9 raeburn 12846: }
12847: my @ids=&Apache::lonnet::current_machine_ids();
1.10 albertel 12848: foreach my $id (@ids) { if ($id eq $home) { $allowed=1; } }
12849: if (!$allowed) {
1.160.6.118.2 14(raebu 12850:23): $switchserver='<a href="/adm/switchserver?otherserver='.$home.'&role='.
12851:23): &HTML::Entities::encode($env{'request.role'},'\'<>"&').
12852:23): '&destinationurl=/adm/domainprefs">'.&mt('Switch Server').'</a>';
1.9 raeburn 12853: }
12854: return $switchserver;
12855: }
12856:
1.1 raeburn 12857: sub modify_quotas {
1.160.6.30 raeburn 12858: my ($r,$dom,$action,$lastactref,%domconfig) = @_;
1.101 raeburn 12859: my ($context,@usertools,@options,%validations,%titles,%confhash,%toolshash,
1.160.6.30 raeburn 12860: %limithash,$toolregexp,%conditions,$resulttext,%changes,$confname,$configuserok,
1.160.6.39 raeburn 12861: $author_ok,$switchserver,$errors,$validationitemsref,$validationnamesref,
12862: $validationfieldsref);
1.86 raeburn 12863: if ($action eq 'quotas') {
1.160.6.118.2 20(raebu 12864:24): $context = 'tools';
1.160.6.26 raeburn 12865: } else {
1.86 raeburn 12866: $context = $action;
12867: }
12868: if ($context eq 'requestcourses') {
1.160.6.118.2 14(raebu 12869:23): @usertools = ('official','unofficial','community','textbook','lti');
1.106 raeburn 12870: @options =('norequest','approval','validate','autolimit');
1.101 raeburn 12871: %validations = &Apache::lonnet::auto_courserequest_checks($dom);
12872: %titles = &courserequest_titles();
12873: $toolregexp = join('|',@usertools);
12874: %conditions = &courserequest_conditions();
1.160.6.30 raeburn 12875: $confname = $dom.'-domainconfig';
12876: my $servadm = $r->dir_config('lonAdmEMail');
12877: ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
1.160.6.39 raeburn 12878: ($validationitemsref,$validationnamesref,$validationfieldsref) =
12879: &Apache::loncoursequeueadmin::requestcourses_validation_types();
1.160.6.5 raeburn 12880: } elsif ($context eq 'requestauthor') {
12881: @usertools = ('author');
12882: %titles = &authorrequest_titles();
1.86 raeburn 12883: } else {
1.160.6.118.2 23(raebu 12884:24): @usertools = ('aboutme','blog','portfolio','portaccess','timezone');
1.101 raeburn 12885: %titles = &tool_titles();
1.86 raeburn 12886: }
1.160.6.27 raeburn 12887: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.44 raeburn 12888: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 12889: foreach my $key (keys(%env)) {
1.101 raeburn 12890: if ($context eq 'requestcourses') {
12891: if ($key =~ /^form\.crsreq_($toolregexp)_(.+)$/) {
12892: my $item = $1;
12893: my $type = $2;
12894: if ($type =~ /^limit_(.+)/) {
12895: $limithash{$item}{$1} = $env{$key};
12896: } else {
12897: $confhash{$item}{$type} = $env{$key};
12898: }
12899: }
1.160.6.5 raeburn 12900: } elsif ($context eq 'requestauthor') {
12901: if ($key =~ /^\Qform.authorreq_\E(.+)$/) {
12902: $confhash{$1} = $env{$key};
12903: }
1.101 raeburn 12904: } else {
1.86 raeburn 12905: if ($key =~ /^form\.quota_(.+)$/) {
12906: $confhash{'defaultquota'}{$1} = $env{$key};
1.160.6.20 raeburn 12907: } elsif ($key =~ /^form\.\Q$context\E_(.+)$/) {
1.101 raeburn 12908: @{$toolshash{$1}} = &Apache::loncommon::get_env_multiple($key);
12909: }
1.72 raeburn 12910: }
12911: }
1.160.6.5 raeburn 12912: if (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.160.6.34 raeburn 12913: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.'.$context.'notifyapproval');
1.102 raeburn 12914: @approvalnotify = sort(@approvalnotify);
12915: $confhash{'notify'}{'approval'} = join(',',@approvalnotify);
1.160.6.118.2 14(raebu 12916:23): my @crstypes = ('official','unofficial','community','textbook','lti');
1.160.6.30 raeburn 12917: my @hasuniquecode = &Apache::loncommon::get_env_multiple('form.uniquecode');
12918: foreach my $type (@hasuniquecode) {
12919: if (grep(/^\Q$type\E$/,@crstypes)) {
12920: $confhash{'uniquecode'}{$type} = 1;
12921: }
12922: }
1.160.6.46 raeburn 12923: my (%newbook,%allpos);
1.160.6.30 raeburn 12924: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12925: foreach my $type ('textbooks','templates') {
12926: @{$allpos{$type}} = ();
12927: my $invalid;
12928: if ($type eq 'textbooks') {
12929: $invalid = &mt('Invalid LON-CAPA course for textbook');
12930: } else {
12931: $invalid = &mt('Invalid LON-CAPA course for template');
12932: }
12933: if ($env{'form.'.$type.'_addbook'}) {
12934: if (($env{'form.'.$type.'_addbook_cnum'} =~ /^$match_courseid$/) &&
12935: ($env{'form.'.$type.'_addbook_cdom'} =~ /^$match_domain$/)) {
12936: if (&Apache::lonnet::homeserver($env{'form.'.$type.'_addbook_cnum'},
12937: $env{'form.'.$type.'_addbook_cdom'}) eq 'no_host') {
12938: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
12939: } else {
12940: $newbook{$type} = $env{'form.'.$type.'_addbook_cdom'}.'_'.$env{'form.'.$type.'_addbook_cnum'};
12941: my $position = $env{'form.'.$type.'_addbook_pos'};
12942: $position =~ s/\D+//g;
12943: if ($position ne '') {
12944: $allpos{$type}[$position] = $newbook{$type};
12945: }
1.160.6.30 raeburn 12946: }
1.160.6.46 raeburn 12947: } else {
12948: $errors .= '<li><span class="LC_error">'.$invalid.'</span></li>';
1.160.6.30 raeburn 12949: }
12950: }
1.160.6.46 raeburn 12951: }
1.160.6.30 raeburn 12952: }
1.102 raeburn 12953: if (ref($domconfig{$action}) eq 'HASH') {
12954: if (ref($domconfig{$action}{'notify'}) eq 'HASH') {
12955: if ($domconfig{$action}{'notify'}{'approval'} ne $confhash{'notify'}{'approval'}) {
12956: $changes{'notify'}{'approval'} = 1;
12957: }
12958: } else {
1.144 raeburn 12959: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 12960: $changes{'notify'}{'approval'} = 1;
12961: }
12962: }
1.160.6.30 raeburn 12963: if (ref($domconfig{$action}{'uniquecode'}) eq 'HASH') {
12964: if (ref($confhash{'uniquecode'}) eq 'HASH') {
12965: foreach my $crstype (keys(%{$domconfig{$action}{'uniquecode'}})) {
12966: unless ($confhash{'uniquecode'}{$crstype}) {
12967: $changes{'uniquecode'} = 1;
12968: }
12969: }
12970: unless ($changes{'uniquecode'}) {
12971: foreach my $crstype (keys(%{$confhash{'uniquecode'}})) {
12972: unless ($domconfig{$action}{'uniquecode'}{$crstype}) {
12973: $changes{'uniquecode'} = 1;
12974: }
12975: }
12976: }
12977: } else {
12978: $changes{'uniquecode'} = 1;
12979: }
12980: } elsif (ref($confhash{'uniquecode'}) eq 'HASH') {
12981: $changes{'uniquecode'} = 1;
12982: }
12983: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 12984: foreach my $type ('textbooks','templates') {
12985: if (ref($domconfig{$action}{$type}) eq 'HASH') {
12986: my %deletions;
12987: my @todelete = &Apache::loncommon::get_env_multiple('form.'.$type.'_del');
12988: if (@todelete) {
12989: map { $deletions{$_} = 1; } @todelete;
12990: }
12991: my %imgdeletions;
12992: my @todeleteimages = &Apache::loncommon::get_env_multiple('form.'.$type.'_image_del');
12993: if (@todeleteimages) {
12994: map { $imgdeletions{$_} = 1; } @todeleteimages;
12995: }
12996: my $maxnum = $env{'form.'.$type.'_maxnum'};
12997: for (my $i=0; $i<=$maxnum; $i++) {
12998: my $itemid = $env{'form.'.$type.'_id_'.$i};
12999: my ($key) = ($itemid =~ /^\Q$type\E_(\w+)$/);
13000: if (ref($domconfig{$action}{$type}{$key}) eq 'HASH') {
13001: if ($deletions{$key}) {
13002: if ($domconfig{$action}{$type}{$key}{'image'}) {
13003: #FIXME need to obsolete item in RES space
13004: }
13005: next;
13006: } else {
13007: my $newpos = $env{'form.'.$itemid};
13008: $newpos =~ s/\D+//g;
1.160.6.47 raeburn 13009: foreach my $item ('subject','title','publisher','author') {
13010: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13011: ($type eq 'templates'));
1.160.6.46 raeburn 13012: $confhash{$type}{$key}{$item} = $env{'form.'.$type.'_'.$item.'_'.$i};
13013: if ($domconfig{$action}{$type}{$key}{$item} ne $confhash{$type}{$key}{$item}) {
13014: $changes{$type}{$key} = 1;
13015: }
13016: }
13017: $allpos{$type}[$newpos] = $key;
1.160.6.30 raeburn 13018: }
1.160.6.46 raeburn 13019: if ($imgdeletions{$key}) {
13020: $changes{$type}{$key} = 1;
13021: #FIXME need to obsolete item in RES space
13022: } elsif ($env{'form.'.$type.'_image_'.$i.'.filename'}) {
13023: my ($cdom,$cnum) = split(/_/,$key);
1.160.6.88 raeburn 13024: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13025: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13026: } else {
13027: my ($imgurl,$error) = &process_textbook_image($r,$dom,$confname,$type.'_image_'.$i,
13028: $cdom,$cnum,$type,$configuserok,
13029: $switchserver,$author_ok);
13030: if ($imgurl) {
13031: $confhash{$type}{$key}{'image'} = $imgurl;
13032: $changes{$type}{$key} = 1;
13033: }
13034: if ($error) {
13035: &Apache::lonnet::logthis($error);
13036: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13037: }
1.160.6.118.2 14(raebu 13038:23): }
1.160.6.46 raeburn 13039: } elsif ($domconfig{$action}{$type}{$key}{'image'}) {
13040: $confhash{$type}{$key}{'image'} =
13041: $domconfig{$action}{$type}{$key}{'image'};
1.160.6.30 raeburn 13042: }
13043: }
13044: }
13045: }
13046: }
13047: }
1.102 raeburn 13048: } else {
1.144 raeburn 13049: if ($confhash{'notify'}{'approval'}) {
1.102 raeburn 13050: $changes{'notify'}{'approval'} = 1;
13051: }
1.160.6.30 raeburn 13052: if (ref($confhash{'uniquecode'} eq 'HASH')) {
13053: $changes{'uniquecode'} = 1;
13054: }
13055: }
13056: if ($context eq 'requestcourses') {
1.160.6.46 raeburn 13057: foreach my $type ('textbooks','templates') {
13058: if ($newbook{$type}) {
13059: $changes{$type}{$newbook{$type}} = 1;
1.160.6.47 raeburn 13060: foreach my $item ('subject','title','publisher','author') {
13061: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13062: ($type eq 'template'));
1.160.6.46 raeburn 13063: $env{'form.'.$type.'_addbook_'.$item} =~ s/(`)/'/g;
13064: if ($env{'form.'.$type.'_addbook_'.$item}) {
13065: $confhash{$type}{$newbook{$type}}{$item} = $env{'form.'.$type.'_addbook_'.$item};
13066: }
13067: }
13068: if ($type eq 'textbooks') {
13069: if ($env{'form.'.$type.'_addbook_image.filename'} ne '') {
13070: my ($cdom,$cnum) = split(/_/,$newbook{$type});
1.160.6.88 raeburn 13071: if (&Apache::lonnet::homeserver($cnum,$cdom) eq 'no_host') {
13072: $errors .= '<li><span class="LC_error">'.&mt('Image not saved: could not find textbook course').'</li>';
13073: } else {
13074: my ($imageurl,$error) =
13075: &process_textbook_image($r,$dom,$confname,$type.'_addbook_image',$cdom,$cnum,$type,
13076: $configuserok,$switchserver,$author_ok);
13077: if ($imageurl) {
13078: $confhash{$type}{$newbook{$type}}{'image'} = $imageurl;
13079: }
13080: if ($error) {
13081: &Apache::lonnet::logthis($error);
13082: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
13083: }
1.160.6.46 raeburn 13084: }
13085: }
1.160.6.30 raeburn 13086: }
13087: }
1.160.6.46 raeburn 13088: if (@{$allpos{$type}} > 0) {
13089: my $idx = 0;
13090: foreach my $item (@{$allpos{$type}}) {
13091: if ($item ne '') {
13092: $confhash{$type}{$item}{'order'} = $idx;
13093: if (ref($domconfig{$action}) eq 'HASH') {
13094: if (ref($domconfig{$action}{$type}) eq 'HASH') {
13095: if (ref($domconfig{$action}{$type}{$item}) eq 'HASH') {
13096: if ($domconfig{$action}{$type}{$item}{'order'} ne $idx) {
13097: $changes{$type}{$item} = 1;
13098: }
1.160.6.30 raeburn 13099: }
13100: }
13101: }
1.160.6.46 raeburn 13102: $idx ++;
1.160.6.30 raeburn 13103: }
13104: }
13105: }
13106: }
1.160.6.39 raeburn 13107: if (ref($validationitemsref) eq 'ARRAY') {
13108: foreach my $item (@{$validationitemsref}) {
13109: if ($item eq 'fields') {
13110: my @changed;
13111: @{$confhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.requestcourses_validation_'.$item);
13112: if (@{$confhash{'validation'}{$item}} > 0) {
13113: @{$confhash{'validation'}{$item}} = sort(@{$confhash{'validation'}{$item}});
13114: }
1.160.6.65 raeburn 13115: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13116: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13117: if (ref($domconfig{'requestcourses'}{'validation'}{$item}) eq 'ARRAY') {
13118: @changed = &Apache::loncommon::compare_arrays($confhash{'validation'}{$item},
13119: $domconfig{'requestcourses'}{'validation'}{$item});
13120: } else {
13121: @changed = @{$confhash{'validation'}{$item}};
13122: }
1.160.6.39 raeburn 13123: } else {
13124: @changed = @{$confhash{'validation'}{$item}};
13125: }
13126: } else {
13127: @changed = @{$confhash{'validation'}{$item}};
13128: }
13129: if (@changed) {
13130: if ($confhash{'validation'}{$item}) {
13131: $changes{'validation'}{$item} = join(', ',@{$confhash{'validation'}{$item}});
13132: } else {
13133: $changes{'validation'}{$item} = &mt('None');
13134: }
13135: }
13136: } else {
13137: $confhash{'validation'}{$item} = $env{'form.requestcourses_validation_'.$item};
13138: if ($item eq 'markup') {
13139: if ($env{'form.requestcourses_validation_'.$item}) {
13140: $env{'form.requestcourses_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
13141: }
13142: }
1.160.6.65 raeburn 13143: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13144: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13145: if ($domconfig{'requestcourses'}{'validation'}{$item} ne $confhash{'validation'}{$item}) {
13146: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13147: }
13148: } else {
13149: if ($confhash{'validation'}{$item} ne '') {
13150: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13151: }
1.160.6.39 raeburn 13152: }
13153: } else {
13154: if ($confhash{'validation'}{$item} ne '') {
13155: $changes{'validation'}{$item} = $confhash{'validation'}{$item};
13156: }
13157: }
13158: }
13159: }
13160: }
13161: if ($env{'form.validationdc'}) {
13162: my $newval = $env{'form.validationdc'};
1.160.6.77 raeburn 13163: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.39 raeburn 13164: if (exists($domcoords{$newval})) {
13165: $confhash{'validation'}{'dc'} = $newval;
13166: }
13167: }
13168: if (ref($confhash{'validation'}) eq 'HASH') {
1.160.6.65 raeburn 13169: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13170: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13171: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13172: unless ($confhash{'validation'}{'dc'} eq $domconfig{'requestcourses'}{'validation'}{'dc'}) {
13173: if ($confhash{'validation'}{'dc'} eq '') {
13174: $changes{'validation'}{'dc'} = &mt('None');
13175: } else {
13176: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13177: }
1.160.6.39 raeburn 13178: }
1.160.6.65 raeburn 13179: } elsif ($confhash{'validation'}{'dc'} ne '') {
13180: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
1.160.6.39 raeburn 13181: }
13182: } elsif ($confhash{'validation'}{'dc'} ne '') {
13183: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13184: }
13185: } elsif ($confhash{'validation'}{'dc'} ne '') {
13186: $changes{'validation'}{'dc'} = $confhash{'validation'}{'dc'};
13187: }
1.160.6.65 raeburn 13188: } else {
13189: if (ref($domconfig{'requestcourses'}) eq 'HASH') {
13190: if (ref($domconfig{'requestcourses'}{'validation'}) eq 'HASH') {
13191: if ($domconfig{'requestcourses'}{'validation'}{'dc'}) {
13192: $changes{'validation'}{'dc'} = &mt('None');
13193: }
13194: }
1.160.6.39 raeburn 13195: }
13196: }
1.102 raeburn 13197: }
13198: } else {
1.86 raeburn 13199: $confhash{'defaultquota'}{'default'} = $env{'form.defaultquota'};
13200: }
1.72 raeburn 13201: foreach my $item (@usertools) {
13202: foreach my $type (@{$types},'default','_LC_adv') {
1.104 raeburn 13203: my $unset;
1.101 raeburn 13204: if ($context eq 'requestcourses') {
1.104 raeburn 13205: $unset = '0';
13206: if ($type eq '_LC_adv') {
13207: $unset = '';
13208: }
1.101 raeburn 13209: if ($confhash{$item}{$type} eq 'autolimit') {
13210: $confhash{$item}{$type} .= '=';
13211: unless ($limithash{$item}{$type} =~ /\D/) {
13212: $confhash{$item}{$type} .= $limithash{$item}{$type};
13213: }
13214: }
1.160.6.5 raeburn 13215: } elsif ($context eq 'requestauthor') {
13216: $unset = '0';
13217: if ($type eq '_LC_adv') {
13218: $unset = '';
13219: }
1.72 raeburn 13220: } else {
1.101 raeburn 13221: if (grep(/^\Q$type\E$/,@{$toolshash{$item}})) {
13222: $confhash{$item}{$type} = 1;
13223: } else {
13224: $confhash{$item}{$type} = 0;
13225: }
1.72 raeburn 13226: }
1.86 raeburn 13227: if (ref($domconfig{$action}) eq 'HASH') {
1.160.6.5 raeburn 13228: if ($action eq 'requestauthor') {
13229: if ($domconfig{$action}{$type} ne $confhash{$type}) {
13230: $changes{$type} = 1;
13231: }
13232: } elsif (ref($domconfig{$action}{$item}) eq 'HASH') {
1.86 raeburn 13233: if ($domconfig{$action}{$item}{$type} ne $confhash{$item}{$type}) {
13234: $changes{$item}{$type} = 1;
13235: }
13236: } else {
13237: if ($context eq 'requestcourses') {
1.104 raeburn 13238: if ($confhash{$item}{$type} ne $unset) {
1.86 raeburn 13239: $changes{$item}{$type} = 1;
13240: }
13241: } else {
13242: if (!$confhash{$item}{$type}) {
13243: $changes{$item}{$type} = 1;
13244: }
13245: }
13246: }
13247: } else {
13248: if ($context eq 'requestcourses') {
1.104 raeburn 13249: if ($confhash{$item}{$type} ne $unset) {
1.72 raeburn 13250: $changes{$item}{$type} = 1;
13251: }
1.160.6.5 raeburn 13252: } elsif ($context eq 'requestauthor') {
13253: if ($confhash{$type} ne $unset) {
13254: $changes{$type} = 1;
13255: }
1.72 raeburn 13256: } else {
13257: if (!$confhash{$item}{$type}) {
13258: $changes{$item}{$type} = 1;
13259: }
13260: }
13261: }
1.1 raeburn 13262: }
13263: }
1.160.6.5 raeburn 13264: unless (($context eq 'requestcourses') || ($context eq 'requestauthor')) {
1.86 raeburn 13265: if (ref($domconfig{'quotas'}) eq 'HASH') {
13266: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13267: foreach my $key (keys(%{$domconfig{'quotas'}{'defaultquota'}})) {
13268: if (exists($confhash{'defaultquota'}{$key})) {
13269: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{'defaultquota'}{$key}) {
13270: $changes{'defaultquota'}{$key} = 1;
13271: }
13272: } else {
13273: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{'defaultquota'}{$key};
1.72 raeburn 13274: }
13275: }
1.86 raeburn 13276: } else {
13277: foreach my $key (keys(%{$domconfig{'quotas'}})) {
13278: if (exists($confhash{'defaultquota'}{$key})) {
13279: if ($confhash{'defaultquota'}{$key} ne $domconfig{'quotas'}{$key}) {
13280: $changes{'defaultquota'}{$key} = 1;
13281: }
13282: } else {
13283: $confhash{'defaultquota'}{$key} = $domconfig{'quotas'}{$key};
1.72 raeburn 13284: }
1.1 raeburn 13285: }
13286: }
1.160.6.20 raeburn 13287: if (ref($domconfig{'quotas'}{'authorquota'}) eq 'HASH') {
1.160.6.118.2 20(raebu 13288:24): $confhash{'authorquota'} = $domconfig{'quotas'}{'authorquota'};
13289:24): }
13290:24): if (ref($domconfig{'quotas'}{'webdav'}) eq 'HASH') {
13291:24): $confhash{'webdav'} = $domconfig{'quotas'}{'webdav'};
1.160.6.20 raeburn 13292: }
1.1 raeburn 13293: }
1.86 raeburn 13294: if (ref($confhash{'defaultquota'}) eq 'HASH') {
13295: foreach my $key (keys(%{$confhash{'defaultquota'}})) {
13296: if (ref($domconfig{'quotas'}) eq 'HASH') {
13297: if (ref($domconfig{'quotas'}{'defaultquota'}) eq 'HASH') {
13298: if (!exists($domconfig{'quotas'}{'defaultquota'}{$key})) {
13299: $changes{'defaultquota'}{$key} = 1;
13300: }
13301: } else {
13302: if (!exists($domconfig{'quotas'}{$key})) {
13303: $changes{'defaultquota'}{$key} = 1;
13304: }
1.72 raeburn 13305: }
13306: } else {
1.86 raeburn 13307: $changes{'defaultquota'}{$key} = 1;
1.55 raeburn 13308: }
1.1 raeburn 13309: }
13310: }
13311: }
1.72 raeburn 13312:
1.160.6.5 raeburn 13313: if ($context eq 'requestauthor') {
13314: $domdefaults{'requestauthor'} = \%confhash;
13315: } else {
13316: foreach my $key (keys(%confhash)) {
1.160.6.46 raeburn 13317: unless (($context eq 'requestcourses') && (($key eq 'textbooks') || ($key eq 'templates'))) {
1.160.6.30 raeburn 13318: $domdefaults{$key} = $confhash{$key};
13319: }
1.160.6.5 raeburn 13320: }
1.72 raeburn 13321: }
1.160.6.5 raeburn 13322:
1.1 raeburn 13323: my %quotahash = (
1.86 raeburn 13324: $action => { %confhash }
1.1 raeburn 13325: );
13326: my $putresult = &Apache::lonnet::put_dom('configuration',\%quotahash,
13327: $dom);
13328: if ($putresult eq 'ok') {
13329: if (keys(%changes) > 0) {
1.72 raeburn 13330: my $cachetime = 24*60*60;
13331: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 13332: if (ref($lastactref) eq 'HASH') {
13333: $lastactref->{'domdefaults'} = 1;
13334: }
1.1 raeburn 13335: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.5 raeburn 13336: unless (($context eq 'requestcourses') ||
13337: ($context eq 'requestauthor')) {
1.86 raeburn 13338: if (ref($changes{'defaultquota'}) eq 'HASH') {
13339: $resulttext .= '<li>'.&mt('Portfolio default quotas').'<ul>';
13340: foreach my $type (@{$types},'default') {
13341: if (defined($changes{'defaultquota'}{$type})) {
13342: my $typetitle = $usertypes->{$type};
13343: if ($type eq 'default') {
13344: $typetitle = $othertitle;
13345: }
1.160.6.28 raeburn 13346: $resulttext .= '<li>'.&mt('[_1] set to [_2] MB',$typetitle,$confhash{'defaultquota'}{$type}).'</li>';
1.72 raeburn 13347: }
13348: }
1.86 raeburn 13349: $resulttext .= '</ul></li>';
1.72 raeburn 13350: }
13351: }
1.80 raeburn 13352: my %newenv;
1.72 raeburn 13353: foreach my $item (@usertools) {
1.160.6.5 raeburn 13354: my (%haschgs,%inconf);
13355: if ($context eq 'requestauthor') {
13356: %haschgs = %changes;
13357: %inconf = %confhash;
13358: } else {
13359: if (ref($changes{$item}) eq 'HASH') {
13360: %haschgs = %{$changes{$item}};
13361: }
13362: if (ref($confhash{$item}) eq 'HASH') {
13363: %inconf = %{$confhash{$item}};
13364: }
13365: }
13366: if (keys(%haschgs) > 0) {
1.80 raeburn 13367: my $newacc =
13368: &Apache::lonnet::usertools_access($env{'user.name'},
13369: $env{'user.domain'},
1.86 raeburn 13370: $item,'reload',$context);
1.160.6.5 raeburn 13371: if (($context eq 'requestcourses') ||
13372: ($context eq 'requestauthor')) {
1.108 raeburn 13373: if ($env{'environment.canrequest.'.$item} ne $newacc) {
13374: $newenv{'environment.canrequest.'.$item} = $newacc;
1.86 raeburn 13375: }
13376: } else {
13377: if ($env{'environment.availabletools.'.$item} ne $newacc) {
13378: $newenv{'environment.availabletools.'.$item} = $newacc;
13379: }
1.80 raeburn 13380: }
1.160.6.5 raeburn 13381: unless ($context eq 'requestauthor') {
13382: $resulttext .= '<li>'.$titles{$item}.'<ul>';
13383: }
1.72 raeburn 13384: foreach my $type (@{$types},'default','_LC_adv') {
1.160.6.5 raeburn 13385: if ($haschgs{$type}) {
1.72 raeburn 13386: my $typetitle = $usertypes->{$type};
13387: if ($type eq 'default') {
13388: $typetitle = $othertitle;
13389: } elsif ($type eq '_LC_adv') {
13390: $typetitle = 'LON-CAPA Advanced Users';
13391: }
1.160.6.5 raeburn 13392: if ($inconf{$type}) {
1.101 raeburn 13393: if ($context eq 'requestcourses') {
13394: my $cond;
1.160.6.5 raeburn 13395: if ($inconf{$type} =~ /^autolimit=(\d*)$/) {
1.101 raeburn 13396: if ($1 eq '') {
13397: $cond = &mt('(Automatic processing of any request).');
13398: } else {
13399: $cond = &mt('(Automatic processing of requests up to limit of [quant,_1,request] per user).',$1);
13400: }
13401: } else {
1.160.6.5 raeburn 13402: $cond = $conditions{$inconf{$type}};
1.101 raeburn 13403: }
13404: $resulttext .= '<li>'.&mt('Set to be available to [_1].',$typetitle).' '.$cond.'</li>';
1.160.6.8 raeburn 13405: } elsif ($context eq 'requestauthor') {
13406: $resulttext .= '<li>'.&mt('Set to "[_1]" for "[_2]".',
13407: $titles{$inconf{$type}},$typetitle);
13408:
1.101 raeburn 13409: } else {
13410: $resulttext .= '<li>'.&mt('Set to be available to [_1]',$typetitle).'</li>';
13411: }
1.72 raeburn 13412: } else {
1.104 raeburn 13413: if ($type eq '_LC_adv') {
1.160.6.5 raeburn 13414: if ($inconf{$type} eq '0') {
1.104 raeburn 13415: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13416: } else {
13417: $resulttext .= '<li>'.&mt('No override set for [_1]',$typetitle).'</li>';
13418: }
13419: } else {
13420: $resulttext .= '<li>'.&mt('Set to be unavailable to [_1]',$typetitle).'</li>';
13421: }
1.72 raeburn 13422: }
13423: }
1.26 raeburn 13424: }
1.160.6.5 raeburn 13425: unless ($context eq 'requestauthor') {
13426: $resulttext .= '</ul></li>';
13427: }
1.26 raeburn 13428: }
1.1 raeburn 13429: }
1.160.6.5 raeburn 13430: if (($action eq 'requestcourses') || ($action eq 'requestauthor')) {
1.102 raeburn 13431: if (ref($changes{'notify'}) eq 'HASH') {
13432: if ($changes{'notify'}{'approval'}) {
13433: if (ref($confhash{'notify'}) eq 'HASH') {
13434: if ($confhash{'notify'}{'approval'}) {
13435: $resulttext .= '<li>'.&mt('Notification of requests requiring approval will be sent to: ').$confhash{'notify'}{'approval'}.'</li>';
13436: } else {
1.160.6.5 raeburn 13437: $resulttext .= '<li>'.&mt('No Domain Coordinators will receive notification of requests requiring approval.').'</li>';
1.102 raeburn 13438: }
13439: }
13440: }
13441: }
13442: }
1.160.6.30 raeburn 13443: if ($action eq 'requestcourses') {
13444: my @offon = ('off','on');
13445: if ($changes{'uniquecode'}) {
13446: if (ref($confhash{'uniquecode'}) eq 'HASH') {
13447: my $codestr = join(' ',map{ &mt($_); } sort(keys(%{$confhash{'uniquecode'}})));
13448: $resulttext .= '<li>'.
13449: &mt('Generation of six character code as course identifier for distribution to students set to on for: [_1].','<b>'.$codestr.'</b>').
13450: '</li>';
13451: } else {
13452: $resulttext .= '<li>'.&mt('Generation of six character code as course identifier for distribution to students set to off.').
13453: '</li>';
13454: }
13455: }
1.160.6.46 raeburn 13456: foreach my $type ('textbooks','templates') {
13457: if (ref($changes{$type}) eq 'HASH') {
13458: $resulttext .= '<li>'.&mt("Available $type updated").'<ul>';
13459: foreach my $key (sort(keys(%{$changes{$type}}))) {
13460: my %coursehash = &Apache::lonnet::coursedescription($key);
13461: my $coursetitle = $coursehash{'description'};
13462: my $position = $confhash{$type}{$key}{'order'} + 1;
13463: $resulttext .= '<li>';
1.160.6.47 raeburn 13464: foreach my $item ('subject','title','publisher','author') {
13465: next if ((($item eq 'author') || ($item eq 'publisher')) &&
13466: ($type eq 'templates'));
1.160.6.46 raeburn 13467: my $name = $item.':';
13468: $name =~ s/^(\w)/\U$1/;
13469: $resulttext .= &mt($name).' '.$confhash{$type}{$key}{$item}.'<br />';
13470: }
13471: $resulttext .= ' '.&mt('Order: [_1]',$position).'<br />';
13472: if ($type eq 'textbooks') {
13473: if ($confhash{$type}{$key}{'image'}) {
13474: $resulttext .= ' '.&mt('Image: [_1]',
13475: '<img src="'.$confhash{$type}{$key}{'image'}.'"'.
13476: ' alt="Textbook cover" />').'<br />';
13477: }
13478: }
13479: $resulttext .= ' '.&mt('LON-CAPA Course: [_1]',$coursetitle).'</li>';
1.160.6.30 raeburn 13480: }
1.160.6.46 raeburn 13481: $resulttext .= '</ul></li>';
1.160.6.30 raeburn 13482: }
13483: }
1.160.6.39 raeburn 13484: if (ref($changes{'validation'}) eq 'HASH') {
13485: if ((ref($validationitemsref) eq 'ARRAY') && (ref($validationnamesref) eq 'HASH')) {
13486: $resulttext .= '<li>'.&mt('Validation of courses/communities updated').'<ul>';
13487: foreach my $item (@{$validationitemsref}) {
13488: if (exists($changes{'validation'}{$item})) {
13489: if ($item eq 'markup') {
13490: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13491: '<br /><pre>'.$changes{'validation'}{$item}.'</pre>').'</li>';
13492: } else {
13493: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$validationnamesref->{$item},
13494: '<b>'.$changes{'validation'}{$item}.'</b>').'</li>';
13495: }
13496: }
13497: }
13498: if (exists($changes{'validation'}{'dc'})) {
13499: $resulttext .= '<li>'.&mt('Validated course requests identified as processed by: [_1]',
13500: '<b>'.$changes{'validation'}{'dc'}.'</b>').'</li>';
13501: }
1.160.6.118.2 24(raebu 13502:24): $resulttext .= '</ul></li>';
1.160.6.39 raeburn 13503: }
13504: }
1.160.6.30 raeburn 13505: }
1.1 raeburn 13506: $resulttext .= '</ul>';
1.80 raeburn 13507: if (keys(%newenv)) {
13508: &Apache::lonnet::appenv(\%newenv);
13509: }
1.1 raeburn 13510: } else {
1.86 raeburn 13511: if ($context eq 'requestcourses') {
13512: $resulttext = &mt('No changes made to rights to request creation of courses.');
1.160.6.5 raeburn 13513: } elsif ($context eq 'requestauthor') {
13514: $resulttext = &mt('No changes made to rights to request author space.');
1.86 raeburn 13515: } else {
1.90 weissno 13516: $resulttext = &mt('No changes made to availability of personal information pages, blogs, portfolios or default quotas');
1.86 raeburn 13517: }
1.1 raeburn 13518: }
13519: } else {
1.11 albertel 13520: $resulttext = '<span class="LC_error">'.
13521: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 13522: }
1.160.6.30 raeburn 13523: if ($errors) {
13524: $resulttext .= '<p>'.&mt('The following errors occurred when modifying Textbook settings.').
13525: '<ul>'.$errors.'</ul></p>';
13526: }
1.3 raeburn 13527: return $resulttext;
1.1 raeburn 13528: }
13529:
1.160.6.30 raeburn 13530: sub process_textbook_image {
1.160.6.46 raeburn 13531: my ($r,$dom,$confname,$caller,$cdom,$cnum,$type,$configuserok,$switchserver,$author_ok) = @_;
1.160.6.30 raeburn 13532: my $filename = $env{'form.'.$caller.'.filename'};
13533: my ($error,$url);
13534: my ($width,$height) = (50,50);
13535: if ($configuserok eq 'ok') {
13536: if ($switchserver) {
13537: $error = &mt('Upload of textbook image is not permitted to this server: [_1]',
13538: $switchserver);
13539: } elsif ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 13540:23): my $modified = [];
1.160.6.30 raeburn 13541: my ($result,$imageurl) =
1.160.6.118.2 14(raebu 13542:23): &Apache::lonconfigsettings::publishlogo($r,'upload',$caller,$dom,$confname,
13543:23): "$type/$cdom/$cnum/cover",$width,$height,
13544:23): '',$modified);
1.160.6.30 raeburn 13545: if ($result eq 'ok') {
13546: $url = $imageurl;
1.160.6.118.2 14(raebu 13547:23): &update_modify_urls($r,$modified);
1.160.6.30 raeburn 13548: } else {
13549: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$filename,$result);
13550: }
13551: } else {
13552: $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);
13553: }
13554: } else {
13555: $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);
13556: }
13557: return ($url,$error);
13558: }
13559:
1.160.6.118.2 1(raebur 13560:1): sub modify_ltitools {
13561:1): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
14(raebu 13562:23): my (%currtoolsec,%secchanges,%newtoolsec,%newkeyset);
13563:23): &fetch_secrets($dom,'toolsec',\%domconfig,\%currtoolsec,\%secchanges,\%newtoolsec,\%newkeyset);
13564:23):
1(raebur 13565:1): my $confname = $dom.'-domainconfig';
13566:1): my $servadm = $r->dir_config('lonAdmEMail');
13567:1): my ($configuserok,$author_ok,$switchserver) = &config_check($dom,$confname,$servadm);
14(raebu 13568:23):
13569:23): my ($resulttext,$ltitoolsoutput,$is_home,$errors,%ltitoolschg,%newtoolsenc,%newltitools);
13570:23): my $toolserror =
13571:23): &Apache::courseprefs::process_ltitools($r,$dom,$confname,$domconfig{'ltitools'},\%ltitoolschg,'domain',
13572:23): $lastactref,$configuserok,$switchserver,$author_ok);
13573:23):
13574:23): my $home = &Apache::lonnet::domain($dom,'primary');
13575:23): unless (($home eq 'no_host') || ($home eq '')) {
13576:23): my @ids=&Apache::lonnet::current_machine_ids();
13577:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; last; } }
13578:23): }
13579:23):
13580:23): if (keys(%ltitoolschg)) {
13581:23): foreach my $id (keys(%ltitoolschg)) {
13582:23): if (ref($ltitoolschg{$id}) eq 'HASH') {
13583:23): foreach my $inner (keys(%{$ltitoolschg{$id}})) {
13584:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13585:23): if ($is_home) {
13586:23): $newtoolsenc{$id}{$inner} = $ltitoolschg{$id}{$inner};
13587:23): }
13588:23): }
1(raebur 13589:1): }
14(raebu 13590:23): }
13591:23): }
13592:23): $ltitoolsoutput = &Apache::courseprefs::store_ltitools($dom,'','domain',\%ltitoolschg,$domconfig{'ltitools'});
13593:23): if (keys(%ltitoolschg)) {
13594:23): %newltitools = %ltitoolschg;
13595:23): }
13596:23): }
13597:23): if (ref($domconfig{'ltitools'}) eq 'HASH') {
13598:23): foreach my $id (%{$domconfig{'ltitools'}}) {
13599:23): next if ($id !~ /^\d+$/);
13600:23): unless (exists($ltitoolschg{$id})) {
13601:23): if (ref($domconfig{'ltitools'}{$id}) eq 'HASH') {
13602:23): foreach my $inner (keys(%{$domconfig{'ltitools'}{$id}})) {
13603:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13604:23): if ($is_home) {
13605:23): $newtoolsenc{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13606:23): }
13607:23): } else {
13608:23): $newltitools{$id}{$inner} = $domconfig{'ltitools'}{$id}{$inner};
13609:23): }
1(raebur 13610:1): }
14(raebu 13611:23): } else {
13612:23): $newltitools{$id} = $domconfig{'ltitools'}{$id};
1(raebur 13613:1): }
13614:1): }
14(raebu 13615:23): }
13616:23): }
13617:23): if ($toolserror) {
13618:23): $errors = '<li>'.$toolserror.'</li>';
13619:23): }
13620:23): if ((keys(%ltitoolschg) == 0) && (keys(%secchanges) == 0)) {
13621:23): $resulttext = &mt('No changes made.');
13622:23): if ($errors) {
13623:23): $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
13624:23): $errors.'</ul>';
13625:23): }
13626:23): return $resulttext;
13627:23): }
13628:23): my %ltitoolshash = (
13629:23): $action => { %newltitools }
13630:23): );
13631:23): if (keys(%secchanges)) {
13632:23): $ltitoolshash{'toolsec'} = \%newtoolsec;
13633:23): }
13634:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltitoolshash,$dom);
13635:23): if ($putresult eq 'ok') {
13636:23): my %keystore;
13637:23): if ($is_home) {
13638:23): my %toolsenchash = (
13639:23): $action => { %newtoolsenc }
13640:23): );
13641:23): &Apache::lonnet::put_dom('encconfig',\%toolsenchash,$dom,undef,1);
13642:23): my $cachetime = 24*60*60;
13643:23): &Apache::lonnet::do_cache_new('ltitoolsenc',$dom,\%newtoolsenc,$cachetime);
13644:23): &store_security($dom,'ltitools',\%secchanges,\%newkeyset,\%keystore,$lastactref);
13645:23): }
13646:23): $resulttext = &mt('Changes made:').'<ul>';
13647:23): if (keys(%secchanges) > 0) {
13648:23): $resulttext .= <i_security_results($dom,'ltitools',\%secchanges,\%newtoolsec,\%newkeyset,\%keystore);
13649:23): }
13650:23): if (keys(%ltitoolschg) > 0) {
13651:23): $resulttext .= $ltitoolsoutput;
13652:23): }
13653:23): my $cachetime = 24*60*60;
13654:23): &Apache::lonnet::do_cache_new('ltitools',$dom,\%newltitools,$cachetime);
13655:23): if (ref($lastactref) eq 'HASH') {
13656:23): $lastactref->{'ltitools'} = 1;
13657:23): }
13658:23): } else {
13659:23): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
13660:23): }
13661:23): if ($errors) {
13662:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
13663:23): $errors.'</ul></p>';
13664:23): }
13665:23): return $resulttext;
13666:23): }
13667:23):
13668:23): sub fetch_secrets {
13669:23): my ($dom,$context,$domconfig,$currsec,$secchanges,$newsec,$newkeyset) = @_;
13670:23): my %keyset;
13671:23): %{$currsec} = ();
13672:23): $newsec->{'private'}{'keys'} = [];
13673:23): $newsec->{'encrypt'} = {};
13674:23): $newsec->{'rules'} = {};
13675:23): if ($context eq 'ltisec') {
13676:23): $newsec->{'linkprot'} = {};
13677:23): }
13678:23): if (ref($domconfig->{$context}) eq 'HASH') {
13679:23): %{$currsec} = %{$domconfig->{$context}};
13680:23): if ($context eq 'ltisec') {
13681:23): if (ref($currsec->{'linkprot'}) eq 'HASH') {
13682:23): foreach my $id (keys(%{$currsec->{'linkprot'}})) {
13683:23): unless ($id =~ /^\d+$/) {
13684:23): delete($currsec->{'linkprot'}{$id});
13685:23): }
13686:23): }
1(raebur 13687:1): }
14(raebu 13688:23): }
13689:23): if (ref($currsec->{'private'}) eq 'HASH') {
13690:23): if (ref($currsec->{'private'}{'keys'}) eq 'ARRAY') {
13691:23): $newsec->{'private'}{'keys'} = $currsec->{'private'}{'keys'};
13692:23): map { $keyset{$_} = 1; } @{$currsec->{'private'}{'keys'}};
1(raebur 13693:1): }
14(raebu 13694:23): }
13695:23): }
13696:23): my @items= ('crs','dom');
13697:23): if ($context eq 'ltisec') {
13698:23): push(@items,'consumers');
13699:23): }
13700:23): foreach my $item (@items) {
13701:23): my $formelement;
13702:23): if (($context eq 'toolsec') || ($item eq 'consumers')) {
13703:23): $formelement = 'form.'.$context.'_'.$item;
13704:23): } else {
13705:23): $formelement = 'form.'.$context.'_'.$item.'linkprot';
13706:23): }
13707:23): if ($env{$formelement}) {
13708:23): $newsec->{'encrypt'}{$item} = 1;
13709:23): if (ref($currsec->{'encrypt'}) eq 'HASH') {
13710:23): unless ($currsec->{'encrypt'}{$item}) {
13711:23): $secchanges->{'encrypt'} = 1;
13712:23): }
1(raebur 13713:1): } else {
14(raebu 13714:23): $secchanges->{'encrypt'} = 1;
13715:23): }
13716:23): } elsif (ref($currsec->{'encrypt'}) eq 'HASH') {
13717:23): if ($currsec->{'encrypt'}{$item}) {
13718:23): $secchanges->{'encrypt'} = 1;
1(raebur 13719:1): }
14(raebu 13720:23): }
13721:23): }
13722:23): my $secrets;
13723:23): if ($context eq 'ltisec') {
13724:23): $secrets = 'ltisecrets';
13725:23): } else {
13726:23): $secrets = 'toolsecrets';
13727:23): }
13728:23): unless (exists($currsec->{'rules'})) {
13729:23): $currsec->{'rules'} = {};
13730:23): }
13731:23): &password_rule_changes($secrets,$newsec->{'rules'},$currsec->{'rules'},$secchanges);
13732:23):
13733:23): my @ids=&Apache::lonnet::current_machine_ids();
13734:23): my %servers = &Apache::lonnet::get_servers($dom,'library');
13735:23):
13736:23): foreach my $hostid (keys(%servers)) {
13737:23): if (($hostid ne '') && (grep(/^\Q$hostid\E$/,@ids))) {
13738:23): my $keyitem = 'form.'.$context.'_privkey_'.$hostid;
13739:23): if (exists($env{$keyitem})) {
13740:23): $env{$keyitem} =~ s/(`)/'/g;
13741:23): if ($keyset{$hostid}) {
13742:23): if ($env{'form.'.$context.'_changeprivkey_'.$hostid}) {
13743:23): if ($env{$keyitem} ne '') {
13744:23): $secchanges->{'private'} = 1;
13745:23): $newkeyset->{$hostid} = $env{$keyitem};
13746:23): }
1(raebur 13747:1): }
14(raebu 13748:23): } elsif ($env{$keyitem} ne '') {
13749:23): unless (grep(/^\Q$hostid\E$/,@{$newsec->{'private'}{'keys'}})) {
13750:23): push(@{$newsec->{'private'}{'keys'}},$hostid);
1(raebur 13751:1): }
14(raebu 13752:23): $secchanges->{'private'} = 1;
13753:23): $newkeyset->{$hostid} = $env{$keyitem};
1(raebur 13754:1): }
13755:1): }
14(raebu 13756:23): }
13757:23): }
13758:23): }
13759:23):
13760:23): sub store_security {
13761:23): my ($dom,$context,$secchanges,$newkeyset,$keystore) = @_;
13762:23): return unless ((ref($secchanges) eq 'HASH') && (ref($newkeyset) eq 'HASH') &&
13763:23): (ref($keystore) eq 'HASH'));
13764:23): if (keys(%{$secchanges})) {
13765:23): if ($secchanges->{'private'}) {
13766:23): my $who = &escape($env{'user.name'}.':'.$env{'user.domain'});
13767:23): foreach my $hostid (keys(%{$newkeyset})) {
13768:23): my $storehash = {
13769:23): key => $newkeyset->{$hostid},
13770:23): who => $env{'user.name'}.':'.$env{'user.domain'},
13771:23): };
13772:23): $keystore->{$hostid} = &Apache::lonnet::store_dom($storehash,$context,'private',
13773:23): $dom,$hostid);
13774:23): }
13775:23): }
13776:23): }
13777:23): }
13778:23):
13779:23): sub lti_security_results {
13780:23): my ($dom,$context,$secchanges,$newsec,$newkeyset,$keystore) = @_;
13781:23): my $output;
13782:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
13783:23): my $needs_update;
13784:23): foreach my $item (keys(%{$secchanges})) {
13785:23): if ($item eq 'encrypt') {
13786:23): $needs_update = 1;
13787:23): my %encrypted;
13788:23): if ($context eq 'lti') {
13789:23): %encrypted = (
13790:23): crs => {
13791:23): on => &mt('Encryption of stored link protection secrets defined in courses enabled'),
13792:23): off => &mt('Encryption of stored link protection secrets defined in courses disabled'),
13793:23): },
13794:23): dom => {
13795:23): on => &mt('Encryption of stored link protection secrets defined in domain enabled'),
13796:23): off => &mt('Encryption of stored link protection secrets defined in domain disabled'),
13797:23): },
13798:23): consumers => {
13799:23): on => &mt('Encryption of stored consumer secrets defined in domain enabled'),
13800:23): off => &mt('Encryption of stored consumer secrets defined in domain disabled'),
13801:23): },
13802:23): );
1(raebur 13803:1): } else {
14(raebu 13804:23): %encrypted = (
13805:23): crs => {
13806:23): on => &mt('Encryption of stored external tool secrets defined in courses enabled'),
13807:23): off => &mt('Encryption of stored external tool secrets defined in courses disabled'),
13808:23): },
13809:23): dom => {
13810:23): on => &mt('Encryption of stored external tool secrets defined in domain enabled'),
13811:23): off => &mt('Encryption of stored external tool secrets defined in domain disabled'),
13812:23): },
13813:23): );
1(raebur 13814:1): }
14(raebu 13815:23): my @types= ('crs','dom');
13816:23): if ($context eq 'lti') {
13817:23): foreach my $type (@types) {
13818:23): undef($domdefaults{'linkprotenc_'.$type});
1(raebur 13819:1): }
14(raebu 13820:23): push(@types,'consumers');
13821:23): undef($domdefaults{'ltienc_consumers'});
13822:23): } elsif ($context eq 'ltitools') {
13823:23): foreach my $type (@types) {
13824:23): undef($domdefaults{'toolenc_'.$type});
1(raebur 13825:1): }
13826:1): }
14(raebu 13827:23): foreach my $type (@types) {
13828:23): my $shown = $encrypted{$type}{'off'};
13829:23): if (ref($newsec->{$item}) eq 'HASH') {
13830:23): if ($newsec->{$item}{$type}) {
13831:23): if ($context eq 'lti') {
13832:23): if ($type eq 'consumers') {
13833:23): $domdefaults{'ltienc_consumers'} = 1;
13834:23): } else {
13835:23): $domdefaults{'linkprotenc_'.$type} = 1;
1(raebur 13836:1): }
14(raebu 13837:23): } elsif ($context eq 'ltitools') {
13838:23): $domdefaults{'toolenc_'.$type} = 1;
1(raebur 13839:1): }
14(raebu 13840:23): $shown = $encrypted{$type}{'on'};
1(raebur 13841:1): }
13842:1): }
14(raebu 13843:23): $output .= '<li>'.$shown.'</li>';
13844:23): }
13845:23): } elsif ($item eq 'rules') {
13846:23): my %titles = &Apache::lonlocal::texthash(
13847:23): min => 'Minimum password length',
13848:23): max => 'Maximum password length',
13849:23): chars => 'Required characters',
13850:23): );
13851:23): foreach my $rule ('min','max') {
13852:23): if ($newsec->{rules}{$rule} eq '') {
13853:23): if ($rule eq 'min') {
13854:23): $output .= '<li>'.&mt('[_1] not set.',$titles{$rule});
13855:23): ' '.&mt('Default of [_1] will be used',
13856:23): $Apache::lonnet::passwdmin).'</li>';
13857:23): } else {
13858:23): $output .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
13859:23): }
13860:23): } else {
13861:23): $output .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$newsec->{rules}{$rule}).'</li>';
13862:23): }
13863:23): }
13864:23): if (ref($newsec->{'rules'}{'chars'}) eq 'ARRAY') {
13865:23): if (@{$newsec->{'rules'}{'chars'}} > 0) {
13866:23): my %rulenames = &Apache::lonlocal::texthash(
13867:23): uc => 'At least one upper case letter',
13868:23): lc => 'At least one lower case letter',
13869:23): num => 'At least one number',
13870:23): spec => 'At least one non-alphanumeric',
13871:23): );
13872:23): my $needed = '<ul><li>'.
13873:23): join('</li><li>',map {$rulenames{$_} } @{$newsec->{'rules'}{'chars'}}).
13874:23): '</li></ul>';
13875:23): $output .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
13876:23): } else {
13877:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
13878:23): }
13879:23): } else {
13880:23): $output .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
1(raebur 13881:1): }
14(raebu 13882:23): } elsif ($item eq 'private') {
13883:23): $needs_update = 1;
13884:23): if ($context eq 'lti') {
13885:23): undef($domdefaults{'ltiprivhosts'});
13886:23): } elsif ($context eq 'ltitools') {
13887:23): undef($domdefaults{'toolprivhosts'});
13888:23): }
13889:23): if (keys(%{$newkeyset})) {
13890:23): my @privhosts;
13891:23): foreach my $hostid (sort(keys(%{$newkeyset}))) {
13892:23): if ($keystore->{$hostid} eq 'ok') {
13893:23): $output .= '<li>'.&mt('Encryption key for storage of shared secrets saved for [_1]',$hostid).'</li>';
13894:23): unless (grep(/^\Q$hostid\E$/,@privhosts)) {
13895:23): push(@privhosts,$hostid);
13896:23): }
13897:23): }
13898:23): }
13899:23): if (@privhosts) {
13900:23): if ($context eq 'lti') {
13901:23): $domdefaults{'ltiprivhosts'} = \@privhosts;
13902:23): } elsif ($context eq 'ltitools') {
13903:23): $domdefaults{'toolprivhosts'} = \@privhosts;
1(raebur 13904:1): }
13905:1): }
13906:1): }
14(raebu 13907:23): } elsif ($item eq 'linkprot') {
13908:23): next;
18(raebu 13909:24): } elsif ($item eq 'suggested') {
13910:24): if ((ref($secchanges->{'suggested'}) eq 'HASH') &&
13911:24): (ref($newsec->{'suggested'}) eq 'HASH')) {
13912:24): my $suggestions;
13913:24): foreach my $id (sort { $a <=> $b } keys(%{$secchanges->{'suggested'}})) {
13914:24): if (ref($newsec->{'suggested'}->{$id}) eq 'HASH') {
13915:24): my $name = $newsec->{'suggested'}->{$id}->{'name'};
13916:24): my $info = $newsec->{'suggested'}->{$id}->{'info'};
13917:24): $suggestions .= '<li>'.&mt('Launcher: [_1]',$name).'<br />'.
13918:24): &mt('Recommend: [_1]','<pre>'.$info.'</pre>').
13919:24): '</li>';
13920:24): } else {
13921:24): $suggestions .= '<li>'.&mt('Recommendations deleted for Launcher: [_1]',
13922:24): $newsec->{'suggested'}->{$id}).'</li>';
13923:24): }
13924:24): }
13925:24): if ($suggestions) {
13926:24): $output .= '<li>'.&mt('Hints in Courses for Link Protector Configuration').
13927:24): '<ul>'.$suggestions.'</ul>'.
13928:24): '</li>';
13929:24): }
13930:24): }
14(raebu 13931:23): }
13932:23): }
13933:23): if ($needs_update) {
13934:23): my $cachetime = 24*60*60;
13935:23): &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
13936:23): }
13937:23): return $output;
13938:23): }
13939:23):
13940:23): sub modify_lti {
13941:23): my ($r,$dom,$action,$lastactref,%domconfig) = @_;
13942:23): my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
13943:23): my ($newid,@allpos,%changes,%confhash,%ltienc,$errors,$resulttext);
13944:23): my (%posslti,%posslticrs,%posscrstype);
13945:23): my @courseroles = ('cc','in','ta','ep','st');
13946:23): my @ltiroles = qw(Learner Instructor ContentDeveloper TeachingAssistant Mentor Member Manager Administrator);
13947:23): my @lticourseroles = qw(Instructor TeachingAssistant Mentor Learner);
13948:23): my @coursetypes = ('official','unofficial','community','textbook','placement','lti');
13949:23): my %coursetypetitles = &Apache::lonlocal::texthash (
13950:23): official => 'Official',
13951:23): unofficial => 'Unofficial',
13952:23): community => 'Community',
13953:23): textbook => 'Textbook',
13954:23): placement => 'Placement Test',
13955:23): lti => 'LTI Provider',
13956:23): );
13957:23): my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
13958:23): my %lt = <i_names();
13959:23): map { $posslti{$_} = 1; } @ltiroles;
13960:23): map { $posslticrs{$_} = 1; } @lticourseroles;
13961:23): map { $posscrstype{$_} = 1; } @coursetypes;
13962:23):
13963:23): my %menutitles = <imenu_titles();
13964:23): my (%currltisec,%secchanges,%newltisec,%newltienc,%newkeyset);
13965:23):
13966:23): &fetch_secrets($dom,'ltisec',\%domconfig,\%currltisec,\%secchanges,\%newltisec,\%newkeyset);
13967:23):
13968:23): my (%linkprotchg,$linkprotoutput,$is_home);
13969:23): my $proterror = &Apache::courseprefs::process_linkprot($dom,'',$currltisec{'linkprot'},
13970:23): \%linkprotchg,'domain');
13971:23): my $home = &Apache::lonnet::domain($dom,'primary');
13972:23): unless (($home eq 'no_host') || ($home eq '')) {
13973:23): my @ids=&Apache::lonnet::current_machine_ids();
13974:23): foreach my $id (@ids) { if ($id eq $home) { $is_home=1; } }
13975:23): }
13976:23):
13977:23): if (keys(%linkprotchg)) {
13978:23): $secchanges{'linkprot'} = 1;
13979:23): my %oldlinkprot;
13980:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
13981:23): %oldlinkprot = %{$currltisec{'linkprot'}};
13982:23): }
13983:23): foreach my $id (keys(%linkprotchg)) {
13984:23): if (ref($linkprotchg{$id}) eq 'HASH') {
13985:23): foreach my $inner (keys(%{$linkprotchg{$id}})) {
13986:23): if (($inner eq 'secret') || ($inner eq 'key')) {
13987:23): if ($is_home) {
13988:23): $newltienc{$id}{$inner} = $linkprotchg{$id}{$inner};
13989:23): }
13990:23): }
13991:23): }
13992:23): } else {
13993:23): $newltisec{'linkprot'}{$id} = $linkprotchg{$id};
1(raebur 13994:1): }
14(raebu 13995:23): }
13996:23): $linkprotoutput = &Apache::courseprefs::store_linkprot($dom,'','domain',\%linkprotchg,\%oldlinkprot);
13997:23): if (keys(%linkprotchg)) {
13998:23): %{$newltisec{'linkprot'}} = %linkprotchg;
13999:23): }
14000:23): }
14001:23): if (ref($currltisec{'linkprot'}) eq 'HASH') {
18(raebu 14002:24): foreach my $id (keys(%{$currltisec{'linkprot'}})) {
14(raebu 14003:23): next if ($id !~ /^\d+$/);
14004:23): unless (exists($linkprotchg{$id})) {
14005:23): if (ref($currltisec{'linkprot'}{$id}) eq 'HASH') {
14006:23): foreach my $inner (keys(%{$currltisec{'linkprot'}{$id}})) {
14007:23): if (($inner eq 'secret') || ($inner eq 'key')) {
14008:23): if ($is_home) {
14009:23): $newltienc{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
14010:23): }
14011:23): } else {
14012:23): $newltisec{'linkprot'}{$id}{$inner} = $currltisec{'linkprot'}{$id}{$inner};
14013:23): }
14014:23): }
14015:23): } else {
14016:23): $newltisec{'linkprot'}{$id} = $currltisec{'linkprot'}{$id};
14017:23): }
1(raebur 14018:1): }
14(raebu 14019:23): }
14020:23): }
14021:23): if ($proterror) {
14022:23): $errors .= '<li>'.$proterror.'</li>';
14023:23): }
18(raebu 14024:24):
14025:24): my (%delsuggested,%suggids,@suggested);;
14026:24): if (ref($currltisec{'suggested'}) eq 'HASH') {
14027:24): my $maxnum = $env{'form.linkprot_suggested_maxnum'};
14028:24): my @todelete = &Apache::loncommon::get_env_multiple('form.linkprot_suggested_del');
14029:24): for (my $i=0; $i<$maxnum; $i++) {
14030:24): my $itemid = $env{'form.linkprot_suggested_id_'.$i};
14031:24): $itemid =~ s/\D+//g;
14032:24): if ($itemid) {
14033:24): if (ref($currltisec{'suggested'}->{$itemid}) eq 'HASH') {
14034:24): push(@suggested,$i);
14035:24): $suggids{$i} = $itemid;
14036:24): if ((@todelete > 0) && (grep(/^$i$/,@todelete))) {
14037:24): if (ref($currltisec{'suggested'}{$itemid}) eq 'HASH') {
14038:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14039:24): }
14040:24): } else {
14041:24): if ($env{'form.linkprot_suggested_name_'.$i} eq '') {
14042:24): $delsuggested{$itemid} = $currltisec{'suggested'}{$itemid}{'name'};
14043:24): } else {
14044:24): $env{'form.linkprot_suggested_name_'.$i} =~ s/(`)/'/g;
14045:24): $env{'form.linkprot_suggested_info_'.$i} =~ s/(`)/'/g;
14046:24): $newltisec{'suggested'}{$itemid}{'name'} = $env{'form.linkprot_suggested_name_'.$i};
14047:24): $newltisec{'suggested'}{$itemid}{'info'} = $env{'form.linkprot_suggested_info_'.$i};
14048:24): if (($currltisec{'suggested'}{$itemid}{'name'} ne $newltisec{'suggested'}{$itemid}{'name'}) ||
14049:24): ($currltisec{'suggested'}{$itemid}{'info'} ne $newltisec{'suggested'}{$itemid}{'info'})) {
14050:24): $secchanges{'suggested'}{$itemid} = 1;
14051:24): }
14052:24): }
14053:24): }
14054:24): }
14055:24): }
14056:24): }
14057:24): }
14058:24): foreach my $key (keys(%delsuggested)) {
14059:24): $newltisec{'suggested'}{$key} = $delsuggested{$key};
14060:24): $secchanges{'suggested'}{$key} = 1;
14061:24): }
14062:24): if (($env{'form.linkprot_suggested_add'}) &&
14063:24): ($env{'form.linkprot_suggested_name_add'} ne '')) {
14064:24): $env{'form.linkprot_suggested_name_add'} =~ s/(`)/'/g;
14065:24): $env{'form.linkprot_suggested_info_add'} =~ s/(`)/'/g;
14066:24): my ($newsuggid,$errormsg) = &get_lti_id($dom,$env{'form.linkprot_suggested_name_add'},'suggested');
14067:24): if ($newsuggid) {
14068:24): $newltisec{'suggested'}{$newsuggid}{'name'} = $env{'form.linkprot_suggested_name_add'};
14069:24): $newltisec{'suggested'}{$newsuggid}{'info'} = $env{'form.linkprot_suggested_info_add'};
14070:24): $secchanges{'suggested'}{$newsuggid} = 1;
14071:24): } else {
14072:24): my $error = &mt('Failed to acquire unique ID for new Link Protectors in Courses Suggestion');
14073:24): if ($errormsg) {
14074:24): $error .= ' ('.$errormsg.')';
14075:24): }
14076:24): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14077:24): }
14078:24): }
14(raebu 14079:23): my (@items,%deletions,%itemids);
14080:23): if ($env{'form.lti_add'}) {
14081:23): my $consumer = $env{'form.lti_consumer_add'};
14082:23): $consumer =~ s/(`)/'/g;
19(raebu 14083:24): ($newid,my $errormsg) = &get_lti_id($dom,$consumer,'lti');
14(raebu 14084:23): if ($newid) {
14085:23): $itemids{'add'} = $newid;
14086:23): push(@items,'add');
14087:23): $changes{$newid} = 1;
1(raebur 14088:1): } else {
14(raebu 14089:23): my $error = &mt('Failed to acquire unique ID for new LTI configuration');
18(raebu 14090:24): if ($errormsg) {
14091:24): $error .= ' ('.$errormsg.')';
14092:24): }
1(raebur 14093:1): $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
14094:1): }
14095:1): }
14096:1): if (ref($domconfig{$action}) eq 'HASH') {
14(raebu 14097:23): my @todelete = &Apache::loncommon::get_env_multiple('form.lti_del');
1(raebur 14098:1): if (@todelete) {
14099:1): map { $deletions{$_} = 1; } @todelete;
14100:1): }
14(raebu 14101:23): my $maxnum = $env{'form.lti_maxnum'};
14102:23): for (my $i=0; $i<$maxnum; $i++) {
14103:23): my $itemid = $env{'form.lti_id_'.$i};
1(raebur 14104:1): $itemid =~ s/\D+//g;
14105:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14106:1): if ($deletions{$itemid}) {
14(raebu 14107:23): $changes{$itemid} = $domconfig{$action}{$itemid}{'consumer'};
1(raebur 14108:1): } else {
14(raebu 14109:23): push(@items,$i);
14110:23): $itemids{$i} = $itemid;
14111:23): }
14112:23): }
14113:23): }
14114:23): }
14115:23): my (%keystore,$secstored);
14116:23): if ($is_home) {
14117:23): &store_security($dom,'lti',\%secchanges,\%newkeyset,\%keystore);
14118:23): }
14119:23):
14120:23): my ($cipher,$privnum);
14121:23): if ((@items > 0) && ($is_home)) {
14122:23): ($cipher,$privnum) = &get_priv_creds($dom,$home,$secchanges{'encrypt'},
14123:23): $newltisec{'encrypt'},$keystore{$home});
14124:23): }
14125:23): foreach my $idx (@items) {
14126:23): my $itemid = $itemids{$idx};
14127:23): next unless ($itemid);
14128:23): my %currlti;
14129:23): unless ($idx eq 'add') {
14130:23): if (ref($domconfig{$action}) eq 'HASH') {
14131:23): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14132:23): %currlti = %{$domconfig{$action}{$itemid}};
14133:23): }
14134:23): }
14135:23): }
14136:23): my $position = $env{'form.lti_pos_'.$itemid};
14137:23): $position =~ s/\D+//g;
14138:23): if ($position ne '') {
14139:23): $allpos[$position] = $itemid;
14140:23): }
14141:23): foreach my $item ('consumer','lifetime','requser','crsinc') {
14142:23): my $formitem = 'form.lti_'.$item.'_'.$idx;
14143:23): $env{$formitem} =~ s/(`)/'/g;
14144:23): if ($item eq 'lifetime') {
14145:23): $env{$formitem} =~ s/[^\d.]//g;
14146:23): }
14147:23): if ($env{$formitem} ne '') {
14148:23): $confhash{$itemid}{$item} = $env{$formitem};
14149:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14150:23): if ($currlti{$item} ne $confhash{$itemid}{$item}) {
14151:23): $changes{$itemid} = 1;
14152:23): }
14153:23): }
14154:23): }
14155:23): }
14156:23): if ($env{'form.lti_version_'.$idx} eq 'LTI-1p0') {
14157:23): $confhash{$itemid}{'version'} = $env{'form.lti_version_'.$idx};
14158:23): }
14159:23): if ($confhash{$itemid}{'requser'}) {
14160:23): if ($env{'form.lti_mapuser_'.$idx} eq 'sourcedid') {
14161:23): $confhash{$itemid}{'mapuser'} = 'lis_person_sourcedid';
14162:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'email') {
14163:23): $confhash{$itemid}{'mapuser'} = 'lis_person_contact_email_primary';
14164:23): } elsif ($env{'form.lti_mapuser_'.$idx} eq 'other') {
14165:23): my $mapuser = $env{'form.lti_customuser_'.$idx};
14166:23): $mapuser =~ s/(`)/'/g;
14167:23): $mapuser =~ s/^\s+|\s+$//g;
14168:23): $confhash{$itemid}{'mapuser'} = $mapuser;
14169:23): }
14170:23): my @possmakeuser = &Apache::loncommon::get_env_multiple('form.lti_makeuser_'.$idx);
14171:23): my @makeuser;
14172:23): foreach my $ltirole (sort(@possmakeuser)) {
14173:23): if ($posslti{$ltirole}) {
14174:23): push(@makeuser,$ltirole);
14175:23): }
14176:23): }
14177:23): $confhash{$itemid}{'makeuser'} = \@makeuser;
14178:23): if (@makeuser) {
14179:23): my $lcauth = $env{'form.lti_lcauth_'.$idx};
14180:23): if ($lcauth =~ /^(internal|krb4|krb5|localauth)$/) {
14181:23): $confhash{$itemid}{'lcauth'} = $lcauth;
14182:23): if ($lcauth ne 'internal') {
14183:23): my $lcauthparm = $env{'form.lti_lcauthparm_'.$idx};
14184:23): $lcauthparm =~ s/^(\s+|\s+)$//g;
14185:23): $lcauthparm =~ s/`//g;
14186:23): if ($lcauthparm ne '') {
14187:23): $confhash{$itemid}{'lcauthparm'} = $lcauthparm;
1(raebur 14188:1): }
14189:1): }
14(raebu 14190:23): } else {
14191:23): $confhash{$itemid}{'lcauth'} = 'lti';
14192:23): }
14193:23): }
14194:23): my @possinstdata = &Apache::loncommon::get_env_multiple('form.lti_instdata_'.$idx);
14195:23): if (@possinstdata) {
14196:23): foreach my $field (@possinstdata) {
14197:23): if (exists($fieldtitles{$field})) {
14198:23): push(@{$confhash{$itemid}{'instdata'}});
14199:23): }
14200:23): }
14201:23): }
14202:23): if ($env{'form.lti_callback_'.$idx}) {
14203:23): if ($env{'form.lti_callbackparam_'.$idx}) {
14204:23): my $callback = $env{'form.lti_callbackparam_'.$idx};
14205:23): $callback =~ s/^\s+|\s+$//g;
14206:23): $confhash{$itemid}{'callback'} = $callback;
14207:23): }
14208:23): }
14209:23): foreach my $field ('topmenu','inlinemenu') {
14210:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14211:23): $confhash{$itemid}{$field} = 1;
14212:23): }
14213:23): }
14214:23): if ($env{'form.lti_topmenu_'.$idx} || $env{'form.lti_inlinemenu_'.$idx}) {
14215:23): $confhash{$itemid}{lcmenu} = [];
14216:23): my @possmenu = &Apache::loncommon::get_env_multiple('form.lti_menuitem_'.$idx);
14217:23): foreach my $field (@possmenu) {
14218:23): if (exists($menutitles{$field})) {
14219:23): if ($field eq 'grades') {
14220:23): next unless ($env{'form.lti_inlinemenu_'.$idx});
1(raebur 14221:1): }
14(raebu 14222:23): push(@{$confhash{$itemid}{lcmenu}},$field);
14223:23): }
14224:23): }
14225:23): }
14226:23): if ($confhash{$itemid}{'crsinc'}) {
14227:23): if (($env{'form.lti_mapcrs_'.$idx} eq 'course_offering_sourcedid') ||
14228:23): ($env{'form.lti_mapcrs_'.$idx} eq 'context_id')) {
14229:23): $confhash{$itemid}{'mapcrs'} = $env{'form.lti_mapcrs_'.$idx};
14230:23): } elsif ($env{'form.lti_mapcrs_'.$idx} eq 'other') {
14231:23): my $mapcrs = $env{'form.lti_mapcrsfield_'.$idx};
14232:23): $mapcrs =~ s/(`)/'/g;
14233:23): $mapcrs =~ s/^\s+|\s+$//g;
14234:23): $confhash{$itemid}{'mapcrs'} = $mapcrs;
14235:23): }
14236:23): my @posstypes = &Apache::loncommon::get_env_multiple('form.lti_mapcrstype_'.$idx);
14237:23): my @crstypes;
14238:23): foreach my $type (sort(@posstypes)) {
14239:23): if ($posscrstype{$type}) {
14240:23): push(@crstypes,$type);
14241:23): }
14242:23): }
14243:23): $confhash{$itemid}{'mapcrstype'} = \@crstypes;
14244:23): if ($env{'form.lti_storecrs_'.$idx}) {
14245:23): $confhash{$itemid}{'storecrs'} = 1;
14246:23): }
14247:23): if ($env{'form.lti_makecrs_'.$idx}) {
14248:23): $confhash{$itemid}{'makecrs'} = 1;
14249:23): }
14250:23): foreach my $ltirole (@lticourseroles) {
14251:23): my $possrole = $env{'form.lti_maprole_'.$ltirole.'_'.$idx};
14252:23): if (grep(/^\Q$possrole\E$/,@courseroles)) {
14253:23): $confhash{$itemid}{'maproles'}{$ltirole} = $possrole;
1(raebur 14254:1): }
14(raebu 14255:23): }
14256:23): my @possenroll = &Apache::loncommon::get_env_multiple('form.lti_selfenroll_'.$idx);
14257:23): my @selfenroll;
14258:23): foreach my $type (sort(@possenroll)) {
14259:23): if ($posslticrs{$type}) {
14260:23): push(@selfenroll,$type);
14261:23): }
14262:23): }
14263:23): $confhash{$itemid}{'selfenroll'} = \@selfenroll;
14264:23): if ($env{'form.lti_crssec_'.$idx}) {
14265:23): if ($env{'form.lti_crssecsrc_'.$idx} eq 'course_section_sourcedid') {
14266:23): $confhash{$itemid}{'section'} = $env{'form.lti_crssecsrc_'.$idx};
14267:23): } elsif ($env{'form.lti_crssecsrc_'.$idx} eq 'other') {
14268:23): my $section = $env{'form.lti_customsection_'.$idx};
14269:23): $section =~ s/(`)/'/g;
14270:23): $section =~ s/^\s+|\s+$//g;
14271:23): if ($section ne '') {
14272:23): $confhash{$itemid}{'section'} = $section;
14273:23): }
1(raebur 14274:1): }
14(raebu 14275:23): }
14276:23): foreach my $field ('passback','roster') {
14277:23): if ($env{'form.lti_'.$field.'_'.$idx}) {
14278:23): $confhash{$itemid}{$field} = 1;
1(raebur 14279:1): }
14(raebu 14280:23): }
14281:23): if ($env{'form.lti_passback_'.$idx}) {
14282:23): if ($env{'form.lti_passbackformat_'.$idx} eq '1.0') {
14283:23): $confhash{$itemid}{'passbackformat'} = '1.0';
1(raebur 14284:1): } else {
14(raebu 14285:23): $confhash{$itemid}{'passbackformat'} = '1.1';
1(raebur 14286:1): }
14(raebu 14287:23): }
14288:23): }
14289:23): unless (($idx eq 'add') || ($changes{$itemid})) {
14290:23): if ($confhash{$itemid}{'crsinc'}) {
14291:23): foreach my $field ('mapcrs','storecrs','makecrs','section','passback','roster') {
14292:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
1(raebur 14293:1): $changes{$itemid} = 1;
14294:1): }
14295:1): }
14(raebu 14296:23): unless ($changes{$itemid}) {
14297:23): if ($currlti{'passback'} eq $confhash{$itemid}{'passback'}) {
14298:23): if ($currlti{'passbackformat'} ne $confhash{$itemid}{'passbackformat'}) {
1(raebur 14299:1): $changes{$itemid} = 1;
14300:1): }
14301:1): }
14302:1): }
14(raebu 14303:23): foreach my $field ('mapcrstype','selfenroll') {
14304:23): unless ($changes{$itemid}) {
14305:23): if (ref($currlti{$field}) eq 'ARRAY') {
14306:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14307:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14308:23): $confhash{$itemid}{$field});
14309:23): if (@diffs) {
14310:23): $changes{$itemid} = 1;
14311:23): }
14312:23): } elsif (@{$currlti{$field}} > 0) {
1(raebur 14313:1): $changes{$itemid} = 1;
14314:1): }
14(raebu 14315:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14316:23): if (@{$confhash{$itemid}{$field}} > 0) {
1(raebur 14317:1): $changes{$itemid} = 1;
14318:1): }
14319:1): }
14320:1): }
14321:1): }
14(raebu 14322:23): unless ($changes{$itemid}) {
14323:23): if (ref($currlti{'maproles'}) eq 'HASH') {
14324:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14325:23): foreach my $ltirole (keys(%{$currlti{'maproles'}})) {
14326:23): if ($currlti{'maproles'}{$ltirole} ne
14327:23): $confhash{$itemid}{'maproles'}{$ltirole}) {
14328:23): $changes{$itemid} = 1;
14329:23): last;
1(raebur 14330:1): }
14(raebu 14331:23): }
14332:23): unless ($changes{$itemid}) {
14333:23): foreach my $ltirole (keys(%{$confhash{$itemid}{'maproles'}})) {
14334:23): if ($confhash{$itemid}{'maproles'}{$ltirole} ne
14335:23): $currlti{'maproles'}{$ltirole}) {
1(raebur 14336:1): $changes{$itemid} = 1;
14(raebu 14337:23): last;
1(raebur 14338:1): }
14339:1): }
14340:1): }
14(raebu 14341:23): } elsif (keys(%{$currlti{'maproles'}}) > 0) {
14342:23): $changes{$itemid} = 1;
14343:23): }
14344:23): } elsif (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14345:23): unless ($changes{$itemid}) {
14346:23): if (keys(%{$confhash{$itemid}{'maproles'}}) > 0) {
1(raebur 14347:1): $changes{$itemid} = 1;
14348:1): }
14349:1): }
14350:1): }
14351:1): }
14(raebu 14352:23): }
14353:23): unless ($changes{$itemid}) {
14354:23): foreach my $field ('mapuser','lcauth','lcauthparm','topmenu','inlinemenu','callback') {
14355:23): if ($currlti{$field} ne $confhash{$itemid}{$field}) {
14356:23): $changes{$itemid} = 1;
14357:23): }
14358:23): }
14359:23): unless ($changes{$itemid}) {
14360:23): foreach my $field ('makeuser','lcmenu') {
14361:23): if (ref($currlti{$field}) eq 'ARRAY') {
14362:23): if (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14363:23): my @diffs = &Apache::loncommon::compare_arrays($currlti{$field},
14364:23): $confhash{$itemid}{$field});
14365:23): if (@diffs) {
14366:23): $changes{$itemid} = 1;
14367:23): }
14368:23): } elsif (@{$currlti{$field}} > 0) {
14369:23): $changes{$itemid} = 1;
14370:23): }
14371:23): } elsif (ref($confhash{$itemid}{$field}) eq 'ARRAY') {
14372:23): if (@{$confhash{$itemid}{$field}} > 0) {
14373:23): $changes{$itemid} = 1;
14374:23): }
1(raebur 14375:1): }
14376:1): }
14377:1): }
14378:1): }
14(raebu 14379:23): }
14380:23): }
14381:23): if ($is_home) {
14382:23): my $keyitem = 'form.lti_key_'.$idx;
14383:23): $env{$keyitem} =~ s/(`)/'/g;
14384:23): if ($env{$keyitem} ne '') {
14385:23): $ltienc{$itemid}{'key'} = $env{$keyitem};
14386:23): unless ($changes{$itemid}) {
14387:23): if ($currlti{'key'} ne $env{$keyitem}) {
1(raebur 14388:1): $changes{$itemid} = 1;
14389:1): }
14(raebu 14390:23): }
14391:23): }
14392:23): my $secretitem = 'form.lti_secret_'.$idx;
14393:23): $env{$secretitem} =~ s/(`)/'/g;
14394:23): if ($currlti{'usable'}) {
14395:23): if ($env{'form.lti_changesecret_'.$idx}) {
14396:23): if ($env{$secretitem} ne '') {
14397:23): if ($privnum && $cipher) {
14398:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14399:23): $confhash{$itemid}{'cipher'} = $privnum;
14400:23): } else {
14401:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14402:23): }
1(raebur 14403:1): $changes{$itemid} = 1;
14404:1): }
14(raebu 14405:23): } else {
14406:23): $ltienc{$itemid}{'secret'} = $currlti{'secret'};
14407:23): $confhash{$itemid}{'cipher'} = $currlti{'cipher'};
1(raebur 14408:1): }
14(raebu 14409:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14410:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'secret'} ne '')) {
14411:23): $confhash{$itemid}{'usable'} = 1;
14412:23): }
1(raebur 14413:1): }
14(raebu 14414:23): } elsif ($env{$secretitem} ne '') {
14415:23): if ($privnum && $cipher) {
14416:23): $ltienc{$itemid}{'secret'} = $cipher->encrypt_hex($env{$secretitem});
14417:23): $confhash{$itemid}{'cipher'} = $privnum;
14418:23): } else {
14419:23): $ltienc{$itemid}{'secret'} = $env{$secretitem};
14420:23): }
14421:23): if (ref($ltienc{$itemid}) eq 'HASH') {
14422:23): if (($ltienc{$itemid}{'key'} ne '') && ($ltienc{$itemid}{'key'} ne '')) {
14423:23): $confhash{$itemid}{'usable'} = 1;
1(raebur 14424:1): }
14425:1): }
14(raebu 14426:23): $changes{$itemid} = 1;
14427:23): }
14428:23): }
14429:23): unless ($changes{$itemid}) {
14430:23): foreach my $key (keys(%currlti)) {
14431:23): if (ref($currlti{$key}) eq 'HASH') {
14432:23): if (ref($confhash{$itemid}{$key}) eq 'HASH') {
14433:23): foreach my $innerkey (keys(%{$currlti{$key}})) {
14434:23): unless (exists($confhash{$itemid}{$key}{$innerkey})) {
1(raebur 14435:1): $changes{$itemid} = 1;
14(raebu 14436:23): last;
1(raebur 14437:1): }
14438:1): }
14(raebu 14439:23): } elsif (keys(%{$currlti{$key}}) > 0) {
14440:23): $changes{$itemid} = 1;
1(raebur 14441:1): }
14442:1): }
14(raebu 14443:23): last if ($changes{$itemid});
1(raebur 14444:1): }
14445:1): }
14446:1): }
14447:1): if (@allpos > 0) {
14448:1): my $idx = 0;
14449:1): foreach my $itemid (@allpos) {
14450:1): if ($itemid ne '') {
14451:1): $confhash{$itemid}{'order'} = $idx;
14452:1): if (ref($domconfig{$action}) eq 'HASH') {
14453:1): if (ref($domconfig{$action}{$itemid}) eq 'HASH') {
14454:1): if ($domconfig{$action}{$itemid}{'order'} ne $idx) {
14455:1): $changes{$itemid} = 1;
14456:1): }
14457:1): }
14458:1): }
14459:1): $idx ++;
14460:1): }
14461:1): }
14462:1): }
14(raebu 14463:23):
14464:23): if ((keys(%changes) == 0) && (keys(%secchanges) == 0)) {
14465:23): return &mt('No changes made.');
14466:23): }
14467:23):
14468:23): my %ltihash = (
14469:23): $action => { %confhash }
14470:23): );
14471:23): my %ltienchash;
14472:23):
14473:23): if ($is_home) {
14474:23): %ltienchash = (
14475:23): $action => { %ltienc }
14476:23): );
14477:23): }
14478:23): if (keys(%secchanges)) {
14479:23): $ltihash{'ltisec'} = \%newltisec;
14480:23): if ($secchanges{'linkprot'}) {
14481:23): if ($is_home) {
14482:23): $ltienchash{'linkprot'} = \%newltienc;
14483:23): }
14484:23): }
14485:23): }
14486:23): my $putresult = &Apache::lonnet::put_dom('configuration',\%ltihash,$dom);
1(raebur 14487:1): if ($putresult eq 'ok') {
14(raebu 14488:23): if (keys(%ltienchash)) {
14489:23): &Apache::lonnet::put_dom('encconfig',\%ltienchash,$dom,undef,1);
14490:23): }
14491:23): $resulttext = &mt('Changes made:').'<ul>';
14492:23): if (keys(%secchanges) > 0) {
14493:23): $resulttext .= <i_security_results($dom,'lti',\%secchanges,\%newltisec,\%newkeyset,\%keystore);
14494:23): if (exists($secchanges{'linkprot'})) {
14495:23): $resulttext .= $linkprotoutput;
14496:23): }
14497:23): }
1(raebur 14498:1): if (keys(%changes) > 0) {
14499:1): my $cachetime = 24*60*60;
14(raebu 14500:23): &Apache::lonnet::do_cache_new('lti',$dom,\%confhash,$cachetime);
1(raebur 14501:1): if (ref($lastactref) eq 'HASH') {
14(raebu 14502:23): $lastactref->{'lti'} = 1;
1(raebur 14503:1): }
14504:1): my %bynum;
14505:1): foreach my $itemid (sort(keys(%changes))) {
14(raebu 14506:23): if (ref($confhash{$itemid}) eq 'HASH') {
14507:23): my $position = $confhash{$itemid}{'order'};
14508:23): $bynum{$position} = $itemid;
14509:23): }
1(raebur 14510:1): }
14511:1): foreach my $pos (sort { $a <=> $b } keys(%bynum)) {
14512:1): my $itemid = $bynum{$pos};
14(raebu 14513:23): if (ref($confhash{$itemid}) eq 'HASH') {
14514:23): $resulttext .= '<li><b>'.$confhash{$itemid}{'consumer'}.'</b><ul>';
1(raebur 14515:1): my $position = $pos + 1;
14516:1): $resulttext .= '<li>'.&mt('Order: [_1]',$position).'</li>';
14(raebu 14517:23): foreach my $item ('version','lifetime') {
1(raebur 14518:1): if ($confhash{$itemid}{$item} ne '') {
14519:1): $resulttext .= '<li>'.$lt{$item}.': '.$confhash{$itemid}{$item}.'</li>';
14520:1): }
14521:1): }
14(raebu 14522:23): if ($ltienc{$itemid}{'key'} ne '') {
14523:23): $resulttext .= '<li>'.$lt{'key'}.': '.$ltienc{$itemid}{'key'}.'</li>';
14524:23): }
14525:23): if ($ltienc{$itemid}{'secret'} ne '') {
14526:23): $resulttext .= '<li>'.$lt{'secret'}.': ['.&mt('not shown').']</li>';
1(raebur 14527:1): }
14(raebu 14528:23): if ($confhash{$itemid}{'requser'}) {
14529:23): if ($confhash{$itemid}{'callback'}) {
14530:23): $resulttext .= '<li>'.&mt('Callback setting').': '.$confhash{$itemid}{'callback'}.'</li>';
14531:23): } else {
14532:23): $resulttext .= '<li>'.&mt('Callback to logout LON-CAPA on log out from Consumer').'</li>';
14533:23): }
14534:23): if ($confhash{$itemid}{'mapuser'}) {
14535:23): my $shownmapuser;
14536:23): if ($confhash{$itemid}{'mapuser'} eq 'lis_person_sourcedid') {
14537:23): $shownmapuser = $lt{'sourcedid'}.' (lis_person_sourcedid)';
14538:23): } elsif ($confhash{$itemid}{'mapuser'} eq 'lis_person_contact_email_primary') {
14539:23): $shownmapuser = $lt{'email'}.' (lis_person_contact_email_primary)';
14540:23): } else {
14541:23): $shownmapuser = &mt('Other').' ('.$confhash{$itemid}{'mapuser'}.')';
14542:23): }
14543:23): $resulttext .= '<li>'.&mt('LON-CAPA username').': '.$shownmapuser.'</li>';
14544:23): }
14545:23): if (ref($confhash{$itemid}{'makeuser'}) eq 'ARRAY') {
14546:23): if (@{$confhash{$itemid}{'makeuser'}} > 0) {
14547:23): $resulttext .= '<li>'.&mt('Following roles may create user accounts: [_1]',
14548:23): join(', ',@{$confhash{$itemid}{'makeuser'}})).'<br />';
14549:23): if ($confhash{$itemid}{'lcauth'} eq 'lti') {
14550:23): $resulttext .= &mt('New users will only be able to authenticate via LTI').'</li>';
14551:23): } else {
14552:23): $resulttext .= &mt('New users will be assigned LON-CAPA authentication: [_1]',
14553:23): $confhash{$itemid}{'lcauth'});
14554:23): if ($confhash{$itemid}{'lcauth'} eq 'internal') {
14555:23): $resulttext .= '; '.&mt('a randomly generated password will be created');
14556:23): } elsif ($confhash{$itemid}{'lcauth'} eq 'localauth') {
14557:23): if ($confhash{$itemid}{'lcauthparm'} ne '') {
14558:23): $resulttext .= ' '.&mt('with argument: [_1]',$confhash{$itemid}{'lcauthparm'});
14559:23): }
14560:23): } else {
14561:23): $resulttext .= '; '.&mt('Kerberos domain: [_1]',$confhash{$itemid}{'lcauthparm'});
14562:23): }
14563:23): }
14564:23): $resulttext .= '</li>';
14565:23): } else {
14566:23): $resulttext .= '<li>'.&mt('User account creation not permitted.').'</li>';
1(raebur 14567:1): }
14568:1): }
14(raebu 14569:23): if (ref($confhash{$itemid}{'instdata'}) eq 'ARRAY') {
14570:23): if (@{$confhash{$itemid}{'instdata'}} > 0) {
14571:23): $resulttext .= '<li>'.&mt('Institutional data will be used when creating a new user for: [_1]',
14572:23): join(', ',map { $fieldtitles{$_}; } @{$confhash{$itemid}{'instdata'}})).'</li>';
14573:23): } else {
14574:23): $resulttext .= '<li>'.&mt('No institutional data used when creating a new user.').'</li>';
1(raebur 14575:1): }
14576:1): }
14(raebu 14577:23): foreach my $item ('topmenu','inlinemenu') {
14578:23): $resulttext .= '<li>'.$lt{$item}.': ';
14579:23): if ($confhash{$itemid}{$item}) {
14580:23): $resulttext .= &mt('Yes');
14581:23): } else {
14582:23): $resulttext .= &mt('No');
1(raebur 14583:1): }
14(raebu 14584:23): $resulttext .= '</li>';
1(raebur 14585:1): }
14(raebu 14586:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14587:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14588:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14589:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14590:23): } else {
14591:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
1(raebur 14592:1): }
14593:1): }
14(raebu 14594:23): if ($confhash{$itemid}{'crsinc'}) {
14595:23): if (ref($confhash{$itemid}{'maproles'}) eq 'HASH') {
14596:23): my $rolemaps;
14597:23): foreach my $role (@ltiroles) {
14598:23): if ($confhash{$itemid}{'maproles'}{$role}) {
14599:23): $rolemaps .= (' 'x2).$role.'='.
14600:23): &Apache::lonnet::plaintext($confhash{$itemid}{'maproles'}{$role},
14601:23): 'Course').',';
14602:23): }
14603:23): }
14604:23): if ($rolemaps) {
14605:23): $rolemaps =~ s/,$//;
14606:23): $resulttext .= '<li>'.&mt('Role mapping:').$rolemaps.'</li>';
14607:23): }
14608:23): }
14609:23): if ($confhash{$itemid}{'mapcrs'}) {
14610:23): $resulttext .= '<li>'.&mt('Unique course identifier').': '.$confhash{$itemid}{'mapcrs'}.'</li>';
14611:23): }
14612:23): if (ref($confhash{$itemid}{'mapcrstype'}) eq 'ARRAY') {
14613:23): if (@{$confhash{$itemid}{'mapcrstype'}} > 0) {
14614:23): $resulttext .= '<li>'.&mt('Mapping for the following LON-CAPA course types: [_1]',
14615:23): join(', ',map { $coursetypetitles{$_}; } @coursetypes)).
14616:23): '</li>';
1(raebur 14617:1): } else {
14(raebu 14618:23): $resulttext .= '<li>'.&mt('No mapping to LON-CAPA courses').'</li>';
1(raebur 14619:1): }
14620:1): }
14(raebu 14621:23): if ($confhash{$itemid}{'storecrs'}) {
14622:23): $resulttext .= '<li>'.&mt('Store mapping of course identifier to LON-CAPA CourseID').': '.$confhash{$itemid}{'storecrs'}.'</li>';
1(raebur 14623:1): }
14(raebu 14624:23): if ($confhash{$itemid}{'makecrs'}) {
14625:23): $resulttext .= '<li>'.&mt('Instructor may create course (if absent).').'</li>';
14626:23): } else {
14627:23): $resulttext .= '<li>'.&mt('Instructor may not create course (if absent).').'</li>';
14628:23): }
14629:23): if (ref($confhash{$itemid}{'selfenroll'}) eq 'ARRAY') {
14630:23): if (@{$confhash{$itemid}{'selfenroll'}} > 0) {
14631:23): $resulttext .= '<li>'.&mt('Self-enrollment for following roles: [_1]',
14632:23): join(', ',@{$confhash{$itemid}{'selfenroll'}})).
14633:23): '</li>';
14634:23): } else {
14635:23): $resulttext .= '<li>'.&mt('Self-enrollment not permitted').'</li>';
14636:23): }
14637:23): }
14638:23): if ($confhash{$itemid}{'section'}) {
14639:23): if ($confhash{$itemid}{'section'} eq 'course_section_sourcedid') {
14640:23): $resulttext .= '<li>'.&mt('User section from standard field:').
14641:23): ' (course_section_sourcedid)'.'</li>';
14642:23): } else {
14643:23): $resulttext .= '<li>'.&mt('User section from:').' '.
14644:23): $confhash{$itemid}{'section'}.'</li>';
14645:23): }
14646:23): } else {
14647:23): $resulttext .= '<li>'.&mt('No section assignment').'</li>';
14648:23): }
14649:23): foreach my $item ('passback','roster','topmenu','inlinemenu') {
14650:23): $resulttext .= '<li>'.$lt{$item}.': ';
14651:23): if ($confhash{$itemid}{$item}) {
14652:23): $resulttext .= &mt('Yes');
14653:23): if ($item eq 'passback') {
14654:23): if ($confhash{$itemid}{'passbackformat'} eq '1.0') {
14655:23): $resulttext .= ' ('.&mt('Outcomes Extension (1.0)').')';
14656:23): } elsif ($confhash{$itemid}{'passbackformat'} eq '1.1') {
14657:23): $resulttext .= ' ('.&mt('Outcomes Service (1.1)').')';
14658:23): }
14659:23): }
14660:23): } else {
14661:23): $resulttext .= &mt('No');
14662:23): }
14663:23): $resulttext .= '</li>';
14664:23): }
14665:23): if (ref($confhash{$itemid}{'lcmenu'}) eq 'ARRAY') {
14666:23): if (@{$confhash{$itemid}{'lcmenu'}} > 0) {
14667:23): $resulttext .= '<li>'.&mt('Menu items:').' '.
14668:23): join(', ', map { $menutitles{$_}; } (@{$confhash{$itemid}{'lcmenu'}})).'</li>';
14669:23): } else {
14670:23): $resulttext .= '<li>'.&mt('No menu items displayed in header or online menu').'</li>';
14671:23): }
1(raebur 14672:1): }
14673:1): }
14674:1): }
14675:1): $resulttext .= '</ul></li>';
14676:1): }
14677:1): }
14(raebu 14678:23): if (keys(%deletions)) {
14679:23): foreach my $itemid (sort { $a <=> $b } keys(%deletions)) {
14680:23): $resulttext .= '<li>'.&mt('Deleted: [_1]',$changes{$itemid}).'</li>';
14681:23): }
14682:23): }
14683:23): }
14684:23): $resulttext .= '</ul>';
14685:23): if (ref($lastactref) eq 'HASH') {
18(raebu 14686:24): if (($secchanges{'encrypt'}) || ($secchanges{'private'}) || (exists($secchanges{'suggested'}))) {
14687:24): &Apache::lonnet::get_domain_defaults($dom,1);
14(raebu 14688:23): $lastactref->{'domdefaults'} = 1;
14689:23): }
1(raebur 14690:1): }
14691:1): } else {
14692:1): $errors .= '<li><span class="LC_error">'.&mt('Failed to save changes').'</span></li>';
14693:1): }
14694:1): if ($errors) {
14695:1): $resulttext .= &mt('The following errors occurred: ').'<ul>'.
14696:1): $errors.'</ul>';
14697:1): }
14698:1): return $resulttext;
14699:1): }
14700:1):
14(raebu 14701:23): sub get_priv_creds {
14702:23): my ($dom,$home,$encchg,$encrypt,$storedsec) = @_;
14703:23): my ($needenc,$cipher,$privnum);
14704:23): my %domdefs = &Apache::lonnet::get_domain_defaults($dom);
14705:23): if (($encchg) && (ref($encrypt) eq 'HASH')) {
14706:23): $needenc = $encrypt->{'consumers'}
14707:23): } else {
14708:23): $needenc = $domdefs{'ltienc_consumers'};
14709:23): }
14710:23): if ($needenc) {
14711:23): if (($storedsec eq 'ok') || ((ref($domdefs{'ltiprivhosts'}) eq 'ARRAY') &&
14712:23): (grep(/^\Q$home\E$/,@{$domdefs{'ltiprivhosts'}})))) {
14713:23): my %privhash = &Apache::lonnet::restore_dom('lti','private',$dom,$home,1);
14714:23): my $privkey = $privhash{'key'};
14715:23): $privnum = $privhash{'version'};
14716:23): if (($privnum) && ($privkey ne '')) {
14717:23): $cipher = Crypt::CBC->new({'key' => $privkey,
14718:23): 'cipher' => 'DES'});
1(raebur 14719:1): }
14720:1): }
14721:1): }
14(raebu 14722:23): return ($cipher,$privnum);
1(raebur 14723:1): }
14724:1):
14(raebu 14725:23): sub get_lti_id {
18(raebu 14726:24): my ($domain,$consumer,$dbname) = @_;
14727:24): unless (($dbname eq 'lti') || ($dbname eq 'suggested')) {
14728:24): return ('','invalid db');
14729:24): }
14730:24): # get lock on db
1(raebur 14731:1): my $lockhash = {
14732:1): lock => $env{'user.name'}.
14733:1): ':'.$env{'user.domain'},
14734:1): };
14735:1): my $tries = 0;
18(raebu 14736:24): my $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14737:1): my ($id,$error);
14738:1):
14739:1): while (($gotlock ne 'ok') && ($tries<10)) {
14740:1): $tries ++;
14741:1): sleep (0.1);
18(raebu 14742:24): $gotlock = &Apache::lonnet::newput_dom($dbname,$lockhash,$domain);
1(raebur 14743:1): }
14744:1): if ($gotlock eq 'ok') {
18(raebu 14745:24): my %currids = &Apache::lonnet::dump_dom($dbname,$domain);
1(raebur 14746:1): if ($currids{'lock'}) {
14747:1): delete($currids{'lock'});
14748:1): if (keys(%currids)) {
14749:1): my @curr = sort { $a <=> $b } keys(%currids);
14750:1): if ($curr[-1] =~ /^\d+$/) {
14751:1): $id = 1 + $curr[-1];
14752:1): }
14753:1): } else {
14754:1): $id = 1;
14755:1): }
14756:1): if ($id) {
18(raebu 14757:24): unless (&Apache::lonnet::newput_dom($dbname,{ $id => $consumer },$domain) eq 'ok') {
1(raebur 14758:1): $error = 'nostore';
14759:1): }
14760:1): } else {
14761:1): $error = 'nonumber';
14762:1): }
14763:1): }
18(raebu 14764:24): my $dellockoutcome = &Apache::lonnet::del_dom($dbname,['lock'],$domain);
1(raebur 14765:1): } else {
14766:1): $error = 'nolock';
14767:1): }
14768:1): return ($id,$error);
14769:1): }
14770:1):
1.3 raeburn 14771: sub modify_autoenroll {
1.160.6.24 raeburn 14772: my ($dom,$lastactref,%domconfig) = @_;
1.1 raeburn 14773: my ($resulttext,%changes);
14774: my %currautoenroll;
14775: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
14776: foreach my $key (keys(%{$domconfig{'autoenroll'}})) {
14777: $currautoenroll{$key} = $domconfig{'autoenroll'}{$key};
14778: }
14779: }
14780: my $autorun = &Apache::lonnet::auto_run(undef,$dom),
14781: my %title = ( run => 'Auto-enrollment active',
1.129 raeburn 14782: sender => 'Sender for notification messages',
1.160.6.68 raeburn 14783: coowners => 'Automatic assignment of co-ownership to instructors of record (institutional data)',
1.160.6.116 raeburn 14784: autofailsafe => 'Failsafe for no drops if institutional data missing for a section');
1.1 raeburn 14785: my @offon = ('off','on');
1.17 raeburn 14786: my $sender_uname = $env{'form.sender_uname'};
14787: my $sender_domain = $env{'form.sender_domain'};
14788: if ($sender_domain eq '') {
14789: $sender_uname = '';
14790: } elsif ($sender_uname eq '') {
14791: $sender_domain = '';
14792: }
1.129 raeburn 14793: my $coowners = $env{'form.autoassign_coowners'};
1.160.6.116 raeburn 14794: my $autofailsafe = $env{'form.autoenroll_autofailsafe'};
14795: $autofailsafe =~ s{^\s+|\s+$}{}g;
14796: if ($autofailsafe =~ /\D/) {
14797: undef($autofailsafe);
14798: }
1.160.6.68 raeburn 14799: my $failsafe = $env{'form.autoenroll_failsafe'};
1.160.6.116 raeburn 14800: unless (($failsafe eq 'zero') || ($failsafe eq 'any')) {
14801: $failsafe = 'off';
14802: undef($autofailsafe);
1.160.6.68 raeburn 14803: }
1.1 raeburn 14804: my %autoenrollhash = (
1.129 raeburn 14805: autoenroll => { 'run' => $env{'form.autoenroll_run'},
14806: 'sender_uname' => $sender_uname,
14807: 'sender_domain' => $sender_domain,
14808: 'co-owners' => $coowners,
1.160.6.116 raeburn 14809: 'autofailsafe' => $autofailsafe,
14810: 'failsafe' => $failsafe,
1.1 raeburn 14811: }
14812: );
1.4 raeburn 14813: my $putresult = &Apache::lonnet::put_dom('configuration',\%autoenrollhash,
14814: $dom);
1.1 raeburn 14815: if ($putresult eq 'ok') {
14816: if (exists($currautoenroll{'run'})) {
14817: if ($currautoenroll{'run'} ne $env{'form.autoenroll_run'}) {
14818: $changes{'run'} = 1;
14819: }
14820: } elsif ($autorun) {
14821: if ($env{'form.autoenroll_run'} ne '1') {
1.23 raeburn 14822: $changes{'run'} = 1;
1.1 raeburn 14823: }
14824: }
1.17 raeburn 14825: if ($currautoenroll{'sender_uname'} ne $sender_uname) {
1.1 raeburn 14826: $changes{'sender'} = 1;
14827: }
1.17 raeburn 14828: if ($currautoenroll{'sender_domain'} ne $sender_domain) {
1.1 raeburn 14829: $changes{'sender'} = 1;
14830: }
1.129 raeburn 14831: if ($currautoenroll{'co-owners'} ne '') {
14832: if ($currautoenroll{'co-owners'} ne $coowners) {
14833: $changes{'coowners'} = 1;
14834: }
14835: } elsif ($coowners) {
14836: $changes{'coowners'} = 1;
1.160.6.68 raeburn 14837: }
1.160.6.116 raeburn 14838: if ($currautoenroll{'autofailsafe'} ne $autofailsafe) {
1.160.6.68 raeburn 14839: $changes{'autofailsafe'} = 1;
14840: }
1.160.6.116 raeburn 14841: if ($currautoenroll{'failsafe'} ne $failsafe) {
14842: $changes{'failsafe'} = 1;
14843: }
1.1 raeburn 14844: if (keys(%changes) > 0) {
14845: $resulttext = &mt('Changes made:').'<ul>';
1.3 raeburn 14846: if ($changes{'run'}) {
1.1 raeburn 14847: $resulttext .= '<li>'.&mt("$title{'run'} set to $offon[$env{'form.autoenroll_run'}]").'</li>';
14848: }
14849: if ($changes{'sender'}) {
1.17 raeburn 14850: if ($sender_uname eq '' || $sender_domain eq '') {
14851: $resulttext .= '<li>'.&mt("$title{'sender'} set to default (course owner).").'</li>';
14852: } else {
14853: $resulttext .= '<li>'.&mt("$title{'sender'} set to [_1]",$sender_uname.':'.$sender_domain).'</li>';
14854: }
1.1 raeburn 14855: }
1.129 raeburn 14856: if ($changes{'coowners'}) {
14857: $resulttext .= '<li>'.&mt("$title{'coowners'} set to $offon[$env{'form.autoassign_coowners'}]").'</li>';
14858: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 14859: if (ref($lastactref) eq 'HASH') {
14860: $lastactref->{'domainconfig'} = 1;
14861: }
1.129 raeburn 14862: }
1.160.6.68 raeburn 14863: if ($changes{'autofailsafe'}) {
1.160.6.116 raeburn 14864: if ($autofailsafe ne '') {
14865: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section set to: [_1]',$autofailsafe).'</li>';
1.160.6.68 raeburn 14866: } else {
1.160.6.116 raeburn 14867: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
1.160.6.68 raeburn 14868: }
1.160.6.116 raeburn 14869: }
14870: if ($changes{'failsafe'}) {
14871: if ($failsafe eq 'off') {
14872: unless ($changes{'autofailsafe'}) {
14873: $resulttext .= '<li>'.&mt('Failsafe for no drops if institutional data missing for a section not in use').'</li>';
14874: }
14875: } elsif ($failsafe eq 'zero') {
14876: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero').'</li>';
14877: } else {
14878: $resulttext .= '<li>'.&mt('Failsafe applies if retrieved section enrollment is zero or greater').'</li>';
14879: }
14880: }
14881: if (($changes{'autofailsafe'}) || ($changes{'failsafe'})) {
1.160.6.68 raeburn 14882: &Apache::lonnet::get_domain_defaults($dom,1);
14883: if (ref($lastactref) eq 'HASH') {
14884: $lastactref->{'domdefaults'} = 1;
14885: }
14886: }
1.1 raeburn 14887: $resulttext .= '</ul>';
14888: } else {
14889: $resulttext = &mt('No changes made to auto-enrollment settings');
14890: }
14891: } else {
1.11 albertel 14892: $resulttext = '<span class="LC_error">'.
14893: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 14894: }
1.3 raeburn 14895: return $resulttext;
1.1 raeburn 14896: }
14897:
14898: sub modify_autoupdate {
1.3 raeburn 14899: my ($dom,%domconfig) = @_;
1.1 raeburn 14900: my ($resulttext,%currautoupdate,%fields,%changes);
14901: if (ref($domconfig{'autoupdate'}) eq 'HASH') {
14902: foreach my $key (keys(%{$domconfig{'autoupdate'}})) {
14903: $currautoupdate{$key} = $domconfig{'autoupdate'}{$key};
14904: }
14905: }
14906: my @offon = ('off','on');
14907: my %title = &Apache::lonlocal::texthash (
1.160.6.113 raeburn 14908: run => 'Auto-update:',
14909: classlists => 'Updates to user information in classlists?',
14910: unexpired => 'Skip updates for users without active or future roles?',
14911: lastactive => 'Skip updates for inactive users?',
1.1 raeburn 14912: );
1.44 raeburn 14913: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.1 raeburn 14914: my %fieldtitles = &Apache::lonlocal::texthash (
14915: id => 'Student/Employee ID',
1.20 raeburn 14916: permanentemail => 'E-mail address',
1.1 raeburn 14917: lastname => 'Last Name',
14918: firstname => 'First Name',
14919: middlename => 'Middle Name',
1.132 raeburn 14920: generation => 'Generation',
1.1 raeburn 14921: );
1.142 raeburn 14922: $othertitle = &mt('All users');
1.1 raeburn 14923: if (keys(%{$usertypes}) > 0) {
1.26 raeburn 14924: $othertitle = &mt('Other users');
1.1 raeburn 14925: }
14926: foreach my $key (keys(%env)) {
14927: if ($key =~ /^form\.updateable_(.+)_([^_]+)$/) {
1.132 raeburn 14928: my ($usertype,$item) = ($1,$2);
14929: if (grep(/^\Q$item\E$/,keys(%fieldtitles))) {
14930: if ($usertype eq 'default') {
14931: push(@{$fields{$1}},$2);
14932: } elsif (ref($types) eq 'ARRAY') {
14933: if (grep(/^\Q$usertype\E$/,@{$types})) {
14934: push(@{$fields{$1}},$2);
14935: }
14936: }
14937: }
1.1 raeburn 14938: }
14939: }
1.131 raeburn 14940: my @lockablenames = &Apache::loncommon::get_env_multiple('form.lockablenames');
14941: @lockablenames = sort(@lockablenames);
14942: if (ref($currautoupdate{'lockablenames'}) eq 'ARRAY') {
14943: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
14944: if (@changed) {
14945: $changes{'lockablenames'} = 1;
14946: }
14947: } else {
14948: if (@lockablenames) {
14949: $changes{'lockablenames'} = 1;
14950: }
14951: }
1.1 raeburn 14952: my %updatehash = (
14953: autoupdate => { run => $env{'form.autoupdate_run'},
14954: classlists => $env{'form.classlists'},
1.160.6.113 raeburn 14955: unexpired => $env{'form.unexpired'},
1.1 raeburn 14956: fields => {%fields},
1.131 raeburn 14957: lockablenames => \@lockablenames,
1.1 raeburn 14958: }
14959: );
1.160.6.113 raeburn 14960: my $lastactivedays;
14961: if ($env{'form.lastactive'}) {
14962: $lastactivedays = $env{'form.lastactivedays'};
14963: $lastactivedays =~ s/^\s+|\s+$//g;
14964: unless ($lastactivedays =~ /^\d+$/) {
14965: undef($lastactivedays);
14966: $env{'form.lastactive'} = 0;
14967: }
14968: }
14969: $updatehash{'autoupdate'}{'lastactive'} = $lastactivedays;
1.1 raeburn 14970: foreach my $key (keys(%currautoupdate)) {
1.160.6.113 raeburn 14971: if (($key eq 'run') || ($key eq 'classlists') || ($key eq 'unexpired') || ($key eq 'lastactive')) {
1.1 raeburn 14972: if (exists($updatehash{autoupdate}{$key})) {
14973: if ($currautoupdate{$key} ne $updatehash{autoupdate}{$key}) {
14974: $changes{$key} = 1;
14975: }
14976: }
14977: } elsif ($key eq 'fields') {
14978: if (ref($currautoupdate{$key}) eq 'HASH') {
1.26 raeburn 14979: foreach my $item (@{$types},'default') {
1.1 raeburn 14980: if (ref($currautoupdate{$key}{$item}) eq 'ARRAY') {
14981: my $change = 0;
14982: foreach my $type (@{$currautoupdate{$key}{$item}}) {
14983: if (!exists($fields{$item})) {
14984: $change = 1;
1.132 raeburn 14985: last;
1.1 raeburn 14986: } elsif (ref($fields{$item}) eq 'ARRAY') {
1.26 raeburn 14987: if (!grep(/^\Q$type\E$/,@{$fields{$item}})) {
1.1 raeburn 14988: $change = 1;
1.132 raeburn 14989: last;
1.1 raeburn 14990: }
14991: }
14992: }
14993: if ($change) {
14994: push(@{$changes{$key}},$item);
14995: }
1.26 raeburn 14996: }
1.1 raeburn 14997: }
14998: }
1.131 raeburn 14999: } elsif ($key eq 'lockablenames') {
15000: if (ref($currautoupdate{$key}) eq 'ARRAY') {
15001: my @changed = &Apache::loncommon::compare_arrays($currautoupdate{'lockablenames'},\@lockablenames);
15002: if (@changed) {
15003: $changes{'lockablenames'} = 1;
15004: }
15005: } else {
15006: if (@lockablenames) {
15007: $changes{'lockablenames'} = 1;
15008: }
15009: }
15010: }
15011: }
15012: unless (grep(/^\Qlockablenames\E$/,keys(%currautoupdate))) {
15013: if (@lockablenames) {
15014: $changes{'lockablenames'} = 1;
1.1 raeburn 15015: }
15016: }
1.160.6.113 raeburn 15017: unless (grep(/^unexpired$/,keys(%currautoupdate))) {
15018: if ($updatehash{'autoupdate'}{'unexpired'}) {
15019: $changes{'unexpired'} = 1;
15020: }
15021: }
15022: unless (grep(/^lastactive$/,keys(%currautoupdate))) {
15023: if ($updatehash{'autoupdate'}{'lastactive'} ne '') {
15024: $changes{'lastactive'} = 1;
15025: }
15026: }
1.26 raeburn 15027: foreach my $item (@{$types},'default') {
15028: if (defined($fields{$item})) {
15029: if (ref($currautoupdate{'fields'}) eq 'HASH') {
1.132 raeburn 15030: if (ref($currautoupdate{'fields'}{$item}) eq 'ARRAY') {
15031: my $change = 0;
15032: if (ref($fields{$item}) eq 'ARRAY') {
15033: foreach my $type (@{$fields{$item}}) {
15034: if (!grep(/^\Q$type\E$/,@{$currautoupdate{'fields'}{$item}})) {
15035: $change = 1;
15036: last;
15037: }
15038: }
15039: }
15040: if ($change) {
15041: push(@{$changes{'fields'}},$item);
15042: }
15043: } else {
1.26 raeburn 15044: push(@{$changes{'fields'}},$item);
15045: }
15046: } else {
15047: push(@{$changes{'fields'}},$item);
1.1 raeburn 15048: }
15049: }
15050: }
15051: my $putresult = &Apache::lonnet::put_dom('configuration',\%updatehash,
15052: $dom);
15053: if ($putresult eq 'ok') {
15054: if (keys(%changes) > 0) {
15055: $resulttext = &mt('Changes made:').'<ul>';
15056: foreach my $key (sort(keys(%changes))) {
1.131 raeburn 15057: if ($key eq 'lockablenames') {
15058: $resulttext .= '<li>';
15059: if (@lockablenames) {
15060: $usertypes->{'default'} = $othertitle;
15061: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update), available for the following affiliations:").' '.
15062: join(', ', map { $usertypes->{$_}; } @lockablenames).'</li>';
15063: } else {
15064: $resulttext .= &mt("User preference to disable replacement of user's name with institutional data (by auto-update) is unavailable.");
15065: }
15066: $resulttext .= '</li>';
15067: } elsif (ref($changes{$key}) eq 'ARRAY') {
1.1 raeburn 15068: foreach my $item (@{$changes{$key}}) {
15069: my @newvalues;
15070: foreach my $type (@{$fields{$item}}) {
15071: push(@newvalues,$fieldtitles{$type});
15072: }
1.3 raeburn 15073: my $newvaluestr;
15074: if (@newvalues > 0) {
15075: $newvaluestr = join(', ',@newvalues);
15076: } else {
15077: $newvaluestr = &mt('none');
1.6 raeburn 15078: }
1.1 raeburn 15079: if ($item eq 'default') {
1.26 raeburn 15080: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$othertitle,$newvaluestr).'</li>';
1.1 raeburn 15081: } else {
1.26 raeburn 15082: $resulttext .= '<li>'.&mt("Updates for '[_1]' set to: '[_2]'",$usertypes->{$item},$newvaluestr).'</li>';
1.1 raeburn 15083: }
15084: }
15085: } else {
15086: my $newvalue;
15087: if ($key eq 'run') {
15088: $newvalue = $offon[$env{'form.autoupdate_run'}];
1.160.6.113 raeburn 15089: } elsif ($key eq 'lastactive') {
15090: $newvalue = $offon[$env{'form.lastactive'}];
15091: unless ($lastactivedays eq '') {
15092: $newvalue .= '; '.&mt('inactive = no activity in last [quant,_1,day]',$lastactivedays);
15093: }
1.1 raeburn 15094: } else {
15095: $newvalue = $offon[$env{'form.'.$key}];
1.3 raeburn 15096: }
1.1 raeburn 15097: $resulttext .= '<li>'.&mt("[_1] set to $newvalue",$title{$key}).'</li>';
15098: }
15099: }
15100: $resulttext .= '</ul>';
15101: } else {
1.3 raeburn 15102: $resulttext = &mt('No changes made to autoupdates');
1.1 raeburn 15103: }
15104: } else {
1.11 albertel 15105: $resulttext = '<span class="LC_error">'.
15106: &mt('An error occurred: [_1]',$putresult).'</span>';
1.1 raeburn 15107: }
1.3 raeburn 15108: return $resulttext;
1.1 raeburn 15109: }
15110:
1.125 raeburn 15111: sub modify_autocreate {
15112: my ($dom,%domconfig) = @_;
15113: my ($resulttext,%changes,%currautocreate,%newvals,%autocreatehash);
15114: if (ref($domconfig{'autocreate'}) eq 'HASH') {
15115: foreach my $key (keys(%{$domconfig{'autocreate'}})) {
15116: $currautocreate{$key} = $domconfig{'autocreate'}{$key};
15117: }
15118: }
15119: my %title= ( xml => 'Auto-creation of courses in XML course description files',
15120: req => 'Auto-creation of validated requests for official courses',
15121: xmldc => 'Identity of course creator of courses from XML files',
15122: );
15123: my @types = ('xml','req');
15124: foreach my $item (@types) {
15125: $newvals{$item} = $env{'form.autocreate_'.$item};
15126: $newvals{$item} =~ s/\D//g;
15127: $newvals{$item} = 0 if ($newvals{$item} eq '');
15128: }
15129: $newvals{'xmldc'} = $env{'form.autocreate_xmldc'};
1.160.6.77 raeburn 15130: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.125 raeburn 15131: unless (exists($domcoords{$newvals{'xmldc'}})) {
15132: $newvals{'xmldc'} = '';
15133: }
15134: %autocreatehash = (
15135: autocreate => { xml => $newvals{'xml'},
15136: req => $newvals{'req'},
15137: }
15138: );
15139: if ($newvals{'xmldc'} ne '') {
15140: $autocreatehash{'autocreate'}{'xmldc'} = $newvals{'xmldc'};
15141: }
15142: my $putresult = &Apache::lonnet::put_dom('configuration',\%autocreatehash,
15143: $dom);
15144: if ($putresult eq 'ok') {
15145: my @items = @types;
15146: if ($newvals{'xml'}) {
15147: push(@items,'xmldc');
15148: }
15149: foreach my $item (@items) {
15150: if (exists($currautocreate{$item})) {
15151: if ($currautocreate{$item} ne $newvals{$item}) {
15152: $changes{$item} = 1;
15153: }
15154: } elsif ($newvals{$item}) {
15155: $changes{$item} = 1;
15156: }
15157: }
15158: if (keys(%changes) > 0) {
15159: my @offon = ('off','on');
15160: $resulttext = &mt('Changes made:').'<ul>';
15161: foreach my $item (@types) {
15162: if ($changes{$item}) {
15163: my $newtxt = $offon[$newvals{$item}];
1.160.6.13 raeburn 15164: $resulttext .= '<li>'.
15165: &mt("$title{$item} set to [_1]$newtxt [_2]",
15166: '<b>','</b>').
15167: '</li>';
1.125 raeburn 15168: }
15169: }
15170: if ($changes{'xmldc'}) {
15171: my ($dcname,$dcdom) = split(':',$newvals{'xmldc'});
15172: my $newtxt = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.13 raeburn 15173: $resulttext .= '<li>'.&mt("$title{'xmldc'} set to [_1]",'<b>'.$newtxt.'</b>').'</li>';
1.125 raeburn 15174: }
15175: $resulttext .= '</ul>';
15176: } else {
15177: $resulttext = &mt('No changes made to auto-creation settings');
15178: }
15179: } else {
15180: $resulttext = '<span class="LC_error">'.
15181: &mt('An error occurred: [_1]',$putresult).'</span>';
15182: }
15183: return $resulttext;
15184: }
15185:
1.23 raeburn 15186: sub modify_directorysrch {
1.160.6.81 raeburn 15187: my ($dom,$lastactref,%domconfig) = @_;
1.23 raeburn 15188: my ($resulttext,%changes);
15189: my %currdirsrch;
15190: if (ref($domconfig{'directorysrch'}) eq 'HASH') {
15191: foreach my $key (keys(%{$domconfig{'directorysrch'}})) {
15192: $currdirsrch{$key} = $domconfig{'directorysrch'}{$key};
15193: }
15194: }
1.160.6.72 raeburn 15195: my %title = ( available => 'Institutional directory search available',
15196: localonly => 'Other domains can search institution',
15197: lcavailable => 'LON-CAPA directory search available',
15198: lclocalonly => 'Other domains can search LON-CAPA domain',
1.23 raeburn 15199: searchby => 'Search types',
15200: searchtypes => 'Search latitude');
15201: my @offon = ('off','on');
1.24 raeburn 15202: my @otherdoms = ('Yes','No');
1.23 raeburn 15203:
1.25 raeburn 15204: my @searchtypes = &Apache::loncommon::get_env_multiple('form.searchtypes');
1.23 raeburn 15205: my @cansearch = &Apache::loncommon::get_env_multiple('form.cansearch');
15206: my @searchby = &Apache::loncommon::get_env_multiple('form.searchby');
15207:
1.44 raeburn 15208: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.26 raeburn 15209: if (keys(%{$usertypes}) == 0) {
15210: @cansearch = ('default');
15211: } else {
15212: if (ref($currdirsrch{'cansearch'}) eq 'ARRAY') {
15213: foreach my $type (@{$currdirsrch{'cansearch'}}) {
15214: if (!grep(/^\Q$type\E$/,@cansearch)) {
15215: push(@{$changes{'cansearch'}},$type);
15216: }
1.23 raeburn 15217: }
1.26 raeburn 15218: foreach my $type (@cansearch) {
15219: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'cansearch'}})) {
15220: push(@{$changes{'cansearch'}},$type);
15221: }
1.23 raeburn 15222: }
1.26 raeburn 15223: } else {
15224: push(@{$changes{'cansearch'}},@cansearch);
1.23 raeburn 15225: }
15226: }
15227:
15228: if (ref($currdirsrch{'searchby'}) eq 'ARRAY') {
15229: foreach my $by (@{$currdirsrch{'searchby'}}) {
15230: if (!grep(/^\Q$by\E$/,@searchby)) {
15231: push(@{$changes{'searchby'}},$by);
15232: }
15233: }
15234: foreach my $by (@searchby) {
15235: if (!grep(/^\Q$by\E$/,@{$currdirsrch{'searchby'}})) {
15236: push(@{$changes{'searchby'}},$by);
15237: }
15238: }
15239: } else {
15240: push(@{$changes{'searchby'}},@searchby);
15241: }
1.25 raeburn 15242:
15243: if (ref($currdirsrch{'searchtypes'}) eq 'ARRAY') {
15244: foreach my $type (@{$currdirsrch{'searchtypes'}}) {
15245: if (!grep(/^\Q$type\E$/,@searchtypes)) {
15246: push(@{$changes{'searchtypes'}},$type);
15247: }
15248: }
15249: foreach my $type (@searchtypes) {
15250: if (!grep(/^\Q$type\E$/,@{$currdirsrch{'searchtypes'}})) {
15251: push(@{$changes{'searchtypes'}},$type);
15252: }
15253: }
15254: } else {
15255: if (exists($currdirsrch{'searchtypes'})) {
15256: foreach my $type (@searchtypes) {
15257: if ($type ne $currdirsrch{'searchtypes'}) {
15258: push(@{$changes{'searchtypes'}},$type);
15259: }
15260: }
15261: if (!grep(/^\Q$currdirsrch{'searchtypes'}\E/,@searchtypes)) {
15262: push(@{$changes{'searchtypes'}},$currdirsrch{'searchtypes'});
15263: }
15264: } else {
15265: push(@{$changes{'searchtypes'}},@searchtypes);
15266: }
15267: }
15268:
1.23 raeburn 15269: my %dirsrch_hash = (
15270: directorysrch => { available => $env{'form.dirsrch_available'},
15271: cansearch => \@cansearch,
1.160.6.72 raeburn 15272: localonly => $env{'form.dirsrch_instlocalonly'},
15273: lclocalonly => $env{'form.dirsrch_domlocalonly'},
15274: lcavailable => $env{'form.dirsrch_domavailable'},
1.23 raeburn 15275: searchby => \@searchby,
1.25 raeburn 15276: searchtypes => \@searchtypes,
1.23 raeburn 15277: }
15278: );
15279: my $putresult = &Apache::lonnet::put_dom('configuration',\%dirsrch_hash,
15280: $dom);
15281: if ($putresult eq 'ok') {
15282: if (exists($currdirsrch{'available'})) {
15283: if ($currdirsrch{'available'} ne $env{'form.dirsrch_available'}) {
15284: $changes{'available'} = 1;
15285: }
15286: } else {
15287: if ($env{'form.dirsrch_available'} eq '1') {
15288: $changes{'available'} = 1;
15289: }
15290: }
1.160.6.72 raeburn 15291: if (exists($currdirsrch{'lcavailable'})) {
1.160.6.78 raeburn 15292: if ($currdirsrch{'lcavailable'} ne $env{'form.dirsrch_domavailable'}) {
15293: $changes{'lcavailable'} = 1;
15294: }
1.24 raeburn 15295: } else {
1.160.6.72 raeburn 15296: if ($env{'form.dirsrch_lcavailable'} eq '1') {
15297: $changes{'lcavailable'} = 1;
15298: }
15299: }
15300: if (exists($currdirsrch{'localonly'})) {
15301: if ($currdirsrch{'localonly'} ne $env{'form.dirsrch_instlocalonly'}) {
1.24 raeburn 15302: $changes{'localonly'} = 1;
15303: }
1.160.6.72 raeburn 15304: } else {
15305: if ($env{'form.dirsrch_instlocalonly'} eq '1') {
15306: $changes{'localonly'} = 1;
15307: }
15308: }
15309: if (exists($currdirsrch{'lclocalonly'})) {
15310: if ($currdirsrch{'lclocalonly'} ne $env{'form.dirsrch_domlocalonly'}) {
15311: $changes{'lclocalonly'} = 1;
15312: }
15313: } else {
15314: if ($env{'form.dirsrch_domlocalonly'} eq '1') {
15315: $changes{'lclocalonly'} = 1;
15316: }
1.24 raeburn 15317: }
1.23 raeburn 15318: if (keys(%changes) > 0) {
15319: $resulttext = &mt('Changes made:').'<ul>';
15320: if ($changes{'available'}) {
15321: $resulttext .= '<li>'.&mt("$title{'available'} set to: $offon[$env{'form.dirsrch_available'}]").'</li>';
15322: }
1.160.6.72 raeburn 15323: if ($changes{'lcavailable'}) {
15324: $resulttext .= '<li>'.&mt("$title{'lcavailable'} set to: $offon[$env{'form.dirsrch_domavailable'}]").'</li>';
15325: }
1.24 raeburn 15326: if ($changes{'localonly'}) {
1.160.6.72 raeburn 15327: $resulttext .= '<li>'.&mt("$title{'localonly'} set to: $otherdoms[$env{'form.dirsrch_instlocalonly'}]").'</li>';
15328: }
15329: if ($changes{'lclocalonly'}) {
15330: $resulttext .= '<li>'.&mt("$title{'lclocalonly'} set to: $otherdoms[$env{'form.dirsrch_domlocalonly'}]").'</li>';
1.24 raeburn 15331: }
1.23 raeburn 15332: if (ref($changes{'cansearch'}) eq 'ARRAY') {
15333: my $chgtext;
1.26 raeburn 15334: if (ref($usertypes) eq 'HASH') {
15335: if (keys(%{$usertypes}) > 0) {
15336: foreach my $type (@{$types}) {
15337: if (grep(/^\Q$type\E$/,@cansearch)) {
15338: $chgtext .= $usertypes->{$type}.'; ';
15339: }
15340: }
15341: if (grep(/^default$/,@cansearch)) {
15342: $chgtext .= $othertitle;
15343: } else {
15344: $chgtext =~ s/\; $//;
15345: }
1.160.6.13 raeburn 15346: $resulttext .=
15347: '<li>'.
15348: &mt("Users from domain '[_1]' permitted to search the institutional directory set to: [_2]",
15349: '<span class="LC_cusr_emph">'.$dom.'</span>',$chgtext).
15350: '</li>';
1.23 raeburn 15351: }
15352: }
15353: }
15354: if (ref($changes{'searchby'}) eq 'ARRAY') {
15355: my ($searchtitles,$titleorder) = &sorted_searchtitles();
15356: my $chgtext;
15357: foreach my $type (@{$titleorder}) {
15358: if (grep(/^\Q$type\E$/,@searchby)) {
15359: if (defined($searchtitles->{$type})) {
15360: $chgtext .= $searchtitles->{$type}.'; ';
15361: }
15362: }
15363: }
15364: $chgtext =~ s/\; $//;
15365: $resulttext .= '<li>'.&mt("$title{'searchby'} set to: [_1]",$chgtext).'</li>';
15366: }
1.25 raeburn 15367: if (ref($changes{'searchtypes'}) eq 'ARRAY') {
15368: my ($srchtypes_desc,$srchtypeorder) = &sorted_searchtypes();
15369: my $chgtext;
15370: foreach my $type (@{$srchtypeorder}) {
15371: if (grep(/^\Q$type\E$/,@searchtypes)) {
15372: if (defined($srchtypes_desc->{$type})) {
15373: $chgtext .= $srchtypes_desc->{$type}.'; ';
15374: }
15375: }
15376: }
15377: $chgtext =~ s/\; $//;
1.160.6.13 raeburn 15378: $resulttext .= '<li>'.&mt($title{'searchtypes'}.' set to: "[_1]"',$chgtext).'</li>';
1.23 raeburn 15379: }
15380: $resulttext .= '</ul>';
1.160.6.81 raeburn 15381: &Apache::lonnet::do_cache_new('directorysrch',$dom,$dirsrch_hash{'directorysrch'},3600);
15382: if (ref($lastactref) eq 'HASH') {
15383: $lastactref->{'directorysrch'} = 1;
15384: }
1.23 raeburn 15385: } else {
1.160.6.72 raeburn 15386: $resulttext = &mt('No changes made to directory search settings');
1.23 raeburn 15387: }
15388: } else {
15389: $resulttext = '<span class="LC_error">'.
1.27 raeburn 15390: &mt('An error occurred: [_1]',$putresult).'</span>';
15391: }
15392: return $resulttext;
15393: }
15394:
1.28 raeburn 15395: sub modify_contacts {
1.160.6.24 raeburn 15396: my ($dom,$lastactref,%domconfig) = @_;
1.28 raeburn 15397: my ($resulttext,%currsetting,%newsetting,%changes,%contacts_hash);
15398: if (ref($domconfig{'contacts'}) eq 'HASH') {
15399: foreach my $key (keys(%{$domconfig{'contacts'}})) {
15400: $currsetting{$key} = $domconfig{'contacts'}{$key};
15401: }
15402: }
1.160.6.78 raeburn 15403: my (%others,%to,%bcc,%includestr,%includeloc);
1.28 raeburn 15404: my @contacts = ('supportemail','adminemail');
1.160.6.78 raeburn 15405: my @mailings = ('errormail','packagesmail','helpdeskmail','otherdomsmail',
1.160.6.95 raeburn 15406: 'lonstatusmail','requestsmail','updatesmail','idconflictsmail','hostipmail');
1.160.6.107 raeburn 15407: my @toggles = ('reporterrors','reportupdates','reportstatus');
15408: my @lonstatus = ('threshold','sysmail','weights','excluded');
1.160.6.78 raeburn 15409: my ($fields,$fieldtitles,$fieldoptions,$possoptions) = &helpform_fields();
1.28 raeburn 15410: foreach my $type (@mailings) {
15411: @{$newsetting{$type}} =
15412: &Apache::loncommon::get_env_multiple('form.'.$type);
15413: foreach my $item (@contacts) {
15414: if (grep(/^\Q$item\E$/,@{$newsetting{$type}})) {
15415: $contacts_hash{contacts}{$type}{$item} = 1;
15416: } else {
15417: $contacts_hash{contacts}{$type}{$item} = 0;
15418: }
1.160.6.78 raeburn 15419: }
1.28 raeburn 15420: $others{$type} = $env{'form.'.$type.'_others'};
15421: $contacts_hash{contacts}{$type}{'others'} = $others{$type};
1.160.6.78 raeburn 15422: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15423: $bcc{$type} = $env{'form.'.$type.'_bcc'};
15424: $contacts_hash{contacts}{$type}{'bcc'} = $bcc{$type};
1.160.6.78 raeburn 15425: if (($env{'form.'.$type.'_includestr'} ne '') && ($env{'form.'.$type.'_includeloc'} =~ /^s|b$/)) {
15426: $includestr{$type} = $env{'form.'.$type.'_includestr'};
15427: $includeloc{$type} = $env{'form.'.$type.'_includeloc'};
15428: $contacts_hash{contacts}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15429: }
1.134 raeburn 15430: }
1.28 raeburn 15431: }
15432: foreach my $item (@contacts) {
15433: $to{$item} = $env{'form.'.$item};
15434: $contacts_hash{'contacts'}{$item} = $to{$item};
15435: }
1.160.6.23 raeburn 15436: foreach my $item (@toggles) {
15437: if ($env{'form.'.$item} =~ /^(0|1)$/) {
15438: $contacts_hash{'contacts'}{$item} = $env{'form.'.$item};
15439: }
15440: }
1.160.6.107 raeburn 15441: my ($lonstatus_defs,$lonstatus_names) = &Apache::loncommon::lon_status_items();
15442: foreach my $item (@lonstatus) {
15443: if ($item eq 'excluded') {
15444: my (%serverhomes,@excluded);
15445: map { $serverhomes{$_} = 1; } values(%Apache::lonnet::serverhomeIDs);
15446: my @possexcluded = &Apache::loncommon::get_env_multiple('form.errorexcluded');
15447: if (@possexcluded) {
15448: foreach my $id (sort(@possexcluded)) {
15449: if ($serverhomes{$id}) {
15450: push(@excluded,$id);
15451: }
15452: }
15453: }
15454: if (@excluded) {
15455: $contacts_hash{'contacts'}{'lonstatus'}{$item} = \@excluded;
15456: }
15457: } elsif ($item eq 'weights') {
15458: foreach my $type ('E','W','N','U') {
15459: $env{'form.error'.$item.'_'.$type} =~ s/^\s+|\s+$//g;
15460: if ($env{'form.error'.$item.'_'.$type} =~ /^\d+$/) {
15461: unless ($env{'form.error'.$item.'_'.$type} == $lonstatus_defs->{$type}) {
15462: $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type} =
15463: $env{'form.error'.$item.'_'.$type};
15464: }
15465: }
15466: }
15467: } elsif (($item eq 'threshold') || ($item eq 'sysmail')) {
15468: $env{'form.error'.$item} =~ s/^\s+|\s+$//g;
15469: if ($env{'form.error'.$item} =~ /^\d+$/) {
15470: unless ($env{'form.error'.$item} == $lonstatus_defs->{$item}) {
15471: $contacts_hash{'contacts'}{'lonstatus'}{$item} = $env{'form.error'.$item};
15472: }
15473: }
15474: }
15475: }
1.160.6.78 raeburn 15476: if ((ref($fields) eq 'ARRAY') && (ref($possoptions) eq 'HASH')) {
15477: foreach my $field (@{$fields}) {
15478: if (ref($possoptions->{$field}) eq 'ARRAY') {
15479: my $value = $env{'form.helpform_'.$field};
15480: $value =~ s/^\s+|\s+$//g;
15481: if (grep(/^\Q$value\E$/,@{$possoptions->{$field}})) {
1.160.6.101 raeburn 15482: $contacts_hash{'contacts'}{'helpform'}{$field} = $value;
1.160.6.78 raeburn 15483: if ($field eq 'screenshot') {
15484: $env{'form.helpform_maxsize'} =~ s/^\s+|\s+$//g;
15485: if ($env{'form.helpform_maxsize'} =~ /^\d+\.?\d*$/) {
1.160.6.101 raeburn 15486: $contacts_hash{'contacts'}{'helpform'}{'maxsize'} = $env{'form.helpform_maxsize'};
1.160.6.78 raeburn 15487: }
15488: }
15489: }
15490: }
15491: }
15492: }
1.160.6.101 raeburn 15493: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15494: my (@statuses,%usertypeshash,@overrides);
15495: if ((ref($types) eq 'ARRAY') && (@{$types} > 0)) {
15496: @statuses = @{$types};
15497: if (ref($usertypes) eq 'HASH') {
15498: %usertypeshash = %{$usertypes};
15499: }
15500: }
15501: if (@statuses) {
15502: my @possoverrides = &Apache::loncommon::get_env_multiple('form.overrides');
15503: foreach my $type (@possoverrides) {
15504: if (($type ne '') && (grep(/^\Q$type\E$/,@statuses))) {
15505: push(@overrides,$type);
15506: }
15507: }
15508: if (@overrides) {
15509: foreach my $type (@overrides) {
15510: my @standard = &Apache::loncommon::get_env_multiple('form.override_'.$type);
15511: foreach my $item (@contacts) {
15512: if (grep(/^\Q$item\E$/,@standard)) {
15513: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 1;
15514: $newsetting{'override_'.$type}{$item} = 1;
15515: } else {
15516: $contacts_hash{'contacts'}{'overrides'}{$type}{$item} = 0;
15517: $newsetting{'override_'.$type}{$item} = 0;
15518: }
15519: }
15520: $contacts_hash{'contacts'}{'overrides'}{$type}{'others'} = $env{'form.override_'.$type.'_others'};
15521: $contacts_hash{'contacts'}{'overrides'}{$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15522: $newsetting{'override_'.$type}{'others'} = $env{'form.override_'.$type.'_others'};
15523: $newsetting{'override_'.$type}{'bcc'} = $env{'form.override_'.$type.'_bcc'};
15524: if (($env{'form.override_'.$type.'_includestr'} ne '') && ($env{'form.override_'.$type.'_includeloc'} =~ /^s|b$/)) {
15525: $includestr{$type} = $env{'form.override_'.$type.'_includestr'};
15526: $includeloc{$type} = $env{'form.override_'.$type.'_includeloc'};
15527: $contacts_hash{'contacts'}{'overrides'}{$type}{'include'} = $includeloc{$type}.':'.&escape($includestr{$type});
15528: $newsetting{'override_'.$type}{'include'} = $contacts_hash{'contacts'}{'overrides'}{$type}{'include'};
15529: }
1.160.6.118.2 14(raebu 15530:23): }
1.160.6.101 raeburn 15531: }
15532: }
1.28 raeburn 15533: if (keys(%currsetting) > 0) {
15534: foreach my $item (@contacts) {
15535: if ($to{$item} ne $currsetting{$item}) {
15536: $changes{$item} = 1;
15537: }
15538: }
15539: foreach my $type (@mailings) {
15540: foreach my $item (@contacts) {
15541: if (ref($currsetting{$type}) eq 'HASH') {
15542: if ($currsetting{$type}{$item} ne $contacts_hash{contacts}{$type}{$item}) {
15543: push(@{$changes{$type}},$item);
15544: }
15545: } else {
15546: push(@{$changes{$type}},@{$newsetting{$type}});
15547: }
15548: }
15549: if ($others{$type} ne $currsetting{$type}{'others'}) {
15550: push(@{$changes{$type}},'others');
15551: }
1.160.6.78 raeburn 15552: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15553: if ($bcc{$type} ne $currsetting{$type}{'bcc'}) {
15554: push(@{$changes{$type}},'bcc');
15555: }
1.160.6.78 raeburn 15556: my ($currloc,$currstr) = split(/:/,$currsetting{$type}{'include'},2);
15557: if (($includeloc{$type} ne $currloc) || (&escape($includestr{$type}) ne $currstr)) {
15558: push(@{$changes{$type}},'include');
15559: }
15560: }
15561: }
15562: if (ref($fields) eq 'ARRAY') {
15563: if (ref($currsetting{'helpform'}) eq 'HASH') {
15564: foreach my $field (@{$fields}) {
15565: if ($currsetting{'helpform'}{$field} ne $contacts_hash{'contacts'}{'helpform'}{$field}) {
15566: push(@{$changes{'helpform'}},$field);
15567: }
15568: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15569: if ($currsetting{'helpform'}{'maxsize'} ne $contacts_hash{'contacts'}{'helpform'}{'maxsize'}) {
15570: push(@{$changes{'helpform'}},'maxsize');
15571: }
15572: }
15573: }
15574: } else {
15575: foreach my $field (@{$fields}) {
15576: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15577: push(@{$changes{'helpform'}},$field);
15578: }
15579: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15580: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15581: push(@{$changes{'helpform'}},'maxsize');
15582: }
15583: }
15584: }
1.134 raeburn 15585: }
1.28 raeburn 15586: }
1.160.6.101 raeburn 15587: if (@statuses) {
15588: if (ref($currsetting{'overrides'}) eq 'HASH') {
15589: foreach my $key (keys(%{$currsetting{'overrides'}})) {
15590: if (ref($currsetting{'overrides'}{$key}) eq 'HASH') {
15591: if (ref($newsetting{'override_'.$key}) eq 'HASH') {
15592: foreach my $item (@contacts,'bcc','others','include') {
15593: if ($currsetting{'overrides'}{$key}{$item} ne $newsetting{'override_'.$key}{$item}) {
15594: push(@{$changes{'overrides'}},$key);
15595: last;
15596: }
15597: }
15598: } else {
15599: push(@{$changes{'overrides'}},$key);
15600: }
15601: }
15602: }
15603: foreach my $key (@overrides) {
15604: unless (exists($currsetting{'overrides'}{$key})) {
15605: push(@{$changes{'overrides'}},$key);
15606: }
15607: }
15608: } else {
15609: foreach my $key (@overrides) {
15610: push(@{$changes{'overrides'}},$key);
15611: }
15612: }
15613: }
1.160.6.107 raeburn 15614: if (ref($currsetting{'lonstatus'}) eq 'HASH') {
15615: foreach my $key ('excluded','weights','threshold','sysmail') {
15616: if ($key eq 'excluded') {
15617: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15618: (ref($contacts_hash{contacts}{lonstatus}{excluded}) eq 'ARRAY')) {
15619: if ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15620: (@{$currsetting{'lonstatus'}{$key}})) {
15621: my @diffs =
15622: &Apache::loncommon::compare_arrays($contacts_hash{contacts}{lonstatus}{excluded},
15623: $currsetting{'lonstatus'}{$key});
15624: if (@diffs) {
15625: push(@{$changes{'lonstatus'}},$key);
15626: }
15627: } elsif (@{$contacts_hash{contacts}{lonstatus}{excluded}}) {
15628: push(@{$changes{'lonstatus'}},$key);
15629: }
15630: } elsif ((ref($currsetting{'lonstatus'}{$key}) eq 'ARRAY') &&
15631: (@{$currsetting{'lonstatus'}{$key}})) {
15632: push(@{$changes{'lonstatus'}},$key);
15633: }
15634: } elsif ($key eq 'weights') {
15635: if ((ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') &&
15636: (ref($contacts_hash{contacts}{lonstatus}{$key}) eq 'HASH')) {
15637: if (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15638: foreach my $type ('E','W','N','U') {
15639: unless ($contacts_hash{contacts}{lonstatus}{$key}{$type} eq
15640: $currsetting{'lonstatus'}{$key}{$type}) {
15641: push(@{$changes{'lonstatus'}},$key);
15642: last;
15643: }
15644: }
15645: } else {
15646: foreach my $type ('E','W','N','U') {
15647: if ($contacts_hash{contacts}{lonstatus}{$key}{$type} ne '') {
15648: push(@{$changes{'lonstatus'}},$key);
15649: last;
15650: }
15651: }
15652: }
15653: } elsif (ref($currsetting{'lonstatus'}{$key}) eq 'HASH') {
15654: foreach my $type ('E','W','N','U') {
15655: if ($currsetting{'lonstatus'}{$key}{$type} ne '') {
15656: push(@{$changes{'lonstatus'}},$key);
15657: last;
15658: }
15659: }
15660: }
15661: } elsif (($key eq 'threshold') || ($key eq 'sysmail')) {
15662: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15663: if ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15664: if ($currsetting{'lonstatus'}{$key} != $contacts_hash{contacts}{lonstatus}{$key}) {
15665: push(@{$changes{'lonstatus'}},$key);
15666: }
15667: } elsif ($contacts_hash{contacts}{lonstatus}{$key} =~ /^\d+$/) {
15668: push(@{$changes{'lonstatus'}},$key);
15669: }
15670: } elsif ($currsetting{'lonstatus'}{$key} =~ /^\d+$/) {
15671: push(@{$changes{'lonstatus'}},$key);
15672: }
15673: }
15674: }
15675: } else {
15676: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15677: foreach my $key ('excluded','weights','threshold','sysmail') {
15678: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15679: push(@{$changes{'lonstatus'}},$key);
15680: }
15681: }
15682: }
15683: }
1.28 raeburn 15684: } else {
15685: my %default;
15686: $default{'supportemail'} = $Apache::lonnet::perlvar{'lonSupportEMail'};
15687: $default{'adminemail'} = $Apache::lonnet::perlvar{'lonAdmEMail'};
15688: $default{'errormail'} = 'adminemail';
15689: $default{'packagesmail'} = 'adminemail';
15690: $default{'helpdeskmail'} = 'supportemail';
1.160.6.78 raeburn 15691: $default{'otherdomsmail'} = 'supportemail';
1.89 raeburn 15692: $default{'lonstatusmail'} = 'adminemail';
1.102 raeburn 15693: $default{'requestsmail'} = 'adminemail';
1.160.6.15 raeburn 15694: $default{'updatesmail'} = 'adminemail';
1.160.6.91 raeburn 15695: $default{'hostipmail'} = 'adminemail';
1.28 raeburn 15696: foreach my $item (@contacts) {
15697: if ($to{$item} ne $default{$item}) {
1.160.6.78 raeburn 15698: $changes{$item} = 1;
1.160.6.23 raeburn 15699: }
1.28 raeburn 15700: }
15701: foreach my $type (@mailings) {
15702: if ((@{$newsetting{$type}} != 1) || ($newsetting{$type}[0] ne $default{$type})) {
15703: push(@{$changes{$type}},@{$newsetting{$type}});
15704: }
15705: if ($others{$type} ne '') {
15706: push(@{$changes{$type}},'others');
1.134 raeburn 15707: }
1.160.6.78 raeburn 15708: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15709: if ($bcc{$type} ne '') {
15710: push(@{$changes{$type}},'bcc');
15711: }
1.160.6.78 raeburn 15712: if (($includeloc{$type} =~ /^b|s$/) && ($includestr{$type} ne '')) {
15713: push(@{$changes{$type}},'include');
15714: }
15715: }
15716: }
15717: if (ref($fields) eq 'ARRAY') {
15718: foreach my $field (@{$fields}) {
15719: if ($contacts_hash{'contacts'}{'helpform'}{$field} ne 'yes') {
15720: push(@{$changes{'helpform'}},$field);
15721: }
15722: if (($field eq 'screenshot') && ($contacts_hash{'contacts'}{'helpform'}{'screenshot'} ne 'no')) {
15723: if ($contacts_hash{'contacts'}{'helpform'}{'maxsize'} != 1) {
15724: push(@{$changes{'helpform'}},'maxsize');
15725: }
15726: }
1.134 raeburn 15727: }
1.28 raeburn 15728: }
1.160.6.107 raeburn 15729: if (ref($contacts_hash{contacts}{lonstatus}) eq 'HASH') {
15730: foreach my $key ('excluded','weights','threshold','sysmail') {
15731: if (exists($contacts_hash{contacts}{lonstatus}{$key})) {
15732: push(@{$changes{'lonstatus'}},$key);
15733: }
15734: }
15735: }
1.28 raeburn 15736: }
1.160.6.23 raeburn 15737: foreach my $item (@toggles) {
15738: if (($env{'form.'.$item} == 1) && ($currsetting{$item} == 0)) {
15739: $changes{$item} = 1;
15740: } elsif ((!$env{'form.'.$item}) &&
15741: (($currsetting{$item} eq '') || ($currsetting{$item} == 1))) {
15742: $changes{$item} = 1;
15743: }
15744: }
1.28 raeburn 15745: my $putresult = &Apache::lonnet::put_dom('configuration',\%contacts_hash,
15746: $dom);
15747: if ($putresult eq 'ok') {
15748: if (keys(%changes) > 0) {
1.160.6.24 raeburn 15749: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 15750: if (ref($lastactref) eq 'HASH') {
15751: $lastactref->{'domainconfig'} = 1;
15752: }
1.28 raeburn 15753: my ($titles,$short_titles) = &contact_titles();
15754: $resulttext = &mt('Changes made:').'<ul>';
15755: foreach my $item (@contacts) {
15756: if ($changes{$item}) {
15757: $resulttext .= '<li>'.$titles->{$item}.
15758: &mt(' set to: ').
15759: '<span class="LC_cusr_emph">'.
15760: $to{$item}.'</span></li>';
15761: }
15762: }
15763: foreach my $type (@mailings) {
15764: if (ref($changes{$type}) eq 'ARRAY') {
1.160.6.78 raeburn 15765: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
15766: $resulttext .= '<li>'.$titles->{$type}.' -- '.&mt('sent to').': ';
15767: } else {
15768: $resulttext .= '<li>'.$titles->{$type}.': ';
15769: }
1.28 raeburn 15770: my @text;
15771: foreach my $item (@{$newsetting{$type}}) {
15772: push(@text,$short_titles->{$item});
15773: }
15774: if ($others{$type} ne '') {
15775: push(@text,$others{$type});
15776: }
1.160.6.78 raeburn 15777: if (@text) {
15778: $resulttext .= '<span class="LC_cusr_emph">'.
15779: join(', ',@text).'</span>';
15780: }
15781: if (($type eq 'helpdeskmail') || ($type eq 'otherdomsmail')) {
1.134 raeburn 15782: if ($bcc{$type} ne '') {
1.160.6.78 raeburn 15783: my $bcctext;
15784: if (@text) {
15785: $bcctext = ' '.&mt('with Bcc to');
15786: } else {
15787: $bcctext = '(Bcc)';
15788: }
15789: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$bcc{$type}.'</span>';
15790: } elsif (!@text) {
15791: $resulttext .= &mt('No one');
1.134 raeburn 15792: }
1.160.6.78 raeburn 15793: if ($includestr{$type} ne '') {
15794: if ($includeloc{$type} eq 'b') {
15795: $resulttext .= '<br />'.&mt('Text automatically added to e-mail body:').' '.$includestr{$type};
15796: } elsif ($includeloc{$type} eq 's') {
15797: $resulttext .= '<br />'.&mt('Text automatically added to e-mail subject:').' '.$includestr{$type};
15798: }
15799: }
15800: } elsif (!@text) {
15801: $resulttext .= &mt('No recipients');
1.134 raeburn 15802: }
15803: $resulttext .= '</li>';
1.28 raeburn 15804: }
15805: }
1.160.6.101 raeburn 15806: if (ref($changes{'overrides'}) eq 'ARRAY') {
15807: my @deletions;
15808: foreach my $type (@{$changes{'overrides'}}) {
15809: if ($usertypeshash{$type}) {
15810: if (grep(/^\Q$type\E/,@overrides)) {
15811: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation set for [_1]",
15812: $usertypeshash{$type}).'<ul><li>';
15813: if (ref($newsetting{'override_'.$type}) eq 'HASH') {
15814: my @text;
15815: foreach my $item (@contacts) {
15816: if ($newsetting{'override_'.$type}{$item}) {
15817: push(@text,$short_titles->{$item});
15818: }
15819: }
15820: if ($newsetting{'override_'.$type}{'others'} ne '') {
15821: push(@text,$newsetting{'override_'.$type}{'others'});
15822: }
15823:
15824: if (@text) {
15825: $resulttext .= &mt('Helpdesk e-mail sent to: [_1]',
15826: '<span class="LC_cusr_emph">'.join(', ',@text).'</span>');
15827: }
15828: if ($newsetting{'override_'.$type}{'bcc'} ne '') {
15829: my $bcctext;
15830: if (@text) {
15831: $bcctext = ' '.&mt('with Bcc to');
15832: } else {
15833: $bcctext = '(Bcc)';
15834: }
15835: $resulttext .= $bcctext.': <span class="LC_cusr_emph">'.$newsetting{'override_'.$type}{'bcc'}.'</span>';
15836: } elsif (!@text) {
15837: $resulttext .= &mt('Helpdesk e-mail sent to no one');
15838: }
15839: $resulttext .= '</li>';
15840: if ($newsetting{'override_'.$type}{'include'} ne '') {
15841: my ($loc,$str) = split(/:/,$newsetting{'override_'.$type}{'include'});
15842: if ($loc eq 'b') {
15843: $resulttext .= '<li>'.&mt('Text automatically added to e-mail body:').' '.&unescape($str).'</li>';
15844: } elsif ($loc eq 's') {
15845: $resulttext .= '<li>'.&mt('Text automatically added to e-mail subject:').' '.&unescape($str).'</li>';
15846: }
15847: }
15848: }
15849: $resulttext .= '</li></ul></li>';
15850: } else {
15851: push(@deletions,$usertypeshash{$type});
15852: }
15853: }
15854: }
15855: if (@deletions) {
15856: $resulttext .= '<li>'.&mt("Overrides based on requester's affiliation discontinued for: [_1]",
15857: join(', ',@deletions)).'</li>';
15858: }
15859: }
1.160.6.23 raeburn 15860: my @offon = ('off','on');
1.160.6.107 raeburn 15861: my $corelink = &core_link_msu();
1.160.6.23 raeburn 15862: if ($changes{'reporterrors'}) {
15863: $resulttext .= '<li>'.
15864: &mt('E-mail error reports to [_1] set to "'.
15865: $offon[$env{'form.reporterrors'}].'".',
1.160.6.107 raeburn 15866: $corelink).
1.160.6.23 raeburn 15867: '</li>';
15868: }
15869: if ($changes{'reportupdates'}) {
15870: $resulttext .= '<li>'.
15871: &mt('E-mail record of completed LON-CAPA updates to [_1] set to "'.
15872: $offon[$env{'form.reportupdates'}].'".',
1.160.6.107 raeburn 15873: $corelink).
1.160.6.23 raeburn 15874: '</li>';
15875: }
1.160.6.107 raeburn 15876: if ($changes{'reportstatus'}) {
15877: $resulttext .= '<li>'.
15878: &mt('E-mail status if errors above threshold to [_1] set to "'.
15879: $offon[$env{'form.reportstatus'}].'".',
15880: $corelink).
15881: '</li>';
15882: }
15883: if (ref($changes{'lonstatus'}) eq 'ARRAY') {
15884: $resulttext .= '<li>'.
15885: &mt('Nightly status check e-mail settings').':<ul>';
15886: my (%defval,%use_def,%shown);
15887: $defval{'threshold'} = $lonstatus_defs->{'threshold'};
15888: $defval{'sysmail'} = $lonstatus_defs->{'sysmail'};
15889: $defval{'weights'} =
15890: join(', ',map { $lonstatus_names->{$_}.'='.$lonstatus_defs->{$_}; } ('E','W','N','U'));
15891: $defval{'excluded'} = &mt('None');
15892: if (ref($contacts_hash{'contacts'}{'lonstatus'}) eq 'HASH') {
15893: foreach my $item ('threshold','sysmail','weights','excluded') {
15894: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item})) {
15895: if (($item eq 'threshold') || ($item eq 'sysmail')) {
15896: $shown{$item} = $contacts_hash{'contacts'}{'lonstatus'}{$item};
15897: } elsif ($item eq 'weights') {
15898: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'HASH') {
15899: foreach my $type ('E','W','N','U') {
15900: $shown{$item} .= $lonstatus_names->{$type}.'=';
15901: if (exists($contacts_hash{'contacts'}{'lonstatus'}{$item}{$type})) {
15902: $shown{$item} .= $contacts_hash{'contacts'}{'lonstatus'}{$item}{$type};
15903: } else {
15904: $shown{$item} .= $lonstatus_defs->{$type};
15905: }
15906: $shown{$item} .= ', ';
15907: }
15908: $shown{$item} =~ s/, $//;
15909: } else {
15910: $shown{$item} = $defval{$item};
15911: }
15912: } elsif ($item eq 'excluded') {
15913: if (ref($contacts_hash{'contacts'}{'lonstatus'}{$item}) eq 'ARRAY') {
15914: $shown{$item} = join(', ',@{$contacts_hash{'contacts'}{'lonstatus'}{$item}});
15915: } else {
15916: $shown{$item} = $defval{$item};
15917: }
15918: }
15919: } else {
15920: $shown{$item} = $defval{$item};
15921: }
15922: }
15923: } else {
15924: foreach my $item ('threshold','weights','excluded','sysmail') {
15925: $shown{$item} = $defval{$item};
15926: }
15927: }
15928: foreach my $item ('threshold','weights','excluded','sysmail') {
15929: $resulttext .= '<li>'.&mt($titles->{'error'.$item}.' -- [_1]',
15930: $shown{$item}).'</li>';
15931: }
15932: $resulttext .= '</ul></li>';
15933: }
1.160.6.78 raeburn 15934: if ((ref($changes{'helpform'}) eq 'ARRAY') && (ref($fields) eq 'ARRAY')) {
15935: my (@optional,@required,@unused,$maxsizechg);
15936: foreach my $field (@{$changes{'helpform'}}) {
15937: if ($field eq 'maxsize') {
15938: $maxsizechg = 1;
15939: next;
15940: }
15941: if ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'yes') {
15942: push(@optional,$field);
15943: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'no') {
15944: push(@unused,$field);
15945: } elsif ($contacts_hash{'contacts'}{'helpform'}{$field} eq 'req') {
15946: push(@required,$field);
15947: }
15948: }
15949: if (@optional) {
15950: $resulttext .= '<li>'.
15951: &mt('Help form fields changed to "Optional": [_1].',
15952: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @optional)).'</span>'.
15953: '</li>';
15954: }
15955: if (@required) {
15956: $resulttext .= '<li>'.
15957: &mt('Help form fields changed to "Required": [_1].',
15958: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @required)).'</span>'.
15959: '</li>';
15960: }
15961: if (@unused) {
15962: $resulttext .= '<li>'.
15963: &mt('Help form fields changed to "Not shown": [_1].',
15964: '<span class="LC_cusr_emph">'.join(', ',map { $fieldtitles->{$_}; } @unused)).'</span>'.
15965: '</li>';
15966: }
15967: if ($maxsizechg) {
15968: $resulttext .= '<li>'.
15969: &mt('Max size for file uploaded to help form by logged-in user set to [_1] MB.',
15970: $contacts_hash{'contacts'}{'helpform'}{'maxsize'}).
15971: '</li>';
15972: }
15973: }
1.28 raeburn 15974: $resulttext .= '</ul>';
15975: } else {
1.160.6.78 raeburn 15976: $resulttext = &mt('No changes made to contacts and form settings');
1.28 raeburn 15977: }
15978: } else {
15979: $resulttext = '<span class="LC_error">'.
1.160.6.118.2 14(raebu 15980:23): &mt('An error occurred: [_1]',$putresult).'</span>';
1.28 raeburn 15981: }
15982: return $resulttext;
15983: }
15984:
1.160.6.98 raeburn 15985: sub modify_passwords {
15986: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
15987: my ($resulttext,%current,%changes,%newvalues,@oktypes,$errors,
15988: $updatedefaults,$updateconf);
15989: my $customfn = 'resetpw.html';
15990: if (ref($domconfig{'passwords'}) eq 'HASH') {
15991: %current = %{$domconfig{'passwords'}};
15992: }
15993: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
15994: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
15995: if (ref($types) eq 'ARRAY') {
15996: @oktypes = @{$types};
15997: }
15998: push(@oktypes,'default');
15999:
16000: my %titles = &Apache::lonlocal::texthash (
16001: intauth_cost => 'Encryption cost for bcrypt (positive integer)',
16002: intauth_check => 'Check bcrypt cost if authenticated',
16003: intauth_switch => 'Existing crypt-based switched to bcrypt on authentication',
16004: permanent => 'Permanent e-mail address',
16005: critical => 'Critical notification address',
16006: notify => 'Notification address',
16007: min => 'Minimum password length',
16008: max => 'Maximum password length',
16009: chars => 'Required characters',
16010: numsaved => 'Number of previous passwords to save',
16011: reset => 'Resetting Forgotten Password',
16012: intauth => 'Encryption of Stored Passwords (Internal Auth)',
16013: rules => 'Rules for LON-CAPA Passwords',
16014: crsownerchg => 'Course Owner Changing Student Passwords',
16015: username => 'Username',
16016: email => 'E-mail address',
16017: );
16018:
16019: #
16020: # Retrieve current domain configuration for internal authentication from $domconfig{'defaults'}.
16021: #
16022: my (%curr_defaults,%save_defaults);
16023: if (ref($domconfig{'defaults'}) eq 'HASH') {
16024: foreach my $key (keys(%{$domconfig{'defaults'}})) {
16025: if ($key =~ /^intauth_(cost|check|switch)$/) {
16026: $curr_defaults{$key} = $domconfig{'defaults'}{$key};
16027: } else {
16028: $save_defaults{$key} = $domconfig{'defaults'}{$key};
16029: }
16030: }
16031: }
16032: my %staticdefaults = (
16033: 'resetlink' => 2,
16034: 'resetcase' => \@oktypes,
16035: 'resetprelink' => 'both',
16036: 'resetemail' => ['critical','notify','permanent'],
16037: 'intauth_cost' => 10,
16038: 'intauth_check' => 0,
16039: 'intauth_switch' => 0,
16040: );
1.160.6.99 raeburn 16041: $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
1.160.6.98 raeburn 16042: foreach my $type (@oktypes) {
16043: $staticdefaults{'resetpostlink'}{$type} = ['email','username'];
16044: }
16045: my $linklife = $env{'form.passwords_link'};
16046: $linklife =~ s/^\s+|\s+$//g;
16047: if (($linklife =~ /^\d+(|\.\d*)$/) && ($linklife > 0)) {
16048: $newvalues{'resetlink'} = $linklife;
16049: if ($current{'resetlink'}) {
16050: if ($current{'resetlink'} ne $linklife) {
16051: $changes{'reset'} = 1;
16052: }
1.160.6.102 raeburn 16053: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16054: if ($staticdefaults{'resetlink'} ne $linklife) {
16055: $changes{'reset'} = 1;
16056: }
16057: }
16058: } elsif ($current{'resetlink'}) {
16059: $changes{'reset'} = 1;
16060: }
16061: my @casesens;
16062: my @posscase = &Apache::loncommon::get_env_multiple('form.passwords_case_sensitive');
16063: foreach my $case (sort(@posscase)) {
16064: if (grep(/^\Q$case\E$/,@oktypes)) {
16065: push(@casesens,$case);
16066: }
16067: }
16068: $newvalues{'resetcase'} = \@casesens;
16069: if (ref($current{'resetcase'}) eq 'ARRAY') {
16070: my @diffs = &Apache::loncommon::compare_arrays($current{'resetcase'},\@casesens);
16071: if (@diffs > 0) {
16072: $changes{'reset'} = 1;
16073: }
1.160.6.102 raeburn 16074: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16075: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetcase'},\@casesens);
16076: if (@diffs > 0) {
16077: $changes{'reset'} = 1;
16078: }
16079: }
16080: if ($env{'form.passwords_prelink'} =~ /^(both|either)$/) {
16081: $newvalues{'resetprelink'} = $env{'form.passwords_prelink'};
16082: if (exists($current{'resetprelink'})) {
16083: if ($current{'resetprelink'} ne $newvalues{'resetprelink'}) {
16084: $changes{'reset'} = 1;
16085: }
1.160.6.102 raeburn 16086: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16087: if ($staticdefaults{'resetprelink'} ne $newvalues{'resetprelink'}) {
16088: $changes{'reset'} = 1;
16089: }
16090: }
16091: } elsif ($current{'resetprelink'}) {
16092: $changes{'reset'} = 1;
16093: }
16094: foreach my $type (@oktypes) {
16095: my @possplink = &Apache::loncommon::get_env_multiple('form.passwords_postlink_'.$type);
16096: my @postlink;
16097: foreach my $item (sort(@possplink)) {
16098: if ($item =~ /^(email|username)$/) {
16099: push(@postlink,$item);
16100: }
16101: }
16102: $newvalues{'resetpostlink'}{$type} = \@postlink;
16103: unless ($changes{'reset'}) {
16104: if (ref($current{'resetpostlink'}) eq 'HASH') {
16105: if (ref($current{'resetpostlink'}{$type}) eq 'ARRAY') {
16106: my @diffs = &Apache::loncommon::compare_arrays($current{'resetpostlink'}{$type},\@postlink);
16107: if (@diffs > 0) {
16108: $changes{'reset'} = 1;
16109: }
16110: } else {
16111: $changes{'reset'} = 1;
16112: }
1.160.6.102 raeburn 16113: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16114: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetpostlink'}{$type},\@postlink);
16115: if (@diffs > 0) {
16116: $changes{'reset'} = 1;
16117: }
16118: }
16119: }
16120: }
16121: my @possemailsrc = &Apache::loncommon::get_env_multiple('form.passwords_emailsrc');
16122: my @resetemail;
16123: foreach my $item (sort(@possemailsrc)) {
16124: if ($item =~ /^(permanent|critical|notify)$/) {
16125: push(@resetemail,$item);
16126: }
16127: }
16128: $newvalues{'resetemail'} = \@resetemail;
16129: unless ($changes{'reset'}) {
16130: if (ref($current{'resetemail'}) eq 'ARRAY') {
16131: my @diffs = &Apache::loncommon::compare_arrays($current{'resetemail'},\@resetemail);
16132: if (@diffs > 0) {
16133: $changes{'reset'} = 1;
16134: }
1.160.6.102 raeburn 16135: } elsif (!ref($domconfig{passwords}) eq 'HASH') {
1.160.6.98 raeburn 16136: my @diffs = &Apache::loncommon::compare_arrays($staticdefaults{'resetemail'},\@resetemail);
16137: if (@diffs > 0) {
16138: $changes{'reset'} = 1;
16139: }
16140: }
16141: }
16142: if ($env{'form.passwords_stdtext'} == 0) {
16143: $newvalues{'resetremove'} = 1;
16144: unless ($current{'resetremove'}) {
16145: $changes{'reset'} = 1;
16146: }
16147: } elsif ($current{'resetremove'}) {
16148: $changes{'reset'} = 1;
16149: }
16150: if ($env{'form.passwords_customfile.filename'} ne '') {
16151: my $servadm = $r->dir_config('lonAdmEMail');
16152: my ($configuserok,$author_ok,$switchserver) =
16153: &config_check($dom,$confname,$servadm);
16154: my $error;
16155: if ($configuserok eq 'ok') {
16156: if ($switchserver) {
16157: $error = &mt("Upload of file containing domain-specific text is not permitted to this server: [_1]",$switchserver);
16158: } else {
16159: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 16160:23): my $modified = [];
1.160.6.98 raeburn 16161: my ($result,$customurl) =
1.160.6.118.2 14(raebu 16162:23): &Apache::lonconfigsettings::publishlogo($r,'upload','passwords_customfile',$dom,
16163:23): $confname,'customtext/resetpw','','',$customfn,
16164:23): $modified);
1.160.6.98 raeburn 16165: if ($result eq 'ok') {
16166: $newvalues{'resetcustom'} = $customurl;
16167: $changes{'reset'} = 1;
1.160.6.118.2 14(raebu 16168:23): &update_modify_urls($r,$modified);
1.160.6.98 raeburn 16169: } else {
16170: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$customfn,$result);
16171: }
16172: } else {
16173: $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);
16174: }
16175: }
16176: } else {
16177: $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);
16178: }
16179: if ($error) {
16180: &Apache::lonnet::logthis($error);
16181: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
16182: }
16183: } elsif ($current{'resetcustom'}) {
16184: if ($env{'form.passwords_custom_del'}) {
16185: $changes{'reset'} = 1;
16186: } else {
16187: $newvalues{'resetcustom'} = $current{'resetcustom'};
16188: }
16189: }
16190: $env{'form.intauth_cost'} =~ s/^\s+|\s+$//g;
16191: if (($env{'form.intauth_cost'} ne '') && ($env{'form.intauth_cost'} =~ /^\d+$/)) {
16192: $save_defaults{'intauth_cost'} = $env{'form.intauth_cost'};
16193: if ($save_defaults{'intauth_cost'} ne $curr_defaults{'intauth_cost'}) {
16194: $changes{'intauth'} = 1;
16195: }
16196: } else {
16197: $save_defaults{'intauth_cost'} = $curr_defaults{'intauth_cost'};
16198: }
16199: if ($env{'form.intauth_check'} =~ /^(0|1|2)$/) {
16200: $save_defaults{'intauth_check'} = $env{'form.intauth_check'};
16201: if ($save_defaults{'intauth_check'} ne $curr_defaults{'intauth_check'}) {
16202: $changes{'intauth'} = 1;
16203: }
16204: } else {
16205: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16206: }
16207: if ($env{'form.intauth_switch'} =~ /^(0|1|2)$/) {
16208: $save_defaults{'intauth_switch'} = $env{'form.intauth_switch'};
16209: if ($save_defaults{'intauth_switch'} ne $curr_defaults{'intauth_switch'}) {
16210: $changes{'intauth'} = 1;
16211: }
16212: } else {
16213: $save_defaults{'intauth_check'} = $curr_defaults{'intauth_check'};
16214: }
16215: foreach my $item ('cost','check','switch') {
16216: if ($save_defaults{'intauth_'.$item} ne $domdefaults{'intauth_'.$item}) {
16217: $domdefaults{'intauth_'.$item} = $save_defaults{'intauth_'.$item};
16218: $updatedefaults = 1;
16219: }
16220: }
1.160.6.118.2 5(raebur 16221:2): &password_rule_changes('passwords',\%newvalues,\%current,\%changes);
1.160.6.98 raeburn 16222: my %crsownerchg = (
16223: by => [],
16224: for => [],
16225: );
16226: foreach my $item ('by','for') {
16227: my @posstypes = &Apache::loncommon::get_env_multiple('form.passwords_crsowner_'.$item);
16228: foreach my $type (sort(@posstypes)) {
16229: if (grep(/^\Q$type\E$/,@oktypes)) {
16230: push(@{$crsownerchg{$item}},$type);
16231: }
16232: }
16233: }
16234: $newvalues{'crsownerchg'} = \%crsownerchg;
16235: if (ref($current{'crsownerchg'}) eq 'HASH') {
16236: foreach my $item ('by','for') {
16237: if (ref($current{'crsownerchg'}{$item}) eq 'ARRAY') {
16238: my @diffs = &Apache::loncommon::compare_arrays($current{'crsownerchg'}{$item},$crsownerchg{$item});
16239: if (@diffs > 0) {
16240: $changes{'crsownerchg'} = 1;
16241: last;
16242: }
16243: }
16244: }
1.160.6.102 raeburn 16245: } elsif (!(ref($domconfig{passwords}) eq 'HASH')) {
1.160.6.98 raeburn 16246: foreach my $item ('by','for') {
16247: if (@{$crsownerchg{$item}} > 0) {
16248: $changes{'crsownerchg'} = 1;
16249: last;
16250: }
16251: }
16252: }
16253:
16254: my %confighash = (
16255: defaults => \%save_defaults,
16256: passwords => \%newvalues,
16257: );
16258: &process_captcha('passwords',\%changes,$confighash{'passwords'},$domconfig{'passwords'});
16259:
16260: my $putresult = &Apache::lonnet::put_dom('configuration',\%confighash,$dom);
16261: if ($putresult eq 'ok') {
16262: if (keys(%changes) > 0) {
16263: $resulttext = &mt('Changes made: ').'<ul>';
16264: foreach my $key ('reset','intauth','rules','crsownerchg') {
16265: if ($changes{$key}) {
16266: unless ($key eq 'intauth') {
16267: $updateconf = 1;
16268: }
16269: $resulttext .= '<li>'.$titles{$key}.':<ul>';
16270: if ($key eq 'reset') {
16271: if ($confighash{'passwords'}{'captcha'} eq 'original') {
16272: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: original CAPTCHA').'</li>';
16273: } elsif ($confighash{'passwords'}{'captcha'} eq 'recaptcha') {
16274: $resulttext .= '<li>'.&mt('CAPTCHA validation set to use: reCAPTCHA').' '.
1.160.6.104 raeburn 16275: &mt('version: [_1]',$confighash{'passwords'}{'recaptchaversion'}).'<br />';
16276: if (ref($confighash{'passwords'}{'recaptchakeys'}) eq 'HASH') {
16277: $resulttext .= &mt('Public key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'public'}).'</br>'.
16278: &mt('Private key: [_1]',$confighash{'passwords'}{'recaptchakeys'}{'private'}).'</li>';
16279: }
1.160.6.98 raeburn 16280: } else {
16281: $resulttext .= '<li>'.&mt('No CAPTCHA validation').'</li>';
16282: }
16283: if ($confighash{'passwords'}{'resetlink'}) {
16284: $resulttext .= '<li>'.&mt('Reset link expiration set to [quant,_1,hour]',$confighash{'passwords'}{'resetlink'}).'</li>';
16285: } else {
16286: $resulttext .= '<li>'.&mt('No reset link expiration set.').' '.
16287: &mt('Will default to 2 hours').'</li>';
16288: }
16289: if (ref($confighash{'passwords'}{'resetcase'}) eq 'ARRAY') {
16290: if (@{$confighash{'passwords'}{'resetcase'}} == 0) {
16291: $resulttext .= '<li>'.&mt('User input for username and/or e-mail address not case sensitive for "Forgot Password" web form').'</li>';
16292: } else {
16293: my $casesens;
16294: foreach my $type (@{$confighash{'passwords'}{'resetcase'}}) {
16295: if ($type eq 'default') {
16296: $casesens .= $othertitle.', ';
16297: } elsif ($usertypes->{$type} ne '') {
16298: $casesens .= $usertypes->{$type}.', ';
16299: }
16300: }
16301: $casesens =~ s/\Q, \E$//;
16302: $resulttext .= '<li>'.&mt('"Forgot Password" web form input for username and/or e-mail address is case-sensitive for: [_1]',$casesens).'</li>';
16303: }
16304: } else {
16305: $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>';
16306: }
16307: if ($confighash{'passwords'}{'resetprelink'} eq 'either') {
16308: $resulttext .= '<li>'.&mt('Users can enter either a username or an e-mail address in "Forgot Password" web form').'</li>';
16309: } else {
16310: $resulttext .= '<li>'.&mt('Users can enter both a username and an e-mail address in "Forgot Password" web form').'</li>';
16311: }
16312: if (ref($confighash{'passwords'}{'resetpostlink'}) eq 'HASH') {
16313: my $output;
16314: if (ref($types) eq 'ARRAY') {
16315: foreach my $type (@{$types}) {
16316: if (ref($confighash{'passwords'}{'resetpostlink'}{$type}) eq 'ARRAY') {
16317: if (@{$confighash{'passwords'}{'resetpostlink'}{$type}} == 0) {
16318: $output .= $usertypes->{$type}.' -- '.&mt('none');
16319: } else {
16320: $output .= $usertypes->{$type}.' -- '.
16321: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{$type}})).'; ';
16322: }
16323: }
16324: }
16325: }
16326: if (ref($confighash{'passwords'}{'resetpostlink'}{'default'}) eq 'ARRAY') {
16327: if (@{$confighash{'passwords'}{'resetpostlink'}{'default'}} == 0) {
16328: $output .= $othertitle.' -- '.&mt('none');
16329: } else {
16330: $output .= $othertitle.' -- '.
16331: join(', ',map { $titles{$_}; } (@{$confighash{'passwords'}{'resetpostlink'}{'default'}}));
16332: }
16333: }
16334: if ($output) {
16335: $resulttext .= '<li>'.&mt('Information required for new password form (by user type) set to: [_1]',$output).'</li>';
16336: } else {
16337: $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>';
16338: }
16339: } else {
16340: $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>';
16341: }
16342: if (ref($confighash{'passwords'}{'resetemail'}) eq 'ARRAY') {
16343: if (@{$confighash{'passwords'}{'resetemail'}} > 0) {
16344: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$confighash{'passwords'}{'resetemail'}})).'</li>';
16345: } else {
16346: $resulttext .= '<li>'.&mt('E-mail address(es) in LON-CAPA used for verification will include: [_1]',join(', ',map { $titles{$_}; } @{$staticdefaults{'resetemail'}})).'</li>';
16347: }
16348: } else {
1.160.6.110 raeburn 16349: $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 16350: }
16351: if ($confighash{'passwords'}{'resetremove'}) {
16352: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form not shown').'</li>';
16353: } else {
16354: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" web form is shown').'</li>';
16355: }
16356: if ($confighash{'passwords'}{'resetcustom'}) {
16357: my $customlink = &Apache::loncommon::modal_link($confighash{'passwords'}{'resetcustom'},
1.160.6.104 raeburn 16358: &mt('custom text'),600,500,undef,undef,
16359: undef,undef,'background-color:#ffffff');
16360: $resulttext .= '<li>'.&mt('Preamble to "Forgot Password" form includes: [_1]',$customlink).'</li>';
1.160.6.98 raeburn 16361: } else {
16362: $resulttext .= '<li>'.&mt('No custom text included in preamble to "Forgot Password" form').'</li>';
16363: }
16364: } elsif ($key eq 'intauth') {
16365: foreach my $item ('cost','switch','check') {
16366: my $value = $save_defaults{$key.'_'.$item};
16367: if ($item eq 'switch') {
16368: my %optiondesc = &Apache::lonlocal::texthash (
16369: 0 => 'No',
16370: 1 => 'Yes',
16371: 2 => 'Yes, and copy existing passwd file to passwd.bak file',
16372: );
16373: if ($value =~ /^(0|1|2)$/) {
16374: $value = $optiondesc{$value};
16375: } else {
16376: $value = &mt('none -- defaults to No');
16377: }
16378: } elsif ($item eq 'check') {
16379: my %optiondesc = &Apache::lonlocal::texthash (
16380: 0 => 'No',
16381: 1 => 'Yes, allow login then update passwd file using default cost (if higher)',
16382: 2 => 'Yes, disallow login if stored cost is less than domain default',
16383: );
16384: if ($value =~ /^(0|1|2)$/) {
16385: $value = $optiondesc{$value};
16386: } else {
16387: $value = &mt('none -- defaults to No');
16388: }
16389: }
16390: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$titles{$key.'_'.$item},$value).'</li>';
16391: }
16392: } elsif ($key eq 'rules') {
16393: foreach my $rule ('min','max','numsaved') {
16394: if ($confighash{'passwords'}{$rule} eq '') {
16395: if ($rule eq 'min') {
16396: $resulttext .= '<li>'.&mt('[_1] not set.',$titles{$rule});
1.160.6.99 raeburn 16397: ' '.&mt('Default of [_1] will be used',
16398: $Apache::lonnet::passwdmin).'</li>';
1.160.6.98 raeburn 16399: } else {
16400: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{$rule}).'</li>';
16401: }
16402: } else {
16403: $resulttext .= '<li>'.&mt('[_1] set to [_2]',$titles{$rule},$confighash{'passwords'}{$rule}).'</li>';
16404: }
16405: }
1.160.6.104 raeburn 16406: if (ref($confighash{'passwords'}{'chars'}) eq 'ARRAY') {
16407: if (@{$confighash{'passwords'}{'chars'}} > 0) {
16408: my %rulenames = &Apache::lonlocal::texthash(
16409: uc => 'At least one upper case letter',
16410: lc => 'At least one lower case letter',
16411: num => 'At least one number',
16412: spec => 'At least one non-alphanumeric',
16413: );
16414: my $needed = '<ul><li>'.
16415: join('</li><li>',map {$rulenames{$_} } @{$confighash{'passwords'}{'chars'}}).
16416: '</li></ul>';
16417: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$titles{'chars'},$needed).'</li>';
16418: } else {
16419: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16420: }
16421: } else {
16422: $resulttext .= '<li>'.&mt('[_1] set to none',$titles{'chars'}).'</li>';
16423: }
1.160.6.98 raeburn 16424: } elsif ($key eq 'crsownerchg') {
16425: if (ref($confighash{'passwords'}{'crsownerchg'}) eq 'HASH') {
16426: if ((@{$confighash{'passwords'}{'crsownerchg'}{'by'}} == 0) ||
16427: (@{$confighash{'passwords'}{'crsownerchg'}{'for'}} == 0)) {
16428: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16429: } else {
16430: my %crsownerstr;
16431: foreach my $item ('by','for') {
16432: if (ref($confighash{'passwords'}{'crsownerchg'}{$item}) eq 'ARRAY') {
16433: foreach my $type (@{$confighash{'passwords'}{'crsownerchg'}{$item}}) {
16434: if ($type eq 'default') {
16435: $crsownerstr{$item} .= $othertitle.', ';
16436: } elsif ($usertypes->{$type} ne '') {
16437: $crsownerstr{$item} .= $usertypes->{$type}.', ';
16438: }
16439: }
16440: $crsownerstr{$item} =~ s/\Q, \E$//;
16441: }
16442: }
16443: $resulttext .= '<li>'.&mt('Course owner (with status: [_1]) may change passwords for students (with status: [_2]).',
16444: $crsownerstr{'by'},$crsownerstr{'for'}).'</li>';
16445: }
16446: } else {
16447: $resulttext .= '<li>'.&mt('Course owner may not change student passwords.').'</li>';
16448: }
16449: }
16450: $resulttext .= '</ul></li>';
16451: }
16452: }
16453: $resulttext .= '</ul>';
16454: } else {
16455: $resulttext = &mt('No changes made to password settings');
16456: }
16457: my $cachetime = 24*60*60;
16458: if ($updatedefaults) {
16459: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
16460: if (ref($lastactref) eq 'HASH') {
16461: $lastactref->{'domdefaults'} = 1;
16462: }
16463: }
16464: if ($updateconf) {
16465: &Apache::lonnet::do_cache_new('passwdconf',$dom,$confighash{'passwords'},$cachetime);
16466: if (ref($lastactref) eq 'HASH') {
16467: $lastactref->{'passwdconf'} = 1;
16468: }
16469: }
16470: } else {
16471: $resulttext = '<span class="LC_error">'.
16472: &mt('An error occurred: [_1]',$putresult).'</span>';
16473: }
16474: if ($errors) {
16475: $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
16476: $errors.'</ul></p>';
16477: }
16478: return $resulttext;
16479: }
16480:
1.160.6.118.2 5(raebur 16481:2): sub password_rule_changes {
16482:2): my ($prefix,$newvalues,$current,$changes) = @_;
16483:2): return unless ((ref($newvalues) eq 'HASH') &&
16484:2): (ref($current) eq 'HASH') &&
16485:2): (ref($changes) eq 'HASH'));
16486:2): my (@rules,%staticdefaults);
16487:2): if ($prefix eq 'passwords') {
16488:2): @rules = ('min','max','numsaved');
14(raebu 16489:23): } elsif (($prefix eq 'ltisecrets') || ($prefix eq 'toolsecrets')) {
5(raebur 16490:2): @rules = ('min','max');
16491:2): }
16492:2): $staticdefaults{'min'} = $Apache::lonnet::passwdmin;
16493:2): foreach my $rule (@rules) {
16494:2): $env{'form.'.$prefix.'_'.$rule} =~ s/^\s+|\s+$//g;
16495:2): my $ruleok;
16496:2): if ($rule eq 'min') {
16497:2): if ($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) {
16498:2): if ($env{'form.'.$prefix.'_'.$rule} >= $staticdefaults{$rule}) {
16499:2): $ruleok = 1;
16500:2): }
16501:2): }
16502:2): } elsif (($env{'form.'.$prefix.'_'.$rule} =~ /^\d+$/) &&
16503:2): ($env{'form.'.$prefix.'_'.$rule} ne '0')) {
16504:2): $ruleok = 1;
16505:2): }
16506:2): if ($ruleok) {
16507:2): $newvalues->{$rule} = $env{'form.'.$prefix.'_'.$rule};
16508:2): if (exists($current->{$rule})) {
16509:2): if ($newvalues->{$rule} ne $current->{$rule}) {
16510:2): $changes->{'rules'} = 1;
16511:2): }
16512:2): } elsif ($rule eq 'min') {
16513:2): if ($staticdefaults{$rule} ne $newvalues->{$rule}) {
16514:2): $changes->{'rules'} = 1;
16515:2): }
16516:2): } else {
16517:2): $changes->{'rules'} = 1;
16518:2): }
16519:2): } elsif (exists($current->{$rule})) {
16520:2): $changes->{'rules'} = 1;
16521:2): }
16522:2): }
16523:2): my @posschars = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_chars');
16524:2): my @chars;
16525:2): foreach my $item (sort(@posschars)) {
16526:2): if ($item =~ /^(uc|lc|num|spec)$/) {
16527:2): push(@chars,$item);
16528:2): }
16529:2): }
16530:2): $newvalues->{'chars'} = \@chars;
16531:2): unless ($changes->{'rules'}) {
16532:2): if (ref($current->{'chars'}) eq 'ARRAY') {
16533:2): my @diffs = &Apache::loncommon::compare_arrays($current->{'chars'},\@chars);
16534:2): if (@diffs > 0) {
16535:2): $changes->{'rules'} = 1;
16536:2): }
16537:2): } else {
16538:2): if (@chars > 0) {
16539:2): $changes->{'rules'} = 1;
16540:2): }
16541:2): }
16542:2): }
16543:2): return;
16544:2): }
16545:2):
1.28 raeburn 16546: sub modify_usercreation {
1.27 raeburn 16547: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 16548: my ($resulttext,%curr_usercreation,%changes,%authallowed,%cancreate,%save_usercreate);
1.43 raeburn 16549: my $warningmsg;
1.27 raeburn 16550: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16551: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
1.160.6.34 raeburn 16552: if ($key eq 'cancreate') {
16553: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16554: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
1.160.6.93 raeburn 16555: if (($item eq 'requestcrs') || ($item eq 'course') || ($item eq 'author')) {
1.160.6.34 raeburn 16556: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.93 raeburn 16557: } else {
16558: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
1.160.6.34 raeburn 16559: }
1.50 raeburn 16560: }
1.43 raeburn 16561: }
1.160.6.34 raeburn 16562: } elsif ($key eq 'email_rule') {
16563: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16564: } else {
16565: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
1.43 raeburn 16566: }
16567: }
1.34 raeburn 16568: }
1.160.6.34 raeburn 16569: my @username_rule = &Apache::loncommon::get_env_multiple('form.username_rule');
16570: my @id_rule = &Apache::loncommon::get_env_multiple('form.id_rule');
16571: my @contexts = ('author','course','requestcrs');
16572: foreach my $item(@contexts) {
16573: $cancreate{$item} = $env{'form.can_createuser_'.$item};
1.93 raeburn 16574: }
1.34 raeburn 16575: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
16576: foreach my $item (@contexts) {
1.160.6.34 raeburn 16577: if ($curr_usercreation{'cancreate'}{$item} ne $cancreate{$item}) {
16578: push(@{$changes{'cancreate'}},$item);
1.50 raeburn 16579: }
1.27 raeburn 16580: }
1.34 raeburn 16581: } elsif (ref($curr_usercreation{'cancreate'}) eq 'ARRAY') {
16582: foreach my $item (@contexts) {
1.43 raeburn 16583: if (!grep(/^\Q$item\E$/,@{$curr_usercreation{'cancreate'}})) {
1.34 raeburn 16584: if ($cancreate{$item} ne 'any') {
16585: push(@{$changes{'cancreate'}},$item);
16586: }
16587: } else {
16588: if ($cancreate{$item} ne 'none') {
16589: push(@{$changes{'cancreate'}},$item);
16590: }
1.27 raeburn 16591: }
16592: }
16593: } else {
1.43 raeburn 16594: foreach my $item (@contexts) {
1.34 raeburn 16595: push(@{$changes{'cancreate'}},$item);
16596: }
1.27 raeburn 16597: }
1.34 raeburn 16598:
1.27 raeburn 16599: if (ref($curr_usercreation{'username_rule'}) eq 'ARRAY') {
16600: foreach my $type (@{$curr_usercreation{'username_rule'}}) {
16601: if (!grep(/^\Q$type\E$/,@username_rule)) {
16602: push(@{$changes{'username_rule'}},$type);
16603: }
16604: }
16605: foreach my $type (@username_rule) {
16606: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'username_rule'}})) {
16607: push(@{$changes{'username_rule'}},$type);
16608: }
16609: }
16610: } else {
16611: push(@{$changes{'username_rule'}},@username_rule);
16612: }
16613:
1.32 raeburn 16614: if (ref($curr_usercreation{'id_rule'}) eq 'ARRAY') {
16615: foreach my $type (@{$curr_usercreation{'id_rule'}}) {
16616: if (!grep(/^\Q$type\E$/,@id_rule)) {
16617: push(@{$changes{'id_rule'}},$type);
16618: }
16619: }
16620: foreach my $type (@id_rule) {
16621: if (!grep(/^\Q$type\E$/,@{$curr_usercreation{'id_rule'}})) {
16622: push(@{$changes{'id_rule'}},$type);
16623: }
16624: }
16625: } else {
16626: push(@{$changes{'id_rule'}},@id_rule);
16627: }
16628:
1.43 raeburn 16629: my @authen_contexts = ('author','course','domain');
1.160.6.118.2 14(raebu 16630:23): my @authtypes = ('int','krb4','krb5','loc','lti');
1.28 raeburn 16631: my %authhash;
1.43 raeburn 16632: foreach my $item (@authen_contexts) {
1.28 raeburn 16633: my @authallowed = &Apache::loncommon::get_env_multiple('form.'.$item.'_auth');
16634: foreach my $auth (@authtypes) {
16635: if (grep(/^\Q$auth\E$/,@authallowed)) {
16636: $authhash{$item}{$auth} = 1;
16637: } else {
16638: $authhash{$item}{$auth} = 0;
16639: }
16640: }
16641: }
16642: if (ref($curr_usercreation{'authtypes'}) eq 'HASH') {
1.43 raeburn 16643: foreach my $item (@authen_contexts) {
1.28 raeburn 16644: if (ref($curr_usercreation{'authtypes'}{$item}) eq 'HASH') {
16645: foreach my $auth (@authtypes) {
16646: if ($authhash{$item}{$auth} ne $curr_usercreation{'authtypes'}{$item}{$auth}) {
16647: push(@{$changes{'authtypes'}},$item);
16648: last;
16649: }
16650: }
16651: }
16652: }
16653: } else {
1.43 raeburn 16654: foreach my $item (@authen_contexts) {
1.28 raeburn 16655: push(@{$changes{'authtypes'}},$item);
16656: }
16657: }
16658:
1.160.6.34 raeburn 16659: $save_usercreate{'cancreate'}{'course'} = $cancreate{'course'};
16660: $save_usercreate{'cancreate'}{'author'} = $cancreate{'author'};
16661: $save_usercreate{'cancreate'}{'requestcrs'} = $cancreate{'requestcrs'};
16662: $save_usercreate{'id_rule'} = \@id_rule;
16663: $save_usercreate{'username_rule'} = \@username_rule,
16664: $save_usercreate{'authtypes'} = \%authhash;
16665:
1.27 raeburn 16666: my %usercreation_hash = (
1.160.6.34 raeburn 16667: usercreation => \%save_usercreate,
16668: );
1.27 raeburn 16669:
16670: my $putresult = &Apache::lonnet::put_dom('configuration',\%usercreation_hash,
16671: $dom);
1.50 raeburn 16672:
1.160.6.34 raeburn 16673: if ($putresult eq 'ok') {
16674: if (keys(%changes) > 0) {
16675: $resulttext = &mt('Changes made:').'<ul>';
16676: if (ref($changes{'cancreate'}) eq 'ARRAY') {
16677: my %lt = &usercreation_types();
16678: foreach my $type (@{$changes{'cancreate'}}) {
16679: my $chgtext = $lt{$type}.', ';
16680: if ($cancreate{$type} eq 'none') {
16681: $chgtext .= &mt('creation of new users is not permitted, except by a Domain Coordinator.');
16682: } elsif ($cancreate{$type} eq 'any') {
16683: $chgtext .= &mt('creation of new users is permitted for both institutional and non-institutional usernames.');
16684: } elsif ($cancreate{$type} eq 'official') {
16685: $chgtext .= &mt('creation of new users is only permitted for institutional usernames.');
16686: } elsif ($cancreate{$type} eq 'unofficial') {
16687: $chgtext .= &mt('creation of new users is only permitted for non-institutional usernames.');
16688: }
16689: $resulttext .= '<li>'.$chgtext.'</li>';
16690: }
16691: }
16692: if (ref($changes{'username_rule'}) eq 'ARRAY') {
16693: my ($rules,$ruleorder) =
16694: &Apache::lonnet::inst_userrules($dom,'username');
16695: my $chgtext = '<ul>';
16696: foreach my $type (@username_rule) {
16697: if (ref($rules->{$type}) eq 'HASH') {
16698: $chgtext .= '<li>'.$rules->{$type}{'name'}.'</li>';
16699: }
16700: }
16701: $chgtext .= '</ul>';
16702: if (@username_rule > 0) {
16703: $resulttext .= '<li>'.&mt('Usernames with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16704: } else {
16705: $resulttext .= '<li>'.&mt('There are now no username formats restricted to verified users in the institutional directory.').'</li>';
16706: }
16707: }
16708: if (ref($changes{'id_rule'}) eq 'ARRAY') {
16709: my ($idrules,$idruleorder) =
16710: &Apache::lonnet::inst_userrules($dom,'id');
16711: my $chgtext = '<ul>';
16712: foreach my $type (@id_rule) {
16713: if (ref($idrules->{$type}) eq 'HASH') {
16714: $chgtext .= '<li>'.$idrules->{$type}{'name'}.'</li>';
16715: }
16716: }
16717: $chgtext .= '</ul>';
16718: if (@id_rule > 0) {
16719: $resulttext .= '<li>'.&mt('IDs with the following formats are restricted to verified users in the institutional directory: ').$chgtext.'</li>';
16720: } else {
16721: $resulttext .= '<li>'.&mt('There are now no ID formats restricted to verified users in the institutional directory.').'</li>';
16722: }
16723: }
16724: my %authname = &authtype_names();
16725: my %context_title = &context_names();
16726: if (ref($changes{'authtypes'}) eq 'ARRAY') {
16727: my $chgtext = '<ul>';
16728: foreach my $type (@{$changes{'authtypes'}}) {
16729: my @allowed;
16730: $chgtext .= '<li><span class="LC_cusr_emph">'.$context_title{$type}.'</span> - '.&mt('assignable authentication types: ');
16731: foreach my $auth (@authtypes) {
16732: if ($authhash{$type}{$auth}) {
16733: push(@allowed,$authname{$auth});
16734: }
16735: }
16736: if (@allowed > 0) {
16737: $chgtext .= join(', ',@allowed).'</li>';
16738: } else {
16739: $chgtext .= &mt('none').'</li>';
16740: }
16741: }
16742: $chgtext .= '</ul>';
16743: $resulttext .= '<li>'.&mt('Authentication types available for assignment to new users').'<br />'.$chgtext;
16744: $resulttext .= '</li>';
16745: }
16746: $resulttext .= '</ul>';
16747: } else {
16748: $resulttext = &mt('No changes made to user creation settings');
16749: }
16750: } else {
16751: $resulttext = '<span class="LC_error">'.
16752: &mt('An error occurred: [_1]',$putresult).'</span>';
16753: }
16754: if ($warningmsg ne '') {
16755: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
16756: }
16757: return $resulttext;
16758: }
16759:
16760: sub modify_selfcreation {
1.160.6.93 raeburn 16761: my ($dom,$lastactref,%domconfig) = @_;
16762: my ($resulttext,$warningmsg,%curr_usercreation,%curr_usermodify,%curr_inststatus,%changes,%cancreate);
16763: my (%save_usercreate,%save_usermodify,%save_inststatus,@types,%usertypes);
16764: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
16765: my ($othertitle,$usertypesref,$typesref) = &Apache::loncommon::sorted_inst_types($dom);
16766: if (ref($typesref) eq 'ARRAY') {
16767: @types = @{$typesref};
16768: }
16769: if (ref($usertypesref) eq 'HASH') {
16770: %usertypes = %{$usertypesref};
1.160.6.35 raeburn 16771: }
1.160.6.93 raeburn 16772: $usertypes{'default'} = $othertitle;
1.160.6.34 raeburn 16773: #
16774: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usercreation'}.
16775: #
16776: if (ref($domconfig{'usercreation'}) eq 'HASH') {
16777: foreach my $key (keys(%{$domconfig{'usercreation'}})) {
16778: if ($key eq 'cancreate') {
16779: if (ref($domconfig{'usercreation'}{$key}) eq 'HASH') {
16780: foreach my $item (keys(%{$domconfig{'usercreation'}{$key}})) {
16781: if (($item eq 'selfcreate') || ($item eq 'statustocreate') ||
1.160.6.93 raeburn 16782: ($item eq 'captcha') || ($item eq 'recaptchakeys') ||
16783: ($item eq 'recaptchaversion') || ($item eq 'notify') ||
16784: ($item eq 'emailusername') || ($item eq 'shibenv') ||
16785: ($item eq 'selfcreateprocessing') || ($item eq 'emailverified') ||
16786: ($item eq 'emailoptions') || ($item eq 'emaildomain')) {
1.160.6.34 raeburn 16787: $curr_usercreation{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16788: } else {
16789: $save_usercreate{$key}{$item} = $domconfig{'usercreation'}{$key}{$item};
16790: }
16791: }
16792: }
16793: } elsif ($key eq 'email_rule') {
16794: $curr_usercreation{$key} = $domconfig{'usercreation'}{$key};
16795: } else {
16796: $save_usercreate{$key} = $domconfig{'usercreation'}{$key};
16797: }
16798: }
16799: }
16800: #
16801: # Retrieve current domain configuration for self-creation of usernames from $domconfig{'usermodification'}.
16802: #
16803: if (ref($domconfig{'usermodification'}) eq 'HASH') {
16804: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
16805: if ($key eq 'selfcreate') {
16806: $curr_usermodify{$key} = $domconfig{'usermodification'}{$key};
16807: } else {
16808: $save_usermodify{$key} = $domconfig{'usermodification'}{$key};
16809: }
16810: }
16811: }
1.160.6.93 raeburn 16812: #
16813: # Retrieve current domain configuration for institutional status types from $domconfig{'inststatus'}.
16814: #
16815: if (ref($domconfig{'inststatus'}) eq 'HASH') {
16816: foreach my $key (keys(%{$domconfig{'inststatus'}})) {
16817: if ($key eq 'inststatusguest') {
16818: $curr_inststatus{$key} = $domconfig{'inststatus'}{$key};
16819: } else {
16820: $save_inststatus{$key} = $domconfig{'inststatus'}{$key};
16821: }
16822: }
16823: }
1.160.6.34 raeburn 16824:
16825: my @contexts = ('selfcreate');
16826: @{$cancreate{'selfcreate'}} = ();
16827: %{$cancreate{'emailusername'}} = ();
1.160.6.93 raeburn 16828: if (@types) {
16829: @{$cancreate{'statustocreate'}} = ();
16830: }
1.160.6.40 raeburn 16831: %{$cancreate{'selfcreateprocessing'}} = ();
1.160.6.44 raeburn 16832: %{$cancreate{'shibenv'}} = ();
1.160.6.93 raeburn 16833: %{$cancreate{'emailverified'}} = ();
16834: %{$cancreate{'emailoptions'}} = ();
16835: %{$cancreate{'emaildomain'}} = ();
1.50 raeburn 16836: my %selfcreatetypes = (
16837: sso => 'users authenticated by institutional single sign on',
16838: login => 'users authenticated by institutional log-in',
1.160.6.93 raeburn 16839: email => 'users verified by e-mail',
1.50 raeburn 16840: );
1.160.6.34 raeburn 16841: #
16842: # Populate $cancreate{'selfcreate'} array reference with types of user, for which self-creation of user accounts
16843: # is permitted.
16844: #
1.160.6.93 raeburn 16845: my ($emailrules,$emailruleorder) = &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.40 raeburn 16846:
1.160.6.93 raeburn 16847: my (@statuses,%email_rule);
1.160.6.35 raeburn 16848: foreach my $item ('login','sso','email') {
1.160.6.34 raeburn 16849: if ($item eq 'email') {
1.160.6.40 raeburn 16850: if ($env{'form.cancreate_email'}) {
1.160.6.93 raeburn 16851: if (@types) {
16852: my @poss_statuses = &Apache::loncommon::get_env_multiple('form.selfassign');
16853: foreach my $status (@poss_statuses) {
16854: if (grep(/^\Q$status\E$/,(@types,'default'))) {
16855: push(@statuses,$status);
16856: }
16857: }
16858: $save_inststatus{'inststatusguest'} = \@statuses;
16859: } else {
16860: push(@statuses,'default');
16861: }
16862: if (@statuses) {
16863: my %curr_rule;
16864: if (ref($curr_usercreation{'email_rule'}) eq 'ARRAY') {
16865: foreach my $type (@statuses) {
16866: $curr_rule{$type} = $curr_usercreation{'email_rule'};
16867: }
16868: } elsif (ref($curr_usercreation{'email_rule'}) eq 'HASH') {
16869: foreach my $type (@statuses) {
16870: $curr_rule{$type} = $curr_usercreation{'email_rule'}{$type};
16871: }
16872: }
16873: push(@{$cancreate{'selfcreate'}},'email');
16874: push(@contexts,('selfcreateprocessing','emailverified','emailoptions'));
16875: my %curremaildom;
16876: if (ref($curr_usercreation{'cancreate'}{'emaildomain'}) eq 'HASH') {
16877: %curremaildom = %{$curr_usercreation{'cancreate'}{'emaildomain'}};
16878: }
16879: foreach my $type (@statuses) {
16880: if ($env{'form.cancreate_emailprocess_'.$type} =~ /^(?:approval|automatic)$/) {
16881: $cancreate{'selfcreateprocessing'}{$type} = $env{'form.cancreate_emailprocess_'.$type};
16882: }
16883: if ($env{'form.cancreate_usernameoptions_'.$type} =~ /^(?:all|first|free)$/) {
16884: $cancreate{'emailverified'}{$type} = $env{'form.cancreate_usernameoptions_'.$type};
16885: }
16886: if ($env{'form.cancreate_emailoptions_'.$type} =~ /^(any|inst|noninst|custom)$/) {
16887: #
16888: # Retrieve rules (if any) governing types of e-mail address which may be used to verify a username.
16889: #
16890: my $chosen = $1;
16891: if (($chosen eq 'inst') || ($chosen eq 'noninst')) {
16892: my $emaildom;
16893: if ($env{'form.cancreate_emaildomain_'.$chosen.'_'.$type} =~ /^\@[^\@]+$/) {
16894: $emaildom = $env{'form.cancreate_emaildomain_'.$chosen.'_'.$type};
16895: $cancreate{'emaildomain'}{$type}{$chosen} = $emaildom;
16896: if (ref($curremaildom{$type}) eq 'HASH') {
16897: if (exists($curremaildom{$type}{$chosen})) {
16898: if ($curremaildom{$type}{$chosen} ne $emaildom) {
16899: push(@{$changes{'cancreate'}},'emaildomain');
16900: }
16901: } elsif ($emaildom ne '') {
16902: push(@{$changes{'cancreate'}},'emaildomain');
16903: }
16904: } elsif ($emaildom ne '') {
16905: push(@{$changes{'cancreate'}},'emaildomain');
16906: }
16907: }
16908: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16909: } elsif ($chosen eq 'custom') {
16910: my @possemail_rules = &Apache::loncommon::get_env_multiple('form.email_rule_'.$type);
16911: $email_rule{$type} = [];
16912: if (ref($emailrules) eq 'HASH') {
16913: foreach my $rule (@possemail_rules) {
16914: if (exists($emailrules->{$rule})) {
16915: push(@{$email_rule{$type}},$rule);
16916: }
16917: }
16918: }
16919: if (@{$email_rule{$type}}) {
16920: $cancreate{'emailoptions'}{$type} = 'custom';
16921: if (ref($curr_rule{$type}) eq 'ARRAY') {
16922: if (@{$curr_rule{$type}} > 0) {
16923: foreach my $rule (@{$curr_rule{$type}}) {
16924: if (!grep(/^\Q$rule\E$/,@{$email_rule{$type}})) {
16925: push(@{$changes{'email_rule'}},$type);
16926: }
16927: }
16928: }
16929: foreach my $type (@{$email_rule{$type}}) {
16930: if (!grep(/^\Q$type\E$/,@{$curr_rule{$type}})) {
16931: push(@{$changes{'email_rule'}},$type);
16932: }
16933: }
16934: } else {
16935: push(@{$changes{'email_rule'}},$type);
16936: }
16937: }
16938: } else {
16939: $cancreate{'emailoptions'}{$type} = $env{'form.cancreate_emailoptions_'.$type};
16940: }
16941: }
16942: }
16943: if (@types) {
16944: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16945: my @changed = &Apache::loncommon::compare_arrays(\@statuses,$curr_inststatus{'inststatusguest'});
16946: if (@changed) {
16947: push(@{$changes{'inststatus'}},'inststatusguest');
16948: }
16949: } else {
16950: push(@{$changes{'inststatus'}},'inststatusguest');
16951: }
16952: }
16953: } else {
16954: delete($env{'form.cancreate_email'});
16955: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16956: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16957: push(@{$changes{'inststatus'}},'inststatusguest');
16958: }
16959: }
16960: }
16961: } else {
16962: $save_inststatus{'inststatusguest'} = [];
16963: if (ref($curr_inststatus{'inststatusguest'}) eq 'ARRAY') {
16964: if (@{$curr_inststatus{'inststatusguest'}} > 0) {
16965: push(@{$changes{'inststatus'}},'inststatusguest');
1.160.6.40 raeburn 16966: }
16967: }
1.160.6.34 raeburn 16968: }
16969: } else {
16970: if ($env{'form.cancreate_'.$item}) {
16971: push(@{$cancreate{'selfcreate'}},$item);
16972: }
16973: }
16974: }
1.160.6.93 raeburn 16975: my (%userinfo,%savecaptcha);
1.160.6.34 raeburn 16976: my ($infofields,$infotitles) = &Apache::loncommon::emailusername_info();
16977: #
1.160.6.35 raeburn 16978: # Populate $cancreate{'emailusername'}{$type} hash ref with information fields (if new user will provide data
16979: # 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 16980: #
1.160.6.40 raeburn 16981:
1.160.6.48 raeburn 16982: if ($env{'form.cancreate_email'}) {
1.160.6.37 raeburn 16983: push(@contexts,'emailusername');
1.160.6.93 raeburn 16984: if (@statuses) {
16985: foreach my $type (@statuses) {
1.160.6.35 raeburn 16986: if (ref($infofields) eq 'ARRAY') {
16987: foreach my $field (@{$infofields}) {
16988: if ($env{'form.canmodify_emailusername_'.$type.'_'.$field} =~ /^(required|optional)$/) {
16989: $cancreate{'emailusername'}{$type}{$field} = $1;
16990: }
16991: }
1.160.6.34 raeburn 16992: }
16993: }
16994: }
16995: #
16996: # Populate $cancreate{'notify'} hash ref with names of Domain Coordinators who are to be notified of
1.160.6.93 raeburn 16997: # queued requests for self-creation of account verified by e-mail.
1.160.6.34 raeburn 16998: #
16999:
17000: my @approvalnotify = &Apache::loncommon::get_env_multiple('form.selfcreationnotifyapproval');
17001: @approvalnotify = sort(@approvalnotify);
17002: $cancreate{'notify'}{'approval'} = join(',',@approvalnotify);
17003: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17004: if (ref($curr_usercreation{'cancreate'}{'notify'}) eq 'HASH') {
17005: if ($curr_usercreation{'cancreate'}{'notify'}{'approval'} ne $cancreate{'notify'}{'approval'}) {
17006: push(@{$changes{'cancreate'}},'notify');
17007: }
17008: } else {
17009: if ($cancreate{'notify'}{'approval'}) {
17010: push(@{$changes{'cancreate'}},'notify');
17011: }
17012: }
17013: } elsif ($cancreate{'notify'}{'approval'}) {
17014: push(@{$changes{'cancreate'}},'notify');
17015: }
17016:
17017: &process_captcha('cancreate',\%changes,\%savecaptcha,$curr_usercreation{'cancreate'});
17018: }
17019: #
1.160.6.40 raeburn 17020: # Check if domain default is set appropriately, if self-creation of accounts is to be available for
1.160.6.34 raeburn 17021: # institutional log-in.
17022: #
17023: if (grep(/^login$/,@{$cancreate{'selfcreate'}})) {
17024: if (!((($domdefaults{'auth_def'} =~/^krb/) && ($domdefaults{'auth_arg_def'} ne '')) ||
17025: ($domdefaults{'auth_def'} eq 'localauth'))) {
17026: $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.').' '.
17027: &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.');
17028: }
17029: }
17030: my @fields = ('lastname','firstname','middlename','generation',
17031: 'permanentemail','id');
1.160.6.44 raeburn 17032: my @shibfields = (@fields,'inststatus');
1.160.6.34 raeburn 17033: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17034: #
17035: # Where usernames may created for institutional log-in and/or institutional single sign on:
17036: # (a) populate $cancreate{'statustocreate'} array reference with institutional status types who
17037: # may self-create accounts
17038: # (b) populate $save_usermodify{'selfcreate'} hash reference with status types, and information fields
17039: # which the user may supply, if institutional data is unavailable.
17040: #
17041: if (($env{'form.cancreate_login'}) || ($env{'form.cancreate_sso'})) {
1.160.6.93 raeburn 17042: if (@types) {
17043: @{$cancreate{'statustocreate'}} = &Apache::loncommon::get_env_multiple('form.statustocreate');
17044: push(@contexts,'statustocreate');
17045: foreach my $type (@types) {
1.160.6.34 raeburn 17046: my @modifiable = &Apache::loncommon::get_env_multiple('form.canmodify_'.$type);
17047: foreach my $field (@fields) {
17048: if (grep(/^\Q$field\E$/,@modifiable)) {
17049: $save_usermodify{'selfcreate'}{$type}{$field} = 1;
17050: } else {
17051: $save_usermodify{'selfcreate'}{$type}{$field} = 0;
17052: }
17053: }
17054: }
17055: if (ref($curr_usermodify{'selfcreate'}) eq 'HASH') {
1.160.6.93 raeburn 17056: foreach my $type (@types) {
1.160.6.34 raeburn 17057: if (ref($curr_usermodify{'selfcreate'}{$type}) eq 'HASH') {
17058: foreach my $field (@fields) {
17059: if ($save_usermodify{'selfcreate'}{$type}{$field} ne
17060: $curr_usermodify{'selfcreate'}{$type}{$field}) {
17061: push(@{$changes{'selfcreate'}},$type);
17062: last;
17063: }
17064: }
17065: }
17066: }
17067: } else {
1.160.6.93 raeburn 17068: foreach my $type (@types) {
1.160.6.34 raeburn 17069: push(@{$changes{'selfcreate'}},$type);
17070: }
17071: }
17072: }
1.160.6.44 raeburn 17073: foreach my $field (@shibfields) {
17074: if ($env{'form.shibenv_'.$field} ne '') {
17075: $cancreate{'shibenv'}{$field} = $env{'form.shibenv_'.$field};
17076: }
17077: }
17078: if (ref($curr_usercreation{'cancreate'}) eq 'HASH') {
17079: if (ref($curr_usercreation{'cancreate'}{'shibenv'}) eq 'HASH') {
17080: foreach my $field (@shibfields) {
17081: if ($env{'form.shibenv_'.$field} ne $curr_usercreation{'cancreate'}{'shibenv'}{$field}) {
17082: push(@{$changes{'cancreate'}},'shibenv');
17083: }
17084: }
17085: } else {
17086: foreach my $field (@shibfields) {
17087: if ($env{'form.shibenv_'.$field}) {
17088: push(@{$changes{'cancreate'}},'shibenv');
17089: last;
17090: }
17091: }
17092: }
17093: }
1.160.6.34 raeburn 17094: }
17095: foreach my $item (@contexts) {
17096: if (ref($curr_usercreation{'cancreate'}{$item}) eq 'ARRAY') {
17097: foreach my $curr (@{$curr_usercreation{'cancreate'}{$item}}) {
17098: if (ref($cancreate{$item}) eq 'ARRAY') {
17099: if (!grep(/^$curr$/,@{$cancreate{$item}})) {
17100: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17101: push(@{$changes{'cancreate'}},$item);
17102: }
17103: }
17104: }
17105: }
17106: if (ref($cancreate{$item}) eq 'ARRAY') {
17107: foreach my $type (@{$cancreate{$item}}) {
17108: if (!grep(/^$type$/,@{$curr_usercreation{'cancreate'}{$item}})) {
17109: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17110: push(@{$changes{'cancreate'}},$item);
17111: }
17112: }
17113: }
17114: }
17115: } elsif (ref($curr_usercreation{'cancreate'}{$item}) eq 'HASH') {
17116: if (ref($cancreate{$item}) eq 'HASH') {
1.160.6.93 raeburn 17117: foreach my $type (keys(%{$curr_usercreation{'cancreate'}{$item}})) {
17118: if (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17119: foreach my $field (keys(%{$curr_usercreation{'cancreate'}{$item}{$type}})) {
17120: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17121: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17122: push(@{$changes{'cancreate'}},$item);
17123: }
17124: }
17125: }
1.160.6.93 raeburn 17126: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17127: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17128: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17129: push(@{$changes{'cancreate'}},$item);
17130: }
1.160.6.34 raeburn 17131: }
17132: }
17133: }
1.160.6.93 raeburn 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 (ref($curr_usercreation{'cancreate'}{$item}{$type}) eq 'HASH') {
17138: unless ($curr_usercreation{'cancreate'}{$item}{$type}{$field} eq $cancreate{$item}{$type}{$field}) {
1.160.6.35 raeburn 17139: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17140: push(@{$changes{'cancreate'}},$item);
17141: }
17142: }
17143: } else {
17144: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17145: push(@{$changes{'cancreate'}},$item);
17146: }
17147: }
17148: }
1.160.6.93 raeburn 17149: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17150: if ($cancreate{$item}{$type} ne $curr_usercreation{'cancreate'}{$item}{$type}) {
1.160.6.35 raeburn 17151: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17152: push(@{$changes{'cancreate'}},$item);
17153: }
1.160.6.34 raeburn 17154: }
17155: }
17156: }
17157: }
17158: } elsif ($curr_usercreation{'cancreate'}{$item}) {
17159: if (ref($cancreate{$item}) eq 'ARRAY') {
17160: if (!grep(/^\Q$curr_usercreation{'cancreate'}{$item}\E$/,@{$cancreate{$item}})) {
17161: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17162: push(@{$changes{'cancreate'}},$item);
17163: }
17164: }
1.160.6.93 raeburn 17165: }
17166: } elsif (($item eq 'selfcreateprocessing') || ($item eq 'emailverified') || ($item eq 'emailoptions')) {
17167: if (ref($cancreate{$item}) eq 'HASH') {
17168: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17169: push(@{$changes{'cancreate'}},$item);
1.160.6.34 raeburn 17170: }
17171: }
17172: } elsif ($item eq 'emailusername') {
1.160.6.35 raeburn 17173: if (ref($cancreate{$item}) eq 'HASH') {
17174: foreach my $type (keys(%{$cancreate{$item}})) {
17175: if (ref($cancreate{$item}{$type}) eq 'HASH') {
17176: foreach my $field (keys(%{$cancreate{$item}{$type}})) {
17177: if ($cancreate{$item}{$type}{$field}) {
17178: if (!grep(/^$item$/,@{$changes{'cancreate'}})) {
17179: push(@{$changes{'cancreate'}},$item);
17180: }
17181: last;
17182: }
17183: }
17184: }
17185: }
1.160.6.34 raeburn 17186: }
17187: }
17188: }
17189: #
17190: # Populate %save_usercreate hash with updates to self-creation configuration.
17191: #
17192: $save_usercreate{'cancreate'}{'captcha'} = $savecaptcha{'captcha'};
17193: $save_usercreate{'cancreate'}{'recaptchakeys'} = $savecaptcha{'recaptchakeys'};
1.160.6.69 raeburn 17194: $save_usercreate{'cancreate'}{'recaptchaversion'} = $savecaptcha{'recaptchaversion'};
1.160.6.34 raeburn 17195: $save_usercreate{'cancreate'}{'selfcreate'} = $cancreate{'selfcreate'};
17196: if (ref($cancreate{'notify'}) eq 'HASH') {
17197: $save_usercreate{'cancreate'}{'notify'} = $cancreate{'notify'};
17198: }
1.160.6.40 raeburn 17199: if (ref($cancreate{'selfcreateprocessing'}) eq 'HASH') {
17200: $save_usercreate{'cancreate'}{'selfcreateprocessing'} = $cancreate{'selfcreateprocessing'};
17201: }
1.160.6.93 raeburn 17202: if (ref($cancreate{'emailverified'}) eq 'HASH') {
17203: $save_usercreate{'cancreate'}{'emailverified'} = $cancreate{'emailverified'};
17204: }
17205: if (ref($cancreate{'emailoptions'}) eq 'HASH') {
17206: $save_usercreate{'cancreate'}{'emailoptions'} = $cancreate{'emailoptions'};
17207: }
17208: if (ref($cancreate{'emaildomain'}) eq 'HASH') {
17209: $save_usercreate{'cancreate'}{'emaildomain'} = $cancreate{'emaildomain'};
17210: }
1.160.6.34 raeburn 17211: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17212: $save_usercreate{'cancreate'}{'statustocreate'} = $cancreate{'statustocreate'};
17213: }
1.160.6.44 raeburn 17214: if (ref($cancreate{'shibenv'}) eq 'HASH') {
17215: $save_usercreate{'cancreate'}{'shibenv'} = $cancreate{'shibenv'};
17216: }
1.160.6.34 raeburn 17217: $save_usercreate{'cancreate'}{'emailusername'} = $cancreate{'emailusername'};
1.160.6.93 raeburn 17218: $save_usercreate{'email_rule'} = \%email_rule;
1.160.6.34 raeburn 17219:
17220: my %userconfig_hash = (
17221: usercreation => \%save_usercreate,
17222: usermodification => \%save_usermodify,
1.160.6.93 raeburn 17223: inststatus => \%save_inststatus,
1.160.6.34 raeburn 17224: );
1.160.6.93 raeburn 17225:
1.160.6.34 raeburn 17226: my $putresult = &Apache::lonnet::put_dom('configuration',\%userconfig_hash,
17227: $dom);
17228: #
1.160.6.93 raeburn 17229: # Accumulate details of changes to domain configuration for self-creation of usernames in $resulttext
1.160.6.34 raeburn 17230: #
1.27 raeburn 17231: if ($putresult eq 'ok') {
17232: if (keys(%changes) > 0) {
17233: $resulttext = &mt('Changes made:').'<ul>';
17234: if (ref($changes{'cancreate'}) eq 'ARRAY') {
1.160.6.34 raeburn 17235: my %lt = &selfcreation_types();
1.34 raeburn 17236: foreach my $type (@{$changes{'cancreate'}}) {
1.160.6.93 raeburn 17237: my $chgtext = '';
1.45 raeburn 17238: if ($type eq 'selfcreate') {
1.50 raeburn 17239: if (@{$cancreate{$type}} == 0) {
1.160.6.34 raeburn 17240: $chgtext .= &mt('Self creation of a new user account is not permitted.');
1.50 raeburn 17241: } else {
1.160.6.34 raeburn 17242: $chgtext .= &mt('Self-creation of a new account is permitted for:').
17243: '<ul>';
1.50 raeburn 17244: foreach my $case (@{$cancreate{$type}}) {
17245: $chgtext .= '<li>'.$selfcreatetypes{$case}.'</li>';
17246: }
17247: $chgtext .= '</ul>';
1.100 raeburn 17248: if (ref($cancreate{$type}) eq 'ARRAY') {
17249: if (grep(/^(login|sso)$/,@{$cancreate{$type}})) {
17250: if (ref($cancreate{'statustocreate'}) eq 'ARRAY') {
17251: if (@{$cancreate{'statustocreate'}} == 0) {
1.160.6.93 raeburn 17252: $chgtext .= '<span class="LC_warning">'.
17253: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts via log-in or single sign-on.").
17254: '</span><br />';
1.100 raeburn 17255: }
17256: }
17257: }
1.160.6.93 raeburn 17258: if (grep(/^email$/,@{$cancreate{$type}})) {
17259: if (!@statuses) {
17260: $chgtext .= '<span class="LC_warning">'.
17261: &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.").
17262: '</span><br />';
17263:
17264: }
17265: }
1.100 raeburn 17266: }
1.43 raeburn 17267: }
1.160.6.44 raeburn 17268: } elsif ($type eq 'shibenv') {
17269: if (keys(%{$cancreate{$type}}) == 0) {
1.160.6.93 raeburn 17270: $chgtext .= &mt('Shibboleth-autheticated user does not use environment variables to set user information').'<br />';
1.160.6.44 raeburn 17271: } else {
17272: $chgtext .= &mt('Shibboleth-autheticated user information set from environment variables, as follows:').
17273: '<ul>';
17274: foreach my $field (@shibfields) {
17275: next if ($cancreate{$type}{$field} eq '');
17276: if ($field eq 'inststatus') {
17277: $chgtext .= '<li>'.&mt('Institutional status').' -- '.$cancreate{$type}{$field}.'</li>';
17278: } else {
17279: $chgtext .= '<li>'.$fieldtitles{$field}.' -- '.$cancreate{$type}{$field}.'</li>';
17280: }
17281: }
17282: $chgtext .= '</ul>';
1.160.6.93 raeburn 17283: }
1.93 raeburn 17284: } elsif ($type eq 'statustocreate') {
1.96 raeburn 17285: if ((ref($cancreate{'selfcreate'}) eq 'ARRAY') &&
17286: (ref($cancreate{'statustocreate'}) eq 'ARRAY')) {
17287: if (@{$cancreate{'selfcreate'}} > 0) {
17288: if (@{$cancreate{'statustocreate'}} == 0) {
1.100 raeburn 17289: $chgtext .= &mt("Institutional affiliations permitted to create accounts set to 'None'.");
1.96 raeburn 17290: if (!grep(/^email$/,@{$cancreate{'selfcreate'}})) {
1.160.6.34 raeburn 17291: $chgtext .= '<br />'.
17292: '<span class="LC_warning">'.
17293: &mt("However, no institutional affiliations (including 'other') are currently permitted to create accounts.").
17294: '</span>';
17295: }
1.160.6.93 raeburn 17296: } elsif (keys(%usertypes) > 0) {
1.96 raeburn 17297: if (grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.100 raeburn 17298: $chgtext .= &mt('Creation of a new account for an institutional user is restricted to the following institutional affiliation(s):');
17299: } else {
17300: $chgtext .= &mt('Institutional affiliations permitted to create accounts with institutional authentication were set as follows:');
17301: }
17302: $chgtext .= '<ul>';
17303: foreach my $case (@{$cancreate{$type}}) {
17304: if ($case eq 'default') {
17305: $chgtext .= '<li>'.$othertitle.'</li>';
17306: } else {
1.160.6.93 raeburn 17307: $chgtext .= '<li>'.$usertypes{$case}.'</li>';
1.93 raeburn 17308: }
17309: }
1.100 raeburn 17310: $chgtext .= '</ul>';
17311: if (!grep(/^(login|sso)$/,@{$cancreate{'selfcreate'}})) {
1.160.6.93 raeburn 17312: $chgtext .= '<span class="LC_warning">'.
1.160.6.34 raeburn 17313: &mt('However, users authenticated by institutional login/single sign on are not currently permitted to create accounts.').
17314: '</span>';
1.100 raeburn 17315: }
17316: }
17317: } else {
17318: if (@{$cancreate{$type}} == 0) {
17319: $chgtext .= &mt("Institutional affiliations permitted to create accounts were set to 'none'.");
17320: } else {
17321: $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 17322: }
17323: }
1.160.6.93 raeburn 17324: $chgtext .= '<br />';
1.93 raeburn 17325: }
1.160.6.40 raeburn 17326: } elsif ($type eq 'selfcreateprocessing') {
17327: my %choices = &Apache::lonlocal::texthash (
17328: automatic => 'Automatic approval',
17329: approval => 'Queued for approval',
17330: );
1.160.6.93 raeburn 17331: if (@types) {
17332: if (@statuses) {
17333: $chgtext .= &mt('Processing of requests to create account with e-mail verification set as follows:').
17334: '<ul>';
17335: foreach my $status (@statuses) {
17336: if ($status eq 'default') {
17337: $chgtext .= '<li>'.$othertitle.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17338: } else {
17339: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$choices{$cancreate{'selfcreateprocessing'}{$status}}.'</li>';
17340: }
17341: }
17342: $chgtext .= '</ul>';
17343: }
17344: } else {
17345: $chgtext .= &mt('Processing of requests to create account with e-mail verification set to: "[_1]"',
17346: $choices{$cancreate{'selfcreateprocessing'}{'default'}});
17347: }
17348: } elsif ($type eq 'emailverified') {
17349: my %options = &Apache::lonlocal::texthash (
17350: all => 'Same as e-mail',
17351: first => 'Omit @domain',
17352: free => 'Free to choose',
17353: );
17354: if (@types) {
17355: if (@statuses) {
17356: $chgtext .= &mt('For self-created accounts verified by e-mail address, username is set as follows:').
17357: '<ul>';
17358: foreach my $status (@statuses) {
17359: if ($status eq 'default') {
17360: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17361: } else {
17362: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailverified'}{$status}}.'</li>';
17363: }
17364: }
17365: $chgtext .= '</ul>';
17366: }
1.160.6.40 raeburn 17367: } else {
1.160.6.93 raeburn 17368: $chgtext .= &mt("For self-created accounts verified by e-mail address, user's username is: '[_1]'",
17369: $options{$cancreate{'emailverified'}{'default'}});
17370: }
17371: } elsif ($type eq 'emailoptions') {
17372: my %options = &Apache::lonlocal::texthash (
17373: any => 'Any e-mail',
17374: inst => 'Institutional only',
17375: noninst => 'Non-institutional only',
17376: custom => 'Custom restrictions',
17377: );
17378: if (@types) {
17379: if (@statuses) {
17380: $chgtext .= &mt('For self-created accounts verified by e-mail address, requirements for e-mail address are as follows:').
17381: '<ul>';
17382: foreach my $status (@statuses) {
17383: if ($type eq 'default') {
17384: $chgtext .= '<li>'.$othertitle.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17385: } else {
17386: $chgtext .= '<li>'.$usertypes{$status}.' -- '.$options{$cancreate{'emailoptions'}{$status}}.'</li>';
17387: }
17388: }
17389: $chgtext .= '</ul>';
17390: }
17391: } else {
17392: if ($cancreate{'emailoptions'}{'default'} eq 'any') {
17393: $chgtext .= &mt('For self-created accounts verified by e-mail address, any e-mail may be used');
17394: } else {
17395: $chgtext .= &mt('For self-created accounts verified by e-mail address, e-mail restricted to: "[_1]"',
17396: $options{$cancreate{'emailoptions'}{'default'}});
17397: }
17398: }
17399: } elsif ($type eq 'emaildomain') {
17400: my $output;
17401: if (@statuses) {
17402: foreach my $type (@statuses) {
17403: if (ref($cancreate{'emaildomain'}{$type}) eq 'HASH') {
17404: if ($cancreate{'emailoptions'}{$type} eq 'inst') {
17405: if ($type eq 'default') {
17406: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17407: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17408: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17409: } else {
17410: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address needs to end: [_1]",
17411: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17412: }
17413: } else {
17414: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17415: ($cancreate{'emaildomain'}{$type}{'inst'} eq '')) {
17416: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17417: } else {
17418: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address needs to end: [_1]",
17419: $cancreate{'emaildomain'}{$type}{'inst'}).'</li>';
17420: }
17421: }
17422: } elsif ($cancreate{'emailoptions'}{$type} eq 'noninst') {
17423: if ($type eq 'default') {
17424: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17425: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17426: $output = '<li>'.$othertitle.' -- '.&mt('No restriction on e-mail domain').'</li>';
17427: } else {
17428: $output = '<li>'.$othertitle.' -- '.&mt("User's e-mail address must not end: [_1]",
17429: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17430: }
17431: } else {
17432: if ((ref($cancreate{'emaildomain'}{$type}) ne 'HASH') ||
17433: ($cancreate{'emaildomain'}{$type}{'noninst'} eq '')) {
17434: $output = '<li>'.$usertypes{$type}.' -- '.&mt('No restriction on e-mail domain').'</li>';
17435: } else {
17436: $output = '<li>'.$usertypes{$type}.' -- '.&mt("User's e-mail address must not end: [_1]",
17437: $cancreate{'emaildomain'}{$type}{'noninst'}).'</li>';
17438: }
17439: }
17440: }
17441: }
17442: }
17443: }
17444: if ($output ne '') {
17445: $chgtext .= &mt('For self-created accounts verified by e-mail address:').
17446: '<ul>'.$output.'</ul>';
1.160.6.40 raeburn 17447: }
1.160.6.5 raeburn 17448: } elsif ($type eq 'captcha') {
1.160.6.34 raeburn 17449: if ($savecaptcha{$type} eq 'notused') {
1.160.6.5 raeburn 17450: $chgtext .= &mt('No CAPTCHA validation in use for self-creation screen.');
17451: } else {
17452: my %captchas = &captcha_phrases();
1.160.6.34 raeburn 17453: if ($captchas{$savecaptcha{$type}}) {
17454: $chgtext .= &mt("Validation for self-creation screen set to $captchas{$savecaptcha{$type}}.");
1.160.6.5 raeburn 17455: } else {
17456: $chgtext .= &mt('Validation for self-creation screen set to unknown type.');
17457: }
17458: }
17459: } elsif ($type eq 'recaptchakeys') {
17460: my ($privkey,$pubkey);
1.160.6.34 raeburn 17461: if (ref($savecaptcha{$type}) eq 'HASH') {
17462: $pubkey = $savecaptcha{$type}{'public'};
17463: $privkey = $savecaptcha{$type}{'private'};
1.160.6.5 raeburn 17464: }
17465: $chgtext .= &mt('ReCAPTCHA keys changes').'<ul>';
17466: if (!$pubkey) {
17467: $chgtext .= '<li>'.&mt('Public key deleted').'</li>';
17468: } else {
17469: $chgtext .= '<li>'.&mt('Public key set to [_1]',$pubkey).'</li>';
17470: }
17471: if (!$privkey) {
17472: $chgtext .= '<li>'.&mt('Private key deleted').'</li>';
17473: } else {
17474: $chgtext .= '<li>'.&mt('Private key set to [_1]',$pubkey).'</li>';
17475: }
17476: $chgtext .= '</ul>';
1.160.6.69 raeburn 17477: } elsif ($type eq 'recaptchaversion') {
17478: if ($savecaptcha{'captcha'} eq 'recaptcha') {
17479: $chgtext .= &mt('ReCAPTCHA set to version [_1]',$savecaptcha{$type});
17480: }
1.160.6.34 raeburn 17481: } elsif ($type eq 'emailusername') {
17482: if (ref($cancreate{'emailusername'}) eq 'HASH') {
1.160.6.93 raeburn 17483: if (@statuses) {
17484: foreach my $type (@statuses) {
1.160.6.35 raeburn 17485: if (ref($cancreate{'emailusername'}{$type}) eq 'HASH') {
17486: if (keys(%{$cancreate{'emailusername'}{$type}}) > 0) {
1.160.6.93 raeburn 17487: $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 17488: '<ul>';
17489: foreach my $field (@{$infofields}) {
17490: if ($cancreate{'emailusername'}{$type}{$field}) {
17491: $chgtext .= '<li>'.$infotitles->{$field}.'</li>';
17492: }
17493: }
1.160.6.50 raeburn 17494: $chgtext .= '</ul>';
17495: } else {
1.160.6.93 raeburn 17496: $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 17497: }
17498: } else {
1.160.6.93 raeburn 17499: $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 17500: }
17501: }
17502: }
17503: }
17504: } elsif ($type eq 'notify') {
1.160.6.93 raeburn 17505: my $numapprove = 0;
1.160.6.34 raeburn 17506: if (ref($changes{'cancreate'}) eq 'ARRAY') {
17507: if ((grep(/^notify$/,@{$changes{'cancreate'}})) && (ref($cancreate{'notify'}) eq 'HASH')) {
17508: if ($cancreate{'notify'}{'approval'}) {
1.160.6.93 raeburn 17509: $chgtext .= &mt('Notification of username requests requiring approval will be sent to: ').$cancreate{'notify'}{'approval'};
17510: $numapprove ++;
1.160.6.34 raeburn 17511: }
17512: }
1.43 raeburn 17513: }
1.160.6.93 raeburn 17514: unless ($numapprove) {
17515: $chgtext .= &mt('No Domain Coordinators will receive notification of username requests requiring approval.');
17516: }
1.34 raeburn 17517: }
1.160.6.34 raeburn 17518: if ($chgtext) {
17519: $resulttext .= '<li>'.$chgtext.'</li>';
1.32 raeburn 17520: }
17521: }
17522: }
1.160.6.93 raeburn 17523: if ((ref($changes{'email_rule'}) eq 'ARRAY') && (@{$changes{'email_rule'}} > 0)) {
1.43 raeburn 17524: my ($emailrules,$emailruleorder) =
17525: &Apache::lonnet::inst_userrules($dom,'email');
1.160.6.93 raeburn 17526: foreach my $type (@{$changes{'email_rule'}}) {
17527: if (ref($email_rule{$type}) eq 'ARRAY') {
17528: my $chgtext = '<ul>';
17529: foreach my $rule (@{$email_rule{$type}}) {
17530: if (ref($emailrules->{$rule}) eq 'HASH') {
17531: $chgtext .= '<li>'.$emailrules->{$rule}{'name'}.'</li>';
17532: }
17533: }
17534: $chgtext .= '</ul>';
17535: my $typename;
17536: if (@types) {
17537: if ($type eq 'default') {
17538: $typename = $othertitle;
17539: } else {
17540: $typename = $usertypes{$type};
17541: }
17542: $chgtext .= &mt('(Affiliation: [_1])',$typename);
17543: }
17544: if (@{$email_rule{$type}} > 0) {
17545: $resulttext .= '<li>'.
17546: &mt('Accounts may not be created by users verified by e-mail, for e-mail addresses of the following types: ',
17547: $usertypes{$type}).
17548: $chgtext.
17549: '</li>';
17550: } else {
17551: $resulttext .= '<li>'.
17552: &mt('There are now no restrictions on e-mail addresses which may be used for verification when a user requests an account.').
17553: '</li>'.
17554: &mt('(Affiliation: [_1])',$typename);
17555: }
1.43 raeburn 17556: }
17557: }
1.160.6.93 raeburn 17558: }
17559: if (ref($changes{'inststatus'}) eq 'ARRAY') {
17560: if (ref($save_inststatus{'inststatusguest'}) eq 'ARRAY') {
17561: if (@{$save_inststatus{'inststatusguest'}} > 0) {
17562: my $chgtext = '<ul>';
17563: foreach my $type (@{$save_inststatus{'inststatusguest'}}) {
17564: $chgtext .= '<li>'.$usertypes{$type}.'</li>';
17565: }
17566: $chgtext .= '</ul>';
17567: $resulttext .= '<li>'.
17568: &mt('A user will self-report one of the following affiliations when requesting an account verified by e-mail: ').
17569: $chgtext.
17570: '</li>';
17571: } else {
17572: $resulttext .= '<li>'.
17573: &mt('No affiliations available for self-reporting when requesting an account verified by e-mail.').
17574: '</li>';
17575: }
1.43 raeburn 17576: }
17577: }
1.160.6.34 raeburn 17578: if (ref($changes{'selfcreate'}) eq 'ARRAY') {
17579: $resulttext .= '<li>'.&mt('When self-creating institutional account:').'<ul>';
17580: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17581: foreach my $type (@{$changes{'selfcreate'}}) {
17582: my $typename = $type;
1.160.6.93 raeburn 17583: if (keys(%usertypes) > 0) {
17584: if ($usertypes{$type} ne '') {
17585: $typename = $usertypes{$type};
1.28 raeburn 17586: }
17587: }
1.160.6.34 raeburn 17588: my @modifiable;
17589: $resulttext .= '<li>'.
17590: &mt('Self-creation of account by users with status: [_1]',
17591: '<span class="LC_cusr_emph">'.$typename.'</span>').
17592: ' - '.&mt('modifiable fields (if institutional data blank): ');
17593: foreach my $field (@fields) {
17594: if ($save_usermodify{'selfcreate'}{$type}{$field}) {
17595: push(@modifiable,'<b>'.$fieldtitles{$field}.'</b>');
17596: }
17597: }
17598: if (@modifiable > 0) {
17599: $resulttext .= join(', ',@modifiable);
1.43 raeburn 17600: } else {
1.160.6.34 raeburn 17601: $resulttext .= &mt('none');
1.43 raeburn 17602: }
1.160.6.34 raeburn 17603: $resulttext .= '</li>';
1.28 raeburn 17604: }
1.160.6.34 raeburn 17605: $resulttext .= '</ul></li>';
1.28 raeburn 17606: }
1.27 raeburn 17607: $resulttext .= '</ul>';
1.160.6.93 raeburn 17608: my $cachetime = 24*60*60;
17609: $domdefaults{'inststatusguest'} = $save_inststatus{'inststatusguest'};
17610: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
17611: if (ref($lastactref) eq 'HASH') {
17612: $lastactref->{'domdefaults'} = 1;
17613: }
1.27 raeburn 17614: } else {
1.160.6.34 raeburn 17615: $resulttext = &mt('No changes made to self-creation settings');
1.27 raeburn 17616: }
17617: } else {
17618: $resulttext = '<span class="LC_error">'.
1.23 raeburn 17619: &mt('An error occurred: [_1]',$putresult).'</span>';
17620: }
1.43 raeburn 17621: if ($warningmsg ne '') {
17622: $resulttext .= '<br /><span class="LC_warning">'.$warningmsg.'</span><br />';
17623: }
1.23 raeburn 17624: return $resulttext;
17625: }
17626:
1.160.6.5 raeburn 17627: sub process_captcha {
1.160.6.104 raeburn 17628: my ($container,$changes,$newsettings,$currsettings) = @_;
17629: return unless ((ref($changes) eq 'HASH') && (ref($newsettings) eq 'HASH'));
1.160.6.5 raeburn 17630: $newsettings->{'captcha'} = $env{'form.'.$container.'_captcha'};
17631: unless ($newsettings->{'captcha'} eq 'recaptcha' || $newsettings->{'captcha'} eq 'notused') {
17632: $newsettings->{'captcha'} = 'original';
17633: }
1.160.6.104 raeburn 17634: my %current;
17635: if (ref($currsettings) eq 'HASH') {
17636: %current = %{$currsettings};
17637: }
17638: if ($current{'captcha'} ne $newsettings->{'captcha'}) {
1.160.6.5 raeburn 17639: if ($container eq 'cancreate') {
17640: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17641: push(@{$changes->{'cancreate'}},'captcha');
17642: } elsif (!defined($changes->{'cancreate'})) {
17643: $changes->{'cancreate'} = ['captcha'];
17644: }
1.160.6.102 raeburn 17645: } elsif ($container eq 'passwords') {
17646: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17647: } else {
17648: $changes->{'captcha'} = 1;
17649: }
17650: }
1.160.6.69 raeburn 17651: my ($newpub,$newpriv,$currpub,$currpriv,$newversion,$currversion);
1.160.6.5 raeburn 17652: if ($newsettings->{'captcha'} eq 'recaptcha') {
17653: $newpub = $env{'form.'.$container.'_recaptchapub'};
17654: $newpriv = $env{'form.'.$container.'_recaptchapriv'};
1.160.6.52 raeburn 17655: $newpub =~ s/[^\w\-]//g;
17656: $newpriv =~ s/[^\w\-]//g;
1.160.6.5 raeburn 17657: $newsettings->{'recaptchakeys'} = {
17658: public => $newpub,
17659: private => $newpriv,
17660: };
1.160.6.69 raeburn 17661: $newversion = $env{'form.'.$container.'_recaptchaversion'};
17662: $newversion =~ s/\D//g;
17663: if ($newversion ne '2') {
17664: $newversion = 1;
17665: }
17666: $newsettings->{'recaptchaversion'} = $newversion;
1.160.6.5 raeburn 17667: }
1.160.6.104 raeburn 17668: if (ref($current{'recaptchakeys'}) eq 'HASH') {
17669: $currpub = $current{'recaptchakeys'}{'public'};
17670: $currpriv = $current{'recaptchakeys'}{'private'};
1.160.6.10 raeburn 17671: unless ($newsettings->{'captcha'} eq 'recaptcha') {
17672: $newsettings->{'recaptchakeys'} = {
17673: public => '',
17674: private => '',
17675: }
17676: }
1.160.6.5 raeburn 17677: }
1.160.6.104 raeburn 17678: if ($current{'captcha'} eq 'recaptcha') {
17679: $currversion = $current{'recaptchaversion'};
1.160.6.69 raeburn 17680: if ($currversion ne '2') {
17681: $currversion = 1;
17682: }
17683: }
17684: if ($currversion ne $newversion) {
17685: if ($container eq 'cancreate') {
17686: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17687: push(@{$changes->{'cancreate'}},'recaptchaversion');
17688: } elsif (!defined($changes->{'cancreate'})) {
17689: $changes->{'cancreate'} = ['recaptchaversion'];
17690: }
1.160.6.102 raeburn 17691: } elsif ($container eq 'passwords') {
17692: $changes->{'reset'} = 1;
1.160.6.69 raeburn 17693: } else {
17694: $changes->{'recaptchaversion'} = 1;
17695: }
17696: }
1.160.6.5 raeburn 17697: if (($newpub ne $currpub) || ($newpriv ne $currpriv)) {
17698: if ($container eq 'cancreate') {
17699: if (ref($changes->{'cancreate'}) eq 'ARRAY') {
17700: push(@{$changes->{'cancreate'}},'recaptchakeys');
17701: } elsif (!defined($changes->{'cancreate'})) {
17702: $changes->{'cancreate'} = ['recaptchakeys'];
17703: }
1.160.6.102 raeburn 17704: } elsif ($container eq 'passwords') {
17705: $changes->{'reset'} = 1;
1.160.6.5 raeburn 17706: } else {
17707: $changes->{'recaptchakeys'} = 1;
17708: }
17709: }
17710: return;
17711: }
17712:
1.33 raeburn 17713: sub modify_usermodification {
17714: my ($dom,%domconfig) = @_;
1.160.6.34 raeburn 17715: my ($resulttext,%curr_usermodification,%changes,%modifyhash);
1.33 raeburn 17716: if (ref($domconfig{'usermodification'}) eq 'HASH') {
17717: foreach my $key (keys(%{$domconfig{'usermodification'}})) {
1.160.6.34 raeburn 17718: if ($key eq 'selfcreate') {
17719: $modifyhash{$key} = $domconfig{'usermodification'}{$key};
17720: } else {
17721: $curr_usermodification{$key} = $domconfig{'usermodification'}{$key};
17722: }
1.33 raeburn 17723: }
17724: }
1.160.6.118.2 25(raebu 17725:24): my @contexts = ('author','coauthor','course');
1.33 raeburn 17726: my %context_title = (
17727: author => 'In author context',
1.160.6.118.2 25(raebu 17728:24): coauthor => 'As co-author manager',
1.33 raeburn 17729: course => 'In course context',
17730: );
17731: my @fields = ('lastname','firstname','middlename','generation',
17732: 'permanentemail','id');
17733: my %roles = (
17734: author => ['ca','aa'],
1.160.6.118.2 25(raebu 17735:24): coauthor => ['ca','aa'],
1.33 raeburn 17736: course => ['st','ep','ta','in','cr'],
17737: );
17738: my %fieldtitles = &Apache::loncommon::personal_data_fieldtitles();
17739: foreach my $context (@contexts) {
1.160.6.118.2 25(raebu 17740:24): my $prefix = 'canmodify';
17741:24): if ($context eq 'coauthor') {
17742:24): $prefix = 'cacanmodify';
17743:24): }
1.33 raeburn 17744: foreach my $role (@{$roles{$context}}) {
1.160.6.118.2 25(raebu 17745:24): my @modifiable = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$role);
1.33 raeburn 17746: foreach my $item (@fields) {
17747: if (grep(/^\Q$item\E$/,@modifiable)) {
17748: $modifyhash{$context}{$role}{$item} = 1;
17749: } else {
17750: $modifyhash{$context}{$role}{$item} = 0;
17751: }
17752: }
17753: }
17754: if (ref($curr_usermodification{$context}) eq 'HASH') {
17755: foreach my $role (@{$roles{$context}}) {
17756: if (ref($curr_usermodification{$context}{$role}) eq 'HASH') {
17757: foreach my $field (@fields) {
17758: if ($modifyhash{$context}{$role}{$field} ne
17759: $curr_usermodification{$context}{$role}{$field}) {
17760: push(@{$changes{$context}},$role);
17761: last;
17762: }
17763: }
17764: }
17765: }
17766: } else {
17767: foreach my $context (@contexts) {
17768: foreach my $role (@{$roles{$context}}) {
17769: push(@{$changes{$context}},$role);
17770: }
17771: }
17772: }
17773: }
17774: my %usermodification_hash = (
17775: usermodification => \%modifyhash,
17776: );
17777: my $putresult = &Apache::lonnet::put_dom('configuration',
17778: \%usermodification_hash,$dom);
17779: if ($putresult eq 'ok') {
17780: if (keys(%changes) > 0) {
17781: $resulttext = &mt('Changes made: ').'<ul>';
17782: foreach my $context (@contexts) {
17783: if (ref($changes{$context}) eq 'ARRAY') {
17784: $resulttext .= '<li>'.$context_title{$context}.':<ul>';
17785: if (ref($changes{$context}) eq 'ARRAY') {
17786: foreach my $role (@{$changes{$context}}) {
17787: my $rolename;
1.160.6.34 raeburn 17788: if ($role eq 'cr') {
17789: $rolename = &mt('Custom');
1.33 raeburn 17790: } else {
1.160.6.34 raeburn 17791: $rolename = &Apache::lonnet::plaintext($role);
1.33 raeburn 17792: }
17793: my @modifiable;
1.160.6.34 raeburn 17794: $resulttext .= '<li><span class="LC_cusr_emph">'.&mt('Target user with [_1] role',$rolename).'</span> - '.&mt('modifiable fields: ');
1.33 raeburn 17795: foreach my $field (@fields) {
17796: if ($modifyhash{$context}{$role}{$field}) {
17797: push(@modifiable,$fieldtitles{$field});
17798: }
17799: }
17800: if (@modifiable > 0) {
17801: $resulttext .= join(', ',@modifiable);
17802: } else {
17803: $resulttext .= &mt('none');
17804: }
17805: $resulttext .= '</li>';
17806: }
17807: $resulttext .= '</ul></li>';
17808: }
17809: }
17810: }
17811: $resulttext .= '</ul>';
17812: } else {
17813: $resulttext = &mt('No changes made to user modification settings');
17814: }
17815: } else {
17816: $resulttext = '<span class="LC_error">'.
17817: &mt('An error occurred: [_1]',$putresult).'</span>';
17818: }
17819: return $resulttext;
17820: }
17821:
1.43 raeburn 17822: sub modify_defaults {
1.160.6.27 raeburn 17823: my ($dom,$lastactref,%domconfig) = @_;
1.43 raeburn 17824: my ($resulttext,$mailmsgtxt,%newvalues,%changes,@errors);
1.160.6.27 raeburn 17825: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.80 raeburn 17826: my @items = ('auth_def','auth_arg_def','lang_def','timezone_def','datelocale_def',
1.160.6.98 raeburn 17827: 'portal_def');
1.160.6.118.2 14(raebu 17828:23): my @authtypes = ('internal','krb4','krb5','localauth','lti');
1.43 raeburn 17829: foreach my $item (@items) {
17830: $newvalues{$item} = $env{'form.'.$item};
17831: if ($item eq 'auth_def') {
17832: if ($newvalues{$item} ne '') {
17833: if (!grep(/^\Q$newvalues{$item}\E$/,@authtypes)) {
17834: push(@errors,$item);
17835: }
17836: }
17837: } elsif ($item eq 'lang_def') {
17838: if ($newvalues{$item} ne '') {
17839: if ($newvalues{$item} =~ /^(\w+)/) {
17840: my $langcode = $1;
1.103 raeburn 17841: if ($langcode ne 'x_chef') {
17842: if (code2language($langcode) eq '') {
17843: push(@errors,$item);
17844: }
1.43 raeburn 17845: }
17846: } else {
17847: push(@errors,$item);
17848: }
17849: }
1.54 raeburn 17850: } elsif ($item eq 'timezone_def') {
17851: if ($newvalues{$item} ne '') {
1.62 raeburn 17852: if (!DateTime::TimeZone->is_valid_name($newvalues{$item})) {
1.54 raeburn 17853: push(@errors,$item);
17854: }
17855: }
1.68 raeburn 17856: } elsif ($item eq 'datelocale_def') {
17857: if ($newvalues{$item} ne '') {
17858: my @datelocale_ids = DateTime::Locale->ids();
17859: if (!grep(/^\Q$newvalues{$item}\E$/,@datelocale_ids)) {
17860: push(@errors,$item);
17861: }
17862: }
1.141 raeburn 17863: } elsif ($item eq 'portal_def') {
17864: if ($newvalues{$item} ne '') {
1.160.6.118.2 12(raebu 17865: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])\/?$/) {
17866:23): foreach my $field ('email','web') {
17867:23): if ($env{'form.'.$item.'_'.$field}) {
17868:23): $newvalues{$item.'_'.$field} = $env{'form.'.$item.'_'.$field};
17869:23): }
17870:23): }
17871:23): } else {
1.141 raeburn 17872: push(@errors,$item);
17873: }
17874: }
1.43 raeburn 17875: }
17876: if (grep(/^\Q$item\E$/,@errors)) {
17877: $newvalues{$item} = $domdefaults{$item};
1.160.6.118.2 12(raebu 17878:23): if ($item eq 'portal_def') {
17879:23): if ($domdefaults{$item}) {
17880:23): foreach my $field ('email','web') {
17881:23): if (exists($domdefaults{$item.'_'.$field})) {
17882:23): $newvalues{$item.'_'.$field} = $domdefaults{$item.'_'.$field};
17883:23): }
17884:23): }
17885:23): }
17886:23): }
1.43 raeburn 17887: } elsif ($domdefaults{$item} ne $newvalues{$item}) {
17888: $changes{$item} = 1;
17889: }
1.160.6.118.2 12(raebu 17890:23): if ($item eq 'portal_def') {
17891:23): unless (grep(/^\Q$item\E$/,@errors)) {
17892:23): if ($newvalues{$item} eq '') {
17893:23): foreach my $field ('email','web') {
17894:23): if (exists($domdefaults{$item.'_'.$field})) {
17895:23): delete($domdefaults{$item.'_'.$field});
17896:23): }
17897:23): }
17898:23): } else {
17899:23): unless ($changes{$item}) {
17900:23): foreach my $field ('email','web') {
17901:23): if ($domdefaults{$item.'_'.$field} ne $newvalues{$item.'_'.$field}) {
17902:23): $changes{$item} = 1;
17903:23): last;
17904:23): }
17905:23): }
17906:23): }
17907:23): foreach my $field ('email','web') {
17908:23): if ($newvalues{$item.'_'.$field}) {
17909:23): $domdefaults{$item.'_'.$field} = $newvalues{$item.'_'.$field};
17910:23): } elsif (exists($domdefaults{$item.'_'.$field})) {
17911:23): delete($domdefaults{$item.'_'.$field});
17912:23): }
17913:23): }
17914:23): }
17915:23): }
17916:23): }
1.72 raeburn 17917: $domdefaults{$item} = $newvalues{$item};
1.43 raeburn 17918: }
1.160.6.98 raeburn 17919: my %staticdefaults = (
17920: 'intauth_cost' => 10,
17921: 'intauth_check' => 0,
17922: 'intauth_switch' => 0,
17923: );
17924: foreach my $item ('intauth_cost','intauth_check','intauth_switch') {
17925: if (exists($domdefaults{$item})) {
17926: $newvalues{$item} = $domdefaults{$item};
17927: } else {
17928: $newvalues{$item} = $staticdefaults{$item};
17929: }
17930: }
1.160.6.118.2 8(raebur 17931:2): my ($unamemaprules,$ruleorder);
17932:2): my @possunamemaprules = &Apache::loncommon::get_env_multiple('form.unamemap_rule');
17933:2): if (@possunamemaprules) {
17934:2): ($unamemaprules,$ruleorder) =
17935:2): &Apache::lonnet::inst_userrules($dom,'unamemap');
17936:2): if ((ref($unamemaprules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
17937:2): if (@{$ruleorder} > 0) {
17938:2): my %possrules;
17939:2): map { $possrules{$_} = 1; } @possunamemaprules;
17940:2): foreach my $rule (@{$ruleorder}) {
17941:2): if ($possrules{$rule}) {
17942:2): push(@{$newvalues{'unamemap_rule'}},$rule);
17943:2): }
17944:2): }
17945:2): }
17946:2): }
17947:2): }
17948:2): if (ref($domdefaults{'unamemap_rule'}) eq 'ARRAY') {
17949:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17950:2): my @rulediffs = &Apache::loncommon::compare_arrays($domdefaults{'unamemap_rule'},
17951:2): $newvalues{'unamemap_rule'});
17952:2): if (@rulediffs) {
17953:2): $changes{'unamemap_rule'} = 1;
17954:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17955:2): }
17956:2): } elsif (@{$domdefaults{'unamemap_rule'}} > 0) {
17957:2): $changes{'unamemap_rule'} = 1;
17958:2): delete($domdefaults{'unamemap_rule'});
17959:2): }
17960:2): } elsif (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
17961:2): if (@{$newvalues{'unamemap_rule'}} > 0) {
17962:2): $changes{'unamemap_rule'} = 1;
17963:2): $domdefaults{'unamemap_rule'} = $newvalues{'unamemap_rule'};
17964:2): }
17965:2): }
1.43 raeburn 17966: my %defaults_hash = (
1.72 raeburn 17967: defaults => \%newvalues,
17968: );
1.43 raeburn 17969: my $title = &defaults_titles();
1.160.6.40 raeburn 17970:
17971: my $currinststatus;
17972: if (ref($domconfig{'inststatus'}) eq 'HASH') {
17973: $currinststatus = $domconfig{'inststatus'};
17974: } else {
17975: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
17976: $currinststatus = {
17977: inststatustypes => $usertypes,
17978: inststatusorder => $types,
17979: inststatusguest => [],
17980: };
17981: }
17982: my @todelete = &Apache::loncommon::get_env_multiple('form.inststatus_delete');
17983: my @allpos;
17984: my %alltypes;
1.160.6.93 raeburn 17985: my @inststatusguest;
17986: if (ref($currinststatus) eq 'HASH') {
17987: if (ref($currinststatus->{'inststatusguest'}) eq 'ARRAY') {
17988: foreach my $type (@{$currinststatus->{'inststatusguest'}}) {
17989: unless (grep(/^\Q$type\E$/,@todelete)) {
17990: push(@inststatusguest,$type);
17991: }
17992: }
17993: }
17994: }
17995: my ($currtitles,$currorder);
1.160.6.40 raeburn 17996: if (ref($currinststatus) eq 'HASH') {
17997: if (ref($currinststatus->{'inststatusorder'}) eq 'ARRAY') {
17998: foreach my $type (@{$currinststatus->{'inststatusorder'}}) {
17999: if (ref($currinststatus->{inststatustypes}) eq 'HASH') {
18000: if ($currinststatus->{inststatustypes}->{$type} ne '') {
18001: $currtitles .= $currinststatus->{inststatustypes}->{$type}.',';
18002: }
18003: }
18004: unless (grep(/^\Q$type\E$/,@todelete)) {
18005: my $position = $env{'form.inststatus_pos_'.$type};
18006: $position =~ s/\D+//g;
18007: $allpos[$position] = $type;
18008: $alltypes{$type} = $env{'form.inststatus_title_'.$type};
18009: $alltypes{$type} =~ s/`//g;
18010: }
18011: }
18012: $currorder = join(',',@{$currinststatus->{'inststatusorder'}});
18013: $currtitles =~ s/,$//;
18014: }
18015: }
18016: if ($env{'form.addinststatus'}) {
18017: my $newtype = $env{'form.addinststatus'};
18018: $newtype =~ s/\W//g;
18019: unless (exists($alltypes{$newtype})) {
18020: $alltypes{$newtype} = $env{'form.addinststatus_title'};
18021: $alltypes{$newtype} =~ s/`//g;
18022: my $position = $env{'form.addinststatus_pos'};
18023: $position =~ s/\D+//g;
18024: if ($position ne '') {
18025: $allpos[$position] = $newtype;
18026: }
18027: }
18028: }
1.160.6.93 raeburn 18029: my @orderedstatus;
1.160.6.40 raeburn 18030: foreach my $type (@allpos) {
18031: unless (($type eq '') || (grep(/^\Q$type\E$/,@orderedstatus))) {
18032: push(@orderedstatus,$type);
18033: }
18034: }
18035: foreach my $type (keys(%alltypes)) {
18036: unless (grep(/^\Q$type\E$/,@orderedstatus)) {
18037: delete($alltypes{$type});
18038: }
18039: }
18040: $defaults_hash{'inststatus'} = {
18041: inststatustypes => \%alltypes,
18042: inststatusorder => \@orderedstatus,
1.160.6.93 raeburn 18043: inststatusguest => \@inststatusguest,
1.160.6.40 raeburn 18044: };
18045: if (ref($defaults_hash{'inststatus'}) eq 'HASH') {
18046: foreach my $item ('inststatustypes','inststatusorder','inststatusguest') {
18047: $domdefaults{$item} = $defaults_hash{'inststatus'}{$item};
18048: }
18049: }
18050: if ($currorder ne join(',',@orderedstatus)) {
18051: $changes{'inststatus'}{'inststatusorder'} = 1;
18052: }
18053: my $newtitles;
18054: foreach my $item (@orderedstatus) {
18055: $newtitles .= $alltypes{$item}.',';
18056: }
18057: $newtitles =~ s/,$//;
18058: if ($currtitles ne $newtitles) {
18059: $changes{'inststatus'}{'inststatustypes'} = 1;
18060: }
1.43 raeburn 18061: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaults_hash,
18062: $dom);
18063: if ($putresult eq 'ok') {
18064: if (keys(%changes) > 0) {
18065: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.27 raeburn 18066: my $version = &Apache::lonnet::get_server_loncaparev($dom);
1.43 raeburn 18067: 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";
18068: foreach my $item (sort(keys(%changes))) {
1.160.6.40 raeburn 18069: if ($item eq 'inststatus') {
18070: if (ref($changes{'inststatus'}) eq 'HASH') {
1.160.6.93 raeburn 18071: if (@orderedstatus) {
1.160.6.40 raeburn 18072: $resulttext .= '<li>'.&mt('Institutional user status types set to:').' ';
18073: foreach my $type (@orderedstatus) {
18074: $resulttext .= $alltypes{$type}.', ';
18075: }
18076: $resulttext =~ s/, $//;
18077: $resulttext .= '</li>';
1.160.6.93 raeburn 18078: } else {
18079: $resulttext .= '<li>'.&mt('Institutional user status types deleted').'</li>';
1.160.6.40 raeburn 18080: }
18081: }
1.160.6.118.2 8(raebur 18082:2): } elsif ($item eq 'unamemap_rule') {
18083:2): if (ref($newvalues{'unamemap_rule'}) eq 'ARRAY') {
18084:2): my @rulenames;
18085:2): if (ref($unamemaprules) eq 'HASH') {
18086:2): foreach my $rule (@{$newvalues{'unamemap_rule'}}) {
18087:2): if (ref($unamemaprules->{$rule}) eq 'HASH') {
18088:2): push(@rulenames,$unamemaprules->{$rule}->{'name'});
18089:2): }
18090:2): }
18091:2): }
18092:2): if (@rulenames) {
18093:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames includes: [_1]',
18094:2): '<ul><li>'.join('</li><li>',@rulenames).'</li></ul>').
18095:2): '</li>';
18096:2): } else {
14(raebu 18097:23): $resulttext .= '<li>'.&mt('No mapping for missing usernames via standard log-in').'</li>';
18098:23): }
8(raebur 18099:2): } else {
18100:2): $resulttext .= '<li>'.&mt('Mapping for missing usernames via standard log-in deleted').'</li>';
18101:2): }
1.160.6.40 raeburn 18102: } else {
18103: my $value = $env{'form.'.$item};
18104: if ($value eq '') {
18105: $value = &mt('none');
18106: } elsif ($item eq 'auth_def') {
18107: my %authnames = &authtype_names();
18108: my %shortauth = (
18109: internal => 'int',
18110: krb4 => 'krb4',
18111: krb5 => 'krb5',
18112: localauth => 'loc',
1.160.6.118.2 14(raebu 18113:23): lti => 'lti',
1.160.6.40 raeburn 18114: );
18115: $value = $authnames{$shortauth{$value}};
18116: }
18117: $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$item},$value).'</li>';
1.160.6.118.2 12(raebu 18118:23): $mailmsgtext .= "$title->{$item} set to $value\n";
18119:23): if ($item eq 'portal_def') {
18120:23): if ($env{'form.'.$item} ne '') {
18121:23): foreach my $field ('email','web') {
18122:23): $value = $env{'form.'.$item.'_'.$field};
18123:23): if ($value) {
18124:23): $value = &mt('Yes');
18125:23): } else {
18126:23): $value = &mt('No');
18127:23): }
18128:23): $resulttext .= '<li>'.&mt('[_1] set to "[_2]"',$title->{$field},$value).'</li>';
18129:23): }
18130:23): }
18131:23): }
1.43 raeburn 18132: }
18133: }
18134: $resulttext .= '</ul>';
18135: $mailmsgtext .= "\n";
18136: my $cachetime = 24*60*60;
1.72 raeburn 18137: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 18138: if (ref($lastactref) eq 'HASH') {
18139: $lastactref->{'domdefaults'} = 1;
18140: }
1.68 raeburn 18141: if ($changes{'auth_def'} || $changes{'auth_arg_def'} || $changes{'lang_def'} || $changes{'datelocale_def'}) {
1.160.6.23 raeburn 18142: my $notify = 1;
18143: if (ref($domconfig{'contacts'}) eq 'HASH') {
18144: if ($domconfig{'contacts'}{'reportupdates'} == 0) {
18145: $notify = 0;
18146: }
18147: }
18148: if ($notify) {
18149: &Apache::lonmsg::sendemail('installrecord@loncapa.org',
18150: "LON-CAPA Domain Settings Change - $dom",
18151: $mailmsgtext);
18152: }
1.54 raeburn 18153: }
1.43 raeburn 18154: } else {
1.54 raeburn 18155: $resulttext = &mt('No changes made to default authentication/language/timezone settings');
1.43 raeburn 18156: }
18157: } else {
18158: $resulttext = '<span class="LC_error">'.
18159: &mt('An error occurred: [_1]',$putresult).'</span>';
18160: }
18161: if (@errors > 0) {
18162: $resulttext .= '<br />'.&mt('The following were left unchanged because the values entered were invalid:');
18163: foreach my $item (@errors) {
18164: $resulttext .= ' "'.$title->{$item}.'",';
18165: }
18166: $resulttext =~ s/,$//;
18167: }
18168: return $resulttext;
18169: }
18170:
1.46 raeburn 18171: sub modify_scantron {
1.160.6.24 raeburn 18172: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.46 raeburn 18173: my ($resulttext,%confhash,%changes,$errors);
18174: my $custom = 'custom.tab';
18175: my $default = 'default.tab';
18176: my $servadm = $r->dir_config('lonAdmEMail');
1.160.6.97 raeburn 18177: my ($configuserok,$author_ok,$switchserver) =
1.46 raeburn 18178: &config_check($dom,$confname,$servadm);
18179: if ($env{'form.scantronformat.filename'} ne '') {
18180: my $error;
18181: if ($configuserok eq 'ok') {
18182: if ($switchserver) {
1.130 raeburn 18183: $error = &mt("Upload of bubblesheet format file is not permitted to this server: [_1]",$switchserver);
1.46 raeburn 18184: } else {
18185: if ($author_ok eq 'ok') {
1.160.6.118.2 14(raebu 18186:23): my $modified = [];
1.46 raeburn 18187: my ($result,$scantronurl) =
1.160.6.118.2 14(raebu 18188:23): &Apache::lonconfigsettings::publishlogo($r,'upload','scantronformat',$dom,
18189:23): $confname,'scantron','','',$custom,
18190:23): $modified);
1.46 raeburn 18191: if ($result eq 'ok') {
18192: $confhash{'scantron'}{'scantronformat'} = $scantronurl;
1.48 raeburn 18193: $changes{'scantronformat'} = 1;
1.160.6.118.2 14(raebu 18194:23): &update_modify_urls($r,$modified);
1.46 raeburn 18195: } else {
18196: $error = &mt("Upload of [_1] failed because an error occurred publishing the file in RES space. Error was: [_2].",$custom,$result);
18197: }
18198: } else {
18199: $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);
18200: }
18201: }
18202: } else {
18203: $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);
18204: }
18205: if ($error) {
18206: &Apache::lonnet::logthis($error);
18207: $errors .= '<li><span class="LC_error">'.$error.'</span></li>';
18208: }
18209: }
1.48 raeburn 18210: if (ref($domconfig{'scantron'}) eq 'HASH') {
18211: if ($domconfig{'scantron'}{'scantronformat'} ne '') {
18212: if ($env{'form.scantronformat_del'}) {
18213: $confhash{'scantron'}{'scantronformat'} = '';
18214: $changes{'scantronformat'} = 1;
1.160.6.97 raeburn 18215: } else {
18216: $confhash{'scantron'}{'scantronformat'} = $domconfig{'scantron'}{'scantronformat'};
18217: }
18218: }
18219: }
18220: my @options = ('hdr','pad','rem');
18221: my @fields = &scantroncsv_fields();
18222: my %titles = &scantronconfig_titles();
18223: my @formats = &Apache::loncommon::get_env_multiple('form.scantronconfig');
18224: my ($newdat,$currdat,%newcol,%currcol);
18225: if (grep(/^dat$/,@formats)) {
18226: $confhash{'scantron'}{config}{dat} = 1;
18227: $newdat = 1;
18228: } else {
18229: $newdat = 0;
18230: }
18231: if (grep(/^csv$/,@formats)) {
18232: my %bynum;
18233: foreach my $field (@fields) {
18234: if ($env{'form.scantronconfig_csv_'.$field} =~ /^(\d+)$/) {
18235: my $posscol = $1;
18236: if (($posscol < 20) && (!$bynum{$posscol})) {
18237: $confhash{'scantron'}{config}{csv}{fields}{$field} = $posscol;
18238: $bynum{$posscol} = $field;
18239: $newcol{$field} = $posscol;
18240: }
18241: }
18242: }
18243: if (keys(%newcol)) {
18244: foreach my $option (@options) {
18245: if ($env{'form.scantroncsv_'.$option}) {
18246: $confhash{'scantron'}{config}{csv}{options}{$option} = 1;
18247: }
18248: }
18249: }
18250: }
18251: $currdat = 1;
18252: if (ref($domconfig{'scantron'}) eq 'HASH') {
18253: if (ref($domconfig{'scantron'}{'config'}) eq 'HASH') {
18254: unless (exists($domconfig{'scantron'}{'config'}{'dat'})) {
18255: $currdat = 0;
18256: }
18257: if (ref($domconfig{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18258: if (ref($domconfig{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18259: %currcol = %{$domconfig{'scantron'}{'config'}{'csv'}{'fields'}};
18260: }
18261: }
18262: }
18263: }
18264: if ($currdat != $newdat) {
18265: $changes{'config'} = 1;
18266: } else {
18267: foreach my $field (@fields) {
18268: if ($currcol{$field} ne '') {
18269: if ($currcol{$field} ne $newcol{$field}) {
18270: $changes{'config'} = 1;
18271: last;
18272: }
18273: } elsif ($newcol{$field} ne '') {
18274: $changes{'config'} = 1;
18275: last;
1.46 raeburn 18276: }
18277: }
18278: }
18279: if (keys(%confhash) > 0) {
18280: my $putresult = &Apache::lonnet::put_dom('configuration',\%confhash,
18281: $dom);
18282: if ($putresult eq 'ok') {
18283: if (keys(%changes) > 0) {
1.48 raeburn 18284: if (ref($confhash{'scantron'}) eq 'HASH') {
18285: $resulttext = &mt('Changes made:').'<ul>';
1.160.6.97 raeburn 18286: if ($changes{'scantronformat'}) {
18287: if ($confhash{'scantron'}{'scantronformat'} eq '') {
18288: $resulttext .= '<li>'.&mt('[_1] bubblesheet format file removed; [_2] file will be used for courses in this domain.',$custom,$default).'</li>';
18289: } else {
18290: $resulttext .= '<li>'.&mt('Custom bubblesheet format file ([_1]) uploaded for use with courses in this domain.',$custom).'</li>';
18291: }
18292: }
18293: if ($changes{'config'}) {
18294: if (ref($confhash{'scantron'}{'config'}) eq 'HASH') {
18295: if ($confhash{'scantron'}{'config'}{'dat'}) {
18296: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .dat format').'</li>';
18297: }
18298: if (ref($confhash{'scantron'}{'config'}{'csv'}) eq 'HASH') {
18299: if (ref($confhash{'scantron'}{'config'}{'csv'}{'fields'}) eq 'HASH') {
18300: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'fields'}})) {
18301: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following fields/column numbers supported:').'<ul>';
18302: foreach my $field (@fields) {
18303: if ($confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} ne '') {
18304: my $showcol = $confhash{'scantron'}{'config'}{'csv'}{'fields'}{$field} + 1;
18305: $resulttext .= '<li>'.$titles{$field}.': '.$showcol.'</li>';
18306: }
18307: }
18308: $resulttext .= '</ul></li>';
18309: if (ref($confhash{'scantron'}{'config'}{'csv'}{'options'}) eq 'HASH') {
18310: if (keys(%{$confhash{'scantron'}{'config'}{'csv'}{'options'}})) {
18311: $resulttext .= '<li>'.&mt('Bubblesheet data upload formats includes .csv format, with following options:').'<ul>';
18312: foreach my $option (@options) {
18313: if ($confhash{'scantron'}{'config'}{'csv'}{'options'}{$option} ne '') {
18314: $resulttext .= '<li>'.$titles{$option}.'</li>';
18315: }
18316: }
18317: $resulttext .= '</ul></li>';
18318: }
18319: }
18320: }
18321: }
18322: }
18323: } else {
18324: $resulttext .= '<li>'.&mt('No bubblesheet data upload formats set -- will default to assuming .dat format').'</li>';
18325: }
1.46 raeburn 18326: }
1.48 raeburn 18327: $resulttext .= '</ul>';
18328: } else {
1.130 raeburn 18329: $resulttext = &mt('Changes made to bubblesheet format file.');
1.46 raeburn 18330: }
18331: &Apache::loncommon::devalidate_domconfig_cache($dom);
1.160.6.27 raeburn 18332: if (ref($lastactref) eq 'HASH') {
18333: $lastactref->{'domainconfig'} = 1;
18334: }
1.46 raeburn 18335: } else {
1.160.6.97 raeburn 18336: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18337: }
18338: } else {
18339: $resulttext = '<span class="LC_error">'.
18340: &mt('An error occurred: [_1]',$putresult).'</span>';
18341: }
18342: } else {
1.160.6.97 raeburn 18343: $resulttext = &mt('No changes made to bubblesheet format settings');
1.46 raeburn 18344: }
18345: if ($errors) {
1.160.6.118.2 14(raebu 18346:23): $resulttext .= '<p>'.&mt('The following errors occurred: ').'<ul>'.
18347:23): $errors.'</ul></p>';
1.46 raeburn 18348: }
18349: return $resulttext;
18350: }
18351:
1.48 raeburn 18352: sub modify_coursecategories {
1.160.6.43 raeburn 18353: my ($dom,$lastactref,%domconfig) = @_;
1.57 raeburn 18354: my ($resulttext,%deletions,%reorderings,%needreordering,%adds,%changes,$errors,
18355: $cathash);
1.48 raeburn 18356: my @deletecategory = &Apache::loncommon::get_env_multiple('form.deletecategory');
1.160.6.42 raeburn 18357: my @catitems = ('unauth','auth');
18358: my @cattypes = ('std','domonly','codesrch','none');
1.55 raeburn 18359: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
1.57 raeburn 18360: $cathash = $domconfig{'coursecategories'}{'cats'};
18361: if ($domconfig{'coursecategories'}{'togglecats'} ne $env{'form.togglecats'}) {
18362: $changes{'togglecats'} = 1;
18363: $domconfig{'coursecategories'}{'togglecats'} = $env{'form.togglecats'};
18364: }
18365: if ($domconfig{'coursecategories'}{'categorize'} ne $env{'form.categorize'}) {
18366: $changes{'categorize'} = 1;
18367: $domconfig{'coursecategories'}{'categorize'} = $env{'form.categorize'};
18368: }
1.120 raeburn 18369: if ($domconfig{'coursecategories'}{'togglecatscomm'} ne $env{'form.togglecatscomm'}) {
18370: $changes{'togglecatscomm'} = 1;
18371: $domconfig{'coursecategories'}{'togglecatscomm'} = $env{'form.togglecatscomm'};
18372: }
18373: if ($domconfig{'coursecategories'}{'categorizecomm'} ne $env{'form.categorizecomm'}) {
18374: $changes{'categorizecomm'} = 1;
18375: $domconfig{'coursecategories'}{'categorizecomm'} = $env{'form.categorizecomm'};
18376: }
1.160.6.42 raeburn 18377: foreach my $item (@catitems) {
18378: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18379: if ($domconfig{'coursecategories'}{$item} ne $env{'form.coursecat_'.$item}) {
18380: $changes{$item} = 1;
18381: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18382: }
18383: }
18384: }
1.57 raeburn 18385: } else {
18386: $changes{'togglecats'} = 1;
18387: $changes{'categorize'} = 1;
1.124 raeburn 18388: $changes{'togglecatscomm'} = 1;
18389: $changes{'categorizecomm'} = 1;
1.87 raeburn 18390: $domconfig{'coursecategories'} = {
18391: togglecats => $env{'form.togglecats'},
18392: categorize => $env{'form.categorize'},
1.124 raeburn 18393: togglecatscomm => $env{'form.togglecatscomm'},
18394: categorizecomm => $env{'form.categorizecomm'},
1.120 raeburn 18395: };
1.160.6.42 raeburn 18396: foreach my $item (@catitems) {
18397: if ($env{'form.coursecat_'.$item} ne 'std') {
18398: $changes{$item} = 1;
18399: }
18400: if (grep(/^\Q$env{'form.coursecat_'.$item}\E$/,@cattypes)) {
18401: $domconfig{'coursecategories'}{$item} = $env{'form.coursecat_'.$item};
18402: }
18403: }
1.57 raeburn 18404: }
18405: if (ref($cathash) eq 'HASH') {
18406: if (($domconfig{'coursecategories'}{'cats'}{'instcode::0'} ne '') && ($env{'form.instcode'} == 0)) {
1.55 raeburn 18407: push (@deletecategory,'instcode::0');
18408: }
1.120 raeburn 18409: if (($domconfig{'coursecategories'}{'cats'}{'communities::0'} ne '') && ($env{'form.communities'} == 0)) {
18410: push(@deletecategory,'communities::0');
18411: }
1.48 raeburn 18412: }
1.57 raeburn 18413: my (@predelcats,@predeltrails,%predelallitems,%sort_by_deltrail);
18414: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18415: if (@deletecategory > 0) {
18416: #FIXME Need to remove category from all courses using a deleted category
1.57 raeburn 18417: &Apache::loncommon::extract_categories($cathash,\@predelcats,\@predeltrails,\%predelallitems);
1.48 raeburn 18418: foreach my $item (@deletecategory) {
1.57 raeburn 18419: if ($domconfig{'coursecategories'}{'cats'}{$item} ne '') {
18420: delete($domconfig{'coursecategories'}{'cats'}{$item});
1.48 raeburn 18421: $deletions{$item} = 1;
1.57 raeburn 18422: &recurse_cat_deletes($item,$cathash,\%deletions);
1.48 raeburn 18423: }
18424: }
18425: }
1.57 raeburn 18426: foreach my $item (keys(%{$cathash})) {
1.48 raeburn 18427: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
1.57 raeburn 18428: if ($cathash->{$item} ne $env{'form.'.$item}) {
1.48 raeburn 18429: $reorderings{$item} = 1;
1.57 raeburn 18430: $domconfig{'coursecategories'}{'cats'}{$item} = $env{'form.'.$item};
1.48 raeburn 18431: }
18432: if ($env{'form.addcategory_name_'.$item} ne '') {
18433: my $newcat = $env{'form.addcategory_name_'.$item};
18434: my $newdepth = $depth+1;
18435: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18436: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos_'.$item};
1.48 raeburn 18437: $adds{$newitem} = 1;
18438: }
18439: if ($env{'form.subcat_'.$item} ne '') {
18440: my $newcat = $env{'form.subcat_'.$item};
18441: my $newdepth = $depth+1;
18442: my $newitem = &escape($newcat).':'.&escape($cat).':'.$newdepth;
1.57 raeburn 18443: $domconfig{'coursecategories'}{'cats'}{$newitem} = 0;
1.48 raeburn 18444: $adds{$newitem} = 1;
18445: }
18446: }
18447: }
18448: if ($env{'form.instcode'} eq '1') {
1.57 raeburn 18449: if (ref($cathash) eq 'HASH') {
1.48 raeburn 18450: my $newitem = 'instcode::0';
1.57 raeburn 18451: if ($cathash->{$newitem} eq '') {
18452: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18453: $adds{$newitem} = 1;
18454: }
18455: } else {
18456: my $newitem = 'instcode::0';
1.57 raeburn 18457: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.instcode_pos'};
1.48 raeburn 18458: $adds{$newitem} = 1;
18459: }
18460: }
1.120 raeburn 18461: if ($env{'form.communities'} eq '1') {
18462: if (ref($cathash) eq 'HASH') {
18463: my $newitem = 'communities::0';
18464: if ($cathash->{$newitem} eq '') {
18465: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18466: $adds{$newitem} = 1;
18467: }
18468: } else {
18469: my $newitem = 'communities::0';
18470: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.communities_pos'};
18471: $adds{$newitem} = 1;
18472: }
18473: }
1.48 raeburn 18474: if ($env{'form.addcategory_name'} ne '') {
1.120 raeburn 18475: if (($env{'form.addcategory_name'} ne 'instcode') &&
18476: ($env{'form.addcategory_name'} ne 'communities')) {
18477: my $newitem = &escape($env{'form.addcategory_name'}).'::0';
18478: $domconfig{'coursecategories'}{'cats'}{$newitem} = $env{'form.addcategory_pos'};
18479: $adds{$newitem} = 1;
18480: }
1.48 raeburn 18481: }
1.57 raeburn 18482: my $putresult;
1.48 raeburn 18483: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18484: if (keys(%deletions) > 0) {
18485: foreach my $key (keys(%deletions)) {
18486: if ($predelallitems{$key} ne '') {
18487: $sort_by_deltrail{$predelallitems{$key}} = $predeltrails[$predelallitems{$key}];
18488: }
18489: }
18490: }
18491: my (@chkcats,@chktrails,%chkallitems);
1.57 raeburn 18492: &Apache::loncommon::extract_categories($domconfig{'coursecategories'}{'cats'},\@chkcats,\@chktrails,\%chkallitems);
1.48 raeburn 18493: if (ref($chkcats[0]) eq 'ARRAY') {
18494: my $depth = 0;
18495: my $chg = 0;
18496: for (my $i=0; $i<@{$chkcats[0]}; $i++) {
18497: my $name = $chkcats[0][$i];
18498: my $item;
18499: if ($name eq '') {
18500: $chg ++;
18501: } else {
18502: $item = &escape($name).'::0';
18503: if ($chg) {
1.57 raeburn 18504: $domconfig{'coursecategories'}{'cats'}{$item} -= $chg;
1.48 raeburn 18505: }
18506: $depth ++;
1.57 raeburn 18507: &recurse_check(\@chkcats,$domconfig{'coursecategories'}{'cats'},$depth,$name);
1.48 raeburn 18508: $depth --;
18509: }
18510: }
18511: }
1.57 raeburn 18512: }
18513: if ((keys(%changes) > 0) || (keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18514: $putresult = &Apache::lonnet::put_dom('configuration',\%domconfig,$dom);
1.48 raeburn 18515: if ($putresult eq 'ok') {
1.57 raeburn 18516: my %title = (
1.120 raeburn 18517: togglecats => 'Show/Hide a course in catalog',
18518: categorize => 'Assign a category to a course',
18519: togglecatscomm => 'Show/Hide a community in catalog',
18520: categorizecomm => 'Assign a category to a community',
1.57 raeburn 18521: );
18522: my %level = (
1.120 raeburn 18523: dom => 'set in Domain ("Modify Course/Community")',
18524: crs => 'set in Course ("Course Configuration")',
18525: comm => 'set in Community ("Community Configuration")',
1.160.6.42 raeburn 18526: none => 'No catalog',
18527: std => 'Standard catalog',
18528: domonly => 'Domain-only catalog',
18529: codesrch => 'Code search form',
1.57 raeburn 18530: );
1.48 raeburn 18531: $resulttext = &mt('Changes made:').'<ul>';
1.57 raeburn 18532: if ($changes{'togglecats'}) {
18533: $resulttext .= '<li>'.&mt("$title{'togglecats'} $level{$env{'form.togglecats'}}").'</li>';
18534: }
18535: if ($changes{'categorize'}) {
18536: $resulttext .= '<li>'.&mt("$title{'categorize'} $level{$env{'form.categorize'}}").'</li>';
1.48 raeburn 18537: }
1.120 raeburn 18538: if ($changes{'togglecatscomm'}) {
18539: $resulttext .= '<li>'.&mt("$title{'togglecatscomm'} $level{$env{'form.togglecatscomm'}}").'</li>';
18540: }
18541: if ($changes{'categorizecomm'}) {
18542: $resulttext .= '<li>'.&mt("$title{'categorizecomm'} $level{$env{'form.categorizecomm'}}").'</li>';
18543: }
1.160.6.42 raeburn 18544: if ($changes{'unauth'}) {
18545: $resulttext .= '<li>'.&mt('Catalog type for unauthenticated users set to "'.$level{$env{'form.coursecat_unauth'}}.'"').'</li>';
18546: }
18547: if ($changes{'auth'}) {
18548: $resulttext .= '<li>'.&mt('Catalog type for authenticated users set to "'.$level{$env{'form.coursecat_auth'}}.'"').'</li>';
18549: }
1.57 raeburn 18550: if ((keys(%deletions) > 0) || (keys(%reorderings) > 0) || (keys(%adds) > 0)) {
18551: my $cathash;
18552: if (ref($domconfig{'coursecategories'}) eq 'HASH') {
18553: $cathash = $domconfig{'coursecategories'}{'cats'};
18554: } else {
18555: $cathash = {};
18556: }
18557: my (@cats,@trails,%allitems);
18558: &Apache::loncommon::extract_categories($cathash,\@cats,\@trails,\%allitems);
18559: if (keys(%deletions) > 0) {
18560: $resulttext .= '<li>'.&mt('Deleted categories:').'<ul>';
18561: foreach my $predeltrail (sort {$a <=> $b } (keys(%sort_by_deltrail))) {
18562: $resulttext .= '<li>'.$predeltrails[$predeltrail].'</li>';
18563: }
18564: $resulttext .= '</ul></li>';
18565: }
18566: if (keys(%reorderings) > 0) {
18567: my %sort_by_trail;
18568: $resulttext .= '<li>'.&mt('Reordered categories:').'<ul>';
18569: foreach my $key (keys(%reorderings)) {
18570: if ($allitems{$key} ne '') {
18571: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18572: }
1.48 raeburn 18573: }
1.57 raeburn 18574: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18575: $resulttext .= '<li>'.$trails[$trail].'</li>';
18576: }
18577: $resulttext .= '</ul></li>';
1.48 raeburn 18578: }
1.57 raeburn 18579: if (keys(%adds) > 0) {
18580: my %sort_by_trail;
18581: $resulttext .= '<li>'.&mt('Added categories:').'<ul>';
18582: foreach my $key (keys(%adds)) {
18583: if ($allitems{$key} ne '') {
18584: $sort_by_trail{$allitems{$key}} = $trails[$allitems{$key}];
18585: }
18586: }
18587: foreach my $trail (sort {$a <=> $b } (keys(%sort_by_trail))) {
18588: $resulttext .= '<li>'.$trails[$trail].'</li>';
1.48 raeburn 18589: }
1.57 raeburn 18590: $resulttext .= '</ul></li>';
1.48 raeburn 18591: }
1.160.6.92 raeburn 18592: &Apache::lonnet::do_cache_new('cats',$dom,$cathash,3600);
18593: if (ref($lastactref) eq 'HASH') {
18594: $lastactref->{'cats'} = 1;
18595: }
1.48 raeburn 18596: }
18597: $resulttext .= '</ul>';
1.160.6.43 raeburn 18598: if ($changes{'unauth'} || $changes{'auth'}) {
1.160.6.50 raeburn 18599: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
18600: if ($changes{'auth'}) {
18601: $domdefaults{'catauth'} = $domconfig{'coursecategories'}{'auth'};
18602: }
18603: if ($changes{'unauth'}) {
18604: $domdefaults{'catunauth'} = $domconfig{'coursecategories'}{'unauth'};
18605: }
18606: my $cachetime = 24*60*60;
18607: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.43 raeburn 18608: if (ref($lastactref) eq 'HASH') {
1.160.6.50 raeburn 18609: $lastactref->{'domdefaults'} = 1;
1.160.6.43 raeburn 18610: }
18611: }
1.48 raeburn 18612: } else {
18613: $resulttext = '<span class="LC_error">'.
1.57 raeburn 18614: &mt('An error occurred: [_1]',$putresult).'</span>';
1.48 raeburn 18615: }
18616: } else {
1.120 raeburn 18617: $resulttext = &mt('No changes made to course and community categories');
1.48 raeburn 18618: }
18619: return $resulttext;
18620: }
18621:
1.69 raeburn 18622: sub modify_serverstatuses {
18623: my ($dom,%domconfig) = @_;
18624: my ($resulttext,%changes,%currserverstatus,%newserverstatus);
18625: if (ref($domconfig{'serverstatuses'}) eq 'HASH') {
18626: %currserverstatus = %{$domconfig{'serverstatuses'}};
18627: }
18628: my @pages = &serverstatus_pages();
18629: foreach my $type (@pages) {
18630: $newserverstatus{$type}{'namedusers'} = '';
18631: $newserverstatus{$type}{'machines'} = '';
18632: if (defined($env{'form.'.$type.'_namedusers'})) {
18633: my @users = split(/,/,$env{'form.'.$type.'_namedusers'});
18634: my @okusers;
18635: foreach my $user (@users) {
18636: my ($uname,$udom) = split(/:/,$user);
18637: if (($udom =~ /^$match_domain$/) &&
18638: (&Apache::lonnet::domain($udom)) &&
18639: ($uname =~ /^$match_username$/)) {
18640: if (!grep(/^\Q$user\E/,@okusers)) {
18641: push(@okusers,$user);
18642: }
18643: }
18644: }
18645: if (@okusers > 0) {
18646: @okusers = sort(@okusers);
18647: $newserverstatus{$type}{'namedusers'} = join(',',@okusers);
18648: }
18649: }
18650: if (defined($env{'form.'.$type.'_machines'})) {
18651: my @machines = split(/,/,$env{'form.'.$type.'_machines'});
18652: my @okmachines;
18653: foreach my $ip (@machines) {
18654: my @parts = split(/\./,$ip);
18655: next if (@parts < 4);
18656: my $badip = 0;
18657: for (my $i=0; $i<4; $i++) {
18658: if (!(($parts[$i] >= 0) && ($parts[$i] <= 255))) {
18659: $badip = 1;
18660: last;
18661: }
18662: }
18663: if (!$badip) {
18664: push(@okmachines,$ip);
18665: }
18666: }
18667: @okmachines = sort(@okmachines);
18668: $newserverstatus{$type}{'machines'} = join(',',@okmachines);
18669: }
18670: }
18671: my %serverstatushash = (
18672: serverstatuses => \%newserverstatus,
18673: );
18674: foreach my $type (@pages) {
1.83 raeburn 18675: foreach my $setting ('namedusers','machines') {
1.84 raeburn 18676: my (@current,@new);
1.83 raeburn 18677: if (ref($currserverstatus{$type}) eq 'HASH') {
1.84 raeburn 18678: if ($currserverstatus{$type}{$setting} ne '') {
18679: @current = split(/,/,$currserverstatus{$type}{$setting});
18680: }
18681: }
18682: if ($newserverstatus{$type}{$setting} ne '') {
18683: @new = split(/,/,$newserverstatus{$type}{$setting});
1.83 raeburn 18684: }
18685: if (@current > 0) {
18686: if (@new > 0) {
18687: foreach my $item (@current) {
18688: if (!grep(/^\Q$item\E$/,@new)) {
18689: $changes{$type}{$setting} = 1;
1.82 raeburn 18690: last;
18691: }
18692: }
1.84 raeburn 18693: foreach my $item (@new) {
18694: if (!grep(/^\Q$item\E$/,@current)) {
18695: $changes{$type}{$setting} = 1;
18696: last;
1.82 raeburn 18697: }
18698: }
18699: } else {
1.83 raeburn 18700: $changes{$type}{$setting} = 1;
1.69 raeburn 18701: }
1.83 raeburn 18702: } elsif (@new > 0) {
18703: $changes{$type}{$setting} = 1;
1.69 raeburn 18704: }
18705: }
18706: }
18707: if (keys(%changes) > 0) {
1.81 raeburn 18708: my $titles= &LONCAPA::lonauthcgi::serverstatus_titles();
1.69 raeburn 18709: my $putresult = &Apache::lonnet::put_dom('configuration',
18710: \%serverstatushash,$dom);
18711: if ($putresult eq 'ok') {
18712: $resulttext .= &mt('Changes made:').'<ul>';
18713: foreach my $type (@pages) {
1.84 raeburn 18714: if (ref($changes{$type}) eq 'HASH') {
1.69 raeburn 18715: $resulttext .= '<li>'.$titles->{$type}.'<ul>';
1.84 raeburn 18716: if ($changes{$type}{'namedusers'}) {
1.69 raeburn 18717: if ($newserverstatus{$type}{'namedusers'} eq '') {
18718: $resulttext .= '<li>'.&mt("Access terminated for all specific (named) users").'</li>'."\n";
18719: } else {
18720: $resulttext .= '<li>'.&mt("Access available for the following specified users: ").$newserverstatus{$type}{'namedusers'}.'</li>'."\n";
18721: }
1.84 raeburn 18722: }
18723: if ($changes{$type}{'machines'}) {
1.69 raeburn 18724: if ($newserverstatus{$type}{'machines'} eq '') {
18725: $resulttext .= '<li>'.&mt("Access terminated for all specific IP addresses").'</li>'."\n";
18726: } else {
18727: $resulttext .= '<li>'.&mt("Access available for the following specified IP addresses: ").$newserverstatus{$type}{'machines'}.'</li>'."\n";
18728: }
18729:
18730: }
18731: $resulttext .= '</ul></li>';
18732: }
18733: }
18734: $resulttext .= '</ul>';
18735: } else {
18736: $resulttext = '<span class="LC_error">'.
18737: &mt('An error occurred saving access settings for server status pages: [_1].',$putresult).'</span>';
18738:
18739: }
18740: } else {
18741: $resulttext = &mt('No changes made to access to server status pages');
18742: }
18743: return $resulttext;
18744: }
18745:
1.118 jms 18746: sub modify_helpsettings {
1.160.6.77 raeburn 18747: my ($r,$dom,$confname,$lastactref,%domconfig) = @_;
1.160.6.5 raeburn 18748: my ($resulttext,$errors,%changes,%helphash);
18749: my %defaultchecked = ('submitbugs' => 'on');
18750: my @offon = ('off','on');
1.118 jms 18751: my @toggles = ('submitbugs');
1.160.6.77 raeburn 18752: my %current = ('submitbugs' => '',
18753: 'adhoc' => {},
18754: );
1.118 jms 18755: if (ref($domconfig{'helpsettings'}) eq 'HASH') {
1.160.6.73 raeburn 18756: %current = %{$domconfig{'helpsettings'}};
18757: }
1.160.6.77 raeburn 18758: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.73 raeburn 18759: foreach my $item (@toggles) {
18760: if ($defaultchecked{$item} eq 'on') {
18761: if ($current{$item} eq '') {
18762: if ($env{'form.'.$item} eq '0') {
1.160.6.5 raeburn 18763: $changes{$item} = 1;
18764: }
1.160.6.73 raeburn 18765: } elsif ($current{$item} ne $env{'form.'.$item}) {
18766: $changes{$item} = 1;
18767: }
18768: } elsif ($defaultchecked{$item} eq 'off') {
18769: if ($current{$item} eq '') {
18770: if ($env{'form.'.$item} eq '1') {
1.160.6.5 raeburn 18771: $changes{$item} = 1;
18772: }
1.160.6.73 raeburn 18773: } elsif ($current{$item} ne $env{'form.'.$item}) {
18774: $changes{$item} = 1;
18775: }
18776: }
18777: if (($env{'form.'.$item} eq '0') || ($env{'form.'.$item} eq '1')) {
18778: $helphash{'helpsettings'}{$item} = $env{'form.'.$item};
18779: }
18780: }
1.160.6.77 raeburn 18781: my $maxnum = $env{'form.helproles_maxnum'};
1.160.6.73 raeburn 18782: my $confname = $dom.'-domainconfig';
18783: my %existing=&Apache::lonnet::dump('roles',$dom,$confname,'rolesdef_');
1.160.6.77 raeburn 18784: my (@allpos,%newsettings,%changedprivs,$newrole);
18785: my ($othertitle,$usertypes,$types) = &Apache::loncommon::sorted_inst_types($dom);
1.160.6.79 raeburn 18786: my @accesstypes = ('all','dh','da','none','status','inc','exc');
18787: my %domhelpdesk = &Apache::lonnet::get_active_domroles($dom,['dh','da']);
1.160.6.77 raeburn 18788: my %lt = &Apache::lonlocal::texthash(
18789: s => 'system',
18790: d => 'domain',
18791: order => 'Display order',
18792: access => 'Role usage',
1.160.6.79 raeburn 18793: all => 'All with domain helpdesk or helpdesk assistant role',
18794: dh => 'All with domain helpdesk role',
18795: da => 'All with domain helpdesk assistant role',
1.160.6.77 raeburn 18796: none => 'None',
18797: status => 'Determined based on institutional status',
18798: inc => 'Include all, but exclude specific personnel',
18799: exc => 'Exclude all, but include specific personnel',
18800: );
18801: for (my $num=0; $num<=$maxnum; $num++) {
18802: my ($prefix,$identifier,$rolename,%curr);
18803: if ($num == $maxnum) {
18804: next unless ($env{'form.newcusthelp'} == $maxnum);
18805: $identifier = 'custhelp'.$num;
18806: $prefix = 'helproles_'.$num;
18807: $rolename = $env{'form.custhelpname'.$num};
18808: $rolename=~s/[^A-Za-z0-9]//gs;
18809: next if ($rolename eq '');
18810: next if (exists($existing{'rolesdef_'.$rolename}));
18811: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18812: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18813: $newprivs{'c'},$confname,$dom);
18814: if ($result ne 'ok') {
18815: $errors .= '<li><span class="LC_error">'.
18816: &mt('An error occurred storing the new custom role: [_1]',
18817: $result).'</span></li>';
18818: next;
18819: } else {
18820: $changedprivs{$rolename} = \%newprivs;
18821: $newrole = $rolename;
18822: }
18823: } else {
18824: $prefix = 'helproles_'.$num;
18825: $rolename = $env{'form.'.$prefix};
18826: next if ($rolename eq '');
18827: next unless (exists($existing{'rolesdef_'.$rolename}));
18828: $identifier = 'custhelp'.$num;
18829: my %newprivs = &Apache::lonuserutils::custom_role_update($rolename,$identifier);
18830: my %currprivs;
18831: ($currprivs{'s'},$currprivs{'d'},$currprivs{'c'}) =
18832: split(/\_/,$existing{'rolesdef_'.$rolename});
18833: foreach my $level ('c','d','s') {
18834: if ($newprivs{$level} ne $currprivs{$level}) {
18835: my $result = &Apache::lonnet::definerole($rolename,$newprivs{'s'},$newprivs{'d'},
18836: $newprivs{'c'},$confname,$dom);
18837: if ($result ne 'ok') {
18838: $errors .= '<li><span class="LC_error">'.
18839: &mt('An error occurred storing privileges for existing role [_1]: [_2]',
18840: $rolename,$result).'</span></li>';
18841: } else {
18842: $changedprivs{$rolename} = \%newprivs;
18843: }
18844: last;
18845: }
18846: }
18847: if (ref($current{'adhoc'}) eq 'HASH') {
18848: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18849: %curr = %{$current{'adhoc'}{$rolename}};
18850: }
18851: }
18852: }
18853: my $newpos = $env{'form.'.$prefix.'_pos'};
18854: $newpos =~ s/\D+//g;
18855: $allpos[$newpos] = $rolename;
18856: my $newdesc = $env{'form.'.$prefix.'_desc'};
18857: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'desc'} = $newdesc;
18858: if ($curr{'desc'}) {
18859: if ($curr{'desc'} ne $newdesc) {
18860: $changes{'customrole'}{$rolename}{'desc'} = 1;
18861: $newsettings{$rolename}{'desc'} = $newdesc;
18862: }
18863: } elsif ($newdesc ne '') {
18864: $changes{'customrole'}{$rolename}{'desc'} = 1;
18865: $newsettings{$rolename}{'desc'} = $newdesc;
18866: }
18867: my $access = $env{'form.'.$prefix.'_access'};
18868: if (grep(/^\Q$access\E$/,@accesstypes)) {
18869: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = $access;
18870: if ($access eq 'status') {
18871: my @statuses = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_status');
18872: if (scalar(@statuses) == 0) {
18873: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'none';
18874: } else {
18875: my (@shownstatus,$numtypes);
18876: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18877: if (ref($types) eq 'ARRAY') {
18878: $numtypes = scalar(@{$types});
18879: foreach my $type (sort(@statuses)) {
18880: if ($type eq 'default') {
18881: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18882: } elsif (grep(/^\Q$type\E$/,@{$types})) {
18883: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$type);
18884: push(@shownstatus,$usertypes->{$type});
18885: }
1.160.6.73 raeburn 18886: }
18887: }
1.160.6.77 raeburn 18888: if (grep(/^default$/,@statuses)) {
18889: push(@shownstatus,$othertitle);
18890: }
18891: if (scalar(@shownstatus) == 1+$numtypes) {
18892: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'} = 'all';
18893: delete($helphash{'helpsettings'}{'adhoc'}{$rolename}{'status'});
18894: } else {
18895: $newsettings{$rolename}{'status'} = join(' '.&mt('or').' ',@shownstatus);
18896: if (ref($curr{'status'}) eq 'ARRAY') {
18897: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18898: if (@diffs) {
18899: $changes{'customrole'}{$rolename}{$access} = 1;
18900: }
18901: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18902: $changes{'customrole'}{$rolename}{$access} = 1;
18903: }
18904: }
18905: }
18906: } elsif (($access eq 'inc') || ($access eq 'exc')) {
18907: my @personnel = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_staff_'.$access);
18908: my @newspecstaff;
18909: $helphash{'helpsettings'}{'adhoc'}{$rolename}{$access} = [];
18910: foreach my $person (sort(@personnel)) {
18911: if ($domhelpdesk{$person}) {
18912: push(@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}},$person);
18913: }
18914: }
18915: if (ref($curr{$access}) eq 'ARRAY') {
18916: my @diffs = &Apache::loncommon::compare_arrays($helphash{'helpsettings'}{'adhoc'}{$rolename}{$access},$curr{$access});
18917: if (@diffs) {
18918: $changes{'customrole'}{$rolename}{$access} = 1;
18919: }
18920: } elsif (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18921: $changes{'customrole'}{$rolename}{$access} = 1;
1.160.6.73 raeburn 18922: }
1.160.6.77 raeburn 18923: foreach my $person (@{$helphash{'helpsettings'}{'adhoc'}{$rolename}{$access}}) {
18924: my ($uname,$udom) = split(/:/,$person);
18925: push(@newspecstaff,&Apache::loncommon::aboutmewrapper(&Apache::loncommon::plainname($uname,$udom,'lastname'),$uname,$udom));
18926: }
18927: $newsettings{$rolename}{$access} = join(', ',sort(@newspecstaff));
1.160.6.26 raeburn 18928: }
1.160.6.77 raeburn 18929: } else {
18930: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}= 'all';
18931: }
18932: unless ($curr{'access'} eq $access) {
18933: $changes{'customrole'}{$rolename}{'access'} = 1;
18934: $newsettings{$rolename}{'access'} = $lt{$helphash{'helpsettings'}{'adhoc'}{$rolename}{'access'}};
1.160.6.73 raeburn 18935: }
18936: }
1.160.6.77 raeburn 18937: if (@allpos > 0) {
18938: my $idx = 0;
18939: foreach my $rolename (@allpos) {
18940: if ($rolename ne '') {
18941: $helphash{'helpsettings'}{'adhoc'}{$rolename}{'order'} = $idx;
18942: if (ref($current{'adhoc'}) eq 'HASH') {
18943: if (ref($current{'adhoc'}{$rolename}) eq 'HASH') {
18944: if ($current{'adhoc'}{$rolename}{'order'} ne $idx) {
18945: $changes{'customrole'}{$rolename}{'order'} = 1;
18946: $newsettings{$rolename}{'order'} = $idx+1;
18947: }
18948: }
1.160.6.73 raeburn 18949: }
1.160.6.77 raeburn 18950: $idx ++;
1.122 jms 18951: }
18952: }
1.118 jms 18953: }
1.123 jms 18954: my $putresult;
18955: if (keys(%changes) > 0) {
1.160.6.5 raeburn 18956: $putresult = &Apache::lonnet::put_dom('configuration',\%helphash,$dom);
18957: if ($putresult eq 'ok') {
1.160.6.77 raeburn 18958: if (ref($helphash{'helpsettings'}) eq 'HASH') {
18959: $domdefaults{'submitbugs'} = $helphash{'helpsettings'}{'submitbugs'};
18960: if (ref($helphash{'helpsettings'}{'adhoc'}) eq 'HASH') {
18961: $domdefaults{'adhocroles'} = $helphash{'helpsettings'}{'adhoc'};
18962: }
18963: }
18964: my $cachetime = 24*60*60;
18965: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
18966: if (ref($lastactref) eq 'HASH') {
18967: $lastactref->{'domdefaults'} = 1;
18968: }
18969: } else {
18970: $errors .= '<li><span class="LC_error">'.
18971: &mt('An error occurred storing the settings: [_1]',
18972: $putresult).'</span></li>';
18973: }
18974: }
18975: if ((keys(%changes) && ($putresult eq 'ok')) || (keys(%changedprivs))) {
18976: $resulttext = &mt('Changes made:').'<ul>';
18977: my (%shownprivs,@levelorder);
18978: @levelorder = ('c','d','s');
18979: if ((keys(%changes)) && ($putresult eq 'ok')) {
1.160.6.5 raeburn 18980: foreach my $item (sort(keys(%changes))) {
18981: if ($item eq 'submitbugs') {
18982: $resulttext .= '<li>'.&mt('Display link to: [_1] set to "'.$offon[$env{'form.'.$item}].'".',
18983: &Apache::loncommon::modal_link('http://bugs.loncapa.org',
18984: &mt('LON-CAPA bug tracker'),600,500)).'</li>';
1.160.6.73 raeburn 18985: } elsif ($item eq 'customrole') {
18986: if (ref($changes{'customrole'}) eq 'HASH') {
1.160.6.77 raeburn 18987: my @keyorder = ('order','desc','access','status','exc','inc');
18988: my %keytext = &Apache::lonlocal::texthash(
18989: order => 'Order',
18990: desc => 'Role description',
18991: access => 'Role usage',
1.160.6.83 raeburn 18992: status => 'Allowed institutional types',
1.160.6.77 raeburn 18993: exc => 'Allowed personnel',
18994: inc => 'Disallowed personnel',
18995: );
1.160.6.73 raeburn 18996: foreach my $role (sort(keys(%{$changes{'customrole'}}))) {
1.160.6.77 raeburn 18997: if (ref($changes{'customrole'}{$role}) eq 'HASH') {
18998: if ($role eq $newrole) {
18999: $resulttext .= '<li>'.&mt('New custom role added: [_1]',
19000: $role).'<ul>';
19001: } else {
19002: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19003: $role).'<ul>';
19004: }
19005: foreach my $key (@keyorder) {
19006: if ($changes{'customrole'}{$role}{$key}) {
19007: $resulttext .= '<li>'.&mt("[_1] set to: [_2]",
19008: $keytext{$key},$newsettings{$role}{$key}).
19009: '</li>';
19010: }
19011: }
19012: if (ref($changedprivs{$role}) eq 'HASH') {
19013: $shownprivs{$role} = 1;
19014: $resulttext .= '<li>'.&mt('Privileges set to :').'<ul>';
19015: foreach my $level (@levelorder) {
19016: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19017: next if ($item eq '');
19018: my ($priv) = split(/\&/,$item,2);
19019: if (&Apache::lonnet::plaintext($priv)) {
19020: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19021: unless ($level eq 'c') {
19022: $resulttext .= ' ('.$lt{$level}.')';
19023: }
19024: $resulttext .= '</li>';
19025: }
19026: }
19027: }
19028: $resulttext .= '</ul>';
19029: }
19030: $resulttext .= '</ul></li>';
19031: }
1.160.6.73 raeburn 19032: }
19033: }
1.160.6.5 raeburn 19034: }
19035: }
19036: }
1.160.6.77 raeburn 19037: if (keys(%changedprivs)) {
19038: foreach my $role (sort(keys(%changedprivs))) {
19039: unless ($shownprivs{$role}) {
19040: $resulttext .= '<li>'.&mt('Existing custom role modified: [_1]',
19041: $role).'<ul>'.
19042: '<li>'.&mt('Privileges set to :').'<ul>';
19043: foreach my $level (@levelorder) {
19044: foreach my $item (split(/\:/,$changedprivs{$role}{$level})) {
19045: next if ($item eq '');
19046: my ($priv) = split(/\&/,$item,2);
19047: if (&Apache::lonnet::plaintext($priv)) {
19048: $resulttext .= '<li>'.&Apache::lonnet::plaintext($priv);
19049: unless ($level eq 'c') {
19050: $resulttext .= ' ('.$lt{$level}.')';
19051: }
19052: $resulttext .= '</li>';
19053: }
19054: }
19055: }
19056: $resulttext .= '</ul></li></ul></li>';
19057: }
19058: }
19059: }
19060: $resulttext .= '</ul>';
19061: } else {
19062: $resulttext = &mt('No changes made to help settings');
1.118 jms 19063: }
19064: if ($errors) {
1.160.6.5 raeburn 19065: $resulttext .= '<br />'.&mt('The following errors occurred: ').'<ul>'.
1.160.6.77 raeburn 19066: $errors.'</ul>';
1.118 jms 19067: }
19068: return $resulttext;
19069: }
19070:
1.121 raeburn 19071: sub modify_coursedefaults {
1.160.6.27 raeburn 19072: my ($dom,$lastactref,%domconfig) = @_;
1.121 raeburn 19073: my ($resulttext,$errors,%changes,%defaultshash);
1.160.6.57 raeburn 19074: my %defaultchecked = (
19075: 'uselcmath' => 'on',
1.160.6.115 raeburn 19076: 'usejsme' => 'on',
19077: 'inline_chem' => 'on',
1.160.6.118.2 4(raebur 19078:2): 'ltiauth' => 'off',
1.160.6.57 raeburn 19079: );
1.160.6.118.2 4(raebur 19080:2): my @toggles = ('uselcmath','usejsme','inline_chem','ltiauth');
1.160.6.21 raeburn 19081: my @numbers = ('anonsurvey_threshold','uploadquota_official','uploadquota_unofficial',
1.160.6.118.2 15(raebu 19082:23): 'uploadquota_community','uploadquota_textbook','coursequota_official',
19083:23): 'coursequota_unofficial','coursequota_community','coursequota_textbook',
19084:23): 'mysqltables_official','mysqltables_unofficial','mysqltables_community',
19085:23): 'mysqltables_textbook');
1.160.6.30 raeburn 19086: my @types = ('official','unofficial','community','textbook');
1.160.6.21 raeburn 19087: my %staticdefaults = (
19088: anonsurvey_threshold => 10,
19089: uploadquota => 500,
1.160.6.118.2 15(raebu 19090:23): coursequota => 20,
1.160.6.57 raeburn 19091: postsubmit => 60,
1.160.6.70 raeburn 19092: mysqltables => 172800,
1.160.6.118.2 14(raebu 19093:23): domexttool => 1,
22(raebu 19094:24): crseditors => ['edit','xml'],
1.160.6.21 raeburn 19095: );
1.160.6.90 raeburn 19096: my %texoptions = (
19097: MathJax => 'MathJax',
19098: mimetex => &mt('Convert to Images'),
19099: tth => &mt('TeX to HTML'),
19100: );
1.160.6.118.2 22(raebu 19101:24):
19102:24): my @editors = ('edit','xml','daxe');
19103:24): my %editornames = &crseditor_titles();
19104:24):
1.121 raeburn 19105: $defaultshash{'coursedefaults'} = {};
19106:
19107: if (ref($domconfig{'coursedefaults'}) ne 'HASH') {
19108: if ($domconfig{'coursedefaults'} eq '') {
19109: $domconfig{'coursedefaults'} = {};
19110: }
19111: }
19112:
19113: if (ref($domconfig{'coursedefaults'}) eq 'HASH') {
19114: foreach my $item (@toggles) {
19115: if ($defaultchecked{$item} eq 'on') {
19116: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19117: ($env{'form.'.$item} eq '0')) {
19118: $changes{$item} = 1;
1.160.6.16 raeburn 19119: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
1.121 raeburn 19120: $changes{$item} = 1;
19121: }
19122: } elsif ($defaultchecked{$item} eq 'off') {
19123: if (($domconfig{'coursedefaults'}{$item} eq '') &&
19124: ($env{'form.'.$item} eq '1')) {
19125: $changes{$item} = 1;
19126: } elsif ($domconfig{'coursedefaults'}{$item} ne $env{'form.'.$item}) {
19127: $changes{$item} = 1;
19128: }
19129: }
19130: $defaultshash{'coursedefaults'}{$item} = $env{'form.'.$item};
19131: }
1.160.6.21 raeburn 19132: foreach my $item (@numbers) {
19133: my ($currdef,$newdef);
1.160.6.26 raeburn 19134: $newdef = $env{'form.'.$item};
1.160.6.21 raeburn 19135: if ($item eq 'anonsurvey_threshold') {
19136: $currdef = $domconfig{'coursedefaults'}{$item};
19137: $newdef =~ s/\D//g;
19138: if ($newdef eq '' || $newdef < 1) {
19139: $newdef = 1;
19140: }
19141: $defaultshash{'coursedefaults'}{$item} = $newdef;
19142: } else {
1.160.6.118.2 15(raebu 19143:23): my ($setting,$type) = ($item =~ /^(uploadquota|coursequota|mysqltables)_(\w+)$/);
1.160.6.70 raeburn 19144: if (ref($domconfig{'coursedefaults'}{$setting}) eq 'HASH') {
19145: $currdef = $domconfig{'coursedefaults'}{$setting}{$type};
1.160.6.21 raeburn 19146: }
19147: $newdef =~ s/[^\w.\-]//g;
1.160.6.70 raeburn 19148: $defaultshash{'coursedefaults'}{$setting}{$type} = $newdef;
1.160.6.21 raeburn 19149: }
19150: if ($currdef ne $newdef) {
19151: if ($item eq 'anonsurvey_threshold') {
19152: unless (($currdef eq '') && ($newdef == $staticdefaults{$item})) {
19153: $changes{$item} = 1;
19154: }
1.160.6.118.2 15(raebu 19155:23): } elsif ($item =~ /^(uploadquota|coursequota|mysqltables)_/) {
1.160.6.70 raeburn 19156: my $setting = $1;
19157: unless (($currdef eq '') && ($newdef == $staticdefaults{$setting})) {
19158: $changes{$setting} = 1;
1.160.6.21 raeburn 19159: }
19160: }
1.139 raeburn 19161: }
19162: }
1.160.6.90 raeburn 19163: my $texengine;
19164: if ($env{'form.texengine'} =~ /^(MathJax|mimetex|tth)$/) {
19165: $texengine = $env{'form.texengine'};
19166: my $currdef = $domconfig{'coursedefaults'}{'texengine'};
19167: if ($currdef eq '') {
19168: unless ($texengine eq $Apache::lonnet::deftex) {
19169: $changes{'texengine'} = 1;
19170: }
19171: } elsif ($currdef ne $texengine) {
19172: $changes{'texengine'} = 1;
19173: }
19174: }
19175: if ($texengine ne '') {
19176: $defaultshash{'coursedefaults'}{'texengine'} = $texengine;
19177: }
1.160.6.64 raeburn 19178: my $currclone = $domconfig{'coursedefaults'}{'canclone'};
19179: my @currclonecode;
19180: if (ref($currclone) eq 'HASH') {
19181: if (ref($currclone->{'instcode'}) eq 'ARRAY') {
19182: @currclonecode = @{$currclone->{'instcode'}};
19183: }
19184: }
19185: my $newclone;
19186: if ($env{'form.canclone'} =~ /^(none|domain|instcode)$/) {
19187: $newclone = $env{'form.canclone'};
19188: }
19189: if ($newclone eq 'instcode') {
19190: my @newcodes = &Apache::loncommon::get_env_multiple('form.clonecode');
19191: my (%codedefaults,@code_order,@clonecode);
19192: &Apache::lonnet::auto_instcode_defaults($dom,\%codedefaults,
19193: \@code_order);
19194: foreach my $item (@code_order) {
19195: if (grep(/^\Q$item\E$/,@newcodes)) {
19196: push(@clonecode,$item);
19197: }
19198: }
19199: if (@clonecode) {
19200: $defaultshash{'coursedefaults'}{'canclone'} = { $newclone => \@clonecode };
19201: my @diffs = &Apache::loncommon::compare_arrays(\@currclonecode,\@clonecode);
19202: if (@diffs) {
19203: $changes{'canclone'} = 1;
19204: }
19205: } else {
19206: $newclone eq '';
19207: }
19208: } elsif ($newclone ne '') {
19209: $defaultshash{'coursedefaults'}{'canclone'} = $newclone;
19210: }
19211: if ($newclone ne $currclone) {
19212: $changes{'canclone'} = 1;
19213: }
1.160.6.57 raeburn 19214: my %credits;
19215: foreach my $type (@types) {
19216: unless ($type eq 'community') {
19217: $credits{$type} = $env{'form.'.$type.'_credits'};
19218: $credits{$type} =~ s/[^\d.]+//g;
19219: }
19220: }
19221: if ((ref($domconfig{'coursedefaults'}{'coursecredits'}) ne 'HASH') &&
19222: ($env{'form.coursecredits'} eq '1')) {
19223: $changes{'coursecredits'} = 1;
19224: foreach my $type (keys(%credits)) {
19225: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19226: }
19227: } else {
19228: if ($env{'form.coursecredits'} eq '1') {
19229: foreach my $type (@types) {
19230: unless ($type eq 'community') {
19231: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type} ne $credits{$type}) {
19232: $changes{'coursecredits'} = 1;
19233: }
19234: $defaultshash{'coursedefaults'}{'coursecredits'}{$type} = $credits{$type};
19235: }
19236: }
19237: } elsif (ref($domconfig{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19238: foreach my $type (@types) {
19239: unless ($type eq 'community') {
19240: if ($domconfig{'coursedefaults'}{'coursecredits'}{$type}) {
19241: $changes{'coursecredits'} = 1;
19242: last;
19243: }
19244: }
19245: }
19246: }
19247: }
19248: if ($env{'form.postsubmit'} eq '1') {
19249: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'on';
19250: my %currtimeout;
19251: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19252: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'off') {
19253: $changes{'postsubmit'} = 1;
19254: }
19255: if (ref($domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19256: %currtimeout = %{$domconfig{'coursedefaults'}{'postsubmit'}{'timeout'}};
19257: }
19258: } else {
19259: $changes{'postsubmit'} = 1;
19260: }
19261: foreach my $type (@types) {
19262: my $timeout = $env{'form.'.$type.'_timeout'};
19263: $timeout =~ s/\D//g;
19264: if ($timeout == $staticdefaults{'postsubmit'}) {
19265: $timeout = '';
19266: } elsif (($timeout eq '') || ($timeout =~ /^0+$/)) {
19267: $timeout = '0';
19268: }
19269: unless ($timeout eq '') {
19270: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type} = $timeout;
19271: }
19272: if (exists($currtimeout{$type})) {
19273: if ($timeout ne $currtimeout{$type}) {
19274: $changes{'postsubmit'} = 1;
19275: }
19276: } elsif ($timeout ne '') {
19277: $changes{'postsubmit'} = 1;
19278: }
19279: }
19280: } else {
19281: $defaultshash{'coursedefaults'}{'postsubmit'}{'client'} = 'off';
19282: if (ref($domconfig{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19283: if ($domconfig{'coursedefaults'}{'postsubmit'}{'client'} eq 'on') {
19284: $changes{'postsubmit'} = 1;
19285: }
19286: } else {
19287: $changes{'postsubmit'} = 1;
19288: }
1.160.6.16 raeburn 19289: }
1.160.6.118.2 22(raebu 19290:24): my (%newdomexttool,%newexttool,%olddomexttool,%oldexttool,%posscrseditors);
14(raebu 19291:23): map { $newdomexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.domexttool');
19292:23): map { $newexttool{$_} = 1; } &Apache::loncommon::get_env_multiple('form.exttool');
22(raebu 19293:24): map { $posscrseditors{$_} = 1; } &Apache::loncommon::get_env_multiple('form.crseditors');
14(raebu 19294:23): if (ref($domconfig{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19295:23): %olddomexttool = %{$domconfig{'coursedefaults'}{'domexttool'}};
19296:23): } else {
19297:23): foreach my $type (@types) {
19298:23): if ($staticdefaults{'domexttool'}) {
19299:23): $olddomexttool{$type} = 1;
19300:23): } else {
19301:23): $olddomexttool{$type} = 0;
19302:23): }
19303:23): }
19304:23): }
19305:23): if (ref($domconfig{'coursedefaults'}{'exttool'}) eq 'HASH') {
19306:23): %oldexttool = %{$domconfig{'coursedefaults'}{'exttool'}};
19307:23): } else {
19308:23): foreach my $type (@types) {
19309:23): if ($staticdefaults{'exttool'}) {
19310:23): $oldexttool{$type} = 1;
19311:23): } else {
19312:23): $oldexttool{$type} = 0;
19313:23): }
19314:23): }
19315:23): }
22(raebu 19316:24): my @newcrseditors = ();
19317:24): foreach my $editor (@editors) {
19318:24): if ($posscrseditors{$editor}) {
19319:24): push(@newcrseditors,$editor);
19320:24): }
19321:24): }
19322:24): if (ref($domconfig{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19323:24): my @diffs =
19324:24): &Apache::loncommon::compare_arrays($domconfig{'coursedefaults'}{'crseditors'},
19325:24): \@newcrseditors);
19326:24): if (@diffs) {
19327:24): $changes{'crseditors'} = 1;
19328:24): }
19329:24): } else {
19330:24): my @diffs =
19331:24): &Apache::loncommon::compare_arrays($staticdefaults{'crseditors'},
19332:24): \@newcrseditors);
19333:24): unless (@diffs == 0) {
19334:24): $changes{'crseditors'} = 1;
19335:24): }
19336:24): }
14(raebu 19337:23): foreach my $type (@types) {
19338:23): unless ($newdomexttool{$type}) {
19339:23): $newdomexttool{$type} = 0;
19340:23): }
19341:23): unless ($newexttool{$type}) {
19342:23): $newexttool{$type} = 0;
19343:23): }
19344:23): if ($newdomexttool{$type} != $olddomexttool{$type}) {
19345:23): $changes{'domexttool'} = 1;
19346:23): }
19347:23): if ($newexttool{$type} != $oldexttool{$type}) {
19348:23): $changes{'exttool'} = 1;
19349:23): }
19350:23): }
19351:23): $defaultshash{'coursedefaults'}{'domexttool'} = \%newdomexttool;
19352:23): $defaultshash{'coursedefaults'}{'exttool'} = \%newexttool;
22(raebu 19353:24): $defaultshash{'coursedefaults'}{'crseditors'} = \@newcrseditors;
1.121 raeburn 19354: }
19355: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
19356: $dom);
19357: if ($putresult eq 'ok') {
19358: if (keys(%changes) > 0) {
1.160.6.27 raeburn 19359: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.160.6.57 raeburn 19360: if (($changes{'uploadquota'}) || ($changes{'postsubmit'}) ||
1.160.6.64 raeburn 19361: ($changes{'coursecredits'}) || ($changes{'uselcmath'}) || ($changes{'usejsme'}) ||
1.160.6.115 raeburn 19362: ($changes{'canclone'}) || ($changes{'mysqltables'}) || ($changes{'texengine'}) ||
1.160.6.118.2 14(raebu 19363:23): ($changes{'inline_chem'}) || ($changes{'ltiauth'}) || ($changes{'domexttool'}) ||
15(raebu 19364:23): ($changes{'exttool'}) || ($changes{'coursequota'})) {
4(raebur 19365:2): foreach my $item ('uselcmath','usejsme','inline_chem','texengine','ltiauth') {
1.160.6.57 raeburn 19366: if ($changes{$item}) {
19367: $domdefaults{$item}=$defaultshash{'coursedefaults'}{$item};
19368: }
1.160.6.16 raeburn 19369: }
19370: if ($changes{'coursecredits'}) {
19371: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
1.160.6.57 raeburn 19372: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'coursecredits'}})) {
19373: $domdefaults{$type.'credits'} =
19374: $defaultshash{'coursedefaults'}{'coursecredits'}{$type};
19375: }
19376: }
19377: }
19378: if ($changes{'postsubmit'}) {
19379: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19380: $domdefaults{'postsubmit'} = $defaultshash{'coursedefaults'}{'postsubmit'}{'client'};
19381: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19382: foreach my $type (keys(%{$defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}})) {
19383: $domdefaults{$type.'postsubtimeout'} =
19384: $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19385: }
19386: }
1.160.6.16 raeburn 19387: }
19388: }
1.160.6.21 raeburn 19389: if ($changes{'uploadquota'}) {
19390: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19391: foreach my $type (@types) {
19392: $domdefaults{$type.'quota'}=$defaultshash{'coursedefaults'}{'uploadquota'}{$type};
19393: }
19394: }
19395: }
1.160.6.118.2 15(raebu 19396:23): if ($changes{'coursequota'}) {
19397:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19398:23): foreach my $type (@types) {
19399:23): $domdefaults{$type.'coursequota'}=$defaultshash{'coursedefaults'}{'coursequota'}{$type};
19400:23): }
19401:23): }
19402:23): }
1.160.6.64 raeburn 19403: if ($changes{'canclone'}) {
19404: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19405: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19406: my @clonecodes = @{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}};
19407: if (@clonecodes) {
19408: $domdefaults{'canclone'} = join('+',@clonecodes);
19409: }
19410: }
19411: } else {
19412: $domdefaults{'canclone'}=$defaultshash{'coursedefaults'}{'canclone'};
19413: }
19414: }
1.160.6.118.2 14(raebu 19415:23): if ($changes{'domexttool'}) {
19416:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19417:23): foreach my $type (@types) {
19418:23): $domdefaults{$type.'domexttool'}=$defaultshash{'coursedefaults'}{'domexttool'}{$type};
19419:23): }
19420:23): }
19421:23): }
19422:23): if ($changes{'exttool'}) {
19423:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19424:23): foreach my $type (@types) {
19425:23): $domdefaults{$type.'exttool'}=$defaultshash{'coursedefaults'}{'exttool'}{$type};
19426:23): }
19427:23): }
19428:23): }
22(raebu 19429:24): if ($changes{'crseditors'}) {
19430:24): if (ref($defaultshash{'coursedefaults'}{'crseditors'}) eq 'ARRAY') {
19431:24): $domdefaults{'crseditors'}=join(',',@{$defaultshash{'coursedefaults'}{'crseditors'}});
19432:24): }
19433:24): }
1.121 raeburn 19434: my $cachetime = 24*60*60;
19435: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.27 raeburn 19436: if (ref($lastactref) eq 'HASH') {
19437: $lastactref->{'domdefaults'} = 1;
19438: }
1.121 raeburn 19439: }
19440: $resulttext = &mt('Changes made:').'<ul>';
19441: foreach my $item (sort(keys(%changes))) {
1.160.6.57 raeburn 19442: if ($item eq 'uselcmath') {
1.121 raeburn 19443: if ($env{'form.'.$item} eq '1') {
1.160.6.57 raeburn 19444: $resulttext .= '<li>'.&mt('Math preview uses LON-CAPA previewer (javascript), if supported by browser.').'</li>';
1.121 raeburn 19445: } else {
1.160.6.57 raeburn 19446: $resulttext .= '<li>'.&mt('Math preview uses DragMath (Java), if supported by client OS.').'</li>';
19447: }
19448: } elsif ($item eq 'usejsme') {
19449: if ($env{'form.'.$item} eq '1') {
19450: $resulttext .= '<li>'.&mt('Molecule editor uses JSME (HTML5), if supported by browser.').'</li>';
19451: } else {
19452: $resulttext .= '<li>'.&mt('Molecule editor uses JME (Java), if supported by client OS.').'</li>';
1.121 raeburn 19453: }
1.160.6.115 raeburn 19454: } elsif ($item eq 'inline_chem') {
19455: if ($env{'form.'.$item} eq '1') {
19456: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses inline previewer').'</li>';
19457: } else {
19458: $resulttext .= '<li>'.&mt('Chemical Reaction Response uses pop-up previewer').'</li>';
19459: }
1.160.6.90 raeburn 19460: } elsif ($item eq 'texengine') {
19461: if ($defaultshash{'coursedefaults'}{'texengine'} ne '') {
19462: $resulttext .= '<li>'.&mt('Default method to display mathematics set to: "[_1]"',
19463: $texoptions{$defaultshash{'coursedefaults'}{'texengine'}}).'</li>';
19464: }
1.139 raeburn 19465: } elsif ($item eq 'anonsurvey_threshold') {
1.160.6.26 raeburn 19466: $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 19467: } elsif ($item eq 'uploadquota') {
19468: if (ref($defaultshash{'coursedefaults'}{'uploadquota'}) eq 'HASH') {
19469: $resulttext .= '<li>'.&mt('Default quota for content uploaded to a course/community via Course Editor set as follows:').'<ul>'.
19470: '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'official'}.'</b>').'</li>'.
19471: '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'unofficial'}.'</b>').'</li>'.
1.160.6.30 raeburn 19472: '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'textbook'}.'</b>').'</li>'.
1.160.6.21 raeburn 19473: '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'uploadquota'}{'community'}.'</b>').'</li>'.
19474: '</ul>'.
19475: '</li>';
19476: } else {
19477: $resulttext .= '<li>'.&mt('Default quota for content uploaded via Course Editor remains default: [_1] MB',$staticdefaults{'uploadquota'}).'</li>';
19478: }
1.160.6.118.2 15(raebu 19479:23): } elsif ($item eq 'coursequota') {
19480:23): if (ref($defaultshash{'coursedefaults'}{'coursequota'}) eq 'HASH') {
19481:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course set as follows:').'<ul>'.
19482:23): '<li>'.&mt('Official courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'official'}.'</b>').'</li>'.
19483:23): '<li>'.&mt('Unofficial courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'unofficial'}.'</b>').'</li>'.
19484:23): '<li>'.&mt('Textbook courses: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'textbook'}.'</b>').'</li>'.
19485:23): '<li>'.&mt('Communities: [_1] MB','<b>'.$defaultshash{'coursedefaults'}{'coursequota'}{'community'}.'</b>').'</li>'.
19486:23): '</ul>'.
19487:23): '</li>';
19488:23): } else {
19489:23): $resulttext .= '<li>'.&mt('Default cumulative quota for all group portfolio spaces in course remains default: [_1] MB',$staticdefaults{'coursequota'}).'</li>';
19490:23): }
1.160.6.70 raeburn 19491: } elsif ($item eq 'mysqltables') {
19492: if (ref($defaultshash{'coursedefaults'}{'mysqltables'}) eq 'HASH') {
19493: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver').'<ul>'.
19494: '<li>'.&mt('Official courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'official'}.'</b>').'</li>'.
19495: '<li>'.&mt('Unofficial courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'unofficial'}.'</b>').'</li>'.
19496: '<li>'.&mt('Textbook courses: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'textbook'}.'</b>').'</li>'.
19497: '<li>'.&mt('Communities: [_1] s','<b>'.$defaultshash{'coursedefaults'}{'mysqltables'}{'community'}.'</b>').'</li>'.
19498: '</ul>'.
19499: '</li>';
19500: } else {
19501: $resulttext .= '<li>'.&mt('Lifetime of "Temporary" MySQL tables (student performance data) on homeserver remains default: [_1] s',$staticdefaults{'uploadquota'}).'</li>';
19502: }
1.160.6.57 raeburn 19503: } elsif ($item eq 'postsubmit') {
19504: if ($domdefaults{'postsubmit'} eq 'off') {
19505: $resulttext .= '<li>'.&mt('Submit button(s) remain enabled on page after student makes submission.');
19506: } else {
19507: $resulttext .= '<li>'.&mt('Submit button(s) disabled on page after student makes submission').'; ';
19508: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}) eq 'HASH') {
19509: $resulttext .= &mt('durations:').'<ul>';
19510: foreach my $type (@types) {
19511: $resulttext .= '<li>';
19512: my $timeout;
19513: if (ref($defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}) eq 'HASH') {
19514: $timeout = $defaultshash{'coursedefaults'}{'postsubmit'}{'timeout'}{$type};
19515: }
19516: my $display;
19517: if ($timeout eq '0') {
19518: $display = &mt('unlimited');
19519: } elsif ($timeout eq '') {
19520: $display = &mt('[quant,_1,second] (default)',$staticdefaults{'postsubmit'});
19521: } else {
19522: $display = &mt('[quant,_1,second]',$timeout);
19523: }
19524: if ($type eq 'community') {
19525: $resulttext .= &mt('Communities');
19526: } elsif ($type eq 'official') {
19527: $resulttext .= &mt('Official courses');
19528: } elsif ($type eq 'unofficial') {
19529: $resulttext .= &mt('Unofficial courses');
19530: } elsif ($type eq 'textbook') {
19531: $resulttext .= &mt('Textbook courses');
19532: }
19533: $resulttext .= ' -- '.$display.'</li>';
19534: }
19535: $resulttext .= '</ul>';
19536: }
19537: $resulttext .= '</li>';
19538: }
1.160.6.16 raeburn 19539: } elsif ($item eq 'coursecredits') {
19540: if (ref($defaultshash{'coursedefaults'}{'coursecredits'}) eq 'HASH') {
19541: if (($domdefaults{'officialcredits'} eq '') &&
1.160.6.30 raeburn 19542: ($domdefaults{'unofficialcredits'} eq '') &&
19543: ($domdefaults{'textbookcredits'} eq '')) {
1.160.6.16 raeburn 19544: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19545: } else {
19546: $resulttext .= '<li>'.&mt('Student credits can be set per course by a Domain Coordinator, with the following defaults applying:').'<ul>'.
19547: '<li>'.&mt('Official courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'official'}).'</li>'.
19548: '<li>'.&mt('Unofficial courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'unofficial'}).'</li>'.
1.160.6.30 raeburn 19549: '<li>'.&mt('Textbook courses: [_1]',$defaultshash{'coursedefaults'}{'coursecredits'}{'textbook'}).'</li>'.
1.160.6.16 raeburn 19550: '</ul>'.
19551: '</li>';
19552: }
19553: } else {
19554: $resulttext .= '<li>'.&mt('Student credits not in use for courses in this domain').'</li>';
19555: }
1.160.6.64 raeburn 19556: } elsif ($item eq 'canclone') {
19557: if (ref($defaultshash{'coursedefaults'}{'canclone'}) eq 'HASH') {
19558: if (ref($defaultshash{'coursedefaults'}{'canclone'}{'instcode'}) eq 'ARRAY') {
19559: my $clonecodes = join(' '.&mt('and').' ',@{$defaultshash{'coursedefaults'}{'canclone'}{'instcode'}});
19560: $resulttext .= '<li>'.&mt('By default, official courses can be cloned from existing courses with the same: [_1]','<b>'.$clonecodes.'</b>').'</li>';
19561: }
19562: } elsif ($defaultshash{'coursedefaults'}{'canclone'} eq 'domain') {
19563: $resulttext .= '<li>'.&mt('By default, a course requester can clone any course from his/her domain.').'</li>';
19564: } else {
19565: $resulttext .= '<li>'.&mt('By default, only course owner and coordinators may clone a course.').'</li>';
19566: }
1.160.6.118.2 4(raebur 19567:2): } elsif ($item eq 'ltiauth') {
19568:2): if ($env{'form.'.$item} eq '1') {
19569:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL need not require re-authentication').'</li>';
19570:2): } else {
19571:2): $resulttext .= '<li>'.&mt('LTI launch of deep-linked URL will require re-authentication').'</li>';
19572:2): }
14(raebu 19573:23): } elsif ($item eq 'domexttool') {
19574:23): my @noyes = (&mt('no'),&mt('yes'));
19575:23): if (ref($defaultshash{'coursedefaults'}{'domexttool'}) eq 'HASH') {
19576:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used as follows:').'<ul>'.
19577:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'official'}].'</b>').'</li>'.
19578:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'unofficial'}].'</b>').'</li>'.
19579:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'textbook'}].'</b>').'</li>'.
19580:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'placement'}].'</b>').'</li>'.
19581:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'domexttool'}{'community'}].'</b>').'</li>'.
19582:23): '</ul>'.
19583:23): '</li>';
19584:23): } else {
19585:23): $resulttext .= '<li>'.&mt('External Tools defined in the domain may be used in all course types, by default').'</li>';
19586:23): }
19587:23): } elsif ($item eq 'exttool') {
19588:23): my @noyes = (&mt('no'),&mt('yes'));
19589:23): if (ref($defaultshash{'coursedefaults'}{'exttool'}) eq 'HASH') {
19590:23): $resulttext .= '<li>'.&mt('External Tools can be defined and configured in course containers as follows:').'<ul>'.
19591:23): '<li>'.&mt('Official courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'official'}].'</b>').'</li>'.
19592:23): '<li>'.&mt('Unofficial courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'unofficial'}].'</b>').'</li>'.
19593:23): '<li>'.&mt('Textbook courses: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'textbook'}].'</b>').'</li>'.
19594:23): '<li>'.&mt('Placement tests: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'placement'}].'</b>').'</li>'.
19595:23): '<li>'.&mt('Communities: [_1]','<b>'.$noyes[$defaultshash{'coursedefaults'}{'exttool'}{'community'}].'</b>').'</li>'.
19596:23): '</ul>'.
19597:23): '</li>';
19598:23): } else {
19599:23): $resulttext .= '<li>'.&mt('External Tools can not be defined in any course types, by default').'</li>';
19600:23): }
22(raebu 19601:24): } elsif ($item eq 'crseditors') {
19602:24): if (ref($defaultshash{'coursedefaults'}{$item}) eq 'ARRAY') {
19603:24): my $shown;
19604:24): if (@{$defaultshash{'coursedefaults'}{$item}}) {
19605:24): $shown = join(', ', map { $editornames{$_} } @{$defaultshash{'coursedefaults'}{$item}});
19606:24): } else {
19607:24): $shown = &mt('None');
19608:24): }
19609:24): $resulttext .= '<li>'.&mt('Available editors for course/community resources: [_1]',$shown).'</li>';
19610:24): }
1.140 raeburn 19611: }
1.121 raeburn 19612: }
19613: $resulttext .= '</ul>';
19614: } else {
19615: $resulttext = &mt('No changes made to course defaults');
19616: }
19617: } else {
19618: $resulttext = '<span class="LC_error">'.
19619: &mt('An error occurred: [_1]',$putresult).'</span>';
19620: }
19621: return $resulttext;
19622: }
19623:
1.160.6.37 raeburn 19624: sub modify_selfenrollment {
19625: my ($dom,$lastactref,%domconfig) = @_;
19626: my ($resulttext,$errors,%changes,%selfenrollhash,%ordered);
19627: my @types = ('official','unofficial','community','textbook');
19628: my %titles = &tool_titles();
19629: my %descs = &Apache::lonuserutils::selfenroll_default_descs();
19630: ($ordered{'admin'},my $titlesref) = &Apache::lonuserutils::get_selfenroll_titles();
19631: $ordered{'default'} = ['types','registered','approval','limit'];
19632:
19633: my (%roles,%shown,%toplevel);
19634: $roles{'0'} = &Apache::lonnet::plaintext('dc');
19635:
19636: if (ref($domconfig{'selfenrollment'}) ne 'HASH') {
19637: if ($domconfig{'selfenrollment'} eq '') {
19638: $domconfig{'selfenrollment'} = {};
19639: }
19640: }
19641: %toplevel = (
19642: admin => 'Configuration Rights',
19643: default => 'Default settings',
19644: validation => 'Validation of self-enrollment requests',
19645: );
19646: my ($itemsref,$namesref,$fieldsref) = &Apache::lonuserutils::selfenroll_validation_types();
19647:
19648: if (ref($ordered{'admin'}) eq 'ARRAY') {
19649: foreach my $item (@{$ordered{'admin'}}) {
19650: foreach my $type (@types) {
19651: if ($env{'form.selfenrolladmin_'.$item.'_'.$type}) {
19652: $selfenrollhash{'admin'}{$type}{$item} = 1;
19653: } else {
19654: $selfenrollhash{'admin'}{$type}{$item} = 0;
19655: }
19656: if (ref($domconfig{'selfenrollment'}{'admin'}) eq 'HASH') {
19657: if (ref($domconfig{'selfenrollment'}{'admin'}{$type}) eq 'HASH') {
19658: if ($selfenrollhash{'admin'}{$type}{$item} ne
19659: $domconfig{'selfenrollment'}{'admin'}{$type}{$item}) {
19660: push(@{$changes{'admin'}{$type}},$item);
19661: }
19662: } else {
19663: if (!$selfenrollhash{'admin'}{$type}{$item}) {
19664: push(@{$changes{'admin'}{$type}},$item);
19665: }
19666: }
19667: } elsif (!$selfenrollhash{'admin'}{$type}{$item}) {
19668: push(@{$changes{'admin'}{$type}},$item);
19669: }
19670: }
19671: }
19672: }
19673:
19674: foreach my $item (@{$ordered{'default'}}) {
19675: foreach my $type (@types) {
19676: my $value = $env{'form.selfenrolldefault_'.$item.'_'.$type};
19677: if ($item eq 'types') {
19678: unless (($value eq 'all') || ($value eq 'dom')) {
19679: $value = '';
19680: }
19681: } elsif ($item eq 'registered') {
19682: unless ($value eq '1') {
19683: $value = 0;
19684: }
19685: } elsif ($item eq 'approval') {
19686: unless ($value =~ /^[012]$/) {
19687: $value = 0;
19688: }
19689: } else {
19690: unless (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19691: $value = 'none';
19692: }
19693: }
19694: $selfenrollhash{'default'}{$type}{$item} = $value;
19695: if (ref($domconfig{'selfenrollment'}{'default'}) eq 'HASH') {
19696: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19697: if ($selfenrollhash{'default'}{$type}{$item} ne
19698: $domconfig{'selfenrollment'}{'default'}{$type}{$item}) {
19699: push(@{$changes{'default'}{$type}},$item);
19700: }
19701: } else {
19702: push(@{$changes{'default'}{$type}},$item);
19703: }
19704: } else {
19705: push(@{$changes{'default'}{$type}},$item);
19706: }
19707: if ($item eq 'limit') {
19708: if (($value eq 'allstudents') || ($value eq 'selfenrolled')) {
19709: $env{'form.selfenrolldefault_cap_'.$type} =~ s/\D//g;
19710: if ($env{'form.selfenrolldefault_cap_'.$type} ne '') {
19711: $selfenrollhash{'default'}{$type}{'cap'} = $env{'form.selfenrolldefault_cap_'.$type};
19712: }
19713: } else {
19714: $selfenrollhash{'default'}{$type}{'cap'} = '';
19715: }
19716: if (ref($domconfig{'selfenrollment'}{'default'}{$type}) eq 'HASH') {
19717: if ($selfenrollhash{'default'}{$type}{'cap'} ne
19718: $domconfig{'selfenrollment'}{'admin'}{$type}{'cap'}) {
19719: push(@{$changes{'default'}{$type}},'cap');
19720: }
19721: } elsif ($selfenrollhash{'default'}{$type}{'cap'} ne '') {
19722: push(@{$changes{'default'}{$type}},'cap');
19723: }
19724: }
19725: }
19726: }
19727:
19728: foreach my $item (@{$itemsref}) {
19729: if ($item eq 'fields') {
19730: my @changed;
19731: @{$selfenrollhash{'validation'}{$item}} = &Apache::loncommon::get_env_multiple('form.selfenroll_validation_'.$item);
19732: if (@{$selfenrollhash{'validation'}{$item}} > 0) {
19733: @{$selfenrollhash{'validation'}{$item}} = sort(@{$selfenrollhash{'validation'}{$item}});
19734: }
19735: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19736: if (ref($domconfig{'selfenrollment'}{'validation'}{$item}) eq 'ARRAY') {
19737: @changed = &Apache::loncommon::compare_arrays($selfenrollhash{'validation'}{$item},
19738: $domconfig{'selfenrollment'}{'validation'}{$item});
19739: } else {
19740: @changed = @{$selfenrollhash{'validation'}{$item}};
19741: }
19742: } else {
19743: @changed = @{$selfenrollhash{'validation'}{$item}};
19744: }
19745: if (@changed) {
19746: if ($selfenrollhash{'validation'}{$item}) {
19747: $changes{'validation'}{$item} = join(', ',@{$selfenrollhash{'validation'}{$item}});
19748: } else {
19749: $changes{'validation'}{$item} = &mt('None');
19750: }
19751: }
19752: } else {
19753: $selfenrollhash{'validation'}{$item} = $env{'form.selfenroll_validation_'.$item};
19754: if ($item eq 'markup') {
19755: if ($env{'form.selfenroll_validation_'.$item}) {
19756: $env{'form.selfenroll_validation_'.$item} =~ s/[\n\r\f]+/\s/gs;
19757: }
19758: }
19759: if (ref($domconfig{'selfenrollment'}{'validation'}) eq 'HASH') {
19760: if ($domconfig{'selfenrollment'}{'validation'}{$item} ne $selfenrollhash{'validation'}{$item}) {
19761: $changes{'validation'}{$item} = $selfenrollhash{'validation'}{$item};
19762: }
19763: }
19764: }
19765: }
19766:
19767: my $putresult = &Apache::lonnet::put_dom('configuration',{'selfenrollment' => \%selfenrollhash},
19768: $dom);
19769: if ($putresult eq 'ok') {
19770: if (keys(%changes) > 0) {
19771: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
19772: $resulttext = &mt('Changes made:').'<ul>';
19773: foreach my $key ('admin','default','validation') {
19774: if (ref($changes{$key}) eq 'HASH') {
19775: $resulttext .= '<li>'.$toplevel{$key}.'<ul>';
19776: if ($key eq 'validation') {
19777: foreach my $item (@{$itemsref}) {
19778: if (exists($changes{$key}{$item})) {
19779: if ($item eq 'markup') {
19780: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19781: '<br /><pre>'.$changes{$key}{$item}.'</pre>').'</li>';
19782: } else {
19783: $resulttext .= '<li>'.&mt('[_1] set to: [_2]',$namesref->{$item},
19784: '<b>'.$changes{$key}{$item}.'</b>').'</li>';
19785: }
19786: }
19787: }
19788: } else {
19789: foreach my $type (@types) {
19790: if ($type eq 'community') {
19791: $roles{'1'} = &mt('Community personnel');
19792: } else {
19793: $roles{'1'} = &mt('Course personnel');
19794: }
19795: if (ref($changes{$key}{$type}) eq 'ARRAY') {
19796: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19797: if ($key eq 'admin') {
19798: my @mgrdc = ();
19799: if (ref($ordered{$key}) eq 'ARRAY') {
19800: foreach my $item (@{$ordered{'admin'}}) {
19801: if (ref($selfenrollhash{$key}{$type}) eq 'HASH') {
19802: if ($selfenrollhash{$key}{$type}{$item} eq '0') {
19803: push(@mgrdc,$item);
19804: }
19805: }
19806: }
19807: if (@mgrdc) {
19808: $domdefaults{$type.'selfenrolladmdc'} = join(',',@mgrdc);
19809: } else {
19810: delete($domdefaults{$type.'selfenrolladmdc'});
19811: }
19812: }
19813: } else {
19814: if (ref($ordered{$key}) eq 'ARRAY') {
19815: foreach my $item (@{$ordered{$key}}) {
19816: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19817: $domdefaults{$type.'selfenroll'.$item} =
19818: $selfenrollhash{$key}{$type}{$item};
19819: }
19820: }
19821: }
19822: }
19823: }
19824: $resulttext .= '<li>'.$titles{$type}.'<ul>';
19825: foreach my $item (@{$ordered{$key}}) {
19826: if (grep(/^\Q$item\E$/,@{$changes{$key}{$type}})) {
19827: $resulttext .= '<li>';
19828: if ($key eq 'admin') {
19829: $resulttext .= &mt('[_1] -- management by: [_2]',$titlesref->{$item},
19830: '<b>'.$roles{$selfenrollhash{'admin'}{$type}{$item}}.'</b>');
19831: } else {
19832: $resulttext .= &mt('[_1] set to: [_2]',$titlesref->{$item},
19833: '<b>'.$descs{$item}{$selfenrollhash{'default'}{$type}{$item}}.'</b>');
19834: }
19835: $resulttext .= '</li>';
19836: }
19837: }
19838: $resulttext .= '</ul></li>';
19839: }
19840: }
19841: $resulttext .= '</ul></li>';
19842: }
19843: }
1.160.6.93 raeburn 19844: }
19845: if ((exists($changes{'admin'})) || (exists($changes{'default'}))) {
19846: my $cachetime = 24*60*60;
19847: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
19848: if (ref($lastactref) eq 'HASH') {
19849: $lastactref->{'domdefaults'} = 1;
1.160.6.37 raeburn 19850: }
19851: }
19852: $resulttext .= '</ul>';
19853: } else {
19854: $resulttext = &mt('No changes made to self-enrollment settings');
19855: }
19856: } else {
19857: $resulttext = '<span class="LC_error">'.
19858: &mt('An error occurred: [_1]',$putresult).'</span>';
19859: }
19860: return $resulttext;
19861: }
19862:
1.160.6.113 raeburn 19863: sub modify_wafproxy {
19864: my ($dom,$action,$lastactref,%domconfig) = @_;
19865: my %servers = &Apache::lonnet::internet_dom_servers($dom);
19866: my (%othercontrol,%canset,%values,%curralias,%currsaml,%currvalue,@warnings,
19867: %wafproxy,%changes,%expirecache,%expiresaml);
19868: foreach my $server (sort(keys(%servers))) {
19869: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
19870: if ($serverhome eq $server) {
19871: my $serverdom = &Apache::lonnet::host_domain($server);
19872: if ($serverdom eq $dom) {
19873: $canset{$server} = 1;
19874: }
19875: }
19876: }
19877: if (ref($domconfig{'wafproxy'}) eq 'HASH') {
19878: %{$values{$dom}} = ();
19879: if (ref($domconfig{'wafproxy'}{'alias'}) eq 'HASH') {
19880: %curralias = %{$domconfig{'wafproxy'}{'alias'}};
19881: }
19882: if (ref($domconfig{'wafproxy'}{'saml'}) eq 'HASH') {
19883: %currsaml = %{$domconfig{'wafproxy'}{'saml'}};
19884: }
19885: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19886: $currvalue{$item} = $domconfig{'wafproxy'}{$item};
19887: }
19888: }
19889: my $output;
19890: if (keys(%canset)) {
19891: %{$wafproxy{'alias'}} = ();
19892: %{$wafproxy{'saml'}} = ();
19893: foreach my $key (sort(keys(%canset))) {
19894: if ($env{'form.wafproxy_'.$dom}) {
19895: $wafproxy{'alias'}{$key} = $env{'form.wafproxy_alias_'.$key};
19896: $wafproxy{'alias'}{$key} =~ s/^\s+|\s+$//g;
19897: if ($wafproxy{'alias'}{$key} ne $curralias{$key}) {
19898: $changes{'alias'} = 1;
19899: }
19900: if ($env{'form.wafproxy_alias_saml_'.$key}) {
19901: $wafproxy{'saml'}{$key} = 1;
19902: }
19903: if ($wafproxy{'saml'}{$key} ne $currsaml{$key}) {
19904: $changes{'saml'} = 1;
19905: }
19906: } else {
19907: $wafproxy{'alias'}{$key} = '';
19908: $wafproxy{'saml'}{$key} = '';
19909: if ($curralias{$key}) {
19910: $changes{'alias'} = 1;
19911: }
19912: if ($currsaml{$key}) {
19913: $changes{'saml'} = 1;
19914: }
19915: }
19916: if ($wafproxy{'alias'}{$key} eq '') {
19917: if ($curralias{$key}) {
19918: $expirecache{$key} = 1;
19919: }
19920: delete($wafproxy{'alias'}{$key});
19921: }
19922: if ($wafproxy{'saml'}{$key} eq '') {
19923: if ($currsaml{$key}) {
19924: $expiresaml{$key} = 1;
19925: }
19926: delete($wafproxy{'saml'}{$key});
19927: }
19928: }
19929: unless (keys(%{$wafproxy{'alias'}})) {
19930: delete($wafproxy{'alias'});
19931: }
19932: unless (keys(%{$wafproxy{'saml'}})) {
19933: delete($wafproxy{'saml'});
19934: }
19935: # Localization for values in %warn occurs in &mt() calls separately.
19936: my %warn = (
19937: trusted => 'trusted IP range(s)',
19938: vpnint => 'internal IP range(s) for VPN sessions(s)',
19939: vpnext => 'IP range(s) for backend WAF connections',
19940: );
19941: foreach my $item ('remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
19942: my $possible = $env{'form.wafproxy_'.$item};
19943: $possible =~ s/^\s+|\s+$//g;
19944: if ($possible ne '') {
19945: if ($item eq 'remoteip') {
19946: if ($possible =~ /^[mhn]$/) {
19947: $wafproxy{$item} = $possible;
19948: }
19949: } elsif ($item eq 'ipheader') {
19950: if ($wafproxy{'remoteip'} eq 'h') {
19951: $wafproxy{$item} = $possible;
19952: }
19953: } elsif ($item eq 'sslopt') {
19954: if ($possible =~ /^0|1$/) {
19955: $wafproxy{$item} = $possible;
19956: }
19957: } else {
19958: my (@ok,$count);
19959: if (($item eq 'vpnint') || ($item eq 'vpnext')) {
19960: unless ($env{'form.wafproxy_vpnaccess'}) {
19961: $possible = '';
19962: }
19963: } elsif ($item eq 'trusted') {
19964: unless ($wafproxy{'remoteip'} eq 'h') {
19965: $possible = '';
19966: }
19967: }
19968: unless ($possible eq '') {
19969: $possible =~ s/[\r\n]+/\s/g;
19970: $possible =~ s/\s*-\s*/-/g;
19971: $possible =~ s/\s+/,/g;
19972: $possible =~ s/,+/,/g;
19973: }
19974: $count = 0;
19975: if ($possible ne '') {
19976: foreach my $poss (split(/\,/,$possible)) {
19977: $count ++;
19978: $poss = &validate_ip_pattern($poss);
19979: if ($poss ne '') {
19980: push(@ok,$poss);
19981: }
19982: }
19983: my $diff = $count - scalar(@ok);
19984: if ($diff) {
19985: push(@warnings,'<li>'.
19986: &mt('[quant,_1,IP] invalid and excluded from saved value for [_2]',
19987: $diff,$warn{$item}).
19988: '</li>');
19989: }
19990: if (@ok) {
19991: my @cidr_list;
19992: foreach my $item (@ok) {
19993: @cidr_list = &Net::CIDR::cidradd($item,@cidr_list);
19994: }
19995: $wafproxy{$item} = join(',',@cidr_list);
19996: }
19997: }
19998: }
19999: if ($wafproxy{$item} ne $currvalue{$item}) {
20000: $changes{$item} = 1;
20001: }
20002: } elsif ($currvalue{$item}) {
20003: $changes{$item} = 1;
20004: }
20005: }
20006: } else {
20007: if (keys(%curralias)) {
20008: $changes{'alias'} = 1;
20009: }
20010: if (keys(%currsaml)) {
20011: $changes{'saml'} = 1;
20012: }
20013: if (keys(%currvalue)) {
20014: foreach my $key (keys(%currvalue)) {
20015: $changes{$key} = 1;
20016: }
20017: }
20018: }
20019: if (keys(%changes)) {
20020: my %defaultshash = (
20021: wafproxy => \%wafproxy,
20022: );
20023: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20024: $dom);
20025: if ($putresult eq 'ok') {
20026: my $cachetime = 24*60*60;
20027: my (%domdefaults,$updatedomdefs);
20028: foreach my $item ('ipheader','trusted','vpnint','vpnext','sslopt') {
20029: if ($changes{$item}) {
20030: unless ($updatedomdefs) {
20031: %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
20032: $updatedomdefs = 1;
20033: }
20034: if ($wafproxy{$item}) {
20035: $domdefaults{'waf_'.$item} = $wafproxy{$item};
20036: } elsif (exists($domdefaults{'waf_'.$item})) {
20037: delete($domdefaults{'waf_'.$item});
20038: }
20039: }
20040: }
20041: if ($updatedomdefs) {
20042: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
20043: if (ref($lastactref) eq 'HASH') {
20044: $lastactref->{'domdefaults'} = 1;
20045: }
20046: }
20047: if ((exists($wafproxy{'alias'})) || (keys(%expirecache))) {
20048: my %updates = %expirecache;
20049: foreach my $key (keys(%expirecache)) {
20050: &Apache::lonnet::devalidate_cache_new('proxyalias',$key);
20051: }
20052: if (ref($wafproxy{'alias'}) eq 'HASH') {
20053: my $cachetime = 24*60*60;
20054: foreach my $key (keys(%{$wafproxy{'alias'}})) {
20055: $updates{$key} = 1;
20056: &Apache::lonnet::do_cache_new('proxyalias',$key,$wafproxy{'alias'}{$key},
20057: $cachetime);
20058: }
20059: }
20060: if (ref($lastactref) eq 'HASH') {
20061: $lastactref->{'proxyalias'} = \%updates;
20062: }
20063: }
20064: if ((exists($wafproxy{'saml'})) || (keys(%expiresaml))) {
20065: my %samlupdates = %expiresaml;
20066: foreach my $key (keys(%expiresaml)) {
20067: &Apache::lonnet::devalidate_cache_new('proxysaml',$key);
20068: }
20069: if (ref($wafproxy{'saml'}) eq 'HASH') {
20070: my $cachetime = 24*60*60;
20071: foreach my $key (keys(%{$wafproxy{'saml'}})) {
20072: $samlupdates{$key} = 1;
20073: &Apache::lonnet::do_cache_new('proxysaml',$key,$wafproxy{'saml'}{$key},
20074: $cachetime);
20075: }
20076: }
20077: if (ref($lastactref) eq 'HASH') {
20078: $lastactref->{'proxysaml'} = \%samlupdates;
20079: }
20080: }
20081: $output = &mt('Changes were made to Web Application Firewall/Reverse Proxy').'<ul>';
1.160.6.118 raeburn 20082: foreach my $item ('alias','saml','remoteip','ipheader','trusted','vpnint','vpnext','sslopt') {
1.160.6.113 raeburn 20083: if ($changes{$item}) {
20084: if ($item eq 'alias') {
20085: my $numaliased = 0;
20086: if (ref($wafproxy{'alias'}) eq 'HASH') {
20087: my $shown;
20088: if (keys(%{$wafproxy{'alias'}})) {
20089: foreach my $server (sort(keys(%{$wafproxy{'alias'}}))) {
20090: $shown .= '<li>'.&mt('[_1] aliased by [_2]',
20091: &Apache::lonnet::hostname($server),
20092: $wafproxy{'alias'}{$server}).'</li>';
20093: $numaliased ++;
20094: }
20095: if ($numaliased) {
20096: $output .= '<li>'.&mt('Aliases for hostnames set to: [_1]',
20097: '<ul>'.$shown.'</ul>').'</li>';
20098: }
20099: }
20100: }
20101: unless ($numaliased) {
20102: $output .= '<li>'.&mt('Aliases deleted for hostnames').'</li>';
20103: }
20104: } elsif ($item eq 'saml') {
20105: my $shown;
20106: if (ref($wafproxy{'saml'}) eq 'HASH') {
20107: if (keys(%{$wafproxy{'saml'}})) {
20108: $shown = join(', ',sort(keys(%{$wafproxy{'saml'}})));
20109: }
20110: }
20111: if ($shown) {
20112: $output .= '<li>'.&mt('Alias used by SSO Auth for: [_1]',
20113: $shown).'</li>';
20114: } else {
20115: $output .= '<li>'.&mt('No alias used for SSO Auth').'</li>';
20116: }
20117: } else {
20118: if ($item eq 'remoteip') {
20119: my %ip_methods = &remoteip_methods();
20120: if ($wafproxy{$item} =~ /^[mh]$/) {
20121: $output .= '<li>'.&mt("Method for determining user's IP set to: [_1]",
20122: $ip_methods{$wafproxy{$item}}).'</li>';
20123: } else {
20124: if (($env{'form.wafproxy_'.$dom}) && (ref($wafproxy{'alias'}) eq 'HASH')) {
20125: $output .= '<li>'.&mt("No method in use to get user's real IP (will report IP used by WAF).").
20126: '</li>';
20127: } else {
20128: $output .= '<li>'.&mt('WAF/Reverse Proxy not in use').'</li>';
20129: }
20130: }
20131: } elsif ($item eq 'ipheader') {
20132: if ($wafproxy{$item}) {
20133: $output .= '<li>'.&mt('Request header with remote IP set to: [_1]',
20134: $wafproxy{$item}).'</li>';
20135: } else {
20136: $output .= '<li>'.&mt('Request header with remote IP deleted').'</li>';
20137: }
20138: } elsif ($item eq 'trusted') {
20139: if ($wafproxy{$item}) {
20140: $output .= '<li>'.&mt('Trusted IP range(s) set to: [_1]',
20141: $wafproxy{$item}).'</li>';
20142: } else {
20143: $output .= '<li>'.&mt('Trusted IP range(s) deleted').'</li>';
20144: }
20145: } elsif ($item eq 'vpnint') {
20146: if ($wafproxy{$item}) {
20147: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions set to: [_1]',
20148: $wafproxy{$item}).'</li>';
20149: } else {
20150: $output .= '<li>'.&mt('Internal IP Range(s) for VPN sessions deleted').'</li>';
20151: }
20152: } elsif ($item eq 'vpnext') {
20153: if ($wafproxy{$item}) {
20154: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections set to: [_1]',
20155: $wafproxy{$item}).'</li>';
20156: } else {
20157: $output .= '<li>'.&mt('IP Range(s) for backend WAF connections deleted').'</li>';
20158: }
20159: } elsif ($item eq 'sslopt') {
20160: if ($wafproxy{$item}) {
20161: $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>';
20162: } else {
20163: $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>';
20164: }
20165: }
20166: }
20167: }
20168: }
1.160.6.118.2 14(raebu 20169:23): $output .= '</ul>';
1.160.6.113 raeburn 20170: } else {
20171: $output = '<span class="LC_error">'.
20172: &mt('An error occurred: [_1]',$putresult).'</span>';
20173: }
20174: } elsif (keys(%canset)) {
20175: $output = &mt('No changes made to Web Application Firewall/Reverse Proxy settings');
20176: }
20177: if (@warnings) {
20178: $output .= '<br />'.&mt('Warnings:').'<ul>'.
20179: join("\n",@warnings).'</ul>';
20180: }
20181: return $output;
20182: }
20183:
20184: sub validate_ip_pattern {
20185: my ($pattern) = @_;
20186: if ($pattern =~ /^([^-]+)\-([^-]+)$/) {
20187: my ($start,$end) = ($1,$2);
20188: if ((&Net::CIDR::cidrvalidate($start)) && (&Net::CIDR::cidrvalidate($end))) {
20189: if (($start !~ m{/}) && ($end !~ m{/})) {
20190: return $start.'-'.$end;
20191: }
20192: }
20193: } elsif ($pattern ne '') {
20194: $pattern = &Net::CIDR::cidrvalidate($pattern);
20195: if ($pattern ne '') {
20196: return $pattern;
20197: }
20198: }
20199: return;
20200: }
20201:
1.137 raeburn 20202: sub modify_usersessions {
1.160.6.27 raeburn 20203: my ($dom,$lastactref,%domconfig) = @_;
1.145 raeburn 20204: my @hostingtypes = ('version','excludedomain','includedomain');
20205: my @offloadtypes = ('primary','default');
20206: my %types = (
20207: remote => \@hostingtypes,
20208: hosted => \@hostingtypes,
20209: spares => \@offloadtypes,
20210: );
20211: my @prefixes = ('remote','hosted','spares');
1.137 raeburn 20212: my @lcversions = &Apache::lonnet::all_loncaparevs();
1.138 raeburn 20213: my (%by_ip,%by_location,@intdoms);
20214: &build_location_hashes(\@intdoms,\%by_ip,\%by_location);
20215: my @locations = sort(keys(%by_location));
1.137 raeburn 20216: my (%defaultshash,%changes);
20217: foreach my $prefix (@prefixes) {
20218: $defaultshash{'usersessions'}{$prefix} = {};
20219: }
1.160.6.27 raeburn 20220: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom,1);
1.137 raeburn 20221: my $resulttext;
1.138 raeburn 20222: my %iphost = &Apache::lonnet::get_iphost();
1.137 raeburn 20223: foreach my $prefix (@prefixes) {
1.145 raeburn 20224: next if ($prefix eq 'spares');
20225: foreach my $type (@{$types{$prefix}}) {
1.137 raeburn 20226: my $inuse = $env{'form.'.$prefix.'_'.$type.'_inuse'};
20227: if ($type eq 'version') {
20228: my $value = $env{'form.'.$prefix.'_'.$type};
20229: my $okvalue;
20230: if ($value ne '') {
20231: if (grep(/^\Q$value\E$/,@lcversions)) {
20232: $okvalue = $value;
20233: }
20234: }
20235: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20236: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20237: if ($domconfig{'usersessions'}{$prefix}{$type} ne '') {
20238: if ($inuse == 0) {
20239: $changes{$prefix}{$type} = 1;
20240: } else {
20241: if ($okvalue ne $domconfig{'usersessions'}{$prefix}{$type}) {
20242: $changes{$prefix}{$type} = 1;
20243: }
20244: if ($okvalue ne '') {
20245: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20246: }
20247: }
20248: } else {
20249: if (($inuse == 1) && ($okvalue ne '')) {
20250: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20251: $changes{$prefix}{$type} = 1;
20252: }
20253: }
20254: } else {
20255: if (($inuse == 1) && ($okvalue ne '')) {
20256: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20257: $changes{$prefix}{$type} = 1;
20258: }
20259: }
20260: } else {
20261: if (($inuse == 1) && ($okvalue ne '')) {
20262: $defaultshash{'usersessions'}{$prefix}{$type} = $okvalue;
20263: $changes{$prefix}{$type} = 1;
20264: }
20265: }
20266: } else {
20267: my @vals = &Apache::loncommon::get_env_multiple('form.'.$prefix.'_'.$type);
20268: my @okvals;
20269: foreach my $val (@vals) {
1.138 raeburn 20270: if ($val =~ /:/) {
20271: my @items = split(/:/,$val);
20272: foreach my $item (@items) {
20273: if (ref($by_location{$item}) eq 'ARRAY') {
20274: push(@okvals,$item);
20275: }
20276: }
20277: } else {
20278: if (ref($by_location{$val}) eq 'ARRAY') {
20279: push(@okvals,$val);
20280: }
1.137 raeburn 20281: }
20282: }
20283: @okvals = sort(@okvals);
20284: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20285: if (ref($domconfig{'usersessions'}{$prefix}) eq 'HASH') {
20286: if (ref($domconfig{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20287: if ($inuse == 0) {
20288: $changes{$prefix}{$type} = 1;
20289: } else {
20290: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20291: my @changed = &Apache::loncommon::compare_arrays($domconfig{'usersessions'}{$prefix}{$type},$defaultshash{'usersessions'}{$prefix}{$type});
20292: if (@changed > 0) {
20293: $changes{$prefix}{$type} = 1;
20294: }
20295: }
20296: } else {
20297: if ($inuse == 1) {
20298: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20299: $changes{$prefix}{$type} = 1;
20300: }
20301: }
20302: } else {
20303: if ($inuse == 1) {
20304: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20305: $changes{$prefix}{$type} = 1;
20306: }
20307: }
20308: } else {
20309: if ($inuse == 1) {
20310: $defaultshash{'usersessions'}{$prefix}{$type} = \@okvals;
20311: $changes{$prefix}{$type} = 1;
20312: }
20313: }
20314: }
20315: }
20316: }
1.145 raeburn 20317:
20318: my @alldoms = &Apache::lonnet::all_domains();
1.149 raeburn 20319: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.145 raeburn 20320: my %spareid = ¤t_offloads_to($dom,$domconfig{'usersessions'},\%servers);
20321: my $savespares;
20322:
20323: foreach my $lonhost (sort(keys(%servers))) {
20324: my $serverhomeID =
20325: &Apache::lonnet::get_server_homeID($servers{$lonhost});
1.152 raeburn 20326: my $serverhostname = &Apache::lonnet::hostname($lonhost);
1.145 raeburn 20327: $defaultshash{'usersessions'}{'spares'}{$lonhost} = {};
20328: my %spareschg;
20329: foreach my $type (@{$types{'spares'}}) {
20330: my @okspares;
20331: my @checked = &Apache::loncommon::get_env_multiple('form.spare_'.$type.'_'.$lonhost);
20332: foreach my $server (@checked) {
1.152 raeburn 20333: if (&Apache::lonnet::hostname($server) ne '') {
20334: unless (&Apache::lonnet::hostname($server) eq $serverhostname) {
20335: unless (grep(/^\Q$server\E$/,@okspares)) {
20336: push(@okspares,$server);
20337: }
1.145 raeburn 20338: }
20339: }
20340: }
20341: my $new = $env{'form.newspare_'.$type.'_'.$lonhost};
20342: my $newspare;
1.152 raeburn 20343: if (($new ne '') && (&Apache::lonnet::hostname($new))) {
20344: unless (&Apache::lonnet::hostname($new) eq $serverhostname) {
1.145 raeburn 20345: $newspare = $new;
20346: }
20347: }
1.152 raeburn 20348: my @spares;
20349: if (($newspare ne '') && (!grep(/^\Q$newspare\E$/,@okspares))) {
20350: @spares = sort(@okspares,$newspare);
20351: } else {
20352: @spares = sort(@okspares);
20353: }
20354: $defaultshash{'usersessions'}{'spares'}{$lonhost}{$type} = \@spares;
1.145 raeburn 20355: if (ref($spareid{$lonhost}) eq 'HASH') {
20356: if (ref($spareid{$lonhost}{$type}) eq 'ARRAY') {
1.152 raeburn 20357: my @diffs = &Apache::loncommon::compare_arrays($spareid{$lonhost}{$type},\@spares);
1.145 raeburn 20358: if (@diffs > 0) {
20359: $spareschg{$type} = 1;
20360: }
20361: }
20362: }
20363: }
20364: if (keys(%spareschg) > 0) {
20365: $changes{'spares'}{$lonhost} = \%spareschg;
20366: }
20367: }
1.160.6.61 raeburn 20368: $defaultshash{'usersessions'}{'offloadnow'} = {};
1.160.6.105 raeburn 20369: $defaultshash{'usersessions'}{'offloadoth'} = {};
1.160.6.61 raeburn 20370: my @offloadnow = &Apache::loncommon::get_env_multiple('form.offloadnow');
20371: my @okoffload;
20372: if (@offloadnow) {
20373: foreach my $server (@offloadnow) {
20374: if (&Apache::lonnet::hostname($server) ne '') {
20375: unless (grep(/^\Q$server\E$/,@okoffload)) {
20376: push(@okoffload,$server);
20377: }
20378: }
20379: }
20380: if (@okoffload) {
20381: foreach my $lonhost (@okoffload) {
20382: $defaultshash{'usersessions'}{'offloadnow'}{$lonhost} = 1;
20383: }
20384: }
20385: }
1.160.6.105 raeburn 20386: my @offloadoth = &Apache::loncommon::get_env_multiple('form.offloadoth');
20387: my @okoffloadoth;
20388: if (@offloadoth) {
20389: foreach my $server (@offloadoth) {
20390: if (&Apache::lonnet::hostname($server) ne '') {
20391: unless (grep(/^\Q$server\E$/,@okoffloadoth)) {
20392: push(@okoffloadoth,$server);
20393: }
20394: }
20395: }
20396: if (@okoffloadoth) {
20397: foreach my $lonhost (@okoffloadoth) {
20398: $defaultshash{'usersessions'}{'offloadoth'}{$lonhost} = 1;
20399: }
20400: }
20401: }
1.145 raeburn 20402: if (ref($domconfig{'usersessions'}) eq 'HASH') {
20403: if (ref($domconfig{'usersessions'}{'spares'}) eq 'HASH') {
20404: if (ref($changes{'spares'}) eq 'HASH') {
20405: if (keys(%{$changes{'spares'}}) > 0) {
20406: $savespares = 1;
20407: }
20408: }
20409: } else {
20410: $savespares = 1;
20411: }
1.160.6.105 raeburn 20412: foreach my $offload ('offloadnow','offloadoth') {
20413: if (ref($domconfig{'usersessions'}{$offload}) eq 'HASH') {
20414: foreach my $lonhost (keys(%{$domconfig{'usersessions'}{$offload}})) {
20415: unless ($defaultshash{'usersessions'}{$offload}{$lonhost}) {
20416: $changes{$offload} = 1;
1.160.6.61 raeburn 20417: last;
20418: }
20419: }
1.160.6.105 raeburn 20420: unless ($changes{$offload}) {
20421: foreach my $lonhost (keys(%{$defaultshash{'usersessions'}{$offload}})) {
20422: unless ($domconfig{'usersessions'}{$offload}{$lonhost}) {
20423: $changes{$offload} = 1;
20424: last;
20425: }
20426: }
20427: }
20428: } else {
20429: if (($offload eq 'offloadnow') && (@okoffload)) {
20430: $changes{'offloadnow'} = 1;
20431: }
20432: if (($offload eq 'offloadoth') && (@okoffloadoth)) {
20433: $changes{'offloadoth'} = 1;
20434: }
1.160.6.61 raeburn 20435: }
1.160.6.105 raeburn 20436: }
20437: } else {
20438: if (@okoffload) {
1.160.6.61 raeburn 20439: $changes{'offloadnow'} = 1;
20440: }
1.160.6.105 raeburn 20441: if (@okoffloadoth) {
20442: $changes{'offloadoth'} = 1;
20443: }
1.145 raeburn 20444: }
1.147 raeburn 20445: my $nochgmsg = &mt('No changes made to settings for user session hosting/offloading.');
20446: if ((keys(%changes) > 0) || ($savespares)) {
1.137 raeburn 20447: my $putresult = &Apache::lonnet::put_dom('configuration',\%defaultshash,
20448: $dom);
20449: if ($putresult eq 'ok') {
20450: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20451: if (ref($defaultshash{'usersessions'}{'remote'}) eq 'HASH') {
20452: $domdefaults{'remotesessions'} = $defaultshash{'usersessions'}{'remote'};
20453: }
20454: if (ref($defaultshash{'usersessions'}{'hosted'}) eq 'HASH') {
20455: $domdefaults{'hostedsessions'} = $defaultshash{'usersessions'}{'hosted'};
20456: }
1.160.6.61 raeburn 20457: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20458: $domdefaults{'offloadnow'} = $defaultshash{'usersessions'}{'offloadnow'};
20459: }
1.160.6.105 raeburn 20460: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20461: $domdefaults{'offloadoth'} = $defaultshash{'usersessions'}{'offloadoth'};
20462: }
1.137 raeburn 20463: }
20464: my $cachetime = 24*60*60;
20465: &Apache::lonnet::do_cache_new('domdefaults',$dom,\%domdefaults,$cachetime);
1.160.6.81 raeburn 20466: &Apache::lonnet::do_cache_new('usersessions',$dom,$defaultshash{'usersessions'},3600);
1.160.6.27 raeburn 20467: if (ref($lastactref) eq 'HASH') {
20468: $lastactref->{'domdefaults'} = 1;
1.160.6.81 raeburn 20469: $lastactref->{'usersessions'} = 1;
1.160.6.27 raeburn 20470: }
1.147 raeburn 20471: if (keys(%changes) > 0) {
20472: my %lt = &usersession_titles();
20473: $resulttext = &mt('Changes made:').'<ul>';
20474: foreach my $prefix (@prefixes) {
20475: if (ref($changes{$prefix}) eq 'HASH') {
20476: $resulttext .= '<li>'.$lt{$prefix}.'<ul>';
20477: if ($prefix eq 'spares') {
20478: if (ref($changes{$prefix}) eq 'HASH') {
20479: foreach my $lonhost (sort(keys(%{$changes{$prefix}}))) {
20480: $resulttext .= '<li><b>'.$lonhost.'</b> ';
1.148 raeburn 20481: my $lonhostdom = &Apache::lonnet::host_domain($lonhost);
1.160.6.27 raeburn 20482: my $cachekey = &escape('spares').':'.&escape($lonhostdom);
20483: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.147 raeburn 20484: if (ref($changes{$prefix}{$lonhost}) eq 'HASH') {
20485: foreach my $type (@{$types{$prefix}}) {
20486: if ($changes{$prefix}{$lonhost}{$type}) {
20487: my $offloadto = &mt('None');
20488: if (ref($defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}) eq 'ARRAY') {
20489: if (@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}} > 0) {
20490: $offloadto = join(', ',@{$defaultshash{'usersessions'}{'spares'}{$lonhost}{$type}});
20491: }
1.145 raeburn 20492: }
1.147 raeburn 20493: $resulttext .= &mt('[_1] set to: [_2].','<i>'.$lt{$type}.'</i>',$offloadto).(' 'x3);
1.145 raeburn 20494: }
1.137 raeburn 20495: }
20496: }
1.147 raeburn 20497: $resulttext .= '</li>';
1.137 raeburn 20498: }
20499: }
1.147 raeburn 20500: } else {
20501: foreach my $type (@{$types{$prefix}}) {
20502: if (defined($changes{$prefix}{$type})) {
20503: my $newvalue;
20504: if (ref($defaultshash{'usersessions'}) eq 'HASH') {
20505: if (ref($defaultshash{'usersessions'}{$prefix})) {
20506: if ($type eq 'version') {
20507: $newvalue = $defaultshash{'usersessions'}{$prefix}{$type};
20508: } elsif (ref($defaultshash{'usersessions'}{$prefix}{$type}) eq 'ARRAY') {
20509: if (@{$defaultshash{'usersessions'}{$prefix}{$type}} > 0) {
20510: $newvalue = join(', ',@{$defaultshash{'usersessions'}{$prefix}{$type}});
20511: }
1.145 raeburn 20512: }
20513: }
20514: }
1.147 raeburn 20515: if ($newvalue eq '') {
20516: if ($type eq 'version') {
20517: $resulttext .= '<li>'.&mt('[_1] set to: off',$lt{$type}).'</li>';
20518: } else {
20519: $resulttext .= '<li>'.&mt('[_1] set to: none',$lt{$type}).'</li>';
20520: }
1.145 raeburn 20521: } else {
1.147 raeburn 20522: if ($type eq 'version') {
1.160.6.118.2 14(raebu 20523:23): $newvalue .= ' '.&mt('(or later)');
1.147 raeburn 20524: }
20525: $resulttext .= '<li>'.&mt('[_1] set to: [_2].',$lt{$type},$newvalue).'</li>';
1.145 raeburn 20526: }
1.137 raeburn 20527: }
20528: }
20529: }
1.147 raeburn 20530: $resulttext .= '</ul>';
1.137 raeburn 20531: }
20532: }
1.160.6.61 raeburn 20533: if ($changes{'offloadnow'}) {
20534: if (ref($defaultshash{'usersessions'}{'offloadnow'}) eq 'HASH') {
20535: if (keys(%{$defaultshash{'usersessions'}{'offloadnow'}}) > 0) {
1.160.6.105 raeburn 20536: $resulttext .= '<li>'.&mt('Switch any active user on next access, for server(s):').'<ul>';
1.160.6.61 raeburn 20537: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadnow'}}))) {
20538: $resulttext .= '<li>'.$lonhost.'</li>';
20539: }
20540: $resulttext .= '</ul>';
20541: } else {
1.160.6.105 raeburn 20542: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.');
20543: }
20544: } else {
20545: $resulttext .= '<li>'.&mt('No servers now set to switch any active user on next access.').'</li>';
20546: }
20547: }
20548: if ($changes{'offloadoth'}) {
20549: if (ref($defaultshash{'usersessions'}{'offloadoth'}) eq 'HASH') {
20550: if (keys(%{$defaultshash{'usersessions'}{'offloadoth'}}) > 0) {
20551: $resulttext .= '<li>'.&mt('Switch other institutions on next access, for server(s):').'<ul>';
20552: foreach my $lonhost (sort(keys(%{$defaultshash{'usersessions'}{'offloadoth'}}))) {
20553: $resulttext .= '<li>'.$lonhost.'</li>';
20554: }
20555: $resulttext .= '</ul>';
20556: } else {
20557: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.');
1.160.6.61 raeburn 20558: }
20559: } else {
1.160.6.105 raeburn 20560: $resulttext .= '<li>'.&mt('No servers now set to switch other institutions on next access.').'</li>';
1.160.6.61 raeburn 20561: }
20562: }
1.147 raeburn 20563: $resulttext .= '</ul>';
20564: } else {
20565: $resulttext = $nochgmsg;
1.137 raeburn 20566: }
20567: } else {
20568: $resulttext = '<span class="LC_error">'.
20569: &mt('An error occurred: [_1]',$putresult).'</span>';
20570: }
20571: } else {
1.147 raeburn 20572: $resulttext = $nochgmsg;
1.137 raeburn 20573: }
20574: return $resulttext;
20575: }
20576:
1.150 raeburn 20577: sub modify_loadbalancing {
20578: my ($dom,%domconfig) = @_;
20579: my $primary_id = &Apache::lonnet::domain($dom,'primary');
20580: my $intdom = &Apache::lonnet::internet_dom($primary_id);
20581: my ($othertitle,$usertypes,$types) =
20582: &Apache::loncommon::sorted_inst_types($dom);
20583: my %servers = &Apache::lonnet::internet_dom_servers($dom);
1.160.6.55 raeburn 20584: my %libraryservers = &Apache::lonnet::get_servers($dom,'library');
1.150 raeburn 20585: my @sparestypes = ('primary','default');
20586: my %typetitles = &sparestype_titles();
20587: my $resulttext;
1.160.6.94 raeburn 20588: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 20589: if (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20590: %existing = %{$domconfig{'loadbalancing'}};
20591: }
20592: &get_loadbalancers_config(\%servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 20593: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 20594: my ($saveloadbalancing,%defaultshash,%changes);
20595: my ($alltypes,$othertypes,$titles) =
20596: &loadbalancing_titles($dom,$intdom,$usertypes,$types);
20597: my %ruletitles = &offloadtype_text();
20598: my @deletions = &Apache::loncommon::get_env_multiple('form.loadbalancing_delete');
20599: for (my $i=0; $i<$env{'form.loadbalancing_total'}; $i++) {
20600: my $balancer = $env{'form.loadbalancing_lonhost_'.$i};
20601: if ($balancer eq '') {
20602: next;
20603: }
20604: if (!exists($servers{$balancer})) {
20605: if (exists($currbalancer{$balancer})) {
20606: push(@{$changes{'delete'}},$balancer);
1.150 raeburn 20607: }
1.160.6.7 raeburn 20608: next;
20609: }
20610: if ((@deletions > 0) && (grep(/^\Q$i\E$/,@deletions))) {
20611: push(@{$changes{'delete'}},$balancer);
20612: next;
20613: }
20614: if (!exists($currbalancer{$balancer})) {
20615: push(@{$changes{'add'}},$balancer);
20616: }
20617: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'} = [];
20618: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{'default'} = [];
20619: $defaultshash{'loadbalancing'}{$balancer}{'rules'} = {};
20620: unless (ref($domconfig{'loadbalancing'}) eq 'HASH') {
20621: $saveloadbalancing = 1;
20622: }
20623: foreach my $sparetype (@sparestypes) {
20624: my @targets = &Apache::loncommon::get_env_multiple('form.loadbalancing_target_'.$i.'_'.$sparetype);
20625: my @offloadto;
20626: foreach my $target (@targets) {
20627: if (($servers{$target}) && ($target ne $balancer)) {
20628: if ($sparetype eq 'default') {
20629: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}) eq 'ARRAY') {
20630: next if (grep(/^\Q$target\E$/,@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{'primary'}}));
1.150 raeburn 20631: }
20632: }
1.160.6.7 raeburn 20633: unless(grep(/^\Q$target\E$/,@offloadto)) {
20634: push(@offloadto,$target);
20635: }
1.150 raeburn 20636: }
20637: }
1.160.6.76 raeburn 20638: if ($env{'form.loadbalancing_target_'.$i.'_hosthere'} eq $sparetype) {
20639: unless(grep(/^\Q$balancer\E$/,@offloadto)) {
20640: push(@offloadto,$balancer);
20641: }
20642: }
20643: $defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype} = \@offloadto;
1.150 raeburn 20644: }
1.160.6.94 raeburn 20645: if ($env{'form.loadbalancing_cookie_'.$i}) {
20646: $defaultshash{'loadbalancing'}{$balancer}{'cookie'} = 1;
20647: if (exists($currbalancer{$balancer})) {
20648: unless ($currcookies{$balancer}) {
20649: $changes{'curr'}{$balancer}{'cookie'} = 1;
20650: }
20651: }
20652: } elsif (exists($currbalancer{$balancer})) {
20653: if ($currcookies{$balancer}) {
20654: $changes{'curr'}{$balancer}{'cookie'} = 1;
20655: }
20656: }
1.160.6.7 raeburn 20657: if (ref($currtargets{$balancer}) eq 'HASH') {
1.150 raeburn 20658: foreach my $sparetype (@sparestypes) {
1.160.6.7 raeburn 20659: if (ref($currtargets{$balancer}{$sparetype}) eq 'ARRAY') {
20660: my @targetdiffs = &Apache::loncommon::compare_arrays($currtargets{$balancer}{$sparetype},$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype});
1.150 raeburn 20661: if (@targetdiffs > 0) {
1.160.6.7 raeburn 20662: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20663: }
1.160.6.7 raeburn 20664: } elsif (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20665: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20666: $changes{'curr'}{$balancer}{'targets'} = 1;
1.150 raeburn 20667: }
20668: }
20669: }
20670: } else {
1.160.6.7 raeburn 20671: if (ref($defaultshash{'loadbalancing'}{$balancer}) eq 'HASH') {
20672: foreach my $sparetype (@sparestypes) {
20673: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20674: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20675: $changes{'curr'}{$balancer}{'targets'} = 1;
20676: }
1.150 raeburn 20677: }
20678: }
1.160.6.7 raeburn 20679: }
1.150 raeburn 20680: }
20681: my $ishomedom;
1.160.6.7 raeburn 20682: if (&Apache::lonnet::host_domain($balancer) eq $dom) {
20683: $ishomedom = 1;
1.150 raeburn 20684: }
20685: if (ref($alltypes) eq 'ARRAY') {
20686: foreach my $type (@{$alltypes}) {
20687: my $rule;
1.160.6.7 raeburn 20688: unless ((($type eq '_LC_external') || ($type eq '_LC_internetdom')) &&
1.150 raeburn 20689: (!$ishomedom)) {
1.160.6.7 raeburn 20690: $rule = $env{'form.loadbalancing_rules_'.$i.'_'.$type};
20691: }
20692: if ($rule eq 'specific') {
1.160.6.55 raeburn 20693: my $specifiedhost = $env{'form.loadbalancing_singleserver_'.$i.'_'.$type};
20694: if (exists($servers{$specifiedhost})) {
20695: $rule = $specifiedhost;
20696: }
1.150 raeburn 20697: }
1.160.6.7 raeburn 20698: $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type} = $rule;
20699: if (ref($currrules{$balancer}) eq 'HASH') {
20700: if ($rule ne $currrules{$balancer}{$type}) {
20701: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20702: }
20703: } elsif ($rule ne '') {
1.160.6.7 raeburn 20704: $changes{'curr'}{$balancer}{'rules'}{$type} = 1;
1.150 raeburn 20705: }
20706: }
20707: }
1.160.6.7 raeburn 20708: }
20709: my $nochgmsg = &mt('No changes made to Load Balancer settings.');
20710: if ((keys(%changes) > 0) || ($saveloadbalancing)) {
20711: unless (ref($defaultshash{'loadbalancing'}) eq 'HASH') {
20712: $defaultshash{'loadbalancing'} = {};
20713: }
20714: my $putresult = &Apache::lonnet::put_dom('configuration',
20715: \%defaultshash,$dom);
20716: if ($putresult eq 'ok') {
20717: if (keys(%changes) > 0) {
1.160.6.54 raeburn 20718: my %toupdate;
1.160.6.7 raeburn 20719: if (ref($changes{'delete'}) eq 'ARRAY') {
20720: foreach my $balancer (sort(@{$changes{'delete'}})) {
20721: $resulttext .= '<li>'.&mt('Load Balancing discontinued for: [_1]',$balancer).'</li>';
1.160.6.54 raeburn 20722: $toupdate{$balancer} = 1;
1.150 raeburn 20723: }
1.160.6.7 raeburn 20724: }
20725: if (ref($changes{'add'}) eq 'ARRAY') {
20726: foreach my $balancer (sort(@{$changes{'add'}})) {
20727: $resulttext .= '<li>'.&mt('Load Balancing enabled for: [_1]',$balancer);
1.160.6.54 raeburn 20728: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20729: }
20730: }
20731: if (ref($changes{'curr'}) eq 'HASH') {
20732: foreach my $balancer (sort(keys(%{$changes{'curr'}}))) {
1.160.6.55 raeburn 20733: $toupdate{$balancer} = 1;
1.160.6.7 raeburn 20734: if (ref($changes{'curr'}{$balancer}) eq 'HASH') {
20735: if ($changes{'curr'}{$balancer}{'targets'}) {
20736: my %offloadstr;
20737: foreach my $sparetype (@sparestypes) {
20738: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20739: if (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}} > 0) {
20740: $offloadstr{$sparetype} = join(', ',@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20741: }
20742: }
1.150 raeburn 20743: }
1.160.6.7 raeburn 20744: if (keys(%offloadstr) == 0) {
20745: $resulttext .= '<li>'.&mt("Servers to which Load Balance server offloads set to 'None', by default").'</li>';
1.150 raeburn 20746: } else {
1.160.6.7 raeburn 20747: my $showoffload;
20748: foreach my $sparetype (@sparestypes) {
20749: $showoffload .= '<i>'.$typetitles{$sparetype}.'</i>: ';
20750: if (defined($offloadstr{$sparetype})) {
20751: $showoffload .= $offloadstr{$sparetype};
20752: } else {
20753: $showoffload .= &mt('None');
20754: }
20755: $showoffload .= (' 'x3);
20756: }
20757: $resulttext .= '<li>'.&mt('By default, Load Balancer: [_1] set to offload to - [_2]',$balancer,$showoffload).'</li>';
1.150 raeburn 20758: }
20759: }
20760: }
1.160.6.7 raeburn 20761: if (ref($changes{'curr'}{$balancer}{'rules'}) eq 'HASH') {
20762: if ((ref($alltypes) eq 'ARRAY') && (ref($titles) eq 'HASH')) {
20763: foreach my $type (@{$alltypes}) {
20764: if ($changes{'curr'}{$balancer}{'rules'}{$type}) {
20765: my $rule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20766: my $balancetext;
20767: if ($rule eq '') {
20768: $balancetext = $ruletitles{'default'};
1.160.6.26 raeburn 20769: } elsif (($rule eq 'homeserver') || ($rule eq 'externalbalancer') ||
1.160.6.55 raeburn 20770: ($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
20771: if (($type eq '_LC_ipchange') || ($type eq '_LC_ipchangesso')) {
1.160.6.54 raeburn 20772: foreach my $sparetype (@sparestypes) {
20773: if (ref($defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}) eq 'ARRAY') {
20774: map { $toupdate{$_} = 1; } (@{$defaultshash{'loadbalancing'}{$balancer}{'targets'}{$sparetype}});
20775: }
20776: }
1.160.6.55 raeburn 20777: foreach my $item (@{$alltypes}) {
20778: next if ($item =~ /^_LC_ipchange/);
20779: my $hasrule = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$item};
20780: if ($hasrule eq 'homeserver') {
20781: map { $toupdate{$_} = 1; } (keys(%libraryservers));
20782: } else {
20783: unless (($hasrule eq 'default') || ($hasrule eq 'none') || ($hasrule eq 'externalbalancer')) {
20784: if ($servers{$hasrule}) {
20785: $toupdate{$hasrule} = 1;
20786: }
20787: }
20788: }
20789: }
20790: if (($rule eq 'balancer') || ($rule eq 'offloadedto')) {
20791: $balancetext = $ruletitles{$rule};
20792: } else {
20793: my $receiver = $defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type};
20794: $balancetext = $ruletitles{'particular'}.' '.$receiver;
20795: if ($receiver) {
20796: $toupdate{$receiver};
20797: }
20798: }
20799: } else {
20800: $balancetext = $ruletitles{$rule};
1.160.6.54 raeburn 20801: }
1.160.6.7 raeburn 20802: } else {
20803: $balancetext = &mt('offload to [_1]',$defaultshash{'loadbalancing'}{$balancer}{'rules'}{$type});
20804: }
1.160.6.26 raeburn 20805: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- balancing for [_2] set to - "[_3]"',$balancer,$titles->{$type},$balancetext).'</li>';
1.150 raeburn 20806: }
20807: }
20808: }
20809: }
1.160.6.94 raeburn 20810: if ($changes{'curr'}{$balancer}{'cookie'}) {
1.160.6.117 raeburn 20811: if ($currcookies{$balancer}) {
20812: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use disabled',
20813: $balancer).'</li>';
20814: } else {
20815: $resulttext .= '<li>'.&mt('Load Balancer: [_1] -- cookie use enabled',
20816: $balancer).'</li>';
20817: }
1.160.6.94 raeburn 20818: }
1.160.6.106 raeburn 20819: }
20820: }
20821: if (keys(%toupdate)) {
20822: my %thismachine;
20823: my $updatedhere;
20824: my $cachetime = 60*60*24;
20825: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
20826: foreach my $lonhost (keys(%toupdate)) {
20827: if ($thismachine{$lonhost}) {
20828: unless ($updatedhere) {
20829: &Apache::lonnet::do_cache_new('loadbalancing',$dom,
20830: $defaultshash{'loadbalancing'},
20831: $cachetime);
20832: $updatedhere = 1;
1.160.6.54 raeburn 20833: }
1.160.6.106 raeburn 20834: } else {
20835: my $cachekey = &escape('loadbalancing').':'.&escape($dom);
20836: &Apache::lonnet::remote_devalidate_cache($lonhost,[$cachekey]);
1.160.6.54 raeburn 20837: }
1.150 raeburn 20838: }
1.160.6.7 raeburn 20839: }
20840: if ($resulttext ne '') {
20841: $resulttext = &mt('Changes made:').'<ul>'.$resulttext.'</ul>';
1.150 raeburn 20842: } else {
20843: $resulttext = $nochgmsg;
20844: }
20845: } else {
1.160.6.7 raeburn 20846: $resulttext = $nochgmsg;
1.150 raeburn 20847: }
20848: } else {
1.160.6.7 raeburn 20849: $resulttext = '<span class="LC_error">'.
20850: &mt('An error occurred: [_1]',$putresult).'</span>';
1.150 raeburn 20851: }
20852: } else {
1.160.6.7 raeburn 20853: $resulttext = $nochgmsg;
1.150 raeburn 20854: }
20855: return $resulttext;
20856: }
20857:
1.48 raeburn 20858: sub recurse_check {
20859: my ($chkcats,$categories,$depth,$name) = @_;
20860: if (ref($chkcats->[$depth]{$name}) eq 'ARRAY') {
20861: my $chg = 0;
20862: for (my $j=0; $j<@{$chkcats->[$depth]{$name}}; $j++) {
20863: my $category = $chkcats->[$depth]{$name}[$j];
20864: my $item;
20865: if ($category eq '') {
20866: $chg ++;
20867: } else {
20868: my $deeper = $depth + 1;
20869: $item = &escape($category).':'.&escape($name).':'.$depth;
20870: if ($chg) {
20871: $categories->{$item} -= $chg;
20872: }
20873: &recurse_check($chkcats,$categories,$deeper,$category);
20874: $deeper --;
20875: }
20876: }
20877: }
20878: return;
20879: }
20880:
20881: sub recurse_cat_deletes {
20882: my ($item,$coursecategories,$deletions) = @_;
20883: my ($deleted,$container,$depth) = map { &unescape($_); } split(/:/,$item);
20884: my $subdepth = $depth + 1;
20885: if (ref($coursecategories) eq 'HASH') {
20886: foreach my $subitem (keys(%{$coursecategories})) {
20887: my ($child,$parent,$itemdepth) = map { &unescape($_); } split(/:/,$subitem);
20888: if (($parent eq $deleted) && ($itemdepth == $subdepth)) {
20889: delete($coursecategories->{$subitem});
20890: $deletions->{$subitem} = 1;
20891: &recurse_cat_deletes($subitem,$coursecategories,$deletions);
1.160.6.26 raeburn 20892: }
1.48 raeburn 20893: }
20894: }
20895: return;
20896: }
20897:
1.125 raeburn 20898: sub active_dc_picker {
1.160.6.16 raeburn 20899: my ($dom,$numinrow,$inputtype,$name,%currhash) = @_;
1.160.6.77 raeburn 20900: my %domcoords = &Apache::lonnet::get_active_domroles($dom,['dc']);
1.160.6.16 raeburn 20901: my @domcoord = keys(%domcoords);
20902: if (keys(%currhash)) {
20903: foreach my $dc (keys(%currhash)) {
20904: unless (exists($domcoords{$dc})) {
20905: push(@domcoord,$dc);
20906: }
20907: }
20908: }
20909: @domcoord = sort(@domcoord);
20910: my $numdcs = scalar(@domcoord);
20911: my $rows = 0;
20912: my $table;
1.125 raeburn 20913: if ($numdcs > 1) {
1.160.6.16 raeburn 20914: $table = '<table>';
20915: for (my $i=0; $i<@domcoord; $i++) {
1.125 raeburn 20916: my $rem = $i%($numinrow);
20917: if ($rem == 0) {
20918: if ($i > 0) {
1.160.6.16 raeburn 20919: $table .= '</tr>';
1.125 raeburn 20920: }
1.160.6.16 raeburn 20921: $table .= '<tr>';
20922: $rows ++;
1.125 raeburn 20923: }
1.160.6.16 raeburn 20924: my $check = '';
20925: if ($inputtype eq 'radio') {
20926: if (keys(%currhash) == 0) {
20927: if (!$i) {
20928: $check = ' checked="checked"';
20929: }
20930: } elsif (exists($currhash{$domcoord[$i]})) {
20931: $check = ' checked="checked"';
20932: }
20933: } else {
20934: if (exists($currhash{$domcoord[$i]})) {
20935: $check = ' checked="checked"';
1.125 raeburn 20936: }
20937: }
1.160.6.16 raeburn 20938: if ($i == @domcoord - 1) {
1.125 raeburn 20939: my $colsleft = $numinrow - $rem;
20940: if ($colsleft > 1) {
1.160.6.16 raeburn 20941: $table .= '<td class="LC_left_item" colspan="'.$colsleft.'">';
1.125 raeburn 20942: } else {
1.160.6.16 raeburn 20943: $table .= '<td class="LC_left_item">';
1.125 raeburn 20944: }
20945: } else {
1.160.6.16 raeburn 20946: $table .= '<td class="LC_left_item">';
20947: }
20948: my ($dcname,$dcdom) = split(':',$domcoord[$i]);
20949: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
20950: $table .= '<span class="LC_nobreak"><label>'.
20951: '<input type="'.$inputtype.'" name="'.$name.'"'.
20952: ' value="'.$domcoord[$i].'"'.$check.' />'.$user;
20953: if ($user ne $dcname.':'.$dcdom) {
1.160.6.32 raeburn 20954: $table .= ' ('.$dcname.':'.$dcdom.')';
1.125 raeburn 20955: }
1.160.6.33 raeburn 20956: $table .= '</label></span></td>';
1.125 raeburn 20957: }
1.160.6.16 raeburn 20958: $table .= '</tr></table>';
20959: } elsif ($numdcs == 1) {
1.160.6.32 raeburn 20960: my ($dcname,$dcdom) = split(':',$domcoord[0]);
20961: my $user = &Apache::loncommon::plainname($dcname,$dcdom);
1.160.6.16 raeburn 20962: if ($inputtype eq 'radio') {
1.160.6.50 raeburn 20963: $table = '<input type="hidden" name="'.$name.'" value="'.$domcoord[0].'" />'.$user;
1.160.6.31 raeburn 20964: if ($user ne $dcname.':'.$dcdom) {
20965: $table .= ' ('.$dcname.':'.$dcdom.')';
20966: }
1.160.6.16 raeburn 20967: } else {
20968: my $check;
20969: if (exists($currhash{$domcoord[0]})) {
20970: $check = ' checked="checked"';
20971: }
1.160.6.50 raeburn 20972: $table = '<span class="LC_nobreak"><label>'.
20973: '<input type="checkbox" name="'.$name.'" '.
20974: 'value="'.$domcoord[0].'"'.$check.' />'.$user;
1.160.6.31 raeburn 20975: if ($user ne $dcname.':'.$dcdom) {
20976: $table .= ' ('.$dcname.':'.$dcdom.')';
20977: }
20978: $table .= '</label></span>';
1.160.6.16 raeburn 20979: $rows ++;
20980: }
1.125 raeburn 20981: }
1.160.6.16 raeburn 20982: return ($numdcs,$table,$rows);
1.125 raeburn 20983: }
20984:
1.137 raeburn 20985: sub usersession_titles {
20986: return &Apache::lonlocal::texthash(
20987: hosted => 'Hosting of sessions for users from other domains on servers in this domain',
20988: remote => 'Hosting of sessions for users in this domain on servers in other domains',
1.145 raeburn 20989: spares => 'Servers offloaded to, when busy',
1.137 raeburn 20990: version => 'LON-CAPA version requirement',
1.138 raeburn 20991: excludedomain => 'Allow all, but exclude specific domains',
20992: includedomain => 'Deny all, but include specific domains',
1.145 raeburn 20993: primary => 'Primary (checked first)',
1.154 raeburn 20994: default => 'Default',
1.137 raeburn 20995: );
20996: }
20997:
1.152 raeburn 20998: sub id_for_thisdom {
20999: my (%servers) = @_;
21000: my %altids;
21001: foreach my $server (keys(%servers)) {
21002: my $serverhome = &Apache::lonnet::get_server_homeID($servers{$server});
21003: if ($serverhome ne $server) {
21004: $altids{$serverhome} = $server;
21005: }
21006: }
21007: return %altids;
21008: }
21009:
1.150 raeburn 21010: sub count_servers {
21011: my ($currbalancer,%servers) = @_;
21012: my (@spares,$numspares);
21013: foreach my $lonhost (sort(keys(%servers))) {
21014: next if ($currbalancer eq $lonhost);
21015: push(@spares,$lonhost);
21016: }
21017: if ($currbalancer) {
21018: $numspares = scalar(@spares);
21019: } else {
21020: $numspares = scalar(@spares) - 1;
21021: }
21022: return ($numspares,@spares);
21023: }
21024:
21025: sub lonbalance_targets_js {
1.160.6.7 raeburn 21026: my ($dom,$types,$servers,$settings) = @_;
1.150 raeburn 21027: my $select = &mt('Select');
21028: my ($alltargets,$allishome,$allinsttypes,@alltypes);
21029: if (ref($servers) eq 'HASH') {
21030: $alltargets = join("','",sort(keys(%{$servers})));
21031: my @homedoms;
21032: foreach my $server (sort(keys(%{$servers}))) {
21033: if (&Apache::lonnet::host_domain($server) eq $dom) {
21034: push(@homedoms,'1');
21035: } else {
21036: push(@homedoms,'0');
21037: }
21038: }
21039: $allishome = join("','",@homedoms);
21040: }
21041: if (ref($types) eq 'ARRAY') {
21042: if (@{$types} > 0) {
21043: @alltypes = @{$types};
21044: }
21045: }
21046: push(@alltypes,'default','_LC_adv','_LC_author','_LC_internetdom','_LC_external');
21047: $allinsttypes = join("','",@alltypes);
1.160.6.94 raeburn 21048: my (%currbalancer,%currtargets,%currrules,%existing,%currcookies);
1.160.6.7 raeburn 21049: if (ref($settings) eq 'HASH') {
21050: %existing = %{$settings};
21051: }
21052: &get_loadbalancers_config($servers,\%existing,\%currbalancer,
1.160.6.94 raeburn 21053: \%currtargets,\%currrules,\%currcookies);
1.160.6.7 raeburn 21054: my $balancers = join("','",sort(keys(%currbalancer)));
1.150 raeburn 21055: return <<"END";
21056:
21057: <script type="text/javascript">
21058: // <![CDATA[
21059:
1.160.6.7 raeburn 21060: currBalancers = new Array('$balancers');
21061:
21062: function toggleTargets(balnum) {
21063: var lonhostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21064: var prevhostitem = document.getElementById('loadbalancing_prevlonhost_'+balnum);
21065: var balancer = lonhostitem.options[lonhostitem.selectedIndex].value;
21066: var prevbalancer = prevhostitem.value;
21067: var baltotal = document.getElementById('loadbalancing_total').value;
21068: prevhostitem.value = balancer;
21069: if (prevbalancer != '') {
21070: var prevIdx = currBalancers.indexOf(prevbalancer);
21071: if (prevIdx != -1) {
21072: currBalancers.splice(prevIdx,1);
21073: }
21074: }
1.150 raeburn 21075: if (balancer == '') {
1.160.6.7 raeburn 21076: hideSpares(balnum);
1.150 raeburn 21077: } else {
1.160.6.7 raeburn 21078: var currIdx = currBalancers.indexOf(balancer);
21079: if (currIdx == -1) {
21080: currBalancers.push(balancer);
21081: }
1.150 raeburn 21082: var homedoms = new Array('$allishome');
1.160.6.7 raeburn 21083: var ishomedom = homedoms[lonhostitem.selectedIndex];
21084: showSpares(balancer,ishomedom,balnum);
1.150 raeburn 21085: }
1.160.6.7 raeburn 21086: balancerChange(balnum,baltotal,'change',prevbalancer,balancer);
1.150 raeburn 21087: return;
21088: }
21089:
1.160.6.7 raeburn 21090: function showSpares(balancer,ishomedom,balnum) {
1.150 raeburn 21091: var alltargets = new Array('$alltargets');
21092: var insttypes = new Array('$allinsttypes');
1.151 raeburn 21093: var offloadtypes = new Array('primary','default');
21094:
1.160.6.7 raeburn 21095: document.getElementById('loadbalancing_targets_'+balnum).style.display='block';
21096: document.getElementById('loadbalancing_disabled_'+balnum).style.display='none';
1.152 raeburn 21097:
1.151 raeburn 21098: for (var i=0; i<offloadtypes.length; i++) {
21099: var count = 0;
21100: for (var j=0; j<alltargets.length; j++) {
21101: if (alltargets[j] != balancer) {
1.160.6.7 raeburn 21102: var item = document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+count);
21103: item.value = alltargets[j];
21104: item.style.textAlign='left';
21105: item.style.textFace='normal';
21106: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+count).innerHTML = alltargets[j];
21107: if (currBalancers.indexOf(alltargets[j]) == -1) {
21108: item.disabled = '';
21109: } else {
21110: item.disabled = 'disabled';
21111: item.checked = false;
21112: }
1.151 raeburn 21113: count ++;
21114: }
1.150 raeburn 21115: }
21116: }
1.151 raeburn 21117: for (var k=0; k<insttypes.length; k++) {
21118: if ((insttypes[k] == '_LC_external') || (insttypes[k] == '_LC_internetdom')) {
1.150 raeburn 21119: if (ishomedom == 1) {
1.160.6.7 raeburn 21120: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21121: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21122: } else {
1.160.6.7 raeburn 21123: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21124: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.150 raeburn 21125: }
21126: } else {
1.160.6.7 raeburn 21127: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='block';
21128: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='block';
1.150 raeburn 21129: }
1.151 raeburn 21130: if ((insttypes[k] != '_LC_external') &&
21131: ((insttypes[k] != '_LC_internetdom') ||
21132: ((insttypes[k] == '_LC_internetdom') && (ishomedom == 1)))) {
1.160.6.7 raeburn 21133: var item = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]);
21134: item.options.length = 0;
21135: item.options[0] = new Option("","",true,true);
21136: var idx = 0;
1.151 raeburn 21137: for (var m=0; m<alltargets.length; m++) {
1.160.6.7 raeburn 21138: if ((currBalancers.indexOf(alltargets[m]) == -1) && (alltargets[m] != balancer)) {
21139: idx ++;
21140: item.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
1.150 raeburn 21141: }
21142: }
21143: }
21144: }
21145: return;
21146: }
21147:
1.160.6.7 raeburn 21148: function hideSpares(balnum) {
1.150 raeburn 21149: var alltargets = new Array('$alltargets');
21150: var insttypes = new Array('$allinsttypes');
21151: var offloadtypes = new Array('primary','default');
21152:
1.160.6.7 raeburn 21153: document.getElementById('loadbalancing_targets_'+balnum).style.display='none';
21154: document.getElementById('loadbalancing_disabled_'+balnum).style.display='block';
1.150 raeburn 21155:
21156: var total = alltargets.length - 1;
21157: for (var i=0; i<offloadtypes; i++) {
21158: for (var j=0; j<total; j++) {
1.160.6.7 raeburn 21159: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).checked = false;
21160: document.getElementById('loadbalancing_target_'+balnum+'_'+offloadtypes[i]+'_'+j).value = '';
21161: document.getElementById('loadbalancing_targettxt_'+balnum+'_'+offloadtypes[i]+'_'+j).innerHTML = '';
1.151 raeburn 21162: }
1.150 raeburn 21163: }
21164: for (var k=0; k<insttypes.length; k++) {
1.160.6.7 raeburn 21165: document.getElementById('balanceruletitle_'+balnum+'_'+insttypes[k]).style.display='none';
21166: document.getElementById('balancerule_'+balnum+'_'+insttypes[k]).style.display='none';
1.151 raeburn 21167: if (insttypes[k] != '_LC_external') {
1.160.6.7 raeburn 21168: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).length = 0;
21169: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+insttypes[k]).options[0] = new Option("","",true,true);
1.150 raeburn 21170: }
21171: }
21172: return;
21173: }
21174:
1.160.6.7 raeburn 21175: function checkOffloads(item,balnum,type) {
1.150 raeburn 21176: var alltargets = new Array('$alltargets');
21177: var offloadtypes = new Array('primary','default');
21178: if (item.checked) {
21179: var total = alltargets.length - 1;
21180: var other;
21181: if (type == offloadtypes[0]) {
1.151 raeburn 21182: other = offloadtypes[1];
1.150 raeburn 21183: } else {
1.151 raeburn 21184: other = offloadtypes[0];
1.150 raeburn 21185: }
21186: for (var i=0; i<total; i++) {
1.160.6.7 raeburn 21187: var server = document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).value;
1.150 raeburn 21188: if (server == item.value) {
1.160.6.7 raeburn 21189: if (document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked) {
21190: document.getElementById('loadbalancing_target_'+balnum+'_'+other+'_'+i).checked = false;
1.150 raeburn 21191: }
21192: }
21193: }
21194: }
21195: return;
21196: }
21197:
1.160.6.7 raeburn 21198: function singleServerToggle(balnum,type) {
21199: var offloadtoSelIdx = document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex;
1.150 raeburn 21200: if (offloadtoSelIdx == 0) {
1.160.6.7 raeburn 21201: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_0').checked = true;
21202: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21203:
21204: } else {
1.160.6.7 raeburn 21205: document.getElementById('loadbalancing_rules_'+balnum+'_'+type+'_2').checked = true;
21206: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
1.150 raeburn 21207: }
21208: return;
21209: }
21210:
1.160.6.7 raeburn 21211: function balanceruleChange(formname,balnum,type) {
1.150 raeburn 21212: if (type == '_LC_external') {
1.160.6.26 raeburn 21213: return;
1.150 raeburn 21214: }
1.160.6.7 raeburn 21215: var typesRules = getIndicesByName(formname,'loadbalancing_rules_'+balnum+'_'+type);
1.150 raeburn 21216: for (var i=0; i<typesRules.length; i++) {
21217: if (formname.elements[typesRules[i]].checked) {
21218: if (formname.elements[typesRules[i]].value != 'specific') {
1.160.6.7 raeburn 21219: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).selectedIndex = 0;
21220: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '';
1.150 raeburn 21221: } else {
1.160.6.7 raeburn 21222: document.getElementById('loadbalancing_singleserver_'+balnum+'_'+type).options[0].text = '$select';
21223: }
21224: }
21225: }
21226: return;
21227: }
21228:
21229: function balancerDeleteChange(balnum) {
21230: var hostitem = document.getElementById('loadbalancing_lonhost_'+balnum);
21231: var baltotal = document.getElementById('loadbalancing_total').value;
21232: var addtarget;
21233: var removetarget;
21234: var action = 'delete';
21235: if (document.getElementById('loadbalancing_delete_'+balnum)) {
21236: var lonhost = hostitem.value;
21237: var currIdx = currBalancers.indexOf(lonhost);
21238: if (document.getElementById('loadbalancing_delete_'+balnum).checked) {
21239: if (currIdx != -1) {
21240: currBalancers.splice(currIdx,1);
21241: }
21242: addtarget = lonhost;
21243: } else {
21244: if (currIdx == -1) {
21245: currBalancers.push(lonhost);
21246: }
21247: removetarget = lonhost;
21248: action = 'undelete';
21249: }
21250: balancerChange(balnum,baltotal,action,addtarget,removetarget);
21251: }
21252: return;
21253: }
21254:
21255: function balancerChange(balnum,baltotal,action,addtarget,removetarget) {
21256: if (baltotal > 1) {
21257: var offloadtypes = new Array('primary','default');
21258: var alltargets = new Array('$alltargets');
21259: var insttypes = new Array('$allinsttypes');
21260: for (var i=0; i<baltotal; i++) {
21261: if (i != balnum) {
21262: for (var j=0; j<offloadtypes.length; j++) {
21263: var total = alltargets.length - 1;
21264: for (var k=0; k<total; k++) {
21265: var serveritem = document.getElementById('loadbalancing_target_'+i+'_'+offloadtypes[j]+'_'+k);
21266: var server = serveritem.value;
21267: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21268: if (server == addtarget) {
21269: serveritem.disabled = '';
21270: }
21271: }
21272: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21273: if (server == removetarget) {
21274: serveritem.disabled = 'disabled';
21275: serveritem.checked = false;
21276: }
21277: }
21278: }
21279: }
21280: for (var j=0; j<insttypes.length; j++) {
21281: if (insttypes[j] != '_LC_external') {
21282: if (document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j])) {
21283: var singleserver = document.getElementById('loadbalancing_singleserver_'+i+'_'+insttypes[j]);
21284: var currSel = singleserver.selectedIndex;
21285: var currVal = singleserver.options[currSel].value;
21286: if ((action == 'delete') || (action == 'change' && addtarget != '')) {
21287: var numoptions = singleserver.options.length;
21288: var needsnew = 1;
21289: for (var k=0; k<numoptions; k++) {
21290: if (singleserver.options[k] == addtarget) {
21291: needsnew = 0;
21292: break;
21293: }
21294: }
21295: if (needsnew == 1) {
21296: singleserver.options[numoptions] = new Option(addtarget,addtarget,false,false);
21297: }
21298: }
21299: if ((action == 'undelete') || (action == 'change' && removetarget != '')) {
21300: singleserver.options.length = 0;
21301: if ((currVal) && (currVal != removetarget)) {
21302: singleserver.options[0] = new Option("","",false,false);
21303: } else {
21304: singleserver.options[0] = new Option("","",true,true);
21305: }
21306: var idx = 0;
21307: for (var m=0; m<alltargets.length; m++) {
21308: if (currBalancers.indexOf(alltargets[m]) == -1) {
21309: idx ++;
21310: if (currVal == alltargets[m]) {
21311: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],true,true);
21312: } else {
21313: singleserver.options[idx] = new Option(alltargets[m],alltargets[m],false,false);
21314: }
21315: }
21316: }
21317: }
21318: }
21319: }
21320: }
1.150 raeburn 21321: }
21322: }
21323: }
21324: return;
21325: }
21326:
1.152 raeburn 21327: // ]]>
21328: </script>
21329:
21330: END
21331: }
21332:
21333: sub new_spares_js {
21334: my @sparestypes = ('primary','default');
21335: my $types = join("','",@sparestypes);
21336: my $select = &mt('Select');
21337: return <<"END";
21338:
21339: <script type="text/javascript">
21340: // <![CDATA[
21341:
21342: function updateNewSpares(formname,lonhost) {
21343: var types = new Array('$types');
21344: var include = new Array();
21345: var exclude = new Array();
21346: for (var i=0; i<types.length; i++) {
21347: var spareboxes = getIndicesByName(formname,'spare_'+types[i]+'_'+lonhost);
21348: for (var j=0; j<spareboxes.length; j++) {
21349: if (formname.elements[spareboxes[j]].checked) {
21350: exclude.push(formname.elements[spareboxes[j]].value);
21351: } else {
21352: include.push(formname.elements[spareboxes[j]].value);
21353: }
21354: }
21355: }
21356: for (var i=0; i<types.length; i++) {
21357: var newSpare = document.getElementById('newspare_'+types[i]+'_'+lonhost);
21358: var selIdx = newSpare.selectedIndex;
21359: var currnew = newSpare.options[selIdx].value;
21360: var okSpares = new Array();
21361: for (var j=0; j<newSpare.options.length; j++) {
21362: var possible = newSpare.options[j].value;
21363: if (possible != '') {
21364: if (exclude.indexOf(possible) == -1) {
21365: okSpares.push(possible);
21366: } else {
21367: if (currnew == possible) {
21368: selIdx = 0;
21369: }
21370: }
21371: }
21372: }
21373: for (var k=0; k<include.length; k++) {
21374: if (okSpares.indexOf(include[k]) == -1) {
21375: okSpares.push(include[k]);
21376: }
21377: }
21378: okSpares.sort();
21379: newSpare.options.length = 0;
21380: if (selIdx == 0) {
21381: newSpare.options[0] = new Option("$select","",true,true);
21382: } else {
21383: newSpare.options[0] = new Option("$select","",false,false);
21384: }
21385: for (var m=0; m<okSpares.length; m++) {
21386: var idx = m+1;
21387: var selThis = 0;
21388: if (selIdx != 0) {
21389: if (okSpares[m] == currnew) {
21390: selThis = 1;
21391: }
21392: }
21393: if (selThis == 1) {
21394: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],true,true);
21395: } else {
21396: newSpare.options[idx] = new Option(okSpares[m],okSpares[m],false,false);
21397: }
21398: }
21399: }
21400: return;
21401: }
21402:
21403: function checkNewSpares(lonhost,type) {
21404: var newSpare = document.getElementById('newspare_'+type+'_'+lonhost);
21405: var chosen = newSpare.options[newSpare.selectedIndex].value;
1.160.6.118.2 14(raebu 21406:23): if (chosen != '') {
1.152 raeburn 21407: var othertype;
21408: var othernewSpare;
21409: if (type == 'primary') {
21410: othernewSpare = document.getElementById('newspare_default_'+lonhost);
21411: }
21412: if (type == 'default') {
21413: othernewSpare = document.getElementById('newspare_primary_'+lonhost);
21414: }
21415: if (othernewSpare.options[othernewSpare.selectedIndex].value == chosen) {
21416: othernewSpare.selectedIndex = 0;
21417: }
21418: }
21419: return;
21420: }
21421:
21422: // ]]>
21423: </script>
21424:
21425: END
21426:
21427: }
21428:
21429: sub common_domprefs_js {
21430: return <<"END";
21431:
21432: <script type="text/javascript">
21433: // <![CDATA[
21434:
1.150 raeburn 21435: function getIndicesByName(formname,item) {
1.152 raeburn 21436: var group = new Array();
1.150 raeburn 21437: for (var i=0;i<formname.elements.length;i++) {
21438: if (formname.elements[i].name == item) {
1.152 raeburn 21439: group.push(formname.elements[i].id);
1.150 raeburn 21440: }
21441: }
1.152 raeburn 21442: return group;
1.150 raeburn 21443: }
21444:
21445: // ]]>
21446: </script>
21447:
21448: END
1.152 raeburn 21449:
1.150 raeburn 21450: }
21451:
1.160.6.5 raeburn 21452: sub recaptcha_js {
21453: my %lt = &captcha_phrases();
21454: return <<"END";
21455:
21456: <script type="text/javascript">
21457: // <![CDATA[
21458:
21459: function updateCaptcha(caller,context) {
21460: var privitem;
21461: var pubitem;
21462: var privtext;
21463: var pubtext;
1.160.6.69 raeburn 21464: var versionitem;
21465: var versiontext;
1.160.6.5 raeburn 21466: if (document.getElementById(context+'_recaptchapub')) {
21467: pubitem = document.getElementById(context+'_recaptchapub');
21468: } else {
21469: return;
21470: }
21471: if (document.getElementById(context+'_recaptchapriv')) {
21472: privitem = document.getElementById(context+'_recaptchapriv');
21473: } else {
21474: return;
21475: }
21476: if (document.getElementById(context+'_recaptchapubtxt')) {
21477: pubtext = document.getElementById(context+'_recaptchapubtxt');
21478: } else {
21479: return;
21480: }
21481: if (document.getElementById(context+'_recaptchaprivtxt')) {
21482: privtext = document.getElementById(context+'_recaptchaprivtxt');
21483: } else {
21484: return;
21485: }
1.160.6.69 raeburn 21486: if (document.getElementById(context+'_recaptchaversion')) {
21487: versionitem = document.getElementById(context+'_recaptchaversion');
21488: } else {
21489: return;
21490: }
21491: if (document.getElementById(context+'_recaptchavertxt')) {
21492: versiontext = document.getElementById(context+'_recaptchavertxt');
21493: } else {
21494: return;
21495: }
1.160.6.5 raeburn 21496: if (caller.checked) {
21497: if (caller.value == 'recaptcha') {
21498: pubitem.type = 'text';
21499: privitem.type = 'text';
21500: pubitem.size = '40';
21501: privitem.size = '40';
21502: pubtext.innerHTML = "$lt{'pub'}";
21503: privtext.innerHTML = "$lt{'priv'}";
1.160.6.69 raeburn 21504: versionitem.type = 'text';
21505: versionitem.size = '3';
21506: versiontext.innerHTML = "$lt{'ver'}";
1.160.6.5 raeburn 21507: } else {
21508: pubitem.type = 'hidden';
21509: privitem.type = 'hidden';
1.160.6.69 raeburn 21510: versionitem.type = 'hidden';
1.160.6.5 raeburn 21511: pubtext.innerHTML = '';
21512: privtext.innerHTML = '';
1.160.6.69 raeburn 21513: versiontext.innerHTML = '';
1.160.6.5 raeburn 21514: }
21515: }
21516: return;
21517: }
21518:
21519: // ]]>
21520: </script>
21521:
21522: END
21523:
21524: }
21525:
1.160.6.40 raeburn 21526: sub toggle_display_js {
1.160.6.16 raeburn 21527: return <<"END";
21528:
21529: <script type="text/javascript">
21530: // <![CDATA[
21531:
1.160.6.40 raeburn 21532: function toggleDisplay(domForm,caller) {
21533: if (document.getElementById(caller)) {
21534: var divitem = document.getElementById(caller);
21535: var optionsElement = domForm.coursecredits;
1.160.6.64 raeburn 21536: var checkval = 1;
21537: var dispval = 'block';
1.160.6.93 raeburn 21538: var selfcreateRegExp = /^cancreate_emailverified/;
1.160.6.40 raeburn 21539: if (caller == 'emailoptions') {
1.160.6.118.2 14(raebu 21540:23): optionsElement = domForm.cancreate_email;
1.160.6.40 raeburn 21541: }
1.160.6.57 raeburn 21542: if (caller == 'studentsubmission') {
21543: optionsElement = domForm.postsubmit;
21544: }
1.160.6.64 raeburn 21545: if (caller == 'cloneinstcode') {
21546: optionsElement = domForm.canclone;
21547: checkval = 'instcode';
21548: }
1.160.6.93 raeburn 21549: if (selfcreateRegExp.test(caller)) {
21550: optionsElement = domForm.elements[caller];
21551: checkval = 'other';
21552: dispval = 'inline'
21553: }
1.160.6.40 raeburn 21554: if (optionsElement.length) {
1.160.6.16 raeburn 21555: var currval;
1.160.6.40 raeburn 21556: for (var i=0; i<optionsElement.length; i++) {
21557: if (optionsElement[i].checked) {
21558: currval = optionsElement[i].value;
1.160.6.16 raeburn 21559: }
21560: }
1.160.6.64 raeburn 21561: if (currval == checkval) {
21562: divitem.style.display = dispval;
1.160.6.16 raeburn 21563: } else {
1.160.6.40 raeburn 21564: divitem.style.display = 'none';
1.160.6.16 raeburn 21565: }
21566: }
21567: }
21568: return;
21569: }
21570:
21571: // ]]>
21572: </script>
21573:
21574: END
21575:
21576: }
21577:
1.160.6.5 raeburn 21578: sub captcha_phrases {
21579: return &Apache::lonlocal::texthash (
21580: priv => 'Private key',
21581: pub => 'Public key',
21582: original => 'original (CAPTCHA)',
21583: recaptcha => 'successor (ReCAPTCHA)',
21584: notused => 'unused',
1.160.6.69 raeburn 21585: ver => 'ReCAPTCHA version (1 or 2)',
1.160.6.5 raeburn 21586: );
21587: }
21588:
1.160.6.24 raeburn 21589: sub devalidate_remote_domconfs {
1.160.6.27 raeburn 21590: my ($dom,$cachekeys) = @_;
21591: return unless (ref($cachekeys) eq 'HASH');
1.160.6.24 raeburn 21592: my %servers = &Apache::lonnet::internet_dom_servers($dom);
21593: my %thismachine;
21594: map { $thismachine{$_} = 1; } &Apache::lonnet::current_machine_ids();
1.160.6.118.2 1(raebur 21595:1): my @posscached = ('domainconfig','domdefaults','ltitools','usersessions',
1.160.6.113 raeburn 21596: 'directorysrch','passwdconf','cats','proxyalias','proxysaml',
21597: 'ipaccess');
21598: my %cache_by_lonhost;
21599: if (exists($cachekeys->{'samllanding'})) {
21600: if (ref($cachekeys->{'samllanding'}) eq 'HASH') {
21601: my %landing = %{$cachekeys->{'samllanding'}};
21602: my %domservers = &Apache::lonnet::get_servers($dom);
21603: if (keys(%domservers)) {
21604: foreach my $server (keys(%domservers)) {
21605: my @cached;
21606: next if ($thismachine{$server});
21607: if ($landing{$server}) {
21608: push(@cached,&escape('samllanding').':'.&escape($server));
21609: }
21610: if (@cached) {
21611: $cache_by_lonhost{$server} = \@cached;
21612: }
21613: }
21614: }
21615: }
21616: }
1.160.6.61 raeburn 21617: if (keys(%servers)) {
1.160.6.24 raeburn 21618: foreach my $server (keys(%servers)) {
21619: next if ($thismachine{$server});
1.160.6.27 raeburn 21620: my @cached;
21621: foreach my $name (@posscached) {
21622: if ($cachekeys->{$name}) {
1.160.6.113 raeburn 21623: if (($name eq 'proxyalias') || ($name eq 'proxysaml')) {
21624: if (ref($cachekeys->{$name}) eq 'HASH') {
21625: foreach my $key (keys(%{$cachekeys->{$name}})) {
21626: push(@cached,&escape($name).':'.&escape($key));
21627: }
21628: }
21629: } else {
21630: push(@cached,&escape($name).':'.&escape($dom));
21631: }
1.160.6.27 raeburn 21632: }
21633: }
1.160.6.113 raeburn 21634: if ((exists($cache_by_lonhost{$server})) &&
21635: (ref($cache_by_lonhost{$server}) eq 'ARRAY')) {
21636: push(@cached,@{$cache_by_lonhost{$server}});
21637: }
1.160.6.27 raeburn 21638: if (@cached) {
21639: &Apache::lonnet::remote_devalidate_cache($server,\@cached);
21640: }
1.160.6.24 raeburn 21641: }
21642: }
21643: return;
21644: }
21645:
1.3 raeburn 21646: 1;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>